| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#ifndef IMAGEENGINEOBJECT_H |
| 22 |
#define IMAGEENGINEOBJECT_H |
| 23 |
|
| 24 |
#include "dbmanager/dbmanager.h" |
| 25 |
#include "thumbnail/thumbnaildelegate.h" |
| 26 |
|
| 27 |
#include <QObject> |
| 28 |
#include <QPixmap> |
| 29 |
#include <QThreadPool> |
| 30 |
#include <QRunnable> |
| 31 |
|
| 32 |
class ImageEngineThreadObject; |
| 33 |
|
| 34 |
//这里将QRunnable继承转移到这里,方便将run函数的实现也转移过来 |
| 35 |
class ImageEngineThreadObject : public QObject, public QRunnable |
| 36 |
{ |
| 37 |
Q_OBJECT |
| 38 |
public: |
| 39 |
ImageEngineThreadObject(); |
| 40 |
virtual void needStop(void *imageobject); |
| 41 |
|
| 42 |
signals: |
| 43 |
void runFinished(); |
| 44 |
|
| 45 |
protected: |
| 46 |
virtual bool ifCanStopThread(void *imgobject); |
| 47 |
|
| 48 |
//这里需要在run前run后执行一些操作,即需要一个装饰器 |
| 49 |
//但C++不支持像Python那样的装饰器操作,就只能先这样搞了 |
| 50 |
//由于thread pool固定执行run,所以后续继承的函数把操作全部扔进runDetail,多出来的操作扔进run |
| 51 |
virtual void run() override final;//使用final禁止后续继承修改run函数实现 |
| 52 |
virtual void runDetail() = 0; |
| 53 |
|
| 54 |
bool bneedstop = false; |
| 55 |
bool bbackstop = false; |
| 56 |
}; |
| 57 |
|
| 58 |
class ImageMountImportPathsObject |
| 59 |
{ |
| 60 |
public: |
| 61 |
ImageMountImportPathsObject(); |
| 62 |
virtual ~ImageMountImportPathsObject(); |
| 63 |
virtual bool imageMountImported(QStringList &filelist) = 0; |
| 64 |
void addThread(ImageEngineThreadObject *thread); |
| 65 |
void removeThread(ImageEngineThreadObject *thread); |
| 66 |
protected: |
| 67 |
void clearAndStopThread(); |
| 68 |
QList<ImageEngineThreadObject *> m_threads; |
| 69 |
}; |
| 70 |
|
| 71 |
class ImageMountGetPathsObject |
| 72 |
{ |
| 73 |
public: |
| 74 |
ImageMountGetPathsObject(); |
| 75 |
virtual ~ImageMountGetPathsObject(); |
| 76 |
virtual bool imageGeted(QStringList &filelist, QString path) = 0; |
| 77 |
void addThread(ImageEngineThreadObject *thread); |
| 78 |
void removeThread(ImageEngineThreadObject *thread); |
| 79 |
protected: |
| 80 |
void clearAndStopThread(); |
| 81 |
QList<ImageEngineThreadObject *> m_threads; |
| 82 |
}; |
| 83 |
|
| 84 |
class ImageEngineImportObject |
| 85 |
{ |
| 86 |
public: |
| 87 |
ImageEngineImportObject(); |
| 88 |
virtual ~ImageEngineImportObject(); |
| 89 |
virtual bool imageImported(bool success) = 0; |
| 90 |
void addThread(ImageEngineThreadObject *thread); |
| 91 |
void removeThread(ImageEngineThreadObject *thread); |
| 92 |
|
| 93 |
protected: |
| 94 |
void clearAndStopThread(); |
| 95 |
QList<ImageEngineThreadObject *> m_threads; |
| 96 |
}; |
| 97 |
|
| 98 |
class ImageEngineObject |
| 99 |
{ |
| 100 |
public: |
| 101 |
ImageEngineObject(); |
| 102 |
virtual ~ImageEngineObject(); |
| 103 |
virtual bool imageLoaded(QString filepath) = 0; |
| 104 |
virtual bool imageLocalLoaded(QStringList &filelist) = 0; |
| 105 |
virtual bool imageFromDBLoaded(QStringList &filelist) = 0; |
| 106 |
void addThread(ImageEngineThreadObject *thread); |
| 107 |
void removeThread(ImageEngineThreadObject *thread); |
| 108 |
void addCheckPath(QString &path); |
| 109 |
void checkSelf(); |
| 110 |
|
| 111 |
// void checkAndReturnPath(QString &path);//保证顺序排列 |
| 112 |
protected: |
| 113 |
void clearAndStopThread(); |
| 114 |
QList<ImageEngineThreadObject *> m_threads; |
| 115 |
QStringList m_checkpath; |
| 116 |
QStringList m_pathlast; |
| 117 |
QMutex m_mutexthread; |
| 118 |
}; |
| 119 |
|
| 120 |
//这是一个用于生成缓存的队列 |
| 121 |
class ImageCacheSaveObject : public QObject |
| 122 |
{ |
| 123 |
Q_OBJECT |
| 124 |
public: |
| 125 |
ImageCacheSaveObject(); |
| 126 |
public: |
| 127 |
bool add(const QStringList &paths); |
| 128 |
bool add(const QString &path); |
| 129 |
QString pop(); |
| 130 |
bool isEmpty(); |
| 131 |
private: |
| 132 |
QList<QString> requestQueue; |
| 133 |
QMutex m_queuqMutex; |
| 134 |
}; |
| 135 |
|
| 136 |
|
| 137 |
#endif // IMAGEENGINEOBJECT_H |