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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "btdevicesearchdialogwidget.h" |
|
20 |
|
21 #include <hblistview.h> |
|
22 #include <hbtoolbar.h> |
|
23 |
|
24 |
|
25 #include <qstandarditemmodel.h> |
|
26 #include <hbaction.h> |
|
27 #include <xqconversions.h> |
|
28 #include <qtranslator.h> |
|
29 #include <qcoreapplication.h> |
|
30 #include <bluetoothdevicedialogs.h> |
|
31 #include <btuidevtypemap.h> |
|
32 #include <btuiiconutil.h> |
|
33 |
|
34 const char* DOCML_BTDEV_SEARCH_DIALOG = ":/docml/bt-device-search-dialog.docml"; |
|
35 |
|
36 |
|
37 #define LOC_SEARCHING_DEVICE hbTrId("txt_bt_subhead_searching") |
|
38 #define LOC_SEARCH_DONE hbTrId("txt_bt_subhead_search_done") |
|
39 #define LOC_SEARCH_STOP hbTrId("txt_common_button_stop") |
|
40 #define LOC_SEARCH_RETRY hbTrId("txt_common_button_retry") |
|
41 |
|
42 |
|
43 BTDeviceSearchDialogWidget::BTDeviceSearchDialogWidget(const QVariantMap ¶meters) |
|
44 { |
|
45 // mDeviceLstIdx = 0; |
|
46 // mViewByChosen = false; |
|
47 mSelectedDeviceType = 0; |
|
48 // mDeviceDialogData = 0; |
|
49 mLoader = 0; |
|
50 mContentItemModel = 0; |
|
51 mStopRetryFlag = 0; // Stop |
|
52 mQuery = 0; |
|
53 mSelectedDeviceType |= (BtuiDevProperty::AVDev | BtuiDevProperty::Computer | |
|
54 BtuiDevProperty::Phone | BtuiDevProperty::Peripheral | |
|
55 BtuiDevProperty::LANAccessDev | BtuiDevProperty::Toy | |
|
56 BtuiDevProperty::WearableDev | BtuiDevProperty::ImagingDev | |
|
57 BtuiDevProperty::HealthDev | BtuiDevProperty::UncategorizedDev); |
|
58 constructDialog(parameters); |
|
59 } |
|
60 |
|
61 BTDeviceSearchDialogWidget::~BTDeviceSearchDialogWidget() |
|
62 { |
|
63 delete mLoader; |
|
64 delete mContentItemModel; |
|
65 if ( mQuery ) { |
|
66 delete mQuery; |
|
67 } |
|
68 |
|
69 // delete mRbl; |
|
70 // delete mViewByDialog; |
|
71 } |
|
72 |
|
73 bool BTDeviceSearchDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
74 { |
|
75 if(parameters.keys().at(0).compare("Search Completed")==0) |
|
76 { |
|
77 mStopRetryFlag = 1; // Retry |
|
78 mSearchLabel->hide(); |
|
79 |
|
80 mSearchIconLabel->hide(); |
|
81 |
|
82 mSearchDoneLabel->show(); |
|
83 mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap); |
|
84 mSearchDoneLabel->setAlignment(Qt::AlignLeft); |
|
85 mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE); |
|
86 |
|
87 mStopRetryAction->setText(LOC_SEARCH_RETRY); |
|
88 } |
|
89 else |
|
90 { |
|
91 double cod = parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceClass)).toDouble(); |
|
92 int uiMajorDevice; |
|
93 int uiMinorDevice; |
|
94 |
|
95 BtuiDevProperty::mapDeiveType(uiMajorDevice, uiMinorDevice, cod); |
|
96 |
|
97 BtSendDataItem devData; |
|
98 devData[NameAliasRole] = QVariant(parameters.value(QString::number(TBluetoothDeviceDialog::EDeviceName)).toString()); |
|
99 devData[ReadableBdaddrRole] = QVariant(parameters.value(QString::number(TBluetoothDialogParams::EAddress)).toString()); |
|
100 devData[CoDRole] = QVariant(cod); |
|
101 devData[DeviceTypeRole] = QVariant(uiMajorDevice); |
|
102 setMajorProperty(devData,BtuiDevProperty::Bonded, |
|
103 parameters.value("Bonded").toBool()); |
|
104 setMajorProperty(devData,BtuiDevProperty::Blocked, |
|
105 parameters.value("Blocked").toBool()); |
|
106 setMajorProperty(devData,BtuiDevProperty::Trusted, |
|
107 parameters.value("Trusted").toBool()); |
|
108 setMajorProperty(devData,BtuiDevProperty::Connected, |
|
109 parameters.value("Connected").toBool()); |
|
110 mData.append(devData); |
|
111 |
|
112 if(mSelectedDeviceType & devData[DeviceTypeRole].toInt()) |
|
113 { |
|
114 QStandardItem* listitem = new QStandardItem(); |
|
115 QStringList info; |
|
116 info.append(devData[NameAliasRole].toString()); |
|
117 listitem->setData(info, Qt::DisplayRole); |
|
118 HbIcon icon = getBadgedDeviceTypeIcon(devData[CoDRole].toDouble(), |
|
119 devData[MajorPropertyRole].toInt(), |
|
120 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight); |
|
121 listitem->setIcon(icon.qicon()); |
|
122 mContentItemModel->appendRow(listitem); |
|
123 mSelectedData.append(devData); |
|
124 } |
|
125 } |
|
126 |
|
127 return true; |
|
128 } |
|
129 |
|
130 int BTDeviceSearchDialogWidget::deviceDialogError() const |
|
131 { |
|
132 return 0; |
|
133 } |
|
134 |
|
135 void BTDeviceSearchDialogWidget::closeDeviceDialog(bool byClient) |
|
136 { |
|
137 Q_UNUSED(byClient); |
|
138 mSearchDevicesDialog->close(); |
|
139 //@ TODO to check below code is required which is written based on the documentation of closeDeviceDialog API |
|
140 |
|
141 /* QVariantMap val; |
|
142 QVariant index(-1); |
|
143 val.insert("selectedindex",index); |
|
144 emit deviceDialogData(val); |
|
145 emit deviceDialogClosed();*/ |
|
146 } |
|
147 |
|
148 HbPopup* BTDeviceSearchDialogWidget::deviceDialogWidget() const |
|
149 { |
|
150 return mSearchDevicesDialog; |
|
151 } |
|
152 |
|
153 QObject* BTDeviceSearchDialogWidget::signalSender() const |
|
154 { |
|
155 return const_cast<BTDeviceSearchDialogWidget*>(this); |
|
156 } |
|
157 |
|
158 bool BTDeviceSearchDialogWidget::constructDialog(const QVariantMap ¶meters) |
|
159 { |
|
160 (void) parameters; |
|
161 bool ok = false; |
|
162 |
|
163 mLoader = new HbDocumentLoader(); |
|
164 mLoader->load(DOCML_BTDEV_SEARCH_DIALOG, &ok); |
|
165 if(ok) |
|
166 { |
|
167 mSearchDevicesDialog = qobject_cast<HbDialog*>(mLoader->findWidget("searchdialog")); |
|
168 |
|
169 /* HbLabel* heading = qobject_cast<HbLabel*>(mLoader->findWidget("heading")); |
|
170 heading->setTextWrapping(Hb::TextWordWrap); |
|
171 heading->setAlignment(Qt::AlignHCenter); |
|
172 heading->setPlainText("Bluetooth - Found devices"); |
|
173 setHeadingWidget(heading);*/ |
|
174 |
|
175 mSearchLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchLabel")); |
|
176 mSearchLabel->setTextWrapping(Hb::TextWordWrap); |
|
177 mSearchLabel->setAlignment(Qt::AlignHCenter); |
|
178 mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE); |
|
179 |
|
180 mSearchIconLabel = qobject_cast<HbLabel*>(mLoader->findWidget("iconLabel")); |
|
181 mSearchIconLabel->setIcon(QIcon(QString(":/icons/qtg_large_bluetooth.svg"))); |
|
182 |
|
183 mSearchDoneLabel = qobject_cast<HbLabel*>(mLoader->findWidget("searchDoneLabel")); |
|
184 mSearchDoneLabel->hide(); |
|
185 |
|
186 |
|
187 mSearchDevicesDialog->setFrameType(HbDialog::Strong); |
|
188 mSearchDevicesDialog->setBackgroundFaded(false); |
|
189 |
|
190 // mViewByBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("viewby")); |
|
191 // mStopRetryBtn = qobject_cast<HbPushButton*>(mLoader->findWidget("stop")); |
|
192 |
|
193 mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView")); |
|
194 mListView->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
195 |
|
196 mContentItemModel = new QStandardItemModel(this); |
|
197 mListView->setModel(mContentItemModel);//, prototype); |
|
198 |
|
199 connect(mListView, SIGNAL(activated(QModelIndex)), this, SLOT(deviceSelected(QModelIndex))); |
|
200 // connect(mStopRetryBtn, SIGNAL(clicked()), this, SLOT(stopRetryClicked())); |
|
201 // connect(mViewByBtn, SIGNAL(clicked()), this, SLOT(viewByClicked())); |
|
202 |
|
203 mShowAction = static_cast<HbAction*>( mLoader->findObject( "viewaction" ) ); |
|
204 mShowAction->disconnect(mSearchDevicesDialog); |
|
205 |
|
206 mStopRetryAction = static_cast<HbAction*>( mLoader->findObject( "stopretryaction" ) ); |
|
207 mStopRetryAction->disconnect(mSearchDevicesDialog); |
|
208 |
|
209 // mCancelAction = static_cast<HbAction*>( mLoader->findObject( "cancelaction" ) ); |
|
210 // mCancelAction->disconnect(mSearchDevicesDialog); |
|
211 |
|
212 connect(mShowAction, SIGNAL(triggered()), this, SLOT(viewByClicked())); |
|
213 connect(mStopRetryAction, SIGNAL(triggered()), this, SLOT(stopRetryClicked())); |
|
214 |
|
215 connect(mSearchDevicesDialog, SIGNAL(aboutToClose()), this, SLOT(searchDialogClosed())); |
|
216 |
|
217 // QGraphicsWidget *widget = mLoader->findWidget(QString("container")); |
|
218 //setContentWidget(widget); |
|
219 } |
|
220 mSearchDevicesDialog->setBackgroundFaded(false); |
|
221 mSearchDevicesDialog->setDismissPolicy(HbPopup::NoDismiss); |
|
222 mSearchDevicesDialog->setTimeout(HbPopup::NoTimeout); |
|
223 mSearchDevicesDialog->setAttribute(Qt::WA_DeleteOnClose); |
|
224 |
|
225 mDevTypeList << hbTrId("txt_bt_list_audio_devices") |
|
226 << hbTrId("txt_bt_list_computers") |
|
227 << hbTrId("txt_bt_list_input_devices") |
|
228 << hbTrId("txt_bt_list_phones") |
|
229 << hbTrId("txt_bt_list_other_devices"); |
|
230 |
|
231 /* mViewByDialog = new HbDialog(); |
|
232 mRbl = new HbRadioButtonList(mViewByDialog); |
|
233 connect(mRbl, SIGNAL(itemSelected(int)), this, SLOT(viewByItemSelected(int)));*/ |
|
234 |
|
235 return true; |
|
236 } |
|
237 |
|
238 |
|
239 void BTDeviceSearchDialogWidget::stopRetryClicked() |
|
240 { |
|
241 QVariantMap val; |
|
242 if(mStopRetryFlag == 1)//mStopRetryAction->text().compare(LOC_SEARCH_RETRY)==0 |
|
243 { |
|
244 mStopRetryFlag = 0; // Stop |
|
245 QVariant index("Retry"); |
|
246 val.insert("Retry",index); |
|
247 emit deviceDialogData(val); |
|
248 delete mContentItemModel; |
|
249 mContentItemModel = new QStandardItemModel(this); |
|
250 mListView->setModel(mContentItemModel); |
|
251 mStopRetryAction->setText(LOC_SEARCH_STOP); |
|
252 |
|
253 mSearchLabel->setTextWrapping(Hb::TextWordWrap); |
|
254 mSearchLabel->setAlignment(Qt::AlignHCenter); |
|
255 mSearchLabel->setPlainText(LOC_SEARCHING_DEVICE); |
|
256 |
|
257 mSearchIconLabel->setIcon(QIcon(QString(":/icons/qtg_large_bluetooth.svg"))); |
|
258 mSearchLabel->show(); |
|
259 |
|
260 mSearchIconLabel->show(); |
|
261 |
|
262 mSearchDoneLabel->hide(); |
|
263 } |
|
264 else |
|
265 { |
|
266 mStopRetryFlag = 1; //Retry |
|
267 mStopRetryAction->setText(LOC_SEARCH_RETRY); |
|
268 |
|
269 mSearchLabel->hide(); |
|
270 |
|
271 mSearchIconLabel->hide(); |
|
272 |
|
273 mSearchDoneLabel->show(); |
|
274 mSearchDoneLabel->setTextWrapping(Hb::TextWordWrap); |
|
275 mSearchDoneLabel->setAlignment(Qt::AlignLeft); |
|
276 mSearchDoneLabel->setPlainText(LOC_SEARCH_DONE); |
|
277 |
|
278 QVariantMap val; |
|
279 QVariant index("Stop"); |
|
280 val.insert("Stop",index); |
|
281 emit deviceDialogData(val); |
|
282 } |
|
283 } |
|
284 |
|
285 void BTDeviceSearchDialogWidget::retryClicked() |
|
286 { |
|
287 QVariantMap val; |
|
288 QVariant index("Retry"); |
|
289 val.insert("Retry",index); |
|
290 emit deviceDialogData(val); |
|
291 delete mContentItemModel; |
|
292 mContentItemModel = new QStandardItemModel(this); |
|
293 mListView->setModel(mContentItemModel); |
|
294 |
|
295 |
|
296 } |
|
297 |
|
298 void BTDeviceSearchDialogWidget::viewByClicked() |
|
299 { |
|
300 |
|
301 if ( !mQuery ) { |
|
302 mQuery = new HbSelectionDialog; |
|
303 mQuery->setStringItems(mDevTypeList, 0); |
|
304 mQuery->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
305 |
|
306 QList<QVariant> current; |
|
307 current.append(QVariant(0)); |
|
308 mQuery->setSelectedItems(current); |
|
309 |
|
310 //todo need to check whether the dialog is destroyed without setting this flag |
|
311 //if not destoryed then set this flag in the destructor and then delete it |
|
312 |
|
313 // mQuery->setAttribute(Qt::WA_DeleteOnClose); |
|
314 // Set the heading for the dialog. |
|
315 HbLabel *headingLabel = new HbLabel(hbTrId("txt_bt_title_show"), mQuery); |
|
316 mQuery->setHeadingWidget(headingLabel); |
|
317 } |
|
318 mQuery->open(this,SLOT(selectionDialogClosed(HbAction*))); |
|
319 |
|
320 |
|
321 } |
|
322 |
|
323 void BTDeviceSearchDialogWidget::searchDialogClosed() |
|
324 { |
|
325 QVariantMap val; |
|
326 QVariant index(-1); |
|
327 val.insert("selectedindex",index); |
|
328 emit deviceDialogData(val); |
|
329 emit deviceDialogClosed(); |
|
330 } |
|
331 |
|
332 void BTDeviceSearchDialogWidget::selectionDialogClosed(HbAction* action) |
|
333 { |
|
334 Q_UNUSED(action); |
|
335 |
|
336 disconnect( mQuery ); |
|
337 int devTypesWanted = 0; |
|
338 |
|
339 if (action == mQuery->actions().first()) { // user pressed "Ok" |
|
340 // Get selected items. |
|
341 QList<QVariant> selections; |
|
342 selections = mQuery->selectedItems(); |
|
343 |
|
344 for (int i=0; i < selections.count(); i++) { |
|
345 switch (selections.at(i).toInt()) { |
|
346 case BtUiDevAudioDevice: |
|
347 devTypesWanted |= BtuiDevProperty::AVDev; |
|
348 break; |
|
349 case BtUiDevComputer: |
|
350 devTypesWanted |= BtuiDevProperty::Computer; |
|
351 break; |
|
352 case BtUiDevInputDevice: |
|
353 devTypesWanted |= BtuiDevProperty::Peripheral; |
|
354 break; |
|
355 case BtUiDevPhone: |
|
356 devTypesWanted |= BtuiDevProperty::Phone; |
|
357 break; |
|
358 case BtUiDevOtherDevice: |
|
359 devTypesWanted |= (BtuiDevProperty::LANAccessDev | |
|
360 BtuiDevProperty::Toy | |
|
361 BtuiDevProperty::WearableDev | |
|
362 BtuiDevProperty::ImagingDev | |
|
363 BtuiDevProperty::HealthDev | |
|
364 BtuiDevProperty::UncategorizedDev); |
|
365 break; |
|
366 default: |
|
367 // should never get here |
|
368 break; |
|
369 } |
|
370 } |
|
371 } |
|
372 else |
|
373 { |
|
374 devTypesWanted = mSelectedDeviceType; |
|
375 } |
|
376 |
|
377 |
|
378 |
|
379 /* HbSelectionDialog *dlg = (HbSelectionDialog*)(sender()); |
|
380 if(dlg->actions().first() == action) { |
|
381 |
|
382 } |
|
383 else if(dlg->actions().at(1) == action) { |
|
384 }*/ |
|
385 |
|
386 if((devTypesWanted != mSelectedDeviceType) &&(devTypesWanted !=0)) |
|
387 { |
|
388 mSelectedDeviceType = devTypesWanted; |
|
389 // mViewByChosen = true; |
|
390 delete mContentItemModel; |
|
391 mContentItemModel = new QStandardItemModel(this); |
|
392 mListView->setModel(mContentItemModel); |
|
393 mSelectedData.clear(); |
|
394 for(int i=0;i<mData.count();i++) |
|
395 { |
|
396 const BtSendDataItem& qtdev = mData[i]; |
|
397 if(devTypesWanted & qtdev[DeviceTypeRole].toInt() ) |
|
398 { |
|
399 QStandardItem* listitem = new QStandardItem(); |
|
400 QStringList info; |
|
401 info.append(qtdev[NameAliasRole].toString()); |
|
402 |
|
403 listitem->setData(info, Qt::DisplayRole); |
|
404 HbIcon icon = getBadgedDeviceTypeIcon(qtdev[CoDRole].toDouble(), |
|
405 qtdev[MajorPropertyRole].toInt(), |
|
406 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight); |
|
407 listitem->setIcon(icon.qicon()); |
|
408 mContentItemModel->appendRow(listitem); |
|
409 mSelectedData.append(qtdev); |
|
410 } |
|
411 } |
|
412 } |
|
413 } |
|
414 |
|
415 void BTDeviceSearchDialogWidget::deviceSelected(const QModelIndex& modelIndex) |
|
416 { |
|
417 int row = 0; |
|
418 |
|
419 /* if(mViewByChosen) |
|
420 { |
|
421 row = mDeviceLstOfType[modelIndex.row()].mDeviceIdx; |
|
422 } |
|
423 |
|
424 else*/ |
|
425 { |
|
426 row = modelIndex.row(); |
|
427 } |
|
428 |
|
429 QVariantMap val; |
|
430 // QVariant index(row); |
|
431 // val.insert("selectedindex",index); |
|
432 |
|
433 const BtSendDataItem& qtdev = mSelectedData.at(row); |
|
434 val.insert("selectedindex",QVariant(row)); |
|
435 val.insert("devicename",QVariant(qtdev[NameAliasRole])); |
|
436 val.insert("deviceaddress",QVariant(qtdev[ReadableBdaddrRole])); |
|
437 val.insert("deviceclass",QVariant(qtdev[CoDRole])); |
|
438 |
|
439 emit deviceDialogData(val); |
|
440 // mDeviceDialogData = 1;//flag is to say that device dialog data is emitted required when we cancel the dialog |
|
441 //emit deviceDialogClosed(); |
|
442 // this->close(); |
|
443 } |
|
444 |
|
445 |
|