MythTV master
mythuiimageresults.cpp
Go to the documentation of this file.
1
3
4// C++
5#include <ranges>
6
7// Qt
8#include <QDir>
9#include <QFile>
10
11// MythTV
16
18
20 MythScreenStack *lparent,
21 ArtworkList list,
22 const VideoArtworkType type) :
23
24 MythScreenType(lparent, "videosearchresultspopup"),
25 m_list(std::move(list)),
26 m_type(type),
27 m_imageDownload(new MetadataImageDownload(this))
28{
29}
30
32{
34
36 {
37 delete m_imageDownload;
38 m_imageDownload = nullptr;
39 }
40}
41
43{
44 if (!LoadWindowFromXML("base.xml", "MythArtworkResults", this))
45 return false;
46
47 bool err = false;
48 UIUtilE::Assign(this, m_resultsList, "results", &err);
49 if (err)
50 {
51 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythArtworkResults'");
52 return false;
53 }
54
55 for (const auto & info : std::as_const(m_list))
56 {
57 auto *button = new MythUIButtonListItem(m_resultsList, QString());
58 button->SetText(info.label, "label");
59 button->SetText(info.thumbnail, "thumbnail");
60 button->SetText(info.url, "url");
61 QString width = QString::number(info.width);
62 QString height = QString::number(info.height);
63 button->SetText(width, "width");
64 button->SetText(height, "height");
65 if (info.width > 0 && info.height > 0)
66 button->SetText(QString("%1x%2").arg(width, height),
67 "resolution");
68
69 QString artfile = info.thumbnail;
70
71 if (artfile.isEmpty())
72 artfile = info.url;
73
74 QString dlfile = getDownloadFilename(info.label,
75 artfile);
76
77 if (!artfile.isEmpty())
78 {
79 int pos = m_resultsList->GetItemPos(button);
80
81 if (QFile::exists(dlfile))
82 button->SetImage(dlfile);
83 else
84 {
86 artfile,
87 QVariant::fromValue<uint>(pos));
88 }
89 }
90
91 button->SetData(QVariant::fromValue<ArtworkInfo>(info));
92 }
93
96
98
99 return true;
100}
101
103{
104 QString cache = QString("%1/cache/metadata-thumbcache")
105 .arg(GetConfDir());
106 QDir cacheDir(cache);
107 QStringList thumbs = cacheDir.entryList(QDir::Files);
108
109 for (const auto & thumb : std::ranges::reverse_view(std::as_const(thumbs)))
110 {
111 QString filename = QString("%1/%2").arg(cache, thumb);
112 QFileInfo fi(filename);
113 QDateTime lastmod = fi.lastModified();
114 if (lastmod.addDays(2) < MythDate::current())
115 {
116 LOG(VB_GENERAL, LOG_DEBUG, QString("Deleting file %1")
117 .arg(filename));
118 QFile::remove(filename);
119 }
120 }
121}
122
124{
125 if (event->type() == ThumbnailDLEvent::kEventType)
126 {
127 auto *tde = dynamic_cast<ThumbnailDLEvent *>(event);
128 if (tde == nullptr)
129 return;
130
131 ThumbnailData *data = tde->m_thumb;
132
133 QString file = data->url;
134 uint pos = data->data.value<uint>();
135
136 if (file.isEmpty())
137 return;
138
139 if (!((uint)m_resultsList->GetCount() >= pos))
140 return;
141
144
145 if (item)
146 {
147 item->SetImage(file);
148 }
149 }
150}
151
153{
154 emit haveResult(item->GetData().value<ArtworkInfo>(),
155 m_type);
156 Close();
157}
158
MythUIButtonList * m_resultsList
void haveResult(ArtworkInfo, VideoArtworkType)
MetadataImageDownload * m_imageDownload
ImageSearchResultsDialog(MythScreenStack *lparent, ArtworkList list, VideoArtworkType type)
void sendResult(MythUIButtonListItem *item)
void customEvent(QEvent *event) override
void addThumb(QString title, QString url, QVariant data)
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
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
VideoArtworkType
QString GetConfDir(void)
Definition: mythdirs.cpp:285
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
dictionary info
Definition: azlyrics.py:7
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