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 "libmythbase/mthread.h"
26 #include "imagetypes.h"
27 
32 enum ImageThumbPriority : std::int8_t {
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(const 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
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
ThumbThread::m_requestQ
ThumbQueue m_requestQ
Synchronises completed tasks.
Definition: imagethumbs.h:119
ImageThumbPriority
ImageThumbPriority
Priority of a thumbnail request.
Definition: imagethumbs.h:32
ThumbThread::m_mutex
QMutex m_mutex
Queue protection.
Definition: imagethumbs.h:122
ThumbThread::~ThumbThread
~ThumbThread() override
Destructor.
Definition: imagethumbs.cpp:18
kPicRequestPriority
@ kPicRequestPriority
Client request to display an image thumbnail.
Definition: imagethumbs.h:34
ThumbTask::m_priority
int m_priority
Request reason/priority.
Definition: imagethumbs.h:77
ThumbThread::RemoveTasks
static void RemoveTasks(ThumbQueue &queue, int devId)
Definition: imagethumbs.cpp:101
ThumbThread::m_backgroundQ
ThumbQueue m_backgroundQ
Priority queue of background tasks.
Definition: imagethumbs.h:120
ThumbThread< ImageDbSg >::ThumbQueue
QMultiMap< int, TaskPtr > ThumbQueue
A priority queue where 0 is highest priority.
Definition: imagethumbs.h:111
ImageThumb
Definition: imagethumbs.h:127
kUrgentPriority
@ kUrgentPriority
Scanner request needed to complete a scan.
Definition: imagethumbs.h:33
ThumbThread::PauseBackground
void PauseBackground(bool pause)
Pauses or restarts processing of background tasks (scanner requests)
Definition: imagethumbs.cpp:325
ThumbThread::m_doBackground
bool m_doBackground
Whether to process background tasks.
Definition: imagethumbs.h:121
imagetypes.h
Common types used by Gallery.
ThumbTask::ThumbTask
ThumbTask(QString action, ImageListK list, int priority=kUrgentPriority, bool notify=false)
Construct request for a list of images/dirs.
Definition: imagethumbs.h:65
ImageListK
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:166
ThumbThread::cancel
void cancel()
Clears all queues so that the thread will terminate.
Definition: imagethumbs.cpp:29
ThumbThread
A generator worker thread.
Definition: imagethumbs.h:87
ImageList
QVector< ImagePtr > ImageList
Definition: imagetypes.h:160
ThumbThread::AbortDevice
void AbortDevice(int devId, const QString &action)
Clears thumbnail request queue.
Definition: imagethumbs.cpp:67
kDirRequestPriority
@ kDirRequestPriority
Client request to display a directory thumbnail.
Definition: imagethumbs.h:35
ThumbTask
A generator request that is queued.
Definition: imagethumbs.h:41
ThumbTask::m_images
ImageListK m_images
Images for thumbnail task.
Definition: imagethumbs.h:73
ThumbTask::ThumbTask
ThumbTask(QString action, const ImagePtrK &im, int priority=kUrgentPriority, bool notify=false)
Construct request for a single image.
Definition: imagethumbs.h:52
kBackgroundPriority
@ kBackgroundPriority
Scanner background request.
Definition: imagethumbs.h:36
TaskPtr
QSharedPointer< ThumbTask > TaskPtr
Definition: imagethumbs.h:82
ImageItem
Represents a picture, video or directory.
Definition: imagetypes.h:68
ImageThumb::m_videoThread
ThumbThread< DBFS > * m_videoThread
Thread generating video previews.
Definition: imagethumbs.h:156
ThumbThread::ThumbThread
ThumbThread(const QString &name, DBFS *const dbfs)
Constructor.
Definition: imagethumbs.h:95
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
ThumbTask::m_notify
bool m_notify
If true, a "THUMBNAIL_CREATED" event is broadcast.
Definition: imagethumbs.h:79
mthread.h
ThumbThread::Enqueue
void Enqueue(const TaskPtr &task)
Queues a Create request.
Definition: imagethumbs.cpp:43
build_compdb.action
action
Definition: build_compdb.py:9
ThumbThread::CreateThumbnail
QString CreateThumbnail(const ImagePtrK &im, int thumbPriority)
Generate thumbnail for an image.
Definition: imagethumbs.cpp:240
ThumbThread::m_dbfs
DBFS & m_dbfs
Database/filesystem adapter.
Definition: imagethumbs.h:116
ThumbThread::m_taskDone
QWaitCondition m_taskDone
Definition: imagethumbs.h:117
ImageThumb::m_imageThread
ThumbThread< DBFS > * m_imageThread
Thread generating picture thumbnails.
Definition: imagethumbs.h:154
ImageThumb::m_dbfs
DBFS & m_dbfs
Db/filesystem adapter.
Definition: imagethumbs.h:152
ThumbTask::m_action
QString m_action
Request action: Create, delete etc.
Definition: imagethumbs.h:75
META_PUBLIC
#define META_PUBLIC
Definition: mythmetaexp.h:9
ThumbThread::run
void run() override
Handles thumbnail requests by priority.
Definition: imagethumbs.cpp:123
Priority
Definition: channelsettings.cpp:216