Skip to content

Commit

Permalink
Fixes #6948. Refs #8211. Fixes a few bugs in channel browse mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kristjansson committed May 17, 2011
1 parent f5cc883 commit d14b660
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 132 deletions.
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/channelbase.cpp
Expand Up @@ -927,8 +927,7 @@ bool ChannelBase::InitializeInputs(void)
m_allchannels.insert(m_allchannels.end(),
channels.begin(), channels.end());
}
ChannelUtil::SortChannels(m_allchannels, order);
ChannelUtil::EliminateDuplicateChanNum(m_allchannels);
ChannelUtil::SortChannels(m_allchannels, order, true);

m_currentInputID = GetDefaultInput(cardid);

Expand Down
80 changes: 40 additions & 40 deletions mythtv/libs/libmythtv/channelutil.cpp
Expand Up @@ -1965,7 +1965,8 @@ bool ChannelUtil::GetExtendedChannelData(
dvb_transportid, dvb_networkid, dtv_si_std);
}

DBChanList ChannelUtil::GetChannels(uint sourceid, bool vis_only, QString grp, int changrpid)
DBChanList ChannelUtil::GetChannels(
uint sourceid, bool vis_only, QString grp, uint changrpid)
{
DBChanList list;

Expand All @@ -1974,36 +1975,42 @@ DBChanList ChannelUtil::GetChannels(uint sourceid, bool vis_only, QString grp, i
QString qstr =
"SELECT channum, callsign, channel.chanid, "
" atsc_major_chan, atsc_minor_chan, "
" name, icon, mplexid, visible "
"FROM channel ";
" name, icon, mplexid, visible, "
" channel.sourceid, cardinput.cardid, channelgroup.grpid "
"FROM channel "
"LEFT JOIN channelgroup ON channel.chanid = channelgroup.chanid "
"JOIN cardinput ON cardinput.sourceid = channel.sourceid "
"JOIN capturecard ON cardinput.cardid = capturecard.cardid ";

// Select only channels from the specified channel group
if (changrpid > -1)
qstr += QString(",channelgroup ");
QString cond = " WHERE ";

if (sourceid)
qstr += QString("WHERE sourceid='%1' ").arg(sourceid);
else
qstr += ",cardinput,capturecard "
"WHERE cardinput.sourceid = channel.sourceid AND "
" cardinput.cardid = capturecard.cardid ";
{
qstr += QString("WHERE channel.sourceid='%1' ").arg(sourceid);
cond = " AND ";
}

if (changrpid > -1)
// Select only channels from the specified channel group
if (changrpid > 0)
{
qstr += QString("AND channel.chanid = channelgroup.chanid "
"AND channelgroup.grpid ='%1' ").arg(changrpid);
qstr += QString("%1 channelgroup.grpid = '%2' ")
.arg(cond).arg(changrpid);
cond = " AND ";
}

if (vis_only)
qstr += "AND visible=1 ";
{
qstr += QString("%1 visible=1 ").arg(cond);
cond = " AND ";
}

if (!grp.isEmpty())
qstr += QString("GROUP BY %1 ").arg(grp);
qstr += QString(" GROUP BY %1 ").arg(grp);

query.prepare(qstr);
if (!query.exec() || !query.isActive())
if (!query.exec())
{
MythDB::DBError("get channels -- sourceid", query);
MythDB::DBError("ChannelUtil::GetChannels()", query);
return list;
}

Expand All @@ -2021,7 +2028,10 @@ DBChanList ChannelUtil::GetChannels(uint sourceid, bool vis_only, QString grp, i
query.value(7).toUInt(), /* mplexid */
query.value(8).toBool(), /* visible */
query.value(5).toString(), /* name */
query.value(6).toString()); /* icon */
query.value(6).toString(), /* icon */
query.value(9).toUInt(), /* sourceid */
query.value(11).toUInt(), /* cardid */
query.value(10).toUInt()); /* grpid */

list.push_back(chan);
}
Expand Down Expand Up @@ -2189,29 +2199,13 @@ void ChannelUtil::SortChannels(DBChanList &list, const QString &order,
}
}

void ChannelUtil::EliminateDuplicateChanNum(DBChanList &list)
{
typedef std::set<QString> seen_set;
seen_set seen;

DBChanList::iterator it = list.begin();

while (it != list.end())
{
QString tmp = it->channum; tmp.detach();
std::pair<seen_set::iterator, bool> insret = seen.insert(tmp);
if (insret.second)
++it;
else
it = list.erase(it);
}
}

uint ChannelUtil::GetNextChannel(
const DBChanList &sorted,
uint old_chanid,
uint mplexid_restriction,
int direction)
int direction,
bool skip_non_visible,
bool skip_same_channum_and_callsign)
{
DBChanList::const_iterator it =
find(sorted.begin(), sorted.end(), old_chanid);
Expand All @@ -2223,7 +2217,6 @@ uint ChannelUtil::GetNextChannel(
return 0; // no channels..

DBChanList::const_iterator start = it;
bool skip_non_visible = true; // TODO make DB selectable

if (CHANNEL_DIRECTION_DOWN == direction)
{
Expand All @@ -2237,10 +2230,14 @@ uint ChannelUtil::GetNextChannel(
}
while ((it != start) &&
((skip_non_visible && !it->visible) ||
(skip_same_channum_and_callsign &&
it->channum == start->channum &&
it->callsign == start->callsign) ||
(mplexid_restriction &&
(mplexid_restriction != it->mplexid))));
}
else if ((CHANNEL_DIRECTION_UP == direction) || (CHANNEL_DIRECTION_FAVORITE == direction))
else if ((CHANNEL_DIRECTION_UP == direction) ||
(CHANNEL_DIRECTION_FAVORITE == direction))
{
do
{
Expand All @@ -2250,6 +2247,9 @@ uint ChannelUtil::GetNextChannel(
}
while ((it != start) &&
((skip_non_visible && !it->visible) ||
(skip_same_channum_and_callsign &&
it->channum == start->channum &&
it->callsign == start->callsign) ||
(mplexid_restriction &&
(mplexid_restriction != it->mplexid))));
}
Expand Down
16 changes: 9 additions & 7 deletions mythtv/libs/libmythtv/channelutil.h
Expand Up @@ -182,18 +182,20 @@ class MTV_PUBLIC ChannelUtil
static QString GetVideoFilters(uint sourceid, const QString &channum)
{ return GetChannelValueStr("videofilters", sourceid, channum); }

static DBChanList GetChannels(uint srcid, bool vis_only,
QString grp = "", int changrpid = -1);
static DBChanList GetChannels(
uint sourceid, bool visible_only,
QString group_by = "", uint channel_groupid = 0);
static vector<uint> GetChanIDs(int sourceid = -1);
static uint GetChannelCount(int sourceid = -1);
static void SortChannels(DBChanList &list, const QString &order,
bool eliminate_duplicates = false);
static void EliminateDuplicateChanNum(DBChanList &list);

static uint GetNextChannel(const DBChanList &sorted,
uint old_chanid,
uint mplexid_restriction,
int direction);
static uint GetNextChannel(const DBChanList &sorted,
uint old_chanid,
uint mplexid_restriction,
int direction,
bool skip_non_visible = true,
bool skip_same_channum_and_callsign = false);

static QString GetChannelValueStr(const QString &channel_field,
uint sourceid,
Expand Down
29 changes: 15 additions & 14 deletions mythtv/libs/libmythtv/dbchannelinfo.cpp
Expand Up @@ -24,32 +24,33 @@ DBChannel::DBChannel(
const QString &_channum, const QString &_callsign,
uint _chanid, uint _major_chan, uint _minor_chan,
uint _mplexid, bool _visible,
const QString &_name, const QString &_icon) :
const QString &_name, const QString &_icon,
uint _sourceid, uint _cardid, uint _grpid) :
channum(_channum),
callsign(_callsign), chanid(_chanid),
callsign(_callsign),
name(_name), icon((_icon == "none") ? QString() : _icon),
chanid(_chanid),
major_chan(_major_chan), minor_chan(_minor_chan),
mplexid(_mplexid), visible(_visible),
name(_name), icon(_icon)
mplexid((_mplexid == 32767) ? 0 : _mplexid),
sourceid(_sourceid), cardid(_cardid), grpid(_grpid),
visible(_visible)
{
channum.detach();
callsign.detach();
name.detach();
icon.detach();
mplexid = (mplexid == 32767) ? 0 : mplexid;
icon = (icon == "none") ? QString::null : icon;
}

DBChannel &DBChannel::operator=(const DBChannel &other)
{
channum = other.channum; channum.detach();
callsign = other.callsign; callsign.detach();
channum = other.channum;
callsign = other.callsign;
name = other.name;
icon = other.icon;
chanid = other.chanid;
major_chan = other.major_chan;
minor_chan = other.minor_chan;
mplexid = (other.mplexid == 32767) ? 0 : other.mplexid;
sourceid = other.sourceid;
cardid = other.cardid;
grpid = other.grpid;
visible = other.visible;
name = other.name; name.detach();
icon = other.icon; icon.detach();

return *this;
}
Expand Down
10 changes: 7 additions & 3 deletions mythtv/libs/libmythtv/dbchannelinfo.h
Expand Up @@ -25,7 +25,8 @@ class MTV_PUBLIC DBChannel
DBChannel(const QString &_channum, const QString &_callsign,
uint _chanid, uint _major_chan, uint _minor_chan,
uint _mplexid, bool _visible,
const QString &_name, const QString &_icon);
const QString &_name, const QString &_icon,
uint _sourceid, uint _cardid, uint _grpid);
DBChannel& operator=(const DBChannel&);

bool operator == (uint _chanid) const
Expand All @@ -34,13 +35,16 @@ class MTV_PUBLIC DBChannel
public:
QString channum;
QString callsign;
QString name;
QString icon;
uint chanid;
uint major_chan;
uint minor_chan;
uint mplexid;
uint sourceid;
uint cardid;
uint grpid;
bool visible;
QString name;
QString icon;
};
typedef vector<DBChannel> DBChanList;

Expand Down
19 changes: 11 additions & 8 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -6493,16 +6493,20 @@ bool TV::CommitQueuedInput(PlayerContext *ctx)
QString chaninput = GetQueuedInput();
if (browsehelper->IsBrowsing())
{
uint sourceid = 0;
ctx->LockPlayingInfo(__FILE__, __LINE__);
if (ctx->playingInfo)
sourceid = ctx->playingInfo->GetSourceID();
ctx->UnlockPlayingInfo(__FILE__, __LINE__);

commited = true;
if (channum.isEmpty())
channum = browsehelper->GetBrowsedInfo().m_channum;

if ((ctx->recorder && ctx->recorder->CheckChannel(channum)) ||
(db_browse_all_tuners &&
browsehelper->BrowseAllGetChanId(channum)))
{
uint chanid = browsehelper->GetChanId(
channum, ctx->GetCardID(), sourceid);
if (chanid)
browsehelper->BrowseChannel(ctx, channum);
}

HideOSDWindow(ctx, "osd_input");
}
else if (GetQueuedChanID() || !channum.isEmpty())
Expand Down Expand Up @@ -6534,8 +6538,7 @@ void TV::ChangeChannel(PlayerContext *ctx, int direction)
return;
}
// Collect channel info
const ProgramInfo pginfo(*ctx->playingInfo);
old_chanid = pginfo.GetChanID();
old_chanid = ctx->playingInfo->GetChanID();
ctx->UnlockPlayingInfo(__FILE__, __LINE__);
}

Expand Down

0 comments on commit d14b660

Please sign in to comment.