|
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 "btcpuideviceview.h" |
|
19 #include "btuiviewutil.h" |
|
20 #include <QtGui/QGraphicsLinearLayout> |
|
21 #include <HbInstance> |
|
22 #include <hbdocumentloader.h> |
|
23 #include <hbdataform.h> |
|
24 #include <hbdataformmodel.h> |
|
25 #include <hbdataformmodelitem.h> |
|
26 #include <hbgroupbox.h> |
|
27 #include <hbpushbutton.h> |
|
28 #include <hblabel.h> |
|
29 #include <hbicon.h> |
|
30 #include <hblineedit.h> |
|
31 #include <hblistview.h> |
|
32 #include <hbmenu.h> |
|
33 #include <qstring> |
|
34 #include <qstringlist> |
|
35 #include <qdebug> |
|
36 #include <bluetoothuitrace.h> |
|
37 #include "btcpuimainview.h" |
|
38 #include <btabstractdelegate.h> |
|
39 #include <btdelegatefactory.h> |
|
40 #include <QModelIndex> |
|
41 #include "btuiiconutil.h" |
|
42 #include "btuidevtypemap.h" |
|
43 |
|
44 #include "btcpuidevicedetail.h" |
|
45 |
|
46 // docml to load |
|
47 const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml"; |
|
48 |
|
49 |
|
50 BtCpUiDeviceView::BtCpUiDeviceView( |
|
51 BtSettingModel &settingModel, |
|
52 BtDeviceModel &deviceModel, |
|
53 QGraphicsItem *parent) : |
|
54 BtCpUiBaseView(settingModel,deviceModel,parent), |
|
55 mPairedStatus(false), mConnectedStatus(false),mPreviousConnectedStatus(false), mTrustedStatus(false), |
|
56 mBlockedStatus(false), mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0) |
|
57 { |
|
58 mDeviceIndex = QModelIndex();//is it needed to initialize mIndex??? |
|
59 |
|
60 mMainView = (BtCpUiMainView *) parent; |
|
61 |
|
62 mMainWindow = hbInstance->allMainWindows().first(); |
|
63 |
|
64 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
|
65 BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action"); |
|
66 |
|
67 // read view info from docml file |
|
68 |
|
69 // Create view for the application. |
|
70 // Set the name for the view. The name should be same as the view's |
|
71 // name in docml. |
|
72 setObjectName("bt_device_view"); |
|
73 |
|
74 mLoader = new HbDocumentLoader(); |
|
75 // Pass the view to documentloader. Document loader uses this view |
|
76 // when docml is parsed, instead of creating new view. |
|
77 QObjectList objectList; |
|
78 objectList.append(this); |
|
79 mLoader->setObjectTree(objectList); |
|
80 |
|
81 bool ret = false; |
|
82 |
|
83 bool ok = false; |
|
84 mLoader->load( BTUI_DEVICEVIEW_DOCML, &ok ); |
|
85 // Exit if the file format is invalid |
|
86 BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file" ); |
|
87 |
|
88 mOrientation = mMainWindow->orientation(); |
|
89 |
|
90 if (mOrientation == Qt::Horizontal) { |
|
91 mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ok); |
|
92 BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" ); |
|
93 } |
|
94 else { |
|
95 mLoader->load(BTUI_DEVICEVIEW_DOCML, "portrait", &ok); |
|
96 BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" ); |
|
97 } |
|
98 |
|
99 // listen for orientation changes |
|
100 ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
|
101 this, SLOT(changeOrientation(Qt::Orientation))); |
|
102 BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView()", "connect orientationChanged() failed"); |
|
103 |
|
104 |
|
105 // assign automatically created widgets to local variables |
|
106 /* |
|
107 mGroupBox = 0; |
|
108 mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox_deviceView" ) ); |
|
109 BTUI_ASSERT_X( mGroupBox != 0, "bt-device-view", "Device groupbox not found" ); |
|
110 */ |
|
111 mDeviceIcon=0; |
|
112 //can't use qobject_cast since HbIcon is not derived from QObject! |
|
113 mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) ); |
|
114 BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" ); |
|
115 |
|
116 mDeviceName=0; |
|
117 mDeviceName = qobject_cast<HbLineEdit *>( mLoader->findWidget( "deviceName" ) ); |
|
118 BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" ); |
|
119 ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName())); |
|
120 |
|
121 mDeviceCategory=0; |
|
122 mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) ); |
|
123 BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" ); |
|
124 |
|
125 mDeviceStatus=0; |
|
126 mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) ); |
|
127 BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" ); |
|
128 |
|
129 |
|
130 mConnectionCombobox = 0; |
|
131 mConnectionCombobox = qobject_cast<HbDataForm *>( mLoader->findWidget( "connectionCombobox" ) ); |
|
132 BTUI_ASSERT_X( mConnectionCombobox != 0, "bt-device-view", "connection combobox not found" ); |
|
133 |
|
134 mConnectionComboboxModel = new HbDataFormModel(); |
|
135 |
|
136 mPair_Unpair=0; |
|
137 mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_0" ) ); |
|
138 BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" ); |
|
139 ret = connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairUnpair())); |
|
140 BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect pair button" ); |
|
141 |
|
142 mConnect_Disconnect=0; |
|
143 mConnect_Disconnect = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_1" ) ); |
|
144 BTUI_ASSERT_X( mConnect_Disconnect != 0, "bt-device-view", "connect/disconnect button not found" ); |
|
145 ret = connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(connectDisconnect())); |
|
146 BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect disconnect button" ); |
|
147 |
|
148 mDeviceSetting = 0; |
|
149 mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) ); |
|
150 BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" ); |
|
151 |
|
152 |
|
153 ret = connect(mDeviceSetting, SIGNAL(clicked()), this, |
|
154 SLOT(handleDeviceSetting())); |
|
155 BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::BtCpUiDeviceView", "clicked() connect failed"); |
|
156 |
|
157 setConnectionCombobox(); |
|
158 |
|
159 } |
|
160 |
|
161 BtCpUiDeviceView::~BtCpUiDeviceView() |
|
162 { |
|
163 delete mLoader; // Also deletes all widgets that it constructed. |
|
164 |
|
165 delete mConnectionComboboxModel; |
|
166 |
|
167 setNavigationAction(0); |
|
168 delete mSoftKeyBackAction; |
|
169 if(mAbstractDelegate) |
|
170 { |
|
171 delete mAbstractDelegate; |
|
172 mAbstractDelegate = 0; |
|
173 } |
|
174 |
|
175 } |
|
176 |
|
177 |
|
178 void BtCpUiDeviceView::setSoftkeyBack() |
|
179 { |
|
180 if (navigationAction() != mSoftKeyBackAction) { |
|
181 setNavigationAction(mSoftKeyBackAction); |
|
182 connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) ); |
|
183 } |
|
184 } |
|
185 |
|
186 void BtCpUiDeviceView::switchToPreviousView() |
|
187 { |
|
188 BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView"); |
|
189 mMainView->switchToPreviousView(); |
|
190 |
|
191 if(mDeviceDetail) { |
|
192 mDeviceDetail->sendCloseEvent(); |
|
193 } |
|
194 unloadDeviceDetails(); |
|
195 } |
|
196 |
|
197 void BtCpUiDeviceView::loadDeviceDetails() |
|
198 { |
|
199 bool ret(false); |
|
200 |
|
201 unloadDeviceDetails(); |
|
202 |
|
203 mDeviceDetail = new BtCpUiDeviceDetail(); |
|
204 |
|
205 ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)), |
|
206 this, SLOT(handleDeviceSettingsChange(bool))); |
|
207 BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::loadDeviceDetails", "deviceSettingsChanged() connect failed"); |
|
208 |
|
209 mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text()); |
|
210 } |
|
211 |
|
212 void BtCpUiDeviceView::unloadDeviceDetails() |
|
213 { |
|
214 if(mDeviceDetail) { |
|
215 disconnect(mDeviceDetail); |
|
216 delete mDeviceDetail; |
|
217 mDeviceDetail = 0; |
|
218 } |
|
219 } |
|
220 |
|
221 void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton ) |
|
222 { |
|
223 |
|
224 Q_UNUSED( fromBackButton ); |
|
225 |
|
226 mConnectedStatus = false; |
|
227 setSoftkeyBack(); |
|
228 |
|
229 |
|
230 QModelIndex index = value.value<QModelIndex>(); |
|
231 mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole)); |
|
232 |
|
233 //activate view is called when device is selected |
|
234 //clearViewData(); |
|
235 updateDeviceData(); |
|
236 |
|
237 mDeviceSetting->setVisible(false); |
|
238 |
|
239 bool ret(false); |
|
240 ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
241 this, SLOT(updateDeviceData())); |
|
242 BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed"); |
|
243 |
|
244 } |
|
245 |
|
246 void BtCpUiDeviceView::handleDeviceSettingsChange(bool status) |
|
247 { |
|
248 mDeviceSetting->setVisible(status); |
|
249 } |
|
250 |
|
251 void BtCpUiDeviceView::handleDeviceSetting() |
|
252 { |
|
253 if(mDeviceDetail) { |
|
254 mDeviceDetail->loadDeviceDetailsView(); |
|
255 } |
|
256 } |
|
257 |
|
258 void BtCpUiDeviceView::deactivateView() |
|
259 { |
|
260 } |
|
261 |
|
262 // called due to real orientation change event coming from main window |
|
263 void BtCpUiDeviceView::changeOrientation( Qt::Orientation orientation ) |
|
264 { |
|
265 bool ok = false; |
|
266 mOrientation = orientation; |
|
267 if( orientation == Qt::Vertical ) { |
|
268 // load "portrait" section |
|
269 mLoader->load( BTUI_DEVICEVIEW_DOCML, "portrait", &ok ); |
|
270 BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: portrait section problem" ); |
|
271 } else { |
|
272 // load "landscape" section |
|
273 mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ok ); |
|
274 BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" ); |
|
275 } |
|
276 } |
|
277 |
|
278 void BtCpUiDeviceView::clearViewData() |
|
279 { |
|
280 mDeviceIcon->clear(); |
|
281 mDeviceCategory->clear(); |
|
282 mDeviceStatus->clear(); |
|
283 mConnectable = false; |
|
284 /* |
|
285 mPairedStatus = false; |
|
286 mConnectedStatus = false; |
|
287 mTrustedStatus = false; |
|
288 mBlockedStatus = false; |
|
289 |
|
290 mConnectable = false; |
|
291 */ |
|
292 } |
|
293 |
|
294 void BtCpUiDeviceView::updateDeviceData() |
|
295 { |
|
296 clearViewData(); |
|
297 //Get the QModelIndex of the device using the device BDAddres |
|
298 QModelIndex start = mDeviceModel->index(0,0); |
|
299 QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr); |
|
300 mDeviceIndex = indexList.at(0); |
|
301 |
|
302 //populate device view with device data fetched from UiModel |
|
303 QString deviceName = (mDeviceModel->data(mDeviceIndex, |
|
304 BtDeviceModel::NameAliasRole)).toString(); |
|
305 mDeviceName->setText(deviceName); |
|
306 |
|
307 int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt(); |
|
308 |
|
309 int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt(); |
|
310 |
|
311 setDeviceCategory(cod, majorRole); |
|
312 setDeviceStatus(majorRole); |
|
313 setTextAndVisibilityOfButtons(); |
|
314 } |
|
315 |
|
316 void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole) |
|
317 { |
|
318 mDeviceCategory->setPlainText( getDeviceTypeString( cod )); |
|
319 HbIcon icon = |
|
320 getBadgedDeviceTypeIcon(cod, majorRole, |
|
321 BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight ); |
|
322 mDeviceIcon->setIcon(icon); |
|
323 |
|
324 if (majorRole & BtuiDevProperty::Connectable ) { |
|
325 mConnectable = true; |
|
326 } |
|
327 } |
|
328 |
|
329 void BtCpUiDeviceView::setDeviceStatus(int majorRole) |
|
330 { |
|
331 QString deviceStatus; |
|
332 |
|
333 updateStatusVariables(majorRole); // should we use bitmap instead?? |
|
334 |
|
335 if (majorRole & BtuiDevProperty::Bonded && |
|
336 majorRole & BtuiDevProperty::Trusted && |
|
337 majorRole & BtuiDevProperty::Connected ) { |
|
338 mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected")); |
|
339 } |
|
340 else if (majorRole & BtuiDevProperty::Bonded && |
|
341 majorRole & BtuiDevProperty::Connected ) { |
|
342 mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected")); |
|
343 } |
|
344 else if (majorRole & BtuiDevProperty::Bonded && |
|
345 majorRole & BtuiDevProperty::Trusted ) { |
|
346 mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted")); |
|
347 } |
|
348 else if (majorRole & BtuiDevProperty::Bonded) { |
|
349 mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired")); |
|
350 } |
|
351 else if (majorRole & BtuiDevProperty::Connected) { |
|
352 mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected")); |
|
353 } |
|
354 else if (majorRole & BtuiDevProperty::Blocked) { |
|
355 mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked")); |
|
356 } |
|
357 else { |
|
358 // device not paired, connected, trusted or blocked. is this ok? |
|
359 } |
|
360 |
|
361 } |
|
362 |
|
363 void BtCpUiDeviceView::setConnectionCombobox(){ |
|
364 |
|
365 //create a model class |
|
366 |
|
367 mConnectionComboboxModel->appendDataFormItem( |
|
368 HbDataFormModelItem::ComboBoxItem, QString("Connection"), mConnectionComboboxModel->invisibleRootItem()); |
|
369 |
|
370 //set the model to the view, once model and data class are created |
|
371 mConnectionCombobox->setModel(mConnectionComboboxModel); |
|
372 |
|
373 |
|
374 |
|
375 } |
|
376 |
|
377 |
|
378 /*! |
|
379 * instead of using separate boolean variables we could use bitmap in single variable |
|
380 */ |
|
381 void BtCpUiDeviceView::updateStatusVariables(int majorRole) |
|
382 { |
|
383 mPreviousConnectedStatus = mConnectedStatus; |
|
384 |
|
385 if (majorRole & BtuiDevProperty::Trusted ) { |
|
386 mTrustedStatus = true; |
|
387 } |
|
388 else { |
|
389 mTrustedStatus = false; |
|
390 } |
|
391 if (majorRole & BtuiDevProperty::Bonded) { |
|
392 mPairedStatus = true; |
|
393 } |
|
394 else { |
|
395 mPairedStatus = false; |
|
396 } |
|
397 if (majorRole & BtuiDevProperty::Connected) { |
|
398 mConnectedStatus = true; |
|
399 if (!mPreviousConnectedStatus){ |
|
400 //Loading device detail plugins after successfull connection. |
|
401 loadDeviceDetails(); |
|
402 } |
|
403 } |
|
404 else { |
|
405 mConnectedStatus = false; |
|
406 } |
|
407 if (majorRole & BtuiDevProperty::Blocked) { |
|
408 mBlockedStatus = true; |
|
409 } |
|
410 else { |
|
411 mBlockedStatus = false; |
|
412 } |
|
413 } |
|
414 |
|
415 void BtCpUiDeviceView::setTextAndVisibilityOfButtons() |
|
416 { |
|
417 mPair_Unpair->setStretched(true); |
|
418 if (mPairedStatus) |
|
419 { |
|
420 HbIcon icon("qtg_mono_bt_unpair"); |
|
421 icon.setIconName("qtg_mono_bt_unpair"); |
|
422 mPair_Unpair->setIcon(icon); |
|
423 mPair_Unpair->setText(hbTrId("txt_bt_button_unpair")); |
|
424 |
|
425 } |
|
426 else |
|
427 { |
|
428 HbIcon icon("qtg_mono_bt_pair"); |
|
429 icon.setIconName("qtg_mono_bt_pair"); |
|
430 mPair_Unpair->setIcon(icon); |
|
431 mPair_Unpair->setText(hbTrId("txt_bt_button_pair")); |
|
432 } |
|
433 |
|
434 if (mConnectable) |
|
435 { |
|
436 mConnect_Disconnect->setVisible(true); |
|
437 mConnect_Disconnect->setStretched(true); |
|
438 if (mConnectedStatus) |
|
439 { |
|
440 HbIcon icon("qtg_mono_speaker_off"); |
|
441 icon.setIconName("qtg_mono_speaker_off"); |
|
442 mConnect_Disconnect->setIcon(icon); |
|
443 mConnect_Disconnect->setText(hbTrId("txt_bt_button_disconnect")); |
|
444 } |
|
445 else |
|
446 { |
|
447 HbIcon icon("qtg_mono_speaker"); |
|
448 icon.setIconName("qtg_mono_speaker"); |
|
449 mConnect_Disconnect->setIcon(icon); |
|
450 mConnect_Disconnect->setText(hbTrId("txt_bt_button_connect")); |
|
451 } |
|
452 |
|
453 } |
|
454 else |
|
455 { |
|
456 //it is not possible to connect, set the button invisible |
|
457 mConnect_Disconnect->setVisible(false); |
|
458 } |
|
459 |
|
460 } |
|
461 |
|
462 |
|
463 void BtCpUiDeviceView::pairUnpair() |
|
464 { |
|
465 if (mPairedStatus) |
|
466 { |
|
467 //if the device is paired, call unpairDevice() when the button is tabbed |
|
468 unpairDevice(); |
|
469 } |
|
470 else |
|
471 { |
|
472 //if the device is unpaired, call pairDevice() when the button is tabbed |
|
473 pairDevice(); |
|
474 |
|
475 } |
|
476 |
|
477 |
|
478 } |
|
479 |
|
480 void BtCpUiDeviceView::connectDisconnect() |
|
481 { |
|
482 if (mConnectedStatus) |
|
483 { |
|
484 //if the device is connected, call disconnectDevice() when the button is tabbed |
|
485 disconnectDevice(); |
|
486 } |
|
487 else |
|
488 { |
|
489 //if the device is disconnected, call connectDevice() when the button is tabbed |
|
490 connectDevice(); |
|
491 |
|
492 } |
|
493 } |
|
494 |
|
495 void BtCpUiDeviceView::pairDevice() |
|
496 { |
|
497 if (!mAbstractDelegate)//if there is no other delegate running |
|
498 { |
|
499 QVariant params; |
|
500 params.setValue(mDeviceIndex); |
|
501 mAbstractDelegate = BtDelegateFactory::newDelegate( |
|
502 BtDelegate::Pair, mSettingModel, mDeviceModel); |
|
503 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(pairDelegateCompleted(int)) ); |
|
504 mAbstractDelegate->exec(params); |
|
505 } |
|
506 |
|
507 } |
|
508 |
|
509 void BtCpUiDeviceView::pairDelegateCompleted(int status) |
|
510 { |
|
511 Q_UNUSED(status); |
|
512 //TODO: handle the error here |
|
513 if (mAbstractDelegate) |
|
514 { |
|
515 disconnect(mAbstractDelegate); |
|
516 delete mAbstractDelegate; |
|
517 mAbstractDelegate = 0; |
|
518 } |
|
519 } |
|
520 |
|
521 void BtCpUiDeviceView::unpairDevice() |
|
522 { |
|
523 if (!mAbstractDelegate)//if there is no other delegate running |
|
524 { |
|
525 QVariant params; |
|
526 params.setValue(mDeviceIndex); |
|
527 mAbstractDelegate = BtDelegateFactory::newDelegate( |
|
528 BtDelegate::Unpair, mSettingModel, mDeviceModel); |
|
529 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(unpairDelegateCompleted(int)) ); |
|
530 mAbstractDelegate->exec(params); |
|
531 } |
|
532 |
|
533 |
|
534 } |
|
535 |
|
536 void BtCpUiDeviceView::unpairDelegateCompleted(int status) |
|
537 { |
|
538 Q_UNUSED(status); |
|
539 //TODO: handle the error here |
|
540 if (mAbstractDelegate) |
|
541 { |
|
542 disconnect(mAbstractDelegate); |
|
543 delete mAbstractDelegate; |
|
544 mAbstractDelegate = 0; |
|
545 } |
|
546 } |
|
547 |
|
548 void BtCpUiDeviceView::connectDevice() |
|
549 { |
|
550 |
|
551 |
|
552 if (!mAbstractDelegate)//if there is no other delegate running |
|
553 { |
|
554 QVariant params; |
|
555 params.setValue(mDeviceIndex); |
|
556 mAbstractDelegate = BtDelegateFactory::newDelegate( |
|
557 BtDelegate::Connect, mSettingModel, mDeviceModel); |
|
558 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(connectDelegateCompleted(int)) ); |
|
559 mAbstractDelegate->exec(params); |
|
560 } |
|
561 |
|
562 |
|
563 } |
|
564 |
|
565 void BtCpUiDeviceView::connectDelegateCompleted(int status) |
|
566 { |
|
567 Q_UNUSED(status); |
|
568 if (mAbstractDelegate) |
|
569 { |
|
570 disconnect(mAbstractDelegate); |
|
571 delete mAbstractDelegate; |
|
572 mAbstractDelegate = 0; |
|
573 } |
|
574 } |
|
575 |
|
576 void BtCpUiDeviceView::disconnectDevice() |
|
577 { |
|
578 if (!mAbstractDelegate)//if there is no other delegate running |
|
579 { |
|
580 |
|
581 |
|
582 DisconnectOption discoOpt = ServiceLevel; |
|
583 |
|
584 QList<QVariant>list; |
|
585 QVariant paramFirst; |
|
586 paramFirst.setValue(mDeviceIndex); |
|
587 |
|
588 QVariant paramSecond; |
|
589 paramSecond.setValue((int)discoOpt); |
|
590 |
|
591 list.append(paramFirst); |
|
592 list.append(paramSecond); |
|
593 |
|
594 QVariant params; |
|
595 params.setValue(list); |
|
596 |
|
597 |
|
598 //params.setValue(mDeviceIndex); |
|
599 mAbstractDelegate = BtDelegateFactory::newDelegate( |
|
600 BtDelegate::Disconnect, mSettingModel, mDeviceModel); |
|
601 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) ); |
|
602 mAbstractDelegate->exec(params); |
|
603 } |
|
604 |
|
605 } |
|
606 |
|
607 void BtCpUiDeviceView::disconnectDelegateCompleted(int status) |
|
608 { |
|
609 Q_UNUSED(status); |
|
610 if (mAbstractDelegate) |
|
611 { |
|
612 disconnect(mAbstractDelegate); |
|
613 delete mAbstractDelegate; |
|
614 mAbstractDelegate = 0; |
|
615 } |
|
616 } |
|
617 |
|
618 void BtCpUiDeviceView::setPrevBtDeviceName() |
|
619 { |
|
620 QString deviceName = (mDeviceModel->data(mDeviceIndex, |
|
621 BtDeviceModel::NameAliasRole)).toString(); |
|
622 mDeviceName->setText(deviceName); |
|
623 } |
|
624 |
|
625 void BtCpUiDeviceView::changeBtDeviceName(){ |
|
626 if (!mAbstractDelegate)//if there is no other delegate running |
|
627 { |
|
628 QList<QVariant>list; |
|
629 |
|
630 QVariant index; |
|
631 index.setValue(mDeviceIndex); |
|
632 |
|
633 QVariant name; |
|
634 name.setValue(mDeviceName->text()); |
|
635 |
|
636 list.append(index); |
|
637 list.append(name); |
|
638 |
|
639 QVariant params; |
|
640 params.setValue(list); |
|
641 |
|
642 mAbstractDelegate = BtDelegateFactory::newDelegate( |
|
643 BtDelegate::RemoteDevName, mSettingModel, mDeviceModel); |
|
644 connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) ); |
|
645 mAbstractDelegate->exec(params); |
|
646 } |
|
647 else { |
|
648 setPrevBtDeviceName(); |
|
649 } |
|
650 |
|
651 } |
|
652 |
|
653 void BtCpUiDeviceView::changeDevNameDelegateCompleted(int status, QVariant param) |
|
654 { |
|
655 |
|
656 |
|
657 if(KErrNone == status) { |
|
658 mDeviceName->setText(param.toString()); |
|
659 } |
|
660 else { |
|
661 setPrevBtDeviceName(); |
|
662 } |
|
663 //TODO:Error handling has to be done. |
|
664 if (mAbstractDelegate) |
|
665 { |
|
666 disconnect(mAbstractDelegate); |
|
667 delete mAbstractDelegate; |
|
668 mAbstractDelegate = 0; |
|
669 } |
|
670 |
|
671 |
|
672 } |