61
|
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:
|
|
15 |
*
|
|
16 |
***************************************************************************/
|
|
17 |
|
|
18 |
#include <hbaction.h>
|
|
19 |
#include <hbdialog.h>
|
|
20 |
#include <hbinputdialog.h>
|
|
21 |
#include<hblineedit.h>
|
|
22 |
#include <hbiconanimationmanager.h>
|
|
23 |
#include "hbdeviceinputdialogwidget_p.h"
|
|
24 |
#include "hbdeviceinputdialogpluginerrors_p.h"
|
|
25 |
|
|
26 |
//For Localization
|
|
27 |
QString LOCALE_PATH("/resource/qt/translations/");
|
|
28 |
QString TS_FILE("filemanager");
|
|
29 |
|
|
30 |
// Constructor
|
|
31 |
HbDeviceInputDialogWidget::HbDeviceInputDialogWidget(const QVariantMap ¶meters):HbInputDialog()
|
|
32 |
{
|
|
33 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::Constructor:Begin") ) );
|
|
34 |
mLastError = NoError;
|
|
35 |
mShowEventReceived = false;
|
|
36 |
mPrimaryAction = 0;
|
|
37 |
mSecondaryAction = 0;
|
|
38 |
mDeviceDialogError =0;
|
|
39 |
mHack = 1;
|
|
40 |
//resetProperties();
|
|
41 |
if (preConstructDialog())
|
|
42 |
{
|
|
43 |
//Translator loaded succesfully then olny construct widgets
|
|
44 |
constructDialog(parameters);
|
|
45 |
if (!mPrimaryAction) {
|
|
46 |
// If default button provided by HbInputDialog is used, connect into its triggered signal.
|
|
47 |
QAction *action = /*primaryAction()*/this->actions().first();
|
|
48 |
if (action) {
|
|
49 |
connect(action, SIGNAL(triggered()), SLOT(primaryActionTriggered()));
|
|
50 |
}
|
|
51 |
}
|
|
52 |
if (!mSecondaryAction) {
|
|
53 |
// If default button provided by HbInputDialog is used, connect into its triggered signal.
|
|
54 |
QAction *action = /*secondaryAction()*/ this->actions().at(1);
|
|
55 |
if (action) {
|
|
56 |
connect(action, SIGNAL(triggered()), SLOT(secondaryActionTriggered()));
|
|
57 |
}
|
|
58 |
}
|
|
59 |
connect(this, SIGNAL(visibilityChanged()), SLOT(closeDialog()));
|
|
60 |
}
|
|
61 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::Constructor:End") ) );
|
|
62 |
}
|
|
63 |
|
|
64 |
// Destructor
|
|
65 |
HbDeviceInputDialogWidget::~HbDeviceInputDialogWidget()
|
|
66 |
{
|
|
67 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::Destrcuctor:Begin") ) );
|
|
68 |
delete mPrimaryAction;
|
|
69 |
delete mSecondaryAction;
|
|
70 |
delete mHbTranslator;
|
|
71 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::Destructor:End") ) );
|
|
72 |
}
|
|
73 |
|
|
74 |
// Set parameters
|
|
75 |
bool HbDeviceInputDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters)
|
|
76 |
{
|
|
77 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setDeviceDialogParameters:Begin") ) );
|
|
78 |
mLastError = NoError;
|
|
79 |
bool ret(false);
|
|
80 |
if (checkProperties(parameters)) {
|
|
81 |
setProperties(parameters);
|
|
82 |
ret = true;
|
|
83 |
}
|
|
84 |
else {
|
|
85 |
mLastError = ParameterError;
|
|
86 |
ret = false;
|
|
87 |
}
|
|
88 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setDeviceDialogParameters:End") ) );
|
|
89 |
return ret;
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Before creating widgets Translator must be loaded
|
|
94 |
*/
|
|
95 |
bool HbDeviceInputDialogWidget::preConstructDialog()
|
|
96 |
{
|
|
97 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::preConstructDialog:Begin") ) );
|
|
98 |
//Translator
|
|
99 |
mHbTranslator = new HbTranslator(LOCALE_PATH,TS_FILE);
|
|
100 |
if(!mHbTranslator)
|
|
101 |
{
|
|
102 |
//Translator is failed to create
|
|
103 |
mDeviceDialogError = UnknownDeviceDialogError;
|
|
104 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::preConstructDialog:MemoryAllocation Failed") ) );
|
|
105 |
return false;
|
|
106 |
}
|
|
107 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::preConstructDialog:End") ) );
|
|
108 |
return true;
|
|
109 |
}
|
|
110 |
|
|
111 |
// Get error
|
|
112 |
int HbDeviceInputDialogWidget::deviceDialogError() const
|
|
113 |
{
|
|
114 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::deviceDialogError:Begin") ) );
|
|
115 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::deviceDialogError:End") ) );
|
|
116 |
return mLastError;
|
|
117 |
}
|
|
118 |
|
|
119 |
// Close device dialog
|
|
120 |
void HbDeviceInputDialogWidget::closeDeviceDialog(bool byClient)
|
|
121 |
{
|
|
122 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::closeDeviceDialog:Begin") ) );
|
|
123 |
Q_UNUSED(byClient);
|
|
124 |
// Closed by client or internally by server -> no action to be transmitted.
|
|
125 |
mSendAction = false;
|
|
126 |
close();
|
|
127 |
// If show event has been received, close is signalled from hide event. If not,
|
|
128 |
// hide event does not come and close is signalled from here.
|
|
129 |
if (!mShowEventReceived) {
|
|
130 |
emit deviceDialogClosed();
|
|
131 |
}
|
|
132 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::closeDeviceDialog:End") ) );
|
|
133 |
}
|
|
134 |
|
|
135 |
// Return display widget
|
|
136 |
HbDialog *HbDeviceInputDialogWidget::deviceDialogWidget() const
|
|
137 |
{
|
|
138 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::deviceDialogWidget:Begin") ) );
|
|
139 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::deviceDialogWidget:End") ) );
|
|
140 |
return const_cast<HbDeviceInputDialogWidget*>(this);
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
// Construct dialog
|
|
145 |
bool HbDeviceInputDialogWidget::constructDialog(const QVariantMap ¶meters)
|
|
146 |
{
|
|
147 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::constructDialog:Begin") ) );
|
|
148 |
bool ret(false);
|
|
149 |
// Check that parameters are valid
|
|
150 |
|
|
151 |
if (!checkProperties(parameters)) {
|
|
152 |
mLastError = ParameterError;
|
|
153 |
ret = false;
|
|
154 |
}
|
|
155 |
else {
|
|
156 |
setProperties(parameters);
|
|
157 |
resetProperties();
|
|
158 |
ret = true;
|
|
159 |
}
|
|
160 |
|
|
161 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::constructDialog:End") ) );
|
|
162 |
return ret;
|
|
163 |
}
|
|
164 |
|
|
165 |
// Check that device dialog parameters are valid
|
|
166 |
bool HbDeviceInputDialogWidget::checkProperties(const QVariantMap ¶meters)
|
|
167 |
{
|
|
168 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::checkProperties:Begin") ) );
|
|
169 |
QVariantMap::const_iterator i = parameters.constBegin();
|
|
170 |
while (i != parameters.constEnd()) {
|
|
171 |
QByteArray key = i.key().toAscii();
|
|
172 |
if (!property(key.constData()).isValid()) {
|
|
173 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::checkProperties:End :: returning false") ) );
|
|
174 |
return false;
|
|
175 |
}
|
|
176 |
++i;
|
|
177 |
}
|
|
178 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::checkProperties:End :: returning true") ) );
|
|
179 |
return true;
|
|
180 |
}
|
|
181 |
|
|
182 |
// Set properties
|
|
183 |
void HbDeviceInputDialogWidget::setProperties(const QVariantMap ¶meters)
|
|
184 |
{
|
|
185 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setProperties:Begin") ) );
|
|
186 |
QVariantMap::const_iterator i = parameters.constBegin();
|
|
187 |
while (i != parameters.constEnd()) {
|
|
188 |
QByteArray key = i.key().toAscii();
|
|
189 |
if (property(key.constData()).isValid()) {
|
|
190 |
setProperty(key.constData(), i.value());
|
|
191 |
}
|
|
192 |
++i;
|
|
193 |
}
|
|
194 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setProperties:End") ) );
|
|
195 |
return;
|
|
196 |
}
|
|
197 |
|
|
198 |
// Reset properties to default values
|
|
199 |
void HbDeviceInputDialogWidget::resetProperties()
|
|
200 |
{
|
|
201 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::resetProperties:Begin") ) );
|
|
202 |
// mIconName.clear();
|
|
203 |
setModal(true);
|
|
204 |
setPromptText(hbTrId("txt_common_dialog_password"), 0);
|
|
205 |
setInputMode(TextInput,0);
|
|
206 |
setEchoMode(HbLineEdit::Password,0);
|
|
207 |
setTimeout(HbPopup::NoTimeout);
|
|
208 |
setDismissPolicy(HbPopup::NoDismiss);
|
|
209 |
|
|
210 |
mPrimaryActionNull = false;
|
|
211 |
mSecondaryActionNull = false;
|
|
212 |
mSendAction = true;
|
|
213 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::resetProperties:End") ) );
|
|
214 |
return;
|
|
215 |
}
|
|
216 |
|
|
217 |
QString HbDeviceInputDialogWidget::primaryActionText() const
|
|
218 |
{
|
|
219 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::primaryActionText:Begin") ) );
|
|
220 |
QAction *action = /*primaryAction()*/this->actions().first();
|
|
221 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::primaryActionText:End") ) );
|
|
222 |
return action ? action->text() : QString();
|
|
223 |
}
|
|
224 |
|
|
225 |
void HbDeviceInputDialogWidget::setPrimaryActionText(QString &actionText)
|
|
226 |
{
|
|
227 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setPrimaryActionText:Begin") ) );
|
|
228 |
QAction *action = /*primaryAction()*/this->actions().first();
|
|
229 |
if (action) {
|
|
230 |
action->setText(actionText);
|
|
231 |
} else {
|
|
232 |
if (!mPrimaryAction) {
|
|
233 |
mPrimaryAction = new HbAction(actionText);
|
|
234 |
connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(primaryActionTriggered()));
|
|
235 |
} else {
|
|
236 |
mPrimaryAction->setText(actionText);
|
|
237 |
}
|
|
238 |
setPrimaryAction(mPrimaryAction);
|
|
239 |
}
|
|
240 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setPrimaryActionText:End") ) );
|
|
241 |
}
|
|
242 |
|
|
243 |
QString HbDeviceInputDialogWidget::secondaryActionText() const
|
|
244 |
{
|
|
245 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::secondaryActionText:Begin") ) );
|
|
246 |
QAction *action = /*secondaryAction()*/ this->actions().at(1);
|
|
247 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::secondaryActionText:End") ) );
|
|
248 |
return action ? action->text() : QString();
|
|
249 |
|
|
250 |
}
|
|
251 |
|
|
252 |
void HbDeviceInputDialogWidget::setSecondaryActionText(QString &actionText)
|
|
253 |
{
|
|
254 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setSecondaryActionText:Begin") ) );
|
|
255 |
QAction *action = /*secondaryAction()*/ this->actions().at(1);
|
|
256 |
if (action) {
|
|
257 |
action->setText(actionText);
|
|
258 |
} else {
|
|
259 |
if (!mSecondaryAction) {
|
|
260 |
mSecondaryAction = new HbAction(actionText);
|
|
261 |
connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(secondaryActionTriggered()));
|
|
262 |
} else {
|
|
263 |
mSecondaryAction->setText(actionText);
|
|
264 |
}
|
|
265 |
setSecondaryAction(mSecondaryAction);
|
|
266 |
}
|
|
267 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setSecondaryActionText:End") ) );
|
|
268 |
}
|
|
269 |
|
|
270 |
bool HbDeviceInputDialogWidget::primaryActionNull() const
|
|
271 |
{
|
|
272 |
return this->actions().first() == 0;
|
|
273 |
}
|
|
274 |
|
|
275 |
void HbDeviceInputDialogWidget::setPrimaryActionNull(bool isNull)
|
|
276 |
{
|
|
277 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setPrimaryActionNull:Begin") ) );
|
|
278 |
if (isNull) {
|
|
279 |
// If there is a message box's default action, disconnect from it.
|
|
280 |
QAction *action = /*primaryAction()*/this->actions().first();
|
|
281 |
if (action && mPrimaryAction == 0) {
|
|
282 |
action->disconnect(SIGNAL(triggered()), this, SLOT(primaryActionTriggered()));
|
|
283 |
}
|
|
284 |
setPrimaryAction(0);
|
|
285 |
} else {
|
|
286 |
QString text = mPrimaryAction ? mPrimaryAction->text() : QString();
|
|
287 |
setPrimaryActionText(text);
|
|
288 |
}
|
|
289 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setPrimaryActionNull:End") ) );
|
|
290 |
}
|
|
291 |
|
|
292 |
bool HbDeviceInputDialogWidget::secondaryActionNull() const
|
|
293 |
{
|
|
294 |
return this->actions().at(1) == 0;
|
|
295 |
}
|
|
296 |
|
|
297 |
void HbDeviceInputDialogWidget::setSecondaryActionNull(bool isNull)
|
|
298 |
{
|
|
299 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setSecondaryActionNull:Begin") ) );
|
|
300 |
if (isNull) {
|
|
301 |
// If there is a message box's default action, disconnect from it.
|
|
302 |
QAction *action = /*secondaryAction()*/ this->actions().at(1);
|
|
303 |
if (action && mSecondaryAction == 0) {
|
|
304 |
action->disconnect(SIGNAL(triggered()), this, SLOT(secondaryActionTriggered()));
|
|
305 |
}
|
|
306 |
setSecondaryAction(0);
|
|
307 |
} else {
|
|
308 |
QString text = mSecondaryAction ? mSecondaryAction->text() : QString();
|
|
309 |
setSecondaryActionText(text);
|
|
310 |
}
|
|
311 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::setSecondaryActionNull:End") ) );
|
|
312 |
}
|
|
313 |
|
|
314 |
// Widget is about to hide. Closing effect has ended.
|
|
315 |
void HbDeviceInputDialogWidget::hideEvent(QHideEvent *event)
|
|
316 |
{
|
|
317 |
Q_UNUSED(event);
|
|
318 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::hideEvent:Begin") ) );
|
|
319 |
HbInputDialog::hideEvent(event);
|
|
320 |
emit deviceDialogClosed();
|
|
321 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::hideEvent:End") ) );
|
|
322 |
}
|
|
323 |
|
|
324 |
// Widget is about to show
|
|
325 |
void HbDeviceInputDialogWidget::showEvent(QShowEvent *event)
|
|
326 |
{
|
|
327 |
Q_UNUSED(event);
|
|
328 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::showEvent:Begin") ) );
|
|
329 |
HbInputDialog::showEvent(event);
|
|
330 |
mShowEventReceived = true;
|
|
331 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::showEvent:End") ) );
|
|
332 |
}
|
|
333 |
|
|
334 |
void HbDeviceInputDialogWidget::setAnimationDefinition(QString &animationDefinition)
|
|
335 |
{
|
|
336 |
mAnimationDefinition = animationDefinition;
|
|
337 |
}
|
|
338 |
|
|
339 |
QString HbDeviceInputDialogWidget::animationDefinition() const
|
|
340 |
{
|
|
341 |
return mAnimationDefinition;
|
|
342 |
}
|
|
343 |
|
|
344 |
// Primary action triggered
|
|
345 |
void HbDeviceInputDialogWidget::primaryActionTriggered()
|
|
346 |
{
|
|
347 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::primaryActionTriggered:Begin") ) );
|
|
348 |
//Get the string enter by user
|
|
349 |
QString myString = this->value().toString();
|
|
350 |
data.insert("ok",myString);
|
|
351 |
emit deviceDialogData(data);
|
|
352 |
mSendAction = true;
|
|
353 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::primaryActionTriggered:End") ) );
|
|
354 |
}
|
|
355 |
|
|
356 |
// Secondary action triggered
|
|
357 |
void HbDeviceInputDialogWidget::secondaryActionTriggered()
|
|
358 |
{
|
|
359 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::secondaryActionTriggered:Begin") ) );
|
|
360 |
data.insert("cancel","cancel");
|
|
361 |
emit deviceDialogData(data);
|
|
362 |
mSendAction = false;
|
|
363 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::secondaryActionTriggered:End") ) );
|
|
364 |
}
|
|
365 |
|
|
366 |
|
|
367 |
// Close Dialog when visibility changed
|
|
368 |
void HbDeviceInputDialogWidget::closeDialog()
|
|
369 |
{
|
|
370 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::closeDialog:Begin") ) );
|
|
371 |
if(mHack == 1)
|
|
372 |
{
|
|
373 |
emit deviceDialogData(data); // first time plugin didnt called deviceDialogData and hence this hack added.
|
|
374 |
}
|
|
375 |
emit deviceDialogClosed();
|
|
376 |
TRACES( RDebug::Print( _L("HbDeviceInputDialogWidget::closeDialog:End") ) );
|
|
377 |
mHack = 0;
|
|
378 |
}
|