[mythtv] [PATCH] use presets instead of channums

Bjorn Hijmans bjorn at hijmans.nl
Thu Apr 24 22:40:34 EDT 2003


Hi,

Attached a patch to use presets instead of channelnumbers to change
channels. The preset will be printed in the OSD as well. Execute the
following query to enable this (you cant change this in the setup):

insert into settings (value, data, hostname) values ('HideChannum', 1,
'<yourhost>');

The preset is derived from the chanid. I order my channels using the
chanid. Also, in my database (and probably others that have loaded their
channels using mythfilldatabase --xawchannels) the chanid starts with
1000. So, the preset is the chanid - 999.

In the UpdateOSD method the channum is rewritten by the preset (chanid -
999). In the ChannelCommit method, the ProgramInfo class is used to
lookup the channum from the chanid so the channum can be used to change
the channel (ChangeChannelByString). Because other functions like the EPG
and the new browse function queue a channum, I have introduced a new
boolean to indicate a chanid was queued.

I know the implementation isnt very decent. But, to do it the right way, I
should add an extra column in the channels table. This would require
rewriting a lot of code (especially because in the majority of the methods
the channum instead of the chanid is used to refer to a record in the
channels table).

Also, because of the risc Isaac doesnt want this in MythTV I have tried to
write as little code as possible. This will make it easy to merge in new
versions.

Maybe somebody is willing to think about a more decent implementation. I
think a lot of european users will be very happy if they could use presets
to change the channel.

Bjorn
-------------- next part --------------
diff -ur MC/libs/libmythtv/programinfo.cpp MC.clean.patched/libs/libmythtv/programinfo.cpp
--- MC/libs/libmythtv/programinfo.cpp	Wed Apr 23 23:15:18 2003
+++ MC.clean.patched/libs/libmythtv/programinfo.cpp	Thu Apr 24 21:29:38 2003
@@ -349,6 +349,25 @@
     return GetProgramAtDateTime(channel, sqltime);
 }
 
+QString ProgramInfo::GetChanNumFromChanid(QString channel)
+{
+    QSqlQuery query;
+    QString thequery;
+    QString channum;
+    
+    thequery = QString("SELECT channum FROM channel WHERE chanid=%1;") . arg(channel);
+    query.exec(thequery);
+    
+    if(query.isActive() && query.numRowsAffected() > 0)
+    {
+        query.next();
+        
+        channum = query.value(0).toString();
+    }
+    
+    return channum;
+}
+
 ProgramInfo *ProgramInfo::GetProgramFromRecorded(QString channel, QString starttime)
 {
     QSqlQuery query;
diff -ur MC/libs/libmythtv/programinfo.h MC.clean.patched/libs/libmythtv/programinfo.h
--- MC/libs/libmythtv/programinfo.h	Wed Apr 23 23:15:18 2003
+++ MC.clean.patched/libs/libmythtv/programinfo.h	Thu Apr 24 21:29:40 2003
@@ -66,6 +66,8 @@
     static ProgramInfo *GetProgramAtDateTime(QString channel, QDateTime &dtime);
     static ProgramInfo *GetProgramFromRecorded(QString channel, QString starttime);
 
+    static QString GetChanNumFromChanid(QString channel);
+
     QString title;
     QString subtitle;
     QString description;
diff -ur MC/libs/libmythtv/tv_play.cpp MC.clean.patched/libs/libmythtv/tv_play.cpp
--- MC/libs/libmythtv/tv_play.cpp	Thu Apr 24 06:10:29 2003
+++ MC.clean.patched/libs/libmythtv/tv_play.cpp	Thu Apr 24 21:29:29 2003
@@ -1470,6 +1470,13 @@
     if (key > 256)
         thekey = key - 256 - 0xb0 + '0';
 
+    QString hideChannum = gContext->GetSetting("HideChannum");
+    
+    if(hideChannum == "1")
+    {
+        chanidqueued = true;
+    }   
+
     if (channelkeysstored == 4)
     {
         channelKeys[0] = channelKeys[1];
@@ -1510,6 +1517,16 @@
     }
 
     QString chan = QString(channelKeys).stripWhiteSpace();
+
+    // Translate to channum
+    if(chanidqueued)
+    {
+        // Add 999
+        chan = QString::number(chan.toInt() + 999);
+        chan = ProgramInfo::GetChanNumFromChanid(chan);
+        chanidqueued = false;
+    }
+
     ChangeChannelByString(chan);
 
     channelqueued = false;
@@ -1657,8 +1674,16 @@
 
     GetChannelInfo(activerecorder, regexpMap);
 
-    osd->SetTextByRegexp("program_info", regexpMap, osd_display_time);
+    QString hideChannum = gContext->GetSetting("HideChannum");
+
+    if(hideChannum == "1")
+    {   regexpMap["channum"] = QString::number(regexpMap["chanid"].toInt() - 999);
+    }    
+    
     osd->SetTextByRegexp("channel_number", regexpMap, osd_display_time);
+
+    osd->SetTextByRegexp("program_info", regexpMap, osd_display_time);
+
 }
 
 void TV::UpdateOSDInput(void)
diff -ur MC/libs/libmythtv/tv_play.h MC.clean.patched/libs/libmythtv/tv_play.h
--- MC/libs/libmythtv/tv_play.h	Wed Apr 23 23:15:18 2003
+++ MC.clean.patched/libs/libmythtv/tv_play.h	Thu Apr 24 21:29:32 2003
@@ -142,6 +142,7 @@
     int osd_display_time;
 
     bool channelqueued;
+    bool chanidqueued;
     char channelKeys[5];
     int channelkeysstored;
 


More information about the mythtv-dev mailing list