MythTV  master
imagethumbs.h
Go to the documentation of this file.
1 
14 #ifndef IMAGETHUMBS_H
15 #define IMAGETHUMBS_H
16 
17 #include <QMap>
18 #include <QMutex>
19 #include <QWaitCondition>
20 
21 #include "imagetypes.h"
22 #include "mthread.h"
23 
33 };
34 
35 
38 {
39 public:
40 
48  ThumbTask(QString action, ImagePtrK im,
49  int priority = kUrgentPriority, bool notify = false)
50  : m_action(action), m_priority(priority), m_notify(notify)
51  { m_images.append(im); }
52 
61  ThumbTask(QString action, const ImageListK &list,
62  int priority = kUrgentPriority, bool notify = false)
63  : m_images(list),
64  m_action(action),
65  m_priority(priority),
66  m_notify(notify) {}
67 
71  QString m_action;
75  bool m_notify;
76 };
77 
78 typedef QSharedPointer<ThumbTask> TaskPtr;
79 
80 
82 template <class DBFS>
83 class ThumbThread : public MThread
84 {
85 public:
91  ThumbThread(const QString &name, DBFS *const dbfs)
92  : MThread(name), m_dbfs(*dbfs) {}
93  ~ThumbThread();
94 
95  void cancel();
96  void Enqueue(const TaskPtr &task);
97  void AbortDevice(int devId, const QString &action);
98  void PauseBackground(bool pause);
99 
100 protected:
101  void run() override; // MThread
102 
103 private:
104  Q_DISABLE_COPY(ThumbThread)
105 
106 
107  typedef QMultiMap<int, TaskPtr> ThumbQueue;
108 
109  QString CreateThumbnail(ImagePtrK im, int thumbPriority);
110  static void RemoveTasks(ThumbQueue &queue, int devId);
111 
112  DBFS &m_dbfs;
113  QWaitCondition m_taskDone;
114 
117  bool m_doBackground {true};
118  QMutex m_mutex;
119 };
120 
121 
122 template <class DBFS>
124 {
125 public:
126  explicit ImageThumb(DBFS *const dbfs);
127  ~ImageThumb();
128 
129  void ClearThumbs(int devId, const QString &action);
130  QString DeleteThumbs(const ImageList &images);
131  void CreateThumbnail(const ImagePtrK &im,
132  int priority = kBackgroundPriority,
133  bool notify = false);
134  void MoveThumbnail(const ImagePtrK &im);
135  void PauseBackground(bool pause);
136 
137 private:
138  Q_DISABLE_COPY(ImageThumb)
139 
140 
141  // Major element = tree depth, so shallow thumbs are created before deep ones
142  // Minor element = id, so thumbs are created in order they were scanned
143  // If not unique, QMultiMap will process later requests before earlier ones
145  { return im.m_filePath.count('/') * 1000 + im.m_id; }
146 
148  DBFS &m_dbfs;
153 };
154 
155 #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:152
Scanner background request.
Definition: imagethumbs.h:32
ThumbQueue m_requestQ
Synchronises completed tasks.
Definition: imagethumbs.h:115
ThumbQueue m_backgroundQ
Priority queue of background tasks.
Definition: imagethumbs.h:116
void PauseBackground(bool pause)
Pauses or restarts processing of background tasks (scanner requests)
QSharedPointer< ThumbTask > TaskPtr
Definition: imagethumbs.h:78
ThumbTask(QString action, ImagePtrK im, int priority=kUrgentPriority, bool notify=false)
Construct request for a single image.
Definition: imagethumbs.h:48
A generator worker thread.
Definition: imagethumbs.h:83
#define META_PUBLIC
Definition: mythmetaexp.h:9
bool m_notify
If true, a "THUMBNAIL_CREATED" event is broadcast.
Definition: imagethumbs.h:75
A generator request that is queued.
Definition: imagethumbs.h:37
bool m_doBackground
Whether to process background tasks.
Definition: imagethumbs.h:117
const char * name
Definition: ParseText.cpp:328
Common types used by Gallery.
QString CreateThumbnail(ImagePtrK im, int thumbPriority)
Generate thumbnail for an image.
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:179
QList< ImagePtr > ImageList
Definition: imagetypes.h:174
DBFS & m_dbfs
Db/filesystem adapter.
Definition: imagethumbs.h:148
Scanner request needed to complete a scan.
Definition: imagethumbs.h:29
Client request to display an image thumbnail.
Definition: imagethumbs.h:30
~ThumbThread()
Destructor.
Definition: imagethumbs.cpp:19
int m_priority
Request reason/priority.
Definition: imagethumbs.h:73
void cancel()
Clears all queues so that the thread will terminate.
Definition: imagethumbs.cpp:30
ThumbTask(QString action, const ImageListK &list, int priority=kUrgentPriority, bool notify=false)
Construct request for a list of images/dirs.
Definition: imagethumbs.h:61
Client request to display a directory thumbnail.
Definition: imagethumbs.h:31
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:150
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:112
ImageThumbPriority
Priority of a thumbnail request.
Definition: imagethumbs.h:28
QWaitCondition m_taskDone
Definition: imagethumbs.h:113
QMultiMap< int, TaskPtr > ThumbQueue
A priority queue where 0 is highest priority.
Definition: imagethumbs.h:107
ThumbThread(const QString &name, DBFS *const dbfs)
Constructor.
Definition: imagethumbs.h:91
QMutex m_mutex
Queue protection.
Definition: imagethumbs.h:118
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:180
void Enqueue(const TaskPtr &task)
Queues a Create request.
Definition: imagethumbs.cpp:44
QString m_action
Request action: Create, delete etc.
Definition: imagethumbs.h:71
ImageListK m_images
Images for thumbnail task.
Definition: imagethumbs.h:69