Ticket #1966: 1966-sort-only.patch
File 1966-sort-only.patch, 48.1 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/previouslist.cpp
40 40 hourFormat = gContext->GetSetting("TimeFormat"); 41 41 timeFormat = gContext->GetSetting("ShortDateFormat") + " " + hourFormat; 42 42 fullDateFormat = dayFormat + " " + hourFormat; 43 channelOrdering = gContext->GetSetting("ChannelOrdering", "channum + 0");44 43 channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>"); 45 44 46 45 allowEvents = true; -
libs/libmythtv/channelutil.h
8 8 9 9 class NetworkInformationTable; 10 10 11 class 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 }; 35 typedef vector<DBChannel> DBChanList; 36 37 11 38 /** \class ChannelUtil 12 39 * \brief Collection of helper utilities for channel DB use 13 40 */ … … 97 124 static QString GetVideoFilters(uint sourceid, const QString &channum) 98 125 { return GetChannelValueStr("videofilters", sourceid, channum); } 99 126 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); 106 129 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); 118 132 119 133 static QString GetChannelValueStr(const QString &channel_field, 120 134 uint sourceid, -
libs/libmythtv/proglist.cpp
23 23 #include "mythcontext.h" 24 24 #include "remoteutil.h" 25 25 #include "mythdbcon.h" 26 #include "channelutil.h" 26 27 27 28 ProgLister::ProgLister(ProgListType pltype, 28 29 const QString &view, const QString &from, … … 39 40 hourFormat = gContext->GetSetting("TimeFormat"); 40 41 timeFormat = gContext->GetSetting("ShortDateFormat") + " " + hourFormat; 41 42 fullDateFormat = dayFormat + " " + hourFormat; 42 channelOrdering = gContext->GetSetting("ChannelOrdering", "channum + 0");43 channelOrdering = gContext->GetSetting("ChannelOrdering", "channum"); 43 44 channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>"); 44 45 45 46 switch (pltype) … … 977 978 stationList.clear(); 978 979 stationList << ""; 979 980 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); 986 983 987 if (query.isActive() && query.size())984 for (uint i = 0; i < channels.size(); i++) 988 985 { 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); 995 991 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; 1000 994 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); 1009 999 } 1000 1010 1001 powerPopup->addWidget(powerStation); 1011 1002 1012 1003 powerOkButton = new MythPushButton(powerPopup); … … 1185 1176 1186 1177 if (type == plChannel) // list by channel 1187 1178 { 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); 1195 1181 1196 if (query.isActive() && query.size())1182 for (uint i = 0; i < channels.size(); i++) 1197 1183 { 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); 1204 1189 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; 1213 1192 } 1214 if (view != "") 1193 1194 if (!view.isEmpty()) 1215 1195 curView = viewList.findIndex(view); 1216 1196 } 1217 1197 else if (type == plCategory) // list by category -
libs/libmythtv/guidegrid.cpp
31 31 #include "customedit.h" 32 32 #include "util.h" 33 33 #include "remoteutil.h" 34 #include "channelutil.h" 34 35 35 36 bool RunProgramGuide(uint &chanid, QString &channum, 36 37 bool thread, TV *player, … … 179 180 container->SetDrawFontShadow(false); 180 181 } 181 182 182 channelOrdering = gContext->GetSetting("ChannelOrdering", "channum + 0");183 channelOrdering = gContext->GetSetting("ChannelOrdering", "channum"); 183 184 dateformat = gContext->GetSetting("ShortDateFormat", "ddd d"); 184 185 unknownTitle = gContext->GetSetting("UnknownTitle", "Unknown"); 185 186 unknownCategory = gContext->GetSetting("UnknownCategory", "Unknown"); … … 559 560 560 561 void GuideGrid::fillChannelInfos(bool gotostartchannel) 561 562 { 562 MSqlQuery query(MSqlQuery::InitCon());563 564 563 m_channelInfos.clear(); 565 564 565 DBChanList channels = ChannelUtil::GetChannels(0, true, "callsign"); 566 ChannelUtil::SortChannels(channels, channelOrdering); 567 566 568 if (showFavorites) 567 569 { 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++) 602 572 { 603 MythContext::DBError("fillChannelInfos -- all connected", query);604 return;573 if (channels[i].favorite) 574 tmp.push_back(channels[i]); 605 575 } 576 577 if (!tmp.empty()) 578 channels = tmp; 606 579 } 607 580 608 581 bool startingset = false; 609 while (query.next())582 for (uint i = 0; i < channels.size(); i++) 610 583 { 611 584 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; 625 591 val.iconload = false; 626 592 627 593 // set starting channel index if it hasn't been set … … 633 599 m_currentStartChannel = m_channelInfos.size(); 634 600 startingset = true; 635 601 } 636 602 637 603 // add the new channel to the list 638 604 m_channelInfos.push_back(val); 639 605 } 606 640 607 // set starting channel index to 0 if it hasn't been set 641 608 if (gotostartchannel) 642 609 m_currentStartChannel = (startingset) ? m_currentStartChannel : 0; -
libs/libmythtv/dbcheck.cpp
10 10 #include "mythdbcon.h" 11 11 12 12 /// This is the DB schema version expected by the running MythTV instance. 13 const QString currentDatabaseVersion = "11 49";13 const QString currentDatabaseVersion = "1150"; 14 14 15 15 static bool UpdateDBVersionNumber(const QString &newnumber); 16 16 static bool performActualUpdate(const QString updates[], QString version, … … 2365 2365 return false; 2366 2366 } 2367 2367 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 2368 2379 //"ALTER TABLE capturecard DROP COLUMN dvb_recordts;" in 0.21 2369 2380 //"ALTER TABLE capturecard DROP COLUMN dvb_hw_decoder;" in 0.21 2370 2381 //"ALTER TABLE cardinput DROP COLUMN preference;" in 0.22 -
libs/libmythtv/channelbase.h
10 10 #include <qsqldatabase.h> 11 11 12 12 // MythTV headers 13 13 #include "channelutil.h" 14 14 #include "frequencies.h" 15 15 #include "tv.h" 16 16 … … 31 31 32 32 InputBase(QString _name, QString _startChanNum, 33 33 QString _tuneToChannel, QString _externalChanger, 34 uint _sourceid, uint _cardid) : 34 uint _sourceid, uint _cardid, 35 const DBChanList &_channels) : 35 36 name(_name), startChanNum(_startChanNum), 36 37 tuneToChannel(_tuneToChannel), externalChanger(_externalChanger), 37 38 sourceid(_sourceid), cardid(_cardid), 39 channels(_channels), 38 40 inputNumV4L(-1), 39 41 videoModeV4L1(0), videoModeV4L2(0) {} 40 42 … … 47 49 QString externalChanger; // for using a cable box... 48 50 uint sourceid; // associated channel listings source 49 51 uint cardid; // input card id 52 DBChanList channels; 50 53 int inputNumV4L; 51 54 int videoModeV4L1; 52 55 int videoModeV4L2; … … 83 86 virtual int GetFd(void) const { return -1; }; 84 87 85 88 // Gets 89 virtual uint GetNextChannel(uint chanid, int direction) const; 90 virtual uint GetNextChannel(const QString &channum, int direction) const; 86 91 virtual int GetInputByName(const QString &input) const; 87 92 virtual QString GetInputByNum(int capchannel) const; 88 93 virtual QString GetCurrentName(void) const … … 101 106 { return inputs[GetCurrentInputNum()]->sourceid; } 102 107 virtual uint GetInputCardID(int inputNum) const; 103 108 virtual QStringList GetConnectedInputs(void) const; 104 virtual QString GetOrdering(void) const105 { return channelorder; }106 109 /// \brief Returns true iff commercial detection is not required 107 110 // on current channel, for BBC, CBC, etc. 108 111 bool IsCommercialFree(void) const { return commfree; } … … 110 113 virtual QString GetDevice(void) const { return ""; } 111 114 112 115 // Sets 113 virtual void SetChannelOrdering(const QString &chanorder)114 { channelorder = chanorder; }115 116 virtual void Renumber(uint srcid, const QString &oldChanNum, 116 117 const QString &newChanNum); 117 118 … … 177 178 static void StoreInputChannels(const InputMap&); 178 179 179 180 TVRec *pParent; 180 QString channelorder;181 181 QString curchannelname; 182 182 int currentInputID; 183 183 bool commfree; -
libs/libmythtv/previouslist.h
48 48 QString hourFormat; 49 49 QString timeFormat; 50 50 QString fullDateFormat; 51 QString channelOrdering;52 51 QString channelFormat; 53 52 54 53 RecSearchType searchtype; -
libs/libmythtv/channelbase.cpp
32 32 33 33 ChannelBase::ChannelBase(TVRec *parent) 34 34 : 35 pParent(parent), c hannelorder("channum + 0"), curchannelname(""),35 pParent(parent), curchannelname(""), 36 36 currentInputID(-1), commfree(false), cardid(0), 37 37 currentATSCMajorChannel(-1), currentATSCMinorChannel(-1), 38 38 currentProgramNum(-1), currentOriginalNetworkID(-1), … … 46 46 47 47 bool ChannelBase::SetChannelByDirection(ChannelChangeDirection dir) 48 48 { 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; 55 51 52 bool ok = false; 56 53 do 57 54 { 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); 65 57 } 66 while (! fTune && nextchan != start);58 while (!ok && (nextchanid != startchanid)); 67 59 68 return fTune;60 return ok; 69 61 } 70 62 63 uint 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 72 uint 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 71 82 int ChannelBase::GetNextInputNum(void) const 72 83 { 73 84 // Exit early if inputs don't exist.. … … 486 497 uint inputcardid = query.value(6).toUInt(); 487 498 inputcardid = (inputcardid) ? inputcardid : cardid; 488 499 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 489 506 inputs[query.value(0).toUInt()] = new InputBase( 490 507 query.value(1).toString(), query.value(2).toString(), 491 508 query.value(3).toString(), query.value(4).toString(), 492 query.value(5).toUInt(), inputcardid);509 sourceid, inputcardid, channels); 493 510 } 494 511 495 512 // Set initial input to first connected input -
libs/libmythtv/channelutil.cpp
796 796 return query.exec(); 797 797 } 798 798 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 direction888 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 else941 {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 this949 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 else975 {976 VERBOSE(VB_IMPORTANT, "getnextchannel, query failed: "<<querystr);977 }978 }979 980 // just stay on same channel981 chanid = max(GetChannelValueInt("chanid", cardid, inputname, channum), 0);982 return channum;983 }984 985 799 int ChannelUtil::GetChanID(int mplexid, int service_transport_id, 986 800 int major_channel, int minor_channel, 987 801 int program_number) … … 1244 1058 query.bindValue(":CHANNUM", chan_num); 1245 1059 if (freqid > 0) 1246 1060 query.bindValue(":FREQID", freqid); 1247 if (atsc_m ajor_channel > 0)1061 if (atsc_minor_channel > 0) 1248 1062 query.bindValue(":TVFORMAT", "ATSC"); 1249 1063 1250 1064 if (!query.exec() || !query.isActive()) … … 1321 1135 1322 1136 return query.value(0).toString(); 1323 1137 } 1138 1139 DBChanList 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 1202 inline bool lt_callsign(const DBChannel &a, const DBChannel &b) 1203 { 1204 return QString::localeAwareCompare(a.callsign, b.callsign) < 0; 1205 } 1206 1207 inline 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 1236 void 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 1244 uint 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
29 29 #include "scanwizard.h" 30 30 #include "cardutil.h" 31 31 #include "sourceutil.h" 32 #include "channelutil.h" 32 33 #include "frequencies.h" 33 34 34 35 #ifdef USING_DVB … … 1614 1615 else if (query.next()) 1615 1616 startChan = query.value(0).toString(); 1616 1617 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); 1624 1619 1625 QString nnsc = startChan.isEmpty() ? "" : startChan; 1626 if (!query.exec() || !query.isActive()) 1620 if (channels.empty()) 1627 1621 { 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; 1630 1625 } 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++) 1632 1632 { 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); 1640 1635 } 1641 else1642 {1643 addSelection(tr("Please add channels to this source"), nnsc);1644 }1645 1636 } 1646 1637 1647 1638 class InputPriority: public SpinBoxSetting, public CISetting { -
libs/libmythtv/tv_rec.cpp
1069 1069 channel->SetChannelByString(startchannel); 1070 1070 else 1071 1071 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);1078 1072 } 1079 1073 1080 1074 void TVRec::CloseChannel(void) … … 2815 2809 { 2816 2810 QString compare = "<="; 2817 2811 QString sortorder = "desc"; 2818 QString input = channel->GetCurrentInput(); 2819 QString order = channel->GetOrdering(); 2820 int chanid = -1; 2812 uint chanid = 0; 2821 2813 2822 2814 if (BROWSE_SAME == direction) 2823 chanid = ChannelUtil::GetNextChannel( 2824 cardid, input, channum, CHANNEL_DIRECTION_SAME, order); 2815 chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME); 2825 2816 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); 2828 2818 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); 2831 2820 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); 2834 2822 else if (BROWSE_LEFT == direction) 2835 2823 { 2836 chanid = ChannelUtil::GetNextChannel( 2837 cardid, input, channum, CHANNEL_DIRECTION_SAME, order); 2824 chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME); 2838 2825 compare = "<"; 2839 2826 } 2840 2827 else if (BROWSE_RIGHT == direction) 2841 2828 { 2842 chanid = ChannelUtil::GetNextChannel( 2843 cardid, input, channum, CHANNEL_DIRECTION_SAME, order); 2829 chanid = channel->GetNextChannel(channum, CHANNEL_DIRECTION_SAME); 2844 2830 compare = ">"; 2845 2831 sortorder = "asc"; 2846 2832 } … … 3047 3033 3048 3034 if (channel && !channum.isEmpty() && (channum.find("NextChannel") >= 0)) 3049 3035 { 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); 3057 3039 } 3058 3040 3059 3041 return channum; -
libs/libmythtv/programinfo.cpp
4002 4002 querystr += " GROUP BY program.starttime, channel.channum, " 4003 4003 " channel.callsign, program.title "; 4004 4004 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 "; 4007 4006 if (!sql.contains(" LIMIT ")) 4008 4007 querystr += " LIMIT 1000 "; 4009 4008 … … 4096 4095 4097 4096 QString ip = gContext->GetSetting("BackendServerIP"); 4098 4097 QString port = gContext->GetSetting("BackendServerPort"); 4099 QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");4100 4098 4101 4099 // ---------------------------------------------------------------------- 4102 4100 … … 4134 4132 4135 4133 // ---------------------------------------------------------------------- 4136 4134 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"; 4159 4159 4160 4160 if ( bDescending ) 4161 4161 thequery += " DESC"; 4162 4162 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;"; 4164 4168 4165 4169 query.prepare(thequery); 4166 4170 4167 if ( query.exec() && query.isActive() && query.size() > 0)4171 if (!query.exec() || !query.isActive()) 4168 4172 { 4173 MythContext::DBError("ProgramList::FromRecorded", query); 4174 return true; 4175 } 4176 else 4177 { 4169 4178 while (query.next()) 4170 4179 { 4171 4180 ProgramInfo *proginfo = new ProgramInfo; -
programs/mythfrontend/globalsettings.cpp
983 983 { 984 984 HostComboBox *gc = new HostComboBox("ChannelOrdering"); 985 985 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"); 991 988 return gc; 992 989 } 993 990 -
programs/mythfrontend/manualschedule.cpp
34 34 #include "libmythtv/scheduledrecording.h" 35 35 #include "libmythtv/recordingtypes.h" 36 36 #include "libmythtv/remoteutil.h" 37 #include "libmythtv/channelutil.h" 37 38 38 39 ManualSchedule::ManualSchedule(MythMainWindow *parent, const char *name) 39 40 : MythDialog(parent, name) … … 72 73 m_channel->setBackgroundOrigin(WindowOrigin); 73 74 74 75 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); 76 81 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); 81 89 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); 95 92 } 96 93 97 94 hbox->addWidget(m_channel); -
programs/mythbackend/mainserver.cpp
987 987 988 988 QString ip = gContext->GetSetting("BackendServerIP"); 989 989 QString port = gContext->GetSetting("BackendServerPort"); 990 QString chanorder = gContext->GetSetting("ChannelOrdering", "channum + 0");991 990 992 991 QMap<QString, int> inUseMap; 993 992 QString inUseKey; … … 1019 1018 } 1020 1019 1021 1020 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"; 1045 1046 1046 1047 if (type == "Delete") 1047 1048 thequery += " DESC"; 1048 1049 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;"; 1050 1055 1051 1056 QStringList outputlist; 1052 1057 QString fileprefix = gContext->GetFilePrefix(); … … 1055 1060 1056 1061 query.prepare(thequery); 1057 1062 1058 if ( query.exec() && query.isActive() && query.size() > 0)1063 if (!query.exec() || !query.isActive()) 1059 1064 { 1065 MythContext::DBError("ProgramList::FromRecorded", query); 1066 outputlist << "0"; 1067 } 1068 else 1069 { 1060 1070 outputlist << QString::number(query.size()); 1061 1071 1062 1072 while (query.next()) … … 1248 1258 delete proginfo; 1249 1259 } 1250 1260 } 1251 else1252 outputlist << "0";1253 1261 1254 1262 for (ri = schedList.begin(); ri != schedList.end(); ri++) 1255 1263 delete (*ri);