|
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 * |
|
15 * Description: SecUi notification content widget. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "secuinotificationdebug.h" |
|
20 #include "secuinotificationcontentwidget.h" |
|
21 #include "secuinotificationdialogpluginkeys.h" |
|
22 #include <QGraphicsLinearLayout> |
|
23 #include <QToolButton> |
|
24 #include <hblabel.h> |
|
25 #include <hbpushbutton.h> |
|
26 #include <hbiconitem.h> |
|
27 #include <hbcombobox.h> |
|
28 #include <hblineedit.h> |
|
29 #include <hbinputeditorinterface.h> |
|
30 #include <QDebug> |
|
31 |
|
32 #include <HbCheckBox> // needed for a checkbox dialog |
|
33 #include <HbListWidget> // needed for multicheckbox dialog |
|
34 #include <HbListWidgetItem> |
|
35 #include <HbAbstractItemView> |
|
36 #include <HbEmailAddressFilter> |
|
37 |
|
38 #define ESecUiCancelSupported 0x1000000 |
|
39 #define ESecUiCancelNotSupported 0x0000000 |
|
40 |
|
41 #define ESecUiEmergencySupported 0x2000000 |
|
42 #define ESecUiEmergencyNotSupported 0x0000000 |
|
43 |
|
44 #define ESecUiAlphaSupported 0x4000000 |
|
45 #define ESecUiAlphaNotSupported 0x0000000 |
|
46 |
|
47 #define ESecUiSecretSupported 0x8000000 |
|
48 #define ESecUiSecretNotSupported 0x0000000 |
|
49 |
|
50 #define ESecUiMaskFlags 0xFF000000 |
|
51 #define ESecUiMaskType 0x00FFFFFF |
|
52 |
|
53 #define ESecUiTypeDeviceLock 0x00100000 |
|
54 #define ESecUiTypeKeyguard 0x00200000 |
|
55 #define ESecUiTypeClock 0x00300000 |
|
56 #define ESecUiTypeScreensaver 0x00400000 |
|
57 |
|
58 #define ESecUiTypeMaskLock 0x00F00000 |
|
59 |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // SecUiNotificationContentWidget::SecUiNotificationContentWidget() |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 SecUiNotificationContentWidget::SecUiNotificationContentWidget( |
|
66 QGraphicsItem *parent, Qt::WindowFlags flags) : HbWidget(parent, flags) |
|
67 { |
|
68 RDEBUG("0", 0); |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // SecUiNotificationContentWidget::~SecUiNotificationContentWidget() |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 SecUiNotificationContentWidget::~SecUiNotificationContentWidget() |
|
76 { |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // SecUiNotificationContentWidget::constructFromParameters() |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 void SecUiNotificationContentWidget::constructFromParameters(const QVariantMap ¶meters) |
|
84 { |
|
85 RDEBUG("0", 0); |
|
86 RDEBUGQT("parameters", parameters); |
|
87 QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
88 |
|
89 lMinLength = 4; // might be replaced later |
|
90 lMaxLength = 8; // might be replaced later |
|
91 queryDual=0; |
|
92 isEmergency=0; |
|
93 codeTop=0; |
|
94 |
|
95 // KApplicationSize |
|
96 if (parameters.contains(KQueryType)) { |
|
97 RDEBUG("0", 0); |
|
98 queryType = parameters.value(KQueryType).toUInt(); |
|
99 RDEBUG("queryType", queryType); |
|
100 if( (queryType & ESecUiTypeMaskLock) ) |
|
101 { |
|
102 RDEBUG("KQueryType=ESecUiTypeMaskLock", queryType); |
|
103 // showing "Lock" icon. All other params are irrelevant. codeTop is not even created |
|
104 |
|
105 HbLabel *iconLabel = new HbLabel("Locked"); |
|
106 HbIcon *icon = new HbIcon("qtg_large_device_lock"); |
|
107 // iconLabel->setAspectRatioMode(Qt::IgnoreAspectRatio); |
|
108 // iconLabel->setGeometry(QRectF(QPointF(10,10),QSizeF(300,300))); |
|
109 iconLabel->setIcon(*icon); |
|
110 if( (queryType & ESecUiTypeMaskLock)==ESecUiTypeDeviceLock ) |
|
111 { // really big icon for the devicelock |
|
112 iconLabel->setPreferredHeight(500); |
|
113 iconLabel->setPreferredWidth(500); |
|
114 } |
|
115 else if( (queryType & ESecUiTypeMaskLock)==ESecUiTypeKeyguard ) |
|
116 { // smaller icon for the keyguard |
|
117 iconLabel->setPreferredHeight(100); |
|
118 iconLabel->setPreferredWidth(100); |
|
119 } |
|
120 |
|
121 // icon->setWidth(300); |
|
122 // icon->setHeight(350); |
|
123 // icon->setGeometry(QRectF(QPointF(10,10),QSizeF(500,300))); |
|
124 // icon->setSize(QSizeF(300,300)); |
|
125 |
|
126 mainLayout->addItem(iconLabel); |
|
127 mainLayout->setAlignment(iconLabel, Qt::AlignCenter ); |
|
128 // mainLayout->setGeometry(QRectF(QPointF(10,10),QSizeF(300,300))); |
|
129 |
|
130 /* |
|
131 QToolButton* mLabelIcon = new QToolButton; |
|
132 mLabelIcon->setIcon(QIcon(":/AutolockSrv_hbicon/qtg_large_device_lock.svg")); |
|
133 mLabelIcon->setIconSize(QSize(300,300)); |
|
134 HbLabel *iconLabel = new HbLabel("Locked"); |
|
135 iconLabel->setIcon(*mLabelIcon); |
|
136 mainLayout->addItem(iconLabel); |
|
137 */ |
|
138 |
|
139 // mainLayout->setContentsMargins(10,10,300,500); // this makes the dialog really big |
|
140 setLayout(mainLayout); // same as at the end |
|
141 return; |
|
142 } |
|
143 // not ESecUiTypeMaskLock |
|
144 lEmergencySupported = ESecUiEmergencyNotSupported; |
|
145 if((queryType & ESecUiEmergencySupported)==ESecUiEmergencySupported) |
|
146 { |
|
147 lEmergencySupported = ESecUiEmergencySupported; |
|
148 } |
|
149 RDEBUG("lEmergencySupported", lEmergencySupported); |
|
150 } |
|
151 |
|
152 if (parameters.contains(KQueryMinLength)) { |
|
153 RDEBUG("KQueryMinLength", 0); |
|
154 lMinLength = parameters.value(KQueryMinLength).toUInt(); |
|
155 RDEBUG("lMinLength", lMinLength); |
|
156 } |
|
157 if (parameters.contains(KQueryMaxLength)) { |
|
158 RDEBUG("KQueryMaxLength", 0); |
|
159 lMaxLength = parameters.value(KQueryMaxLength).toUInt(); |
|
160 RDEBUG("lMaxLength", lMaxLength); |
|
161 } |
|
162 |
|
163 if (parameters.contains(KEmergency)) { |
|
164 RDEBUG("KEmergency", 0); |
|
165 QString emergencyText = parameters.value(KEmergency).toString(); |
|
166 RDEBUGQT("emergencyText", emergencyText); |
|
167 if(!emergencyText.compare("emergencyYes")) |
|
168 { |
|
169 RDEBUG("emergencyYes", 1); |
|
170 isEmergency = 1; |
|
171 } |
|
172 if(!emergencyText.compare("emergencyNo")) |
|
173 { |
|
174 RDEBUG("emergencyNo", 0); |
|
175 isEmergency = 0; |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 // KCodeTop |
|
181 if (parameters.contains(KCodeTop)) { |
|
182 RDEBUG("KCodeTop", 0); |
|
183 codeTop = new HbLineEdit(""); // no default value |
|
184 RDEBUG("queryType", queryType); |
|
185 codeTop->setInputMethodHints(Qt::ImhDigitsOnly); // default |
|
186 if (queryType & ESecUiAlphaSupported) |
|
187 { |
|
188 RDEBUG("ESecUiAlphaSupported", ESecUiAlphaSupported); |
|
189 codeTop->setInputMethodHints(Qt::ImhNone); |
|
190 } |
|
191 if (queryType & ESecUiSecretSupported) |
|
192 { |
|
193 RDEBUG("ESecUiSecretSupported", ESecUiSecretSupported); |
|
194 codeTop->setEchoMode(HbLineEdit::PasswordEchoOnEdit); |
|
195 } |
|
196 RDEBUG("lMaxLength", lMaxLength); |
|
197 if(lMaxLength>2) |
|
198 codeTop->setMaxLength(lMaxLength); |
|
199 |
|
200 if (parameters.contains(KDefaultCode)) { |
|
201 RDEBUG("KDefaultCode", 0); |
|
202 QString defaultCode = parameters.value(KDefaultCode).toString(); |
|
203 RDEBUGQT("defaultCode", defaultCode); |
|
204 codeTop->setText(defaultCode); |
|
205 } |
|
206 RDEBUG("1", 1); |
|
207 |
|
208 connect(codeTop, SIGNAL(textChanged(const QString &)), this, SIGNAL(codeTopChanged(const QString &))); |
|
209 connect(codeTop, SIGNAL(contentsChanged()), this, SIGNAL(codeTopContentChanged())); |
|
210 |
|
211 if (parameters.contains(KDefaultCode)) { // this is done in this step so that the OK becomes valid (if rules are fulfilled) |
|
212 RDEBUG("KDefaultCode", 0); |
|
213 QString defaultCode = parameters.value(KDefaultCode).toString(); |
|
214 RDEBUGQT("defaultCode", defaultCode); |
|
215 codeTop->setText(defaultCode); |
|
216 } |
|
217 RDEBUG("2", 2); |
|
218 |
|
219 if (parameters.contains(KDialogTitle)) { |
|
220 QString titleText = parameters.value(KDialogTitle).toString(); |
|
221 QString titleAttempts = ""; |
|
222 if(titleText.indexOf('|')>0) |
|
223 { // if separator, take only first part |
|
224 titleText = titleText.left(titleText.indexOf('|')); |
|
225 } |
|
226 if(titleText.indexOf('$')>0) |
|
227 { // if separator, take only first part |
|
228 // it comes translated alredy, from the client |
|
229 titleAttempts = titleText.right(titleText.length()-titleText.indexOf('$')-1); |
|
230 RDEBUGQT("titleAttempts", titleAttempts); |
|
231 int nAttempts = titleAttempts.toInt(); |
|
232 RDEBUG("nAttempts", nAttempts); |
|
233 titleText = titleText.left(titleText.indexOf('$')); // this comes translated already |
|
234 if(nAttempts==1) // last attempt |
|
235 { |
|
236 // This must be in a new line, to avoid problems with left-to-right writing |
|
237 titleAttempts = hbTrId("txt_pin_code_dpophead_last_attempt"); |
|
238 } |
|
239 else if(nAttempts>0) |
|
240 { |
|
241 titleAttempts = hbTrId("attempts") + "=" + QString::number(nAttempts); |
|
242 // TODO this requires %L1 localization using txt_pin_code_dpopinfo_ln_attempts_remaining |
|
243 } |
|
244 else if(nAttempts==0) |
|
245 { |
|
246 titleAttempts = ""; // something special for the last attempt ? |
|
247 } |
|
248 else |
|
249 { |
|
250 titleAttempts = ""; |
|
251 } |
|
252 } |
|
253 HbLabel *titleTop = new HbLabel(titleText); |
|
254 mainLayout->addItem(titleTop); |
|
255 if (titleAttempts.length()>0 ) |
|
256 { |
|
257 HbLabel *titleTopAttemps = new HbLabel(titleAttempts); |
|
258 mainLayout->addItem(titleTopAttemps); |
|
259 } |
|
260 // in the dialog, it was setHeadingWidget(title); |
|
261 } |
|
262 RDEBUG("3", 3); |
|
263 mainLayout->addItem(codeTop); |
|
264 // double-query |
|
265 if (parameters.contains(KCodeBottom)) |
|
266 { |
|
267 queryDual=1; |
|
268 QString titleText = parameters.value(KDialogTitle).toString(); |
|
269 if(titleText.indexOf('|')>0) |
|
270 { // if no separator, don't create label |
|
271 QString titleBottomStr = titleText.right(titleText.length()-titleText.indexOf('|')-1); |
|
272 // no need to translate |
|
273 HbLabel *titleBottom = new HbLabel(titleBottomStr); |
|
274 mainLayout->addItem(titleBottom); |
|
275 } |
|
276 |
|
277 codeBottom = new HbLineEdit(""); // no default value |
|
278 if(lMaxLength>2) |
|
279 codeBottom->setMaxLength(lMaxLength); |
|
280 codeBottom->setInputMethodHints(Qt::ImhDigitsOnly); // default |
|
281 if (queryType & ESecUiAlphaSupported) |
|
282 { |
|
283 RDEBUG("setInputMethodHints", 0); |
|
284 codeBottom->setInputMethodHints(Qt::ImhNone); |
|
285 } |
|
286 if (queryType & ESecUiSecretSupported) |
|
287 { |
|
288 RDEBUG("ESecUiSecretSupported", 0); |
|
289 codeBottom->setEchoMode(HbLineEdit::PasswordEchoOnEdit); // this will also remove predictive, which is what we want |
|
290 } |
|
291 RDEBUG("connecting", 0); |
|
292 connect(codeBottom, SIGNAL(textChanged(const QString &)), this, SIGNAL(codeBottomChanged(const QString &))); |
|
293 connect(codeBottom, SIGNAL(contentsChanged(const QString &)), this, SIGNAL(codeBottomChanged(const QString &))); |
|
294 mainLayout->addItem(codeBottom); |
|
295 } |
|
296 |
|
297 QGraphicsLinearLayout *mainLayoutButtons = new QGraphicsLinearLayout(Qt::Horizontal); |
|
298 HbPushButton *but1 = new HbPushButton("1234"); |
|
299 HbPushButton *but2 = new HbPushButton("+1"); |
|
300 HbPushButton *but3 = new HbPushButton("+5"); |
|
301 connect(but1, SIGNAL(clicked()), this, SIGNAL(but1Changed())); |
|
302 connect(but2, SIGNAL(clicked()), this, SIGNAL(but2Changed())); |
|
303 connect(but3, SIGNAL(clicked()), this, SIGNAL(but3Changed())); |
|
304 #if defined(_DEBUG) |
|
305 mainLayoutButtons->addItem(but1); |
|
306 mainLayoutButtons->addItem(but2); |
|
307 mainLayoutButtons->addItem(but3); |
|
308 #endif |
|
309 |
|
310 mainLayout->addItem(mainLayoutButtons); |
|
311 |
|
312 // remove setFocus from PIN query because Orbit can't handle it |
|
313 // codeTop->setFocus(); // this should open the VKB |
|
314 |
|
315 } |
|
316 |
|
317 if (parameters.contains(KChecboxType)) { |
|
318 RDEBUG("KChecboxType", 0); |
|
319 if (parameters.contains(KDialogTitle)) { |
|
320 //TODO position of the label is not centered |
|
321 QString tmpText=parameters.value(KDialogTitle).toString(); |
|
322 if (tmpText.endsWith("\n")) tmpText=tmpText.left(tmpText.length()-1); |
|
323 DialogText= new HbLabel(tmpText); |
|
324 DialogText->setTextWrapping(Hb::TextWordWrap); |
|
325 DialogText->setAlignment(Qt::AlignVCenter); |
|
326 mainLayout->addItem(DialogText); |
|
327 } |
|
328 |
|
329 checkbox = new HbCheckBox("Caption"); |
|
330 if (parameters.contains(KDefaultCode)) { |
|
331 RDEBUG("KDefaultCode", 0); |
|
332 QStringList list1 = parameters.value(KDefaultCode).toString().split("|"); |
|
333 if (!list1.isEmpty() && list1.count()==2) { |
|
334 if (!list1[0].isNull() && !list1[0].isEmpty()) checkbox->setText(list1[0]); |
|
335 if (!list1[1].isNull() && !list1[1].isEmpty()) checkbox->setChecked(list1[1].toInt()); |
|
336 } |
|
337 // TODO this needs localization |
|
338 } |
|
339 mainLayout->addItem(checkbox); |
|
340 } |
|
341 |
|
342 if (parameters.contains(KMultiChecboxType) && parameters.contains(KDefaultCode)) |
|
343 { |
|
344 RDEBUG("KMultiChecboxType", 0); |
|
345 QStringList list1 = parameters.value(KDefaultCode).toString().split("1\t"); |
|
346 if (!list1.isEmpty()) { |
|
347 listWidget = new HbListWidget(); |
|
348 for (int i = 0; (i < list1.count()); i++) |
|
349 if (!list1[i].isEmpty() && !list1[i].isNull()) { |
|
350 HbListWidgetItem* modelItem = new HbListWidgetItem(); |
|
351 modelItem->setData(QVariant(list1[i]), Qt::DisplayRole); |
|
352 // TODO this needs localization |
|
353 listWidget->addItem(modelItem); |
|
354 } |
|
355 listWidget->setCurrentRow(0); |
|
356 listWidget->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
357 //listWidget->setClampingStyle(HbScrollArea::BounceBackClamping); |
|
358 listWidget->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
|
359 listWidget->setMaximumHeight(150); |
|
360 mainLayout->addItem(listWidget); |
|
361 // delete listWidget; |
|
362 } |
|
363 } |
|
364 |
|
365 setLayout(mainLayout); |
|
366 } |
|
367 |