dictionaryrunner_config.cpp 1.7 KB
Newer Older
1
/*
2
3
 * SPDX-License-Identifier: GPL-2.0-or-later
 * SPDX-FileCopyrightText: 2010, 2012 Jason A. Donenfeld <Jason@zx2c4.com>
4
5
6
 */

#include "dictionaryrunner_config.h"
7
#include <KRunner/AbstractRunner>
8
9
#include <QFormLayout>
#include <QLineEdit>
10
#include <KSharedConfig>
11
#include <KLocalizedString>
Marco Martin's avatar
Marco Martin committed
12
#include <KPluginFactory>
13

14
15
K_PLUGIN_FACTORY(DictionaryRunnerConfigFactory,
                 registerPlugin<DictionaryRunnerConfig>(QStringLiteral("kcm_krunner_dictionary"));)
16
17

DictionaryRunnerConfig::DictionaryRunnerConfig(QWidget* parent, const QVariantList& args) :
18
	KCModule(parent, args)
19
20
21
{
	QFormLayout *layout = new QFormLayout;
	m_triggerWord = new QLineEdit;
22
	layout->addRow(i18nc("@label:textbox", "Trigger word:"), m_triggerWord);
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	setLayout(layout);
	connect(m_triggerWord, SIGNAL(textChanged(QString)), this, SLOT(changed()));
	load();
}

void DictionaryRunnerConfig::load()
{
	KCModule::load();
	KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QLatin1String("krunnerrc"));
	KConfigGroup grp = cfg->group("Runners");
	grp = KConfigGroup(&grp, "Dictionary");
	m_triggerWord->setText(grp.readEntry(CONFIG_TRIGGERWORD, i18nc("Trigger word before word to define", "define")));
	emit changed(false);
}

void DictionaryRunnerConfig::save()
{
	KCModule::save();
	KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QLatin1String("krunnerrc"));
	KConfigGroup grp = cfg->group("Runners");
	grp = KConfigGroup(&grp, "Dictionary");
	grp.writeEntry(CONFIG_TRIGGERWORD, m_triggerWord->text());
45
	grp.sync();
46
47
48
49
50
51
52
53
54
55
56
	emit changed(false);
}

void DictionaryRunnerConfig::defaults()
{
	KCModule::defaults();
	m_triggerWord->setText(i18nc("Trigger word before word to define", "define"));
	emit changed(true);
}

#include "dictionaryrunner_config.moc"