1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtVirtualKeyboard/private/settings_p.h>
5#include <QtCore/private/qobject_p.h>
6#include <QStandardPaths>
7#include <QFileInfo>
8#include <QDir>
9#include "virtualkeyboarddebug_p.h"
10
11QT_BEGIN_NAMESPACE
12namespace QtVirtualKeyboard {
13
14class SettingsPrivate : public QObjectPrivate
15{
16public:
17 SettingsPrivate() :
18 QObjectPrivate(),
19 style(),
20 styleName(),
21 locale(),
22 availableLocales(),
23 activeLocales(),
24 layoutPath(),
25 wclAutoHideDelay(5000),
26 wclAlwaysVisible(false),
27 wclAutoCommitWord(false),
28 fullScreenMode(false),
29 userDataPath(QStringLiteral("%1/qtvirtualkeyboard")
30 .arg(a: QStandardPaths::writableLocation(
31 type: QStandardPaths::GenericConfigLocation))),
32 hwrTimeoutForAlphabetic(500),
33 hwrTimeoutForCjk(500),
34 handwritingModeDisabled(false),
35 defaultInputMethodDisabled(false),
36 defaultDictionaryDisabled(false)
37 {
38 ensureUserDataPathExists();
39 }
40
41 void ensureUserDataPathExists() const
42 {
43 if (!userDataPath.isEmpty() && !QFileInfo::exists(file: userDataPath)) {
44 if (!QDir::root().mkpath(dirPath: userDataPath)) {
45 VIRTUALKEYBOARD_WARN() << "Cannot create directory for user data" << userDataPath;
46 }
47 }
48 }
49
50 QString style;
51 QString styleName;
52 QString locale;
53 QStringList availableLocales;
54 QStringList activeLocales;
55 QUrl layoutPath;
56 int wclAutoHideDelay;
57 bool wclAlwaysVisible;
58 bool wclAutoCommitWord;
59 bool fullScreenMode;
60 QString userDataPath;
61 int hwrTimeoutForAlphabetic;
62 int hwrTimeoutForCjk;
63 Qt::InputMethodHints inputMethodHints;
64 bool handwritingModeDisabled;
65 bool defaultInputMethodDisabled;
66 bool defaultDictionaryDisabled;
67 QtVirtualKeyboard::KeyboardFunctionKeys visibleFunctionKeys = QtVirtualKeyboard::KeyboardFunctionKey::All;
68};
69
70static QScopedPointer<Settings> s_settingsInstance;
71
72/*!
73 \class QtVirtualKeyboard::Settings
74 \internal
75*/
76
77Settings::Settings(QObject *parent) :
78 QObject(*new SettingsPrivate(), parent)
79{
80}
81
82Settings *Settings::instance()
83{
84 if (!s_settingsInstance)
85 s_settingsInstance.reset(other: new Settings());
86 return s_settingsInstance.data();
87}
88
89QString Settings::style() const
90{
91 Q_D(const Settings);
92 return d->style;
93}
94
95void Settings::setStyle(const QString &style)
96{
97 Q_D(Settings);
98 if (d->style != style) {
99 d->style = style;
100 emit styleChanged();
101 }
102}
103
104QString Settings::styleName() const
105{
106 Q_D(const Settings);
107 return d->styleName;
108}
109
110void Settings::setStyleName(const QString &styleName)
111{
112 Q_D(Settings);
113 if (d->styleName != styleName) {
114 d->styleName = styleName;
115 emit styleNameChanged();
116 }
117}
118
119QString Settings::locale() const
120{
121 Q_D(const Settings);
122 return d->locale;
123}
124
125void Settings::setLocale(const QString &locale)
126{
127 Q_D(Settings);
128 if (d->locale != locale) {
129 d->locale = locale;
130 emit localeChanged();
131 }
132}
133
134QStringList Settings::availableLocales() const
135{
136 Q_D(const Settings);
137 return d->availableLocales;
138}
139
140void Settings::setAvailableLocales(const QStringList &availableLocales)
141{
142 Q_D(Settings);
143 if (d->availableLocales != availableLocales) {
144 d->availableLocales = availableLocales;
145 emit availableLocalesChanged();
146 }
147}
148
149QStringList Settings::activeLocales() const
150{
151 Q_D(const Settings);
152 return d->activeLocales;
153}
154
155void Settings::setActiveLocales(const QStringList &activeLocales)
156{
157 Q_D(Settings);
158 if (d->activeLocales != activeLocales) {
159 d->activeLocales = activeLocales;
160 emit activeLocalesChanged();
161 }
162}
163
164QUrl Settings::layoutPath() const
165{
166 Q_D(const Settings);
167 return d->layoutPath;
168}
169
170void Settings::setLayoutPath(const QUrl &layoutPath)
171{
172 Q_D(Settings);
173 if (d->layoutPath != layoutPath) {
174 d->layoutPath = layoutPath;
175 emit layoutPathChanged();
176 }
177}
178
179int Settings::wclAutoHideDelay() const
180{
181 Q_D(const Settings);
182 return d->wclAutoHideDelay;
183}
184
185void Settings::setWclAutoHideDelay(int wclAutoHideDelay)
186{
187 Q_D(Settings);
188 if (d->wclAutoHideDelay != wclAutoHideDelay) {
189 d->wclAutoHideDelay = wclAutoHideDelay;
190 emit wclAutoHideDelayChanged();
191 }
192}
193
194bool Settings::wclAlwaysVisible() const
195{
196 Q_D(const Settings);
197 return d->wclAlwaysVisible;
198}
199
200void Settings::setWclAlwaysVisible(bool wclAlwaysVisible)
201{
202 Q_D(Settings);
203 if (d->wclAlwaysVisible != wclAlwaysVisible) {
204 d->wclAlwaysVisible = wclAlwaysVisible;
205 emit wclAlwaysVisibleChanged();
206 }
207}
208
209bool Settings::wclAutoCommitWord() const
210{
211 Q_D(const Settings);
212 return d->wclAutoCommitWord;
213}
214
215void Settings::setWclAutoCommitWord(bool wclAutoCommitWord)
216{
217 Q_D(Settings);
218 if (d->wclAutoCommitWord != wclAutoCommitWord) {
219 d->wclAutoCommitWord = wclAutoCommitWord;
220 emit wclAutoCommitWordChanged();
221 }
222}
223
224bool Settings::fullScreenMode() const
225{
226 Q_D(const Settings);
227 return d->fullScreenMode;
228}
229
230void Settings::setFullScreenMode(bool fullScreenMode)
231{
232 Q_D(Settings);
233 if (d->fullScreenMode != fullScreenMode) {
234 d->fullScreenMode = fullScreenMode;
235 emit fullScreenModeChanged();
236 }
237}
238
239QString Settings::userDataPath() const
240{
241 Q_D(const Settings);
242 return d->userDataPath;
243}
244
245void Settings::setUserDataPath(const QString &userDataPath)
246{
247 Q_D(Settings);
248 if (d->userDataPath != userDataPath) {
249 d->userDataPath = userDataPath;
250 d->ensureUserDataPathExists();
251 emit userDataPathChanged();
252 }
253}
254
255int Settings::hwrTimeoutForAlphabetic() const
256{
257 Q_D(const Settings);
258 return d->hwrTimeoutForAlphabetic;
259}
260
261void Settings::setHwrTimeoutForAlphabetic(int hwrTimeoutForAlphabetic)
262{
263 Q_D(Settings);
264 if (d->hwrTimeoutForAlphabetic != hwrTimeoutForAlphabetic) {
265 d->hwrTimeoutForAlphabetic = hwrTimeoutForAlphabetic;
266 emit hwrTimeoutForAlphabeticChanged();
267 }
268}
269
270int Settings::hwrTimeoutForCjk() const
271{
272 Q_D(const Settings);
273 return d->hwrTimeoutForCjk;
274}
275
276void Settings::setHwrTimeoutForCjk(int hwrTimeoutForCjk)
277{
278 Q_D(Settings);
279 if (d->hwrTimeoutForCjk != hwrTimeoutForCjk) {
280 d->hwrTimeoutForCjk = hwrTimeoutForCjk;
281 emit hwrTimeoutForCjkChanged();
282 }
283}
284
285Qt::InputMethodHints Settings::inputMethodHints() const
286{
287 Q_D(const Settings);
288 return d->inputMethodHints;
289}
290
291void Settings::setInputMethodHints(const Qt::InputMethodHints &inputMethodHints)
292{
293 Q_D(Settings);
294 if (d->inputMethodHints != inputMethodHints) {
295 d->inputMethodHints = inputMethodHints;
296 emit inputMethodHintsChanged();
297 }
298}
299
300bool Settings::isHandwritingModeDisabled() const
301{
302 Q_D(const Settings);
303 return d->handwritingModeDisabled;
304}
305
306void Settings::setHandwritingModeDisabled(bool handwritingModeDisabled)
307{
308 Q_D(Settings);
309 if (d->handwritingModeDisabled != handwritingModeDisabled) {
310 d->handwritingModeDisabled = handwritingModeDisabled;
311 emit handwritingModeDisabledChanged();
312 }
313}
314
315bool Settings::isDefaultInputMethodDisabled() const
316{
317 Q_D(const Settings);
318 return d->defaultInputMethodDisabled;
319}
320
321void Settings::setDefaultInputMethodDisabled(bool defaultInputMethodDisabled)
322{
323 Q_D(Settings);
324 if (d->defaultInputMethodDisabled != defaultInputMethodDisabled) {
325 d->defaultInputMethodDisabled = defaultInputMethodDisabled;
326 emit defaultInputMethodDisabledChanged();
327 }
328}
329
330bool QtVirtualKeyboard::Settings::isDefaultDictionaryDisabled() const
331{
332 Q_D(const Settings);
333 return d->defaultDictionaryDisabled;
334}
335
336void QtVirtualKeyboard::Settings::setDefaultDictionaryDisabled(bool defaultDictionaryDisabled)
337{
338 Q_D(Settings);
339 if (d->defaultDictionaryDisabled != defaultDictionaryDisabled) {
340 d->defaultDictionaryDisabled = defaultDictionaryDisabled;
341 emit defaultDictionaryDisabledChanged();
342 }
343}
344
345QtVirtualKeyboard::KeyboardFunctionKeys Settings::visibleFunctionKeys() const
346{
347 Q_D(const Settings);
348 return d->visibleFunctionKeys;
349}
350
351void Settings::setVisibleFunctionKeys(QtVirtualKeyboard::KeyboardFunctionKeys newVisibleFunctionKeys)
352{
353 Q_D(Settings);
354 if (d->visibleFunctionKeys != newVisibleFunctionKeys) {
355 d->visibleFunctionKeys = newVisibleFunctionKeys;
356 emit visibleFunctionKeysChanged();
357 }
358}
359
360} // namespace QtVirtualKeyboard
361QT_END_NAMESPACE
362

source code of qtvirtualkeyboard/src/virtualkeyboard/settings.cpp