MythTV
master
libs
libmythmetadata
mythuimetadataresults.cpp
Go to the documentation of this file.
1
2
#include "
mythuimetadataresults.h
"
3
4
#include "
mythuiimage.h
"
5
#include "
mythuitext.h
"
6
#include "
mythuistatetype.h
"
7
#include "
mythmainwindow.h
"
8
#include "
mythdialogbox.h
"
9
#include "
mythdate.h
"
10
#include "
mythdirs.h
"
11
#include "
mythlogging.h
"
12
13
#include "
metadatadownload.h
"
14
#include "
metadataimagedownload.h
"
15
16
MetadataResultsDialog::MetadataResultsDialog
(
17
MythScreenStack
*lparent,
18
const
MetadataLookupList
&
results
) :
19
20
MythScreenType
(lparent,
"metadataresultspopup"
),
21
m_results(
results
)
22
{
23
m_imageDownload
=
new
MetadataImageDownload
(
this
);
24
}
25
26
MetadataResultsDialog::~MetadataResultsDialog
()
27
{
28
cleanCacheDir
();
29
30
if
(
m_imageDownload
)
31
{
32
delete
m_imageDownload
;
33
m_imageDownload
=
nullptr
;
34
}
35
}
36
37
bool
MetadataResultsDialog::Create
()
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
98
connect(
m_resultsList
, &
MythUIButtonList::itemClicked
,
99
this
, &
MetadataResultsDialog::sendResult
);
100
101
BuildFocusList
();
102
103
return
true
;
104
}
105
106
void
MetadataResultsDialog::cleanCacheDir
()
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).arg(*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
127
void
MetadataResultsDialog::customEvent
(QEvent *event)
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
146
MythUIButtonListItem
*item =
147
m_resultsList
->
GetItemAt
(pos);
148
149
if
(item)
150
{
151
item->
SetImage
(
file
);
152
}
153
}
154
}
155
156
void
MetadataResultsDialog::sendResult
(
MythUIButtonListItem
* item)
157
{
158
RefCountHandler<MetadataLookup>
lookup =
m_results
.
takeAtAndDecr
(item->
GetData
().value<
uint
>());
159
m_results
.clear();
160
emit
haveResult
(lookup);
161
Close
();
162
}
MythUIButtonList::GetItemAt
MythUIButtonListItem * GetItemAt(int pos) const
Definition:
mythuibuttonlist.cpp:1676
mythuimetadataresults.h
RefCountHandler
Definition:
referencecounterlist.h:17
mythuitext.h
MetadataImageDownload
Definition:
metadataimagedownload.h:87
MetadataResultsDialog::customEvent
void customEvent(QEvent *event) override
Definition:
mythuimetadataresults.cpp:127
MythScreenType::Close
virtual void Close()
Definition:
mythscreentype.cpp:402
ArtworkList
QList< ArtworkInfo > ArtworkList
Definition:
metadataimagehelper.h:30
mythdialogbox.h
MythScreenStack
Definition:
mythscreenstack.h:16
arg
arg(title).arg(filename).arg(doDelete))
MetadataResultsDialog::m_results
MetadataLookupList m_results
Definition:
mythuimetadataresults.h:26
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition:
mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition:
mythscreentype.h:44
MetadataImageDownload::addThumb
void addThumb(QString title, QString url, QVariant data)
Definition:
metadataimagedownload.cpp:35
mythuistatetype.h
build_compdb.file
file
Definition:
build_compdb.py:55
mythdirs.h
mythuiimage.h
MythUIButtonList::GetCount
int GetCount() const
Definition:
mythuibuttonlist.cpp:1655
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition:
mythdate.cpp:10
InfoMap
QHash< QString, QString > InfoMap
Definition:
mythtypes.h:15
MythUIButtonList::GetItemPos
int GetItemPos(MythUIButtonListItem *item) const
Definition:
mythuibuttonlist.cpp:1698
hardwareprofile.os_detect.results
results
Definition:
os_detect.py:296
getDownloadFilename
QString getDownloadFilename(const QString &title, const QString &url)
Definition:
metadataimagedownload.cpp:334
MythUIButtonListItem
Definition:
mythuibuttonlist.h:27
mythdate.h
ThumbnailDLEvent::kEventType
static Type kEventType
Definition:
metadataimagedownload.h:84
mythlogging.h
GetConfDir
QString GetConfDir(void)
Definition:
mythdirs.cpp:224
MythUIButtonList::itemClicked
void itemClicked(MythUIButtonListItem *item)
MetadataResultsDialog::Create
bool Create() override
Definition:
mythuimetadataresults.cpp:37
ThumbnailData::url
QString url
Definition:
metadataimagedownload.h:15
metadatadownload.h
metadataimagedownload.h
RefCountedList< MetadataLookup >
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition:
mythscreentype.cpp:222
RefCountedList::takeAtAndDecr
RefCountHandler< T > takeAtAndDecr(int i)
Removes the item at index position i and returns it.
Definition:
referencecounterlist.h:102
ThumbnailDLEvent
Definition:
metadataimagedownload.h:70
filename
QString filename
Definition:
mythplugins/mytharchive/mytharchivehelper/main.cpp:637
MythUIButtonListItem::GetData
QVariant GetData()
Definition:
mythuibuttonlist.cpp:3580
RefCountedList::takeFirst
T * takeFirst(void)
Removes the first item in the list and returns it.
Definition:
referencecounterlist.h:78
uint
unsigned int uint
Definition:
compat.h:141
ThumbnailData::data
QVariant data
Definition:
metadataimagedownload.h:14
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition:
mythuiutils.h:27
MetadataResultsDialog::m_imageDownload
MetadataImageDownload * m_imageDownload
Definition:
mythuimetadataresults.h:28
MetadataResultsDialog::haveResult
void haveResult(RefCountHandler< MetadataLookup >)
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition:
xmlparsebase.cpp:692
MythUIButtonListItem::SetImage
void SetImage(MythImage *image, const QString &name="")
Sets an image directly, should only be used in special circumstances since it bypasses the cache.
Definition:
mythuibuttonlist.cpp:3398
kArtworkBanner
@ kArtworkBanner
Definition:
metadataimagehelper.h:13
MetadataResultsDialog::cleanCacheDir
static void cleanCacheDir()
Definition:
mythuimetadataresults.cpp:106
kArtworkScreenshot
@ kArtworkScreenshot
Definition:
metadataimagehelper.h:14
ThumbnailData
Definition:
metadataimagedownload.h:12
MetadataResultsDialog::sendResult
void sendResult(MythUIButtonListItem *item)
Definition:
mythuimetadataresults.cpp:156
mythmainwindow.h
MetadataResultsDialog::~MetadataResultsDialog
~MetadataResultsDialog() override
Definition:
mythuimetadataresults.cpp:26
kArtworkCoverart
@ kArtworkCoverart
Definition:
metadataimagehelper.h:11
MetadataResultsDialog::MetadataResultsDialog
MetadataResultsDialog(MythScreenStack *lparent, const MetadataLookupList &results)
Definition:
mythuimetadataresults.cpp:16
MetadataResultsDialog::m_resultsList
MythUIButtonList * m_resultsList
Definition:
mythuimetadataresults.h:27
Generated on Sun Jan 24 2021 03:17:11 for MythTV by
1.8.17