From cda7871fad69c83ba1f254ec5f0fa547f4bc1864 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 3 Mar 2012 22:08:16 +0000 Subject: [PATCH] Fix the channel icon not loading in the OSD on remote frontends by switching to using the channel icon storage group. This bug has been around for years so it's nice to finally have a fix. --- mythtv/libs/libmythbase/mythcorecontext.cpp | 9 ++- mythtv/libs/libmythbase/mythcorecontext.h | 3 +- mythtv/libs/libmythbase/mythversion.h | 2 +- mythtv/libs/libmythbase/storagegroup.cpp | 14 ++-- mythtv/libs/libmythtv/dbchannelinfo.cpp | 82 --------------------- mythtv/libs/libmythtv/dbchannelinfo.h | 16 +--- mythtv/libs/libmythtv/osd.cpp | 14 +++- mythtv/programs/mythfrontend/guidegrid.cpp | 48 ++++++------ mythtv/programs/mythfrontend/guidegrid.h | 10 +-- 9 files changed, 57 insertions(+), 141 deletions(-) diff --git a/mythtv/libs/libmythbase/mythcorecontext.cpp b/mythtv/libs/libmythbase/mythcorecontext.cpp index 40bbc8e9a70..95404d98e0c 100644 --- a/mythtv/libs/libmythbase/mythcorecontext.cpp +++ b/mythtv/libs/libmythbase/mythcorecontext.cpp @@ -703,7 +703,7 @@ void MythCoreContext::ConfigureHostAddress(void) QString("Adding IPv6 loopback to address list.")); d->m_IPv6.append(*it); } - else if (config_v6.isNull() && + else if (config_v6.isNull() && (it->protocol() == QAbstractSocket::IPv6Protocol)) { // IPv6 address is not defined, populate one @@ -735,7 +735,7 @@ void MythCoreContext::ConfigureHostAddress(void) } #if !defined(QT_NO_IPV6) - if (!config_v6.isNull() && !d->m_IPv6.contains(config_v6) && + if (!config_v6.isNull() && !d->m_IPv6.contains(config_v6) && !d->m_IPv6.isEmpty()) { LOG(VB_GENERAL, LOG_CRIT, LOC + QString("Host is configured to listen " @@ -810,7 +810,8 @@ QString MythCoreContext::GenMythURL(QString host, int port, QString path, QStrin } -QString MythCoreContext::GetMasterHostPrefix(QString storageGroup) +QString MythCoreContext::GetMasterHostPrefix(const QString &storageGroup, + const QString &path) { QString ret; @@ -834,7 +835,7 @@ QString MythCoreContext::GetMasterHostPrefix(QString storageGroup) ret = GenMythURL(d->m_serverSock->peerAddress().toString(), d->m_serverSock->peerPort(), - "", + path, storageGroup); } diff --git a/mythtv/libs/libmythbase/mythcorecontext.h b/mythtv/libs/libmythbase/mythcorecontext.h index 06f5525baab..9b9321608b0 100644 --- a/mythtv/libs/libmythbase/mythcorecontext.h +++ b/mythtv/libs/libmythbase/mythcorecontext.h @@ -87,7 +87,8 @@ class MBASE_PUBLIC MythCoreContext : public MythObservable, public MythSocketCBs QString GenMythURL(QString host = QString(), int port = 0, QString path = QString(), QString storageGroup = QString()); - QString GetMasterHostPrefix(QString storageGroup = QString()); + QString GetMasterHostPrefix(const QString &storageGroup = QString(), + const QString &path = QString()); QString GetMasterHostName(void); QString GetHostName(void); QString GetFilePrefix(void); diff --git a/mythtv/libs/libmythbase/mythversion.h b/mythtv/libs/libmythbase/mythversion.h index 71295f1841e..9095c6d508d 100644 --- a/mythtv/libs/libmythbase/mythversion.h +++ b/mythtv/libs/libmythbase/mythversion.h @@ -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.25.20120225-2" +#define MYTH_BINARY_VERSION "0.25.20120303-1" /** \brief Increment this whenever the MythTV network protocol changes. * diff --git a/mythtv/libs/libmythbase/storagegroup.cpp b/mythtv/libs/libmythbase/storagegroup.cpp index 8f96c68c04b..db579e39df4 100644 --- a/mythtv/libs/libmythbase/storagegroup.cpp +++ b/mythtv/libs/libmythbase/storagegroup.cpp @@ -65,7 +65,7 @@ void StorageGroup::StaticInit(void) m_staticInitDone = true; - m_builtinGroups["ChannelIcons"] = GetConfDir() + "/ChannelIcons"; + m_builtinGroups["ChannelIcons"] = GetConfDir() + "/channels"; m_builtinGroups["Themes"] = GetConfDir() + "/themes"; m_builtinGroups["Temp"] = GetConfDir() + "/tmp"; m_builtinGroups["Streaming"] = GetConfDir() + "/tmp/hls"; @@ -363,7 +363,7 @@ bool StorageGroup::FileExists(QString filename) // in the order EXISTS, DATE, SIZE QStringList StorageGroup::GetFileInfo(QString filename) { - LOG(VB_FILE, LOG_DEBUG, LOC + + LOG(VB_FILE, LOG_DEBUG, LOC + QString("GetFileInfo: For '%1'") .arg(filename)); QStringList details; @@ -440,7 +440,7 @@ QString StorageGroup::GetRelativePathname(const QString &filename) if (result.startsWith("/")) result.replace(0, 1, ""); - LOG(VB_FILE, LOG_DEBUG, + LOG(VB_FILE, LOG_DEBUG, QString("StorageGroup::GetRelativePathname(%1) = '%2'") .arg(filename).arg(result)); return result; @@ -585,7 +585,7 @@ QString StorageGroup::FindFile(QString filename) QString recDir = FindFileDir(filename); QString result = ""; - + if (!recDir.isEmpty()) { result = recDir + "/" + filename; @@ -698,7 +698,7 @@ QString StorageGroup::FindNextDirMostFree(void) } if (nextDir.isEmpty()) - LOG(VB_FILE, LOG_ERR, LOC + + LOG(VB_FILE, LOG_ERR, LOC + "FindNextDirMostFree: Unable to find any directories to use."); else LOG(VB_FILE, LOG_DEBUG, LOC + @@ -724,7 +724,7 @@ void StorageGroup::CheckAllStorageGroupDirs(void) return; } - LOG(VB_FILE, LOG_DEBUG, LOC + + LOG(VB_FILE, LOG_DEBUG, LOC + "CheckAllStorageGroupDirs(): Checking All Storage Group directories"); QFile testFile(""); @@ -809,7 +809,7 @@ QStringList StorageGroup::getGroupDirs(QString groupname, QString host) QString sql = QString("SELECT dirname,hostname " "FROM storagegroup " "WHERE groupname = :GROUPNAME %1").arg(addHost); - + query.prepare(sql); query.bindValue(":GROUPNAME", groupname); diff --git a/mythtv/libs/libmythtv/dbchannelinfo.cpp b/mythtv/libs/libmythtv/dbchannelinfo.cpp index cfa886274ba..09d9a1457f8 100644 --- a/mythtv/libs/libmythtv/dbchannelinfo.cpp +++ b/mythtv/libs/libmythtv/dbchannelinfo.cpp @@ -136,88 +136,6 @@ void ChannelInfo::ToMap(InfoMap& infoMap) const //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// -bool PixmapChannel::CacheChannelIcon(void) -{ - if (icon.isEmpty()) - return false; - - m_localIcon = icon; - - // Is icon local? - if (QFile(icon).exists()) - return true; - - QString localDirStr = QString("%1/channels").arg(GetConfDir()); - QDir localDir(localDirStr); - - if (!localDir.exists() && !localDir.mkdir(localDirStr)) - { - LOG(VB_GENERAL, LOG_ERR, - QString("Icons directory is missing and could not be created: %1") - .arg(localDirStr)); - icon.clear(); - return false; - } - - // Has it been saved to the local cache? - m_localIcon = QString("%1/%2").arg(localDirStr) - .arg(QFileInfo(icon).fileName()); - if (QFile(m_localIcon).exists()) - return true; - - // Get address of master backed - QString url = gCoreContext->GetMasterHostPrefix("ChannelIcons"); - if (url.length() < 1) - { - icon.clear(); - return false; - } - - url.append(icon); - - QUrl qurl = url; - if (qurl.host().isEmpty()) - { - icon.clear(); - return false; - } - - RemoteFile *rf = new RemoteFile(url, false, false, 0); - - QByteArray data; - bool ret = rf->SaveAs(data); - - delete rf; - - if (ret && data.size()) - { - QImage image; - - image.loadFromData(data); - - //if (image.loadFromData(data) && image.width() > 0 - - if (image.save(m_localIcon)) - { - LOG(VB_GENERAL, LOG_INFO, - QString("Caching channel icon %1").arg(m_localIcon)); - return true; - } - else - LOG(VB_GENERAL, LOG_ERR, - QString("Failed to save to %1").arg(m_localIcon)); - } - - // if we get here then the icon is set in the db but couldn't be found - // anywhere so maybe we should remove it from the DB? - icon.clear(); - - return false; -} - -//////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////// - bool ChannelInsertInfo::SaveScan(uint scanid, uint transportid) const { MSqlQuery query(MSqlQuery::InitCon()); diff --git a/mythtv/libs/libmythtv/dbchannelinfo.h b/mythtv/libs/libmythtv/dbchannelinfo.h index b78f3e3c5a1..6e62bd29c05 100644 --- a/mythtv/libs/libmythtv/dbchannelinfo.h +++ b/mythtv/libs/libmythtv/dbchannelinfo.h @@ -17,7 +17,7 @@ using namespace std; #include "mythtvexp.h" #include "programtypes.h" -// TODO: Refactor DBChannel, PixmapChannel and ChannelInfo into a single class +// TODO: Refactor DBChannel and ChannelInfo into a single class class MTV_PUBLIC DBChannel { @@ -72,20 +72,6 @@ class MTV_PUBLIC ChannelInfo QString recpriority; }; -class MTV_PUBLIC PixmapChannel : public DBChannel -{ - public: - PixmapChannel(const PixmapChannel &other) : - DBChannel(other), m_localIcon() { } - PixmapChannel(const DBChannel &other) : - DBChannel(other), m_localIcon() { } - - bool CacheChannelIcon(void); - - public: - QString m_localIcon; -}; - class MTV_PUBLIC ChannelInsertInfo { public: diff --git a/mythtv/libs/libmythtv/osd.cpp b/mythtv/libs/libmythtv/osd.cpp index 88686c4f465..207ecefab52 100644 --- a/mythtv/libs/libmythtv/osd.cpp +++ b/mythtv/libs/libmythtv/osd.cpp @@ -416,14 +416,24 @@ void OSD::SetText(const QString &window, QHash &map, MythUIImage *icon = dynamic_cast (win->GetChild("iconpath")); if (icon) { + icon->Reset(); + uint chanid = map["chanid"].toUInt(); QString iconpath; if (map.contains("iconpath")) iconpath = map["iconpath"]; else iconpath = ChannelUtil::GetIcon(chanid); - icon->SetFilename(iconpath); - icon->Load(false); + + if (!iconpath.isEmpty()) + { + QString iconurl = + gCoreContext->GetMasterHostPrefix("ChannelIcon", + iconpath); + + icon->SetFilename(iconurl); + icon->Load(false); + } } } if (map.contains("inetref")) diff --git a/mythtv/programs/mythfrontend/guidegrid.cpp b/mythtv/programs/mythfrontend/guidegrid.cpp index 1e1a70370b2..7fec975e264 100644 --- a/mythtv/programs/mythfrontend/guidegrid.cpp +++ b/mythtv/programs/mythfrontend/guidegrid.cpp @@ -657,7 +657,7 @@ void GuideGrid::ShowRecordingMenu(void) } } -PixmapChannel *GuideGrid::GetChannelInfo(uint chan_idx, int sel) +DBChannel *GuideGrid::GetChannelInfo(uint chan_idx, int sel) { sel = (sel >= 0) ? sel : m_channelInfoIdx[chan_idx]; @@ -670,7 +670,7 @@ PixmapChannel *GuideGrid::GetChannelInfo(uint chan_idx, int sel) return &(m_channelInfos[chan_idx][sel]); } -const PixmapChannel *GuideGrid::GetChannelInfo(uint chan_idx, int sel) const +const DBChannel *GuideGrid::GetChannelInfo(uint chan_idx, int sel) const { return ((GuideGrid*)this)->GetChannelInfo(chan_idx, sel); } @@ -715,7 +715,7 @@ uint GuideGrid::GetAlternateChannelIndex( uint chan_idx, bool with_same_channum) const { uint si = m_channelInfoIdx[chan_idx]; - const PixmapChannel *chinfo = GetChannelInfo(chan_idx, si); + const DBChannel *chinfo = GetChannelInfo(chan_idx, si); PlayerContext *ctx = m_player->GetPlayerReadLock(-1, __FILE__, __LINE__); @@ -725,7 +725,7 @@ uint GuideGrid::GetAlternateChannelIndex( if (i == si) continue; - const PixmapChannel *ciinfo = GetChannelInfo(chan_idx, i); + const DBChannel *ciinfo = GetChannelInfo(chan_idx, i); if (!ciinfo) continue; @@ -783,7 +783,7 @@ DBChanList GuideGrid::GetSelection(void) const vector sel; sel.push_back( MKKEY(idx, si) ); - const PixmapChannel *ch = GetChannelInfo(sel[0]>>32, sel[0]&0xffff); + const DBChannel *ch = GetChannelInfo(sel[0]>>32, sel[0]&0xffff); if (!ch) return selected; @@ -798,7 +798,7 @@ DBChanList GuideGrid::GetSelection(void) const for (uint i = 0; i < m_channelInfos[idx].size(); ++i) { - const PixmapChannel *ci = GetChannelInfo(idx, i); + const DBChannel *ci = GetChannelInfo(idx, i); if (ci && (i != si) && (ci->callsign == ch->callsign) && (ci->channum == ch->channum)) { @@ -808,7 +808,7 @@ DBChanList GuideGrid::GetSelection(void) const for (uint i = 0; i < m_channelInfos[idx].size(); ++i) { - const PixmapChannel *ci = GetChannelInfo(idx, i); + const DBChannel *ci = GetChannelInfo(idx, i); if (ci && (i != si) && (ci->callsign == ch->callsign) && (ci->channum != ch->channum)) { @@ -818,7 +818,7 @@ DBChanList GuideGrid::GetSelection(void) const for (uint i = 0; i < m_channelInfos[idx].size(); ++i) { - const PixmapChannel *ci = GetChannelInfo(idx, i); + const DBChannel *ci = GetChannelInfo(idx, i); if ((i != si) && (ci->callsign != ch->callsign)) { sel.push_back( MKKEY(idx, i) ); @@ -827,7 +827,7 @@ DBChanList GuideGrid::GetSelection(void) const for (uint i = 1; i < sel.size(); ++i) { - const PixmapChannel *ci = GetChannelInfo(sel[i]>>32, sel[i]&0xffff); + const DBChannel *ci = GetChannelInfo(sel[i]>>32, sel[i]&0xffff); const ProgramList ch_proglist = GetProgramList(ch->chanid); if (!ci || proglist.size() != ch_proglist.size()) @@ -882,13 +882,13 @@ void GuideGrid::fillChannelInfos(bool gotostartchannel) if (ndup && cdup) continue; - PixmapChannel val(channels[chan]); + DBChannel val(channels[chan]); channum_to_index_map[val.channum].push_back(GetChannelCount()); callsign_to_index_map[val.callsign].push_back(GetChannelCount()); // add the new channel to the list - pix_chan_list_t tmp; + db_chan_list_t tmp; tmp.push_back(val); m_channelInfos.push_back(tmp); } @@ -1508,7 +1508,7 @@ void GuideGrid::updateChannels(void) { m_channelList->Reset(); - PixmapChannel *chinfo = GetChannelInfo(m_currentStartChannel); + DBChannel *chinfo = GetChannelInfo(m_currentStartChannel); if (m_player) m_player->ClearTunableCache(); @@ -1575,11 +1575,12 @@ void GuideGrid::updateChannels(void) chinfo->ToMap(infomap); item->SetTextFromMap(infomap); - if (!chinfo->icon.isEmpty() && - chinfo->CacheChannelIcon()) + if (!chinfo->icon.isEmpty()) { - QString localpath = chinfo->m_localIcon; - item->SetImage(localpath, "channelicon"); + QString iconurl = + gCoreContext->GetMasterHostPrefix("ChannelIcon", + chinfo->icon); + item->SetImage(iconurl, "channelicon"); } } } @@ -1604,19 +1605,18 @@ void GuideGrid::updateInfo(void) if (chanNum < 0) chanNum = 0; - PixmapChannel *chinfo = GetChannelInfo(chanNum); + DBChannel *chinfo = GetChannelInfo(chanNum); if (m_channelImage) { m_channelImage->Reset(); if (!chinfo->icon.isEmpty()) { - if (chinfo->CacheChannelIcon()) - { - QString localpath = chinfo->m_localIcon; - m_channelImage->SetFilename(localpath); - m_channelImage->Load(); - } + QString iconurl = gCoreContext->GetMasterHostPrefix("ChannelIcon", + chinfo->icon); + + m_channelImage->SetFilename(iconurl); + m_channelImage->Load(); } } @@ -1736,7 +1736,7 @@ void GuideGrid::toggleChannelFavorite(int grpid) if (chanNum < 0) chanNum = 0; - PixmapChannel *ch = GetChannelInfo(chanNum); + DBChannel *ch = GetChannelInfo(chanNum); uint chanid = ch->chanid; if (m_changrpid == -1) diff --git a/mythtv/programs/mythfrontend/guidegrid.h b/mythtv/programs/mythfrontend/guidegrid.h index 99af8451024..1a6725c7b7d 100644 --- a/mythtv/programs/mythfrontend/guidegrid.h +++ b/mythtv/programs/mythfrontend/guidegrid.h @@ -31,8 +31,8 @@ class MythUIGuideGrid; #define MAX_DISPLAY_TIMES 36 -typedef vector pix_chan_list_t; -typedef vector pix_chan_list_list_t; +typedef vector db_chan_list_t; +typedef vector db_chan_list_list_t; class JumpToChannel; class JumpToChannelListener @@ -180,8 +180,8 @@ class GuideGrid : public ScheduleCommon, public JumpToChannelListener void setStartChannel(int newStartChannel); - PixmapChannel *GetChannelInfo(uint chan_idx, int sel = -1); - const PixmapChannel *GetChannelInfo(uint chan_idx, int sel = -1) const; + DBChannel *GetChannelInfo(uint chan_idx, int sel = -1); + const DBChannel *GetChannelInfo(uint chan_idx, int sel = -1) const; uint GetChannelCount(void) const; int GetStartChannelOffset(int row = -1) const; @@ -194,7 +194,7 @@ class GuideGrid : public ScheduleCommon, public JumpToChannelListener int m_selectRecThreshold; bool m_allowFinder; - pix_chan_list_list_t m_channelInfos; + db_chan_list_list_t m_channelInfos; QMap m_channelInfoIdx; vector m_programs;