autostartmodel.h 3.23 KB
Newer Older
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
/***************************************************************************
 *   Copyright (C) 2020 by Méven Car <meven.car@enioka.com>                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
 ***************************************************************************/
#ifndef AUTOSTARTMODEL_H
#define AUTOSTARTMODEL_H

#include <QAbstractListModel>

#include <KService>

Nicolas Fella's avatar
Nicolas Fella committed
26
27
struct AutostartEntry;
class QQuickItem;
28
29
30
31
32
33

class AutostartModel : public QAbstractListModel
{
    Q_OBJECT

public:
Nicolas Fella's avatar
Nicolas Fella committed
34
    explicit AutostartModel(QObject *parent = nullptr);
35
36

    enum Roles {
Nicolas Fella's avatar
Nicolas Fella committed
37
38
        Name = Qt::DisplayRole,
        IconName = Qt::DecorationRole,
39
40
41
42
43
44
45
        Command = Qt::UserRole + 1,
        Enabled,
        Source,
        FileName,
        OnlyInPlasma
    };

Nicolas Fella's avatar
Nicolas Fella committed
46
47
48
49
50
51
52
    enum AutostartEntrySource {
        XdgAutoStart = 0,
        XdgScripts = 1,
        PlasmaShutdown = 2,
        PlasmaStart = 3,
    };
    Q_ENUM(AutostartEntrySource)
53
54
55
56
57
58

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    bool reloadEntry(const QModelIndex &index, const QString &fileName);
Nicolas Fella's avatar
Nicolas Fella committed
59
60
61
62
63

    Q_INVOKABLE void removeEntry(int row);
    Q_INVOKABLE void editApplication(int row, QQuickItem *context);
    Q_INVOKABLE void addScript(const QUrl &url, AutostartEntrySource kind);
    Q_INVOKABLE void showApplicationDialog(QQuickItem *context);
64
65
66

    void load();

Nicolas Fella's avatar
Nicolas Fella committed
67
68
69
Q_SIGNALS:
    void error(const QString &message);

70
private:
Nicolas Fella's avatar
Nicolas Fella committed
71
72
73
74
    void addApplication(const KService::Ptr &service);
    void loadScriptsFromDir(const QString &subDir, AutostartEntrySource kind);
    QString XdgAutoStartPath() const;

75
76
77
    QVector<AutostartEntry> m_entries;
};

Nicolas Fella's avatar
Nicolas Fella committed
78
struct AutostartEntry {
79
    QString name;    // Human readable name or script file path. In case of symlinks the target file path
Nicolas Fella's avatar
Nicolas Fella committed
80
81
82
83
84
85
86
87
88
    QString command; // exec or original .sh file
    AutostartModel::AutostartEntrySource source;
    bool enabled;
    QString fileName; // the file backing the entry
    bool onlyInPlasma;
    QString iconName;
};
Q_DECLARE_TYPEINFO(AutostartEntry, Q_MOVABLE_TYPE);

89
#endif // AUTOSTARTMODEL_H