MauiMan

inputdevicesmanager.cpp
1#include "inputdevicesmanager.h"
2#include "settingsstore.h"
3#include "mauimanutils.h"
4
5#include <QDebug>
6
7#if !defined Q_OS_ANDROID
8#include <QDBusInterface>
9#endif
10
11using namespace MauiMan;
12InputDevicesManager::InputDevicesManager(QObject *parent) : QObject(parent)
13 ,m_settings(new MauiMan::SettingsStore(this))
14{
15 qDebug( " INIT ACCESSIBILITY MANAGER");
16
17#if !defined Q_OS_ANDROID
18 auto server = new MauiManUtils(this);
19 if(server->serverRunning())
20 {
21 this->setConnections();
22 }
23
24 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state)
25 {
26 if(state)
27 {
28 this->setConnections();
29 }
30 });
31#endif
32
33 loadSettings();
34
35}
36
38{
39 return m_keyboardLayout;
40}
41
43{
44 return m_keyboardModel;
45}
46
48{
49 return m_keyboardVariant;
50}
51
53{
54 return m_keyboardOptions;
55}
56
58{
59 return m_keyboardRules;
60}
61
62void MauiMan::InputDevicesManager::setKeyboardLayout(QString keyboardLayout)
63{
64 if (m_keyboardLayout == keyboardLayout)
65 return;
66
67 m_keyboardLayout = keyboardLayout;
68 sync(QStringLiteral("setKeyboardLayout"), m_keyboardLayout);
69 m_settings->save(QStringLiteral("KeyboardLayout"), m_keyboardLayout);
70 Q_EMIT keyboardLayoutChanged(m_keyboardLayout);
71}
72
73void MauiMan::InputDevicesManager::setKeyboardModel(QString keyboardModel)
74{
75 if (m_keyboardModel == keyboardModel)
76 return;
77
78 m_keyboardModel = keyboardModel;
79 sync(QStringLiteral("setKeyboardModel"), m_keyboardModel);
80 m_settings->save(QStringLiteral("KeyboardModel"), m_keyboardModel);
81 Q_EMIT keyboardModelChanged(m_keyboardModel);
82}
83
84void MauiMan::InputDevicesManager::setKeyboardVariant(QString keyboardVariant)
85{
86 if (m_keyboardVariant == keyboardVariant)
87 return;
88
89 m_keyboardVariant = keyboardVariant;
90 sync(QStringLiteral("setKeyboardVariant"), m_keyboardVariant);
91 m_settings->save(QStringLiteral("KeyboardVariant"), m_keyboardVariant);
92 Q_EMIT keyboardVariantChanged(m_keyboardVariant);
93}
94
95void MauiMan::InputDevicesManager::setKeyboardOptions(QString keyboardOptions)
96{
97 if (m_keyboardOptions == keyboardOptions)
98 return;
99
100 m_keyboardOptions = keyboardOptions;
101 sync(QStringLiteral("setKeyboardOptions"), m_keyboardOptions);
102 m_settings->save(QStringLiteral("KeyboardOptions"), m_keyboardOptions);
103 Q_EMIT keyboardOptionsChanged(m_keyboardOptions);
104}
105
106void MauiMan::InputDevicesManager::setKeyboardRules(QString keyboardRules)
107{
108 if (m_keyboardRules == keyboardRules)
109 return;
110
111 m_keyboardRules = keyboardRules;
112 sync(QStringLiteral("setKeyboardRules"), m_keyboardRules);
113 m_settings->save(QStringLiteral("KeyboardRules"), m_keyboardRules);
114 Q_EMIT keyboardRulesChanged(m_keyboardRules);
115}
116
117void MauiMan::InputDevicesManager::onKeyboardLayoutChanged(const QString &keyboardLayout)
118{
119 if (m_keyboardLayout == keyboardLayout)
120 return;
121
122 m_keyboardLayout = keyboardLayout;
123 Q_EMIT keyboardLayoutChanged(m_keyboardLayout);
124}
125
126void MauiMan::InputDevicesManager::onKeyboardModelChanged(const QString &keyboardModel)
127{
128 if (m_keyboardModel == keyboardModel)
129 return;
130
131 m_keyboardModel = keyboardModel;
132 Q_EMIT keyboardModelChanged(m_keyboardModel);
133}
134
135void MauiMan::InputDevicesManager::onKeyboardOptionsChanged(const QString &keyboardOptions)
136{
137 if (m_keyboardOptions == keyboardOptions)
138 return;
139
140 m_keyboardOptions = keyboardOptions;
141 Q_EMIT keyboardOptionsChanged(m_keyboardOptions);
142}
143
144void MauiMan::InputDevicesManager::onKeyboardRulesChanged(const QString &keyboardRules)
145{
146 if (m_keyboardRules == keyboardRules)
147 return;
148
149 m_keyboardRules = keyboardRules;
150 Q_EMIT keyboardRulesChanged(m_keyboardRules);
151}
152
153void MauiMan::InputDevicesManager::onKeyboardVariantChanged(const QString &keyboardVariant)
154{
155 if (m_keyboardVariant == keyboardVariant)
156 return;
157
158 m_keyboardVariant = keyboardVariant;
159 Q_EMIT keyboardVariantChanged(m_keyboardVariant);
160}
161
162void MauiMan::InputDevicesManager::sync(const QString &key, const QVariant &value)
163{
164#if !defined Q_OS_ANDROID
165 if (m_interface && m_interface->isValid())
166 {
167 m_interface->call(key, value);
168 }
169#else
170 Q_UNUSED(key)
171 Q_UNUSED(value)
172#endif
173}
174
175void MauiMan::InputDevicesManager::setConnections()
176{
177#if !defined Q_OS_ANDROID
178 if(m_interface)
179 {
180 m_interface->disconnect();
181 m_interface->deleteLater();
182 m_interface = nullptr;
183 }
184
185 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"),
186 QStringLiteral("/InputDevices"),
187 QStringLiteral("org.mauiman.InputDevices"),
189 if (m_interface->isValid())
190 {
191 connect(m_interface, SIGNAL(keyboardLayoutChanged(double)), this, SLOT(onKeyboardLayoutChanged(QString)));
192 connect(m_interface, SIGNAL(keyboardModelChanged(double)), this, SLOT(onKeyboardModelChanged(QString)));
193 connect(m_interface, SIGNAL(keyboardRulesChanged(double)), this, SLOT(onKeyboardRulesChanged(QString)));
194 connect(m_interface, SIGNAL(keyboardOptionsChanged(double)), this, SLOT(onKeyboardOptionsChanged(QString)));
195 connect(m_interface, SIGNAL(keyboardVariantChanged(double)), this, SLOT(onKeyboardVariantChanged(QString)));
196
197 }
198#endif
199}
200
201void MauiMan::InputDevicesManager::loadSettings()
202{
203 m_settings->beginModule(QStringLiteral("InputDevices"));
204
205#if !defined Q_OS_ANDROID
206
207 if(m_interface && m_interface->isValid())
208 {
209 m_keyboardLayout = m_interface->property("keyboardLayout").toString();
210 m_keyboardModel = m_interface->property("keyboardModel").toString();
211 m_keyboardOptions = m_interface->property("keyboardOptions").toString();
212 m_keyboardRules = m_interface->property("keyboardRules").toString();
213 m_keyboardVariant = m_interface->property("keyboardVariant").toString();
214 return;
215 }
216#endif
217
218 m_keyboardLayout = m_settings->load(QStringLiteral("KeyboardLayout"), m_keyboardLayout).toString();
219 m_keyboardModel = m_settings->load(QStringLiteral("KeyboardModel"), m_keyboardModel).toString();
220 m_keyboardOptions = m_settings->load(QStringLiteral("KeyboardOptions"), m_keyboardOptions).toString();
221 m_keyboardRules = m_settings->load(QStringLiteral("KeyboardRules"), m_keyboardRules).toString();
222 m_keyboardVariant = m_settings->load(QStringLiteral("KeyboardVariant"), m_keyboardVariant).toString();
223}
The MauiManUtils class.
QString keyboardVariant
The preferred keyboard layout variant.
QString keyboardRules
The keyboard layout custom rules.
QString keyboardModel
The preferred keyboard model.
QString keyboardLayout
The preferred keyboard language layout.
QString keyboardOptions
The keyboard layout options.
The SettingsStore class Allows to store and read settings for MauiMan from the local conf file.
The MauiMan name-space contains all of the available modules for configuring the Maui Applications an...
QDBusConnection sessionBus()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.