Ticket #4501: browse_tuners.patch

File browse_tuners.patch, 8.6 KB (added by Ron Frazier <ron@…>, 12 years ago)

allows browsing across multiple tuners

  • libs/libmythtv/tv_play.h

     
    1919#include "programinfo.h"
    2020#include "channelutil.h"
    2121#include "videoouttypes.h"
     22#include "channelutil.h"
    2223
    2324#include <qobject.h>
    2425
     
    384385    void ToggleRecord(void);
    385386    void BrowseChannel(const QString &channum);
    386387
     388    uint    GetChanIDAnyTuner(const QString &chan);
     389    void    GetNextProgramAnyTuner(int direction, InfoMap &infoMap);
     390    QString GetProgramTunerStatus(InfoMap &infoMap);
     391    uint    FindAvailableTuner(const QString &chanid);
     392
    387393    void DoTogglePictureAttribute(PictureAdjustType type);
    388394    void DoChangePictureAttribute(
    389395        PictureAdjustType type, PictureAttribute attr, bool up);
     
    568574    QString browsechannum;
    569575    QString browsechanid;
    570576    QString browsestarttime;
     577    bool browsealltuners;
     578    DBChanList allchannels;   
    571579
    572580    // Program Info for currently playing video
    573581    // (or next video if InChangeState() is true)
  • libs/libmythtv/tv_play.cpp

     
    545545      browsemode(false), persistentbrowsemode(false),
    546546      browseTimer(new QTimer(this)),
    547547      browsechannum(""), browsechanid(""), browsestarttime(""),
     548      browsealltuners(false),
    548549      // Program Info for currently playing video
    549550      recorderPlaybackInfo(NULL),
    550551      playbackinfo(NULL), playbackLen(0),
     
    634635        ff_rew_speeds.push_back(
    635636            gContext->GetNumSetting(QString("FFRewSpeed%1").arg(i), def[i]));
    636637
     638    browsealltuners = gContext->GetNumSetting("BrowseAllTuners", 0);
     639    if (browsealltuners)
     640    {
     641        QString channelOrdering = gContext->GetSetting("ChannelOrdering", "channum");
     642        allchannels = ChannelUtil::GetChannels(0, true, "channum, callsign");
     643        ChannelUtil::SortChannels(allchannels, channelOrdering, true);
     644    };
     645
    637646    vbimode = VBIMode::Parse(gContext->GetSetting("VbiFormat"));
    638647
    639648    if (createWindow)
     
    56115620    return false;
    56125621}
    56135622
     5623uint TV::GetChanIDAnyTuner(const QString &chan)
     5624{
     5625    for (uint i = 0; i < allchannels.size(); ++i)
     5626        if (allchannels[i].channum == chan)
     5627            return allchannels[i].chanid;
     5628    return 0;
     5629};
     5630
     5631void TV::GetNextProgramAnyTuner(int direction, InfoMap &infoMap)
     5632{
     5633    uint chanid = infoMap["chanid"].toUInt();
     5634    if (infoMap["chanid"] == "")
     5635        chanid = GetChanIDAnyTuner(infoMap["channum"]);
     5636       
     5637    int chandir = -1;
     5638    switch(direction)
     5639    {
     5640        case BROWSE_UP:          chandir = CHANNEL_DIRECTION_UP;         break;
     5641        case BROWSE_DOWN:        chandir = CHANNEL_DIRECTION_DOWN;       break;
     5642        case BROWSE_FAVORITE:    chandir = CHANNEL_DIRECTION_FAVORITE;   break;
     5643    };
     5644    if (direction != -1)
     5645        chanid = ChannelUtil::GetNextChannel(allchannels, chanid, 0, chandir);
     5646
     5647    infoMap["chanid"] = QString("%1").arg(chanid);
     5648    infoMap["channum"] = ChannelUtil::GetChanNum(chanid);
     5649       
     5650
     5651    QDateTime nowtime = QDateTime::currentDateTime();
     5652    QDateTime latesttime = nowtime.addSecs(6*60*60);
     5653    QDateTime browsetime = QDateTime::fromString(infoMap["dbstarttime"], Qt::ISODate);
     5654
     5655    MSqlBindings bindings;
     5656    bindings[":CHANID"] = chanid;
     5657    bindings[":NOWTS"] = nowtime.toString("yyyy-MM-ddThh:mm:ss");
     5658    bindings[":LATESTTS"] = latesttime.toString("yyyy-MM-ddThh:mm:ss");
     5659    bindings[":BROWSETS"] = browsetime.toString("yyyy-MM-ddThh:mm:ss");
     5660
     5661    QString querystr = " WHERE program.chanid = :CHANID ";
     5662    switch(direction)
     5663    {
     5664        case BROWSE_LEFT:
     5665                querystr += " AND program.endtime <= :BROWSETS "
     5666                            " AND program.endtime > :NOWTS ";
     5667                break;
     5668
     5669        case BROWSE_RIGHT:
     5670                querystr += " AND program.starttime > :BROWSETS "
     5671                            " AND program.starttime < :LATESTTS ";
     5672                break;
     5673           
     5674        default:
     5675                querystr += " AND program.starttime <= :BROWSETS "
     5676                            " AND program.endtime > :BROWSETS ";
     5677    };
     5678
     5679    ProgramList progList;
     5680    progList.FromProgram(querystr, bindings);
     5681   
     5682    if (progList.isEmpty())
     5683    {
     5684        infoMap["dbstarttime"] = "";
     5685        return;
     5686    };
     5687
     5688    ProgramInfo* prog = (direction == BROWSE_LEFT) ? progList.last()
     5689                                                   : progList.first();
     5690   
     5691    infoMap["dbstarttime"] = prog->startts.toString(Qt::ISODate);
     5692}
     5693
     5694QString TV::GetProgramTunerStatus(InfoMap &infoMap)
     5695{
     5696    infoMap["tuner"] = infoMap["notuner"] = "";
     5697
     5698    uint cardid = FindAvailableTuner(infoMap["chanid"]);
     5699   
     5700    QString status;
     5701    if (!cardid)
     5702    {
     5703        infoMap["notuner"] = tr("No Tuner Available");
     5704        status = "unavailable";
     5705    }
     5706    else if (cardid == (uint)activerecorder->GetRecorderNumber())
     5707    {
     5708        infoMap["tuner"] = tr("Current Tuner");
     5709        status = "current";
     5710    }
     5711    else
     5712    {
     5713        infoMap["tuner"] = tr("Tuner")+QString(" %1").arg(cardid);
     5714        status = "available";
     5715    }
     5716   
     5717    return status;
     5718};
     5719
     5720uint TV::FindAvailableTuner(const QString &chanid)
     5721{
     5722    if (!activerecorder->ShouldSwitchToAnotherCard(chanid))
     5723        return activerecorder->GetRecorderNumber();
     5724
     5725    QStringList validlist = GetValidRecorderList(chanid.toUInt());
     5726    QStringList freelist = "GET_FREE_RECORDER_LIST";
     5727    if (!gContext->SendReceiveStringList(freelist, true))
     5728        return 0;
     5729
     5730    QStringList::iterator recIter;
     5731    for (recIter = validlist.begin(); recIter != validlist.end(); ++recIter)
     5732    {
     5733        if (freelist.find(*recIter) == freelist.end())
     5734            continue;
     5735
     5736        return (*recIter).toInt();
     5737    }
     5738
     5739    return 0;
     5740};
     5741
    56145742void TV::EmbedOutput(WId wid, int x, int y, int w, int h)
    56155743{
    56165744    embedWinID = wid;
     
    64286556    infoMap["channum"]     = browsechannum;
    64296557    infoMap["chanid"]      = browsechanid;
    64306558   
    6431     GetNextProgram(activerecorder, direction, infoMap);
     6559    if (browsealltuners)
     6560        GetNextProgramAnyTuner(direction, infoMap);
     6561    else
     6562        GetNextProgram(activerecorder, direction, infoMap);
    64326563   
    64336564    browsechannum = infoMap["channum"];
    64346565    browsechanid  = infoMap["chanid"];
     
    64466577    if (program_info)
    64476578        program_info->ToMap(infoMap);
    64486579
     6580    QString tunerstatus = GetProgramTunerStatus(infoMap);
     6581   
    64496582    GetOSD()->ClearAllText("browse_info");
     6583    GetOSD()->SetFontFunction("browse_info", "tuner", tunerstatus);
    64506584    GetOSD()->SetText("browse_info", infoMap, -1);
    64516585
    64526586    delete program_info;
     
    64936627            ProgramInfo::GetProgramAtDateTime(browsechanid, startts);
    64946628        program_info->ToggleRecord();
    64956629        program_info->ToMap(infoMap);
     6630        QString tunerstatus = GetProgramTunerStatus(infoMap);
    64966631
    64976632        if (GetOSD())
    64986633        {
    64996634            GetOSD()->ClearAllText("browse_info");
     6635            GetOSD()->SetFontFunction("browse_info", "tuner", tunerstatus);
    65006636            GetOSD()->SetText("browse_info", infoMap, -1);
    65016637
    65026638            if (activenvp == nvp)
     
    65436679
    65446680void TV::BrowseChannel(const QString &chan)
    65456681{
    6546     if (!activerecorder->CheckChannel(chan))
     6682    if (browsealltuners)
     6683    {
     6684        if (!GetChanIDAnyTuner(chan))
     6685            return;
     6686    }
     6687    else if (!activerecorder->CheckChannel(chan))
    65476688        return;
    65486689
    65496690    browsechannum = chan;
  • programs/mythfrontend/globalsettings.cpp

     
    17921792    return gc;
    17931793}
    17941794
     1795static HostCheckBox *BrowseAllTuners()
     1796{
     1797    HostCheckBox *gc = new HostCheckBox("BrowseAllTuners");
     1798    gc->setLabel(QObject::tr("Browse channels from all tuners"));
     1799    gc->setValue(true);
     1800    gc->setHelpText(QObject::tr("By default, browse mode only shows channels "
     1801                    "on the currently active tuner. If enabled, browse mode "
     1802                    "will shows all channels, no matter what tuner they "
     1803                    "exist on."));
     1804    return gc;
     1805}
     1806
    17951807static HostCheckBox *AggressiveBuffer()
    17961808{
    17971809    HostCheckBox *gc = new HostCheckBox("AggressiveSoundcardBuffer");
     
    45624574    osd->addChild(CCBackground());
    45634575    osd->addChild(DefaultCCMode());
    45644576    osd->addChild(PersistentBrowseMode());
     4577    osd->addChild(BrowseAllTuners());
    45654578    addChild(osd);
    45664579
    45674580    addChild(OSDCC708Settings());