[mythtv] Patch - LiveTV channel favorites

Chris Martin dev at cgmartin.com
Fri Feb 28 00:35:31 EST 2003


Here's a patch against CVS (as of 28 Feb 2003 04:54:30 -0000) for 
channel favorites. This includes everything from the last patch I've 
posted to this thread, including some new EPG stuff.

*) Can now edit favorite channels within the EPG - Move program 
selection to any program on the channel you'd like to set/unset as a 
favorite and press the '/' key. Channels marked as a favorite will have 
asterisk(s) next to the channel name.

*) Can toggle EPG channel listings by All channels or ONLY Favorite 
Channels by pressing the '4' key.

*) While watching LiveTV, you can cycle through your Favorite Channels 
by pressing the '/' key. (FYI from the last patch)

Please try it out and let me know if you have any problems...

To install the patch, update your CVS source and run the following...
    $ cd mythtv/MC
    $ patch -p0 < {path_to}/favorites-epg.patch
...then recompile.

You also need to add the favorites table to the database...look in 
MC/databases/cvs.sql after running the patch.

-- 
-Chris Martin

-------------- next part --------------
Index: keys.txt
===================================================================
RCS file: /var/lib/cvs/MC/keys.txt,v
retrieving revision 1.14
diff -u -d -r1.14 keys.txt
--- keys.txt	22 Feb 2003 01:06:33 -0000	1.14
+++ keys.txt	28 Feb 2003 04:54:30 -0000
@@ -28,6 +28,8 @@
 - ] to increase volume
 - | to toggle mute
 - Z to skip through current commercial(s)
+- / to jump to the next "favorite" channel
+- ? to mark/unmark the current channel as a "favorite"
 
 Without the stickykeys option selected:
 
@@ -92,6 +94,9 @@
   are selected for the highlighted entry.
 - Pressing X will change the channel to the currently selected channel without
   leaving the EPG (Most useful in the alternate EPG)
+- Pressing '/' will mark/unmark the current channel as a "favorite"
+- Pressing 4 will toggle the guide listing between all channels, and filtered
+  "favorites".
 
 Remote Controls
 ---------------
Index: database/cvs.sql
===================================================================
RCS file: /var/lib/cvs/MC/database/cvs.sql,v
retrieving revision 1.10
diff -u -d -r1.10 cvs.sql
--- database/cvs.sql	16 Feb 2003 19:25:37 -0000	1.10
+++ database/cvs.sql	28 Feb 2003 04:54:31 -0000
@@ -10,3 +10,10 @@
 ALTER TABLE capturecard ADD COLUMN vbidevice VARCHAR(255);
 REPLACE INTO settings (value, data) VALUES ("LCDHost","localhost");
 REPLACE INTO settings (value, data) VALUES ("LCDPort","13666");
+
+CREATE TABLE favorites (
+	favid int(11) unsigned NOT NULL auto_increment,
+	userid int(11) unsigned NOT NULL default '0',
+	chanid int(11) unsigned NOT NULL default '0',
+	PRIMARY KEY  (favid)
+) TYPE=MyISAM;
Index: libs/libmythtv/channel.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/channel.cpp,v
retrieving revision 1.27
diff -u -d -r1.27 channel.cpp
--- libs/libmythtv/channel.cpp	22 Feb 2003 01:06:33 -0000	1.27
+++ libs/libmythtv/channel.cpp	28 Feb 2003 04:54:31 -0000
@@ -121,7 +121,7 @@
         if (name == listname)
         {
             curList = chanlists[i].list;
-	    totalChannels = chanlists[i].count;
+	    	totalChannels = chanlists[i].count;
             break;
         }
         i++;
@@ -130,7 +130,7 @@
     if (!curList)
     {
         curList = chanlists[0].list;
-	totalChannels = chanlists[0].count;
+		totalChannels = chanlists[0].count;
     }
 }
   
@@ -196,7 +196,7 @@
 
 bool Channel::ChannelUp(void)
 {
-    QString nextchan = pParent->GetNextChannel(this, true);
+    QString nextchan = pParent->GetNextChannel(this, CHANNEL_DIRECTION_UP);
     if (SetChannelByString(nextchan))
         return true;
 
@@ -229,7 +229,7 @@
 
 bool Channel::ChannelDown(void)
 {
-    QString nextchan = pParent->GetNextChannel(this, false);
+    QString nextchan = pParent->GetNextChannel(this, CHANNEL_DIRECTION_DOWN);
     if (SetChannelByString(nextchan))
         return true;
 
@@ -257,7 +257,12 @@
         }
     }
 
-    return false;
+    return finished;
+}
+
+bool Channel::NextFavorite(void) {
+	QString nextchan = pParent->GetNextChannel(this, CHANNEL_DIRECTION_FAVORITE);
+	return SetChannelByString(nextchan);
 }
 
 QString Channel::GetCurrentName(void)
Index: libs/libmythtv/channel.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/channel.h,v
retrieving revision 1.14
diff -u -d -r1.14 channel.h
--- libs/libmythtv/channel.h	15 Dec 2002 22:06:49 -0000	1.14
+++ libs/libmythtv/channel.h	28 Feb 2003 04:54:31 -0000
@@ -26,6 +26,7 @@
     bool SetChannelByString(const QString &chan); 
     bool ChannelUp(void);
     bool ChannelDown(void);
+    bool NextFavorite(void);
 
     int ChangeColour(bool up);
     int ChangeBrightness(bool up);
Index: libs/libmythtv/guidegrid.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/guidegrid.cpp,v
retrieving revision 1.89
diff -u -d -r1.89 guidegrid.cpp
--- libs/libmythtv/guidegrid.cpp	26 Feb 2003 13:47:40 -0000	1.89
+++ libs/libmythtv/guidegrid.cpp	28 Feb 2003 04:54:31 -0000
@@ -66,9 +66,10 @@
                      const char *name)
          : MythDialog(parent, name)
 {
-    DISPLAY_CHANS = 6;
+    desiredDisplayChans = DISPLAY_CHANS = 6;
     DISPLAY_TIMES = 30;
     int maxchannel = 0;
+	showFavorites = false;
 
     m_player = player;
     m_db = QSqlDatabase::database();
@@ -100,7 +101,7 @@
     if (programGuideType == 1)
     {
 	int dNum = gContext->GetNumSetting("chanPerPage", 8);
-	DISPLAY_CHANS = dNum;
+	desiredDisplayChans = DISPLAY_CHANS = dNum;
 
 	dNum = gContext->GetNumSetting("timePerPage", 5);
         if (dNum > 5)
@@ -210,9 +211,11 @@
 
     accel->connectItem(accel->insertItem(Key_7), this, SLOT(dayLeft()));
     accel->connectItem(accel->insertItem(Key_1), this, SLOT(dayRight()));
+    accel->connectItem(accel->insertItem(Key_4), this, SLOT(toggleGuideListing()));
     accel->connectItem(accel->insertItem(Key_6), this, SLOT(showProgFinder()));
     accel->connectItem(accel->insertItem(Key_9), this, SLOT(pageUp()));
     accel->connectItem(accel->insertItem(Key_3), this, SLOT(pageDown()));
+    accel->connectItem(accel->insertItem(Key_Slash), this, SLOT(toggleChannelFavorite()));
 
     accel->connectItem(accel->insertItem(Key_C), this, SLOT(escape()));
     accel->connectItem(accel->insertItem(Key_Escape), this, SLOT(escape()));
@@ -375,9 +378,9 @@
 void GuideGrid::createProgramBar(QBoxLayout *holdingTank)
 {
 	QLabel *leftFiller = NULL;
-        QLabel *currentButton = new QLabel("   (4) Current Programs   ", this);
-        QLabel *futureButton = new QLabel("   (6) Program Finder   ", this);
-        QLabel *rightFiller = new QLabel("   ", this);
+	currentButton = new QLabel("   (4) Favorite Programs   ", this);
+	QLabel *futureButton = new QLabel("   (6) Program Finder   ", this);
+	QLabel *rightFiller = new QLabel("   ", this);
 
 	QTime new_time = QTime::currentTime();
     	QString curTime = new_time.toString("h:mm:ss ap");
@@ -621,16 +624,39 @@
     }
 }
 
-void GuideGrid::fillChannelInfos(int &maxchannel)
+void GuideGrid::fillChannelInfos(int &maxchannel, bool gotostartchannel)
 {
     m_channelInfos.clear();
 
-    QString thequery;
+    QString queryfav;
     QSqlQuery query;
 
-    thequery = "SELECT channum,callsign,icon,chanid FROM channel "
-               "ORDER BY " + channelOrdering + ";";
-    query.exec(thequery);
+    QString queryall = "SELECT channel.channum, channel.callsign, channel.icon, "
+					   "channel.chanid, favorites.favid "
+					   "FROM channel LEFT JOIN favorites ON favorites.chanid = channel.chanid "
+               		   "ORDER BY " + channelOrdering + ";";
+
+	if (showFavorites)
+	{
+    	queryfav = "SELECT channel.channum, channel.callsign, "
+					"channel.icon, channel.chanid, favorites.favid "
+					"FROM favorites, channel "
+               		"WHERE channel.chanid = favorites.chanid "
+					"ORDER BY " + channelOrdering + ";";
+
+    	query.exec(queryfav);
+
+		// If we don't have any favorites, then just show regular listings.
+    	if (!query.isActive() || query.numRowsAffected() == 0)
+    	{
+			showFavorites = (!showFavorites);
+    		query.exec(queryall);
+		}
+	}
+	else
+	{
+    	query.exec(queryall);
+	}
     
     bool set = false;
     maxchannel = 0;
@@ -650,9 +676,10 @@
             if (val.chanstr == QString::null)
                 val.chanstr = "";
             val.chanid = query.value(3).toInt();
+            val.favid = query.value(4).toInt();
             val.icon = NULL;
         
-            if (val.chanstr == m_startChanStr && !set)
+            if (gotostartchannel && val.chanstr == m_startChanStr && !set)
             {
                 m_currentStartChannel = m_channelInfos.size();
                 set = true;
@@ -930,6 +957,10 @@
         QFontMetrics lfm(*m_chanFont);
         int bheight = lfm.height();
 
+		QString favstr = "";
+		if (chinfo->favid > 0)
+			favstr = "*";
+
         if (programGuideType != 1)
         {
             if (chinfo->iconpath != "none" && chinfo->iconpath != "" && 
@@ -958,13 +989,15 @@
                              chinfo->chanstr);
             }
 
+			QString callsignstr = favstr + " " + chinfo->callsign + " " + favstr;
+			
             tmp.setFont(*m_chanCallsignFont);
             QFontMetrics fm(*m_chanCallsignFont);
-            int width = fm.width(chinfo->callsign);
+            int width = fm.width(callsignstr);
             int height = fm.height();
             tmp.drawText((cr.width() - width) / 2, 
                          ydifference * y + yoffset + bheight + height, 
-                         chinfo->callsign);
+                         callsignstr);
 
             tmp.drawLine(0, ydifference * (y + 1), cr.right(), 
                          ydifference * (y + 1));
@@ -974,9 +1007,9 @@
             QString chData;
 
             if (gContext->GetNumSetting("DisplayChanNum") != 0)
-                chData = chinfo->callsign;
+                chData = chinfo->callsign + " " + favstr;
             else
-                chData = chinfo->chanstr + " " + chinfo->callsign;
+                chData = chinfo->chanstr + " " + chinfo->callsign + " " + favstr;
 
             int width = lfm.width(chData);
 
@@ -1815,77 +1848,77 @@
 
 QRect GuideGrid::programRect() const
 {
-    QRect r;
-    if (programGuideType != 1)
-    {
-        // Change only these numbers to adjust the size of the visible regions
+		QRect r;
+		if (programGuideType != 1)
+		{
+				// Change only these numbers to adjust the size of the visible regions
 
-        unsigned int min_dateheight = 50;  // also min_timeheight
-        unsigned int min_datewidth = 74;   // also min_chanwidth
-        unsigned int titleheight = showtitle ? 40 : 0;
+				unsigned int min_dateheight = 50;  // also min_timeheight
+				unsigned int min_datewidth = 74;   // also min_chanwidth
+				unsigned int titleheight = showtitle ? 40 : 0;
 
-        unsigned int programheight = (int)((600 - min_dateheight - 
-                                           titleheight) * wmult);
+				unsigned int programheight = (int)((600 - min_dateheight - 
+										titleheight) * wmult);
 
-	if (showProgramBar == 0)
-        	programheight = DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS);
-	else
-		programheight = (DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS)) - 
-				(int)(25 * 1.5);
+				if (showProgramBar == 0)
+						programheight = DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS);
+				else
+						programheight = (DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS)) - 
+								(int)(25 * 1.5);
 
-        unsigned int programwidth = (int)((800 - min_datewidth) * hmult);
-        programwidth = DISPLAY_TIMES * (int)(programwidth / DISPLAY_TIMES);
+				unsigned int programwidth = (int)((800 - min_datewidth) * hmult);
+				programwidth = DISPLAY_TIMES * (int)(programwidth / DISPLAY_TIMES);
 
-	if (showProgramBar == 0)
-	{
-        	r = QRect((int)(800 * wmult) - programwidth, 
-                    (int)(600 * hmult) - programheight - titleheight,
-                    programwidth, programheight);
-	}
-	else
-	{
-		r = QRect((int)(800 * wmult) - programwidth,
-                    (int)(600 * hmult) - programheight - titleheight - (int)(hmult*1.5*25),
-                    programwidth, programheight);
-	}
-    }
-    else
-    {
-        // Change only these numbers to adjust the size of the visible regions
-        unsigned int min_dateheight = 25;  // also min_timeheight
-        unsigned int min_datewidth = 100;   // also min_chanwidth
+				if (showProgramBar == 0)
+				{
+						r = QRect((int)(800 * wmult) - programwidth, 
+										(int)(600 * hmult) - programheight - titleheight,
+										programwidth, programheight);
+				}
+				else
+				{
+						r = QRect((int)(800 * wmult) - programwidth,
+										(int)(600 * hmult) - programheight - titleheight - (int)(hmult*1.5*25),
+										programwidth, programheight);
+				}
+		}
+		else
+		{
+				// Change only these numbers to adjust the size of the visible regions
+				unsigned int min_dateheight = 25;  // also min_timeheight
+				unsigned int min_datewidth = 100;   // also min_chanwidth
 
-        unsigned int programheight;
+				unsigned int programheight;
 
-	if (showProgramBar == 1)
-        {
-		programheight = (int)( (int)(300*hmult) - (int)(min_dateheight*2.5*hmult) );
-	}
-	else
-	{
-		programheight = (int)((int)(300*hmult) - (int)(min_dateheight*hmult));;;
-	}
+				if (showProgramBar == 1)
+				{
+						programheight = (int)( (int)(300*hmult) - (int)(min_dateheight*2.5*hmult) );
+				}
+				else
+				{
+						programheight = (int)((int)(300*hmult) - (int)(min_dateheight*hmult));;;
+				}
 
-        programheight = DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS);
+				//programheight = DISPLAY_CHANS * (int)(programheight / DISPLAY_CHANS);
 
-        unsigned int programwidth = (int)((800 - min_datewidth) * hmult);
-        programwidth = DISPLAY_TIMES * (int)(programwidth / DISPLAY_TIMES);
+				unsigned int programwidth = (int)((800 - min_datewidth) * hmult);
+				programwidth = DISPLAY_TIMES * (int)(programwidth / DISPLAY_TIMES);
 
-        if (showProgramBar == 1)
-	{
-             r = QRect((int)(800 * wmult) - programwidth,
-                  (int)(600 * hmult) - programheight - (int)(hmult*1.5*min_dateheight),
-                  programwidth, programheight);
-	}
-	else
-	{
-	     r = QRect((int)(800 * wmult) - programwidth,
-                  (int)(600 * hmult) - programheight,
-                  programwidth, programheight);
-	}
-    }
+				if (showProgramBar == 1)
+				{
+						r = QRect((int)(800 * wmult) - programwidth,
+										(int)(600 * hmult) - programheight - (int)(hmult*1.5*min_dateheight),
+										programwidth, programheight);
+				}
+				else
+				{
+						r = QRect((int)(800 * wmult) - programwidth,
+										(int)(600 * hmult) - programheight,
+										programwidth, programheight);
+				}
+		}
 
-    return r;
+		return r;
 }
 
 QRect GuideGrid::infoRect() const
@@ -1972,6 +2005,7 @@
     }
 }
 
+
 void GuideGrid::cursorUp()
 {
     m_currentRow--;
@@ -2098,6 +2132,84 @@
         update(titleRect());
     if (programGuideType == 1)
         update(infoRect());
+}
+
+void GuideGrid::toggleGuideListing()
+{
+	showFavorites = (!showFavorites);
+	generateListings();
+}
+
+void GuideGrid::generateListings()
+{
+    m_currentStartChannel = 0;
+    m_currentRow = 0;
+
+	int maxchannel = 0;
+	DISPLAY_CHANS = desiredDisplayChans;
+    fillChannelInfos(maxchannel);
+    if (DISPLAY_CHANS > maxchannel)
+        DISPLAY_CHANS = maxchannel;
+
+    fillProgramInfos();
+
+	if (showFavorites)
+		currentButton->setText("   (4) All Programs   ");
+	else
+		currentButton->setText("   (4) Favorite Programs   ");
+
+    update(channelRect());
+    update(programRect());
+	if (showtitle)
+		update(titleRect());
+	if (programGuideType == 1)
+		update(infoRect());
+
+}
+
+void GuideGrid::toggleChannelFavorite()
+{
+	QString thequery;
+    QSqlQuery query;
+
+	// Get current channel id, and make sure it exists...
+    int chanNum = m_currentRow + m_currentStartChannel;
+    if (chanNum >= (int)m_channelInfos.size())
+        chanNum -= (int)m_channelInfos.size();
+    if (chanNum < 0)
+        chanNum = 0;
+
+    int favid = m_channelInfos[chanNum].favid;
+    int chanid = m_channelInfos[chanNum].chanid;
+
+	if (favid > 0) 
+	{
+		thequery = QString("DELETE FROM favorites WHERE favid = '%1'")
+						   .arg(favid);
+
+		query.exec(thequery);
+    }
+    else
+    {
+		// We have no favorites record...Add one to toggle...
+		thequery = QString("INSERT INTO favorites (chanid) VALUES ('%1')")
+						   .arg(chanid);
+
+		query.exec(thequery);
+	}
+
+	if (showFavorites)
+		generateListings();
+	else
+	{
+		int maxchannel = 0;
+		DISPLAY_CHANS = desiredDisplayChans;
+    	fillChannelInfos(maxchannel, false);
+    	if (DISPLAY_CHANS > maxchannel)
+        	DISPLAY_CHANS = maxchannel;
+
+    	update(channelRect());
+	}
 }
 
 void GuideGrid::dayLeft()
Index: libs/libmythtv/guidegrid.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/guidegrid.h,v
retrieving revision 1.38
diff -u -d -r1.38 guidegrid.h
--- libs/libmythtv/guidegrid.h	5 Feb 2003 19:46:51 -0000	1.38
+++ libs/libmythtv/guidegrid.h	28 Feb 2003 04:54:31 -0000
@@ -61,6 +61,9 @@
     void pageRight();
     void pageDown();
     void pageUp();
+	void toggleGuideListing();
+	void toggleChannelFavorite();
+	void generateListings();
 
     void enter();
     void escape();
@@ -92,7 +95,7 @@
     QRect titleRect() const;
     QRect infoRect() const;
 
-    void fillChannelInfos(int &maxchannel);
+    void fillChannelInfos(int &maxchannel, bool gotostartchannel = true);
 
     void fillTimeInfos();
 
@@ -118,6 +121,7 @@
     QLabel *descriptionfield;
     QLabel *currentTime;
     QLabel *currentChan;
+	QLabel *currentButton;
 
     QFont *m_timeFont;
     QFont *m_chanFont;
@@ -143,6 +147,7 @@
     bool selectState;
     bool showInfo;
     bool showIcon;
+	bool showFavorites;
 
     bool showtitle;
     bool usetheme;
@@ -153,6 +158,7 @@
 
     int startChannel;
     int programGuideType;
+    int desiredDisplayChans;
     int DISPLAY_CHANS;
     int DISPLAY_TIMES;
 
Index: libs/libmythtv/infostructs.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/infostructs.h,v
retrieving revision 1.13
diff -u -d -r1.13 infostructs.h
--- libs/libmythtv/infostructs.h	5 Feb 2003 19:46:51 -0000	1.13
+++ libs/libmythtv/infostructs.h	28 Feb 2003 04:54:31 -0000
@@ -17,6 +17,7 @@
     QString iconpath;
     QString chanstr;
     int chanid;
+    int favid;
 
     QPixmap *icon;
 };
Index: libs/libmythtv/remoteencoder.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/remoteencoder.cpp,v
retrieving revision 1.4
diff -u -d -r1.4 remoteencoder.cpp
--- libs/libmythtv/remoteencoder.cpp	16 Feb 2003 19:25:37 -0000	1.4
+++ libs/libmythtv/remoteencoder.cpp	28 Feb 2003 04:54:31 -0000
@@ -226,11 +226,19 @@
     SendReceiveStringList(strlist);
 }
 
-void RemoteEncoder::ChangeChannel(bool direction)
+void RemoteEncoder::ToggleChannelFavorite(void)
+{
+    QStringList strlist = QString("QUERY_RECORDER %1").arg(recordernum);
+    strlist << "TOGGLE_CHANNEL_FAVORITE";
+
+    SendReceiveStringList(strlist);
+}
+
+void RemoteEncoder::ChangeChannel(int channeldirection)
 {
     QStringList strlist = QString("QUERY_RECORDER %1").arg(recordernum);
     strlist << "CHANGE_CHANNEL";
-    strlist << QString::number((int)direction);
+    strlist << QString::number(channeldirection);
 
     SendReceiveStringList(strlist);
 }
Index: libs/libmythtv/remoteencoder.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/remoteencoder.h,v
retrieving revision 1.4
diff -u -d -r1.4 remoteencoder.h
--- libs/libmythtv/remoteencoder.h	6 Feb 2003 04:37:27 -0000	1.4
+++ libs/libmythtv/remoteencoder.h	28 Feb 2003 04:54:31 -0000
@@ -36,7 +36,8 @@
     void ChangeContrast(bool direction);
     void ChangeBrightness(bool direction);
     void ChangeColour(bool direction);
-    void ChangeChannel(bool direction);
+    void ChangeChannel(int channeldirection);
+	void ToggleChannelFavorite(void);
     void SetChannel(QString channel);
     bool CheckChannel(QString channel);
     void GetChannelInfo(QString &title, QString &subtitle, QString &desc, 
Index: libs/libmythtv/tv.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv.h,v
retrieving revision 1.49
diff -u -d -r1.49 tv.h
--- libs/libmythtv/tv.h	9 Jan 2003 20:04:47 -0000	1.49
+++ libs/libmythtv/tv.h	28 Feb 2003 04:54:31 -0000
@@ -1,6 +1,10 @@
 #ifndef TV_H
 #define TV_H
 
+#define CHANNEL_DIRECTION_UP 0
+#define CHANNEL_DIRECTION_DOWN 1
+#define CHANNEL_DIRECTION_FAVORITE 2
+
 typedef enum 
 {
     kState_Error = -1,
Index: libs/libmythtv/tv_play.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.33
diff -u -d -r1.33 tv_play.cpp
--- libs/libmythtv/tv_play.cpp	25 Feb 2003 04:45:21 -0000	1.33
+++ libs/libmythtv/tv_play.cpp	28 Feb 2003 04:54:31 -0000
@@ -845,9 +845,11 @@
         {
             case 'i': case 'I': UpdateOSD(); break;
 
-            case wsUp: ChangeChannel(true); break;
+            case wsUp: ChangeChannel(CHANNEL_DIRECTION_UP); break;
+            case wsDown: ChangeChannel(CHANNEL_DIRECTION_DOWN); break;
 
-            case wsDown: ChangeChannel(false); break;
+            case '/': ChangeChannel(CHANNEL_DIRECTION_FAVORITE); break;
+			case '?': ToggleChannelFavorite(); break;
 
             case 'c': case 'C': ToggleInputs(); break;
 
@@ -1221,7 +1223,12 @@
     activenvp->Unpause();
 }
 
-void TV::ChangeChannel(bool up)
+void TV::ToggleChannelFavorite(void)
+{
+    activerecorder->ToggleChannelFavorite();
+}
+
+void TV::ChangeChannel(int direction)
 {
     bool muted = false;
 
@@ -1244,7 +1251,7 @@
 
     activerecorder->Pause();
     activerbuffer->Reset();
-    activerecorder->ChangeChannel(up);
+    activerecorder->ChangeChannel(direction);
 
     activenvp->ResetPlaying();
     while (!activenvp->ResetYet())
Index: libs/libmythtv/tv_play.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_play.h,v
retrieving revision 1.19
diff -u -d -r1.19 tv_play.h
--- libs/libmythtv/tv_play.h	25 Feb 2003 04:45:21 -0000	1.19
+++ libs/libmythtv/tv_play.h	28 Feb 2003 04:54:31 -0000
@@ -59,7 +59,8 @@
  private:
     void SetChannel(bool needopen = false);
 
-    void ChangeChannel(bool up);
+	void ToggleChannelFavorite(void);
+    void ChangeChannel(int direction);
     void ChangeChannelByString(QString &name);
 
     void ChangeVolume(bool up);
Index: libs/libmythtv/tv_rec.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_rec.cpp,v
retrieving revision 1.38
diff -u -d -r1.38 tv_rec.cpp
--- libs/libmythtv/tv_rec.cpp	25 Feb 2003 04:45:21 -0000	1.38
+++ libs/libmythtv/tv_rec.cpp	28 Feb 2003 04:54:31 -0000
@@ -877,10 +877,11 @@
     return ret;
 }
 
-QString TVRec::GetNextChannel(Channel *chan, bool direction)
+QString TVRec::GetNextChannel(Channel *chan, int channeldirection)
 {
     QString ret = "";
 
+	// Get info on the current channel we're on
     QString channum = chan->GetCurrentName();
     QString channelinput = chan->GetCurrentInput();
     QString device = chan->GetDevice();
@@ -940,23 +941,34 @@
         return ret;
     }
 
-    QString comp = ">";
-    QString ordering = "";
+	// Now lets try finding the next channel in the desired direction...
+   	QString comp = ">";
+   	QString ordering = "";
+	QString fromfavorites = "";
+	QString wherefavorites = "";
 
-    if (direction == false)
+	if (channeldirection == CHANNEL_DIRECTION_DOWN)
     {
         comp = "<";
         ordering = " DESC ";
     }
+	else if (channeldirection == CHANNEL_DIRECTION_FAVORITE)
+	{
+		fromfavorites = ",favorites";
+		wherefavorites = "AND favorites.chanid = channel.chanid";
+	}
 
     thequery = QString("SELECT channel.channum FROM channel,capturecard,"
-                       "cardinput WHERE channel.%1 %2 \"%3\" AND "
+                       "cardinput%1 WHERE "
+					   "channel.%2 %3 \"%4\" %5 AND "
                        "channel.sourceid = cardinput.sourceid AND "
-                       "cardinput.inputname = \"%4\" AND "
+                       "cardinput.inputname = \"%6\" AND "
                        "cardinput.cardid = capturecard.cardid AND "
-                       "capturecard.videodevice = \"%5\" ORDER BY %6 %7 "
+                       "capturecard.videodevice = \"%7\" "
+					   "ORDER BY %8 %9 "
                        "LIMIT 1;")
-                       .arg(channelorder).arg(comp).arg(id)
+                       .arg(fromfavorites).arg(channelorder)
+					   .arg(comp).arg(id).arg(wherefavorites)
                        .arg(channelinput).arg(device)
                        .arg(channelorder).arg(ordering);
 
@@ -972,19 +984,23 @@
     }
     else
     {
-        if (direction)        
-            comp = "<";
-        else
+		// Couldn't find the channel going the desired direction,
+		// so loop around and find it on the flip side...
+        comp = "<";
+        if (channeldirection == CHANNEL_DIRECTION_DOWN)        
             comp = ">";
 
         thequery = QString("SELECT channel.channum FROM channel,capturecard,"
-                           "cardinput WHERE channel.%1 %2 \"%3\" AND "
+                           "cardinput%1 WHERE "
+						   "channel.%2 %3 \"%4\" %5 AND "
                            "channel.sourceid = cardinput.sourceid AND "
-                           "cardinput.inputname = \"%4\" AND "
+                           "cardinput.inputname = \"%6\" AND "
                            "cardinput.cardid = capturecard.cardid AND "
-                           "capturecard.videodevice = \"%5\" ORDER BY %6 %7 "
+                           "capturecard.videodevice = \"%7\" "
+						   "ORDER BY %8 %9 "
                            "LIMIT 1;")
-                           .arg(channelorder).arg(comp).arg(id)
+                           .arg(fromfavorites).arg(channelorder)
+						   .arg(comp).arg(id).arg(wherefavorites)
                            .arg(channelinput).arg(device)
                            .arg(channelorder).arg(ordering);
 
@@ -1162,11 +1178,13 @@
     UnpauseRingBuffer();
 }
 
-void TVRec::ChangeChannel(bool direction)
+void TVRec::ChangeChannel(int channeldirection)
 {
     rbuffer->Reset();
     
-    if (direction)
+	if (channeldirection == CHANNEL_DIRECTION_FAVORITE) 
+		channel->NextFavorite();
+	else if (channeldirection == CHANNEL_DIRECTION_UP)
         channel->ChannelUp();
     else
         channel->ChannelDown();
@@ -1175,6 +1193,79 @@
     nvr->Unpause();
 
     UnpauseRingBuffer();
+}
+
+void TVRec::ToggleChannelFavorite(void)
+{
+	// Get current channel id...
+    QString channum = channel->GetCurrentName();
+    QString channelinput = channel->GetCurrentInput();
+    QString device = channel->GetDevice();
+
+    pthread_mutex_lock(&db_lock);
+
+    MythContext::KickDatabase(db_conn);
+
+    QString thequery = QString("SELECT channel.chanid FROM "
+                               "channel,capturecard,cardinput "
+                               "WHERE channel.channum = \"%1\" AND "
+                               "channel.sourceid = cardinput.sourceid AND "
+                               "cardinput.inputname = \"%2\" AND "
+                               "cardinput.cardid = capturecard.cardid AND "
+                               "capturecard.videodevice = \"%3\";")
+                               .arg(channum).arg(channelinput).arg(device);
+
+    QSqlQuery query = db_conn->exec(thequery);
+
+    QString chanid = QString::null;
+
+    if (query.isActive() && query.numRowsAffected() > 0)
+    {
+        query.next();
+
+        chanid = query.value(0).toString();
+    }
+    else
+    {
+        pthread_mutex_unlock(&db_lock);
+        cerr << "Channel: \'" << channum << "\' was not found in the database.";
+        cerr << "\nMost likely, your DefaultTVChannel setting is wrong.";
+        cerr << "\nCould not toggle favorite.\n";
+        return;
+    }
+
+	// Check if favorite exists for that chanid...
+    thequery = QString("SELECT favorites.favid FROM favorites WHERE "
+                       "favorites.chanid = \"%1\""
+                       "LIMIT 1;")
+                       .arg(chanid);
+
+    query = db_conn->exec(thequery);
+
+    if (!query.isActive())
+        MythContext::DBError("togglechannelfavorite", query);
+    else if (query.numRowsAffected() > 0)
+    {
+		// We have a favorites record...Remove it to toggle...
+        query.next();
+        QString favid = query.value(0).toString();
+
+		thequery = QString("DELETE FROM favorites WHERE favid = \"%1\"")
+						   .arg(favid);
+
+		query = db_conn->exec(thequery);
+		cout << "Removing Favorite.\n";
+    }
+    else
+    {
+		// We have no favorites record...Add one to toggle...
+		thequery = QString("INSERT INTO favorites (chanid) VALUES (\"%1\")")
+						   .arg(chanid);
+
+		query = db_conn->exec(thequery);
+		cout << "Adding Favorite.\n";
+	}
+	pthread_mutex_unlock(&db_lock);
 }
 
 void TVRec::ChangeContrast(bool direction)
Index: libs/libmythtv/tv_rec.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_rec.h,v
retrieving revision 1.17
diff -u -d -r1.17 tv_rec.h
--- libs/libmythtv/tv_rec.h	25 Feb 2003 04:45:21 -0000	1.17
+++ libs/libmythtv/tv_rec.h	28 Feb 2003 04:54:31 -0000
@@ -41,7 +41,7 @@
 
     bool CheckChannel(Channel *chan, const QString &channum, int &finetuning); 
     bool ChangeExternalChannel(const QString &channum);
-    QString GetNextChannel(Channel *chan, bool direction);
+    QString GetNextChannel(Channel *chan, int channeldirection);
 
     bool IsReallyRecording(void);
     float GetFramerate(void);
@@ -57,7 +57,8 @@
     void StopLiveTV(void);
     void PauseRecorder(void);
     void ToggleInputs(void);
-    void ChangeChannel(bool direction);
+    void ToggleChannelFavorite(void);
+    void ChangeChannel(int channeldirection);
     void SetChannel(QString name);
     void ChangeColour(bool direction);
     void ChangeContrast(bool direction);
Index: programs/mythbackend/encoderlink.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythbackend/encoderlink.cpp,v
retrieving revision 1.9
diff -u -d -r1.9 encoderlink.cpp
--- programs/mythbackend/encoderlink.cpp	25 Feb 2003 04:45:21 -0000	1.9
+++ programs/mythbackend/encoderlink.cpp	28 Feb 2003 04:54:31 -0000
@@ -193,10 +193,16 @@
         tv->ToggleInputs();
 }
 
-void EncoderLink::ChangeChannel(bool direction)
+void EncoderLink::ToggleChannelFavorite(void)
 {
     if (local)
-        tv->ChangeChannel(direction);
+        tv->ToggleChannelFavorite();
+}
+
+void EncoderLink::ChangeChannel(int channeldirection)
+{
+    if (local)
+        tv->ChangeChannel(channeldirection);
 }
 
 void EncoderLink::SetChannel(QString name)
Index: programs/mythbackend/encoderlink.h
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythbackend/encoderlink.h,v
retrieving revision 1.9
diff -u -d -r1.9 encoderlink.h
--- programs/mythbackend/encoderlink.h	14 Feb 2003 17:30:23 -0000	1.9
+++ programs/mythbackend/encoderlink.h	28 Feb 2003 04:54:31 -0000
@@ -44,7 +44,8 @@
     void StopLiveTV(void);
     void PauseRecorder(void);
     void ToggleInputs(void);
-    void ChangeChannel(bool direction);
+    void ToggleChannelFavorite(void);
+    void ChangeChannel(int channeldirection);
     void SetChannel(QString name);
     void ChangeContrast(bool direction);
     void ChangeBrightness(bool direction);
Index: programs/mythbackend/mainserver.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythbackend/mainserver.cpp,v
retrieving revision 1.33
diff -u -d -r1.33 mainserver.cpp
--- programs/mythbackend/mainserver.cpp	26 Feb 2003 04:39:04 -0000	1.33
+++ programs/mythbackend/mainserver.cpp	28 Feb 2003 04:54:32 -0000
@@ -685,10 +685,15 @@
         enc->ToggleInputs();
         retlist << "ok";
     }
+	else if (command == "TOGGLE_CHANNEL_FAVORITE")
+	{
+        enc->ToggleChannelFavorite();
+        retlist << "ok";
+	}
     else if (command == "CHANGE_CHANNEL")
     {
-        bool up = slist[2].toInt(); 
-        enc->ChangeChannel(up);
+        int direction = slist[2].toInt(); 
+        enc->ChangeChannel(direction);
         retlist << "ok";
     }
     else if (command == "SET_CHANNEL")


More information about the mythtv-dev mailing list