MythTV  master
metadataimagedownload.h
Go to the documentation of this file.
1 #ifndef METADATAIMAGEDOWNLOAD_H
2 #define METADATAIMAGEDOWNLOAD_H
3 
4 #include <QString>
5 #include <QStringList>
6 #include <QMutex>
7 
8 #include "mthread.h"
9 #include "mythmetaexp.h"
10 #include "metadatacommon.h"
11 
12 struct ThumbnailData {
13  QString title;
14  QVariant data;
15  QString url;
16 };
17 
18 class META_PUBLIC ImageDLEvent : public QEvent
19 {
20  public:
21  explicit ImageDLEvent(MetadataLookup *lookup) :
22  QEvent(kEventType),
23  m_item(lookup)
24  {
25  if (m_item)
26  {
27  m_item->IncrRef();
28  }
29  }
30  ~ImageDLEvent() override
31  {
32  if (m_item)
33  {
34  m_item->DecrRef();
35  m_item = nullptr;
36  }
37  }
38 
39  MetadataLookup *m_item {nullptr};
40 
41  static Type kEventType;
42 };
43 
44 class META_PUBLIC ImageDLFailureEvent : public QEvent
45 {
46  public:
47  explicit ImageDLFailureEvent(MetadataLookup *lookup) :
48  QEvent(kEventType),
49  m_item(lookup)
50  {
51  if (m_item)
52  {
53  m_item->IncrRef();
54  }
55  }
57  {
58  if (m_item)
59  {
60  m_item->DecrRef();
61  m_item = nullptr;
62  }
63  }
64 
65  MetadataLookup *m_item {nullptr};
66 
67  static Type kEventType;
68 };
69 
70 class META_PUBLIC ThumbnailDLEvent : public QEvent
71 {
72  public:
73  explicit ThumbnailDLEvent(ThumbnailData *data) :
74  QEvent(kEventType),
75  m_thumb(data) {}
76  ~ThumbnailDLEvent() override
77  {
78  delete m_thumb;
79  m_thumb = nullptr;
80  }
81 
82  ThumbnailData *m_thumb {nullptr};
83 
84  static Type kEventType;
85 };
86 
88 {
89  public:
90 
91  explicit MetadataImageDownload(QObject *parent)
92  : MThread("MetadataImageDownload"), m_parent(parent) {}
93  ~MetadataImageDownload() override;
94 
95  void addThumb(QString title, QString url, QVariant data);
96  void addDownloads(MetadataLookup *lookup);
97  void cancel();
98 
99  protected:
100 
101  void run() override; // MThread
102 
103  private:
104 
105  ThumbnailData* moreThumbs();
106 
107  QObject *m_parent;
109  QList<ThumbnailData*> m_thumbnailList;
110  QMutex m_mutex;
111 };
112 
113 META_PUBLIC QString getDownloadFilename(const QString& title, const QString& url);
115  const QString& url);
116 
118 META_PUBLIC QString getStorageGroupURL(VideoArtworkType type, const QString& host);
119 META_PUBLIC QString getLocalStorageGroupPath(VideoArtworkType type, const QString& host);
121 
123 
124 #endif /* METADATAIMAGEDOWNLOAD_H */
VideoArtworkType
VideoArtworkType
Definition: metadataimagehelper.h:10
cleanThumbnailCacheDir
META_PUBLIC void cleanThumbnailCacheDir(void)
Definition: metadataimagedownload.cpp:491
ImageDLEvent::~ImageDLEvent
~ImageDLEvent() override
Definition: metadataimagedownload.h:30
MetadataImageDownload
Definition: metadataimagedownload.h:88
MetadataType
MetadataType
Definition: metadatacommon.h:41
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:633
ImageDLFailureEvent::kEventType
static Type kEventType
Definition: metadataimagedownload.h:67
ImageDLFailureEvent::ImageDLFailureEvent
ImageDLFailureEvent(MetadataLookup *lookup)
Definition: metadataimagedownload.h:47
MetadataImageDownload::m_thumbnailList
QList< ThumbnailData * > m_thumbnailList
Definition: metadataimagedownload.h:109
ImageDLEvent
Definition: metadataimagedownload.h:19
MetadataImageDownload::MetadataImageDownload
MetadataImageDownload(QObject *parent)
Definition: metadataimagedownload.h:91
mythmetaexp.h
ImageDLEvent::ImageDLEvent
ImageDLEvent(MetadataLookup *lookup)
Definition: metadataimagedownload.h:21
MetadataImageDownload::m_downloadList
MetadataLookupList m_downloadList
Definition: metadataimagedownload.h:108
ThumbnailData::title
QString title
Definition: metadataimagedownload.h:13
MetadataLookup
Definition: metadatacommon.h:87
getStorageGroupName
META_PUBLIC QString getStorageGroupName(VideoArtworkType type)
Definition: metadataimagedownload.cpp:474
getDownloadFilename
META_PUBLIC QString getDownloadFilename(const QString &title, const QString &url)
Definition: metadataimagedownload.cpp:334
ThumbnailDLEvent::kEventType
static Type kEventType
Definition: metadataimagedownload.h:84
getLocalWritePath
META_PUBLIC QString getLocalWritePath(MetadataType metadatatype, VideoArtworkType type)
Definition: metadataimagedownload.cpp:424
ThumbnailData::url
QString url
Definition: metadataimagedownload.h:15
ImageDLFailureEvent
Definition: metadataimagedownload.h:45
RefCountedList< MetadataLookup >
ThumbnailDLEvent
Definition: metadataimagedownload.h:71
ThumbnailDLEvent::~ThumbnailDLEvent
~ThumbnailDLEvent() override
Definition: metadataimagedownload.h:76
MetadataImageDownload::m_parent
QObject * m_parent
Definition: metadataimagedownload.h:107
MetadataImageDownload::m_mutex
QMutex m_mutex
Definition: metadataimagedownload.h:110
ThumbnailData::data
QVariant data
Definition: metadataimagedownload.h:14
MThread::run
virtual void run(void)
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mthread.cpp:313
getStorageGroupURL
META_PUBLIC QString getStorageGroupURL(VideoArtworkType type, const QString &host)
Definition: metadataimagedownload.cpp:455
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
ImageDLFailureEvent::~ImageDLFailureEvent
~ImageDLFailureEvent() override
Definition: metadataimagedownload.h:56
mthread.h
getLocalStorageGroupPath
META_PUBLIC QString getLocalStorageGroupPath(VideoArtworkType type, const QString &host)
Definition: metadataimagedownload.cpp:463
ThumbnailData
Definition: metadataimagedownload.h:12
META_PUBLIC
#define META_PUBLIC
Definition: mythmetaexp.h:9
metadatacommon.h
ThumbnailDLEvent::ThumbnailDLEvent
ThumbnailDLEvent(ThumbnailData *data)
Definition: metadataimagedownload.h:73
ImageDLEvent::kEventType
static Type kEventType
Definition: metadataimagedownload.h:41