Permalink
Browse files

Store card and group ids as a list in ChannelInfo instead of creating…

… multiple ChannelInfo objects for each chanid/cardid mapping. Saves a little memory and is much tidier.
  • Loading branch information...
stuartm committed Nov 25, 2012
1 parent fb15568 commit 3ce30e783053e2946b6eead9959f16e2fe249763
@@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.27.20121125-1"
#define MYTH_BINARY_VERSION "0.27.20121125-2"
/** \brief Increment this whenever the MythTV network protocol changes.
*
@@ -200,6 +200,10 @@ QString ChannelGroup::GetChannelGroupName(int grpid)
if (grpid == -1)
return QObject::tr("All Channels");
// No group
if (grpid == 0)
return "";
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT name FROM channelgroupnames WHERE grpid = :GROUPID");
query.bindValue(":GROUPID", grpid);
@@ -60,8 +60,8 @@ ChannelInfo::ChannelInfo(const ChannelInfo &other)
iptvid = other.iptvid;
// Not in channel table
groupid = other.groupid;
cardid = other.cardid;
m_groupIdList = other.m_groupIdList;
m_cardIdList = other.m_cardIdList;
old_xmltvid = other.old_xmltvid;
m_sourcename = other.m_sourcename;
}
@@ -71,7 +71,7 @@ ChannelInfo::ChannelInfo(
uint _chanid, uint _major_chan, uint _minor_chan,
uint _mplexid, bool _visible,
const QString &_name, const QString &_icon,
uint _sourceid, uint _cardid, uint _grpid)
uint _sourceid)
{
Init();
@@ -84,8 +84,6 @@ ChannelInfo::ChannelInfo(
atsc_minor_chan = _minor_chan;
mplexid = (_mplexid == 32767) ? 0 : _mplexid;
sourceid = _sourceid;
cardid = _cardid;
groupid = _grpid;
visible = _visible;
}
@@ -124,8 +122,8 @@ ChannelInfo &ChannelInfo::operator=(const ChannelInfo &other)
iptvid = other.iptvid;
// Not in channel table
groupid = other.groupid;
cardid = other.cardid;
m_groupIdList = other.m_groupIdList;
m_cardIdList = other.m_cardIdList;
old_xmltvid = other.old_xmltvid;
m_sourcename = other.m_sourcename;
@@ -170,9 +168,9 @@ void ChannelInfo::Init()
tmoffset = 0;
iptvid = 0;
// Following not in database
groupid = -1;
cardid = -1;
m_cardIdList.clear();
m_groupIdList.clear();
m_sourcename.clear();
}
QString ChannelInfo::GetFormatted(const ChannelFormat &format) const
@@ -220,7 +218,58 @@ void ChannelInfo::ToMap(InfoMap& infoMap)
infoMap["mplexid"] = QString().setNum(mplexid);
infoMap["channelvisible"] = visible ? QObject::tr("Yes") : QObject::tr("No");
infoMap["channelgroupname"] = ChannelGroup::GetChannelGroupName(groupid);
if (!GetGroupIds().isEmpty())
infoMap["channelgroupname"] = ChannelGroup::GetChannelGroupName(GetGroupIds().first());
}
void ChannelInfo::LoadCardIds()
{
if (chanid && m_cardIdList.isEmpty())
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT capturecard.cardid FROM channel "
"JOIN cardinput ON cardinput.sourceid = channel.sourceid "
"JOIN capturecard ON cardinput.cardid = capturecard.cardid "
"WHERE chanid = :CHANID");
query.bindValue(":CHANID", chanid);
if (!query.exec())
MythDB::DBError("ChannelInfo::GetCardIds()", query);
else
{
while(query.next())
{
AddCardId(query.value(0).toUInt());
}
}
}
}
void ChannelInfo::LoadGroupIds()
{
if (chanid && m_groupIdList.isEmpty())
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT grpid FROM channelgroup "
"WHERE chanid = :CHANID");
query.bindValue(":CHANID", chanid);
if (!query.exec())
MythDB::DBError("ChannelInfo::GetCardIds()", query);
else if (query.size() == 0)
{
// HACK Avoid re-running this query each time for channels
// which don't belong to any group
AddGroupId(0);
}
else
{
while(query.next())
{
AddGroupId(query.value(0).toUInt());
}
}
}
}
////////////////////////////////////////////////////////////////////////////
@@ -28,7 +28,7 @@ class MTV_PUBLIC ChannelInfo
uint _chanid, uint _major_chan, uint _minor_chan,
uint _mplexid, bool _visible,
const QString &_name, const QString &_icon,
uint _sourceid, uint _cardid, uint _grpid);
uint _sourceid);
ChannelInfo& operator=(const ChannelInfo&);
@@ -41,6 +41,29 @@ class MTV_PUBLIC ChannelInfo
QString GetSourceName();
void SetSourceName(const QString lname) { m_sourcename = lname; }
const QList<uint> GetGroupIds() const { return m_groupIdList; }
void LoadGroupIds();
void AddGroupId(uint lgroupid)
{
if (m_groupIdList.contains(lgroupid))
m_groupIdList.push_back(lgroupid);
}
void RemoveGroupId(uint lgroupid) { m_groupIdList.removeOne(lgroupid); }
const QList<uint> GetCardIds() const { return m_cardIdList; }
void LoadCardIds();
// Since cardids must only appear once in a list, protect access
// to it
void AddCardId(uint lcardid)
{
if (m_cardIdList.contains(lcardid))
m_cardIdList.push_back(lcardid);
}
void RemoveCardId(uint lcardid) { m_cardIdList.removeOne(lcardid); }
private:
void Init();
@@ -84,14 +107,13 @@ class MTV_PUBLIC ChannelInfo
int tmoffset;
uint iptvid;
// Following not in database
int groupid;
int cardid;
QString old_xmltvid; // Used by mythfilldatabase when updating the xmltvid
private:
QString m_sourcename; // Cache here rather than looking up each time
// Following not in database - Cached
QList<uint> m_groupIdList;
QList<uint> m_cardIdList;
};
typedef vector<ChannelInfo> ChannelInfoList;
@@ -2111,7 +2111,8 @@ ChannelInfoList ChannelUtil::GetChannelsInternal(
"SELECT channum, callsign, channel.chanid, "
" atsc_major_chan, atsc_minor_chan, "
" name, icon, mplexid, visible, "
" channel.sourceid, cardinput.cardid, channelgroup.grpid, "
" channel.sourceid, GROUP_CONCAT(DISTINCT cardinput.cardid),"
" GROUP_CONCAT(DISTINCT channelgroup.grpid), "
" xmltvid "
"FROM channel "
"LEFT JOIN channelgroup ON channel.chanid = channelgroup.chanid "
@@ -2142,8 +2143,10 @@ ChannelInfoList ChannelUtil::GetChannelsInternal(
cond = " AND ";
}
qstr += " GROUP BY chanid";
if (!grp.isEmpty())
qstr += QString(" GROUP BY %1 ").arg(grp);
qstr += QString(", %1").arg(grp);
query.prepare(qstr);
if (!query.exec())
@@ -2167,13 +2170,22 @@ ChannelInfoList ChannelUtil::GetChannelsInternal(
query.value(8).toBool(), /* visible */
query.value(5).toString(), /* name */
query.value(6).toString(), /* icon */
query.value(9).toUInt(), /* sourceid */
query.value(11).toUInt(), /* cardid */
query.value(10).toUInt()); /* grpid */
query.value(9).toUInt()); /* sourceid */
chan.xmltvid = query.value(12).toString(); /* xmltvid */
QStringList cardIDs = query.value(11).toString().split(",");
QString cardid;
while (!cardIDs.isEmpty())
chan.AddCardId(cardIDs.takeFirst().toUInt());
QStringList groupIDs = query.value(10).toString().split(",");
QString groupid;
while (!groupIDs.isEmpty())
chan.AddCardId(groupIDs.takeFirst().toUInt());
list.push_back(chan);
}
return list;
@@ -245,7 +245,8 @@ uint TVBrowseHelper::GetChanId(
ChannelInfoList::const_iterator it = db_all_channels.begin();
for (; it != db_all_channels.end(); ++it)
{
if ((*it).cardid == pref_cardid && (*it).channum == channum)
if ((*it).GetCardIds().contains(pref_cardid) &&
(*it).channum == channum)
return (*it).chanid;
}
}
@@ -133,8 +133,7 @@ QHash<QString, ChannelInfo> ChannelData::channelList(int sourceId)
{
QHash<QString, ChannelInfo> retList;
ChannelInfoList channelList = ChannelUtil::GetChannels(sourceId, true,
"chanid");
ChannelInfoList channelList = ChannelUtil::GetChannels(sourceId, true);
ChannelInfoList::iterator it = channelList.begin();
for ( ; it != channelList.end(); ++it)

0 comments on commit 3ce30e7

Please sign in to comment.