| 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 IMAGEENGINEAPI_H |
| 22 |
#define IMAGEENGINEAPI_H |
| 23 |
|
| 24 |
#include <QObject> |
| 25 |
#include <QMap> |
| 26 |
#include <QUrl> |
| 27 |
#include "imageenginethread.h" |
| 28 |
#include "imageengineobject.h" |
| 29 |
#include "thumbnail/thumbnaildelegate.h" |
| 30 |
|
| 31 |
//加载图片的频率 |
| 32 |
const int Number_Of_Displays_Per_Time = 32; |
| 33 |
|
| 34 |
//#define NOGLOBAL; //是否启用全局线程 |
| 35 |
class DBandImgOperate; |
| 36 |
|
| 37 |
class ImageEngineApi: public QObject |
| 38 |
{ |
| 39 |
Q_OBJECT |
| 40 |
public: |
| 41 |
static ImageEngineApi *instance(QObject *parent = nullptr); |
| 42 |
~ImageEngineApi(); |
| 43 |
|
| 44 |
//reLoadIsvideo为true,重新判断是否是视频 |
| 45 |
bool insertImage(const QString &imagepath, const QString &remainDay, bool reLoadIsvideo = false); |
| 46 |
bool removeImage(QString imagepath); |
| 47 |
bool removeImage(QStringList imagepathList); |
| 48 |
bool insertObject(void *obj); |
| 49 |
bool removeObject(void *obj); |
| 50 |
bool ifObjectExist(void *obj); |
| 51 |
bool getImageData(QString imagepath, DBImgInfo &data); |
| 52 |
bool ImportImagesFromFileList(QStringList files, QString albumname, ImageEngineImportObject *obj, bool bdialogselect = false); |
| 53 |
bool ImportImagesFromUrlList(QList<QUrl> files, QString albumname, ImageEngineImportObject *obj, bool bdialogselect = false); |
| 54 |
void setImgPathAndAlbumNames(); |
| 55 |
void setImgPathAndAlbumNames(const QMultiMap<QString, QString> &imgPahtAlbums); |
| 56 |
const QMultiMap<QString, QString> &getImgPathAndAlbumNames(); |
| 57 |
//清理删除时间过长图片 |
| 58 |
void cleanUpTrash(const DBImgInfoList &list); |
| 59 |
//过滤不存在图片后重新加载 |
| 60 |
bool reloadAfterFilterUnExistImage(); |
| 61 |
//判断是否视频 |
| 62 |
bool isVideo(QString path); |
| 63 |
//全部数据数量 |
| 64 |
int getAllImageDataCount(); |
| 65 |
//添加数据 |
| 66 |
void addImageData(QString path, DBImgInfo data); |
| 67 |
//清除全部数据 |
| 68 |
void clearAllImageData(); |
| 69 |
//判断是否已经从数据库加载过,或者是否已经加载到缓存里了 |
| 70 |
bool isItemLoadedFromDB(QString path); |
| 71 |
|
| 72 |
//从外部启动,启用线程加载图片 |
| 73 |
bool loadImagesFromNewAPP(QStringList files, ImageEngineImportObject *obj); |
| 74 |
bool importImageFilesFromMount(QString albumname, QStringList paths, ImageMountImportPathsObject *obj); |
| 75 |
bool moveImagesToTrash(QStringList files, bool typetrash = false, bool bneedprogress = true); |
| 76 |
bool recoveryImagesFromTrash(QStringList files); |
| 77 |
|
| 78 |
QStringList get_AllImagePath(); |
| 79 |
|
| 80 |
bool loadImageDateToMemory(QStringList pathlist, QString devName); |
| 81 |
|
| 82 |
void close() |
| 83 |
{ |
| 84 |
bcloseFg = true; |
| 85 |
} |
| 86 |
bool closeFg() |
| 87 |
{ |
| 88 |
return bcloseFg; |
| 89 |
} |
| 90 |
void loadFirstPageThumbnails(int num, bool clearCache = true); |
| 91 |
void thumbnailLoadThread(int num); |
| 92 |
|
| 93 |
//设置线程循环跳出 |
| 94 |
void setThreadShouldStop(); |
| 95 |
//根据路径制作缩略图,并保存到指定位置 |
| 96 |
// bool makeThumbnailByPaths(QStringList files); |
| 97 |
private slots: |
| 98 |
// void sltImageLocalLoaded(void *imgobject, QStringList &filelist); |
| 99 |
// void sltImageDBLoaded(void *imgobject, QStringList &filelist); |
| 100 |
// void sltImageFilesGeted(void *imgobject, QStringList &filelist, QString path); |
| 101 |
void sltImageFilesImported(void *imgobject, QStringList &filelist); |
| 102 |
// void sltstopCacheSave(); |
| 103 |
|
| 104 |
void sigImageBackLoaded(QString path, const DBImgInfo &data); |
| 105 |
|
| 106 |
void slt80ImgInfosReady(QVector<DBImgInfo> ImageDatas); |
| 107 |
signals: |
| 108 |
//发送给主线程 |
| 109 |
//加载到数据库完成 |
| 110 |
void sigLoadCompleted(); |
| 111 |
//发送给缩略图控件 |
| 112 |
void sigLoadFirstPageThumbnailsToView(); |
| 113 |
//加载一张图片请求完成 |
| 114 |
void sigOneImgReady(QString path, QPixmap pixmap); |
| 115 |
//加载设备中图片列表请求完成 |
| 116 |
void sigMountFileListLoadReady(QString path, QStringList fileList); |
| 117 |
//过滤不存在图片后重新加载 |
| 118 |
void sigReloadAfterFilterEnd(); |
| 119 |
|
| 120 |
//发给子线程 |
| 121 |
//先加载指定数量的缩略图 |
| 122 |
void sigLoadThumbnailsByNum(QVector<DBImgInfo> allImageDataVector, int num); |
| 123 |
//发给子线程,加载一张缩略图 |
| 124 |
void sigLoadThumbnailIMG(QString path); |
| 125 |
//发给子线程,旋转图片 |
| 126 |
void sigRotateImageFile(int angel, const QString &path); |
| 127 |
void sigLoadOneThumbnail(QString imagepath, DBImgInfo data); |
| 128 |
void sigLoadOneThumbnailToThumbnailView(QString imagepath, DBImgInfo data); |
| 129 |
//加载设备中图片列表 |
| 130 |
void sigLoadMountFileList(QString path); |
| 131 |
public: |
| 132 |
QVector<DBImgInfo> m_AllImageDataVector; |
| 133 |
int m_FirstPageScreen = 0; |
| 134 |
QStringList m_imgLoaded;//已经加载过的图片,防止多次加载 |
| 135 |
QMultiMap<QString, QString> m_allPathAndAlbumNames; |
| 136 |
bool m_firstPageIsLoaded = false; |
| 137 |
private: |
| 138 |
explicit ImageEngineApi(QObject *parent = nullptr); |
| 139 |
|
| 140 |
QMap<void *, void *>m_AllObject; |
| 141 |
QMap<QString, DBImgInfo>m_AllImageData; |
| 142 |
|
| 143 |
static ImageEngineApi *s_ImageEngine; |
| 144 |
ImageCacheSaveObject *m_imageCacheSaveobj = nullptr; |
| 145 |
bool bcloseFg = false; |
| 146 |
QThreadPool *m_pool = nullptr; |
| 147 |
#ifdef NOGLOBAL |
| 148 |
QThreadPool m_qtpool; |
| 149 |
QThreadPool cacheThreadPool; |
| 150 |
#endif |
| 151 |
DBandImgOperate *m_worker = nullptr; |
| 152 |
QMutex m_dataMutex; |
| 153 |
}; |
| 154 |
|
| 155 |
#endif // IMAGEENGINEAPI_H |