[mythtv] Patch - LiveTV channel favorites
Chris Martin
dev at cgmartin.com
Wed Feb 26 01:26:14 EST 2003
Here's the basis for the channel favorites as been described in the
group. With this patch, the user may mark/unmark a channel in LiveTV as
a favorite with the '?' key, then cycle upwards through the favorite
channels with the '/' key. No on-screen-display yet, but should be
relatively easy to add a marker in the info panel which lets the user
know if the channel is a favorite or not. On my TWC system here, a
little star (*) is placed next to the channel when marked as a
favorite...was thinking of something similar. Then on to the
"Favourites" section of MythWeb.
The patch does not include the SQL changes, as I wasn't too sure what
file was best for them... Here's the SQL table dump below:
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;
The userid in the favorites table is not used yet, but is there in preparation of future user-based settings/favorites/parental-locks.
This is my first patch for MythTV, so let me know if I've done something that is unacceptably different :) I didn't spend a lot of time trying to figure out which keystrokes would be best (as 'f'/'F' were already taken!), so please change them if needed.
-------------- 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 26 Feb 2003 06:02:21 -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 the current channel as a "favorite"
Without the stickykeys option selected:
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 26 Feb 2003 06:02:22 -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 26 Feb 2003 06:02:22 -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/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 26 Feb 2003 06:02:22 -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 26 Feb 2003 06:02:22 -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 26 Feb 2003 06:02:22 -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 26 Feb 2003 06:02:22 -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 26 Feb 2003 06:02:22 -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 26 Feb 2003 06:02:23 -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 26 Feb 2003 06:02:23 -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 26 Feb 2003 06:02:23 -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 26 Feb 2003 06:02:23 -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.32
diff -u -d -r1.32 mainserver.cpp
--- programs/mythbackend/mainserver.cpp 25 Feb 2003 04:45:21 -0000 1.32
+++ programs/mythbackend/mainserver.cpp 26 Feb 2003 06:02:23 -0000
@@ -684,10 +684,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