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 | #include "config_keys.h" | 27 | #include "config_keys.h" | ||
28 | 28 | | |||
29 | K_PLUGIN_FACTORY(KillRunnerConfigFactory, registerPlugin<KillRunnerConfig>(QStringLiteral("kcm_krunner_kill"));) | 29 | K_PLUGIN_FACTORY(KillRunnerConfigFactory, registerPlugin<KillRunnerConfig>(QStringLiteral("kcm_krunner_kill"));) | ||
30 | 30 | | |||
31 | KillRunnerConfigForm::KillRunnerConfigForm(QWidget* parent) : QWidget(parent) | 31 | KillRunnerConfigForm::KillRunnerConfigForm(QWidget *parent) : QWidget(parent) | ||
32 | { | 32 | { | ||
33 | setupUi(this); | 33 | setupUi(this); | ||
34 | } | 34 | } | ||
35 | 35 | | |||
36 | KillRunnerConfig::KillRunnerConfig(QWidget* parent, const QVariantList& args) : | 36 | KillRunnerConfig::KillRunnerConfig(QWidget *parent, const QVariantList &args) | ||
37 | KCModule(parent, args) | 37 | : KCModule(parent, args) | ||
38 | { | 38 | { | ||
39 | m_ui = new KillRunnerConfigForm(this); | 39 | m_ui = new KillRunnerConfigForm(this); | ||
40 | 40 | | |||
41 | QGridLayout* layout = new QGridLayout(this); | 41 | QGridLayout *layout = new QGridLayout(this); | ||
42 | layout->addWidget(m_ui, 0, 0); | 42 | layout->addWidget(m_ui, 0, 0); | ||
43 | 43 | | |||
44 | m_ui->sorting->addItem(i18n("CPU usage"), CPU); | 44 | m_ui->sorting->addItem(i18n("CPU usage"), CPU); | ||
45 | m_ui->sorting->addItem(i18n("inverted CPU usage"), CPUI); | 45 | m_ui->sorting->addItem(i18n("inverted CPU usage"), CPUI); | ||
46 | m_ui->sorting->addItem(i18n("nothing"), NONE); | 46 | m_ui->sorting->addItem(i18n("nothing"), NONE); | ||
47 | #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 64, 0) | 47 | | ||
48 | connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, QOverload<>::of(&KillRunnerConfig::changed)); | | |||
49 | connect(m_ui->triggerWord, &KLineEdit::textChanged, this, QOverload<>::of(&KillRunnerConfig::changed)); | | |||
50 | connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, QOverload<>::of(&KillRunnerConfig::changed)); | | |||
51 | #else | | |||
52 | connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, &KillRunnerConfig::markAsChanged); | 48 | connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, &KillRunnerConfig::markAsChanged); | ||
53 | connect(m_ui->triggerWord, &KLineEdit::textChanged, this, &KillRunnerConfig::markAsChanged); | 49 | connect(m_ui->triggerWord, &KLineEdit::textChanged, this, &KillRunnerConfig::markAsChanged); | ||
54 | connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KillRunnerConfig::markAsChanged); | 50 | connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KillRunnerConfig::markAsChanged); | ||
55 | #endif | | |||
56 | 51 | | |||
57 | load(); | 52 | load(); | ||
58 | } | 53 | } | ||
59 | 54 | | |||
60 | void KillRunnerConfig::load() | 55 | void KillRunnerConfig::load() | ||
61 | { | 56 | { | ||
62 | KCModule::load(); | 57 | KCModule::load(); | ||
63 | 58 | | |||
64 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | 59 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | ||
65 | KConfigGroup grp = cfg->group("Runners"); | 60 | const KConfigGroup grp = cfg->group("Runners").group("Kill Runner"); | ||
66 | grp = KConfigGroup(&grp, "Kill Runner"); | | |||
67 | 61 | | |||
68 | m_ui->useTriggerWord->setChecked(grp.readEntry(CONFIG_USE_TRIGGERWORD,true)); | 62 | m_ui->useTriggerWord->setChecked(grp.readEntry(CONFIG_USE_TRIGGERWORD,true)); | ||
69 | m_ui->triggerWord->setText(grp.readEntry(CONFIG_TRIGGERWORD,i18n("kill"))); | 63 | m_ui->triggerWord->setText(grp.readEntry(CONFIG_TRIGGERWORD, i18n("kill"))); | ||
70 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData(grp.readEntry<int>(CONFIG_SORTING, static_cast<int>(NONE)))); | 64 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData(grp.readEntry<int>(CONFIG_SORTING, NONE))); | ||
71 | 65 | | |||
72 | emit changed(false); | 66 | emit changed(false); | ||
73 | } | 67 | } | ||
74 | 68 | | |||
75 | void KillRunnerConfig::save() | 69 | void KillRunnerConfig::save() | ||
76 | { | 70 | { | ||
77 | KCModule::save(); | 71 | KCModule::save(); | ||
78 | 72 | | |||
79 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | 73 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); | ||
80 | KConfigGroup grp = cfg->group("Runners"); | 74 | KConfigGroup grp = cfg->group("Runners").group("Kill Runner"); | ||
81 | grp = KConfigGroup(&grp, "Kill Runner"); | | |||
82 | 75 | | |||
83 | grp.writeEntry(CONFIG_USE_TRIGGERWORD,m_ui->useTriggerWord->isChecked()); | 76 | grp.writeEntry(CONFIG_USE_TRIGGERWORD, m_ui->useTriggerWord->isChecked()); | ||
84 | grp.writeEntry(CONFIG_TRIGGERWORD,m_ui->triggerWord->text()); | 77 | grp.writeEntry(CONFIG_TRIGGERWORD, m_ui->triggerWord->text()); | ||
85 | grp.writeEntry(CONFIG_SORTING,m_ui->sorting->itemData(m_ui->sorting->currentIndex())); | 78 | grp.writeEntry(CONFIG_SORTING, m_ui->sorting->itemData(m_ui->sorting->currentIndex())); | ||
86 | 79 | | |||
87 | emit changed(false); | 80 | emit changed(false); | ||
88 | } | 81 | } | ||
89 | 82 | | |||
90 | void KillRunnerConfig::defaults() | 83 | void KillRunnerConfig::defaults() | ||
91 | { | 84 | { | ||
92 | KCModule::defaults(); | 85 | KCModule::defaults(); | ||
93 | 86 | | |||
94 | m_ui->useTriggerWord->setChecked(true); | 87 | m_ui->useTriggerWord->setChecked(true); | ||
95 | m_ui->triggerWord->setText(i18n("kill")); | 88 | m_ui->triggerWord->setText(i18n("kill")); | ||
96 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData((int) NONE)); | 89 | m_ui->sorting->setCurrentIndex(m_ui->sorting->findData((int) NONE)); | ||
97 | 90 | | |||
98 | emit changed(true); | 91 | emit markAsChanged(); | ||
99 | } | 92 | } | ||
100 | 93 | | |||
101 | #include "killrunner_config.moc" | 94 | #include "killrunner_config.moc" |