31
|
1 |
/*
|
42
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
31
|
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>
|
42
|
24 |
#include <hbdataformmodel.h>
|
|
25 |
#include <hbdataformmodelitem.h>
|
31
|
26 |
#include <hbgroupbox.h>
|
|
27 |
#include <hbpushbutton.h>
|
|
28 |
#include <hblabel.h>
|
42
|
29 |
#include <hbicon.h>
|
|
30 |
#include <hblineedit.h>
|
31
|
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>
|
42
|
41 |
#include "btuiiconutil.h"
|
|
42 |
#include "btuidevtypemap.h"
|
|
43 |
|
|
44 |
#include "btcpuidevicedetail.h"
|
31
|
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),
|
42
|
55 |
mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false),
|
|
56 |
mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)
|
31
|
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 |
|
42
|
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.
|
31
|
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 |
|
42
|
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");
|
31
|
103 |
|
42
|
104 |
|
31
|
105 |
// assign automatically created widgets to local variables
|
42
|
106 |
/*
|
31
|
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" );
|
42
|
110 |
*/
|
31
|
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;
|
42
|
117 |
mDeviceName = qobject_cast<HbLineEdit *>( mLoader->findWidget( "deviceName" ) );
|
31
|
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 |
|
42
|
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 |
|
31
|
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" );
|
42
|
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 |
|
31
|
159 |
}
|
|
160 |
|
|
161 |
BtCpUiDeviceView::~BtCpUiDeviceView()
|
|
162 |
{
|
42
|
163 |
delete mLoader; // Also deletes all widgets that it constructed.
|
|
164 |
|
|
165 |
delete mConnectionComboboxModel;
|
|
166 |
|
31
|
167 |
setNavigationAction(0);
|
|
168 |
delete mSoftKeyBackAction;
|
|
169 |
if(mAbstractDelegate)
|
|
170 |
{
|
|
171 |
delete mAbstractDelegate;
|
|
172 |
mAbstractDelegate = 0;
|
|
173 |
}
|
42
|
174 |
|
31
|
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();
|
42
|
190 |
delete mDeviceDetail;
|
|
191 |
mDeviceDetail = 0;
|
31
|
192 |
}
|
|
193 |
|
42
|
194 |
void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton )
|
31
|
195 |
{
|
42
|
196 |
Q_UNUSED( fromBackButton );
|
31
|
197 |
|
|
198 |
setSoftkeyBack();
|
|
199 |
|
|
200 |
QModelIndex index = value.value<QModelIndex>();
|
|
201 |
mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
|
|
202 |
|
|
203 |
//activate view is called when device is selected
|
42
|
204 |
//clearViewData();
|
31
|
205 |
updateDeviceData();
|
|
206 |
|
42
|
207 |
mDeviceSetting->setVisible(false);
|
|
208 |
|
|
209 |
mDeviceDetail = new BtCpUiDeviceDetail();
|
|
210 |
|
31
|
211 |
bool ret(false);
|
|
212 |
ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
213 |
this, SLOT(updateDeviceData()));
|
|
214 |
BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
|
42
|
215 |
|
|
216 |
ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
|
|
217 |
this, SLOT(handleDeviceSettingsChange(bool)));
|
|
218 |
BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "deviceSettingsChanged() connect failed");
|
|
219 |
|
|
220 |
|
|
221 |
mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text());
|
|
222 |
|
|
223 |
}
|
|
224 |
|
|
225 |
void BtCpUiDeviceView::handleDeviceSettingsChange(bool status)
|
|
226 |
{
|
|
227 |
mDeviceSetting->setVisible(status);
|
|
228 |
}
|
|
229 |
|
|
230 |
void BtCpUiDeviceView::handleDeviceSetting()
|
|
231 |
{
|
|
232 |
mDeviceDetail->loadDeviceDetailsView();
|
31
|
233 |
}
|
|
234 |
|
|
235 |
void BtCpUiDeviceView::deactivateView()
|
|
236 |
{
|
|
237 |
}
|
|
238 |
|
42
|
239 |
// called due to real orientation change event coming from main window
|
|
240 |
void BtCpUiDeviceView::changeOrientation( Qt::Orientation orientation )
|
|
241 |
{
|
|
242 |
bool ok = false;
|
|
243 |
mOrientation = orientation;
|
|
244 |
if( orientation == Qt::Vertical ) {
|
|
245 |
// load "portrait" section
|
|
246 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "portrait", &ok );
|
|
247 |
BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: portrait section problem" );
|
|
248 |
} else {
|
|
249 |
// load "landscape" section
|
|
250 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ok );
|
|
251 |
BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
|
|
252 |
}
|
|
253 |
}
|
|
254 |
|
31
|
255 |
void BtCpUiDeviceView::clearViewData()
|
|
256 |
{
|
|
257 |
mDeviceIcon->clear();
|
|
258 |
mDeviceCategory->clear();
|
|
259 |
mDeviceStatus->clear();
|
|
260 |
|
42
|
261 |
mPairedStatus = false;
|
|
262 |
mConnectedStatus = false;
|
|
263 |
mTrustedStatus = false;
|
|
264 |
mBlockedStatus = false;
|
|
265 |
|
31
|
266 |
mConnectable = false;
|
|
267 |
}
|
|
268 |
|
|
269 |
void BtCpUiDeviceView::updateDeviceData()
|
|
270 |
{
|
42
|
271 |
clearViewData();
|
31
|
272 |
//Get the QModelIndex of the device using the device BDAddres
|
|
273 |
QModelIndex start = mDeviceModel->index(0,0);
|
|
274 |
QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
|
|
275 |
mDeviceIndex = indexList.at(0);
|
|
276 |
|
|
277 |
//populate device view with device data fetched from UiModel
|
|
278 |
QString deviceName = (mDeviceModel->data(mDeviceIndex,
|
|
279 |
BtDeviceModel::NameAliasRole)).toString();
|
42
|
280 |
mDeviceName->setText(deviceName);
|
31
|
281 |
|
|
282 |
int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
|
|
283 |
|
|
284 |
int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
|
|
285 |
|
42
|
286 |
setDeviceCategory(cod, majorRole);
|
31
|
287 |
setDeviceStatus(majorRole);
|
|
288 |
setTextAndVisibilityOfButtons();
|
|
289 |
}
|
|
290 |
|
42
|
291 |
void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole)
|
31
|
292 |
{
|
42
|
293 |
mDeviceCategory->setPlainText( getDeviceTypeString( cod ));
|
|
294 |
HbIcon icon =
|
|
295 |
getBadgedDeviceTypeIcon(cod, majorRole,
|
|
296 |
BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
|
|
297 |
mDeviceIcon->setIcon(icon);
|
|
298 |
|
|
299 |
if (majorRole & BtuiDevProperty::Connectable ) {
|
|
300 |
mConnectable = true;
|
|
301 |
}
|
31
|
302 |
}
|
42
|
303 |
|
31
|
304 |
void BtCpUiDeviceView::setDeviceStatus(int majorRole)
|
|
305 |
{
|
|
306 |
QString deviceStatus;
|
42
|
307 |
|
|
308 |
updateStatusVariables(majorRole); // should we use bitmap instead??
|
|
309 |
|
|
310 |
if (majorRole & BtuiDevProperty::Bonded &&
|
|
311 |
majorRole & BtuiDevProperty::Trusted &&
|
|
312 |
majorRole & BtuiDevProperty::Connected ) {
|
|
313 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
|
|
314 |
}
|
|
315 |
else if (majorRole & BtuiDevProperty::Bonded &&
|
|
316 |
majorRole & BtuiDevProperty::Connected ) {
|
|
317 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
|
31
|
318 |
}
|
42
|
319 |
else if (majorRole & BtuiDevProperty::Bonded &&
|
|
320 |
majorRole & BtuiDevProperty::Trusted ) {
|
|
321 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
|
|
322 |
}
|
|
323 |
else if (majorRole & BtuiDevProperty::Bonded) {
|
|
324 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
|
|
325 |
}
|
|
326 |
else if (majorRole & BtuiDevProperty::Connected) {
|
|
327 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
|
31
|
328 |
}
|
42
|
329 |
else if (majorRole & BtuiDevProperty::Blocked) {
|
|
330 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
|
|
331 |
}
|
|
332 |
else {
|
|
333 |
// device not paired, connected, trusted or blocked. is this ok?
|
|
334 |
}
|
|
335 |
|
|
336 |
}
|
|
337 |
|
|
338 |
void BtCpUiDeviceView::setConnectionCombobox(){
|
|
339 |
|
|
340 |
//create a model class
|
31
|
341 |
|
42
|
342 |
mConnectionComboboxModel->appendDataFormItem(
|
|
343 |
HbDataFormModelItem::ComboBoxItem, QString("Connection"), mConnectionComboboxModel->invisibleRootItem());
|
|
344 |
|
|
345 |
//set the model to the view, once model and data class are created
|
|
346 |
mConnectionCombobox->setModel(mConnectionComboboxModel);
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
}
|
|
351 |
|
|
352 |
|
|
353 |
/*!
|
|
354 |
* instead of using separate boolean variables we could use bitmap in single variable
|
|
355 |
*/
|
|
356 |
void BtCpUiDeviceView::updateStatusVariables(int majorRole)
|
|
357 |
{
|
|
358 |
if (majorRole & BtuiDevProperty::Trusted ) {
|
|
359 |
mTrustedStatus = true;
|
|
360 |
}
|
|
361 |
else {
|
|
362 |
mTrustedStatus = false;
|
31
|
363 |
}
|
42
|
364 |
if (majorRole & BtuiDevProperty::Bonded) {
|
|
365 |
mPairedStatus = true;
|
|
366 |
}
|
|
367 |
else {
|
|
368 |
mPairedStatus = false;
|
|
369 |
}
|
|
370 |
if (majorRole & BtuiDevProperty::Connected) {
|
|
371 |
mConnectedStatus = true;
|
31
|
372 |
}
|
42
|
373 |
else {
|
|
374 |
mConnectedStatus = false;
|
|
375 |
}
|
|
376 |
if (majorRole & BtuiDevProperty::Blocked) {
|
|
377 |
mBlockedStatus = true;
|
|
378 |
}
|
|
379 |
else {
|
|
380 |
mBlockedStatus = false;
|
|
381 |
}
|
31
|
382 |
}
|
|
383 |
|
|
384 |
void BtCpUiDeviceView::setTextAndVisibilityOfButtons()
|
|
385 |
{
|
42
|
386 |
mPair_Unpair->setStretched(true);
|
|
387 |
if (mPairedStatus)
|
31
|
388 |
{
|
42
|
389 |
HbIcon icon("qtg_mono_bt_unpair");
|
|
390 |
icon.setIconName("qtg_mono_bt_unpair");
|
|
391 |
mPair_Unpair->setIcon(icon);
|
|
392 |
mPair_Unpair->setText(hbTrId("txt_bt_button_unpair"));
|
|
393 |
|
31
|
394 |
}
|
|
395 |
else
|
|
396 |
{
|
42
|
397 |
HbIcon icon("qtg_mono_bt_pair");
|
|
398 |
icon.setIconName("qtg_mono_bt_pair");
|
|
399 |
mPair_Unpair->setIcon(icon);
|
|
400 |
mPair_Unpair->setText(hbTrId("txt_bt_button_pair"));
|
31
|
401 |
}
|
|
402 |
|
|
403 |
if (mConnectable)
|
|
404 |
{
|
42
|
405 |
mConnect_Disconnect->setStretched(true);
|
|
406 |
if (mConnectedStatus)
|
31
|
407 |
{
|
42
|
408 |
HbIcon icon("qtg_mono_speaker_off");
|
|
409 |
icon.setIconName("qtg_mono_speaker_off");
|
|
410 |
mConnect_Disconnect->setIcon(icon);
|
|
411 |
mConnect_Disconnect->setText(hbTrId("txt_bt_button_disconnect"));
|
31
|
412 |
}
|
|
413 |
else
|
|
414 |
{
|
42
|
415 |
HbIcon icon("qtg_mono_speaker");
|
|
416 |
icon.setIconName("qtg_mono_speaker");
|
|
417 |
mConnect_Disconnect->setIcon(icon);
|
|
418 |
mConnect_Disconnect->setText(hbTrId("txt_bt_button_connect"));
|
31
|
419 |
}
|
|
420 |
|
|
421 |
}
|
|
422 |
else
|
|
423 |
{
|
|
424 |
//it is not possible to connect, set the button invisible
|
|
425 |
mConnect_Disconnect->setVisible(false);
|
|
426 |
}
|
|
427 |
|
|
428 |
}
|
|
429 |
|
|
430 |
|
|
431 |
void BtCpUiDeviceView::pairUnpair()
|
|
432 |
{
|
42
|
433 |
if (mPairedStatus)
|
31
|
434 |
{
|
|
435 |
//if the device is paired, call unpairDevice() when the button is tabbed
|
|
436 |
unpairDevice();
|
|
437 |
}
|
|
438 |
else
|
|
439 |
{
|
|
440 |
//if the device is unpaired, call pairDevice() when the button is tabbed
|
|
441 |
pairDevice();
|
|
442 |
|
|
443 |
}
|
|
444 |
|
|
445 |
|
|
446 |
}
|
|
447 |
|
|
448 |
void BtCpUiDeviceView::connectDisconnect()
|
|
449 |
{
|
42
|
450 |
if (mConnectedStatus)
|
31
|
451 |
{
|
|
452 |
//if the device is connected, call disconnectDevice() when the button is tabbed
|
|
453 |
disconnectDevice();
|
|
454 |
}
|
|
455 |
else
|
|
456 |
{
|
|
457 |
//if the device is disconnected, call connectDevice() when the button is tabbed
|
|
458 |
connectDevice();
|
|
459 |
|
|
460 |
}
|
|
461 |
}
|
|
462 |
|
|
463 |
void BtCpUiDeviceView::pairDevice()
|
|
464 |
{
|
|
465 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
466 |
{
|
|
467 |
QVariant params;
|
|
468 |
params.setValue(mDeviceIndex);
|
|
469 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
470 |
BtDelegate::Pair, mSettingModel, mDeviceModel);
|
|
471 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(pairDelegateCompleted(int)) );
|
|
472 |
mAbstractDelegate->exec(params);
|
|
473 |
}
|
|
474 |
|
|
475 |
}
|
|
476 |
|
|
477 |
void BtCpUiDeviceView::pairDelegateCompleted(int status)
|
|
478 |
{
|
|
479 |
Q_UNUSED(status);
|
|
480 |
//TODO: handle the error here
|
|
481 |
if (mAbstractDelegate)
|
|
482 |
{
|
|
483 |
disconnect(mAbstractDelegate);
|
|
484 |
delete mAbstractDelegate;
|
|
485 |
mAbstractDelegate = 0;
|
|
486 |
}
|
|
487 |
}
|
|
488 |
|
|
489 |
void BtCpUiDeviceView::unpairDevice()
|
|
490 |
{
|
|
491 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
492 |
{
|
|
493 |
QVariant params;
|
|
494 |
params.setValue(mDeviceIndex);
|
|
495 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
496 |
BtDelegate::Unpair, mSettingModel, mDeviceModel);
|
|
497 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(unpairDelegateCompleted(int)) );
|
|
498 |
mAbstractDelegate->exec(params);
|
|
499 |
}
|
|
500 |
|
|
501 |
|
|
502 |
}
|
|
503 |
|
|
504 |
void BtCpUiDeviceView::unpairDelegateCompleted(int status)
|
|
505 |
{
|
|
506 |
Q_UNUSED(status);
|
|
507 |
//TODO: handle the error here
|
|
508 |
if (mAbstractDelegate)
|
|
509 |
{
|
|
510 |
disconnect(mAbstractDelegate);
|
|
511 |
delete mAbstractDelegate;
|
|
512 |
mAbstractDelegate = 0;
|
|
513 |
}
|
|
514 |
}
|
|
515 |
|
|
516 |
void BtCpUiDeviceView::connectDevice()
|
|
517 |
{
|
|
518 |
|
|
519 |
|
|
520 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
521 |
{
|
|
522 |
QVariant params;
|
|
523 |
params.setValue(mDeviceIndex);
|
|
524 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
525 |
BtDelegate::Connect, mSettingModel, mDeviceModel);
|
|
526 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(connectDelegateCompleted(int)) );
|
|
527 |
mAbstractDelegate->exec(params);
|
|
528 |
}
|
|
529 |
|
|
530 |
|
|
531 |
}
|
|
532 |
|
|
533 |
void BtCpUiDeviceView::connectDelegateCompleted(int status)
|
|
534 |
{
|
|
535 |
Q_UNUSED(status);
|
|
536 |
if (mAbstractDelegate)
|
|
537 |
{
|
|
538 |
disconnect(mAbstractDelegate);
|
|
539 |
delete mAbstractDelegate;
|
|
540 |
mAbstractDelegate = 0;
|
|
541 |
}
|
|
542 |
|
|
543 |
|
|
544 |
}
|
|
545 |
|
|
546 |
void BtCpUiDeviceView::disconnectDevice()
|
|
547 |
{
|
|
548 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
549 |
{
|
42
|
550 |
|
|
551 |
|
|
552 |
DisconnectOption discoOpt = ServiceLevel;
|
|
553 |
|
|
554 |
QList<QVariant>list;
|
|
555 |
QVariant paramFirst;
|
|
556 |
paramFirst.setValue(mDeviceIndex);
|
|
557 |
|
|
558 |
QVariant paramSecond;
|
|
559 |
paramSecond.setValue((int)discoOpt);
|
|
560 |
|
|
561 |
list.append(paramFirst);
|
|
562 |
list.append(paramSecond);
|
|
563 |
|
31
|
564 |
QVariant params;
|
42
|
565 |
params.setValue(list);
|
|
566 |
|
|
567 |
|
|
568 |
//params.setValue(mDeviceIndex);
|
31
|
569 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
570 |
BtDelegate::Disconnect, mSettingModel, mDeviceModel);
|
|
571 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
|
|
572 |
mAbstractDelegate->exec(params);
|
|
573 |
}
|
|
574 |
|
|
575 |
}
|
|
576 |
|
|
577 |
void BtCpUiDeviceView::disconnectDelegateCompleted(int status)
|
|
578 |
{
|
|
579 |
Q_UNUSED(status);
|
|
580 |
if (mAbstractDelegate)
|
|
581 |
{
|
|
582 |
disconnect(mAbstractDelegate);
|
|
583 |
delete mAbstractDelegate;
|
|
584 |
mAbstractDelegate = 0;
|
|
585 |
}
|
|
586 |
|
|
587 |
|
|
588 |
}
|
|
589 |
|
42
|
590 |
void BtCpUiDeviceView::changeBtDeviceName(){
|
|
591 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
592 |
{
|
|
593 |
QList<QVariant>list;
|
|
594 |
|
|
595 |
QVariant index;
|
|
596 |
index.setValue(mDeviceIndex);
|
|
597 |
|
|
598 |
QVariant name;
|
|
599 |
name.setValue(mDeviceName->text());
|
|
600 |
|
|
601 |
list.append(index);
|
|
602 |
list.append(name);
|
|
603 |
|
|
604 |
QVariant params;
|
|
605 |
params.setValue(list);
|
|
606 |
|
|
607 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
608 |
BtDelegate::RemoteDevName, mSettingModel, mDeviceModel);
|
|
609 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
|
|
610 |
mAbstractDelegate->exec(params);
|
|
611 |
}
|
|
612 |
|
|
613 |
}
|
|
614 |
|
|
615 |
void BtCpUiDeviceView::changeDevNameDelegateCompleted(int status, QVariant param)
|
|
616 |
{
|
|
617 |
|
|
618 |
|
|
619 |
if(KErrNone == status) {
|
|
620 |
mDeviceName->setText(param.toString());
|
|
621 |
}
|
|
622 |
else {
|
|
623 |
//setPrevBtLocalName();
|
|
624 |
}
|
|
625 |
//TODO:Error handling has to be done.
|
|
626 |
if (mAbstractDelegate)
|
|
627 |
{
|
|
628 |
disconnect(mAbstractDelegate);
|
|
629 |
delete mAbstractDelegate;
|
|
630 |
mAbstractDelegate = 0;
|
|
631 |
}
|
|
632 |
|
|
633 |
|
|
634 |
}
|