killrunner_config.cpp 3.33 KB
Newer Older
1
/* Copyright 2009  <Jan Gerrit Marker> <jangerrit@weiler-marker.com>
2
 * Copyright 2020  <Alexander Lohnau> <alexander.lohnau@gmx.de>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) version 3, or any
 * later version accepted by the membership of KDE e.V. (or its
 * successor approved by the membership of KDE e.V.), which shall
 * act as a proxy defined in Section 6 of version 3 of the license.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

//Project-Includes
#include "killrunner_config.h"
//KDE-Includes
24
#include <KSharedConfig>
25
#include <KConfigGroup>
26
#include <KPluginFactory>
27
#include "config_keys.h"
28

29
K_PLUGIN_FACTORY(KillRunnerConfigFactory, registerPlugin<KillRunnerConfig>(QStringLiteral("kcm_krunner_kill"));)
30

31
KillRunnerConfigForm::KillRunnerConfigForm(QWidget *parent) : QWidget(parent)
32
33
34
35
{
    setupUi(this);
}

36
37
KillRunnerConfig::KillRunnerConfig(QWidget *parent, const QVariantList &args)
    : KCModule(parent, args)
38
39
40
{
    m_ui = new KillRunnerConfigForm(this);

41
    QGridLayout *layout = new QGridLayout(this);
42
43
44
45
46
    layout->addWidget(m_ui, 0, 0);

    m_ui->sorting->addItem(i18n("CPU usage"), CPU);
    m_ui->sorting->addItem(i18n("inverted CPU usage"), CPUI);
    m_ui->sorting->addItem(i18n("nothing"), NONE);
47

Laurent Montel's avatar
Laurent Montel committed
48
49
50
    connect(m_ui->useTriggerWord, &QCheckBox::stateChanged, this, &KillRunnerConfig::markAsChanged);
    connect(m_ui->triggerWord, &KLineEdit::textChanged, this, &KillRunnerConfig::markAsChanged);
    connect(m_ui->sorting, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KillRunnerConfig::markAsChanged);
51
52
53
54
55
56
57
58

    load();
}

void KillRunnerConfig::load()
{
    KCModule::load();

59
    KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc"));
60
    const KConfigGroup grp = cfg->group("Runners").group("Kill Runner");
61
62

    m_ui->useTriggerWord->setChecked(grp.readEntry(CONFIG_USE_TRIGGERWORD,true));
63
64
    m_ui->triggerWord->setText(grp.readEntry(CONFIG_TRIGGERWORD, i18n("kill")));
    m_ui->sorting->setCurrentIndex(m_ui->sorting->findData(grp.readEntry<int>(CONFIG_SORTING, NONE)));
65
66
67
68
69
70
71
72

    emit changed(false);
}

void KillRunnerConfig::save()
{
    KCModule::save();

73
    KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc"));
74
    KConfigGroup grp = cfg->group("Runners").group("Kill Runner");
75

76
77
78
    grp.writeEntry(CONFIG_USE_TRIGGERWORD, m_ui->useTriggerWord->isChecked());
    grp.writeEntry(CONFIG_TRIGGERWORD, m_ui->triggerWord->text());
    grp.writeEntry(CONFIG_SORTING, m_ui->sorting->itemData(m_ui->sorting->currentIndex()));
79
    grp.sync();
80
81
82
83
84
85
86
87
88
89
90
91

    emit changed(false);
}

void KillRunnerConfig::defaults()
{
    KCModule::defaults();

    m_ui->useTriggerWord->setChecked(true);
    m_ui->triggerWord->setText(i18n("kill"));
    m_ui->sorting->setCurrentIndex(m_ui->sorting->findData((int) NONE));

Alexander Lohnau's avatar
Alexander Lohnau committed
92
    markAsChanged();
93
}
94

95
#include "killrunner_config.moc"