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 {
83 button->SetImage(dlfile);
84 }
85 else
86 {
88 artfile,
89 QVariant::fromValue<uint>(pos));
90 }
91 }
92
93 button->SetData(QVariant::fromValue<ArtworkInfo>(info));
94 }
95
98
100
101 return true;
102}
103
105{
106 QString cache = QString("%1/cache/metadata-thumbcache")
107 .arg(GetConfDir());
108 QDir cacheDir(cache);
109 QStringList thumbs = cacheDir.entryList(QDir::Files);
110
111 for (const auto & thumb : std::ranges::reverse_view(std::as_const(thumbs)))
112 {
113 QString filename = QString("%1/%2").arg(cache, thumb);
114 QFileInfo fi(filename);
115 QDateTime lastmod = fi.lastModified();
116 if (lastmod.addDays(2) < MythDate::current())
117 {
118 LOG(VB_GENERAL, LOG_DEBUG, QString("Deleting file %1")
119 .arg(filename));
120 QFile::remove(filename);
121 }
122 }
123}
124
126{
127 if (event->type() == ThumbnailDLEvent::kEventType)
128 {
129 auto *tde = dynamic_cast<ThumbnailDLEvent *>(event);
130 if (tde == nullptr)
131 return;
132
133 ThumbnailData *data = tde->m_thumb;
134
135 QString file = data->url;
136 uint pos = data->data.value<uint>();
137
138 if (file.isEmpty())
139 return;
140
141 if (!((uint)m_resultsList->GetCount() >= pos))
142 return;
143
146
147 if (item)
148 {
149 item->SetImage(file);
150 }
151 }
152}
153
155{
156 emit haveResult(item->GetData().value<ArtworkInfo>(),
157 m_type);
158 Close();
159}
160
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