Debian Codegraph @

src/album/imageengine/imagedataservice.h

raw
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 IMAGEDATASERVICE_H
22 #define IMAGEDATASERVICE_H
23
24 #include <QObject>
25 #include <QMap>
26 #include <QUrl>
27 #include <QMutex>
28 #include <QThread>
29 #include <QQueue>
30
31 class readThumbnailThread;
32 class ImageDataService: public QObject
33 {
34 Q_OBJECT
35 public:
36 static ImageDataService *instance(QObject *parent = nullptr);
37 explicit ImageDataService(QObject *parent = nullptr);
38 ~ImageDataService();
39
40 bool add(const QStringList &paths, bool reLoadThumbnail = false);
41 bool add(const QString &path);
42 QString pop();
43 bool isRequestQueueEmpty();
44 //获取全部图片数量
45 int getCount();
46
47 //读取缩略图到缓存map isFinishFilter:是否过滤过路径 reLoadThumbnail:重新加载缩略图
48 bool readThumbnailByPaths(QStringList files, bool isFinishFilter = false, bool reLoadThumbnail = false);
49 // bool readThumbnailByPath(QString file);
50
51 void addImage(const QString &path, const QImage &image);
52 QImage getThumnailImageByPath(const QString &path);
53 bool imageIsLoaded(const QString &path);
54
55 void addMovieDurationStr(const QString &path, const QString &durationStr);
56 QString getMovieDurationStrByPath(const QString &path);
57
58 //
59 void setVisualIndex(int row);
60 int getVisualIndex();
61 private slots:
62 signals:
63 void sigeUpdateListview();
64 public:
65 private:
66 static ImageDataService *s_ImageDataService;
67 QMutex m_queuqMutex;
68 QList<QString> m_requestQueue;
69
70 //图片数据锁
71 QMutex m_imgDataMutex;
72 //QString:原图路径 QImage:缩略图
73 QMap<QString, QImage> m_AllImageMap;
74 //QString:原图路径 QString:原图文件hash
75 QMap<QString, QString> m_AllImageDataHashMap;
76 QMap<QString, QString> m_movieDurationStrMap;
77 QQueue<QString> m_imageKeys;
78 int m_visualIndex = 0;//用户查找视图中的model index
79 };
80
81
82 //缩略图读取线程
83 class readThumbnailThread : public QThread
84 {
85 Q_OBJECT
86 public:
87 readThumbnailThread(QObject *parent = nullptr);
88 ~readThumbnailThread() override;
89 void readThumbnail(QString m_path);
90 void setQuit(bool quit);
91 protected:
92 void run() override;
93 private:
94 bool m_quit = false;
95 };
96 #endif // IMAGEDATASERVICE_H