Changeset View
Changeset View
Standalone View
Standalone View
runners/kill/killrunner_config.cpp
1 | /* Copyright 2009 <Jan Gerrit Marker> <jangerrit@weiler-marker.com> | 1 | /* Copyright 2009 <Jan Gerrit Marker> <jangerrit@weiler-marker.com> | ||
---|---|---|---|---|---|
2 | * Copyright 2020 <Alexander Lohnau> <alexander.lohnau@gmx.de> | ||||
2 | * | 3 | * | ||
3 | * This library is free software; you can redistribute it and/or | 4 | * This library is free software; you can redistribute it and/or | ||
4 | * modify it under the terms of the GNU Lesser General Public | 5 | * modify it under the terms of the GNU Lesser General Public | ||
5 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either | ||
6 | * version 2.1 of the License, or (at your option) version 3, or any | 7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
7 | * later version accepted by the membership of KDE e.V. (or its | 8 | * later version accepted by the membership of KDE e.V. (or its | ||
8 | * successor approved by the membership of KDE e.V.), which shall | 9 | * successor approved by the membership of KDE e.V.), which shall | ||
9 | * act as a proxy defined in Section 6 of version 3 of the license. | 10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
10 | * | 11 | * | ||
11 | * This library is distributed in the hope that it will be useful, | 12 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | 15 | * Lesser General Public License for more details. | ||
15 | * | 16 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | 17 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | //Project-Includes | 21 | //Project-Includes | ||
21 | #include "killrunner_config.h" | 22 | #include "killrunner_config.h" | ||
22 | #include <kconfigwidgets_version.h> | | |||
23 | //KDE-Includes | 23 | //KDE-Includes | ||
24 | #include <KSharedConfig> | 24 | #include <KSharedConfig> | ||
25 | #include <KConfigGroup> | ||||
25 | #include <KPluginFactory> | 26 | #include <KPluginFactory> | ||
26 | #include <krunner/abstractrunner.h> | | |||
27 | 27 | | |||
28 | K_PLUGIN_FACTORY(KillRunnerConfigFactory, registerPlugin<KillRunnerConfig>(QStringLiteral("kcm_krunner_kill"));) | 28 | K_PLUGIN_FACTORY(KillRunnerConfigFactory, registerPlugin<KillRunnerConfig>(QStringLiteral("kcm_krunner_kill"));) | ||
29 | 29 | | |||
30 | KillRunnerConfigForm::KillRunnerConfigForm(QWidget* parent) : QWidget(parent) | 30 | KillRunnerConfigForm::KillRunnerConfigForm(QWidget* parent) : QWidget(parent) | ||
31 | { | 31 | { | ||
32 | setupUi(this); | 32 | setupUi(this); | ||
33 | } | 33 | } | ||
34 | 34 | | |||
35 | KillRunnerConfig::KillRunnerConfig(QWidget* parent, const QVariantList& args) : | 35 | KillRunnerConfig::KillRunnerConfig(QWidget* parent, const QVariantList& args) : KCModule(parent, args) | ||
36 | KCModule(parent, args) | | |||
37 | { | 36 | { | ||
38 | m_ui = new KillRunnerConfigForm(this); | 37 | m_ui = new KillRunnerConfigForm(this); | ||
39 | 38 | | |||
40 | QGridLayout* layout = new QGridLayout(this); | 39 | QGridLayout* layout = new QGridLayout(this); | ||
41 | layout->addWidget(m_ui, 0, 0); | 40 | layout->addWidget(m_ui, 0, 0); | ||
42 | 41 | | |||
43 | m_ui->sorting->addItem(i18n("CPU usage"), CPU); | 42 | m_ui->sorting->addItem(i18n("CPU usage"), CPU); | ||
44 | m_ui->sorting->addItem(i18n("inverted CPU usage"), CPUI); | 43 | m_ui->sorting->addItem(i18n("inverted CPU usage"), CPUI); | ||
45 | m_ui->sorting->addItem(i18n("nothing"), NONE); | 44 | m_ui->sorting->addItem(i18n("nothing"), NONE); | ||
46 | #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 64, 0) | 45 | | ||
47 | connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, QOverload<>::of(&KillRunnerConfig::changed)); | | |||
48 | connect(m_ui->triggerWord, &KLineEdit::textChanged, this, QOverload<>::of(&KillRunnerConfig::changed)); | | |||
49 | connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, QOverload<>::of(&KillRunnerConfig::changed)); | | |||
50 | #else | | |||
51 | connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, &KillRunnerConfig::markAsChanged); | 46 | connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, &KillRunnerConfig::markAsChanged); | ||
52 | connect(m_ui->triggerWord, &KLineEdit::textChanged, this, &KillRunnerConfig::markAsChanged); | 47 | connect(m_ui->triggerWord, &KLineEdit::textChanged, this, &KillRunnerConfig::markAsChanged); | ||
53 | connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KillRunnerConfig::markAsChanged); | 48 | connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KillRunnerConfig::markAsChanged); | ||
54 | #endif | | |||
55 | 49 | | |||
56 | load(); | 50 | load(); | ||
57 | } | 51 | } | ||
58 | 52 | | |||
59 | void KillRunnerConfig::load() | 53 | void KillRunnerConfig::load() | ||
60 | { | 54 | { | ||
61 | KCModule::load(); | 55 | KCModule::load(); | ||
62 | 56 | | |||
63 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | 57 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | ||
64 | KConfigGroup grp = cfg->group("Runners"); | 58 | const KConfigGroup grp = cfg->group("Runners").group("Kill Runner"); | ||
65 | grp = KConfigGroup(&grp, "Kill Runner"); | | |||
66 | 59 | | |||
67 | m_ui->useTriggerWord->setChecked(grp.readEntry(CONFIG_USE_TRIGGERWORD,true)); | 60 | m_ui->useTriggerWord->setChecked(grp.readEntry(CONFIG_USE_TRIGGERWORD,true)); | ||
68 | m_ui->triggerWord->setText(grp.readEntry(CONFIG_TRIGGERWORD,i18n("kill"))); | 61 | m_ui->triggerWord->setText(grp.readEntry(CONFIG_TRIGGERWORD, i18n("kill"))); | ||
69 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData(grp.readEntry<int>(CONFIG_SORTING, static_cast<int>(NONE)))); | 62 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData(grp.readEntry<int>(CONFIG_SORTING, NONE))); | ||
70 | 63 | | |||
71 | emit changed(false); | 64 | emit changed(false); | ||
72 | } | 65 | } | ||
73 | 66 | | |||
74 | void KillRunnerConfig::save() | 67 | void KillRunnerConfig::save() | ||
75 | { | 68 | { | ||
76 | KCModule::save(); | 69 | KCModule::save(); | ||
77 | 70 | | |||
78 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | 71 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | ||
79 | KConfigGroup grp = cfg->group("Runners"); | 72 | KConfigGroup grp = cfg->group("Runners").group("Kill Runner"); | ||
80 | grp = KConfigGroup(&grp, "Kill Runner"); | | |||
81 | 73 | | |||
82 | grp.writeEntry(CONFIG_USE_TRIGGERWORD,m_ui->useTriggerWord->isChecked()); | 74 | grp.writeEntry(CONFIG_USE_TRIGGERWORD, m_ui->useTriggerWord->isChecked()); | ||
83 | grp.writeEntry(CONFIG_TRIGGERWORD,m_ui->triggerWord->text()); | 75 | grp.writeEntry(CONFIG_TRIGGERWORD, m_ui->triggerWord->text()); | ||
84 | grp.writeEntry(CONFIG_SORTING,m_ui->sorting->itemData(m_ui->sorting->currentIndex())); | 76 | grp.writeEntry(CONFIG_SORTING, m_ui->sorting->itemData(m_ui->sorting->currentIndex())); | ||
85 | 77 | | |||
86 | emit changed(false); | 78 | emit changed(false); | ||
87 | } | 79 | } | ||
88 | 80 | | |||
89 | void KillRunnerConfig::defaults() | 81 | void KillRunnerConfig::defaults() | ||
90 | { | 82 | { | ||
91 | KCModule::defaults(); | 83 | KCModule::defaults(); | ||
92 | 84 | | |||
93 | m_ui->useTriggerWord->setChecked(true); | 85 | m_ui->useTriggerWord->setChecked(true); | ||
94 | m_ui->triggerWord->setText(i18n("kill")); | 86 | m_ui->triggerWord->setText(i18n("kill")); | ||
95 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData((int) NONE)); | 87 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData((int) NONE)); | ||
96 | 88 | | |||
97 | emit changed(true); | 89 | emit markAsChanged(); | ||
98 | } | 90 | } | ||
99 | 91 | | |||
100 | #include "killrunner_config.moc" | 92 | #include "killrunner_config.moc" |