|
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: This file implements the plugin interface for positioning verification dialogs |
|
15 * |
|
16 */ |
|
17 #include "posverificationdialogplugin.h" |
|
18 //User Includes |
|
19 #include "customdocumentloader.h" |
|
20 #include "posverificationcustomdialog.h" |
|
21 #include "apilogger.h" |
|
22 |
|
23 #include <QDebug> |
|
24 #include <QTCore> |
|
25 |
|
26 //Carbide Application docml file |
|
27 const char *POSVERFICATIONDIALOG_DOCML = |
|
28 ":/xml/posverificationcustomdialog.docml"; |
|
29 |
|
30 // This plugin implements one custom dialog type |
|
31 enum DeviceDlgType |
|
32 { |
|
33 PosVerificationDialogType |
|
34 }; |
|
35 static const struct |
|
36 { |
|
37 const char *mTypeString; |
|
38 DeviceDlgType mType; |
|
39 } verdlgtypes[] = |
|
40 { |
|
41 { |
|
42 "hb.posverifiction.dialog/1.0", PosVerificationDialogType |
|
43 } |
|
44 }; |
|
45 |
|
46 //----------------------------------------------------------------------- |
|
47 // PosVerificationDialogPlugin::PosVerificationDialogPlugin() |
|
48 // Constructor |
|
49 //----------------------------------------------------------------------- |
|
50 PosVerificationDialogPlugin::PosVerificationDialogPlugin() : |
|
51 mTranslator(NULL) |
|
52 { |
|
53 qDebug() << "+PosVerificationDialogPlugin::PosVerificationDialogPlugin()"; |
|
54 //#ifndef QT_NO_DEBUG_OUTPUT |
|
55 // ApiLogger::OpenLogFile(); |
|
56 // qInstallMsgHandler(ApiLogger::MyOutputHandler); |
|
57 //#endif |
|
58 qDebug() << "-PosVerificationDialogPlugin::PosVerificationDialogPlugin()"; |
|
59 } |
|
60 |
|
61 //----------------------------------------------------------------------- |
|
62 // PosVerificationDialogPlugin::~PosVerificationDialogPlugin() |
|
63 // Destructor |
|
64 //----------------------------------------------------------------------- |
|
65 PosVerificationDialogPlugin::~PosVerificationDialogPlugin() |
|
66 { |
|
67 qDebug() |
|
68 << "+PosVerificationDialogPlugin::~PosVerificationDialogPlugin()"; |
|
69 if (mTranslator) |
|
70 { |
|
71 if (mTranslator->isEmpty() == false) |
|
72 qApp->removeTranslator(mTranslator); |
|
73 delete mTranslator; |
|
74 } |
|
75 qDebug() |
|
76 << "-PosVerificationDialogPlugin::~PosVerificationDialogPlugin()"; |
|
77 //#ifndef QT_NO_DEBUG_OUTPUT |
|
78 // ApiLogger::CloseLogFile(); |
|
79 //#endif |
|
80 } |
|
81 |
|
82 //----------------------------------------------------------------------- |
|
83 // PosVerificationDialogPlugin::accessAllowed |
|
84 // Check if client is allowed to use device dialog widget |
|
85 //----------------------------------------------------------------------- |
|
86 bool PosVerificationDialogPlugin::accessAllowed( |
|
87 const QString &deviceDialogType, const QVariantMap ¶meters, |
|
88 const QVariantMap &securityInfo) const |
|
89 { |
|
90 qDebug() << "+PosVerificationDialogPlugin::accessAllowed()"; |
|
91 Q_UNUSED(deviceDialogType) |
|
92 Q_UNUSED(parameters) |
|
93 Q_UNUSED(securityInfo) |
|
94 |
|
95 // This plugin doesn't perform operations that may compromise security. All clients |
|
96 // are allowed to use. |
|
97 qDebug() << "-PosVerificationDialogPlugin::accessAllowed()"; |
|
98 return true; |
|
99 } |
|
100 |
|
101 //----------------------------------------------------------------------- |
|
102 // PosVerificationDialogPlugin::createDeviceDialog |
|
103 // Create device dialog widget |
|
104 //----------------------------------------------------------------------- |
|
105 HbDeviceDialogInterface * PosVerificationDialogPlugin::createDeviceDialog( |
|
106 const QString &deviceDialogType, const QVariantMap ¶meters) |
|
107 { |
|
108 qDebug() << "+PosVerificationDialogPlugin::createDeviceDialog(): Type" |
|
109 << deviceDialogType; |
|
110 //install the translator. Fix for Bug id: ou1cimx1#462081 |
|
111 installTranslator(); |
|
112 |
|
113 int i; |
|
114 PosVerificationCustomDialog * dialog = 0; |
|
115 const int numTypes = sizeof(verdlgtypes) / sizeof(verdlgtypes[0]); |
|
116 for (i = 0; i < numTypes; ++i) |
|
117 { |
|
118 if (verdlgtypes[i].mTypeString == deviceDialogType) |
|
119 { |
|
120 break; |
|
121 } |
|
122 } |
|
123 if (i < numTypes) |
|
124 { |
|
125 switch (verdlgtypes[i].mType) |
|
126 { |
|
127 case PosVerificationDialogType: |
|
128 { |
|
129 CustomDocumentLoader loader; |
|
130 bool ok = false; |
|
131 loader.load(POSVERFICATIONDIALOG_DOCML, &ok); |
|
132 Q_ASSERT_X(ok, "PosVerificationCustomDialog", |
|
133 "invalid DocML file"); |
|
134 |
|
135 if (ok) |
|
136 { |
|
137 dialog = qobject_cast<PosVerificationCustomDialog *> ( |
|
138 loader.findWidget("PosVerificationCustomDialog")); |
|
139 if (dialog) |
|
140 { |
|
141 dialog->getWidgets(loader); |
|
142 dialog->setDeviceDialogParameters(parameters); |
|
143 qDebug() << "createDeviceDialog(): success"; |
|
144 } |
|
145 else |
|
146 { |
|
147 qDebug() |
|
148 << "createDeviceDialog(): creation of device dialog failed"; |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 qDebug() << "createDeviceDialog(): loading docml failed"; |
|
154 } |
|
155 break; |
|
156 } |
|
157 default: |
|
158 { |
|
159 qDebug() << "createDeviceDialog(): default case"; |
|
160 Q_ASSERT(false); |
|
161 break; |
|
162 } |
|
163 } |
|
164 } |
|
165 else |
|
166 { |
|
167 qDebug() |
|
168 << "createDeviceDialog(): Dialog type not supported by this plugin"; |
|
169 } |
|
170 qDebug() << "-PosVerificationDialogPlugin::createDeviceDialog()"; |
|
171 return dialog; |
|
172 } |
|
173 |
|
174 //----------------------------------------------------------------------- |
|
175 // PosVerificationDialogPlugin::deviceDialogInfo |
|
176 // Return information of device dialog the plugin creates |
|
177 //----------------------------------------------------------------------- |
|
178 bool PosVerificationDialogPlugin::deviceDialogInfo( |
|
179 const QString &deviceDialogType, const QVariantMap ¶meters, |
|
180 DeviceDialogInfo *info) const |
|
181 { |
|
182 qDebug() << "+PosVerificationDialogPlugin::deviceDialogInfo()"; |
|
183 Q_UNUSED(parameters) |
|
184 Q_UNUSED(deviceDialogType) |
|
185 |
|
186 info->group = GenericDeviceDialogGroup; |
|
187 info->flags = NoDeviceDialogFlags; |
|
188 info->priority = DefaultPriority; |
|
189 qDebug() << "-PosVerificationDialogPlugin::deviceDialogInfo()"; |
|
190 return true; |
|
191 } |
|
192 |
|
193 //----------------------------------------------------------------------- |
|
194 // PosVerificationDialogPlugin::deviceDialogTypes |
|
195 // Return device dialog types this plugin implements |
|
196 //----------------------------------------------------------------------- |
|
197 QStringList PosVerificationDialogPlugin::deviceDialogTypes() const |
|
198 { |
|
199 qDebug() << "+PosVerificationDialogPlugin::deviceDialogTypes()"; |
|
200 QStringList types; |
|
201 const int numTypes = sizeof(verdlgtypes) / sizeof(verdlgtypes[0]); |
|
202 for (int i = 0; i < numTypes; i++) |
|
203 { |
|
204 types.append(verdlgtypes[i].mTypeString); |
|
205 } |
|
206 qDebug() << "-PosVerificationDialogPlugin::deviceDialogTypes()"; |
|
207 return types; |
|
208 } |
|
209 |
|
210 //----------------------------------------------------------------------- |
|
211 // PosVerificationDialogPlugin::pluginFlags |
|
212 // Return plugin flags |
|
213 //----------------------------------------------------------------------- |
|
214 HbDeviceDialogPlugin::PluginFlags PosVerificationDialogPlugin::pluginFlags() const |
|
215 { |
|
216 qDebug() << "PosVerificationDialogPlugin::pluginFlags()"; |
|
217 return NoPluginFlags; |
|
218 } |
|
219 |
|
220 //----------------------------------------------------------------------- |
|
221 // PosVerificationDialogPlugin::error |
|
222 // Return last error |
|
223 //----------------------------------------------------------------------- |
|
224 int PosVerificationDialogPlugin::error() const |
|
225 { |
|
226 qDebug() << "PosVerificationDialogPlugin::error()"; |
|
227 return 0; |
|
228 } |
|
229 |
|
230 //----------------------------------------------------------------------- |
|
231 // PosVerificationDialogPlugin::installTranslator |
|
232 // loads the qt message file and installs the translator |
|
233 //----------------------------------------------------------------------- |
|
234 void PosVerificationDialogPlugin::installTranslator() |
|
235 { |
|
236 if (!mTranslator) |
|
237 { |
|
238 mTranslator = new QTranslator(); |
|
239 } |
|
240 else |
|
241 { |
|
242 return; |
|
243 } |
|
244 QString lang = QLocale::system().name(); |
|
245 QString path = "z:/resource/qt/translations/"; |
|
246 QString altpath = "c://resource/"; |
|
247 bool loaded = false; |
|
248 loaded = mTranslator->load(path + QString("lilocationmw_") + lang); |
|
249 if (loaded == false) |
|
250 { |
|
251 loaded = mTranslator->load(altpath + QString("lilocationmw_") + lang); |
|
252 } |
|
253 if (loaded) |
|
254 { |
|
255 qApp->installTranslator(mTranslator); |
|
256 } |
|
257 } |
|
258 |
|
259 Q_EXPORT_PLUGIN2(posverificationdialogplugin, PosVerificationDialogPlugin) |
|
260 |