Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwinrules/kcmrules.cpp
Show All 23 Lines | |||||
24 | #include <QDBusConnection> | 24 | #include <QDBusConnection> | ||
25 | #include <QDBusMessage> | 25 | #include <QDBusMessage> | ||
26 | 26 | | |||
27 | #include <KAboutData> | 27 | #include <KAboutData> | ||
28 | #include <KConfig> | 28 | #include <KConfig> | ||
29 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
30 | #include <KPluginFactory> | 30 | #include <KPluginFactory> | ||
31 | 31 | | |||
32 | #include "ruleitem.h" | ||||
32 | 33 | | |||
33 | namespace KWin | 34 | namespace KWin | ||
34 | { | 35 | { | ||
35 | 36 | | |||
36 | KCMKWinRules::KCMKWinRules(QObject *parent, const QVariantList &arguments) | 37 | KCMKWinRules::KCMKWinRules(QObject *parent, const QVariantList &arguments) | ||
37 | : KQuickAddons::ConfigModule(parent, arguments) | 38 | : KQuickAddons::ConfigModule(parent, arguments) | ||
38 | , m_ruleBookModel(new RuleBookModel(this)) | 39 | , m_ruleBookModel(new RuleBookModel(this)) | ||
39 | , m_rulesModel(new RulesModel(this)) | | |||
40 | { | 40 | { | ||
41 | auto about = new KAboutData(QStringLiteral("kcm_kwinrules"), | 41 | auto about = new KAboutData(QStringLiteral("kcm_kwinrules"), | ||
42 | i18n("Window Rules"), | 42 | i18n("Window Rules"), | ||
43 | QStringLiteral("1.0"), | 43 | QStringLiteral("1.0"), | ||
44 | QString(), | 44 | QString(), | ||
45 | KAboutLicense::GPL); | 45 | KAboutLicense::GPL); | ||
46 | about->addAuthor(i18n("Ismael Asensio"), | 46 | about->addAuthor(i18n("Ismael Asensio"), | ||
47 | i18n("Author"), | 47 | i18n("Author"), | ||
48 | QStringLiteral("isma.af@gmail.com")); | 48 | QStringLiteral("isma.af@gmail.com")); | ||
49 | setAboutData(about); | 49 | setAboutData(about); | ||
50 | 50 | | |||
51 | setQuickHelp(i18n("<p><h1>Window-specific Settings</h1> Here you can customize window settings specifically only" | 51 | setQuickHelp(i18n("<p><h1>Window-specific Settings</h1> Here you can customize window settings specifically only" | ||
52 | " for some windows.</p>" | 52 | " for some windows.</p>" | ||
53 | " <p>Please note that this configuration will not take effect if you do not use" | 53 | " <p>Please note that this configuration will not take effect if you do not use" | ||
54 | " KWin as your window manager. If you do use a different window manager, please refer to its documentation" | 54 | " KWin as your window manager. If you do use a different window manager, please refer to its documentation" | ||
55 | " for how to customize window behavior.</p>")); | 55 | " for how to customize window behavior.</p>")); | ||
56 | 56 | | |||
57 | qmlRegisterUncreatableType<RuleItem>("org.kde.kcms.kwinrules", 1, 0, "RuleItem", | ||||
58 | QStringLiteral("Do not create objects of type RuleItem")); | ||||
59 | qmlRegisterUncreatableType<RulesModel>("org.kde.kcms.kwinrules", 1, 0, "RulesModel", | ||||
60 | QStringLiteral("Do not create objects of type RulesModel")); | ||||
61 | | ||||
62 | connect(m_ruleBookModel, &RulesModel::dataChanged, this, &KCMKWinRules::updateNeedsSave); | ||||
63 | } | ||||
64 | | ||||
65 | RulesModel *KCMKWinRules::rulesModel() | ||||
66 | { | ||||
67 | if (!m_rulesModel) { | ||||
68 | m_rulesModel = new RulesModel(this); | ||||
57 | connect(m_rulesModel, &RulesModel::descriptionChanged, this, [this]{ | 69 | connect(m_rulesModel, &RulesModel::descriptionChanged, this, [this]{ | ||
58 | if (m_editIndex.isValid()) { | 70 | if (m_editIndex.isValid()) { | ||
59 | m_ruleBookModel->setDescriptionAt(m_editIndex.row(), m_rulesModel->description()); | 71 | m_ruleBookModel->setDescriptionAt(m_editIndex.row(), m_rulesModel->description()); | ||
60 | } | 72 | } | ||
61 | } ); | 73 | } ); | ||
62 | connect(m_rulesModel, &RulesModel::dataChanged, this, &KCMKWinRules::updateNeedsSave); | 74 | connect(m_rulesModel, &RulesModel::dataChanged, this, &KCMKWinRules::updateNeedsSave); | ||
63 | connect(m_ruleBookModel, &RulesModel::dataChanged, this, &KCMKWinRules::updateNeedsSave); | 75 | } | ||
76 | | ||||
77 | return m_rulesModel; | ||||
64 | } | 78 | } | ||
65 | 79 | | |||
66 | void KCMKWinRules::load() | 80 | void KCMKWinRules::load() | ||
67 | { | 81 | { | ||
68 | m_ruleBookModel->load(); | 82 | m_ruleBookModel->load(); | ||
69 | 83 | | |||
70 | m_editIndex = QModelIndex(); | 84 | m_editIndex = QModelIndex(); | ||
71 | emit editIndexChanged(); | 85 | emit editIndexChanged(); | ||
Show All 16 Lines | |||||
88 | { | 102 | { | ||
89 | setNeedsSave(true); | 103 | setNeedsSave(true); | ||
90 | emit needsSaveChanged(); | 104 | emit needsSaveChanged(); | ||
91 | } | 105 | } | ||
92 | 106 | | |||
93 | void KCMKWinRules::saveCurrentRule() | 107 | void KCMKWinRules::saveCurrentRule() | ||
94 | { | 108 | { | ||
95 | if (m_editIndex.isValid() && needsSave()) { | 109 | if (m_editIndex.isValid() && needsSave()) { | ||
96 | m_ruleBookModel->setRuleAt(m_editIndex.row(), m_rulesModel->exportToRules()); | 110 | m_ruleBookModel->setRuleAt(m_editIndex.row(), rulesModel()->exportToRules()); | ||
97 | } | 111 | } | ||
98 | } | 112 | } | ||
99 | 113 | | |||
100 | int KCMKWinRules::editIndex() const | 114 | int KCMKWinRules::editIndex() const | ||
101 | { | 115 | { | ||
102 | if (!m_editIndex.isValid()) { | 116 | if (!m_editIndex.isValid()) { | ||
103 | return -1; | 117 | return -1; | ||
104 | } | 118 | } | ||
105 | return m_editIndex.row(); | 119 | return m_editIndex.row(); | ||
106 | } | 120 | } | ||
107 | 121 | | |||
108 | 122 | | |||
109 | void KCMKWinRules::setRuleDescription(int index, const QString &description) | 123 | void KCMKWinRules::setRuleDescription(int index, const QString &description) | ||
110 | { | 124 | { | ||
111 | if (index < 0 || index >= m_ruleBookModel->rowCount()) { | 125 | if (index < 0 || index >= m_ruleBookModel->rowCount()) { | ||
112 | return; | 126 | return; | ||
113 | } | 127 | } | ||
114 | 128 | | |||
115 | if (m_editIndex.row() == index) { | 129 | if (m_editIndex.row() == index) { | ||
116 | m_rulesModel->setDescription(description); | 130 | rulesModel()->setDescription(description); | ||
117 | return; | 131 | return; | ||
118 | } | 132 | } | ||
119 | m_ruleBookModel->setDescriptionAt(index, description); | 133 | m_ruleBookModel->setDescriptionAt(index, description); | ||
120 | 134 | | |||
121 | updateNeedsSave(); | 135 | updateNeedsSave(); | ||
122 | } | 136 | } | ||
123 | 137 | | |||
124 | 138 | | |||
125 | void KCMKWinRules::editRule(int index) | 139 | void KCMKWinRules::editRule(int index) | ||
126 | { | 140 | { | ||
127 | if (index < 0 || index >= m_ruleBookModel->rowCount()) { | 141 | if (index < 0 || index >= m_ruleBookModel->rowCount()) { | ||
128 | return; | 142 | return; | ||
129 | } | 143 | } | ||
130 | saveCurrentRule(); | 144 | saveCurrentRule(); | ||
131 | 145 | | |||
132 | m_editIndex = m_ruleBookModel->index(index); | 146 | m_editIndex = m_ruleBookModel->index(index); | ||
133 | emit editIndexChanged(); | 147 | emit editIndexChanged(); | ||
134 | 148 | | |||
135 | m_rulesModel->importFromRules(m_ruleBookModel->ruleAt(m_editIndex.row())); | 149 | rulesModel()->importFromRules(m_ruleBookModel->ruleAt(m_editIndex.row())); | ||
136 | 150 | | |||
137 | // Set the active page to rules editor (0:RulesList, 1:RulesEditor) | 151 | // Set the active page to rules editor (0:RulesList, 1:RulesEditor) | ||
138 | setCurrentIndex(1); | 152 | setCurrentIndex(1); | ||
139 | } | 153 | } | ||
140 | 154 | | |||
141 | void KCMKWinRules::createRule() | 155 | void KCMKWinRules::createRule() | ||
142 | { | 156 | { | ||
143 | const int newIndex = m_ruleBookModel->rowCount(); | 157 | const int newIndex = m_ruleBookModel->rowCount(); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 248 | if (newIndex < 0) { | |||
235 | newIndex = m_ruleBookModel->rowCount(); | 249 | newIndex = m_ruleBookModel->rowCount(); | ||
236 | m_ruleBookModel->insertRow(newIndex); | 250 | m_ruleBookModel->insertRow(newIndex); | ||
237 | } | 251 | } | ||
238 | 252 | | |||
239 | m_ruleBookModel->setRuleAt(newIndex, new Rules(&settings)); | 253 | m_ruleBookModel->setRuleAt(newIndex, new Rules(&settings)); | ||
240 | 254 | | |||
241 | // Reset rule editor if the current rule changed when importing | 255 | // Reset rule editor if the current rule changed when importing | ||
242 | if (m_editIndex.row() == newIndex) { | 256 | if (m_editIndex.row() == newIndex) { | ||
243 | m_rulesModel->importFromRules(m_ruleBookModel->ruleAt(m_editIndex.row())); | 257 | rulesModel()->importFromRules(m_ruleBookModel->ruleAt(m_editIndex.row())); | ||
244 | } | 258 | } | ||
245 | } | 259 | } | ||
246 | 260 | | |||
247 | updateNeedsSave(); | 261 | updateNeedsSave(); | ||
248 | } | 262 | } | ||
249 | 263 | | |||
250 | K_PLUGIN_CLASS_WITH_JSON(KCMKWinRules, "kcm_kwinrules.json"); | 264 | K_PLUGIN_CLASS_WITH_JSON(KCMKWinRules, "kcm_kwinrules.json"); | ||
251 | 265 | | |||
252 | } // namespace | 266 | } // namespace | ||
253 | 267 | | |||
254 | #include "kcmrules.moc" | 268 | #include "kcmrules.moc" |