Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/mousesettings.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2017 Xuetian Weng <wengxt@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 "mousesettings.h" | ||||
20 | | ||||
21 | #include <KSharedConfig> | ||||
22 | #include <KConfigGroup> | ||||
23 | #include <KGlobalSettings> | ||||
24 | | ||||
25 | #include "../migrationlib/kdelibs4config.h" | ||||
26 | | ||||
27 | void MouseSettings::apply(MouseBackend* backend, bool force) | ||||
28 | { | ||||
29 | if (!backend) { | ||||
30 | return; | ||||
31 | } | ||||
32 | | ||||
33 | backend->apply(*this, force); | ||||
34 | m_handedNeedsApply = false; | ||||
35 | } | ||||
36 | | ||||
37 | void MouseSettings::load(KConfig *config, MouseBackend *backend) | ||||
38 | { | ||||
39 | // TODO: what's a good threshold default value | ||||
40 | int threshold = 0; | ||||
41 | handed = MouseHanded::Right; | ||||
42 | double accel = 1.0; | ||||
43 | QString profile; | ||||
44 | if (backend) { | ||||
45 | backend->load(); | ||||
46 | auto handedOnServer = backend->handed(); | ||||
47 | handedEnabled = handedOnServer != MouseHanded::NotSupported; | ||||
48 | if (handedEnabled) { | ||||
49 | handed = handedOnServer; | ||||
50 | } | ||||
51 | accel = backend->accelRate(); | ||||
52 | threshold = backend->threshold(); | ||||
53 | profile = backend->accelerationProfile(); | ||||
54 | } | ||||
55 | | ||||
56 | KConfigGroup group = config->group("Mouse"); | ||||
57 | double a = group.readEntry("Acceleration", -1.0); | ||||
58 | if (a == -1) | ||||
59 | accelRate = accel; | ||||
60 | else | ||||
61 | accelRate = a; | ||||
62 | | ||||
63 | int t = group.readEntry("Threshold", -1); | ||||
64 | if (t == -1) | ||||
65 | thresholdMove = threshold; | ||||
66 | else | ||||
67 | thresholdMove = t; | ||||
68 | | ||||
69 | QString key = group.readEntry("MouseButtonMapping"); | ||||
70 | if (key == "RightHanded") | ||||
71 | handed = MouseHanded::Right; | ||||
72 | else if (key == "LeftHanded") | ||||
73 | handed = MouseHanded::Left; | ||||
74 | reverseScrollPolarity = group.readEntry("ReverseScrollPolarity", false); | ||||
75 | m_currentAccelProfile = group.readEntry("AccelerationProfile"); | ||||
76 | if (m_currentAccelProfile.isEmpty()) { | ||||
77 | m_currentAccelProfile = profile; | ||||
78 | } | ||||
79 | m_handedNeedsApply = false; | ||||
80 | | ||||
81 | // SC/DC/AutoSelect/ChangeCursor | ||||
82 | group = config->group("KDE"); | ||||
83 | doubleClickInterval = group.readEntry("DoubleClickInterval", 400); | ||||
84 | dragStartTime = group.readEntry("StartDragTime", 500); | ||||
85 | dragStartDist = group.readEntry("StartDragDist", 4); | ||||
86 | wheelScrollLines = group.readEntry("WheelScrollLines", 3); | ||||
87 | | ||||
88 | singleClick = group.readEntry("SingleClick", KDE_DEFAULT_SINGLECLICK); | ||||
89 | } | ||||
90 | | ||||
91 | void MouseSettings::save(KConfig *config) | ||||
92 | { | ||||
93 | KSharedConfig::Ptr kcminputProfile = KSharedConfig::openConfig("kcminputrc"); | ||||
94 | KConfigGroup kcminputGroup(kcminputProfile, "Mouse"); | ||||
95 | kcminputGroup.writeEntry("Acceleration",accelRate); | ||||
96 | kcminputGroup.writeEntry("Threshold",thresholdMove); | ||||
97 | if (handed == MouseHanded::Right) | ||||
98 | kcminputGroup.writeEntry("MouseButtonMapping",QString("RightHanded")); | ||||
99 | else | ||||
100 | kcminputGroup.writeEntry("MouseButtonMapping",QString("LeftHanded")); | ||||
101 | kcminputGroup.writeEntry("ReverseScrollPolarity", reverseScrollPolarity); | ||||
102 | kcminputGroup.writeEntry("AccelerationProfile", m_currentAccelProfile); | ||||
103 | kcminputGroup.sync(); | ||||
104 | | ||||
105 | KSharedConfig::Ptr profile = KSharedConfig::openConfig("kdeglobals"); | ||||
106 | KConfigGroup group(profile, "KDE"); | ||||
107 | group.writeEntry("DoubleClickInterval", doubleClickInterval, KConfig::Persistent); | ||||
108 | group.writeEntry("StartDragTime", dragStartTime, KConfig::Persistent); | ||||
109 | group.writeEntry("StartDragDist", dragStartDist, KConfig::Persistent); | ||||
110 | group.writeEntry("WheelScrollLines", wheelScrollLines, KConfig::Persistent); | ||||
111 | group.writeEntry("SingleClick", singleClick, KConfig::Persistent); | ||||
112 | | ||||
113 | group.sync(); | ||||
114 | config->sync(); | ||||
115 | | ||||
116 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("Mouse"), "kcminputrc"); | ||||
117 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("KDE"), "kdeglobals"); | ||||
118 | | ||||
119 | KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE); | ||||
120 | } |