[mythtv] [patch] Enable video posters in mythvideo tree view

David Härdeman david at 2gen.com
Tue Aug 24 16:59:18 EDT 2004


Hi,

this is my first post to the list (been lurking since January though), 
with a small patch. This one allows posters to be shown in the tree view 
of mythvideo.

Please review.

Regards,
David Härdeman
david at 2gen.com

-------------- next part --------------
? mythvideo_postersintree.patch
Index: mythvideo/metadata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.cpp,v
retrieving revision 1.15
diff -u -r1.15 metadata.cpp
--- mythvideo/metadata.cpp	19 Aug 2004 10:17:49 -0000	1.15
+++ mythvideo/metadata.cpp	24 Aug 2004 20:52:15 -0000
@@ -161,10 +161,10 @@
 
 }
 
-void Metadata::fillData(QSqlDatabase *db)
+bool Metadata::fillData(QSqlDatabase *db)
 {
     if (title == "")
-        return;
+        return false;
 
     QString thequery = "SELECT title,director,plot,rating,year,userrating,"
                        "length,filename,showlevel,intid,coverfile,inetref,"
@@ -199,14 +199,20 @@
         childID = query.value(12).toUInt();
         browse = query.value(13).toBool();
         playcommand = query.value(14).toString();
+	return true;
+    }
+    else
+    {
+        return false;
     }
 }
 
-void Metadata::fillDataFromID(QSqlDatabase *db)
+bool Metadata::fillDataFromID(QSqlDatabase *db)
 {       
     if (id == 0)
-        return; 
+        return false; 
         
+    
     QString thequery;
     thequery = QString("SELECT title,director,plot,rating,year,userrating,"
                        "length,filename,showlevel,coverfile,inetref,childid,"
@@ -215,7 +221,6 @@
                        " ON videometadata.category = videocategory.intid"
                        "  WHERE videometadata.intid=%1;")
                        .arg(id);
-        
     QSqlQuery query = db->exec(thequery);
 
     if (query.isActive() && query.numRowsAffected() > 0)
@@ -237,16 +242,69 @@
         browse = query.value(12).toBool();
         playcommand = query.value(13).toString();
         category = query.value(14).toString();
+
+	// Genres
+        fillGenres(db);
+    
+        //Countries
+        fillCountries(db);
+
+	return true;
+    }
+    else
+    {
+        cerr << "metadata.o : SELECT by id failed : " << thequery << endl;
+	return false;
+    }
+}
+
+bool Metadata::fillDataFromFilename(QSqlDatabase *db)
+{       
+    if (filename == "")
+        return false; 
         
-        // Genres
+    
+    QString thequery;
+    thequery = QString("SELECT videometadata.intid,title,director,plot"
+		       ",rating,year,userrating,length,showlevel,coverfile"
+		       ",inetref,childid,browse,playcommand"
+		       ", videocategory.category "
+                       " FROM videometadata LEFT JOIN videocategory"
+                       " ON videometadata.category = videocategory.intid"
+                       "  WHERE videometadata.filename='%1';")
+                       .arg(filename.utf8());
+    QSqlQuery query = db->exec(thequery);
+    if (query.isActive() && query.numRowsAffected() > 0)
+    {
+        query.next();
+
+	id = query.value(0).toInt();
+        title = QString::fromUtf8(query.value(1).toString());
+        director = QString::fromUtf8(query.value(2).toString());
+        plot = QString::fromUtf8(query.value(3).toString());
+        rating = query.value(4).toString();
+        year = query.value(5).toInt();
+        userrating = (float)query.value(6).toDouble();
+        length = query.value(7).toInt();
+        showlevel = query.value(8).toInt();
+        coverfile = QString::fromUtf8(query.value(9).toString());
+        inetref = QString::fromUtf8(query.value(10).toString());
+        childID = query.value(11).toUInt();
+        browse = query.value(12).toBool();
+        playcommand = query.value(13).toString();
+        category = query.value(14).toString();
+
+	// Genres
         fillGenres(db);
     
         //Countries
         fillCountries(db);
+	return true;
     }
     else
     {
-        cerr << "metadata.o : SELECT Failed : " << thequery << endl;
+        cerr << "metadata.o : SELECT by filename failed : " << thequery << endl;
+	return false;
     }
 }
 
Index: mythvideo/metadata.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.h,v
retrieving revision 1.12
diff -u -r1.12 metadata.h
--- mythvideo/metadata.h	22 Aug 2004 18:16:32 -0000	1.12
+++ mythvideo/metadata.h	24 Aug 2004 20:52:15 -0000
@@ -159,8 +159,9 @@
     void setField(QString field, QString data);
     void dumpToDatabase(QSqlDatabase *db);
     void updateDatabase(QSqlDatabase *db);
-    void fillData(QSqlDatabase *db);
-    void fillDataFromID(QSqlDatabase *db);
+    bool fillData(QSqlDatabase *db);
+    bool fillDataFromID(QSqlDatabase *db);
+    bool fillDataFromFilename(QSqlDatabase *db);
     int getIdCategory(QSqlDatabase *db);
     void setIdCategory(QSqlDatabase *db, int id);
     bool Remove(QSqlDatabase *db);
Index: mythvideo/videotree.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videotree.cpp,v
retrieving revision 1.31
diff -u -r1.31 videotree.cpp
--- mythvideo/videotree.cpp	22 Aug 2004 18:16:32 -0000	1.31
+++ mythvideo/videotree.cpp	24 Aug 2004 20:52:16 -0000
@@ -451,16 +451,31 @@
                     
                 QString the_file = *(browser_mode_files.at(node_int));
                 QString base_name = the_file.section("/", -1);
-                video_title->SetText(base_name.section(".", 0, -2));
-                video_file->SetText(base_name);
+
+		/* See if we can find this filename in DB */
+                curitem->setFilename(the_file);
+                if(curitem->fillDataFromFilename(db)) {
+		    video_title->SetText(curitem->Title());
+                    video_file->SetText(curitem->Filename().section("/", -1));
+                    video_poster->SetImage(curitem->CoverFile());
+                    video_poster->LoadImage();
+                    if (video_plot)
+                        video_plot->SetText(curitem->Plot());
+		}
+		else
+		{
+                    /* Nope, let's make the best of the situation */
+		    video_title->SetText(base_name.section(".", 0, -2));
+                    video_file->SetText(base_name);
+		    video_poster->ResetImage();
+                    curitem->setTitle(base_name.section(".", 0, -2));
+                    curitem->setPlayer(player);
+                    if (video_plot)
+                        video_plot->SetText(" ");
+		}
                 extension = the_file.section(".", -1);
                 player = gContext->GetSetting("VideoDefaultPlayer");
                 
-                curitem->setFilename(the_file);
-                curitem->setTitle(base_name.section(".", 0, -2));
-                curitem->setPlayer(player);
-                if (video_plot)
-                    video_plot->SetText(" ");
             }
         }
         else


More information about the mythtv-dev mailing list