[mythtv] [PATCH] mythvideo

Xavier Hervy maxpower44 at tiscali.fr
Fri May 28 11:46:47 EDT 2004


This patch resolve conflict between videofilter and browse flag.
Now the browse flag can't be select in videofilter.
I have add a field in database called lastshown which is the date of the 
last time we show a video.
then we can filter list of video by lastshown : ALL, Never , More than 1 
year ... More than 1 month ... more than 1 week ... more than 1 day.
But videofilter know if it is in videolist mode or in videomanager mode 
then in videolist mode, it select only video with browse flag set to 1.
videofilter need filter by browse flag when it was in videolist mode to 
count then number of videos available.
then it will be not necessary to check the browse flag in 
videobrowser.cpp a second time (i remove it)

To resume, video with browse flag set to 0 will never show in video list.

Thor can you apply this patch ?
thx
-------------- next part --------------
? mythvideo/log
Index: mythvideo/mythvideo/dbcheck.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/dbcheck.cpp,v
retrieving revision 1.4
diff -u -r1.4 dbcheck.cpp
--- mythvideo/mythvideo/dbcheck.cpp	2 Mar 2004 17:57:53 -0000	1.4
+++ mythvideo/mythvideo/dbcheck.cpp	28 May 2004 15:34:50 -0000
@@ -8,7 +8,7 @@
 
 #include "mythtv/mythcontext.h"
 
-const QString currentDatabaseVersion = "1003";
+const QString currentDatabaseVersion = "1004";
 
 static void UpdateDBVersionNumber(const QString &newnumber)
 {
@@ -152,5 +152,13 @@
 
         performActualUpdate(updates, "1003", dbver);
     }
-}
+    if (dbver == "1003")
+    {
+        const QString updates[] = {
+"ALTER TABLE videometadata ADD COLUMN lastshown DATE DEFAULT NULL;",
+""
+};
 
+        performActualUpdate(updates, "1004", dbver);
+    }
+}
Index: mythvideo/mythvideo/metadata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.cpp,v
retrieving revision 1.11
diff -u -r1.11 metadata.cpp
--- mythvideo/mythvideo/metadata.cpp	2 Mar 2004 17:57:53 -0000	1.11
+++ mythvideo/mythvideo/metadata.cpp	28 May 2004 15:34:52 -0000
@@ -94,7 +94,7 @@
 			cerr << "metadata.o: The following metadata update failed :" << thequery << endl;
     		}
 	}else{
-		cout << "impossible de supprimmer le fichier" << endl;
+		cerr << "Enable to delete this file" << endl;
 	}
 	return isremoved;
 }
@@ -157,7 +157,7 @@
 
     QString thequery = "SELECT title,director,plot,rating,year,userrating,"
                        "length,filename,showlevel,intid,coverfile,inetref,"
-                       "childid, browse, playcommand FROM videometadata WHERE title=\"" + 
+                       "childid, browse, playcommand, lastshown FROM videometadata WHERE title=\"" + 
                         title + "\"";
 
     if (director != "")
@@ -188,6 +188,7 @@
         childID = query.value(12).toUInt();
         browse = query.value(13).toBool();
         playcommand = query.value(14).toString();
+	lastshown = query.value(15).toDate();
     }
 }
 
@@ -199,7 +200,7 @@
     QString thequery;
     thequery = QString("SELECT title,director,plot,rating,year,userrating,"
                        "length,filename,showlevel,coverfile,inetref,childid,"
-                       "browse,playcommand, videocategory.category "
+                       "browse,playcommand, videocategory.category, lastshown "
 			" FROM videometadata LEFT JOIN videocategory"
 			" ON videometadata.category = videocategory.intid"
 			"  WHERE videometadata.intid=%1;")
@@ -226,7 +227,8 @@
         browse = query.value(12).toBool();
         playcommand = query.value(13).toString();
 	category = query.value(14).toString();
-	
+	lastshown = query.value(15).toDate();
+
 	// Genres
 	fillGenres(db);
 
@@ -272,16 +274,24 @@
     QString sqlcoverfile = coverfile;
     sqlcoverfile.replace(QRegExp("\""), QString("\\\""));
 
+    QString sqllastshown;
+   if (lastshown.isNull())
+       sqllastshown = "NULL";
+    else
+       sqllastshown = QString("\"%1\"")
+           .arg(lastshown.toString(Qt::ISODate).replace(QRegExp("-"),""));
+  
     QString thequery;
     thequery.sprintf("INSERT INTO videometadata (title,director,plot,"
                      "rating,year,userrating,length,filename,showlevel,"
-                     "coverfile,inetref,browse) VALUES "
+                     "coverfile,inetref,browse, lastshown) VALUES "
                      "(\"%s\",\"%s\",\"%s\",\"%s\",%d,%f,%d,\"%s\",%d,\"%s\","
-                     "\"%s\", %d);",
+                     "\"%s\", %d, %s);",
                      title.utf8().data(), director.utf8().data(),
                      plot.utf8().data(), rating.utf8().data(), year,
                      userrating, length, sqlfilename.utf8().data(), showlevel,
-                     sqlcoverfile.utf8().data(), inetref.utf8().data(),browse);
+                     sqlcoverfile.utf8().data(), inetref.utf8().data(),browse,
+                     sqllastshown.utf8().data());
 
     db->exec(thequery);
 
@@ -346,18 +356,26 @@
 
     int idCategory = getIdCategory(db);
 
+    QString sqllastshown;
+    if (lastshown.isNull())
+       sqllastshown = "NULL";
+    else
+       sqllastshown = QString("\"%1\"")
+           .arg(lastshown.toString(Qt::ISODate).replace(QRegExp("-"),""));
+
     QString thequery;
     thequery.sprintf("UPDATE videometadata SET title=\"%s\",director=\"%s\","
                      "plot=\"%s\",rating=\"%s\",year=%d,userrating=%f,"
                      "length=%d,filename=\"%s\",showlevel=%d,coverfile=\"%s\","
                      "inetref=\"%s\",browse=%d,playcommand=\"%s\",childid=%d,"
-		     "category=%d"
+		     "category=%d, lastshown=%s"
                      " WHERE intid=%d",
                      title.utf8().data(), director.utf8().data(),
                      plot.utf8().data(), rating.utf8().data(), year,
                      userrating, length, sqlfilename.utf8().data(), showlevel,
                      sqlcoverfile.utf8().data(), inetref.utf8().data(), browse,
-                     playcommand.utf8().data(), childID, idCategory, id);
+                     playcommand.utf8().data(), childID, idCategory,
+                     sqllastshown.utf8().data(), id);
 
     QSqlQuery a_query(thequery, db);
     if(!a_query.isActive())
Index: mythvideo/mythvideo/metadata.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/metadata.h,v
retrieving revision 1.9
diff -u -r1.9 metadata.h
--- mythvideo/mythvideo/metadata.h	2 Mar 2004 17:57:53 -0000	1.9
+++ mythvideo/mythvideo/metadata.h	28 May 2004 15:34:52 -0000
@@ -61,6 +61,7 @@
 	category = other.category;
 	genres = other.genres;
 	countries = other.countries;
+	lastshown = other.lastshown;
     }
 
    ~Metadata() {}
@@ -117,6 +118,9 @@
 
     QStringList Countries() const { return countries;}
     void setCountries(QStringList lcountries){countries = lcountries;}
+   
+    QDate LastShown() const {return lastshown;}
+    void setLastShown (QDate llastshown) {lastshown = llastshown;}
 
     void guessTitle();
     void setField(QString field, QString data);
@@ -146,6 +150,7 @@
     int length;
     int showlevel;
     bool browse;
+    QDate lastshown;
     QString playcommand;
     QString category;
     QStringList genres;
Index: mythvideo/mythvideo/video-ui.xml
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/video-ui.xml,v
retrieving revision 1.26
diff -u -r1.26 video-ui.xml
--- mythvideo/mythvideo/video-ui.xml	22 May 2004 19:31:41 -0000	1.26
+++ mythvideo/mythvideo/video-ui.xml	28 May 2004 15:34:54 -0000
@@ -1013,10 +1013,10 @@
 			<font>display</font>
 			<value>User Rating :</value>
 		</textarea>
-		<textarea name="browse_text" draworder="0" align="right">
+		<textarea name="lastshown_text" draworder="0" align="right">
 			<area>50,340,320,40</area>
 			<font>display</font>
-			<value>Browse :</value>
+			<value>Last shown :</value>
 		</textarea>
 		<textarea name="orderby_text" draworder="0" align="right">
 			<area>50,380,320,40</area>
@@ -1072,7 +1072,7 @@
 			<image function="off" filename="mv_leftright_off.png"></image>
 			<image function="pushed" filename="mv_leftright_pushed.png"></image>
 		</selector>
-		<selector name="browse_select" draworder="0">
+		<selector name="lastshown_select" draworder="0">
 			<area>380,335,300,40</area>
 			<font>display</font>
 			<image function="on" filename="mv_leftright_on.png"></image>
Index: mythvideo/mythvideo/videobrowser.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videobrowser.cpp,v
retrieving revision 1.31
diff -u -r1.31 videobrowser.cpp
--- mythvideo/mythvideo/videobrowser.cpp	22 May 2004 19:31:42 -0000	1.31
+++ mythvideo/mythvideo/videobrowser.cpp	28 May 2004 15:35:01 -0000
@@ -347,9 +347,9 @@
         while (query.next())
         {
             unsigned int idnum = query.value(0).toUInt();
-            bool is_browsable = query.value(1).toBool();
-            if(is_browsable)
-            {
+    //        bool is_browsable = query.value(1).toBool();
+    //        if(is_browsable)
+    //        {
                 myData = new Metadata();
                 myData->setID(idnum);
                 myData->fillDataFromID(db);
@@ -358,7 +358,7 @@
                     m_list.append(*myData);
                 }
                 delete myData;
-            }
+      //      }
         }
     }
     updateML = false;
@@ -428,6 +428,11 @@
 
     Metadata *childItem = new Metadata;
     Metadata *parentItem = new Metadata(*curitem);
+    //set lastshown property to current date
+    QDate ldate;
+    parentItem->setLastShown(ldate.currentDate());
+    parentItem->updateDatabase(db);
+
 
     while (parentItem->ChildID() > 0 && playing_time.elapsed() > 10000)
     {
@@ -440,12 +445,19 @@
             selected(childItem);
             playing_time.start();
             myth_system((QString("%1 ") .arg(m_cmd)).local8Bit());
-        }
+            //Set lastshown property to currentdate
+            childItem->setLastShown(ldate.currentDate());
+            childItem->updateDatabase(db);
+
+       }
 
         delete parentItem;
         parentItem = new Metadata(*childItem);
     }
 
+    parentItem->setLastShown(QDate::currentDate());
+    parentItem->updateDatabase(db);
+
     delete childItem;
     delete parentItem;
 
Index: mythvideo/mythvideo/videofilter.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videofilter.cpp,v
retrieving revision 1.2
diff -u -r1.2 videofilter.cpp
--- mythvideo/mythvideo/videofilter.cpp	24 May 2004 01:19:11 -0000	1.2
+++ mythvideo/mythvideo/videofilter.cpp	28 May 2004 15:35:03 -0000
@@ -1,7 +1,7 @@
 /*
-	editmetadata.cpp
+	videofilter.cpp
 
-	(c) 2003 Thor Sigvaldason, Isaac Richards, and ?? ??
+	(c) 2003 Xavier Hervy
 	Part of the mythTV project
 	
 
@@ -22,7 +22,7 @@
 		year = gContext->GetNumSetting("VideoDefaultYear",-1);
 		runtime = gContext->GetNumSetting("VideoDefaultRuntime",-2);
 		userrating = gContext->GetNumSetting("VideoDefaultUserrating",-1);
-		browse = gContext->GetNumSetting("VideoDefaultBrowse",-1);
+		lastshown = gContext->GetNumSetting("VideoDefaultLastShown",-2);
 		orderby = gContext->GetNumSetting("VideoDefaultOrderby",0);
 	}else{
 		category = -1;
@@ -31,10 +31,12 @@
 		year = -1;
 		runtime = -2;
 		userrating = -1;
-		browse = -1;
+		lastshown = -2;
 		orderby = 0;
 
 	}
+	//if loaddefaultsettings == true then we are in browse mode
+	browse = loaddefaultsettings;
 }
 
 VideoFilterSettings::VideoFilterSettings(VideoFilterSettings *other)
@@ -46,7 +48,7 @@
 	year = other->year;
 	runtime = other->runtime;
 	userrating = other->userrating;
-	browse = other->browse;
+	lastshown = other->lastshown;
 	orderby = other->orderby;
 	db = other->db;
 }
@@ -63,7 +65,7 @@
     gContext->SaveSetting("VideoDefaultYear", year);
     gContext->SaveSetting("VideoDefaultRuntime", runtime);
     gContext->SaveSetting("VideoDefaultUserrating", userrating);
-    gContext->SaveSetting("VideoDefaultBrowse", browse);
+    gContext->SaveSetting("VideoDefaultLastShown", lastshown);
     gContext->SaveSetting("VideoDefaultOrderby", orderby);
 }
 
@@ -167,12 +169,25 @@
 			where += QString(" AND userrating >= %1").arg(userrating);
 		else 
 			where = QString(" WHERE userrating >= %1").arg(userrating);
-	if (browse !=-1)
+	if (lastshown !=-2)
+		if (lastshown==-1)
+			if (where)
+				where += QString(" AND lastshown is NULL ");
+			else 
+				where = QString(" WHERE lastshown is NULL ");
+
+	else
+			if (where)
+
+				where += QString(" AND (lastshown IS NULL OR TO_DAYS(curdate())-TO_DAYS(lastshown) >= %1)").arg(lastshown);
+			else 
+				where = QString(" WHERE (lastshown IS NULL OR TO_DAYS(curdate()-TO_DAYS(lastshown) >== %1)").arg(lastshown);
+	if (browse)
 		if (where)
-			where += QString(" AND browse >= %1").arg(browse);
-		else 
-			where = QString(" WHERE browse >= %1").arg(browse);
-return where;
+			where += QString(" AND browse = 1");
+		else
+			where = QString(" WHERE browse = 1");
+	return where;
 }
 
 QString VideoFilterSettings::BuildClauseOrderBy(){
@@ -203,27 +218,6 @@
 				tr("Result of this filter : No Videos")));
 		}
 	}
-/*	QString q_string = QString("SELECT * FROM videometadata");
-	QSqlQuery a_query(q_string,db);
-	if(a_query.isActive() && numvideos_text)  
-		if (a_query.numRowsAffected()>0){
-			int numvideo = a_query.numRowsAffected(); 
-			QString select = QString("SELECT * FROM ");
-			QString from = currentSettings->BuildClauseFrom();
-			QString where = currentSettings->BuildClauseWhere();
-			q_string = QString("%1 %2 %3")
-					.arg(select).arg(from).arg(where);
-			a_query.exec(q_string);
-			if(a_query.isActive())  
-				numvideos_text->SetText(
-				QString(tr("%1 of %2"))
-					.arg(a_query.numRowsAffected())
-					.arg(numvideo));
-		}
-		else{	
-			numvideos_text->SetText(QString(tr("No Videos")));
-
-		}*/
 }
 void VideoFilterDialog::fillWidgets()
 {
@@ -325,8 +319,6 @@
 		}
 		else
 		{
-		    /*QString s = QString("%1 " + tr("minutes") + " ~ " + "%2 " + tr("minutes"));
-		    s.arg(a_query.value(0).toInt()*30).arg((a_query.value(0).toInt()+1)*30); */
 		    QString s = QString("%1 ").arg(a_query.value(0).toInt()*30);
 		    s += tr("minutes");
 		    s += " ~ " + QString("%1 ").arg((a_query.value(0).toInt()+1)*30);
@@ -355,12 +347,81 @@
 	}
 	userrating_select->setToItem(currentSettings->getUserrating());
     }
-    if (browse_select)
+    if (lastshown_select)
     {
-	browse_select->addItem(-1,"All");
-	browse_select->addItem(1,"Yes");
-	browse_select->addItem(0,"No");
-	browse_select->setToItem(currentSettings->getBrowse());
+
+	lastshown_select->addItem(-2,"All");
+	lastshown_select->addItem(-1,"Never");
+	//by last years
+	QString q_string = QString("SELECT FLOOR((TO_DAYS(curdate())"
+                                   "-TO_DAYS(lastshown))/365) "
+				   "FROM videometadata "
+				   "WHERE lastshown IS NOT NULL "
+			    "AND TO_DAYS(curdate())-TO_DAYS(lastshown) > 364 "
+			       "GROUP BY FLOOR((TO_DAYS(curdate())"
+                               "-TO_DAYS(lastshown))/365) DESC;");
+	QSqlQuery a_query(q_string, db);
+	if(a_query.isActive()&&a_query.numRowsAffected()>0)
+	{
+		while(a_query.next())
+		{
+		    QString s = QString(tr("More than %1 year(s)")).arg(a_query.value(0).toInt());
+		    lastshown_select->addItem(a_query.value(0).toInt()*365,s);
+		}
+	}
+	//by last months
+	q_string = QString("SELECT FLOOR((TO_DAYS(curdate())"
+                            "-TO_DAYS(lastshown))/30) "
+			    "FROM videometadata "
+			    "WHERE lastshown IS NOT NULL "
+			    "AND TO_DAYS(curdate())-TO_DAYS(lastshown) > 29 "
+			    " AND TO_DAYS(curdate())-TO_DAYS(lastshown) < 365 "
+			    "GROUP BY FLOOR((TO_DAYS(curdate())"
+                            "-TO_DAYS(lastshown))/30) DESC;");
+	a_query.exec(q_string);
+	if(a_query.isActive()&&a_query.numRowsAffected()>0)
+	{
+		while(a_query.next())
+		{
+		    QString s = QString(tr("More than %1 month(s)"))
+                               .arg(a_query.value(0).toInt());
+		    lastshown_select->addItem(a_query.value(0).toInt()*30,s);
+		}
+	}
+	//by last weeks
+	q_string = QString("SELECT FLOOR((TO_DAYS(curdate())-TO_DAYS(lastshown))/7) "
+					"FROM videometadata "
+					"WHERE lastshown IS NOT NULL "
+					"AND TO_DAYS(curdate())-TO_DAYS(lastshown) > 6 "
+					" AND TO_DAYS(curdate())-TO_DAYS(lastshown) < 30 "
+					"GROUP BY FLOOR((TO_DAYS(curdate())-TO_DAYS(lastshown))/7) DESC;");
+	a_query.exec(q_string);
+	if(a_query.isActive()&&a_query.numRowsAffected()>0)
+	{
+		while(a_query.next())
+		{
+		    QString s = QString(tr("More than %1 week(s)")).arg(a_query.value(0).toInt());
+		    lastshown_select->addItem(a_query.value(0).toInt()*7,s);
+	}
+
+
+
+	//by last 6 days
+	q_string = QString("SELECT TO_DAYS(curdate())-TO_DAYS(lastshown) "
+					"FROM videometadata "
+					"WHERE TO_DAYS(curdate()) - TO_DAYS(lastshown)<7 "
+                                        " AND lastshown IS NOT NULL "
+					"GROUP BY TO_DAYS(curdate())-TO_DAYS(lastshown) DESC;");
+	a_query.exec(q_string);
+	if(a_query.isActive()&&a_query.numRowsAffected()>0)
+	{
+		while(a_query.next())
+		{
+		    QString s = QString("More than %1 day(s)").arg(a_query.value(0).toInt());
+		    lastshown_select->addItem(a_query.value(0).toInt(),s);
+		}
+	}
+	lastshown_select->setToItem(currentSettings->getLastShown());
     }
     if (orderby_select)
     {
@@ -371,7 +432,7 @@
 	orderby_select->setToItem(currentSettings->getOrderby());
     }
 }
-
+}
 void VideoFilterDialog::keyPressEvent(QKeyEvent *e)
 {
     bool handled = false;
@@ -405,8 +466,8 @@
 		currentSelector = runtime_select;	
 	   if ((userrating_select)&&(getCurrentFocusWidget() == userrating_select)) 
 		currentSelector = userrating_select;
-	    if ((browse_select)&&(getCurrentFocusWidget() == browse_select)) 
-		currentSelector = browse_select;
+	    if ((lastshown_select)&&(getCurrentFocusWidget() == lastshown_select)) 
+		currentSelector = lastshown_select;
 	    if ((orderby_select)&&(getCurrentFocusWidget() == orderby_select))
 		currentSelector = orderby_select;
 	    if(currentSelector)
@@ -463,7 +524,7 @@
 	originalSettings->setYear(currentSettings->getYear());
 	originalSettings->setRuntime(currentSettings->getRuntime());
 	originalSettings->setUserrating(currentSettings->getUserrating());
-	originalSettings->setBrowse(currentSettings->getBrowse());
+	originalSettings->setLastShown(currentSettings->getLastShown());
 	originalSettings->setOrderby(currentSettings->getOrderby());
     }
     done(0);
@@ -493,8 +554,8 @@
 	currentSettings->setRuntime(new_runtime);
 	update_numvideo();
 }
-void VideoFilterDialog::setBrowse(int new_browse){
-	currentSettings->setBrowse(new_browse);
+void VideoFilterDialog::setLastShown(int new_lastshown){
+	currentSettings->setLastShown(new_lastshown);
 	update_numvideo();
 }
 void VideoFilterDialog::setOrderby(int new_orderby){
@@ -533,10 +594,10 @@
 	connect(runtime_select, SIGNAL(pushed(int)),
 		this, SLOT(setRunTime(int)));
 
-    browse_select = getUISelectorType("browse_select");
-    if (browse_select)
-	connect(browse_select, SIGNAL(pushed(int)),
-		this, SLOT(setBrowse(int)));
+    lastshown_select = getUISelectorType("lastshown_select");
+    if (lastshown_select)
+	connect(lastshown_select, SIGNAL(pushed(int)),
+		this, SLOT(setLastShown(int)));
 
     orderby_select = getUISelectorType("orderby_select");
     if (orderby_select)
Index: mythvideo/mythvideo/videofilter.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videofilter.h,v
retrieving revision 1.1
diff -u -r1.1 videofilter.h
--- mythvideo/mythvideo/videofilter.h	2 Mar 2004 17:57:54 -0000	1.1
+++ mythvideo/mythvideo/videofilter.h	28 May 2004 15:35:03 -0000
@@ -43,8 +43,8 @@
 /*		int getShowlevel(void){return showlevel;};
 		void setShowlevel (int lshowlevel)
 			{showlevel = lshowlevel;};*/
-		int getBrowse(void){return browse;};
-		void setBrowse(int lbrowse){browse = lbrowse;};
+		int getLastShown(void){return lastshown;};
+		void setLastShown(int llastshown){lastshown = llastshown;};
 		int getOrderby (void) {return orderby;};
 		void setOrderby (int lorderby) {orderby = lorderby;};
 	private : 
@@ -54,8 +54,8 @@
 		int year;
 		int runtime;
 		int userrating;
-//		int showlevel;
-		int browse;
+                bool browse;
+		int lastshown;
 		int orderby;
 		QSqlDatabase	*db;
 };
@@ -96,7 +96,7 @@
     void setGenre(int new_genre);
     void setRunTime(int new_runtime);
 //    void setShowlevel(int new_showlevel);
-    void setBrowse(int new_browse);
+    void setLastShown(int new_lastshown);
     void setOrderby(int new_orderby);
  private:
     void update_numvideo();
@@ -107,7 +107,7 @@
     //  GUI Stuff
     //
 //    UISelectorType      *showlevel_select;
-    UISelectorType      *browse_select;
+    UISelectorType      *lastshown_select;
     UISelectorType      *orderby_select;
     UISelectorType      *year_select;
     UISelectorType	*userrating_select;


More information about the mythtv-dev mailing list