MythTV  master
thumbgenerator.h
Go to the documentation of this file.
1 /* ============================================================
2  * File : thumbgenerator.h
3  * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
4  * Date : 2004-01-02
5  * Description :
6  *
7  * Copyright 2004 by Renchi Raju
8 
9  * This program is free software; you can redistribute it
10  * and/or modify it under the terms of the GNU General
11  * Public License as published bythe Free Software Foundation;
12  * either version 2, or (at your option)
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * ============================================================ */
21 
22 #ifndef THUMBGENERATOR_H
23 #define THUMBGENERATOR_H
24 
25 #include <QStringList>
26 #include <QImage>
27 
28 #include <mthread.h>
29 
30 class QObject;
31 class QImage;
32 
33 typedef struct {
34  QImage thumb;
35  QString fileName;
36  QString directory;
37 } ThumbData;
38 
39 class ThumbGenEvent : public QEvent
40 {
41  public:
42  explicit ThumbGenEvent(ThumbData *td) : QEvent(kEventType), m_thumbData(td) {}
43  ~ThumbGenEvent() = default;
44 
45  ThumbData *m_thumbData {nullptr};
46 
47  static Type kEventType;
48 };
49 
50 class ThumbGenerator : public MThread
51 {
52 public:
53 
54  ThumbGenerator(QObject *parent, int w, int h)
55  : MThread("ThumbGenerator"), m_parent(parent),
56  m_width(w), m_height(h) {}
58 
59  void setSize(int w, int h);
60  void setDirectory(const QString& directory, bool isGallery=false);
61  void addFile(const QString& filePath);
62  void cancel();
63 
64  static QString getThumbcacheDir(const QString& inDir);
65 
66 protected:
67 
68  void run() override; // MThread
69 
70 private:
71 
72  bool moreWork();
73  bool checkGalleryDir(const QFileInfo& fi);
74  bool checkGalleryFile(const QFileInfo& fi);
75  void loadDir(QImage& image, const QFileInfo& fi);
76  void loadFile(QImage& image, const QFileInfo& fi);
77 
78  QObject *m_parent {nullptr};
79  QString m_directory;
80  bool m_isGallery {false};
81  QStringList m_fileList;
82  QMutex m_mutex;
83  int m_width;
84  int m_height;
85  bool m_cancel {false};
86 };
87 
88 #endif /* THUMBGENERATOR_H */
QStringList m_fileList
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
QString fileName
QImage thumb
bool checkGalleryDir(const QFileInfo &fi)
~ThumbGenEvent()=default
void setDirectory(const QString &directory, bool isGallery=false)
QObject * m_parent
ThumbGenerator(QObject *parent, int w, int h)
static QString getThumbcacheDir(const QString &inDir)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
ThumbData * m_thumbData
bool checkGalleryFile(const QFileInfo &fi)
void loadDir(QImage &image, const QFileInfo &fi)
void loadFile(QImage &image, const QFileInfo &fi)
static Type kEventType
QString m_directory
void addFile(const QString &filePath)
ThumbGenEvent(ThumbData *td)
QString directory
void setSize(int w, int h)