Warning, file /plasma/plasma-workspace/kcms/autostart/autostartmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2020 Méven Car <meven.car@enioka.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractListModel>
0010 #include <QDir>
0011 
0012 #include <KService>
0013 #include <optional>
0014 
0015 struct AutostartEntry;
0016 class QQuickItem;
0017 
0018 class AutostartModel : public QAbstractListModel
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit AutostartModel(QObject *parent = nullptr);
0024 
0025     enum Roles {
0026         Name,
0027         IconName = Qt::DecorationRole,
0028         Enabled = Qt::UserRole + 1,
0029         TargetFileDirPath,
0030         Source,
0031         FileName,
0032         OnlyInPlasma,
0033     };
0034 
0035     enum AutostartEntrySource {
0036         XdgAutoStart = 0,
0037         XdgScripts = 1,
0038         PlasmaShutdown = 2,
0039         PlasmaEnvScripts = 3,
0040     };
0041     Q_ENUM(AutostartEntrySource)
0042 
0043     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0044     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0045     QHash<int, QByteArray> roleNames() const override;
0046 
0047     bool reloadEntry(const QModelIndex &index, const QString &fileName);
0048 
0049     Q_INVOKABLE void removeEntry(int row);
0050     Q_INVOKABLE void editApplication(int row, QQuickItem *context);
0051     Q_INVOKABLE void addScript(const QUrl &url, AutostartEntrySource kind);
0052     Q_INVOKABLE void showApplicationDialog(QQuickItem *context);
0053     Q_INVOKABLE void makeFileExecutable(const QString &fileName);
0054 
0055     void load();
0056 
0057 Q_SIGNALS:
0058     void error(const QString &message);
0059     void nonExecutableScript(const QString &fileName, AutostartModel::AutostartEntrySource kind);
0060 
0061 private:
0062     void addApplication(const KService::Ptr &service);
0063     void loadScriptsFromDir(const QString &subDir, AutostartEntrySource kind);
0064     void insertScriptEntry(int index, const QString &name, const QString &targetFileDirPath, const QString &path, AutostartModel::AutostartEntrySource kind);
0065     QString makeSuggestedName(const QString &oldName);
0066     QString suggestName(const QUrl &baseUrl, const QString &oldName);
0067     static std::optional<AutostartEntry> loadDesktopEntry(const QString &fileName);
0068 
0069     QDir m_xdgConfigPath;
0070     QDir m_xdgAutoStartPath;
0071     QVector<AutostartEntry> m_entries;
0072 };
0073 
0074 struct AutostartEntry {
0075     QString name; // Human readable name of file
0076     QString targetFileDirPath; // Script file Path without filename. In case of symlinks the target file path without filename. In case of application, Just the
0077                                // name of the application
0078     AutostartModel::AutostartEntrySource source;
0079     bool enabled;
0080     QString fileName; // the file backing the entry
0081     bool onlyInPlasma;
0082     QString iconName;
0083 };
0084 Q_DECLARE_TYPEINFO(AutostartEntry, Q_MOVABLE_TYPE);