|
1 /* |
|
2 * Copyright (c) 2009 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: BtDeviceDialogWidget class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "btdevicedialoginputwidget.h" |
|
20 #include "btdevicedialogplugintrace.h" |
|
21 #include <bluetoothdevicedialogs.h> |
|
22 #include <hbaction.h> |
|
23 #include <hbdialog.h> |
|
24 #include "btdevicedialogpluginerrors.h" |
|
25 |
|
26 /*! |
|
27 class Constructor |
|
28 */ |
|
29 BtDeviceDialogInputWidget::BtDeviceDialogInputWidget( |
|
30 const QVariantMap ¶meters) |
|
31 { |
|
32 TRACE_ENTRY |
|
33 // set properties |
|
34 mLastError = NoError; |
|
35 mShowEventReceived = false; |
|
36 mInputDialog = new HbInputDialog(); |
|
37 |
|
38 resetProperties(); |
|
39 constructInputDialog(parameters); |
|
40 TRACE_EXIT |
|
41 } |
|
42 |
|
43 /*! |
|
44 Set parameters, implementation of interface |
|
45 Invoked when HbDeviceDialog::update calls. |
|
46 */ |
|
47 bool BtDeviceDialogInputWidget::setDeviceDialogParameters( |
|
48 const QVariantMap ¶meters) |
|
49 { |
|
50 TRACE_ENTRY |
|
51 mLastError = NoError; |
|
52 processParam(parameters); |
|
53 TRACE_EXIT |
|
54 return true; |
|
55 } |
|
56 |
|
57 /*! |
|
58 Get error, implementation of interface |
|
59 */ |
|
60 int BtDeviceDialogInputWidget::deviceDialogError() const |
|
61 { |
|
62 TRACE_ENTRY |
|
63 TRACE_EXIT |
|
64 return mLastError; |
|
65 } |
|
66 |
|
67 /*! |
|
68 Close notification, implementation of interface |
|
69 */ |
|
70 void BtDeviceDialogInputWidget::closeDeviceDialog(bool byClient) |
|
71 { |
|
72 TRACE_ENTRY |
|
73 Q_UNUSED(byClient); |
|
74 // Closed by client or internally by server -> no action to be transmitted. |
|
75 mSendAction = false; |
|
76 mInputDialog->close(); |
|
77 // If show event has been received, close is signalled from hide event. If not, |
|
78 // hide event does not come and close is signalled from here. |
|
79 if (!mShowEventReceived) { |
|
80 emit deviceDialogClosed(); |
|
81 } |
|
82 TRACE_EXIT |
|
83 } |
|
84 |
|
85 /*! |
|
86 Return display widget, implementation of interface |
|
87 */ |
|
88 HbDialog *BtDeviceDialogInputWidget::deviceDialogWidget() const |
|
89 { |
|
90 TRACE_ENTRY |
|
91 TRACE_EXIT |
|
92 return mInputDialog; |
|
93 } |
|
94 |
|
95 QObject *BtDeviceDialogInputWidget::signalSender() const |
|
96 { |
|
97 return const_cast<BtDeviceDialogInputWidget*>(this); |
|
98 } |
|
99 |
|
100 /*! |
|
101 Construct display widget |
|
102 */ |
|
103 bool BtDeviceDialogInputWidget::constructInputDialog(const QVariantMap ¶meters) |
|
104 { |
|
105 TRACE_ENTRY |
|
106 // analyze the parameters to compose the properties of the widget |
|
107 processParam(parameters); |
|
108 connect(mInputDialog, SIGNAL(finished(HbAction*)), this, SLOT(inputClosed(HbAction*))); |
|
109 |
|
110 TRACE_EXIT |
|
111 return true; |
|
112 } |
|
113 |
|
114 /*! |
|
115 Take parameter values and generate relevant property of this widget |
|
116 */ |
|
117 void BtDeviceDialogInputWidget::processParam(const QVariantMap ¶meters) |
|
118 { |
|
119 TRACE_ENTRY |
|
120 |
|
121 QString keyStr, prompt; |
|
122 keyStr.setNum( TBluetoothDialogParams::EResource ); |
|
123 // Validate if the resource item exists. |
|
124 QVariantMap::const_iterator i = parameters.constFind( keyStr ); |
|
125 // item of ResourceId is not found, can't continue. |
|
126 if ( i == parameters.constEnd() ) { |
|
127 mLastError = UnknownDeviceDialogError; |
|
128 return; |
|
129 } |
|
130 |
|
131 QVariant param = parameters.value( keyStr ); |
|
132 if ( param.toInt() == EPinInput ) { |
|
133 prompt = QString( tr( "Passcode for device %1:" ) ); |
|
134 } |
|
135 else { |
|
136 mLastError = ParameterError; |
|
137 return; |
|
138 } |
|
139 |
|
140 // check if minLength of passcode required |
|
141 keyStr.setNum( TBluetoothDeviceDialog::EAdditionalDesc ); |
|
142 i = parameters.constFind( keyStr ); |
|
143 // Mini Length required, update prompt |
|
144 // ToDo: use Validator to check input length. |
|
145 if ( i != parameters.constEnd() ) { |
|
146 prompt = QString( tr( "Enter %1 digit passcode for device %2:" ) ); |
|
147 param = parameters.value( keyStr ); |
|
148 } |
|
149 |
|
150 // replace % with the miniLength and device name |
|
151 int repls = prompt.count( QString( "%" ) ); |
|
152 if ( repls > 1 ) { |
|
153 prompt = prompt.arg( param.toString() ); |
|
154 } |
|
155 if ( repls > 0 ) { |
|
156 QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) ); |
|
157 prompt = prompt.arg( name.toString() ); |
|
158 } |
|
159 // set property value to this dialog widget |
|
160 mInputDialog->setPromptText( prompt ); |
|
161 TRACE_EXIT |
|
162 } |
|
163 |
|
164 /*! |
|
165 Reset properties to default values |
|
166 */ |
|
167 void BtDeviceDialogInputWidget::resetProperties() |
|
168 { |
|
169 TRACE_ENTRY |
|
170 // set to default values |
|
171 mInputDialog->setModal(true); |
|
172 mInputDialog->setTimeout(HbDialog::NoTimeout); |
|
173 mInputDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
174 mSendAction = true; |
|
175 // Todo: clean the Validator |
|
176 TRACE_EXIT |
|
177 return; |
|
178 } |
|
179 |
|
180 void BtDeviceDialogInputWidget::inputClosed(HbAction *action) |
|
181 { |
|
182 QVariantMap data; |
|
183 |
|
184 HbInputDialog *dlg=static_cast<HbInputDialog*>(sender()); |
|
185 if(dlg->actions().first() == action) { |
|
186 //Ok |
|
187 QVariant result( dlg->value().toString().toUtf8() ); |
|
188 data.insert( QString( "result" ), QVariant(true)); |
|
189 data.insert( QString( "input" ), result ); |
|
190 } |
|
191 else if(dlg->actions().at(1) == action) { |
|
192 //Cancel |
|
193 data.insert( QString( "result" ), QVariant(false)); |
|
194 } |
|
195 |
|
196 emit deviceDialogData(data); |
|
197 emit deviceDialogClosed(); |
|
198 mSendAction = false; |
|
199 } |
|
200 |
|
201 |