[mythtv] [PATCH] Minor MythGame/MythGallery mods

m0j0.j0j0 m0j0 at foofus.net
Thu Oct 23 12:29:23 EDT 2003


I made another lame attempt at mangling some Myth code...

MythGallery:

-Set "Icon View" to use the same background type (theme, black or white)
as "Single View". 

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.

The following DB update is necessary:

INSERT INTO settings VALUES ('GameShowFavorites', 0, NULL);
ALTER TABLE gamemetadata ADD COLUMN favorite BOOL NULL;


Hope this is useful and not too horribly coded. Let me know if I should
be doing anything different.

Joe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mythgallery-black-background.diff
Type: text/x-patch
Size: 721 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20031023/36f4f593/mythgallery-black-background.bin
-------------- 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_I: 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