MythTV master
mythuimetadataresults.cpp
Go to the documentation of this file.
1
3
4// C++
5#include <ranges>
6
7// MythTV
16
17#include "metadatadownload.h"
19
21 MythScreenStack *lparent,
23
24 MythScreenType(lparent, "metadataresultspopup"),
25 m_results(results),
26 m_imageDownload(new MetadataImageDownload(this))
27{
28}
29
31{
33
35 {
36 delete m_imageDownload;
37 m_imageDownload = nullptr;
38 }
39}
40
42{
43 if (!LoadWindowFromXML("base.xml", "MythMetadataResults", this))
44 return false;
45
46 bool err = false;
47 UIUtilE::Assign(this, m_resultsList, "results", &err);
48 if (err)
49 {
50 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythMetadataResults'");
51 return false;
52 }
53
54 for (int i = 0;
55 i != m_results.count(); ++i)
56 {
57 auto *button = new MythUIButtonListItem(m_resultsList,
58 m_results[i]->GetTitle());
59 InfoMap metadataMap;
60 m_results[i]->toMap(metadataMap);
61
62 QString coverartfile;
63 ArtworkList art = m_results[i]->GetArtwork(kArtworkCoverart);
64 if (art.count() > 0)
65 coverartfile = art.takeFirst().thumbnail;
66
67 if (coverartfile.isEmpty())
68 {
69 art = m_results[i]->GetArtwork(kArtworkBanner);
70 if (art.count() > 0)
71 coverartfile = art.takeFirst().thumbnail;
72 }
73
74 if (coverartfile.isEmpty())
75 {
76 art = m_results[i]->GetArtwork(kArtworkScreenshot);
77 if (art.count() > 0)
78 coverartfile = art.takeFirst().thumbnail;
79 }
80
81 QString dlfile = getDownloadFilename(m_results[i]->GetTitle(),
82 coverartfile);
83
84 if (!coverartfile.isEmpty())
85 {
86 int pos = m_resultsList->GetItemPos(button);
87
88 if (QFile::exists(dlfile))
89 button->SetImage(dlfile);
90 else
91 {
92 m_imageDownload->addThumb(m_results[i]->GetTitle(),
93 coverartfile,
94 QVariant::fromValue<uint>(pos));
95 }
96 }
97
98 button->SetTextFromMap(metadataMap);
99 button->SetData(QVariant::fromValue<uint>(i));
100 }
101
104
106
107 return true;
108}
109
111{
112 QString cache = QString("%1/cache/metadata-thumbcache")
113 .arg(GetConfDir());
114 QDir cacheDir(cache);
115 QStringList thumbs = cacheDir.entryList(QDir::Files);
116
117 for (const auto & thumb : std::ranges::reverse_view(std::as_const(thumbs)))
118 {
119 QString filename = QString("%1/%2").arg(cache, thumb);
120 QFileInfo fi(filename);
121 QDateTime lastmod = fi.lastModified();
122 if (lastmod.addDays(2) < MythDate::current())
123 {
124 LOG(VB_GENERAL, LOG_DEBUG, QString("Deleting old cache file %1")
125 .arg(filename));
126 QFile::remove(filename);
127 }
128 }
129}
130
132{
133 if (event->type() == ThumbnailDLEvent::kEventType)
134 {
135 auto *tde = dynamic_cast<ThumbnailDLEvent *>(event);
136 if (tde == nullptr)
137 return;
138
139 ThumbnailData *data = tde->m_thumb;
140
141 QString file = data->url;
142 uint pos = data->data.value<uint>();
143
144 if (file.isEmpty())
145 return;
146
147 if (!((uint)m_resultsList->GetCount() >= pos))
148 return;
149
152
153 if (item)
154 {
155 item->SetImage(file);
156 }
157 }
158}
159
161{
163 m_results.clear();
164 emit haveResult(lookup);
165 Close();
166}
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: compat.h:60
QString getDownloadFilename(const QString &title, const QString &url)
QList< ArtworkInfo > ArtworkList
@ kArtworkScreenshot
@ kArtworkBanner
@ kArtworkCoverart
QString GetConfDir(void)
Definition: mythdirs.cpp:285
#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