[mythtv] PATCH: Resolve DVB Channel Editor Inconsistency

Martin Smith martin at spamcop.net
Sat Jan 10 10:00:24 EST 2004


Folks,

The way the channel editor decides to decide to display DVB setup pages for a
channel may not work correctly if there is a mixture of card types in a system.

I just looked at the code in CVS and at the moment the editor displays DVB pages
if a new channel is being created (id == 0) or if a query on cardtype matches
"DVB". The query only looks at the first row of the results, which on my system
is MPEG because of the existing analogue card sharing the input source.

The attached patch changes this so that you get the V4l page if there is a.) no
DVB card or b.) a DVB card plus at least one other card type associated with
the source. Also you now get the DVB pages if there is at least one DVB card
associated with the source. I believe this should work in all cases, famous
last words though these may be.

This issue isn't a major one but the patch might help people migrating from an
analogue to DVB setup. Some people are currently using manual sql inserts (see
users list).

Martin
-------------- next part --------------
Index: libs/libmythtv/channeleditor.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/channeleditor.cpp,v
retrieving revision 1.3
diff -u -r1.3 channeleditor.cpp
--- libs/libmythtv/channeleditor.cpp	4 Jan 2004 18:37:01 -0000	1.3
+++ libs/libmythtv/channeleditor.cpp	10 Jan 2004 14:50:33 -0000
@@ -38,13 +38,19 @@
     ChannelOptionsCommon* common = new ChannelOptionsCommon(*cid);
     addChild(common);
 
+    int cardtypes = countCardtypes();
+    bool hasDVB = cardTypesInclude("DVB");
+
+    // add v4l options if no dvb or if dvb and some other card type
+    // present
     QString cardtype = getCardtype();
-    if (cardtype != "DVB" || id == 0) {
+    if (!hasDVB || cardtypes > 1 || id == 0) {
         ChannelOptionsV4L* v4l = new ChannelOptionsV4L(*cid);
         addChild(v4l);
     }
 
-    if (cardtype == "DVB" || id == 0)
+    // add dvb options if dvb is present
+    if (hasDVB || id == 0)
     {
         ChannelOptionsDVB* dvb = new ChannelOptionsDVB(*cid);
         ChannelOptionsDVBPids* pids = new ChannelOptionsDVBPids(*cid);
@@ -68,6 +74,43 @@
         return "";
 }
 
+bool ChannelWizard::cardTypesInclude(const QString& thecardtype) {
+    QSqlQuery query = db->exec(QString("SELECT count(cardtype)"
+        " FROM capturecard, cardinput, channel"
+        " WHERE channel.chanid=%1"
+        " AND channel.sourceid = cardinput.sourceid"
+        " AND cardinput.cardid = capturecard.cardid"
+        " AND capturecard.cardtype=\"%2\"")
+        .arg(cid->getValue())
+        .arg(thecardtype));
+    if (query.isActive() && query.numRowsAffected() > 0)
+    {
+        query.next();
+        int count = query.value(0).toInt();
+
+        if (count > 0)
+            return true;
+        else
+            return false;
+    } else
+        return false;
+}
+
+int ChannelWizard::countCardtypes() {
+    QSqlQuery query = db->exec(QString("SELECT count(DISTINCT cardtype)"
+        " FROM capturecard, cardinput, channel"
+        " WHERE channel.chanid=%1"
+        " AND channel.sourceid = cardinput.sourceid"
+        " AND cardinput.cardid = capturecard.cardid")
+        .arg(cid->getValue()));
+    if (query.isActive() && query.numRowsAffected() > 0)
+    {
+        query.next();
+        return query.value(0).toInt();
+    } else
+        return 0;
+}
+
 void ChannelListSetting::fillSelections(const QString& sourceid) 
 {
     currentSourceID = sourceid;
Index: libs/libmythtv/channeleditor.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/channeleditor.h,v
retrieving revision 1.2
diff -u -r1.2 channeleditor.h
--- libs/libmythtv/channeleditor.h	1 Jan 2004 03:43:51 -0000	1.2
+++ libs/libmythtv/channeleditor.h	10 Jan 2004 14:50:33 -0000
@@ -33,6 +33,8 @@
 public:
     ChannelWizard(int id, QSqlDatabase* _db);
     QString getCardtype();
+    bool cardTypesInclude(const QString& cardtype); 
+    int countCardtypes();
 
 private:
     ChannelID *cid;


More information about the mythtv-dev mailing list