Ticket #11019: 0002-Cache-Channelicons-in-local-folder-026.patch
File 0002-Cache-Channelicons-in-local-folder-026.patch, 9.5 KB (added by , 12 years ago) |
---|
-
mythtv/libs/libmythtv/dbchannelinfo.cpp
From 3074732c8da922ca8fa6426064a62d4a05aae8a6 Mon Sep 17 00:00:00 2001 From: Sascha Hinck <SHinck@web.de> Date: Sat, 25 Aug 2012 18:21:05 +0200 Subject: [PATCH] Cache channelicons in local folder on remote frontends If channelicons are not in local folder $(ConfDIR)/channels they will be fetched from backend StorageGroup ChannelIcons an cached in local folder on first showing in the program guide. --- mythtv/libs/libmythtv/dbchannelinfo.cpp | 82 ++++++++++++++++++++++++ mythtv/libs/libmythtv/dbchannelinfo.h | 3 + mythtv/libs/libmythtv/osd.cpp | 15 +++-- mythtv/programs/mythfilldatabase/icondata.cpp | 2 +- mythtv/programs/mythfrontend/guidegrid.cpp | 20 +++--- mythtv/programs/mythtv-setup/channeleditor.cpp | 14 ++++- mythtv/programs/mythtv-setup/importicons.cpp | 2 +- 7 files changed, 118 insertions(+), 20 deletions(-) diff --git a/mythtv/libs/libmythtv/dbchannelinfo.cpp b/mythtv/libs/libmythtv/dbchannelinfo.cpp index 2e9086a..b0caa68 100644
a b QString DBChannel::GetFormatted(const ChannelFormat &format) const 102 102 //////////////////////////////////////////////////////////////////////////// 103 103 //////////////////////////////////////////////////////////////////////////// 104 104 105 bool DBChannel::CacheChannelIcon(void) 106 { 107 if (icon.isEmpty()) 108 return false; 109 110 m_localIcon = icon; 111 112 // Is icon local? 113 if (QFile(icon).exists()) 114 return true; 115 116 QString localDirStr = QString("%1/channels").arg(GetConfDir()); 117 QDir localDir(localDirStr); 118 119 if (!localDir.exists() && !localDir.mkdir(localDirStr)) 120 { 121 LOG(VB_GENERAL, LOG_ERR, 122 QString("Icons directory is missing and could not be created: %1") 123 .arg(localDirStr)); 124 icon.clear(); 125 return false; 126 } 127 128 // Has it been saved to the local cache? 129 m_localIcon = QString("%1/%2").arg(localDirStr) 130 .arg(QFileInfo(icon).fileName()); 131 if (QFile(m_localIcon).exists()) 132 return true; 133 134 // Get address of master backed 135 QString url = gCoreContext->GetMasterHostPrefix("ChannelIcons", 136 icon); 137 if (url.length() < 1) 138 { 139 icon.clear(); 140 return false; 141 } 142 143 QUrl qurl = url; 144 if (qurl.host().isEmpty()) 145 { 146 icon.clear(); 147 return false; 148 } 149 150 RemoteFile *rf = new RemoteFile(url, false, false, 0); 151 152 QByteArray data; 153 bool ret = rf->SaveAs(data); 154 155 delete rf; 156 157 if (ret && data.size()) 158 { 159 QImage image; 160 161 image.loadFromData(data); 162 163 //if (image.loadFromData(data) && image.width() > 0 164 165 if (image.save(m_localIcon)) 166 { 167 LOG(VB_GENERAL, LOG_INFO, 168 QString("Caching channel icon %1").arg(m_localIcon)); 169 return true; 170 } 171 else 172 LOG(VB_GENERAL, LOG_ERR, 173 QString("Failed to save to %1").arg(m_localIcon)); 174 } 175 176 // if we get here then the icon is set in the db but couldn't be found 177 // anywhere so maybe we should remove it from the DB? 178 icon.clear(); 179 180 return false; 181 } 182 183 //////////////////////////////////////////////////////////////////////////// 184 //////////////////////////////////////////////////////////////////////////// 185 186 105 187 QString ChannelInfo::GetFormatted(const ChannelFormat &format) const 106 188 { 107 189 QString tmp; -
mythtv/libs/libmythtv/dbchannelinfo.h
diff --git a/mythtv/libs/libmythtv/dbchannelinfo.h b/mythtv/libs/libmythtv/dbchannelinfo.h index 3e4b6ea..991b8b2 100644
a b class MTV_PUBLIC DBChannel 33 33 bool operator == (uint _chanid) const 34 34 { return chanid == _chanid; } 35 35 36 bool CacheChannelIcon(void); 37 36 38 enum ChannelFormat { kChannelShort, kChannelLong }; 37 39 QString GetFormatted(const ChannelFormat &format) const; 38 40 void ToMap(InfoMap &infoMap) const; … … class MTV_PUBLIC DBChannel 42 44 QString callsign; 43 45 QString name; 44 46 QString icon; 47 QString m_localIcon; 45 48 uint chanid; 46 49 uint major_chan; 47 50 uint minor_chan; -
mythtv/libs/libmythtv/osd.cpp
diff --git a/mythtv/libs/libmythtv/osd.cpp b/mythtv/libs/libmythtv/osd.cpp index 5703ed3..694d18f 100644
a b 4 4 // libmyth 5 5 #include "mythlogging.h" 6 6 7 // libmythbase 8 #include "mythdirs.h" 9 7 10 // libmythui 8 11 #include "mythmainwindow.h" 9 12 #include "mythuihelper.h" … … void OSD::SetText(const QString &window, QHash<QString,QString> &map, 436 439 iconpath = map["iconpath"]; 437 440 else 438 441 iconpath = ChannelUtil::GetIcon(chanid); 442 443 QString localIcon = QString("%1/channels/%2").arg(GetConfDir()) 444 .arg(QFileInfo(iconpath).fileName()); 439 445 440 if (!iconpath.isEmpty())441 {442 QString iconurl =443 gCoreContext->GetMasterHostPrefix("ChannelIcons",444 iconpath);445 446 446 icon->SetFilename(iconurl); 447 if (QFile(localIcon).exists()) 448 { 449 icon->SetFilename(localIcon); 447 450 icon->Load(false); 448 451 } 449 452 } -
mythtv/programs/mythfilldatabase/icondata.cpp
diff --git a/mythtv/programs/mythfilldatabase/icondata.cpp b/mythtv/programs/mythfilldatabase/icondata.cpp index 95e44d9..1e47ee3 100644
a b bool IconData::Save(const FI &fi, const QByteArray &data) 316 316 "UPDATE channel SET icon = :ICON " 317 317 "WHERE chanid = :CHANID"); 318 318 319 update.bindValue(":ICON", fi.filename);319 update.bindValue(":ICON", QFileInfo(fi.filename).fileName()); 320 320 update.bindValue(":CHANID", fi.chanid); 321 321 322 322 if (!update.exec()) -
mythtv/programs/mythfrontend/guidegrid.cpp
diff --git a/mythtv/programs/mythfrontend/guidegrid.cpp b/mythtv/programs/mythfrontend/guidegrid.cpp index 24e1956..1990c4e 100644
a b void GuideGrid::updateChannels(void) 1576 1576 chinfo->ToMap(infomap); 1577 1577 item->SetTextFromMap(infomap); 1578 1578 1579 if (!chinfo->icon.isEmpty()) 1579 if (!chinfo->icon.isEmpty() && 1580 chinfo->CacheChannelIcon()) 1580 1581 { 1581 QString iconurl = 1582 gCoreContext->GetMasterHostPrefix("ChannelIcons", 1583 chinfo->icon); 1584 item->SetImage(iconurl, "channelicon"); 1582 QString localpath = chinfo->m_localIcon; 1583 item->SetImage(localpath, "channelicon"); 1585 1584 } 1586 1585 } 1587 1586 } … … void GuideGrid::updateInfo(void) 1613 1612 m_channelImage->Reset(); 1614 1613 if (!chinfo->icon.isEmpty()) 1615 1614 { 1616 QString iconurl = gCoreContext->GetMasterHostPrefix("ChannelIcons", 1617 chinfo->icon); 1618 1619 m_channelImage->SetFilename(iconurl); 1620 m_channelImage->Load(); 1615 if (chinfo->CacheChannelIcon()) 1616 { 1617 QString localpath = chinfo->m_localIcon; 1618 m_channelImage->SetFilename(localpath); 1619 m_channelImage->Load(); 1620 } 1621 1621 } 1622 1622 } 1623 1623 -
mythtv/programs/mythtv-setup/channeleditor.cpp
diff --git a/mythtv/programs/mythtv-setup/channeleditor.cpp b/mythtv/programs/mythtv-setup/channeleditor.cpp index f93c03b..9ea11db 100644
a b 4 4 // MythTV 5 5 #include "mythprogressdialog.h" 6 6 #include "mythuibuttonlist.h" 7 #include "mythcorecontext.h" 7 8 #include "channelsettings.h" 8 9 #include "transporteditor.h" 9 10 #include "mythuicheckbox.h" … … void ChannelEditor::itemChanged(MythUIButtonListItem *item) 210 211 QString iconpath = item->GetImageFilename(); 211 212 if (!iconpath.isEmpty()) 212 213 { 213 m_preview->SetFilename(iconpath); 214 QString iconurl = gCoreContext->GetMasterHostPrefix("ChannelIcons", 215 iconpath); 216 217 m_preview->SetFilename(iconurl); 214 218 m_preview->Load(); 215 219 } 216 220 } … … void ChannelEditor::fillList(void) 336 340 item->SetText(callsign, "callsign"); 337 341 item->SetText(sourceid, "sourcename"); 338 342 item->SetImage(icon); 339 item->SetImage(icon, "icon"); 343 if (!icon.isEmpty()) 344 { 345 QString iconurl = 346 gCoreContext->GetMasterHostPrefix("ChannelIcons", 347 icon); 348 item->SetImage(iconurl, "icon"); 349 } 340 350 item->DisplayState(state, "status"); 341 351 } 342 352 } -
mythtv/programs/mythtv-setup/importicons.cpp
diff --git a/mythtv/programs/mythtv-setup/importicons.cpp b/mythtv/programs/mythtv-setup/importicons.cpp index 4fe041b..3cce488 100644
a b bool ImportIconsWizard::checkAndDownload(const QString& url, const QString& loca 553 553 "WHERE chanid = :CHANID"; 554 554 555 555 query.prepare(qstr); 556 query.bindValue(":ICON", file. absoluteFilePath());556 query.bindValue(":ICON", file.fileName()); 557 557 query.bindValue(":CHANID", localChanId); 558 558 559 559 if (!query.exec())