Changeset View
Changeset View
Standalone View
Standalone View
kcms/colors/colors.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QScopedPointer> | ||||
24 | #include <QPointer> | ||||
25 | | ||||
26 | #include <KSharedConfig> | ||||
27 | | ||||
28 | #include <KNewStuff3/KNS3/DownloadDialog> | ||||
29 | | ||||
30 | #include <KQuickAddons/ConfigModule> | ||||
31 | | ||||
32 | class QStandardItemModel; | ||||
33 | class QProcess; | ||||
34 | class QTemporaryFile; | ||||
35 | | ||||
36 | namespace KIO | ||||
37 | { | ||||
38 | class FileCopyJob; | ||||
39 | } | ||||
40 | | ||||
41 | class KCMColors : public KQuickAddons::ConfigModule | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | | ||||
45 | Q_PROPERTY(QStandardItemModel *colorsModel READ colorsModel CONSTANT) | ||||
46 | Q_PROPERTY(QString selectedScheme READ selectedScheme WRITE setSelectedScheme NOTIFY selectedSchemeChanged) | ||||
47 | Q_PROPERTY(int selectedSchemeIndex READ selectedSchemeIndex NOTIFY selectedSchemeIndexChanged) | ||||
48 | Q_PROPERTY(bool downloadingFile READ downloadingFile NOTIFY downloadingFileChanged) | ||||
49 | | ||||
50 | public: | ||||
51 | KCMColors(QObject *parent, const QVariantList &args); | ||||
52 | ~KCMColors() override; | ||||
53 | | ||||
54 | enum Roles { | ||||
55 | SchemeNameRole = Qt::UserRole + 1, | ||||
56 | PaletteRole, | ||||
57 | RemovableRole, | ||||
58 | PendingDeletionRole | ||||
59 | }; | ||||
60 | | ||||
61 | QStandardItemModel *colorsModel() const; | ||||
62 | | ||||
63 | QString selectedScheme() const; | ||||
64 | void setSelectedScheme(const QString &scheme); | ||||
65 | | ||||
66 | int selectedSchemeIndex() const; | ||||
67 | | ||||
68 | bool downloadingFile() const; | ||||
69 | | ||||
70 | Q_INVOKABLE void getNewStuff(QQuickItem *ctx); | ||||
71 | Q_INVOKABLE void installSchemeFromFile(const QUrl &url); | ||||
72 | | ||||
73 | Q_INVOKABLE void setPendingDeletion(int index, bool pending); | ||||
74 | | ||||
75 | Q_INVOKABLE void editScheme(int index, QQuickItem *ctx); | ||||
76 | | ||||
77 | public Q_SLOTS: | ||||
78 | void load() override; | ||||
79 | void save() override; | ||||
80 | void defaults() override; | ||||
81 | | ||||
82 | Q_SIGNALS: | ||||
83 | void selectedSchemeChanged(); | ||||
84 | void selectedSchemeIndexChanged(); | ||||
85 | void downloadingFileChanged(); | ||||
86 | | ||||
87 | void showSuccessMessage(const QString &message); | ||||
88 | void showErrorMessage(const QString &message); | ||||
89 | | ||||
90 | void showSchemeNotInstalledWarning(const QString &schemeName); | ||||
91 | | ||||
92 | private: | ||||
93 | void loadModel(); | ||||
94 | | ||||
95 | void saveColors(); | ||||
96 | void processPendingDeletions(); | ||||
97 | | ||||
98 | int indexOfScheme(const QString &schemeName) const; | ||||
99 | | ||||
100 | void installSchemeFile(const QString &path); | ||||
101 | | ||||
102 | QStandardItemModel *m_model; | ||||
103 | | ||||
104 | QString m_selectedScheme; | ||||
105 | bool m_selectedSchemeDirty = false; | ||||
106 | | ||||
107 | bool m_applyToAlien = true; | ||||
108 | | ||||
109 | QPointer<KNS3::DownloadDialog> m_newStuffDialog; | ||||
110 | | ||||
111 | QProcess *m_editDialogProcess = nullptr; | ||||
112 | | ||||
113 | KSharedConfigPtr m_config; | ||||
114 | | ||||
115 | QScopedPointer<QTemporaryFile> m_tempInstallFile; | ||||
116 | QPointer<KIO::FileCopyJob> m_tempCopyJob; | ||||
117 | | ||||
118 | }; |