Ticket #1966: 1966-sort-only.patch

File 1966-sort-only.patch, 48.1 KB (added by danielk, 18 years ago)

Version that only changes the channel sorting

  • libs/libmythtv/previouslist.cpp

     
    4040    hourFormat = gContext->GetSetting("TimeFormat");
    4141    timeFormat = gContext->GetSetting("ShortDateFormat") + " " + hourFormat;
    4242    fullDateFormat = dayFormat + " " + hourFormat;
    43     channelOrdering = gContext->GetSetting("ChannelOrdering", "channum + 0");
    4443    channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>");
    4544
    4645    allowEvents = true;
  • libs/libmythtv/channelutil.h

     
    88
    99class NetworkInformationTable;
    1010
     11class DBChannel
     12{
     13  public:
     14    DBChannel(const QString &_channum, const QString &_callsign,
     15              uint _chanid, uint _major_chan, uint _minor_chan,
     16              uint _favorite,
     17              const QString &_name, const QString &_icon) :
     18        channum(_channum), callsign(_callsign), chanid(_chanid),
     19        major_chan(_major_chan), minor_chan(_minor_chan),
     20        favorite(_favorite),
     21        name(_name), icon(_icon) {}
     22
     23    bool operator == (uint _chanid) const
     24        { return chanid == _chanid; }
     25
     26    QString channum;
     27    QString callsign;
     28    uint    chanid;
     29    uint    major_chan;
     30    uint    minor_chan;
     31    uint    favorite;
     32    QString name;
     33    QString icon;
     34};
     35typedef vector<DBChannel> DBChanList;
     36
     37
    1138/** \class ChannelUtil
    1239 *  \brief Collection of helper utilities for channel DB use
    1340 */
     
    97124    static QString GetVideoFilters(uint sourceid, const QString &channum)
    98125        { return GetChannelValueStr("videofilters", sourceid, channum); }
    99126
    100     static QString GetNextChannel(uint           cardid,
    101                                   const QString &inputname,
    102                                   const QString &channum,
    103                                   int            direction,
    104                                   QString       &channelorder,
    105                                   uint          &chanid);
     127    static DBChanList GetChannels(uint srcid, bool vis_only, QString grp="");
     128    static void    SortChannels(DBChanList &list, const QString &order);
    106129
    107     static uint    GetNextChannel(uint           cardid,
    108                                   const QString &inputname,
    109                                   const QString &channum,
    110                                   int            direction,
    111                                   QString       &channelorder)
    112     {
    113         uint chanid = 0;
    114         GetNextChannel(cardid,    inputname,    channum,
    115                        direction, channelorder, chanid);
    116         return chanid;
    117     }
     130    static uint    GetNextChannel(const DBChanList &sorted,
     131                                  uint old_chanid, int direction);
    118132
    119133    static QString GetChannelValueStr(const QString &channel_field,
    120134                                      uint           sourceid,
  • libs/libmythtv/proglist.cpp

     
    2323#include "mythcontext.h"
    2424#include "remoteutil.h"
    2525#include "mythdbcon.h"
     26#include "channelutil.h"
    2627
    2728ProgLister::ProgLister(ProgListType pltype,
    2829                       const QString &view, const QString &from,
     
    3940    hourFormat = gContext->GetSetting("TimeFormat");
    4041    timeFormat = gContext->GetSetting("ShortDateFormat") + " " + hourFormat;
    4142    fullDateFormat = dayFormat + " " + hourFormat;
    42     channelOrdering = gContext->GetSetting("ChannelOrdering", "channum + 0");
     43    channelOrdering = gContext->GetSetting("ChannelOrdering", "channum");
    4344    channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>");
    4445
    4546    switch (pltype)
     
    977978    stationList.clear();
    978979    stationList << "";
    979980
    980     query.prepare(QString("SELECT channel.chanid, channel.channum, "
    981                   "channel.callsign, channel.name FROM channel "
    982                   "WHERE channel.visible = 1 "
    983                   "GROUP BY callsign "
    984                   "ORDER BY ") + channelOrdering + ";");
    985     query.exec();
     981    DBChanList channels = ChannelUtil::GetChannels(0, false, "callsign");
     982    ChannelUtil::SortChannels(channels, channelOrdering);
    986983
    987     if (query.isActive() && query.size())
     984    for (uint i = 0; i < channels.size(); i++)
    988985    {
    989         while (query.next())
    990         {
    991             QString chanid = query.value(0).toString();
    992             QString channum = query.value(1).toString();
    993             QString chansign = QString::fromUtf8(query.value(2).toString());
    994             QString channame = QString::fromUtf8(query.value(3).toString());
     986        QString chantext = QDeepCopy<QString>(channelFormat);
     987        chantext
     988            .replace("<num>",  channels[i].channum)
     989            .replace("<sign>", channels[i].callsign)
     990            .replace("<name>", channels[i].name);
    995991
    996             QString chantext = channelFormat;
    997             chantext.replace("<num>", channum)
    998                 .replace("<sign>", chansign)
    999                 .replace("<name>", channame);
     992        viewList << QString::number(channels[i].chanid);
     993        viewTextList << chantext;
    1000994
    1001             viewList << chanid;
    1002             viewTextList << chantext;
    1003 
    1004             powerStation->insertItem(chantext);
    1005             stationList << chansign;
    1006             if (chansign == field[5])
    1007                 powerStation->setCurrentItem(powerStation->count() - 1);
    1008         }
     995        powerStation->insertItem(chantext);
     996        stationList << channels[i].callsign;
     997        if (channels[i].callsign == field[5])
     998            powerStation->setCurrentItem(powerStation->count() - 1);
    1009999    }
     1000
    10101001    powerPopup->addWidget(powerStation);
    10111002
    10121003    powerOkButton = new MythPushButton(powerPopup);
     
    11851176
    11861177    if (type == plChannel) // list by channel
    11871178    {
    1188         MSqlQuery query(MSqlQuery::InitCon());
    1189         query.prepare(QString("SELECT channel.chanid, channel.channum, "
    1190                       "channel.callsign, channel.name FROM channel "
    1191                       "WHERE channel.visible = 1 "
    1192                       "GROUP BY channum, callsign "
    1193                       "ORDER BY ") + channelOrdering + ";");
    1194         query.exec();
     1179        DBChanList channels = ChannelUtil::GetChannels(0, false, "callsign");
     1180        ChannelUtil::SortChannels(channels, channelOrdering);
    11951181
    1196         if (query.isActive() && query.size())
     1182        for (uint i = 0; i < channels.size(); i++)
    11971183        {
    1198             while (query.next())
    1199             {
    1200                 QString chanid = query.value(0).toString();
    1201                 QString channum = query.value(1).toString();
    1202                 QString chansign = QString::fromUtf8(query.value(2).toString());
    1203                 QString channame = QString::fromUtf8(query.value(3).toString());
     1184            QString chantext = QDeepCopy<QString>(channelFormat);
     1185            chantext
     1186                .replace("<num>",  channels[i].channum)
     1187                .replace("<sign>", channels[i].callsign)
     1188                .replace("<name>", channels[i].name);
    12041189
    1205                 QString chantext = channelFormat;
    1206                 chantext.replace("<num>", channum)
    1207                     .replace("<sign>", chansign)
    1208                     .replace("<name>", channame);
    1209 
    1210                 viewList << chanid;
    1211                 viewTextList << chantext;
    1212             }
     1190            viewList << QString::number(channels[i].chanid);
     1191            viewTextList << chantext;
    12131192        }
    1214         if (view != "")
     1193
     1194        if (!view.isEmpty())
    12151195            curView = viewList.findIndex(view);
    12161196    }
    12171197    else if (type == plCategory) // list by category
  • libs/libmythtv/guidegrid.cpp

     
    3131#include "customedit.h"
    3232#include "util.h"
    3333#include "remoteutil.h"
     34#include "channelutil.h"
    3435
    3536bool RunProgramGuide(uint &chanid, QString &channum,
    3637                     bool thread, TV *player,
     
    179180            container->SetDrawFontShadow(false);
    180181    }
    181182
    182     channelOrdering = gContext->GetSetting("ChannelOrdering", "channum + 0");
     183    channelOrdering = gContext->GetSetting("ChannelOrdering", "channum");
    183184    dateformat = gContext->GetSetting("ShortDateFormat", "ddd d");
    184185    unknownTitle = gContext->GetSetting("UnknownTitle", "Unknown");
    185186    unknownCategory = gContext->GetSetting("UnknownCategory", "Unknown");
     
    559560
    560561void GuideGrid::fillChannelInfos(bool gotostartchannel)
    561562{
    562     MSqlQuery query(MSqlQuery::InitCon());
    563 
    564563    m_channelInfos.clear();
    565564
     565    DBChanList channels = ChannelUtil::GetChannels(0, true, "callsign");
     566    ChannelUtil::SortChannels(channels, channelOrdering);
     567
    566568    if (showFavorites)
    567569    {
    568         query.prepare(
    569             "SELECT channel.channum, channel.callsign, "
    570             "       channel.icon,    channel.chanid, "
    571             "       favorites.favid, channel.name "
    572             "FROM videosource, cardinput, favorites, channel "
    573             "WHERE channel.chanid       = favorites.chanid     AND "
    574             "      visible              = 1                    AND "
    575             "      channel.sourceid     = videosource.sourceid AND "
    576             "      videosource.sourceid = cardinput.sourceid "
    577             "GROUP BY channum, callsign "
    578             "ORDER BY " + channelOrdering);
    579 
    580         if (query.exec() && query.isActive())
    581             showFavorites = query.size();
    582         else
    583             MythContext::DBError("fillChannelInfos -- favorites", query);
    584     }
    585 
    586     if (!showFavorites)
    587     {
    588         query.prepare(
    589             "SELECT channel.channum, channel.callsign, "
    590             "       channel.icon,    channel.chanid, "
    591             "       favorites.favid, channel.name "
    592             "FROM videosource, cardinput, "
    593             "       channel LEFT JOIN favorites "
    594             "       ON favorites.chanid = channel.chanid "
    595             "WHERE visible              = 1                    AND "
    596             "      channel.sourceid     = videosource.sourceid AND "
    597             "      videosource.sourceid = cardinput.sourceid "
    598             "GROUP BY channum, callsign "
    599             "ORDER BY " + channelOrdering);
    600 
    601         if (!query.exec() || !query.isActive())
     570        DBChanList tmp;
     571        for (uint i = 0; i < channels.size(); i++)
    602572        {
    603             MythContext::DBError("fillChannelInfos -- all connected", query);
    604             return;
     573            if (channels[i].favorite)
     574                tmp.push_back(channels[i]);
    605575        }
     576
     577        if (!tmp.empty())
     578            channels = tmp;
    606579    }
    607  
     580
    608581    bool startingset = false;
    609     while (query.next())
     582    for (uint i = 0; i < channels.size(); i++)
    610583    {
    611584        ChannelInfo val;
    612 
    613         val.chanstr  = query.value(0).toString();
    614         val.chanid   = query.value(3).toInt();
    615 
    616         // validate the channum and chanid, skip channel if these are invalid
    617         if (val.chanstr == "" || !val.chanid)
    618             continue;
    619 
    620         // fill in the rest of the data...
    621         val.callsign = QString::fromUtf8(query.value(1).toString());
    622         val.iconpath = query.value(2).toString();
    623         val.favid    = query.value(4).toInt();
    624         val.channame = QString::fromUtf8(query.value(5).toString());
     585        val.chanstr  = channels[i].channum;
     586        val.chanid   = channels[i].chanid;
     587        val.callsign = channels[i].callsign;
     588        val.favid    = channels[i].favorite;
     589        val.channame = channels[i].name;
     590        val.iconpath = channels[i].icon;
    625591        val.iconload = false;
    626592
    627593        // set starting channel index if it hasn't been set
     
    633599            m_currentStartChannel = m_channelInfos.size();
    634600            startingset = true;
    635601        }
    636                
     602
    637603        // add the new channel to the list
    638604        m_channelInfos.push_back(val);
    639605    }
     606 
    640607    // set starting channel index to 0 if it hasn't been set
    641608    if (gotostartchannel)
    642609        m_currentStartChannel = (startingset) ? m_currentStartChannel : 0;
  • libs/libmythtv/dbcheck.cpp

     
    1010#include "mythdbcon.h"
    1111
    1212/// This is the DB schema version expected by the running MythTV instance.
    13 const QString currentDatabaseVersion = "1149";
     13const QString currentDatabaseVersion = "1150";
    1414
    1515static bool UpdateDBVersionNumber(const QString &newnumber);
    1616static bool performActualUpdate(const QString updates[], QString version,
     
    23652365            return false;
    23662366    }
    23672367
     2368    if (dbver == "1149")
     2369    {
     2370        const QString updates[] = {
     2371"UPDATE settings SET data='channum' WHERE value='ChannelOrdering' AND data!='callsign';",
     2372""
     2373};
     2374
     2375        if (!performActualUpdate(updates, "1150", dbver))
     2376            return false;
     2377    }
     2378
    23682379//"ALTER TABLE capturecard DROP COLUMN dvb_recordts;" in 0.21
    23692380//"ALTER TABLE capturecard DROP COLUMN dvb_hw_decoder;" in 0.21
    23702381//"ALTER TABLE cardinput DROP COLUMN  preference;" in 0.22
  • libs/libmythtv/channelbase.h

     
    1010#include <qsqldatabase.h>
    1111
    1212// MythTV headers
    13 
     13#include "channelutil.h"
    1414#include "frequencies.h"
    1515#include "tv.h"
    1616
     
    3131
    3232    InputBase(QString _name,            QString _startChanNum,
    3333              QString _tuneToChannel,   QString _externalChanger,
    34               uint    _sourceid,        uint    _cardid) :
     34              uint    _sourceid,        uint    _cardid,
     35              const DBChanList &_channels) :
    3536        name(_name),                    startChanNum(_startChanNum),
    3637        tuneToChannel(_tuneToChannel),  externalChanger(_externalChanger),
    3738        sourceid(_sourceid),            cardid(_cardid),
     39        channels(_channels),
    3840        inputNumV4L(-1),
    3941        videoModeV4L1(0),               videoModeV4L2(0) {}
    4042
     
    4749    QString externalChanger; // for using a cable box...
    4850    uint    sourceid;        // associated channel listings source
    4951    uint    cardid;          // input card id
     52    DBChanList channels;
    5053    int     inputNumV4L;
    5154    int     videoModeV4L1;
    5255    int     videoModeV4L2;
     
    8386    virtual int GetFd(void) const { return -1; };
    8487
    8588    // Gets
     89    virtual uint GetNextChannel(uint chanid, int direction) const;
     90    virtual uint GetNextChannel(const QString &channum, int direction) const;
    8691    virtual int GetInputByName(const QString &input) const;
    8792    virtual QString GetInputByNum(int capchannel) const;
    8893    virtual QString GetCurrentName(void) const
     
    101106        { return inputs[GetCurrentInputNum()]->sourceid; }
    102107    virtual uint GetInputCardID(int inputNum) const;
    103108    virtual QStringList GetConnectedInputs(void) const;
    104     virtual QString GetOrdering(void) const
    105         { return channelorder; }
    106109    /// \brief Returns true iff commercial detection is not required
    107110    //         on current channel, for BBC, CBC, etc.
    108111    bool IsCommercialFree(void) const { return commfree; }
     
    110113    virtual QString GetDevice(void) const { return ""; }
    111114
    112115    // Sets
    113     virtual void SetChannelOrdering(const QString &chanorder)
    114         { channelorder = chanorder; }
    115116    virtual void Renumber(uint srcid, const QString &oldChanNum,
    116117                          const QString &newChanNum);
    117118
     
    177178    static void StoreInputChannels(const InputMap&);
    178179
    179180    TVRec   *pParent;
    180     QString  channelorder;
    181181    QString  curchannelname;
    182182    int      currentInputID;
    183183    bool     commfree;
  • libs/libmythtv/previouslist.h

     
    4848    QString hourFormat;
    4949    QString timeFormat;
    5050    QString fullDateFormat;
    51     QString channelOrdering;
    5251    QString channelFormat;
    5352
    5453    RecSearchType searchtype;
  • libs/libmythtv/channelbase.cpp

     
    3232
    3333ChannelBase::ChannelBase(TVRec *parent)
    3434    :
    35     pParent(parent), channelorder("channum + 0"), curchannelname(""),
     35    pParent(parent), curchannelname(""),
    3636    currentInputID(-1), commfree(false), cardid(0),
    3737    currentATSCMajorChannel(-1), currentATSCMinorChannel(-1),
    3838    currentProgramNum(-1), currentOriginalNetworkID(-1),
     
    4646
    4747bool ChannelBase::SetChannelByDirection(ChannelChangeDirection dir)
    4848{
    49     bool fTune = false;
    50     uint chanid;
    51     QString start, nextchan;
    52     start = nextchan = ChannelUtil::GetNextChannel(
    53         GetCardID(), GetCurrentInput(), GetCurrentName(),
    54         dir,         channelorder,      chanid);
     49    uint startchanid = GetNextChannel(GetCurrentName(), dir);
     50    uint nextchanid  = startchanid;
    5551
     52    bool ok = false;
    5653    do
    5754    {
    58        fTune = SetChannelByString(nextchan);
    59        if (!fTune)
    60        {
    61            nextchan = ChannelUtil::GetNextChannel(
    62                GetCardID(), GetCurrentInput(), GetCurrentName(),
    63                dir,         channelorder,      chanid);
    64        }
     55        if (!(ok = SetChannelByString(ChannelUtil::GetChanNum(nextchanid))))
     56            nextchanid = GetNextChannel(nextchanid, dir);
    6557    }
    66     while (!fTune && nextchan != start);
     58    while (!ok && (nextchanid != startchanid));
    6759
    68     return fTune;
     60    return ok;
    6961}
    7062
     63uint ChannelBase::GetNextChannel(uint chanid, int direction) const
     64{
     65    InputMap::const_iterator it = inputs.find(currentInputID);
     66    if (it == inputs.end())
     67        return 0;
     68
     69    return ChannelUtil::GetNextChannel((*it)->channels, chanid, direction);
     70}
     71
     72uint ChannelBase::GetNextChannel(const QString &channum, int direction) const
     73{
     74    InputMap::const_iterator it = inputs.find(currentInputID);
     75    if (it == inputs.end())
     76        return 0;
     77
     78    uint chanid = ChannelUtil::GetChanID((*it)->sourceid, channum);
     79    return GetNextChannel(chanid, direction);
     80}
     81
    7182int ChannelBase::GetNextInputNum(void) const
    7283{
    7384    // Exit early if inputs don't exist..
     
    486497        uint inputcardid = query.value(6).toUInt();
    487498        inputcardid = (inputcardid) ? inputcardid : cardid;
    488499
     500        uint sourceid = query.value(5).toUInt();
     501        DBChanList channels = ChannelUtil::GetChannels(sourceid, false);
     502
     503        QString order = gContext->GetSetting("ChannelOrdering", "channum");
     504        ChannelUtil::SortChannels(channels, order);
     505
    489506        inputs[query.value(0).toUInt()] = new InputBase(
    490507            query.value(1).toString(), query.value(2).toString(),
    491508            query.value(3).toString(), query.value(4).toString(),
    492             query.value(5).toUInt(),   inputcardid);
     509            sourceid, inputcardid, channels);
    493510    }
    494511
    495512    // Set initial input to first connected input
  • libs/libmythtv/channelutil.cpp

     
    796796    return query.exec();
    797797}
    798798
    799 QString ChannelUtil::GetNextChannel(
    800     uint           cardid,       const QString &inputname,
    801     const QString &channum,      int            direction,
    802     QString       &channelorder, uint          &chanid)
    803 {
    804     chanid = 0;
    805     bool isNum = true;
    806     channum.toULong(&isNum);
    807 
    808     if (!isNum && channelorder == "channum + 0")
    809     {
    810         bool has_atsc = GetChannelValueInt("atscsrcid", cardid,
    811                                            inputname, channum);
    812         channelorder = (has_atsc) ? "atscsrcid" : "channum";
    813         if (!has_atsc)
    814         {
    815             QString msg = QString(
    816                 "Your channel ordering method \"channel number (numeric)\"\n"
    817                 "\t\t\twill not work with channels like: '%1' \n"
    818                 "\t\t\tConsider switching to order by \"database order\"  \n"
    819                 "\t\t\tor \"channel number (alpha)\" in the general       \n"
    820                 "\t\t\tsettings section of the frontend setup             \n"
    821                 "\t\t\tSwitched to '%2' order.")
    822                 .arg(channum).arg(channelorder);
    823             VERBOSE(VB_IMPORTANT, LOC + msg);
    824         }
    825     }
    826 
    827     MSqlQuery query(MSqlQuery::InitCon());
    828 
    829     QString querystr = QString(
    830         "SELECT %1 "
    831         "FROM channel,capturecard,cardinput "
    832         "WHERE channel.channum      = :CHANNUM           AND "
    833         "      channel.sourceid     = cardinput.sourceid AND "
    834         "      cardinput.cardid     = capturecard.cardid AND "
    835         "      capturecard.cardid   = :CARDID            AND "
    836         "      capturecard.hostname = :HOSTNAME").arg(channelorder);
    837     query.prepare(querystr);
    838     query.bindValue(":CHANNUM",  channum);
    839     query.bindValue(":CARDID",   cardid);
    840     query.bindValue(":HOSTNAME", gContext->GetHostName());
    841 
    842     QString id = QString::null;
    843 
    844     if (!query.exec() || !query.isActive())
    845         MythContext::DBError("getnextchannel 1", query);
    846     else if (query.next())
    847         id = query.value(0).toString();
    848 
    849     if (id.isEmpty())
    850     {
    851         QString msg = QString(
    852             "Channel: '%1' was not found in the database.\n"
    853             "\t\t\tMost likely, the default channel set for this input\n"
    854             "\t\t\tcardid %2, input '%3'\n"
    855             "\t\t\tin setup is wrong\n")
    856             .arg(channum).arg(cardid).arg(inputname);
    857         VERBOSE(VB_IMPORTANT, LOC + msg);
    858 
    859         querystr = QString(
    860             "SELECT %1 "
    861             "FROM channel, capturecard, cardinput "
    862             "WHERE channel.sourceid     = cardinput.sourceid AND "
    863             "      cardinput.cardid     = capturecard.cardid AND "
    864             "      capturecard.cardid   = :CARDID            AND "
    865             "      capturecard.hostname = :HOSTNAME "
    866             "ORDER BY %2 "
    867             "LIMIT 1").arg(channelorder).arg(channelorder);
    868         query.prepare(querystr);
    869         query.bindValue(":CARDID",   cardid);
    870         query.bindValue(":HOSTNAME", gContext->GetHostName());
    871 
    872         if (!query.exec() || !query.isActive())
    873             MythContext::DBError("getnextchannel 2", query);
    874         else if (query.next())
    875             id = query.value(0).toString();
    876     }
    877 
    878     if (id.isEmpty())
    879     {
    880         VERBOSE(VB_IMPORTANT, LOC_ERR +
    881                 "Couldn't find any channels in the database,\n"
    882                 "\t\t\tplease make sure your inputs are associated\n"
    883                 "\t\t\tproperly with your cards.");
    884         return "";
    885     }
    886 
    887     // Now let's try finding the next channel in the desired direction
    888     QString comp = ">";
    889     QString ordering = "";
    890     QString fromfavorites = "";
    891     QString wherefavorites = "";
    892 
    893     if (direction == CHANNEL_DIRECTION_DOWN)
    894     {
    895         comp = "<";
    896         ordering = " DESC ";
    897     }
    898     else if (direction == CHANNEL_DIRECTION_FAVORITE)
    899     {
    900         fromfavorites = ",favorites";
    901         wherefavorites = "AND favorites.chanid = channel.chanid";
    902     }
    903     else if (direction == CHANNEL_DIRECTION_SAME)
    904     {
    905         comp = "=";
    906     }
    907 
    908     QString wherepart = QString(
    909         "cardinput.cardid     = capturecard.cardid AND "
    910         "capturecard.cardid   = :CARDID            AND "
    911         "capturecard.hostname = :HOSTNAME          AND "
    912         "channel.visible      = 1                  AND "
    913         "cardinput.sourceid = channel.sourceid ");
    914 
    915     querystr = QString(
    916         "SELECT channel.channum, channel.chanid "
    917         "FROM channel, capturecard, cardinput%1 "
    918         "WHERE channel.%2 %3 :ID %4 AND "
    919         "      %5 "
    920         "ORDER BY channel.%6 %7 "
    921         "LIMIT 1")
    922         .arg(fromfavorites).arg(channelorder)
    923         .arg(comp).arg(wherefavorites)
    924         .arg(wherepart).arg(channelorder).arg(ordering);
    925 
    926     query.prepare(querystr);
    927     query.bindValue(":CARDID",   cardid);
    928     query.bindValue(":HOSTNAME", gContext->GetHostName());
    929     query.bindValue(":ID",       id);
    930 
    931     if (!query.exec() || !query.isActive())
    932     {
    933         MythContext::DBError("getnextchannel 3", query);
    934     }
    935     else if (query.next())
    936     {
    937         chanid = query.value(1).toUInt();
    938         return query.value(0).toString();
    939     }
    940     else
    941     {
    942         // Couldn't find the channel going in the desired direction,
    943         // so loop around and find it on the flip side...
    944         comp = "<";
    945         if (direction == CHANNEL_DIRECTION_DOWN)
    946             comp = ">";
    947 
    948         // again, %9 is the limit for this
    949         querystr = QString(
    950             "SELECT channel.channum, channel.chanid "
    951             "FROM channel, capturecard, cardinput%1 "
    952             "WHERE channel.%2 %3 :ID %4 AND "
    953             "      %5 "
    954             "ORDER BY channel.%6 %7 "
    955             "LIMIT 1")
    956             .arg(fromfavorites).arg(channelorder)
    957             .arg(comp).arg(wherefavorites)
    958             .arg(wherepart).arg(channelorder).arg(ordering);
    959 
    960         query.prepare(querystr);
    961         query.bindValue(":CARDID",   cardid);
    962         query.bindValue(":HOSTNAME", gContext->GetHostName());
    963         query.bindValue(":ID",       id);
    964 
    965         if (!query.exec() || !query.isActive())
    966         {
    967             MythContext::DBError("getnextchannel", query);
    968         }
    969         else if (query.next())
    970         {
    971             chanid = query.value(1).toUInt();
    972             return query.value(0).toString();
    973         }
    974         else
    975         {
    976             VERBOSE(VB_IMPORTANT, "getnextchannel, query failed: "<<querystr);
    977         }
    978     }
    979 
    980     // just stay on same channel
    981     chanid = max(GetChannelValueInt("chanid", cardid, inputname, channum), 0);
    982     return channum;
    983 }
    984 
    985799int ChannelUtil::GetChanID(int mplexid,       int service_transport_id,
    986800                           int major_channel, int minor_channel,
    987801                           int program_number)
     
    12441058        query.bindValue(":CHANNUM",   chan_num);
    12451059    if (freqid > 0)
    12461060        query.bindValue(":FREQID",    freqid);
    1247     if (atsc_major_channel > 0)
     1061    if (atsc_minor_channel > 0)
    12481062        query.bindValue(":TVFORMAT",  "ATSC");
    12491063
    12501064    if (!query.exec() || !query.isActive())
     
    13211135
    13221136    return query.value(0).toString();
    13231137}
     1138
     1139DBChanList ChannelUtil::GetChannels(uint sourceid, bool vis_only, QString grp)
     1140{
     1141    DBChanList list;
     1142    QMap<uint,uint> favorites;
     1143    MSqlQuery query(MSqlQuery::InitCon());
     1144    query.prepare(
     1145        "SELECT chanid, favid "
     1146        "FROM favorites");
     1147    if (!query.exec() || !query.isActive())
     1148        MythContext::DBError("get channels -- favorites", query);
     1149    else
     1150    {
     1151        while (query.next())
     1152            favorites[query.value(0).toUInt()] = query.value(1).toUInt();
     1153    }
     1154
     1155    QString qstr =
     1156        "SELECT channum, callsign, chanid, "
     1157        "       atscsrcid/256, atscsrcid%255, "
     1158        "       name, icon "
     1159        "FROM channel ";
     1160
     1161    if (sourceid)
     1162        qstr += QString("WHERE sourceid='%1' ").arg(sourceid);
     1163    else
     1164        qstr += ",cardinput,capturecard "
     1165            "WHERE cardinput.sourceid = channel.sourceid   AND "
     1166            "      cardinput.cardid   = capturecard.cardid     ";
     1167
     1168    if (vis_only)
     1169        qstr += "AND visible=1 ";
     1170
     1171    if (!grp.isEmpty())
     1172        qstr += QString("GROUP BY %1 ").arg(grp);
     1173
     1174    query.prepare(qstr);
     1175    if (!query.exec() || !query.isActive())
     1176    {
     1177        MythContext::DBError("get channels -- sourceid", query);
     1178        return list;
     1179    }
     1180
     1181    while (query.next())
     1182    {
     1183        if (query.value(0).toString().isEmpty() || !query.value(2).toUInt())
     1184            continue; // skip if channum blank, or chanid empty
     1185
     1186        DBChannel chan(
     1187            query.value(0).toString(),                    /* channum    */
     1188            QString::fromUtf8(query.value(1).toString()), /* callsign   */
     1189            query.value(2).toUInt(),                      /* chanid     */
     1190            query.value(3).toUInt(),                      /* ATSC major */
     1191            query.value(4).toUInt(),                      /* ATSC minor */
     1192            favorites[query.value(2).toUInt()],           /* favid      */
     1193            QString::fromUtf8(query.value(5).toString()), /* name       */
     1194            query.value(6).toString());                   /* icon       */
     1195
     1196        list.push_back(chan);
     1197    }
     1198
     1199    return list;
     1200}
     1201
     1202inline bool lt_callsign(const DBChannel &a, const DBChannel &b)
     1203{
     1204    return QString::localeAwareCompare(a.callsign, b.callsign) < 0;
     1205}
     1206
     1207inline bool lt_smart(const DBChannel &a, const DBChannel &b)
     1208{
     1209    int cmp = 0;
     1210    if (a.major_chan && b.major_chan)
     1211    {
     1212        if ((cmp = a.major_chan - b.major_chan))
     1213            return cmp < 0;
     1214
     1215        if ((cmp = a.minor_chan - b.minor_chan))
     1216            return cmp < 0;
     1217    }
     1218
     1219    bool isIntA, isIntB;
     1220    int a_int = a.channum.toUInt(&isIntA);
     1221    int b_int = a.channum.toUInt(&isIntB);
     1222    if (isIntA && isIntB)
     1223    {
     1224        cmp = a_int - b_int;
     1225        if (cmp)
     1226            return cmp < 0;
     1227    }
     1228    else
     1229    {
     1230        return QString::localeAwareCompare(a.channum, b.channum) < 0;
     1231    }
     1232
     1233    return lt_callsign(a,b);
     1234}
     1235
     1236void ChannelUtil::SortChannels(DBChanList &list, const QString &order)
     1237{
     1238    if (order.lower() == "callsign")
     1239        sort(list.begin(), list.end(), lt_callsign);
     1240    else /* if (sortorder == "channum") */
     1241        sort(list.begin(), list.end(), lt_smart);
     1242}
     1243
     1244uint ChannelUtil::GetNextChannel(const DBChanList &sorted,
     1245                                 uint old_chanid, int direction)
     1246{
     1247    DBChanList::const_iterator it =
     1248        find(sorted.begin(), sorted.end(), old_chanid);
     1249
     1250    if (it == sorted.end())
     1251        it = sorted.begin(); // not in list, pretend we are on first channel
     1252
     1253    if (it == sorted.end())
     1254        return 0; // no channels..
     1255
     1256    if (CHANNEL_DIRECTION_DOWN == direction)
     1257    {
     1258        if (it == sorted.begin())
     1259            return sorted.rbegin()->chanid;
     1260        it--;
     1261    }
     1262    else if (CHANNEL_DIRECTION_UP == direction)
     1263    {
     1264        it++;
     1265        if (it == sorted.end())
     1266            it = sorted.begin();
     1267    }
     1268    else if (CHANNEL_DIRECTION_FAVORITE == direction)
     1269    {
     1270        DBChanList::const_iterator it_orig = it;
     1271        for (;;++it)
     1272        {
     1273            if (it == sorted.end())
     1274                it = sorted.begin();
     1275
     1276            if (it == it_orig)
     1277            {
     1278                if (!it->favorite)
     1279                    ++it;
     1280                break; // no (other?) favorites
     1281            }
     1282
     1283            if (it->favorite)
     1284                break; // found next favorite
     1285        }
     1286    }
     1287
     1288    return it->chanid;
     1289}
  • libs/libmythtv/videosource.cpp

     
    2929#include "scanwizard.h"
    3030#include "cardutil.h"
    3131#include "sourceutil.h"
     32#include "channelutil.h"
    3233#include "frequencies.h"
    3334
    3435#ifdef USING_DVB
     
    16141615    else if (query.next())
    16151616        startChan = query.value(0).toString();
    16161617
    1617     // Get the existing channels on the connected source
    1618     query.prepare(
    1619         "SELECT channum "
    1620         "FROM channel "
    1621         "WHERE sourceid = :SOURCEID "
    1622         "ORDER BY atscsrcid, channum");
    1623     query.bindValue(":SOURCEID", sourceid.toUInt());
     1618    DBChanList channels = ChannelUtil::GetChannels(sourceid.toUInt(), false);
    16241619
    1625     QString nnsc = startChan.isEmpty() ? "" : startChan;
    1626     if (!query.exec() || !query.isActive())
     1620    if (channels.empty())
    16271621    {
    1628         addSelection(tr("DB Error, see console"), nnsc);
    1629         MythContext::DBError("SetSourceID -- get channels", query);
     1622        addSelection(tr("Please add channels to this source"),
     1623                     startChan.isEmpty() ? "" : startChan);
     1624        return;
    16301625    }
    1631     else if (query.size() > 0)
     1626
     1627    // If there are channels sort them, then add them
     1628    // (selecting the old start channel if it is there).
     1629    QString order = gContext->GetSetting("ChannelOrdering", "channum");
     1630    ChannelUtil::SortChannels(channels, order);
     1631    for (uint i = 0; i < channels.size(); i++)
    16321632    {
    1633         // If there are channels add them, and
    1634         // highlight the old start channel
    1635         while (query.next())
    1636         {
    1637             const QString channum = query.value(0).toString();
    1638             addSelection(channum, channum, channum == startChan);
    1639         }
     1633        const QString channum = channels[i].channum;
     1634        addSelection(channum, channum, channum == startChan);
    16401635    }
    1641     else
    1642     {
    1643         addSelection(tr("Please add channels to this source"), nnsc);
    1644     }
    16451636}
    16461637
    16471638class InputPriority: public SpinBoxSetting, public CISetting {
  • libs/libmythtv/tv_rec.cpp

     
    10691069        channel->SetChannelByString(startchannel);
    10701070    else
    10711071        channel->SwitchToInput(inputname, startchannel);
    1072 
    1073     // Set channel ordering, and check validity...
    1074     QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");
    1075     ChannelUtil::GetNextChannel(cardid, inputname, startchannel,
    1076                                 BROWSE_SAME, chanorder);
    1077     channel->SetChannelOrdering(chanorder);
    10781072}
    10791073
    10801074void TVRec::CloseChannel(void)
     
    28152809{
    28162810    QString compare     = "<=";
    28172811    QString sortorder   = "desc";
    2818     QString input       = channel->GetCurrentInput();
    2819     QString order       = channel->GetOrdering();
    2820     int     chanid      = -1;
     2812    uint     chanid     = 0;
    28212813
    28222814    if (BROWSE_SAME == direction)
    2823         chanid = ChannelUtil::GetNextChannel(
    2824             cardid, input, channum, CHANNEL_DIRECTION_SAME, order);
     2815        chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME);
    28252816    else if (BROWSE_UP == direction)
    2826         chanid = ChannelUtil::GetNextChannel(
    2827             cardid, input, channum, CHANNEL_DIRECTION_UP, order);
     2817        chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_UP);
    28282818    else if (BROWSE_DOWN == direction)
    2829         chanid = ChannelUtil::GetNextChannel(
    2830             cardid, input, channum, CHANNEL_DIRECTION_DOWN, order);
     2819        chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_DOWN);
    28312820    else if (BROWSE_FAVORITE == direction)
    2832         chanid = ChannelUtil::GetNextChannel(
    2833             cardid, input, channum, CHANNEL_DIRECTION_FAVORITE, order);
     2821        chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_FAVORITE);
    28342822    else if (BROWSE_LEFT == direction)
    28352823    {
    2836         chanid = ChannelUtil::GetNextChannel(
    2837             cardid, input, channum, CHANNEL_DIRECTION_SAME, order);
     2824        chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME);
    28382825        compare = "<";
    28392826    }
    28402827    else if (BROWSE_RIGHT == direction)
    28412828    {
    2842         chanid = ChannelUtil::GetNextChannel(
    2843             cardid, input, channum, CHANNEL_DIRECTION_SAME, order);
     2829        chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME);
    28442830        compare = ">";
    28452831        sortorder = "asc";
    28462832    }
     
    30473033
    30483034    if (channel && !channum.isEmpty() && (channum.find("NextChannel") >= 0))
    30493035    {
    3050         int dir = channum.right(channum.length() - 12).toInt();
    3051         uint chanid;
    3052         QString channelordering = channel->GetOrdering();
    3053         channum = ChannelUtil::GetNextChannel(
    3054             cardid,                    channel->GetCurrentInput(),
    3055             channel->GetCurrentName(), dir,
    3056             channelordering,           chanid);
     3036        int dir     = channum.right(channum.length() - 12).toInt();
     3037        uint chanid = channel->GetNextChannel(0, dir);
     3038        channum     = ChannelUtil::GetChanNum(chanid);
    30573039    }
    30583040
    30593041    return channum;
  • libs/libmythtv/programinfo.cpp

     
    40024002        querystr += " GROUP BY program.starttime, channel.channum, "
    40034003            "  channel.callsign, program.title ";
    40044004    if (!sql.contains(" ORDER BY "))
    4005         querystr += QString(" ORDER BY program.starttime, ") +
    4006                     gContext->GetSetting("ChannelOrdering", "channum+0") + " ";
     4005        querystr += " ORDER BY program.starttime, program.chanid ";
    40074006    if (!sql.contains(" LIMIT "))
    40084007        querystr += " LIMIT 1000 ";
    40094008
     
    40964095
    40974096    QString ip        = gContext->GetSetting("BackendServerIP");
    40984097    QString port      = gContext->GetSetting("BackendServerPort");
    4099     QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");
    41004098
    41014099    // ----------------------------------------------------------------------
    41024100
     
    41344132
    41354133    // ----------------------------------------------------------------------
    41364134
    4137     QString thequery = "SELECT recorded.chanid,recorded.starttime,recorded.endtime,"
    4138                        "recorded.title,recorded.subtitle,recorded.description,"
    4139                        "recorded.hostname,channum,name,callsign,commflagged,cutlist,"
    4140                        "recorded.autoexpire,editing,bookmark,recorded.category,"
    4141                        "recorded.recgroup,record.dupin,record.dupmethod,"
    4142                        "record.recordid,outputfilters,"
    4143                        "recorded.seriesid,recorded.programid,recorded.filesize, "
    4144                        "recorded.lastmodified, recorded.findid, "
    4145                        "recorded.originalairdate, recorded.playgroup, "
    4146                        "recorded.basename, recorded.progstart, "
    4147                        "recorded.progend, recorded.stars, "
    4148                        "recordedprogram.stereo, recordedprogram.hdtv, "
    4149                        "recordedprogram.closecaptioned "
    4150                        "FROM recorded "
    4151                        "LEFT JOIN record ON recorded.recordid = record.recordid "
    4152                        "LEFT JOIN channel ON recorded.chanid = channel.chanid "
    4153                        "LEFT JOIN recordedprogram ON (recorded.chanid = recordedprogram.chanid "
    4154                               "AND recorded.starttime = recordedprogram.starttime) "
    4155                        "WHERE (recorded.deletepending = 0 OR "
    4156                               "DATE_ADD(recorded.lastmodified, "
    4157                                        "INTERVAL 5 MINUTE) <= NOW()) "
    4158                        "ORDER BY recorded.starttime";
     4135    QString thequery =
     4136        "SELECT recorded.chanid,recorded.starttime,recorded.endtime,"
     4137        "recorded.title,recorded.subtitle,recorded.description,"
     4138        "recorded.hostname,channum,name,callsign,commflagged,cutlist,"
     4139        "recorded.autoexpire,editing,bookmark,recorded.category,"
     4140        "recorded.recgroup,record.dupin,record.dupmethod,"
     4141        "record.recordid,outputfilters,"
     4142        "recorded.seriesid,recorded.programid,recorded.filesize, "
     4143        "recorded.lastmodified, recorded.findid, "
     4144        "recorded.originalairdate, recorded.playgroup, "
     4145        "recorded.basename, recorded.progstart, "
     4146        "recorded.progend, recorded.stars, "
     4147        "recordedprogram.stereo, recordedprogram.hdtv, "
     4148        "recordedprogram.closecaptioned "
     4149        "FROM recorded "
     4150        "LEFT JOIN record ON recorded.recordid = record.recordid "
     4151        "LEFT JOIN channel ON recorded.chanid = channel.chanid "
     4152        "LEFT JOIN recordedprogram ON "
     4153        " ( recorded.chanid    = recordedprogram.chanid AND "
     4154        "   recorded.starttime = recordedprogram.starttime ) "
     4155        "WHERE ( recorded.deletepending = 0 OR "
     4156        "        DATE_ADD(recorded.lastmodified,  INTERVAL 5 MINUTE) <= NOW() "
     4157        "      ) "
     4158        "ORDER BY recorded.starttime";
    41594159
    41604160    if ( bDescending )
    41614161        thequery += " DESC";
    41624162
    4163     thequery += ", " + chanorder + " DESC;";
     4163    QString chanorder = gContext->GetSetting("ChannelOrdering", "channum");
     4164    if (chanorder != "channum")
     4165        thequery += ", " + chanorder + " DESC;";
     4166    else // approximation which the DB can handle
     4167        thequery += ",atscsrcid/256,atscsrcid%255,channum,callsign DESC;";
    41644168
    41654169    query.prepare(thequery);
    41664170
    4167     if (query.exec() && query.isActive() && query.size() > 0)
     4171    if (!query.exec() || !query.isActive())
    41684172    {
     4173        MythContext::DBError("ProgramList::FromRecorded", query);
     4174        return true;
     4175    }
     4176    else
     4177    {
    41694178        while (query.next())
    41704179        {
    41714180            ProgramInfo *proginfo = new ProgramInfo;
  • programs/mythfrontend/globalsettings.cpp

     
    983983{
    984984    HostComboBox *gc = new HostComboBox("ChannelOrdering");
    985985    gc->setLabel(QObject::tr("Channel ordering"));
    986     gc->addSelection(QObject::tr("channel number (numeric)"), "channum + 0");
    987     gc->addSelection(QObject::tr("channel number (alpha)"), "channum");
    988     gc->addSelection(QObject::tr("database order"), "chanid");
    989     gc->addSelection(QObject::tr("channel name"), "callsign");
    990     gc->addSelection(QObject::tr("ATSC channel"), "atscsrcid");
     986    gc->addSelection(QObject::tr("channel number"), "channum");
     987    gc->addSelection(QObject::tr("channel name"),   "callsign");
    991988    return gc;
    992989}
    993990
  • programs/mythfrontend/manualschedule.cpp

     
    3434#include "libmythtv/scheduledrecording.h"
    3535#include "libmythtv/recordingtypes.h"
    3636#include "libmythtv/remoteutil.h"
     37#include "libmythtv/channelutil.h"
    3738
    3839ManualSchedule::ManualSchedule(MythMainWindow *parent, const char *name)
    3940              : MythDialog(parent, name)
     
    7273    m_channel->setBackgroundOrigin(WindowOrigin);
    7374
    7475
    75     QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");
     76    QString longChannelFormat = gContext->GetSetting("LongChannelFormat",
     77                                                     "<num> <name>");
     78    QString chanorder = gContext->GetSetting("ChannelOrdering", "channum");
     79    DBChanList channels = ChannelUtil::GetChannels(0, false, "callsign");
     80    ChannelUtil::SortChannels(channels, chanorder);
    7681
    77     MSqlQuery query(MSqlQuery::InitCon());
    78     query.prepare(QString("SELECT chanid, channum, callsign, name "
    79                           "FROM channel GROUP BY channum, callsign "
    80                           "ORDER BY %1;").arg(chanorder));
     82    for (uint i = 0; i < channels.size(); i++)
     83    {
     84        QString chantext = QDeepCopy<QString>(longChannelFormat);
     85        chantext
     86            .replace("<num>",  channels[i].channum)
     87            .replace("<sign>", channels[i].callsign)
     88            .replace("<name>", channels[i].name);
    8189
    82     QString longChannelFormat =
    83         gContext->GetSetting("LongChannelFormat", "<num> <name>");
    84 
    85     if (query.exec() && query.isActive() && query.size()) {
    86       while(query.next()) {
    87           QString channel = longChannelFormat;
    88           channel.replace("<num>", query.value(1).toString())
    89               .replace("<sign>", QString::fromUtf8(query.value(2).toString()))
    90               .replace("<name>", QString::fromUtf8(query.value(3).toString()));
    91           m_channel->insertItem(channel);
    92           m_chanids << query.value(0).toString();
    93       }
    94      
     90        m_channel->insertItem(chantext);
     91        m_chanids << QString::number(channels[i].chanid);
    9592    }
    9693
    9794    hbox->addWidget(m_channel);
  • programs/mythbackend/mainserver.cpp

     
    987987
    988988    QString ip = gContext->GetSetting("BackendServerIP");
    989989    QString port = gContext->GetSetting("BackendServerPort");
    990     QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");
    991990
    992991    QMap<QString, int> inUseMap;
    993992    QString inUseKey;
     
    10191018        }
    10201019
    10211020
    1022     QString thequery = "SELECT recorded.chanid,recorded.starttime,recorded.endtime,"
    1023                        "recorded.title,recorded.subtitle,recorded.description,"
    1024                        "recorded.hostname,channum,name,callsign,commflagged,cutlist,"
    1025                        "recorded.autoexpire,editing,bookmark,recorded.category,"
    1026                        "recorded.recgroup,record.dupin,record.dupmethod,"
    1027                        "record.recordid,outputfilters,"
    1028                        "recorded.seriesid,recorded.programid,recorded.filesize, "
    1029                        "recorded.lastmodified, recorded.findid, "
    1030                        "recorded.originalairdate, recorded.playgroup, "
    1031                        "recorded.basename, recorded.progstart, "
    1032                        "recorded.progend, recorded.stars, "
    1033                        "recordedprogram.stereo, recordedprogram.hdtv, "
    1034                        "recordedprogram.closecaptioned, transcoded, "
    1035                        "recorded.recpriority "
    1036                        "FROM recorded "
    1037                        "LEFT JOIN record ON recorded.recordid = record.recordid "
    1038                        "LEFT JOIN channel ON recorded.chanid = channel.chanid "
    1039                        "LEFT JOIN recordedprogram ON (recorded.chanid = recordedprogram.chanid "
    1040                               "AND recorded.starttime = recordedprogram.starttime) "
    1041                        "WHERE (recorded.deletepending = 0 OR "
    1042                               "DATE_ADD(recorded.lastmodified, "
    1043                                        "INTERVAL 5 MINUTE) <= NOW()) "
    1044                        "ORDER BY recorded.starttime";
     1021    QString thequery =
     1022        "SELECT recorded.chanid,recorded.starttime,recorded.endtime,"
     1023        "recorded.title,recorded.subtitle,recorded.description,"
     1024        "recorded.hostname,channum,name,callsign,commflagged,cutlist,"
     1025        "recorded.autoexpire,editing,bookmark,recorded.category,"
     1026        "recorded.recgroup,record.dupin,record.dupmethod,"
     1027        "record.recordid,outputfilters,"
     1028        "recorded.seriesid,recorded.programid,recorded.filesize, "
     1029        "recorded.lastmodified, recorded.findid, "
     1030        "recorded.originalairdate, recorded.playgroup, "
     1031        "recorded.basename, recorded.progstart, "
     1032        "recorded.progend, recorded.stars, "
     1033        "recordedprogram.stereo, recordedprogram.hdtv, "
     1034        "recordedprogram.closecaptioned, transcoded, "
     1035        "recorded.recpriority "
     1036        "FROM recorded "
     1037        "LEFT JOIN record ON recorded.recordid = record.recordid "
     1038        "LEFT JOIN channel ON recorded.chanid = channel.chanid "
     1039        "LEFT JOIN recordedprogram ON "
     1040        " ( recorded.chanid = recordedprogram.chanid AND "
     1041        "  recorded.starttime = recordedprogram.starttime ) "
     1042        "WHERE ( recorded.deletepending = 0 OR "
     1043        "        DATE_ADD(recorded.lastmodified, INTERVAL 5 MINUTE) <= NOW() "
     1044        "      ) "
     1045        "ORDER BY recorded.starttime";
    10451046
    10461047    if (type == "Delete")
    10471048        thequery += " DESC";
    10481049
    1049     thequery += ", " + chanorder + " DESC;";
     1050    QString chanorder = gContext->GetSetting("ChannelOrdering", "channum");
     1051    if (chanorder != "channum")
     1052        thequery += ", " + chanorder + " DESC;";
     1053    else // approximation which the DB can handle
     1054        thequery += ",atscsrcid/256,atscsrcid%255,channum,callsign DESC;";
    10501055
    10511056    QStringList outputlist;
    10521057    QString fileprefix = gContext->GetFilePrefix();
     
    10551060
    10561061    query.prepare(thequery);
    10571062
    1058     if (query.exec() && query.isActive() && query.size() > 0)
     1063    if (!query.exec() || !query.isActive())
    10591064    {
     1065        MythContext::DBError("ProgramList::FromRecorded", query);
     1066        outputlist << "0";
     1067    }
     1068    else
     1069    {
    10601070        outputlist << QString::number(query.size());
    10611071
    10621072        while (query.next())
     
    12481258            delete proginfo;
    12491259        }
    12501260    }
    1251     else
    1252         outputlist << "0";
    12531261
    12541262    for (ri = schedList.begin(); ri != schedList.end(); ri++)
    12551263        delete (*ri);