File: settingsapp.h

package info (click to toggle)
plasma-settings 25.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: cpp: 1,213; xml: 124; makefile: 3; sh: 1
file content (138 lines) | stat: -rw-r--r-- 4,132 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*

    SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org>
    SPDX-FileCopyrightText: 2011-2014 Sebastian Kügler <sebas@kde.org>
    SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
    SPDX-FileCopyrightText: 2025 Devin Lin <devin@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include <QAbstractItemModel>
#include <QCommandLineParser>
#include <QIcon>
#include <QObject>
#include <QPersistentModelIndex>

#include <KDescendantsProxyModel>
#include <KSelectionProxyModel>
#include <qqmlintegration.h>

#include "module.h"
#include "modulesmodel.h"
#include "modulesproxymodel.h"

class SubcategoryModel;

class SettingsApp : public QObject
{
    Q_OBJECT
    QML_ELEMENT
    QML_SINGLETON

    Q_PROPERTY(QString startModule MEMBER m_startModule CONSTANT)
    Q_PROPERTY(bool singleModule MEMBER m_singleModule CONSTANT)

    Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
    Q_PROPERTY(bool showAllModules READ showAllModules WRITE setShowAllModules NOTIFY showAllModulesChanged)

    Q_PROPERTY(ModulesProxyModel *categoryModel READ categoryModel CONSTANT)
    Q_PROPERTY(SubcategoryModel *subCategoryModel READ subCategoryModel CONSTANT)
    Q_PROPERTY(ModulesProxyModel *searchModel READ searchModel CONSTANT)

    Q_PROPERTY(int activeCategoryRow READ activeCategoryRow NOTIFY activeCategoryRowChanged)
    Q_PROPERTY(int activeSearchRow READ activeSearchRow NOTIFY activeSearchRowChanged)
    Q_PROPERTY(int activeSubCategoryRow READ activeSubCategoryRow NOTIFY activeSubCategoryRowChanged)
    Q_PROPERTY(Module *activeModule READ activeModule NOTIFY activeModuleChanged)

public:
    explicit SettingsApp(QObject *parent = nullptr);
    ~SettingsApp() override;

    void init(QCommandLineParser &parser, QString startModule, bool singleModule);

    void loadModuleById(QString id);
    Q_INVOKABLE void loadModule(const QModelIndex &activeModule, const QStringList &args = QStringList());

    QString filterString() const;
    void setFilterString(QString filterString);

    bool showAllModules() const;
    void setShowAllModules(bool showAllModules);

    ModulesProxyModel *categoryModel();
    SubcategoryModel *subCategoryModel();
    ModulesProxyModel *searchModel();

    int activeCategoryRow() const;
    int activeSearchRow() const;
    int activeSubCategoryRow() const;
    Module *activeModule();

Q_SIGNALS:
    void moduleChangeRequested();
    void activateRequested();

    void filterStringChanged();
    void showAllModulesChanged();
    void startModuleChanged();
    void singleModuleChanged();

    void activeCategoryRowChanged();
    void activeSearchRowChanged();
    void activeSubCategoryRowChanged();
    void activeModuleChanged();

    void subCategoryRequested();

private:
    void setupKDBus();
    QCommandLineParser *m_parser;

    QString m_startModule;
    bool m_singleModule;

    Module *m_activeModule{nullptr};

    QString m_filterString;
    bool m_showAllModules{false};

    int m_activeCategoryRow{0};
    int m_activeSearchRow{0};
    int m_activeSubCategoryRow{0};

    ModulesModel *m_model{nullptr};
    ModulesProxyModel *m_categoryModel{nullptr};
    SubcategoryModel *m_subCategoryModel{nullptr};
    ModulesProxyModel *m_searchModel{nullptr};
    KDescendantsProxyModel *m_flatModel{nullptr};
};

class SubcategoryModel : public KSelectionProxyModel
{
    Q_OBJECT
    Q_PROPERTY(QString title READ title NOTIFY titleChanged)
    Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
    Q_PROPERTY(bool categoryOwnedByKCM READ categoryOwnedByKCM NOTIFY categoryOwnedByKCMChanged)

public:
    explicit SubcategoryModel(QAbstractItemModel *parentModel, SettingsApp *parent = nullptr);

    QString title() const;
    QIcon icon() const;
    bool categoryOwnedByKCM() const;

    void setParentIndex(const QModelIndex &activeModule);

Q_SIGNALS:
    void titleChanged();
    void iconChanged();
    void categoryOwnedByKCMChanged();

private:
    QAbstractItemModel *m_parentModel;
    QPersistentModelIndex m_activeModuleIndex;
    SettingsApp *m_settingsApp;
};