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 {
90 button->SetImage(dlfile);
91 }
92 else
93 {
94 m_imageDownload->addThumb(m_results[i]->GetTitle(),
95 coverartfile,
96 QVariant::fromValue<uint>(pos));
97 }
98 }
99
100 button->SetTextFromMap(metadataMap);
101 button->SetData(QVariant::fromValue<uint>(i));
102 }
103
106
108
109 return true;
110}
111
113{
114 QString cache = QString("%1/cache/metadata-thumbcache")
115 .arg(GetConfDir());
116 QDir cacheDir(cache);
117 QStringList thumbs = cacheDir.entryList(QDir::Files);
118
119 for (const auto & thumb : std::ranges::reverse_view(std::as_const(thumbs)))
120 {
121 QString filename = QString("%1/%2").arg(cache, thumb);
122 QFileInfo fi(filename);
123 QDateTime lastmod = fi.lastModified();
124 if (lastmod.addDays(2) < MythDate::current())
125 {
126 LOG(VB_GENERAL, LOG_DEBUG, QString("Deleting old cache file %1")
127 .arg(filename));
128 QFile::remove(filename);
129 }
130 }
131}
132
134{
135 if (event->type() == ThumbnailDLEvent::kEventType)
136 {
137 auto *tde = dynamic_cast<ThumbnailDLEvent *>(event);
138 if (tde == nullptr)
139 return;
140
141 ThumbnailData *data = tde->m_thumb;
142
143 QString file = data->url;
144 uint pos = data->data.value<uint>();
145
146 if (file.isEmpty())
147 return;
148
149 if (!((uint)m_resultsList->GetCount() >= pos))
150 return;
151
154
155 if (item)
156 {
157 item->SetImage(file);
158 }
159 }
160}
161
163{
165 m_results.clear();
166 emit haveResult(lookup);
167 Close();
168}
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