|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include <qbytearray.h> |
|
26 #include <QFile> |
|
27 #include <QBuffer> |
|
28 #include <QDataStream> |
|
29 #include <QCoreApplication> |
|
30 #include <QSharedMemory> |
|
31 #include <QVector> |
|
32 #include <QDir> |
|
33 |
|
34 #include "hbinputsettingproxy.h" |
|
35 #include "hbinputsettingproxy_p.h" |
|
36 #include "hbinputmodecache_p.h" |
|
37 #include "hbinputbasepaths_p.h" |
|
38 #include "hbinputfilter.h" |
|
39 |
|
40 /*! |
|
41 @alpha |
|
42 @hbcore |
|
43 \class HbInputSettingProxy |
|
44 \brief A singleton class providing access to system wide input related settings. |
|
45 |
|
46 HbInputSettingProxy provides access to all system wide input settings. It is implemented |
|
47 as process specific singleton, but it stores the settings to a shared memory chunk |
|
48 so that all the processes in the system share the same set of settings. |
|
49 |
|
50 Setting proxy stores its state to disk when the last instance in memory is destroyed |
|
51 and loads it back again when the first instance is created. |
|
52 |
|
53 It also knows file system paths to several important input related folders in the |
|
54 system. |
|
55 */ |
|
56 |
|
57 /// @cond |
|
58 |
|
59 // Special character classifier class for bookkeeping |
|
60 // of how popular a SC is. |
|
61 class HbScClassifier |
|
62 { |
|
63 public: |
|
64 HbScClassifier(QChar aChar = 0, int aCount = 0) |
|
65 : mChar(aChar), mCount(aCount) |
|
66 { |
|
67 } |
|
68 |
|
69 void operator=(const HbScClassifier& aOther) |
|
70 { |
|
71 mChar = aOther.mChar; |
|
72 mCount = aOther.mCount; |
|
73 } |
|
74 |
|
75 public: |
|
76 QChar mChar; |
|
77 int mCount; |
|
78 }; |
|
79 |
|
80 /// @endcond |
|
81 |
|
82 HbInputSettingProxyPrivate::HbInputSettingProxyPrivate() |
|
83 { |
|
84 iSharedMemory = new QSharedMemory(KInputSettingProxyKey); |
|
85 |
|
86 if (!iSharedMemory->attach()) { |
|
87 if (iSharedMemory->error() != QSharedMemory::NotFound) { |
|
88 qDebug("HbInputSettingProxy: QSharedMemory::attached returned error %d", iSharedMemory->error()); |
|
89 return; |
|
90 } |
|
91 |
|
92 if (!iSharedMemory->create(sizeof(HbSettingProxyInternalData))) { |
|
93 qDebug("HbInputSettingProxy : Unable to create shared memory block!"); |
|
94 return; |
|
95 } |
|
96 |
|
97 initializeDataArea(); |
|
98 } |
|
99 |
|
100 lock(); |
|
101 |
|
102 HbSettingProxyInternalData* prData = proxyData(); |
|
103 if (prData) { |
|
104 ++prData->iReferences; |
|
105 } |
|
106 |
|
107 unlock(); |
|
108 |
|
109 // This is needed because qApp doesn't not exist anymore when singleton destructs. |
|
110 iSaveFile = dataFileNameAndPath(); |
|
111 } |
|
112 |
|
113 HbInputSettingProxyPrivate::~HbInputSettingProxyPrivate() |
|
114 { |
|
115 // NOTE: iSharedMemory is not deleted on purpose. See HbInputSettingProxy::shutdown. |
|
116 } |
|
117 |
|
118 void HbInputSettingProxyPrivate::shutdownDataArea() |
|
119 { |
|
120 lock(); |
|
121 HbSettingProxyInternalData* prData = proxyData(); |
|
122 if (prData) { |
|
123 prData->iReferences--; |
|
124 if (prData->iReferences <= 0) { |
|
125 save(); |
|
126 } |
|
127 } |
|
128 unlock(); |
|
129 } |
|
130 |
|
131 QString HbInputSettingProxyPrivate::dataFilePath() |
|
132 { |
|
133 return HbInputSettingProxy::writablePath()+QDir::separator()+QString("settings"); |
|
134 } |
|
135 |
|
136 QString HbInputSettingProxyPrivate::dataFileNameAndPath() |
|
137 { |
|
138 return dataFilePath()+QDir::separator()+QString("proxy.dat"); |
|
139 } |
|
140 |
|
141 void HbInputSettingProxyPrivate::initializeDataArea() |
|
142 { |
|
143 lock(); |
|
144 bool wasLoaded = load(); |
|
145 |
|
146 HbSettingProxyInternalData* prData = proxyData(); |
|
147 if (prData) { |
|
148 prData->iReferences = 0; |
|
149 prData->iOrientationChangeCompleted = true; |
|
150 // Default values, real ones should be set by calling initializeOrientation() |
|
151 prData->iScreenOrientation = Qt::Vertical; |
|
152 |
|
153 if (!wasLoaded) { |
|
154 // There was no permanent storage version, so initialize to defaults. |
|
155 prData->iVersion = HbProxyDataRequiredVersion; |
|
156 prData->iGlobalPrimaryInputLanguage = HbInputLanguage(QLocale::English, QLocale::UnitedKingdom); |
|
157 prData->iGlobalSecondaryInputLanguage = QLocale::Language(0); |
|
158 prData->iActiveKeyboard = HbKeyboardVirtual12Key; |
|
159 prData->iTouchKeyboard = HbKeyboardVirtual12Key; |
|
160 prData->iHwKeyboard = HbKeyboardQwerty; |
|
161 prData->iActiveCustomMethodName[0] = 0; |
|
162 prData->iActiveCustomMethodKey[0] = 0; |
|
163 prData->iPredictiveInputState = 0; |
|
164 prData->iDigitType = HbDigitTypeLatin; |
|
165 prData->iQwertyTextCasing = true; |
|
166 prData->iQwertyCharacterPreview = true; |
|
167 prData->iRegionalCorrectionStatus = true; |
|
168 } |
|
169 } |
|
170 unlock(); |
|
171 } |
|
172 |
|
173 bool HbInputSettingProxyPrivate::load() |
|
174 { |
|
175 QFile file(dataFileNameAndPath()); |
|
176 if (!file.open(QIODevice::ReadOnly)) { |
|
177 return false; |
|
178 } |
|
179 |
|
180 QByteArray rawData = file.read(sizeof(HbSettingProxyInternalData)); |
|
181 if (rawData.size() == sizeof(HbSettingProxyInternalData)) { |
|
182 HbSettingProxyInternalData* ldData = (HbSettingProxyInternalData*)rawData.constData(); |
|
183 if (ldData) { |
|
184 if (ldData->iVersion == HbProxyDataRequiredVersion) { |
|
185 |
|
186 HbSettingProxyInternalData* prData = proxyData(); |
|
187 memcpy((void*)prData, (void*)ldData, sizeof(HbSettingProxyInternalData)); |
|
188 prData->iActiveKeyboard = ldData->iActiveKeyboard; |
|
189 |
|
190 // Temporarily like this, will be moved as part of shared data later... |
|
191 int numItems = 0; |
|
192 file.read((char *)&numItems, sizeof(int)); |
|
193 iTopScs.clear(); |
|
194 for (int jj = 0; jj < numItems; jj++) { |
|
195 HbScClassifier tmpItem; |
|
196 file.read((char*)&tmpItem, sizeof(HbScClassifier)); |
|
197 iTopScs.append(tmpItem); |
|
198 } |
|
199 |
|
200 file.close(); |
|
201 return true; |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 file.close(); |
|
207 return false; |
|
208 } |
|
209 |
|
210 void HbInputSettingProxyPrivate::save() |
|
211 { |
|
212 // Make sure that the path exists |
|
213 QDir settingDir; |
|
214 settingDir.mkpath(dataFilePath()); |
|
215 |
|
216 HbSettingProxyInternalData* prData = proxyData(); |
|
217 if (prData) { |
|
218 QFile file(iSaveFile); |
|
219 if (!file.open(QIODevice::WriteOnly)) { |
|
220 return; |
|
221 } |
|
222 |
|
223 file.write((const char*)prData, sizeof(HbSettingProxyInternalData)); |
|
224 |
|
225 // Temporarily like this, will be moved to shared data later... |
|
226 int numItems = iTopScs.count(); |
|
227 file.write((const char*)&numItems, sizeof(int)); |
|
228 file.write((const char*)iTopScs.constData(), numItems * sizeof(HbScClassifier)); |
|
229 file.close(); |
|
230 } |
|
231 } |
|
232 |
|
233 QString HbInputSettingProxyPrivate::stringFromProxyDataElement(QChar *string) const |
|
234 { |
|
235 QString result; |
|
236 for (int i = 0; string[i] != 0; i++) { |
|
237 result.append(string[i]); |
|
238 } |
|
239 |
|
240 return QString(result); |
|
241 } |
|
242 |
|
243 void HbInputSettingProxyPrivate::stringToProxyDataElement(QChar *string, const QString &source, int maxSize) const |
|
244 { |
|
245 int i = 0; |
|
246 for (; i < source.length() && i < maxSize - 1; i++) { |
|
247 string[i] = source[i]; |
|
248 } |
|
249 string[i] = 0; |
|
250 } |
|
251 |
|
252 HbSettingProxyInternalData* HbInputSettingProxyPrivate::proxyData() const |
|
253 { |
|
254 return static_cast<HbSettingProxyInternalData*>(iSharedMemory->data()); |
|
255 } |
|
256 |
|
257 void HbInputSettingProxyPrivate::flipToggle() |
|
258 { |
|
259 setFlipStatus(!flipStatus()); |
|
260 } |
|
261 |
|
262 bool HbInputSettingProxyPrivate::flipStatus() |
|
263 { |
|
264 HbSettingProxyInternalData* prData = proxyData(); |
|
265 return prData->iFlipStatus; |
|
266 } |
|
267 |
|
268 void HbInputSettingProxyPrivate::setFlipStatus(bool flipStatus) |
|
269 { |
|
270 HbSettingProxyInternalData* prData = proxyData(); |
|
271 prData->iFlipStatus = flipStatus; |
|
272 |
|
273 handleDeviceSpecificOriantationAndFlipChange(); |
|
274 } |
|
275 |
|
276 void HbInputSettingProxyPrivate::handleDeviceSpecificOriantationAndFlipChange() |
|
277 { |
|
278 HbKeyboardType keyboard = HbKeyboardNone; |
|
279 |
|
280 if (HbInputSettingProxy::instance()->screenOrientation() == Qt::Vertical) { |
|
281 keyboard = HbKeyboardVirtual12Key; |
|
282 } else { |
|
283 if(flipStatus()) { |
|
284 keyboard = HbKeyboardQwerty; |
|
285 } else { |
|
286 keyboard = HbKeyboardVirtualQwerty; |
|
287 } |
|
288 } |
|
289 |
|
290 HbInputSettingProxy::instance()->setActiveKeyboard(keyboard); |
|
291 } |
|
292 |
|
293 // |
|
294 // HbInputSettingProxy |
|
295 // |
|
296 |
|
297 /*! |
|
298 Returns pointer to the singleton object. |
|
299 */ |
|
300 HbInputSettingProxy* HbInputSettingProxy::instance() |
|
301 { |
|
302 static HbInputSettingProxy theProxy; |
|
303 return &theProxy; |
|
304 } |
|
305 |
|
306 /*! |
|
307 Constructs the object. |
|
308 */ |
|
309 HbInputSettingProxy::HbInputSettingProxy() : d_ptr(new HbInputSettingProxyPrivate()) |
|
310 { |
|
311 } |
|
312 |
|
313 /*! |
|
314 Destructs the object |
|
315 */ |
|
316 HbInputSettingProxy::~HbInputSettingProxy() |
|
317 { |
|
318 delete d_ptr; |
|
319 } |
|
320 |
|
321 /*! |
|
322 Shuts down the object safely. This is needed mainly for singleton object. There has been a lot |
|
323 of problems related to random singleton destruction order and additional shutdown step is |
|
324 needed to guarantee that it will be done safely. The slot is connected to |
|
325 QCoreApplication::aboutToQuit when the framework is initialized. |
|
326 */ |
|
327 void HbInputSettingProxy::shutdown() |
|
328 { |
|
329 Q_D(HbInputSettingProxy); |
|
330 |
|
331 d->shutdownDataArea(); |
|
332 delete d->iSharedMemory; |
|
333 d->iSharedMemory = 0; |
|
334 } |
|
335 |
|
336 /*! |
|
337 Toggles prediction mode |
|
338 */ |
|
339 void HbInputSettingProxy::togglePrediction() |
|
340 { |
|
341 if (predictiveInputStatus()) { |
|
342 setPredictiveInputStatus(0); |
|
343 } else { |
|
344 setPredictiveInputStatus(1); |
|
345 } |
|
346 } |
|
347 |
|
348 /*! |
|
349 Setting proxy emits a signal when any of the monitored settings changes. This |
|
350 method connects those signals to given object. |
|
351 |
|
352 \sa disconnectObservingObject |
|
353 \sa globalInputLanguageChanged |
|
354 \sa activeHwKeyboardChanged |
|
355 \sa predictiveInputStateChanged |
|
356 \sa orientationAboutToChange |
|
357 \sa orientationChanged |
|
358 */ |
|
359 void HbInputSettingProxy::connectObservingObject(QObject* aObserver) |
|
360 { |
|
361 if (aObserver) { |
|
362 connect(this, SIGNAL(globalInputLanguageChanged(const HbInputLanguage &)), aObserver, SLOT(globalInputLanguageChanged(const HbInputLanguage &))); |
|
363 connect(this, SIGNAL(globalSecondaryInputLanguageChanged(const HbInputLanguage &)), aObserver, SLOT(globalSecondaryInputLanguageChanged(const HbInputLanguage &))); |
|
364 connect(this, SIGNAL(activeKeyboardChanged(HbKeyboardType)), aObserver, SLOT(activeKeyboardChanged(HbKeyboardType))); |
|
365 connect(this, SIGNAL(activeHwKeyboardChanged(HbKeyboardType)), aObserver, SLOT(activeHwKeyboardChanged(HbKeyboardType))); |
|
366 connect(this, SIGNAL(activeTouchKeyboardChanged(HbKeyboardType)), aObserver, SLOT(activeTouchKeyboardChanged(HbKeyboardType))); |
|
367 connect(this, SIGNAL(predictiveInputStateChanged(int)), aObserver, SLOT(predictiveInputStateChanged(int))); |
|
368 connect(this, SIGNAL(orientationAboutToChange()), aObserver, SLOT(orientationAboutToChange())); |
|
369 connect(this, SIGNAL(orientationChanged(Qt::Orientation)), aObserver, SLOT(orientationChanged(Qt::Orientation))); |
|
370 } |
|
371 } |
|
372 |
|
373 /*! |
|
374 Disconnects given object from the setting proxy. |
|
375 |
|
376 \sa connectObservingObject |
|
377 */ |
|
378 void HbInputSettingProxy::disconnectObservingObject(QObject* aObserver) |
|
379 { |
|
380 if (aObserver) { |
|
381 disconnect(this, SIGNAL(globalInputLanguageChanged(const HbInputLanguage &)), aObserver, SLOT(globalInputLanguageChanged(const HbInputLanguage &))); |
|
382 disconnect(this, SIGNAL(globalSecondaryInputLanguageChanged(const HbInputLanguage &)), aObserver, SLOT(globalSecondaryInputLanguageChanged(const HbInputLanguage &))); |
|
383 disconnect(this, SIGNAL(predictiveInputStateChanged(int)), aObserver, SLOT(predictiveInputStateChanged(int))); |
|
384 disconnect(this, SIGNAL(activeKeyboardChanged(HbKeyboardType)), aObserver, SLOT(activeKeyboardChanged(HbKeyboardType))); |
|
385 disconnect(this, SIGNAL(activeHwKeyboardChanged(HbKeyboardType)), aObserver, SLOT(activeHwKeyboardChanged(HbKeyboardType))); |
|
386 disconnect(this, SIGNAL(activeTouchKeyboardChanged(HbKeyboardType)), aObserver, SLOT(activeTouchKeyboardChanged(HbKeyboardType))); |
|
387 disconnect(this, SIGNAL(orientationAboutToChange()), aObserver, SLOT(orientationAboutToChange())); |
|
388 disconnect(this, SIGNAL(orientationChanged(Qt::Orientation)), aObserver, SLOT(orientationChanged(Qt::Orientation))); |
|
389 } |
|
390 } |
|
391 |
|
392 /*! |
|
393 Returns active input language. This is system wide value, an editor and input state machine may override this by defining |
|
394 local input language. Use HbInputMethod::ActiveLanguage for input state related situation and |
|
395 this method for system wide setting. |
|
396 |
|
397 \sa setGlobalInputLanguage |
|
398 */ |
|
399 HbInputLanguage HbInputSettingProxy::globalInputLanguage() const |
|
400 { |
|
401 Q_D(const HbInputSettingProxy); |
|
402 HbInputLanguage res; |
|
403 |
|
404 d->lock(); |
|
405 HbSettingProxyInternalData* prData = d->proxyData(); |
|
406 if (prData) { |
|
407 res = prData->iGlobalPrimaryInputLanguage; |
|
408 } |
|
409 d->unlock(); |
|
410 |
|
411 return HbInputLanguage(res); |
|
412 } |
|
413 |
|
414 /*! |
|
415 Returns active secondary input language. Secondary input language is often used by the prediction engines for predicting |
|
416 candidates in both the languages. |
|
417 |
|
418 \sa setGlobalSecondaryInputLanguage |
|
419 */ |
|
420 HbInputLanguage HbInputSettingProxy::globalSecondaryInputLanguage() const |
|
421 { |
|
422 Q_D(const HbInputSettingProxy); |
|
423 HbInputLanguage res; |
|
424 |
|
425 d->lock(); |
|
426 HbSettingProxyInternalData* prData = d->proxyData(); |
|
427 if (prData) { |
|
428 res = prData->iGlobalSecondaryInputLanguage; |
|
429 } |
|
430 d->unlock(); |
|
431 |
|
432 return HbInputLanguage(res); |
|
433 } |
|
434 |
|
435 /*! |
|
436 Returns available hardware keyboard in the device. |
|
437 */ |
|
438 void HbInputSettingProxy::availableHwKeyboard(QList<HbKeyboardType>& aListOfAvailableKeyboards) const |
|
439 { |
|
440 aListOfAvailableKeyboards.append(HbKeyboard12Key); |
|
441 aListOfAvailableKeyboards.append(HbKeyboardQwerty); |
|
442 |
|
443 //Read the prData and get the list of keyboards from the device profile |
|
444 } |
|
445 |
|
446 /*! |
|
447 Returns active hardware keyboard type. |
|
448 |
|
449 \sa setActiveHwKeyboard |
|
450 \sa activeTouchKeyboard |
|
451 */ |
|
452 HbKeyboardType HbInputSettingProxy::activeHwKeyboard() const |
|
453 { |
|
454 Q_D(const HbInputSettingProxy); |
|
455 HbKeyboardType res = HbKeyboardNone; |
|
456 |
|
457 HbSettingProxyInternalData* prData = d->proxyData(); |
|
458 if (prData) { |
|
459 res = prData->iHwKeyboard; |
|
460 } |
|
461 |
|
462 return res; |
|
463 } |
|
464 |
|
465 /*! |
|
466 Returns active touch keyboard type. |
|
467 |
|
468 \sa setActiveTouchKeyboard |
|
469 \sa activeHwKeyboard |
|
470 */ |
|
471 HbKeyboardType HbInputSettingProxy::activeTouchKeyboard() const |
|
472 { |
|
473 Q_D(const HbInputSettingProxy); |
|
474 HbKeyboardType res = HbKeyboardNone; |
|
475 |
|
476 HbSettingProxyInternalData* prData = d->proxyData(); |
|
477 if (prData) { |
|
478 res = prData->iTouchKeyboard; |
|
479 } |
|
480 |
|
481 return res; |
|
482 } |
|
483 |
|
484 /*! |
|
485 Returns active keyboard type. |
|
486 |
|
487 \sa setActiveKeyboard |
|
488 */ |
|
489 HbKeyboardType HbInputSettingProxy::activeKeyboard() const |
|
490 { |
|
491 Q_D(const HbInputSettingProxy); |
|
492 HbKeyboardType res = HbKeyboardNone; |
|
493 |
|
494 HbSettingProxyInternalData* prData = d->proxyData(); |
|
495 if (prData) { |
|
496 res = prData->iActiveKeyboard; |
|
497 } |
|
498 |
|
499 return res; |
|
500 } |
|
501 |
|
502 /*! |
|
503 Sets system wide input language. Will emit signal globalInputLanguageChanged. |
|
504 |
|
505 \sa globalInputLanguage |
|
506 */ |
|
507 void HbInputSettingProxy::setGlobalInputLanguage(const HbInputLanguage& language) |
|
508 { |
|
509 Q_D(HbInputSettingProxy); |
|
510 HbSettingProxyInternalData* prData = d->proxyData(); |
|
511 if (prData) { |
|
512 d->lock(); |
|
513 prData->iGlobalPrimaryInputLanguage = language; |
|
514 d->unlock(); |
|
515 emit globalInputLanguageChanged(language); |
|
516 } |
|
517 } |
|
518 |
|
519 /*! |
|
520 Sets system wide secondary input language. Will emit signal globalSecondaryInputLanguageChanged. |
|
521 |
|
522 \sa globalSecondaryInputLanguage |
|
523 */ |
|
524 void HbInputSettingProxy::setGlobalSecondaryInputLanguage(const HbInputLanguage &language) |
|
525 { |
|
526 Q_D(HbInputSettingProxy); |
|
527 HbSettingProxyInternalData* prData = d->proxyData(); |
|
528 if (prData) { |
|
529 d->lock(); |
|
530 prData->iGlobalSecondaryInputLanguage = language; |
|
531 d->unlock(); |
|
532 emit globalSecondaryInputLanguageChanged(language); |
|
533 } |
|
534 } |
|
535 |
|
536 /*! |
|
537 Sets active hardware keyboard type. Will emit signal activeHwKeyboardChanged. |
|
538 |
|
539 \sa activeHwKeyboard |
|
540 \sa activeTouchKeyboard |
|
541 \sa setActiveTouchKeyboard |
|
542 \sa setActiveHwKeyboard |
|
543 */ |
|
544 void HbInputSettingProxy::setActiveHwKeyboard(HbKeyboardType keyboard) |
|
545 { |
|
546 Q_D(HbInputSettingProxy); |
|
547 HbSettingProxyInternalData* prData = d->proxyData(); |
|
548 if (prData) { |
|
549 d->lock(); |
|
550 prData->iHwKeyboard = keyboard; |
|
551 d->unlock(); |
|
552 emit activeHwKeyboardChanged(keyboard); |
|
553 } |
|
554 } |
|
555 |
|
556 /*! |
|
557 Sets active touch keyboard type. Will emit signal activeTouchKeyboardChanged. |
|
558 |
|
559 \sa activeTouchKeyboard |
|
560 \sa activeHwKeyboard |
|
561 \sa setActiveTouchKeyboard |
|
562 \sa setActiveHwKeyboard |
|
563 */ |
|
564 void HbInputSettingProxy::setActiveTouchKeyboard(HbKeyboardType keyboard) |
|
565 { |
|
566 Q_D(HbInputSettingProxy); |
|
567 HbSettingProxyInternalData* prData = d->proxyData(); |
|
568 if (prData) { |
|
569 d->lock(); |
|
570 prData->iTouchKeyboard = keyboard; |
|
571 d->unlock(); |
|
572 emit activeTouchKeyboardChanged(keyboard); |
|
573 } |
|
574 } |
|
575 |
|
576 /*! |
|
577 Sets active keyboard type. Will emit signal activeKeyboardChanged. |
|
578 |
|
579 \sa activeKeyboard |
|
580 \sa activeHwKeyboard |
|
581 \sa setactiveKeyboard |
|
582 \sa setActiveHwKeyboard |
|
583 */ |
|
584 void HbInputSettingProxy::setActiveKeyboard(HbKeyboardType keyboard) |
|
585 { |
|
586 Q_D(HbInputSettingProxy); |
|
587 HbSettingProxyInternalData* prData = d->proxyData(); |
|
588 if (prData) { |
|
589 d->lock(); |
|
590 prData->iActiveKeyboard = keyboard; |
|
591 d->unlock(); |
|
592 emit activeKeyboardChanged(keyboard); |
|
593 } |
|
594 } |
|
595 |
|
596 /*! |
|
597 Returns the status of predictive input feature. An editor instance |
|
598 may still forbid predictive input feature, even if the device wide status allows it. |
|
599 |
|
600 \sa setPredictiveInputStatus. |
|
601 */ |
|
602 int HbInputSettingProxy::predictiveInputStatus() const |
|
603 { |
|
604 Q_D(const HbInputSettingProxy); |
|
605 int res = 0; |
|
606 |
|
607 HbSettingProxyInternalData* prData = d->proxyData(); |
|
608 if (prData) { |
|
609 res = prData->iPredictiveInputState; |
|
610 } |
|
611 |
|
612 return res; |
|
613 } |
|
614 |
|
615 /*! |
|
616 Sets the status of predictive text input feature. |
|
617 |
|
618 \sa predictiveInputStatus |
|
619 */ |
|
620 void HbInputSettingProxy::setPredictiveInputStatus(int newStatus) |
|
621 { |
|
622 Q_D(HbInputSettingProxy); |
|
623 |
|
624 if (newStatus != 0) { |
|
625 newStatus = 1; |
|
626 } |
|
627 |
|
628 HbSettingProxyInternalData* prData = d->proxyData(); |
|
629 if (prData) { |
|
630 d->lock(); |
|
631 prData->iPredictiveInputState = newStatus; |
|
632 d->unlock(); |
|
633 emit predictiveInputStateChanged(newStatus); |
|
634 } |
|
635 } |
|
636 |
|
637 /*! |
|
638 Returns path to a writable location that should be used as a base storage folder for |
|
639 dynamic input data. |
|
640 */ |
|
641 QString HbInputSettingProxy::writablePath() |
|
642 { |
|
643 #ifdef Q_OS_SYMBIAN |
|
644 return HBI_BASE_WRITABLE_PATH ; |
|
645 #else |
|
646 if (QString(HB_BUILD_DIR) == QString(HB_INSTALL_DIR)) { |
|
647 // This is local build so also use local writable path. |
|
648 return QString(HB_INSTALL_DIR) + QDir::separator() + QString(".hbinputs"); |
|
649 } else { |
|
650 #ifdef Q_OS_UNIX |
|
651 return QDir::homePath() + QDir::separator() + QString(".hbinputs"); |
|
652 #else |
|
653 return HBI_BASE_WRITABLE_PATH ; |
|
654 #endif |
|
655 } |
|
656 #endif |
|
657 } |
|
658 |
|
659 /*! |
|
660 Returns path to input method plugin folder. |
|
661 */ |
|
662 QStringList HbInputSettingProxy::inputMethodPluginPaths() |
|
663 { |
|
664 QStringList result; |
|
665 |
|
666 #ifdef Q_OS_SYMBIAN |
|
667 result.append(QString("z:") + HBI_BASE_PATH + QDir::separator() + QString("inputmethods")); |
|
668 result.append(QString("c:") + HBI_BASE_PATH + QDir::separator() + QString("inputmethods")); |
|
669 result.append(QString("f:") + HBI_BASE_PATH + QDir::separator() + QString("inputmethods")); |
|
670 // Hard coded paths at the moment, we will really do this with QDir::drives() later... |
|
671 #else |
|
672 result.append(HB_PLUGINS_DIR + (QDir::separator() + QString("inputmethods"))); |
|
673 #endif |
|
674 |
|
675 return QStringList(result); |
|
676 } |
|
677 |
|
678 /*! |
|
679 Returns list of paths to all possible keymap plugin locations. |
|
680 */ |
|
681 QStringList HbInputSettingProxy::keymapPluginPaths() |
|
682 { |
|
683 QStringList result; |
|
684 #ifdef Q_OS_SYMBIAN |
|
685 result.append(QString("z:/resource/keymaps")); |
|
686 #else |
|
687 result.append(HB_RESOURCES_DIR + (QDir::separator() + QString("keymaps"))); |
|
688 #endif |
|
689 result.append(":/keymaps"); |
|
690 return QStringList(result); |
|
691 } |
|
692 |
|
693 /*! |
|
694 Returns path to language database folder. |
|
695 */ |
|
696 QString HbInputSettingProxy::languageDatabasePath() |
|
697 { |
|
698 #ifdef Q_OS_SYMBIAN |
|
699 #ifdef __WINSCW__ |
|
700 return (QString("c:") + HBI_BASE_PATH + QDir::separator() + QString("langdata")); |
|
701 #else |
|
702 return (QString("z:") + HBI_BASE_PATH + QDir::separator() + QString("langdata")); |
|
703 #endif |
|
704 // We'll need to do this for other drives too... |
|
705 #else |
|
706 return HB_PLUGINS_DIR + (QDir::separator() + QString("langdata")); |
|
707 #endif |
|
708 } |
|
709 |
|
710 /*! |
|
711 Returns path to dictionary plugin folder. |
|
712 */ |
|
713 QString HbInputSettingProxy::dictionaryPath() |
|
714 { |
|
715 return writablePath() + QDir::separator() + QString("dictionary"); |
|
716 } |
|
717 |
|
718 /*! |
|
719 Returns list of paths where prediction engine plugins will be searched. |
|
720 */ |
|
721 QStringList HbInputSettingProxy::predictionEnginePaths() |
|
722 { |
|
723 QStringList result; |
|
724 |
|
725 #ifdef Q_OS_SYMBIAN |
|
726 result.append(QString("z:") + HBI_BASE_PATH + QDir::separator() + QString("inputengines")); |
|
727 result.append(QString("c:") + HBI_BASE_PATH + QDir::separator() + QString("inputengines")); |
|
728 // Add memory card handling here later... |
|
729 #else |
|
730 result.append(HB_PLUGINS_DIR + (QDir::separator() + QString("inputengines"))); |
|
731 #endif |
|
732 |
|
733 return QStringList(result); |
|
734 } |
|
735 |
|
736 /*! |
|
737 Returns path to extra user dictionary folder. |
|
738 |
|
739 \sa HbExtraUserDictionary |
|
740 */ |
|
741 QString HbInputSettingProxy::extraDictionaryPath() |
|
742 { |
|
743 return writablePath() + QDir::separator() + QString("eud"); |
|
744 } |
|
745 |
|
746 /*! |
|
747 Returns system wide digit type setting. |
|
748 |
|
749 \sa setGlobalDigitType |
|
750 */ |
|
751 HbInputDigitType HbInputSettingProxy::globalDigitType() const |
|
752 { |
|
753 Q_D(const HbInputSettingProxy); |
|
754 HbInputDigitType res = HbDigitTypeLatin; |
|
755 |
|
756 HbSettingProxyInternalData* prData = d->proxyData(); |
|
757 if (prData) { |
|
758 res = prData->iDigitType; |
|
759 } |
|
760 |
|
761 return res; |
|
762 } |
|
763 |
|
764 /*! |
|
765 Sets system wide digit type setting. |
|
766 |
|
767 \sa globalDigitType |
|
768 */ |
|
769 void HbInputSettingProxy::setGlobalDigitType(HbInputDigitType digitType) |
|
770 { |
|
771 Q_D(HbInputSettingProxy); |
|
772 d->lock(); |
|
773 HbSettingProxyInternalData* prData = d->proxyData(); |
|
774 if (prData) { |
|
775 prData->iDigitType = digitType; |
|
776 } |
|
777 d->unlock(); |
|
778 } |
|
779 |
|
780 /*! |
|
781 Returns true if automatic text casing should be used with qwerty keyboards. |
|
782 |
|
783 \sa setAutomaticTextCasingForQwerty |
|
784 */ |
|
785 bool HbInputSettingProxy::automaticTextCasingForQwerty() |
|
786 { |
|
787 Q_D(HbInputSettingProxy); |
|
788 bool res = false; |
|
789 |
|
790 HbSettingProxyInternalData* prData = d->proxyData(); |
|
791 if (prData) { |
|
792 res = prData->iQwertyTextCasing; |
|
793 } |
|
794 |
|
795 return res; |
|
796 } |
|
797 |
|
798 /*! |
|
799 Sets automatic text casing for qwerty keyboards. |
|
800 |
|
801 \sa automaticTextCasingForQwerty |
|
802 */ |
|
803 void HbInputSettingProxy::setAutomaticTextCasingForQwerty(bool status) |
|
804 { |
|
805 Q_D(HbInputSettingProxy); |
|
806 d->lock(); |
|
807 HbSettingProxyInternalData* prData = d->proxyData(); |
|
808 if (prData) { |
|
809 prData->iQwertyTextCasing = status; |
|
810 } |
|
811 d->unlock(); |
|
812 } |
|
813 |
|
814 /*! |
|
815 Enables/Disables character preview in Qwerty keypad. |
|
816 |
|
817 \sa characterPreviewForQwerty |
|
818 */ |
|
819 void HbInputSettingProxy::setCharacterPreviewForQwerty(bool previewEnabled) |
|
820 { |
|
821 Q_D(HbInputSettingProxy); |
|
822 |
|
823 d->lock(); |
|
824 HbSettingProxyInternalData* prData = d->proxyData(); |
|
825 if (prData) { |
|
826 prData->iQwertyCharacterPreview = previewEnabled; |
|
827 } |
|
828 d->unlock(); |
|
829 } |
|
830 |
|
831 /*! |
|
832 Returns true if the character preview is enabled in Qwerty keypad. |
|
833 |
|
834 \sa setCharacterPreviewForQwerty |
|
835 */ |
|
836 bool HbInputSettingProxy::isCharacterPreviewForQwertyEnabled() |
|
837 { |
|
838 Q_D(HbInputSettingProxy); |
|
839 |
|
840 bool res = false; |
|
841 |
|
842 HbSettingProxyInternalData* prData = d->proxyData(); |
|
843 if (prData) { |
|
844 res = prData->iQwertyCharacterPreview; |
|
845 } |
|
846 |
|
847 return res; |
|
848 } |
|
849 |
|
850 /*! |
|
851 Returns active custom input method. The pluginNameAndPath field is empty if no custom input methid is active. |
|
852 |
|
853 \sa setActiveCustomInputMethod |
|
854 */ |
|
855 HbInputMethodDescriptor HbInputSettingProxy::activeCustomInputMethod() const |
|
856 { |
|
857 Q_D(const HbInputSettingProxy); |
|
858 |
|
859 HbInputMethodDescriptor result; |
|
860 |
|
861 d->lock(); |
|
862 HbSettingProxyInternalData* prData = d->proxyData(); |
|
863 if (prData) { |
|
864 result.setPluginNameAndPath(d->stringFromProxyDataElement(prData->iActiveCustomMethodName)); |
|
865 result.setKey(d->stringFromProxyDataElement(prData->iActiveCustomMethodKey)); |
|
866 } |
|
867 d->unlock(); |
|
868 |
|
869 return HbInputMethodDescriptor(result); |
|
870 } |
|
871 |
|
872 /*! |
|
873 |
|
874 \sa activeCustomInputMethod |
|
875 */ |
|
876 void HbInputSettingProxy::setActiveCustomInputMethod(const HbInputMethodDescriptor &inputMethod) |
|
877 { |
|
878 Q_D(HbInputSettingProxy); |
|
879 |
|
880 d->lock(); |
|
881 HbSettingProxyInternalData* prData = d->proxyData(); |
|
882 if (prData) { |
|
883 d->stringToProxyDataElement(prData->iActiveCustomMethodName, inputMethod.pluginNameAndPath(), HbActiveMethodNameMax); |
|
884 d->stringToProxyDataElement(prData->iActiveCustomMethodKey, inputMethod.key(), HbActiveMethodKeyMax); |
|
885 } |
|
886 d->unlock(); |
|
887 } |
|
888 |
|
889 /*! |
|
890 Returns the current screen orientation in settings |
|
891 */ |
|
892 Qt::Orientation HbInputSettingProxy::screenOrientation() |
|
893 { |
|
894 Q_D(HbInputSettingProxy); |
|
895 |
|
896 Qt::Orientation orientation = Qt::Vertical; |
|
897 HbSettingProxyInternalData* prData = d->proxyData(); |
|
898 if (prData) { |
|
899 orientation = prData->iScreenOrientation; |
|
900 } |
|
901 return orientation; |
|
902 } |
|
903 |
|
904 /*! |
|
905 Sets the current screen orientation in settings. This completes orientation change |
|
906 started with notifyScreenOrientationChange. |
|
907 */ |
|
908 void HbInputSettingProxy::setScreenOrientation(Qt::Orientation screenOrientation) |
|
909 { |
|
910 Q_D(HbInputSettingProxy); |
|
911 |
|
912 HbSettingProxyInternalData* prData = d->proxyData(); |
|
913 if (prData) { |
|
914 bool notify = false; |
|
915 |
|
916 d->lock(); |
|
917 if (screenOrientation != prData->iScreenOrientation) { |
|
918 prData->iScreenOrientation = screenOrientation; |
|
919 notify = true; |
|
920 } |
|
921 d->unlock(); |
|
922 |
|
923 if (notify) { |
|
924 // notify everyone that the orientation has changed. |
|
925 d->handleDeviceSpecificOriantationAndFlipChange(); |
|
926 emit orientationChanged(screenOrientation); |
|
927 // set orientation change operation completed. |
|
928 d->lock(); |
|
929 prData->iOrientationChangeCompleted = true; |
|
930 d->unlock(); |
|
931 } |
|
932 } |
|
933 } |
|
934 |
|
935 /*! |
|
936 Starts screen orientation change sequence. Emits orientationAboutToChange signal |
|
937 and set internal orientation change flag to true. Whoever calls this |
|
938 method, must also complete the orientation change sequence by calling setScreenOrientation. |
|
939 Generally this mechanims is connected to operating system level screen orientation attribute |
|
940 begind the scenes and there is no need to call this directly from application or input |
|
941 method. |
|
942 */ |
|
943 void HbInputSettingProxy::notifyScreenOrientationChange() |
|
944 { |
|
945 Q_D(HbInputSettingProxy); |
|
946 |
|
947 HbSettingProxyInternalData* prData = d->proxyData(); |
|
948 if (prData) { |
|
949 d->lock(); |
|
950 prData->iOrientationChangeCompleted = false; |
|
951 d->unlock(); |
|
952 } |
|
953 emit orientationAboutToChange(); |
|
954 } |
|
955 |
|
956 /*! |
|
957 Returns true if the orientation change is completed |
|
958 */ |
|
959 bool HbInputSettingProxy::orientationChangeCompleted() const |
|
960 { |
|
961 Q_D(const HbInputSettingProxy); |
|
962 |
|
963 bool completed = true; |
|
964 HbSettingProxyInternalData* prData = d->proxyData(); |
|
965 if (prData) { |
|
966 completed = prData->iOrientationChangeCompleted; |
|
967 } |
|
968 return completed; |
|
969 } |
|
970 |
|
971 /*! |
|
972 Method for initializing orientation state of the input framework. Needed only on |
|
973 framework level, should not be called by applications. |
|
974 */ |
|
975 void HbInputSettingProxy::initializeOrientation(Qt::Orientation screenOrientation) |
|
976 { |
|
977 Q_D(HbInputSettingProxy); |
|
978 |
|
979 // call handleDeviceSpecificOriantationAndFlipChange method |
|
980 HbSettingProxyInternalData* prData = d->proxyData(); |
|
981 if (prData) { |
|
982 d->lock(); |
|
983 prData->iScreenOrientation = screenOrientation; |
|
984 if (screenOrientation == Qt::Vertical) { |
|
985 prData->iActiveKeyboard = HbKeyboardVirtual12Key; |
|
986 } else { |
|
987 prData->iActiveKeyboard = HbKeyboardVirtualQwerty; |
|
988 } |
|
989 d->unlock(); |
|
990 } |
|
991 } |
|
992 |
|
993 /*! |
|
994 Returns the status of regional input correction feature. |
|
995 |
|
996 \sa enableRegionalCorrection. |
|
997 */ |
|
998 bool HbInputSettingProxy::regionalCorrectionEnabled() |
|
999 { |
|
1000 Q_D(const HbInputSettingProxy); |
|
1001 bool res = false; |
|
1002 HbSettingProxyInternalData* prData = d->proxyData(); |
|
1003 if (prData) { |
|
1004 res = prData->iRegionalCorrectionStatus; |
|
1005 } |
|
1006 return res; |
|
1007 } |
|
1008 |
|
1009 /*! |
|
1010 Sets the status of regional input correction feature. |
|
1011 |
|
1012 \sa regionalCorrectionEnabled. |
|
1013 */ |
|
1014 void HbInputSettingProxy::enableRegionalCorrection(bool newStatus) |
|
1015 { |
|
1016 Q_D(HbInputSettingProxy); |
|
1017 HbSettingProxyInternalData* prData = d->proxyData(); |
|
1018 if (prData) { |
|
1019 d->lock(); |
|
1020 prData->iRegionalCorrectionStatus = newStatus; |
|
1021 d->unlock(); |
|
1022 emit regionalCorretionStatusChanged(newStatus); |
|
1023 } |
|
1024 } |
|
1025 |
|
1026 // End of file |