Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/kcm/xlib/touchpadparametersbase.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 Alexander Mezin <mezin.alexander@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "touchpadparametersbase.h" | ||||
20 | #include "touchpadbackend.h" | ||||
21 | | ||||
22 | namespace | ||||
23 | { | ||||
24 | | ||||
25 | KConfigGroup &systemDefaults() | ||||
26 | { | ||||
27 | static KSharedConfig::Ptr p(KSharedConfig::openConfig(".touchpaddefaults", | ||||
28 | KConfig::SimpleConfig, | ||||
29 | QStandardPaths::TempLocation)); | ||||
30 | static KConfigGroup group(p->group("parameters")); | ||||
31 | return group; | ||||
32 | } | ||||
33 | | ||||
34 | } | ||||
35 | | ||||
36 | TouchpadParametersBase::TouchpadParametersBase(const QString &configname, | ||||
37 | QObject *parent) | ||||
38 | : KCoreConfigSkeleton(configname, parent) | ||||
39 | { | ||||
40 | if (!systemDefaults().exists()) { | ||||
41 | setSystemDefaults(); | ||||
42 | } | ||||
43 | } | ||||
44 | | ||||
45 | QVariantHash TouchpadParametersBase::values() const | ||||
46 | { | ||||
47 | QVariantHash r; | ||||
48 | Q_FOREACH(const KConfigSkeletonItem *i, items()) { | ||||
49 | r[i->name()] = i->property(); | ||||
50 | } | ||||
51 | return r; | ||||
52 | } | ||||
53 | | ||||
54 | void TouchpadParametersBase::setValues(const QVariantHash &v) | ||||
55 | { | ||||
56 | for (QVariantHash::ConstIterator i = v.begin(); i != v.end(); ++i) { | ||||
57 | KConfigSkeletonItem *j = findItem(i.key()); | ||||
58 | if (j) { | ||||
59 | j->setProperty(i.value()); | ||||
60 | } | ||||
61 | } | ||||
62 | } | ||||
63 | | ||||
64 | void TouchpadParametersBase::setSystemDefaults() | ||||
65 | { | ||||
66 | TouchpadBackend *backend = TouchpadBackend::implementation(); | ||||
67 | if (!backend) { | ||||
68 | return; | ||||
69 | } | ||||
70 | QVariantHash v; | ||||
71 | backend->getConfig(v); | ||||
72 | | ||||
73 | for (QVariantHash::ConstIterator i = v.constBegin(); i != v.constEnd(); ++i) { | ||||
74 | systemDefaults().writeEntry(i.key(), i.value()); | ||||
75 | } | ||||
76 | systemDefaults().sync(); | ||||
77 | } | ||||
78 | | ||||
79 | QVariant TouchpadParametersBase::systemDefault(const QString &name, | ||||
80 | const QVariant &hardcoded) | ||||
81 | { | ||||
82 | return systemDefaults().readEntry(name, hardcoded); | ||||
83 | } |