summaryrefslogtreecommitdiff
path: root/src/lib/xdgentry.h
blob: 147072c9baa786913634f095854ed94502b4491a (plain)
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
#ifndef XDGENTRY_H
#define XDGENTRY_H

#include <QObject>
#include <QFileSystemWatcher>
#include <QProcess>
#include <QSettings>

#define XDG_EXEC            "Desktop Entry/Exec"
#define XDG_ICON            "Desktop Entry/Icon"
#define XDG_NAME            "Desktop Entry/Name"
#define XDG_KEYWORDS        "Desktop Entry/Keywords"
#define XDG_NODISPLAY       "Desktop Entry/NoDisplay"
#define XDG_CATEGORIES      "Desktop Entry/Categories"

#define XDG_ACTION_START    "Desktop Action Start/Exec"
#define XDG_ACTION_STOP     "Desktop Action Stop/Exec"

namespace KaZoe {
    class Entry: public QObject
    {
        Q_OBJECT

        Q_PROPERTY(QString appId READ appId WRITE setAppId NOTIFY appIdChanged)
        Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
        Q_PROPERTY(QString desktopFile READ path WRITE setDesktopFile NOTIFY desktopFileChanged)

        QString m_path;
        QSettings *m_file {nullptr};
        QFileSystemWatcher m_watcher;
        QProcess m_process;
        mutable QMap<QString, QString> m_used;

    private slots:
        void _desktopFileChanged(const QString &path);
        void _processStateChanged(QProcess::ProcessState newState);

    public:
        explicit Entry(QString desktopfile, QObject *parent = nullptr);
        explicit Entry(QObject *parent = nullptr);
        explicit Entry(const KaZoe::Entry& origin);

        QString path() const;
        QString appId() const;
        QString icon() const;
        int pid() const;
        void setDesktopFile(QString desktopFile);
        void setAppId(QString appId);

    public slots:
        void start(QStringList args);
        void stop(QStringList args);
        QString data(const QString &key) const;

    signals:
        void dataChanged(const QString key, const QString value);
        void raiseProcess(int pid);
        void removed(const QString path);
        void appIdChanged(QString appId);
        void iconChanged(QString icon);
        void desktopFileChanged(QString desktopFile);
    };
}

Q_DECLARE_METATYPE(const KaZoe::Entry*)

#endif // XDGENTRY_H