[mythtv] [PATCH] Minor MythGame/MythGallery mods

m0j0.j0j0 m0j0 at foofus.net
Wed Oct 29 13:20:38 EST 2003


> > MythGame:
> >
> > -Added "Favorites" feature. With this patch you can toggle the
> > "Favorite" flag for each game using the "I" key. Within MythGame's
> > settings you can then configure it to show either all games or only
> > those which have been tagged.
> 
> Mind changing this so it uses the same favorites key as mythtv does?
> 
> Isaac

No problem. It's now set to '?'.

In looking for where MythTV set the "Favorites" key, I noticed the
following:

% grep Key_ * -r|grep fav -i                                
libs/libmythtv/guidegrid.cpp:        case Key_Slash: toggleChannelFavorite(); break;
libs/libmythtv/tv_play.cpp:            case Key_Slash: ChangeChannel(CHANNEL_DIRECTION_FAVORITE); break;
libs/libmythtv/tv_play.cpp:            case Key_Question: ToggleChannelFavorite(); break;

Shouldn't toggleChannelFavorite() in guidegrid.cpp use Key_Question?


Thanks,
Joe
-------------- next part --------------
? mythgame/.gametree.cpp.swp
Index: mythgame/game-ui.xml
===================================================================
RCS file: /var/lib/mythcvs/mythgame/mythgame/game-ui.xml,v
retrieving revision 1.3
diff -u -r1.3 game-ui.xml
--- mythgame/game-ui.xml	23 Sep 2003 22:41:54 -0000	1.3
+++ mythgame/game-ui.xml	23 Oct 2003 16:10:37 -0000
@@ -127,6 +127,19 @@
         <font>infofont</font>
       </textarea>
 
+      <textarea name="favorite" draworder="6">
+        <area>13,170,150,35</area>
+        <font>infofont</font>
+        <value>Favorite:</value>
+        <value lang="PT">GĂ©nero:</value>
+        <value lang="SV">Genre:</value>
+      </textarea>
+
+      <textarea name="showfavorite" draworder="6">
+        <area>153,170,500,35</area>
+        <font>infofont</font>
+      </textarea>
+
       <image name="gameimage" draworder="6" fleximage="no">
           <position>535,25</position>
           <staticsize>180,150</staticsize>
Index: mythgame/gamesettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythgame/mythgame/gamesettings.cpp,v
retrieving revision 1.4
diff -u -r1.4 gamesettings.cpp
--- mythgame/gamesettings.cpp	13 Sep 2003 16:19:11 -0000	1.4
+++ mythgame/gamesettings.cpp	23 Oct 2003 16:10:37 -0000
@@ -20,6 +20,17 @@
     };
 };
 
+class GameShowFavorites: public CheckBoxSetting, public GlobalSetting {
+public:
+    GameShowFavorites():
+        GlobalSetting("GameShowFavorites") {
+        setLabel(QObject::tr("Show Only Favorites"));
+        setValue(false);
+        setHelpText(QObject::tr("Limit games listed to only those tagged "
+                    "as \"favorite\""));
+    };
+};
+
 class MameBinary: public LineEditSetting, public GlobalSetting {
 public:
     MameBinary():
@@ -232,6 +243,7 @@
     VerticalConfigurationGroup *general = new VerticalConfigurationGroup(false);
     general->setLabel(QObject::tr("MythGame Settings -- General"));
     general->addChild(new GameTreeLevels());
+    general->addChild(new GameShowFavorites());
     addChild(general);
 
     VerticalConfigurationGroup *mame = new VerticalConfigurationGroup(false);
Index: mythgame/gametree.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythgame/mythgame/gametree.cpp,v
retrieving revision 1.5
diff -u -r1.5 gametree.cpp
--- mythgame/gametree.cpp	15 Oct 2003 15:13:19 -0000	1.5
+++ mythgame/gametree.cpp	23 Oct 2003 16:10:37 -0000
@@ -19,6 +19,7 @@
     db = ldb;
     m_paths = paths;
     m_pathlist = QStringList::split(" ", m_paths);
+    showfavs = gContext->GetSetting("GameShowFavorites");
 
     wireUpTheme();
 
@@ -44,6 +45,7 @@
             game_tree_list->select(); break;
 
         case Key_E: edit(); break;
+        case Key_Question: toggleFavorite(); break;
 
         case Key_Up: game_tree_list->moveUp(); break;
         case Key_Down: game_tree_list->moveDown(); break;
@@ -51,7 +53,7 @@
         case Key_Right: goRight(); break;
         case Key_PageUp: game_tree_list->pageUp(); break;
         case Key_PageDown: game_tree_list->pageDown(); break;
-          
+
         default: MythThemedDialog::keyPressEvent(e); break;
     }
 }
@@ -106,6 +108,7 @@
     game_system->SetText("");
     game_year->SetText("");
     game_genre->SetText("");
+    game_favorite->SetText("");
 
     if (node_int > 0)
     {
@@ -137,8 +140,14 @@
             else if (*field == "genre")
                 game_genre->SetText(curitem->rominfo->Genre());
             else if (*field == "gamename")
+            {
                 game_title->SetText(curitem->rominfo->Gamename());
-        } 
+                if (curitem->rominfo->Favorite())
+                    game_favorite->SetText("Yes");
+                else
+                    game_favorite->SetText("No");
+            }
+        }
     }
     else
         curitem = NULL;
@@ -183,6 +192,21 @@
         GameHandler::EditSettings(curitem->rominfo);
 }
 
+void GameTree::toggleFavorite(void)
+{
+    if (!curitem)
+        return;
+
+    if (curitem->level == "gamename" && curitem->isleaf)
+    {
+        curitem->rominfo->setFavorite(db);
+        if (curitem->rominfo->Favorite())
+            game_favorite->SetText("Yes");
+        else
+            game_favorite->SetText("No");
+    }
+}
+
 void GameTree::FillListFrom(GameTreeItem *item)
 {
     QString whereClause;
@@ -202,6 +226,9 @@
             break;
         }
     }
+    
+    if (showfavs == "1")
+      whereClause += " AND favorite=1";
 
     QString thequery = QString("SELECT DISTINCT %1 FROM gamemetadata "
                                "WHERE %2 ORDER BY %3;")
@@ -314,11 +341,17 @@
     }
 
     game_genre = getUITextType("genrename");
-    if (!game_title)
+    if (!game_genre)
     {
         cerr << "gametree.o: Couldn't find a text area genrename\n";
     }
 
+    game_favorite = getUITextType("showfavorite");
+    if (!game_favorite)
+    {
+        cerr << "gametree.o: Couldn't find a text area showfavorite\n";
+    }
+
     game_shot = getUIImageType("gameimage");
     if (!game_shot)
     {
Index: mythgame/gametree.h
===================================================================
RCS file: /var/lib/mythcvs/mythgame/mythgame/gametree.h,v
retrieving revision 1.1
diff -u -r1.1 gametree.h
--- mythgame/gametree.h	28 Jul 2003 20:17:38 -0000	1.1
+++ mythgame/gametree.h	23 Oct 2003 16:10:37 -0000
@@ -82,6 +82,7 @@
     void goRight(void);
     void FillListFrom(GameTreeItem *item);
     void edit(void);
+    void toggleFavorite(void);
 
     QString getClause(QString field, GameTreeItem *item);
 
@@ -97,11 +98,13 @@
 
     QString m_paths;
     QStringList m_pathlist;
+    QString showfavs;
 
     UITextType  *game_title;
     UITextType  *game_system;
     UITextType  *game_year;
     UITextType  *game_genre;
+    UITextType  *game_favorite;
     UIImageType *game_shot;
 };
 
Index: mythgame/rominfo.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythgame/mythgame/rominfo.cpp,v
retrieving revision 1.2
diff -u -r1.2 rominfo.cpp
--- mythgame/rominfo.cpp	30 Oct 2002 22:25:07 -0000	1.2
+++ mythgame/rominfo.cpp	23 Oct 2003 16:10:37 -0000
@@ -18,6 +18,18 @@
         genre = data;
     else if (field == "year")
         year = data.toInt();
+    else if (field == "favorite")
+        favorite = data.toInt();
+}
+
+void RomInfo::setFavorite(QSqlDatabase *db)
+{
+    favorite = 1 - favorite;
+
+    QString thequery = QString("UPDATE gamemetadata SET favorite=\"%1\" WHERE "
+                               "romname=\"%2\";").arg(favorite).arg(romname);
+
+    db->exec(thequery);
 }
 
 void RomInfo::fillData(QSqlDatabase *db)
@@ -27,7 +39,7 @@
         return;
     }
 
-    QString thequery = "SELECT system,gamename,genre,year,romname"
+    QString thequery = "SELECT system,gamename,genre,year,romname,favorite"
                        " FROM gamemetadata WHERE gamename=\"" + gamename + "\"";
 
     if (system != "")
@@ -46,6 +58,7 @@
         genre = query.value(2).toString();
         year = query.value(3).toInt();
         romname = query.value(4).toString();
+        favorite = query.value(5).toInt();
     }
 }
 
Index: mythgame/rominfo.h
===================================================================
RCS file: /var/lib/mythcvs/mythgame/mythgame/rominfo.h,v
retrieving revision 1.3
diff -u -r1.3 rominfo.h
--- mythgame/rominfo.h	28 Oct 2002 01:17:11 -0000	1.3
+++ mythgame/rominfo.h	23 Oct 2003 16:10:37 -0000
@@ -9,13 +9,14 @@
 {
   public:
     RomInfo(QString lromname = "", QString lsystem = "", QString lgamename ="",
-            QString lgenre = "", int lyear = 0)
+            QString lgenre = "", int lyear = 0, bool lfavorite = FALSE)
             {
                 romname = lromname;
                 system = lsystem;
                 gamename = lgamename;
                 genre = lgenre;
                 year = lyear;
+                favorite = lfavorite;
             }
     RomInfo(const RomInfo &lhs)
             {
@@ -24,6 +25,7 @@
                 gamename = lhs.gamename;
                 genre = lhs.genre;
                 year = lhs.year;
+                favorite = lhs.favorite;
             }
     virtual ~RomInfo() {}
 
@@ -42,6 +44,9 @@
     int Year() { return year; }
     void setYear(int lyear) { year = lyear; }
 
+    int Favorite() { return favorite; }
+    virtual void setFavorite(QSqlDatabase *db);
+
     virtual void setField(QString field, QString data);
     virtual void fillData(QSqlDatabase *db);
 
@@ -55,6 +60,7 @@
     QString gamename;
     QString genre;
     int year;
+    bool favorite;
 };
 
 bool operator==(const RomInfo& a, const RomInfo& b);


More information about the mythtv-dev mailing list