Exemple #1
0
void* sbp_recv(void* newfd) {
	//char* ip;
	//int port;
	int tfd = *(int*) newfd;
	recinfo(tfd);
	decode_head(rec_buf, &sbphead);
	ana_head(&sbphead, rec_buf);

	//s64_t sockfd = ConnectServer(ip, port);
	sendinfo(tfd, send_buf, sizeof(send_buf));
	return 0;
}
Exemple #2
0
int reportlist(char* ip, int port) {
	if (getlist() < 0) {
		perror("fail to get list \n");
		return -1;
	}
	s64_t sockfd = ConnectServer(ip, port);
	sbphead = report_head(databuf, req_len);
	build_headp(&send_buf, &sbphead);
	sendinfo(sockfd, send_buf, sizeof(send_buf));
	recinfo(sockfd);
	if (strcmp(rec_buf, "SBPFS_OK") == 0) {
		printf("succeed in report");
		return 0;
	} else if (strcmp(rec_buf, "SBPFS_ERR") == 0) {
		printf("fail in report");
		return -1;
	} else {
		perror("fail to receive feedback \n");
		return -1;
	}
}
/**
*  \brief Creates a dialog for editing the recording status,
*         blocking until user leaves dialog.
*/
void ScheduleCommon::EditRecording(bool may_watch_now)
{
    ProgramInfo *pginfo = GetCurrentProgram();
    if (!pginfo)
        return;

    RecordingInfo recinfo(*pginfo);

    QString timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");

    QString message = recinfo.toString(ProgramInfo::kTitleSubtitle, " - ");

    message += "\n\n";
    message += RecStatus::toDescription(recinfo.GetRecordingStatus(),
                             recinfo.GetRecordingRuleType(),
                             recinfo.GetRecordingStartTime());

    if (recinfo.GetRecordingStatus() == RecStatus::Conflict ||
        recinfo.GetRecordingStatus() == RecStatus::LaterShowing)
    {
        vector<ProgramInfo *> *confList = RemoteGetConflictList(&recinfo);

        if (!confList->empty())
        {
            message += " ";
            message += tr("The following programs will be recorded instead:");
            message += "\n";
        }

        uint maxi = 0;
        for (; confList->begin() != confList->end() && maxi < 4; maxi++)
        {
            ProgramInfo *p = *confList->begin();
            message += QString("%1 - %2  %3\n")
                .arg(p->GetRecordingStartTime()
                     .toLocalTime().toString(timeFormat))
                .arg(p->GetRecordingEndTime()
                     .toLocalTime().toString(timeFormat))
                .arg(p->toString(ProgramInfo::kTitleSubtitle, " - "));
            delete p;
            confList->erase(confList->begin());
        }
        message += "\n";
        while (!confList->empty())
        {
            delete confList->back();
            confList->pop_back();
        }
        delete confList;
    }

    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
    MythDialogBox *menuPopup = new MythDialogBox(message, popupStack,
                                                 "recOptionPopup", true);
    if (!menuPopup->Create())
    {
        delete menuPopup;
        return;
    }
    menuPopup->SetReturnEvent(this, "editrecording");

    QDateTime now = MythDate::current();

    if(may_watch_now)
        menuPopup->AddButton(tr("Watch This Channel"));

    if (recinfo.GetRecordingStatus() == RecStatus::Unknown)
    {
        if (recinfo.GetRecordingEndTime() > now)
            menuPopup->AddButton(tr("Record this showing"),
                                 qVariantFromValue(recinfo));
        menuPopup->AddButton(tr("Record all showings"),
                             qVariantFromValue(recinfo));
        if (!recinfo.IsGeneric())
        {
            if (recinfo.GetCategoryType() == ProgramInfo::kCategoryMovie)
                menuPopup->AddButton(tr("Record one showing"),
                                     qVariantFromValue(recinfo));
            else
                menuPopup->AddButton(tr("Record one showing (this episode)"),
                                     qVariantFromValue(recinfo));

        }
        menuPopup->AddButton(tr("Record all showings (this channel)"),
                             qVariantFromValue(recinfo));
        menuPopup->AddButton(tr("Edit recording rule"),
                             qVariantFromValue(recinfo));
    }
    else if (recinfo.GetRecordingStatus() == RecStatus::Recording ||
             recinfo.GetRecordingStatus() == RecStatus::Tuning    ||
             recinfo.GetRecordingStatus() == RecStatus::Failing   ||
             recinfo.GetRecordingStatus() == RecStatus::Pending)
    {
        if (recinfo.GetRecordingStatus() != RecStatus::Pending)
            menuPopup->AddButton(tr("Stop this recording"),
                                 qVariantFromValue(recinfo));
        menuPopup->AddButton(tr("Modify recording options"),
                             qVariantFromValue(recinfo));
    }
    else
    {
        if (recinfo.GetRecordingStartTime() < now &&
            recinfo.GetRecordingEndTime() > now &&
            recinfo.GetRecordingStatus() != RecStatus::DontRecord &&
            recinfo.GetRecordingStatus() != RecStatus::NotListed)
        {
            menuPopup->AddButton(tr("Restart this recording"),
                                 qVariantFromValue(recinfo));
        }

        if (recinfo.GetRecordingEndTime() > now &&
            recinfo.GetRecordingRuleType() != kSingleRecord &&
            recinfo.GetRecordingRuleType() != kOverrideRecord &&
            (recinfo.GetRecordingStatus() == RecStatus::DontRecord ||
             recinfo.GetRecordingStatus() == RecStatus::PreviousRecording ||
             recinfo.GetRecordingStatus() == RecStatus::CurrentRecording ||
             recinfo.GetRecordingStatus() == RecStatus::EarlierShowing ||
             recinfo.GetRecordingStatus() == RecStatus::TooManyRecordings ||
             recinfo.GetRecordingStatus() == RecStatus::LaterShowing ||
             recinfo.GetRecordingStatus() == RecStatus::Repeat ||
             recinfo.GetRecordingStatus() == RecStatus::Inactive ||
             recinfo.GetRecordingStatus() == RecStatus::NeverRecord))
        {
            menuPopup->AddButton(tr("Record this showing"),
                                 qVariantFromValue(recinfo));
            if (recinfo.GetRecordingStartTime() > now &&
                (recinfo.GetRecordingStatus() == RecStatus::PreviousRecording ||
                 recinfo.GetRecordingStatus() == RecStatus::NeverRecord))
            {
                menuPopup->AddButton(tr("Forget previous recording"),
                                     qVariantFromValue(recinfo));
            }
        }

        if (recinfo.GetRecordingRuleType() != kSingleRecord &&
            recinfo.GetRecordingRuleType() != kDontRecord &&
            (recinfo.GetRecordingStatus() == RecStatus::WillRecord ||
             recinfo.GetRecordingStatus() == RecStatus::CurrentRecording ||
             recinfo.GetRecordingStatus() == RecStatus::EarlierShowing ||
             recinfo.GetRecordingStatus() == RecStatus::TooManyRecordings ||
             recinfo.GetRecordingStatus() == RecStatus::Conflict ||
             recinfo.GetRecordingStatus() == RecStatus::LaterShowing ||
             recinfo.GetRecordingStatus() == RecStatus::Offline))
        {
            if (recinfo.GetRecordingStatus() == RecStatus::WillRecord ||
                recinfo.GetRecordingStatus() == RecStatus::Conflict)
                menuPopup->AddButton(tr("Don't record this showing"),
                                     qVariantFromValue(recinfo));

            const RecordingDupMethodType dupmethod =
                recinfo.GetDuplicateCheckMethod();
            if (recinfo.GetRecordingRuleType() != kOverrideRecord &&
                !((recinfo.GetFindID() == 0 ||
                   !IsFindApplicable(recinfo)) &&
                  recinfo.GetCategoryType() == ProgramInfo::kCategorySeries &&
                  recinfo.GetProgramID().contains(QRegExp("0000$"))) &&
                ((!(dupmethod & kDupCheckNone) &&
                  !recinfo.GetProgramID().isEmpty() &&
                  (recinfo.GetFindID() != 0 ||
                   !IsFindApplicable(recinfo))) ||
                 ((dupmethod & kDupCheckSub) &&
                  !recinfo.GetSubtitle().isEmpty()) ||
                 ((dupmethod & kDupCheckDesc) &&
                  !recinfo.GetDescription().isEmpty()) ||
                 ((dupmethod & kDupCheckSubThenDesc) &&
                  (!recinfo.GetSubtitle().isEmpty() ||
                   !recinfo.GetDescription().isEmpty())) ))
            {
                menuPopup->AddButton(tr("Never record this episode"),
                                     qVariantFromValue(recinfo));
            }
        }

        if (recinfo.GetRecordingRuleType() == kOverrideRecord ||
            recinfo.GetRecordingRuleType() == kDontRecord)
        {
            menuPopup->AddButton(tr("Edit override rule"),
                                 qVariantFromValue(recinfo));
            menuPopup->AddButton(tr("Delete override rule"),
                                 qVariantFromValue(recinfo));
        }
        else
        {
            if (recinfo.GetRecordingRuleType() != kSingleRecord &&
                recinfo.GetRecordingStatus() != RecStatus::NotListed)
                menuPopup->AddButton(tr("Add override rule"),
                                     qVariantFromValue(recinfo));
            menuPopup->AddButton(tr("Edit recording rule"),
                                 qVariantFromValue(recinfo));
            menuPopup->AddButton(tr("Delete recording rule"),
                                 qVariantFromValue(recinfo));
        }
    }

    popupStack->AddScreen(menuPopup);
}
Exemple #4
0
void TVBrowseHelper::run()
{
    RunProlog();
    QMutexLocker locker(&m_lock);
    while (true)
    {
        while (m_list.empty() && m_run)
            m_wait.wait(&m_lock);

        if (!m_run)
            break;

        BrowseInfo bi = m_list.front();
        m_list.pop_front();

        PlayerContext *ctx = m_ctx;

        vector<uint> chanids;
        if (BROWSE_SAME == bi.m_dir)
        {
            if (!bi.m_chanid)
            {
                vector<uint> chanids_extra;
                uint sourceid = db_chanid_to_sourceid[m_chanid];
                QMultiMap<QString,uint>::iterator it;
                it = db_channum_to_chanids.lowerBound(bi.m_channum);
                for ( ; (it != db_channum_to_chanids.end()) &&
                          (it.key() == bi.m_channum); ++it)
                {
                    if (db_chanid_to_sourceid[*it] == sourceid)
                        chanids.push_back(*it);
                    else
                        chanids_extra.push_back(*it);
                }
                chanids.insert(chanids.end(),
                               chanids_extra.begin(),
                               chanids_extra.end());
            }
            m_channum   = bi.m_channum;
            m_chanid    = (chanids.empty()) ? bi.m_chanid : chanids[0];
            m_starttime = bi.m_starttime;
        }

        BrowseDirection direction = bi.m_dir;

        QDateTime lasttime = MythDate::fromString(m_starttime);
        QDateTime curtime  = MythDate::current();
        if (lasttime < curtime)
            m_starttime = curtime.toString(Qt::ISODate);

        QDateTime maxtime  = curtime.addSecs(db_browse_max_forward);
        if ((lasttime > maxtime) && (direction == BROWSE_RIGHT))
            continue;

        m_lock.unlock();

        // if browsing channel groups is enabled or
        // direction if BROWSE_FAVORITES
        // Then pick the next channel in the channel group list to browse
        // If channel group is ALL CHANNELS (-1), then bypass picking from
        // the channel group list
        if ((db_use_channel_groups || (direction == BROWSE_FAVORITE)) &&
            (direction != BROWSE_RIGHT) && (direction != BROWSE_LEFT) &&
            (direction != BROWSE_SAME))
        {
            m_tv->channelGroupLock.lock();
            if (m_tv->channelGroupId > -1)
            {
                ChannelChangeDirection dir = CHANNEL_DIRECTION_SAME;
                if ((direction == BROWSE_UP) || (direction == BROWSE_FAVORITE))
                    dir = CHANNEL_DIRECTION_UP;
                else if (direction == BROWSE_DOWN)
                    dir = CHANNEL_DIRECTION_DOWN;

                uint chanid = ChannelUtil::GetNextChannel(
                    m_tv->channelGroupChannelList, m_chanid, 0, 0, dir);
                direction = BROWSE_SAME;

                m_tv->channelGroupLock.unlock();

                m_lock.lock();
                m_chanid  = chanid;
                m_channum = QString::null;
                m_lock.unlock();
            }
            else
                m_tv->channelGroupLock.unlock();
        }

        if (direction == BROWSE_FAVORITE)
            direction = BROWSE_UP;

        InfoMap infoMap;
        infoMap["dbstarttime"] = m_starttime;
        infoMap["channum"]     = m_channum;
        infoMap["chanid"]      = QString::number(m_chanid);

        m_tv->GetPlayerReadLock(0,__FILE__,__LINE__);
        bool still_there = false;
        for (uint i = 0; i < m_tv->player.size() && !still_there; i++)
            still_there |= (ctx == m_tv->player[i]);
        if (still_there)
        {
            if (!db_browse_all_tuners)
            {
                GetNextProgram(direction, infoMap);
            }
            else
            {
                if (!chanids.empty())
                {
                    for (uint i = 0; i < chanids.size(); i++)
                    {
                        if (m_tv->IsTunable(ctx, chanids[i]))
                        {
                            infoMap["chanid"] = QString::number(chanids[i]);
                            GetNextProgramDB(direction, infoMap);
                            break;
                        }
                    }
                }
                else
                {
                    uint orig_chanid = infoMap["chanid"].toUInt();
                    GetNextProgramDB(direction, infoMap);
                    while (!m_tv->IsTunable(ctx, infoMap["chanid"].toUInt()) &&
                           (infoMap["chanid"].toUInt() != orig_chanid))
                    {
                        GetNextProgramDB(direction, infoMap);
                    }
                }
            }
        }
        m_tv->ReturnPlayerLock(ctx);

        m_lock.lock();
        if (!m_ctx && !still_there)
            continue;

        m_channum = infoMap["channum"];
        m_chanid  = infoMap["chanid"].toUInt();

        if (((direction == BROWSE_LEFT) || (direction == BROWSE_RIGHT)) &&
            !infoMap["dbstarttime"].isEmpty())
        {
            m_starttime = infoMap["dbstarttime"];
        }

        if (!m_list.empty())
        {
            // send partial info to UI for appearance of responsiveness
            QCoreApplication::postEvent(
                m_tv, new UpdateBrowseInfoEvent(infoMap));
            continue;
        }
        m_lock.unlock();

        // pull in additional data from the DB...
        if (m_tv->channelGroupId > -1 && db_use_channel_groups)
            infoMap["channelgroup"] = ChannelGroup::GetChannelGroupName(m_tv->channelGroupId);
        else
            infoMap["channelgroup"] = QObject::tr("All channels");

        QDateTime startts = MythDate::fromString(m_starttime);
        RecordingInfo recinfo(m_chanid, startts, false);
        recinfo.ToMap(infoMap);
        infoMap["iconpath"] = ChannelUtil::GetIcon(recinfo.GetChanID());

        m_lock.lock();
        if (m_ctx)
        {
            QCoreApplication::postEvent(
                m_tv, new UpdateBrowseInfoEvent(infoMap));
        }
    }
    RunEpilog();
}