1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
//===========================================
// Lumina-desktop source code
// Copyright (c) 2017, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
// This is a simple class for loading/serving icon files
// from the icon theme or local filesystem
//===========================================
#include <QHash>
#include <QIcon>
#include <QPixmap>
#include <QFileSystemWatcher>
#include <QString>
#include <QFile>
#include <QDateTime>
#include <QAbstractButton>
#include <QLabel>
#include <QAction>
//Data structure for saving the icon/information internally
struct icon_data{
QString fullpath;
QDateTime lastread;
QList<QLabel*> pendingLabels;
QList<QAbstractButton*> pendingButtons;
QList<QAction*> pendingActions;
QIcon icon;
QIcon thumbnail;
};
class LIconCache : public QObject{
Q_OBJECT
public:
LIconCache(QObject *parent = 0);
~LIconCache();
//Icon Checks
bool exists(QString icon);
bool isLoaded(QString icon);
QString findFile(QString icon); //find the full path of a given file/name (searching the current Icon theme)
//Special loading routines for QLabel and QAbstractButton (pushbutton, toolbutton, etc)
void loadIcon(QAbstractButton *button, QString icon, bool noThumb = false);
void loadIcon(QLabel *label, QString icon, bool noThumb = false);
void loadIcon(QAction *action, QString icon, bool noThumb = false);
QIcon loadIcon(QString icon, bool noThumb = false); //generic loading routine - does not background the loading of icons when not in the cache
void clearIconTheme(); //use when the icon theme changes to refresh all requested icons
void clearAll(); //Clear all cached icons
private:
QHash<QString, icon_data> HASH;
QFileSystemWatcher *WATCHER;
icon_data createData(QString icon);
QStringList getChildIconDirs(QString path); //recursive function to find directories with icons in them
QStringList getIconThemeDepChain(QString theme, QStringList paths);
void ReadFile(LIconCache *obj, QString id, QString path);
private slots:
void IconLoaded(QString id, QDateTime sync, QByteArray *data);
signals:
void InternalIconLoaded(QString, QDateTime, QByteArray*); //INTERNAL SIGNAL - DO NOT USE in other classes/objects
void IconAvailable(QString); //way for classes to listen/reload icons as they change
};
|