MythTV  master
imagethumbs.h
Go to the documentation of this file.
1 
14 #ifndef IMAGETHUMBS_H
15 #define IMAGETHUMBS_H
16 
17 #include <utility>
18 
19 // Qt headers
20 #include <QMap>
21 #include <QMutex>
22 #include <QWaitCondition>
23 
24 // MythTV headers
25 #include "imagetypes.h"
26 #include "mthread.h"
27 
37 };
38 
39 
42 {
43 public:
44 
52  ThumbTask(QString action, const ImagePtrK& im,
53  int priority = kUrgentPriority, bool notify = false)
54  : m_action(std::move(action)), m_priority(priority), m_notify(notify)
55  { m_images.append(im); }
56 
65  ThumbTask(QString action, ImageListK list,
66  int priority = kUrgentPriority, bool notify = false)
67  : m_images(std::move(list)),
68  m_action(std::move(action)),
69  m_priority(priority),
70  m_notify(notify) {}
71 
75  QString m_action;
79  bool m_notify;
80 };
81 
82 using TaskPtr = QSharedPointer<ThumbTask>;
83 
84 
86 template <class DBFS>
87 class ThumbThread : public MThread
88 {
89 public:
95  ThumbThread(const QString &name, DBFS *const dbfs)
96  : MThread(name), m_dbfs(*dbfs) {}
97  ~ThumbThread() override;
98 
99  void cancel();
100  void Enqueue(const TaskPtr &task);
101  void AbortDevice(int devId, const QString &action);
102  void PauseBackground(bool pause);
103 
104 protected:
105  void run() override; // MThread
106 
107 private:
108  Q_DISABLE_COPY(ThumbThread)
109 
110 
111  using ThumbQueue = QMultiMap<int, TaskPtr>;
112 
113  QString CreateThumbnail(ImagePtrK im, int thumbPriority);
114  static void RemoveTasks(ThumbQueue &queue, int devId);
115 
116  DBFS &m_dbfs;
117  QWaitCondition m_taskDone;
118 
121  bool m_doBackground {true};
122  QMutex m_mutex;
123 };
124 
125 
126 template <class DBFS>
128 {
129 public:
130  explicit ImageThumb(DBFS *dbfs);
131  ~ImageThumb();
132 
133  void ClearThumbs(int devId, const QString &action);
134  QString DeleteThumbs(const ImageList &images);
135  void CreateThumbnail(const ImagePtrK &im,
136  int priority = kBackgroundPriority,
137  bool notify = false);
138  void MoveThumbnail(const ImagePtrK &im);
139  void PauseBackground(bool pause);
140 
141 private:
142  Q_DISABLE_COPY(ImageThumb)
143 
144 
145  // Major element = tree depth, so shallow thumbs are created before deep ones
146  // Minor element = id, so thumbs are created in order they were scanned
147  // If not unique, QMultiMap will process later requests before earlier ones
149  { return im.m_filePath.count('/') * 1000 + im.m_id; }
150 
152  DBFS &m_dbfs;
157 };
158 
159 #endif // IMAGETHUMBS_H
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
static void RemoveTasks(ThumbQueue &queue, int devId)
Definition: imagethumbs.cpp:98
ThumbThread< DBFS > * m_videoThread
Thread generating video previews.
Definition: imagethumbs.h:156
Scanner background request.
Definition: imagethumbs.h:36
QMultiMap< int, TaskPtr > ThumbQueue
A priority queue where 0 is highest priority.
Definition: imagethumbs.h:111
~ThumbThread() override
Destructor.
Definition: imagethumbs.cpp:19
ThumbQueue m_requestQ
Synchronises completed tasks.
Definition: imagethumbs.h:119
ThumbQueue m_backgroundQ
Priority queue of background tasks.
Definition: imagethumbs.h:120
void PauseBackground(bool pause)
Pauses or restarts processing of background tasks (scanner requests)
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:172
ThumbTask(QString action, const ImagePtrK &im, int priority=kUrgentPriority, bool notify=false)
Construct request for a single image.
Definition: imagethumbs.h:52
A generator worker thread.
Definition: imagethumbs.h:87
#define META_PUBLIC
Definition: mythmetaexp.h:9
bool m_notify
If true, a "THUMBNAIL_CREATED" event is broadcast.
Definition: imagethumbs.h:79
A generator request that is queued.
Definition: imagethumbs.h:41
bool m_doBackground
Whether to process background tasks.
Definition: imagethumbs.h:121
Common types used by Gallery.
QString CreateThumbnail(ImagePtrK im, int thumbPriority)
Generate thumbnail for an image.
QList< ImagePtr > ImageList
Definition: imagetypes.h:167
DBFS & m_dbfs
Db/filesystem adapter.
Definition: imagethumbs.h:152
Scanner request needed to complete a scan.
Definition: imagethumbs.h:33
Client request to display an image thumbnail.
Definition: imagethumbs.h:34
int m_priority
Request reason/priority.
Definition: imagethumbs.h:77
void cancel()
Clears all queues so that the thread will terminate.
Definition: imagethumbs.cpp:30
Client request to display a directory thumbnail.
Definition: imagethumbs.h:35
ThumbTask(QString action, ImageListK list, int priority=kUrgentPriority, bool notify=false)
Construct request for a list of images/dirs.
Definition: imagethumbs.h:65
void AbortDevice(int devId, const QString &action)
Clears thumbnail request queue.
Definition: imagethumbs.cpp:68
ThumbThread< DBFS > * m_imageThread
Thread generating picture thumbnails.
Definition: imagethumbs.h:154
Represents a picture, video or directory.
Definition: imagetypes.h:67
void run() override
Handles thumbnail requests by priority.
DBFS & m_dbfs
Database/filesystem adapter.
Definition: imagethumbs.h:116
ImageThumbPriority
Priority of a thumbnail request.
Definition: imagethumbs.h:32
QWaitCondition m_taskDone
Definition: imagethumbs.h:117
ThumbThread(const QString &name, DBFS *const dbfs)
Constructor.
Definition: imagethumbs.h:95
QSharedPointer< ThumbTask > TaskPtr
Definition: imagethumbs.h:82
QMutex m_mutex
Queue protection.
Definition: imagethumbs.h:122
void Enqueue(const TaskPtr &task)
Queues a Create request.
Definition: imagethumbs.cpp:44
QString m_action
Request action: Create, delete etc.
Definition: imagethumbs.h:75
ImageListK m_images
Images for thumbnail task.
Definition: imagethumbs.h:73
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:173