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 "btdevicedialogquerywidget.h" |
|
20 #include "btdevicedialogplugintrace.h" |
|
21 #include <bluetoothdevicedialogs.h> |
|
22 #include <hbaction.h> |
|
23 #include <hbdialog.h> |
|
24 #include <hblabel.h> |
|
25 #include "btdevicedialogpluginerrors.h" |
|
26 |
|
27 /*! |
|
28 class Constructor |
|
29 */ |
|
30 BtDeviceDialogQueryWidget::BtDeviceDialogQueryWidget( |
|
31 HbMessageBox::MessageBoxType type, const QVariantMap ¶meters) |
|
32 { |
|
33 TRACE_ENTRY |
|
34 // set properties |
|
35 mLastError = NoError; |
|
36 mShowEventReceived = false; |
|
37 mMessageBox = new HbMessageBox(type); |
|
38 resetProperties(); |
|
39 constructQueryDialog(parameters); |
|
40 TRACE_EXIT |
|
41 } |
|
42 |
|
43 /*! |
|
44 Set parameters, implementation of interface |
|
45 Invoked when HbDeviceDialog::update calls. |
|
46 */ |
|
47 bool BtDeviceDialogQueryWidget::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 BtDeviceDialogQueryWidget::deviceDialogError() const |
|
61 { |
|
62 TRACE_ENTRY |
|
63 TRACE_EXIT |
|
64 return mLastError; |
|
65 } |
|
66 |
|
67 /*! |
|
68 Close notification, implementation of interface |
|
69 */ |
|
70 void BtDeviceDialogQueryWidget::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 mMessageBox->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 *BtDeviceDialogQueryWidget::deviceDialogWidget() const |
|
89 { |
|
90 TRACE_ENTRY |
|
91 TRACE_EXIT |
|
92 return mMessageBox; |
|
93 } |
|
94 |
|
95 QObject *BtDeviceDialogQueryWidget::signalSender() const |
|
96 { |
|
97 return const_cast<BtDeviceDialogQueryWidget*>(this); |
|
98 } |
|
99 |
|
100 /*! |
|
101 Construct display widget |
|
102 */ |
|
103 bool BtDeviceDialogQueryWidget::constructQueryDialog(const QVariantMap ¶meters) |
|
104 { |
|
105 TRACE_ENTRY |
|
106 // analyze the parameters to compose the properties of the message box widget |
|
107 processParam(parameters); |
|
108 |
|
109 connect(mMessageBox, SIGNAL(finished(HbAction*)), this, SLOT(messageBoxClosed(HbAction*))); |
|
110 |
|
111 TRACE_EXIT |
|
112 return true; |
|
113 } |
|
114 |
|
115 /*! |
|
116 Take parameter values and generate relevant property of this widget |
|
117 */ |
|
118 void BtDeviceDialogQueryWidget::processParam(const QVariantMap ¶meters) |
|
119 { |
|
120 TRACE_ENTRY |
|
121 QString keyStr, prompt,title; |
|
122 QVariant name,param,addval; |
|
123 keyStr.setNum( TBluetoothDialogParams::EResource ); |
|
124 // Validate if the resource item exists. |
|
125 QVariantMap::const_iterator i = parameters.constFind( keyStr ); |
|
126 // item of ResourceId is not found, can't continue. |
|
127 if ( i == parameters.constEnd() ) { |
|
128 mLastError = UnknownDeviceDialogError; |
|
129 return; |
|
130 } |
|
131 |
|
132 param = parameters.value( keyStr ); |
|
133 int key = param.toInt(); |
|
134 switch ( key ) { |
|
135 case ENumericComparison: |
|
136 prompt = QString( hbTrId( "txt_bt_info_does_this_code_match_the_code_on_1" ) ); |
|
137 break; |
|
138 case EPasskeyDisplay: |
|
139 prompt = QString( hbTrId( "txt_bt_info_enter_the_following_code_to_the_1" ) ); |
|
140 break; |
|
141 case EPairingFailureRetry: |
|
142 prompt = QString( hbTrId( "txt_bt_info_pairing_with_1_failed_either_the_pas" ) ); |
|
143 break; |
|
144 case EPairingFailureOk: |
|
145 prompt = QString( hbTrId( "txt_bt_info_unable_to_pair_with_1" ) ); |
|
146 break; |
|
147 // Input dialogs |
|
148 case EPinInput: |
|
149 case EObexPasskeyInput: |
|
150 // NULL parameters |
|
151 case ENoResource: |
|
152 case EUnusedResource: |
|
153 default: |
|
154 mLastError = ParameterError; |
|
155 break; |
|
156 } |
|
157 int repls = prompt.count( QString( "%" ) ); |
|
158 if ( repls > 0 ) { |
|
159 name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) ); |
|
160 prompt = prompt.arg( name.toString() ); |
|
161 if(key != EPairingFailureRetry && key != EPairingFailureOk) |
|
162 { |
|
163 addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) ); |
|
164 // todo: Formating the prompt need to be discussed with UI designer |
|
165 // The passcode could be displayed on a separate row if it the label did support |
|
166 // the use of newline escape character. |
|
167 prompt.append(tr("\n\n")); // insert 2 newlines for clarity |
|
168 prompt.append(addval.toString()); |
|
169 if(key == EPasskeyDisplay) |
|
170 { |
|
171 prompt.append("\n"); |
|
172 } |
|
173 } |
|
174 } |
|
175 // set property value to this dialog widget |
|
176 if(key != EPairingFailureRetry && key != EPairingFailureOk) |
|
177 { |
|
178 title = QString(hbTrId("txt_bt_title_pairing_with_1")); |
|
179 title = title.arg(name.toString()); |
|
180 mMessageBox->setHeadingWidget(new HbLabel(title)); |
|
181 mMessageBox->setIconVisible(false); |
|
182 mMessageBox->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No); |
|
183 } |
|
184 else |
|
185 { |
|
186 if(key == EPairingFailureRetry) |
|
187 { |
|
188 mMessageBox->setStandardButtons( HbMessageBox::Retry | HbMessageBox::Cancel); |
|
189 } |
|
190 else |
|
191 { |
|
192 mMessageBox->setStandardButtons( HbMessageBox::Ok); |
|
193 } |
|
194 } |
|
195 mMessageBox->setText( prompt ); |
|
196 TRACE_EXIT |
|
197 } |
|
198 |
|
199 /*! |
|
200 Reset properties to default values |
|
201 */ |
|
202 void BtDeviceDialogQueryWidget::resetProperties() |
|
203 { |
|
204 TRACE_ENTRY |
|
205 // set to default values |
|
206 mMessageBox->setModal(true); |
|
207 mMessageBox->setTimeout(HbDialog::NoTimeout); |
|
208 mMessageBox->setDismissPolicy(HbDialog::NoDismiss); |
|
209 mSendAction = true; |
|
210 TRACE_EXIT |
|
211 return; |
|
212 } |
|
213 |
|
214 |
|
215 void BtDeviceDialogQueryWidget::messageBoxClosed(HbAction* action) |
|
216 { |
|
217 QVariantMap data; |
|
218 |
|
219 HbMessageBox *dlg=static_cast<HbMessageBox*>(sender()); |
|
220 if(dlg->actions().first() == action) { |
|
221 //Yes |
|
222 data.insert( QString( "result" ), QVariant(true)); |
|
223 } |
|
224 else if(dlg->actions().at(1) == action) { |
|
225 //No |
|
226 data.insert( QString( "result" ), QVariant(false)); |
|
227 } |
|
228 |
|
229 emit deviceDialogData(data); |
|
230 emit deviceDialogClosed(); |
|
231 mSendAction = false; |
|
232 } |
|