|
1 /*! |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements Qt Highway provider for key sequence handling. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QCoreApplication> |
|
19 #include <QTimer> |
|
20 #include <QTranslator> |
|
21 #include <QLocale> |
|
22 #include "keysequencerecognitionprovider.h" |
|
23 #include "manufacturerkeysequencehandler.h" |
|
24 #include "imeikeysequencehandler.h" |
|
25 #include "lifetimerkeysequencehandler.h" |
|
26 #include "keysequencerecognitionservicelog.h" |
|
27 |
|
28 /*! |
|
29 KeySequenceRecognitionProvider::KeySequenceRecognitionProvider. |
|
30 */ |
|
31 KeySequenceRecognitionProvider::KeySequenceRecognitionProvider( |
|
32 QObject* parent) |
|
33 : |
|
34 XQServiceProvider(QLatin1String( |
|
35 "keysequencerecognitionservice.com.nokia.symbian.IKeySequenceRecognition"), |
|
36 parent), |
|
37 m_keySequenceValidator("") |
|
38 { |
|
39 DPRINT_METHODENTRYEXIT; |
|
40 |
|
41 publishAll(); |
|
42 |
|
43 setupLocalization(); |
|
44 |
|
45 // One should not call anything exception generating after handlers are |
|
46 // created because memory for handlers will be leaked on an exception |
|
47 // while being in c++ constructor. |
|
48 constructKeySequenceHandlers(); |
|
49 } |
|
50 |
|
51 |
|
52 /*! |
|
53 KeySequenceRecognitionProvider::~KeySequenceRecognitionProvider. |
|
54 */ |
|
55 KeySequenceRecognitionProvider::~KeySequenceRecognitionProvider() |
|
56 { |
|
57 DPRINT_METHODENTRYEXIT; |
|
58 } |
|
59 |
|
60 |
|
61 /*! |
|
62 KeySequenceRecognitionProvider::keySequenceValidator. |
|
63 */ |
|
64 QString KeySequenceRecognitionProvider::keySequenceValidator() |
|
65 { |
|
66 DPRINT_METHODENTRYEXIT; |
|
67 |
|
68 if (m_keySequenceValidator.isEmpty()) { |
|
69 constructKeySequenceValidator(); |
|
70 } |
|
71 |
|
72 return m_keySequenceValidator; |
|
73 } |
|
74 |
|
75 |
|
76 /*! |
|
77 KeySequenceRecognitionProvider::executeKeySequence. |
|
78 */ |
|
79 bool KeySequenceRecognitionProvider::executeKeySequence( |
|
80 const QString &keySequence) |
|
81 { |
|
82 DPRINT_METHODENTRYEXIT; |
|
83 |
|
84 bool handled = false; |
|
85 |
|
86 QList<KeySequenceHandler*>::const_iterator it = m_handlers.constBegin(); |
|
87 for (;(it != m_handlers.constEnd()) && (!handled); ++it) { |
|
88 handled = (*it)->executeKeySequence(keySequence); |
|
89 } |
|
90 |
|
91 return handled; |
|
92 } |
|
93 |
|
94 |
|
95 /*! |
|
96 KeySequenceRecognitionProvider::setupLocalization. |
|
97 */ |
|
98 void KeySequenceRecognitionProvider::setupLocalization() |
|
99 { |
|
100 DPRINT_METHODENTRYEXIT; |
|
101 |
|
102 QScopedPointer<QTranslator> translator(new QTranslator(this)); |
|
103 |
|
104 QString locale = QLocale::system().name(); |
|
105 QString path = QString("z:/resource/qt/translations/"); |
|
106 bool translatorLoaded = |
|
107 translator->load(QString(path + "telephone_" + locale)); |
|
108 |
|
109 if (translatorLoaded) { |
|
110 qApp->installTranslator(translator.data()); |
|
111 translator.take(); |
|
112 } |
|
113 } |
|
114 |
|
115 |
|
116 /*! |
|
117 KeySequenceRecognitionProvider::constructKeySequenceHandlers. |
|
118 */ |
|
119 void KeySequenceRecognitionProvider::constructKeySequenceHandlers() |
|
120 { |
|
121 DPRINT_METHODENTRYEXIT; |
|
122 |
|
123 QScopedPointer<KeySequenceHandler> manufacturerHandler( |
|
124 new ManufacturerKeySequenceHandler(this)); |
|
125 m_handlers.append(manufacturerHandler.data()); |
|
126 manufacturerHandler.take(); |
|
127 |
|
128 QScopedPointer<KeySequenceHandler> imeiHandler( |
|
129 new ImeiKeySequenceHandler(this)); |
|
130 m_handlers.append(imeiHandler.data()); |
|
131 imeiHandler.take(); |
|
132 |
|
133 QScopedPointer<KeySequenceHandler> lifeTimerHandler( |
|
134 new LifeTimerKeySequenceHandler(this)); |
|
135 m_handlers.append(lifeTimerHandler.data()); |
|
136 lifeTimerHandler.take(); |
|
137 } |
|
138 |
|
139 |
|
140 /*! |
|
141 KeySequenceRecognitionProvider::constructKeySequenceValidator. |
|
142 */ |
|
143 void KeySequenceRecognitionProvider::constructKeySequenceValidator() |
|
144 { |
|
145 DPRINT_METHODENTRYEXIT; |
|
146 |
|
147 QList<KeySequenceHandler*>::const_iterator it = m_handlers.constBegin(); |
|
148 for (;it != m_handlers.constEnd(); ++it) { |
|
149 if (!m_keySequenceValidator.isEmpty()) { |
|
150 m_keySequenceValidator.append("|"); |
|
151 } |
|
152 |
|
153 QString validator = (*it)->keySequenceValidator(); |
|
154 m_keySequenceValidator.append(validator); |
|
155 } |
|
156 } |