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