MythTV master
mythuimetadataresults.cpp
Go to the documentation of this file.
1
3
12
13#include "metadatadownload.h"
15
17 MythScreenStack *lparent,
19
20 MythScreenType(lparent, "metadataresultspopup"),
21 m_results(results),
22 m_imageDownload(new MetadataImageDownload(this))
23{
24}
25
27{
29
31 {
32 delete m_imageDownload;
33 m_imageDownload = nullptr;
34 }
35}
36
38{
39 if (!LoadWindowFromXML("base.xml", "MythMetadataResults", this))
40 return false;
41
42 bool err = false;
43 UIUtilE::Assign(this, m_resultsList, "results", &err);
44 if (err)
45 {
46 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythMetadataResults'");
47 return false;
48 }
49
50 for (int i = 0;
51 i != m_results.count(); ++i)
52 {
53 auto *button = new MythUIButtonListItem(m_resultsList,
54 m_results[i]->GetTitle());
55 InfoMap metadataMap;
56 m_results[i]->toMap(metadataMap);
57
58 QString coverartfile;
59 ArtworkList art = m_results[i]->GetArtwork(kArtworkCoverart);
60 if (art.count() > 0)
61 coverartfile = art.takeFirst().thumbnail;
62
63 if (coverartfile.isEmpty())
64 {
65 art = m_results[i]->GetArtwork(kArtworkBanner);
66 if (art.count() > 0)
67 coverartfile = art.takeFirst().thumbnail;
68 }
69
70 if (coverartfile.isEmpty())
71 {
72 art = m_results[i]->GetArtwork(kArtworkScreenshot);
73 if (art.count() > 0)
74 coverartfile = art.takeFirst().thumbnail;
75 }
76
77 QString dlfile = getDownloadFilename(m_results[i]->GetTitle(),
78 coverartfile);
79
80 if (!coverartfile.isEmpty())
81 {
82 int pos = m_resultsList->GetItemPos(button);
83
84 if (QFile::exists(dlfile))
85 button->SetImage(dlfile);
86 else
87 {
88 m_imageDownload->addThumb(m_results[i]->GetTitle(),
89 coverartfile,
90 QVariant::fromValue<uint>(pos));
91 }
92 }
93
94 button->SetTextFromMap(metadataMap);
95 button->SetData(QVariant::fromValue<uint>(i));
96 }
97
100
102
103 return true;
104}
105
107{
108 QString cache = QString("%1/cache/metadata-thumbcache")
109 .arg(GetConfDir());
110 QDir cacheDir(cache);
111 QStringList thumbs = cacheDir.entryList(QDir::Files);
112
113 for (auto i = thumbs.crbegin(); i != thumbs.crend(); ++i)
114 {
115 QString filename = QString("%1/%2").arg(cache, *i);
116 QFileInfo fi(filename);
117 QDateTime lastmod = fi.lastModified();
118 if (lastmod.addDays(2) < MythDate::current())
119 {
120 LOG(VB_GENERAL, LOG_DEBUG, QString("Deleting old cache file %1")
121 .arg(filename));
122 QFile::remove(filename);
123 }
124 }
125}
126
128{
129 if (event->type() == ThumbnailDLEvent::kEventType)
130 {
131 auto *tde = dynamic_cast<ThumbnailDLEvent *>(event);
132 if (tde == nullptr)
133 return;
134
135 ThumbnailData *data = tde->m_thumb;
136
137 QString file = data->url;
138 uint pos = data->data.value<uint>();
139
140 if (file.isEmpty())
141 return;
142
143 if (!((uint)m_resultsList->GetCount() >= pos))
144 return;
145
148
149 if (item)
150 {
151 item->SetImage(file);
152 }
153 }
154}
155
157{
159 m_results.clear();
160 emit haveResult(lookup);
161 Close();
162}
void addThumb(QString title, QString url, QVariant data)
void customEvent(QEvent *event) override
MythUIButtonList * m_resultsList
MetadataResultsDialog(MythScreenStack *lparent, const MetadataLookupList &results)
MetadataImageDownload * m_imageDownload
void haveResult(RefCountHandler< MetadataLookup >)
MetadataLookupList m_results
void sendResult(MythUIButtonListItem *item)
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
virtual void Close()
void SetImage(MythImage *image, const QString &name="")
Sets an image directly, should only be used in special circumstances since it bypasses the cache.
int GetItemPos(MythUIButtonListItem *item) const
void itemClicked(MythUIButtonListItem *item)
MythUIButtonListItem * GetItemAt(int pos) const
RefCountHandler< T > takeAtAndDecr(int i)
Removes the item at index position i and returns it.
T * takeFirst(void)
Removes the first item in the list and returns it.
static const Type kEventType
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
unsigned int uint
Definition: freesurround.h:24
QString getDownloadFilename(const QString &title, const QString &url)
QList< ArtworkInfo > ArtworkList
@ kArtworkScreenshot
@ kArtworkBanner
@ kArtworkCoverart
QString GetConfDir(void)
Definition: mythdirs.cpp:263
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
bool exists(str path)
Definition: xbmcvfs.py:51
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27