-
Notifications
You must be signed in to change notification settings - Fork 11
/
desktopapplications.h
97 lines (76 loc) · 2.07 KB
/
desktopapplications.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef DESKTOPAPPLICATIONS_H
#define DESKTOPAPPLICATIONS_H
#include <QtCore/QMetaType>
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <QtCore/QMutex>
#include <QtCore/QWaitCondition>
#include <QtCore/QMap>
#include <QtCore/QStringList>
#include <QtCore/QDateTime>
#include <QtGui/QImage>
class DesktopApplication
{
public:
DesktopApplication()
: m_isNoDisplay(false)
{
}
bool init(const QString& path);
bool exists() const;
bool needUpdate() const;
void launch() const;
const bool isNoDisplay() const { return m_isNoDisplay; }
const QString& path() const { return m_path; }
const QString& name() const { return m_name; }
const QString& iconName() const { return m_iconName; }
void setIconImage(const QImage& iconImage) { m_iconImage = iconImage; }
const QImage& iconImage() const { return m_iconImage; }
const QStringList& categories() const { return m_categories; }
private:
QString m_path;
QDateTime m_lastUpdated;
bool m_isNoDisplay;
QString m_name;
QString m_exec;
QString m_iconName;
QImage m_iconImage;
QStringList m_categories;
};
Q_DECLARE_METATYPE(DesktopApplication)
class QDir;
class QTimer;
class QFileSystemWatcher;
class DesktopApplications: public QThread
{
Q_OBJECT
public:
DesktopApplications();
~DesktopApplications();
static DesktopApplications* instance() { return m_instance; }
QList<DesktopApplication> applications();
DesktopApplication applicationFromPath(const QString& path);
void launch(const QString& path);
signals:
void applicationUpdated(const DesktopApplication& app);
void applicationRemoved(const QString& path);
protected:
void run();
private slots:
void directoryChanged(const QString& path);
void fileChanged(const QString& path);
void refresh();
private:
void traverse(const QDir& dir);
static DesktopApplications* m_instance;
QTimer* m_updateTimer;
QFileSystemWatcher* m_watcher;
QMutex m_applicationsMutex;
QMap<QString, DesktopApplication> m_applications;
QMutex m_tasksMutex;
QWaitCondition m_tasksWaitCondition;
bool m_abortWorker;
QStringList m_fileTasks;
QStringList m_imageTasks;
};
#endif