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>
|
57
|
21 |
#include <hbmainwindow.h>
|
31
|
22 |
#include <hbdocumentloader.h>
|
70
|
23 |
#include <hbcombobox.h>
|
31
|
24 |
#include <hbgroupbox.h>
|
|
25 |
#include <hbpushbutton.h>
|
|
26 |
#include <hblabel.h>
|
42
|
27 |
#include <hbicon.h>
|
|
28 |
#include <hblineedit.h>
|
31
|
29 |
#include <hblistview.h>
|
|
30 |
#include <hbmenu.h>
|
67
|
31 |
#include <QString>
|
|
32 |
#include <QStringList>
|
|
33 |
#include <QDebug>
|
31
|
34 |
#include <bluetoothuitrace.h>
|
|
35 |
#include <btabstractdelegate.h>
|
|
36 |
#include <btdelegatefactory.h>
|
42
|
37 |
#include "btuiiconutil.h"
|
|
38 |
#include "btuidevtypemap.h"
|
57
|
39 |
#include "btqtconstants.h"
|
42
|
40 |
#include "btcpuidevicedetail.h"
|
57
|
41 |
#include "btcpuiviewmgr.h"
|
31
|
42 |
|
|
43 |
// docml to load
|
|
44 |
const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
|
|
45 |
|
67
|
46 |
|
|
47 |
// ToDo: should use base class delegate instead of mAbstractDelegate, also base class createDelegate()
|
|
48 |
// and createExecuteDelegate()
|
|
49 |
|
57
|
50 |
BtcpuiDeviceView::BtcpuiDeviceView(BtSettingModel &settingModel,
|
31
|
51 |
BtDeviceModel &deviceModel,
|
|
52 |
QGraphicsItem *parent) :
|
57
|
53 |
BtcpuiBaseView(settingModel,deviceModel,parent),
|
|
54 |
mComboboxIndex(-1), mAbstractDelegate(0), mDeviceDetail(0)
|
31
|
55 |
{
|
57
|
56 |
mDeviceIndex = QModelIndex(); // initialize to zero
|
31
|
57 |
|
|
58 |
// read view info from docml file
|
|
59 |
|
|
60 |
// Create view for the application.
|
|
61 |
// Set the name for the view. The name should be same as the view's
|
|
62 |
// name in docml.
|
|
63 |
setObjectName("bt_device_view");
|
|
64 |
|
42
|
65 |
mLoader = new HbDocumentLoader();
|
|
66 |
// Pass the view to documentloader. Document loader uses this view
|
|
67 |
// when docml is parsed, instead of creating new view.
|
31
|
68 |
QObjectList objectList;
|
|
69 |
objectList.append(this);
|
|
70 |
mLoader->setObjectTree(objectList);
|
|
71 |
|
|
72 |
bool ret = false;
|
|
73 |
|
57
|
74 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, &ret );
|
31
|
75 |
// Exit if the file format is invalid
|
57
|
76 |
BTUI_ASSERT_X( ret, "bt-device-view", "Invalid docml file" );
|
42
|
77 |
// listen for orientation changes
|
|
78 |
ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
|
|
79 |
this, SLOT(changeOrientation(Qt::Orientation)));
|
|
80 |
BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView()", "connect orientationChanged() failed");
|
|
81 |
|
31
|
82 |
// assign automatically created widgets to local variables
|
57
|
83 |
|
31
|
84 |
mDeviceIcon=0;
|
|
85 |
mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) );
|
|
86 |
BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" );
|
|
87 |
|
|
88 |
mDeviceName=0;
|
42
|
89 |
mDeviceName = qobject_cast<HbLineEdit *>( mLoader->findWidget( "deviceName" ) );
|
31
|
90 |
BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" );
|
|
91 |
ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName()));
|
|
92 |
|
|
93 |
mDeviceCategory=0;
|
|
94 |
mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) );
|
|
95 |
BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" );
|
|
96 |
|
|
97 |
mDeviceStatus=0;
|
|
98 |
mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );
|
|
99 |
BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
|
|
100 |
|
42
|
101 |
|
70
|
102 |
mCombobox = 0;
|
|
103 |
mCombobox = qobject_cast<HbComboBox *>( mLoader->findWidget( "connectionCombobox" ) );
|
|
104 |
BTUI_ASSERT_X( mCombobox != 0, "bt-device-view", "connection combobox not found" );
|
42
|
105 |
|
70
|
106 |
ret = connect(mCombobox, SIGNAL(currentIndexChanged (int)),
|
|
107 |
this, SLOT(connectionPreferenceChanged(int)));
|
|
108 |
BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::BtcpuiDeviceView", "currentIndexChanged() connect failed");
|
|
109 |
|
31
|
110 |
mPair_Unpair=0;
|
57
|
111 |
mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "devicePairUnpair" ) );
|
31
|
112 |
BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
|
|
113 |
|
|
114 |
mConnect_Disconnect=0;
|
57
|
115 |
mConnect_Disconnect = qobject_cast<HbPushButton *>( mLoader->findWidget( "deviceConnectDisconnect" ) );
|
31
|
116 |
BTUI_ASSERT_X( mConnect_Disconnect != 0, "bt-device-view", "connect/disconnect button not found" );
|
|
117 |
|
|
118 |
mDeviceSetting = 0;
|
57
|
119 |
mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "deviceSettings" ) );
|
31
|
120 |
BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
|
42
|
121 |
ret = connect(mDeviceSetting, SIGNAL(clicked()), this,
|
|
122 |
SLOT(handleDeviceSetting()));
|
57
|
123 |
BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::BtcpuiDeviceView", "clicked() connect failed");
|
42
|
124 |
|
70
|
125 |
|
31
|
126 |
}
|
|
127 |
|
57
|
128 |
BtcpuiDeviceView::~BtcpuiDeviceView()
|
31
|
129 |
{
|
57
|
130 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
131 |
delete mLoader; // Also deletes all widgets that it constructed.
|
57
|
132 |
delete mAbstractDelegate;
|
|
133 |
unloadDeviceDetails();
|
|
134 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
135 |
}
|
|
136 |
|
57
|
137 |
void BtcpuiDeviceView::backToPreviousView()
|
31
|
138 |
{
|
57
|
139 |
BtcpuiBaseView::backToPreviousView();
|
47
|
140 |
unloadDeviceDetails();
|
|
141 |
}
|
|
142 |
|
57
|
143 |
void BtcpuiDeviceView::loadDeviceDetails()
|
47
|
144 |
{
|
57
|
145 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
47
|
146 |
bool ret(false);
|
57
|
147 |
unloadDeviceDetails(); // ToDo: is it necessary to delete the device view every time there is a change?
|
47
|
148 |
mDeviceDetail = new BtCpUiDeviceDetail();
|
|
149 |
ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
|
|
150 |
this, SLOT(handleDeviceSettingsChange(bool)));
|
57
|
151 |
BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::loadDeviceDetails", "deviceSettingsChanged() connect failed");
|
47
|
152 |
|
57
|
153 |
QString btAddr = mDeviceBdAddr.toString();
|
|
154 |
QString deviceName = mDeviceName->text();
|
|
155 |
mDeviceDetail->loadDeviceDetailPlugins(btAddr, deviceName);
|
|
156 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
47
|
157 |
}
|
|
158 |
|
57
|
159 |
void BtcpuiDeviceView::unloadDeviceDetails()
|
47
|
160 |
{
|
57
|
161 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
47
|
162 |
if(mDeviceDetail) {
|
57
|
163 |
mDeviceDetail->sendCloseEvent();
|
47
|
164 |
delete mDeviceDetail;
|
|
165 |
mDeviceDetail = 0;
|
|
166 |
}
|
57
|
167 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
168 |
}
|
|
169 |
|
57
|
170 |
void BtcpuiDeviceView::activateView( const QVariant& value, bool backNavi)
|
31
|
171 |
{
|
57
|
172 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
173 |
Q_UNUSED( backNavi );
|
|
174 |
// get bluetooth address of device in question
|
31
|
175 |
QModelIndex index = value.value<QModelIndex>();
|
|
176 |
mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
|
57
|
177 |
QModelIndex start = mDeviceModel->index(0,0);
|
|
178 |
QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
|
|
179 |
mDeviceIndex = indexList.at(0);
|
31
|
180 |
|
57
|
181 |
bool ret = false;
|
|
182 |
if (mMainWindow->orientation() == Qt::Horizontal) {
|
|
183 |
//mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ret);
|
|
184 |
//BTUI_ASSERT_X( ret, "bt-device-view", "Invalid docml file: landscape section problem" );
|
|
185 |
int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
|
|
186 |
if (majorRole & BtuiDevProperty::Connectable ) {
|
|
187 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ret );
|
|
188 |
BTUI_ASSERT_X( ret, "bt-device-view", "Invalid docml file: landscape section problem" );
|
|
189 |
}
|
|
190 |
else{
|
|
191 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape2", &ret );
|
|
192 |
BTUI_ASSERT_X( ret, "bt-device-view", "Invalid docml file: landscape2 section problem" );
|
|
193 |
}
|
|
194 |
}
|
|
195 |
else {
|
|
196 |
mLoader->load(BTUI_DEVICEVIEW_DOCML, "portrait", &ret);
|
|
197 |
BTUI_ASSERT_X( ret, "bt-device-view", "Invalid docml file: portrait section problem" );
|
|
198 |
|
|
199 |
|
|
200 |
}
|
|
201 |
|
31
|
202 |
updateDeviceData();
|
|
203 |
|
42
|
204 |
mDeviceSetting->setVisible(false);
|
57
|
205 |
loadDeviceDetails();
|
|
206 |
ret = false;
|
31
|
207 |
ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
208 |
this, SLOT(updateDeviceData()));
|
|
209 |
BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
|
57
|
210 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
211 |
}
|
42
|
212 |
|
57
|
213 |
void BtcpuiDeviceView::deactivateView()
|
|
214 |
{
|
|
215 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
216 |
disconnect(mDeviceModel, 0, this, 0);
|
|
217 |
unloadDeviceDetails();
|
|
218 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
219 |
}
|
|
220 |
|
57
|
221 |
void BtcpuiDeviceView::handleDeviceSettingsChange(bool status)
|
42
|
222 |
{
|
57
|
223 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
47
|
224 |
mDeviceSetting->setVisible(status);
|
57
|
225 |
mDeviceSetting->setStretched(true);
|
|
226 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
227 |
}
|
|
228 |
|
57
|
229 |
void BtcpuiDeviceView::handleDeviceSetting()
|
42
|
230 |
{
|
57
|
231 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
47
|
232 |
if(mDeviceDetail) {
|
|
233 |
mDeviceDetail->loadDeviceDetailsView();
|
|
234 |
}
|
57
|
235 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
236 |
}
|
|
237 |
|
57
|
238 |
|
42
|
239 |
// called due to real orientation change event coming from main window
|
57
|
240 |
void BtcpuiDeviceView::changeOrientation( Qt::Orientation orientation )
|
42
|
241 |
{
|
57
|
242 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
243 |
bool ok = false;
|
57
|
244 |
int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
|
42
|
245 |
if( orientation == Qt::Vertical ) {
|
|
246 |
// load "portrait" section
|
|
247 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "portrait", &ok );
|
|
248 |
BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: portrait section problem" );
|
|
249 |
} else {
|
|
250 |
// load "landscape" section
|
57
|
251 |
//mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ok );
|
|
252 |
//BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
|
|
253 |
if (majorRole & BtuiDevProperty::Connectable ) {
|
|
254 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ok );
|
|
255 |
BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
|
|
256 |
}
|
|
257 |
else{
|
|
258 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape2", &ok );
|
|
259 |
BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape2 section problem" );
|
|
260 |
}
|
42
|
261 |
}
|
57
|
262 |
setTextAndVisibilityOfButtons(majorRole);
|
|
263 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
264 |
}
|
|
265 |
|
57
|
266 |
void BtcpuiDeviceView::clearViewData()
|
31
|
267 |
{
|
57
|
268 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
269 |
mDeviceIcon->clear();
|
|
270 |
mDeviceCategory->clear();
|
|
271 |
mDeviceStatus->clear();
|
57
|
272 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
273 |
}
|
57
|
274 |
|
|
275 |
void BtcpuiDeviceView::updateDeviceData()
|
31
|
276 |
{
|
57
|
277 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
278 |
clearViewData();
|
57
|
279 |
//Get the QModelIndex of the device using the device BDAddress
|
31
|
280 |
QModelIndex start = mDeviceModel->index(0,0);
|
|
281 |
QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
|
|
282 |
mDeviceIndex = indexList.at(0);
|
|
283 |
|
|
284 |
//populate device view with device data fetched from UiModel
|
|
285 |
QString deviceName = (mDeviceModel->data(mDeviceIndex,
|
|
286 |
BtDeviceModel::NameAliasRole)).toString();
|
42
|
287 |
mDeviceName->setText(deviceName);
|
31
|
288 |
|
|
289 |
int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
|
|
290 |
|
|
291 |
int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
|
|
292 |
|
42
|
293 |
setDeviceCategory(cod, majorRole);
|
31
|
294 |
setDeviceStatus(majorRole);
|
57
|
295 |
setTextAndVisibilityOfButtons(majorRole);
|
|
296 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
297 |
}
|
|
298 |
|
57
|
299 |
void BtcpuiDeviceView::setDeviceCategory(int cod,int majorRole)
|
31
|
300 |
{
|
57
|
301 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
302 |
mDeviceCategory->setPlainText( getDeviceTypeString( cod ));
|
|
303 |
HbIcon icon =
|
|
304 |
getBadgedDeviceTypeIcon(cod, majorRole,
|
|
305 |
BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
|
|
306 |
mDeviceIcon->setIcon(icon);
|
57
|
307 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
308 |
}
|
42
|
309 |
|
57
|
310 |
void BtcpuiDeviceView::setDeviceStatus(int majorRole)
|
31
|
311 |
{
|
57
|
312 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
313 |
QString deviceStatus;
|
70
|
314 |
bool ret = false;
|
|
315 |
|
57
|
316 |
// Avoid unnecessary actions:
|
|
317 |
// The device model has been modified and need to be reflected
|
|
318 |
// in the UI however if we don't disable the signal before the UI update
|
|
319 |
// the connectionPreferenceChanged function will be called and trigger
|
|
320 |
// unnecessary update of the model by the device view.
|
70
|
321 |
ret = disconnect(mCombobox, SIGNAL(currentIndexChanged (int)),
|
57
|
322 |
this, SLOT(connectionPreferenceChanged(int)));
|
70
|
323 |
BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::setDeviceStatus", "currentIndexChanged() disconnect failed");
|
|
324 |
|
42
|
325 |
if (majorRole & BtuiDevProperty::Bonded &&
|
|
326 |
majorRole & BtuiDevProperty::Trusted &&
|
|
327 |
majorRole & BtuiDevProperty::Connected ) {
|
|
328 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
|
70
|
329 |
mCombobox->setCurrentIndex(ConnectionAutomatic );
|
57
|
330 |
mComboboxIndex = ConnectionAutomatic;
|
42
|
331 |
}
|
|
332 |
else if (majorRole & BtuiDevProperty::Bonded &&
|
|
333 |
majorRole & BtuiDevProperty::Connected ) {
|
|
334 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
|
70
|
335 |
mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
|
57
|
336 |
mComboboxIndex = ConnectionAlwaysAsk;
|
31
|
337 |
}
|
42
|
338 |
else if (majorRole & BtuiDevProperty::Bonded &&
|
|
339 |
majorRole & BtuiDevProperty::Trusted ) {
|
|
340 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
|
70
|
341 |
mCombobox->setCurrentIndex(ConnectionAutomatic );
|
57
|
342 |
mComboboxIndex = ConnectionAutomatic;
|
|
343 |
}
|
|
344 |
else if (majorRole & BtuiDevProperty::Connected &&
|
|
345 |
majorRole & BtuiDevProperty::Trusted ) {
|
|
346 |
mDeviceStatus->setPlainText(hbTrId("Trusted, Connected")); // ToDo: missing textId!
|
70
|
347 |
mCombobox->setCurrentIndex(ConnectionAutomatic );
|
57
|
348 |
mComboboxIndex = ConnectionAutomatic;
|
|
349 |
}
|
|
350 |
else if (majorRole & BtuiDevProperty::Trusted ) {
|
|
351 |
mDeviceStatus->setPlainText(hbTrId("Trusted")); // ToDo: missing textId!
|
70
|
352 |
mCombobox->setCurrentIndex(ConnectionAutomatic );
|
57
|
353 |
mComboboxIndex = ConnectionAutomatic;
|
42
|
354 |
}
|
|
355 |
else if (majorRole & BtuiDevProperty::Bonded) {
|
|
356 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
|
70
|
357 |
mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
|
57
|
358 |
mComboboxIndex = ConnectionAlwaysAsk;
|
42
|
359 |
}
|
|
360 |
else if (majorRole & BtuiDevProperty::Connected) {
|
|
361 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
|
70
|
362 |
mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
|
57
|
363 |
mComboboxIndex = ConnectionAlwaysAsk;
|
31
|
364 |
}
|
42
|
365 |
else if (majorRole & BtuiDevProperty::Blocked) {
|
|
366 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
|
70
|
367 |
mCombobox->setCurrentIndex(ConnectionBlocked );
|
57
|
368 |
mComboboxIndex = ConnectionBlocked;
|
42
|
369 |
}
|
|
370 |
else {
|
57
|
371 |
// device not paired, connected, trusted or blocked.
|
|
372 |
mDeviceStatus->setPlainText(" ");
|
70
|
373 |
mCombobox->setCurrentIndex(ConnectionAlwaysAsk );
|
57
|
374 |
mComboboxIndex = ConnectionAlwaysAsk;
|
42
|
375 |
}
|
70
|
376 |
ret = connect(mCombobox, SIGNAL(currentIndexChanged (int)),
|
57
|
377 |
this, SLOT(connectionPreferenceChanged(int)));
|
70
|
378 |
BTUI_ASSERT_X( ret, "Btui, BtcpuiDeviceView::setDeviceStatus", "currentIndexChanged() connect failed");
|
|
379 |
|
57
|
380 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
381 |
}
|
|
382 |
|
57
|
383 |
void BtcpuiDeviceView::setTextAndVisibilityOfButtons(int majorProperty)
|
42
|
384 |
{
|
57
|
385 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
386 |
disconnect(mPair_Unpair, 0, 0, 0);
|
|
387 |
disconnect(mConnect_Disconnect, 0, 0, 0);
|
47
|
388 |
|
57
|
389 |
if (majorProperty & BtuiDevProperty::Blocked) {
|
|
390 |
mPair_Unpair->setVisible(false);
|
|
391 |
mConnect_Disconnect->setVisible(false);
|
|
392 |
mDeviceSetting->setVisible(false);
|
|
393 |
return;
|
31
|
394 |
}
|
57
|
395 |
bool ret;
|
|
396 |
mPair_Unpair->setVisible(true);
|
|
397 |
mPair_Unpair->setStretched(true);
|
|
398 |
if (majorProperty & BtuiDevProperty::Bonded) {
|
|
399 |
updateButton(mPair_Unpair, "qtg_mono_bt_unpair", hbTrId("txt_bt_button_unpair"));
|
|
400 |
ret = connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(unpairDevice()));
|
|
401 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect unpair button" );
|
42
|
402 |
}
|
|
403 |
else {
|
57
|
404 |
updateButton(mPair_Unpair, "qtg_mono_bt_pair", hbTrId("txt_bt_button_pair"));
|
|
405 |
ret = connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairDevice()));
|
|
406 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect pair button" );
|
42
|
407 |
}
|
57
|
408 |
|
|
409 |
if (majorProperty & BtuiDevProperty::Connectable ) {
|
|
410 |
mConnect_Disconnect->setVisible(true);
|
|
411 |
mConnect_Disconnect->setStretched(true);
|
|
412 |
if (majorProperty & BtuiDevProperty::Connected) {
|
|
413 |
updateButton(mConnect_Disconnect, "qtg_mono_speaker_off", hbTrId("txt_bt_button_disconnect"));
|
|
414 |
ret = connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(disconnectDevice()));
|
|
415 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect disconnect button" );
|
|
416 |
}
|
|
417 |
else {
|
|
418 |
updateButton(mConnect_Disconnect, "qtg_mono_speaker", hbTrId("txt_bt_button_connect"));
|
|
419 |
ret = connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(connectDevice()));
|
|
420 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect connect button" );
|
47
|
421 |
}
|
31
|
422 |
}
|
42
|
423 |
else {
|
31
|
424 |
//it is not possible to connect, set the button invisible
|
|
425 |
mConnect_Disconnect->setVisible(false);
|
|
426 |
}
|
57
|
427 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
428 |
}
|
|
429 |
|
|
430 |
void BtcpuiDeviceView::connectionPreferenceChanged(int index)
|
|
431 |
{
|
|
432 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
433 |
if ((index >= ConnectionAutomatic)&&(index != mComboboxIndex)) {
|
|
434 |
switch ( index )
|
|
435 |
{
|
|
436 |
case ConnectionAutomatic:
|
|
437 |
setDeviceAuthorised();
|
|
438 |
break;
|
|
439 |
case ConnectionAlwaysAsk:
|
|
440 |
setDeviceAlwaysAsk();
|
|
441 |
break;
|
|
442 |
case ConnectionBlocked:
|
|
443 |
setDeviceBlocked();
|
|
444 |
break;
|
|
445 |
default:
|
|
446 |
BTUI_ASSERT_X( 0, "BtCpUiDeviceView::connectionPreferenceChanged()", "wrong index" );
|
|
447 |
}
|
|
448 |
}
|
|
449 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
450 |
}
|
|
451 |
|
|
452 |
void BtcpuiDeviceView::setDeviceAuthorised()
|
|
453 |
{
|
|
454 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
455 |
if (!mAbstractDelegate){
|
|
456 |
//if there is no other delegate running
|
|
457 |
QList<QVariant>list;
|
|
458 |
list.append(mDeviceBdAddr);
|
|
459 |
|
|
460 |
if (mComboboxIndex != ConnectionAutomatic) { // transition: (always ask|blocked) --> automatic
|
|
461 |
// unblock the device
|
|
462 |
list.append(QVariant(BtAuthorize));
|
|
463 |
}
|
|
464 |
else {
|
|
465 |
// do nothing, state is already correct
|
|
466 |
return;
|
|
467 |
}
|
|
468 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
469 |
BtDelegate::TrustDevice, mSettingModel, mDeviceModel);
|
|
470 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
471 |
this, SLOT(unpairDelegateCompleted(int)) );
|
|
472 |
mAbstractDelegate->exec(QVariant(list));
|
|
473 |
}
|
|
474 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
475 |
}
|
|
476 |
|
57
|
477 |
void BtcpuiDeviceView::setDeviceAlwaysAsk()
|
31
|
478 |
{
|
57
|
479 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
480 |
if (!mAbstractDelegate){
|
|
481 |
//if there is no other delegate running
|
|
482 |
QList<QVariant>list;
|
|
483 |
BtDelegate::EditorType type;
|
|
484 |
list.append(mDeviceBdAddr);
|
|
485 |
if (mComboboxIndex == ConnectionAutomatic) { // transition: automatic --> always ask
|
|
486 |
// unauthorize the device
|
|
487 |
list.append(QVariant(BtUnauthorize));
|
|
488 |
type = BtDelegate::UntrustDevice;
|
|
489 |
}
|
|
490 |
else if (mComboboxIndex == ConnectionBlocked) { // transition: blocked --> always ask
|
|
491 |
// unblock the device
|
|
492 |
list.append(QVariant(BtUnblock));
|
|
493 |
type = BtDelegate::UnblockDevice;
|
|
494 |
}
|
|
495 |
else {
|
|
496 |
// do nothing, state is already correct
|
|
497 |
return;
|
|
498 |
}
|
|
499 |
|
|
500 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
501 |
type, mSettingModel, mDeviceModel);
|
|
502 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
503 |
this, SLOT(unpairDelegateCompleted(int)) );
|
|
504 |
mAbstractDelegate->exec(QVariant(list));
|
|
505 |
}
|
|
506 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
507 |
}
|
|
508 |
|
57
|
509 |
void BtcpuiDeviceView::setDeviceBlocked()
|
31
|
510 |
{
|
57
|
511 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
512 |
//simple version of the delegate
|
|
513 |
//TODO: disconnect after blocking
|
|
514 |
if (!mAbstractDelegate){
|
|
515 |
//if there is no other delegate running
|
|
516 |
QList<QVariant> list;
|
|
517 |
list.append(mDeviceBdAddr);
|
|
518 |
|
|
519 |
if ( mComboboxIndex == ConnectionAutomatic ||
|
|
520 |
mComboboxIndex == ConnectionAlwaysAsk ) { // transition: automatic|always ask --> blocked
|
|
521 |
// to unauthorized the device
|
|
522 |
list.append(QVariant(BtBlock));
|
|
523 |
}
|
|
524 |
else{
|
|
525 |
// do nothing, state is already correct
|
|
526 |
return;
|
|
527 |
}
|
|
528 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
529 |
BtDelegate::BlockDevice, mSettingModel, mDeviceModel);
|
|
530 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
531 |
this, SLOT(unpairDelegateCompleted(int)) );
|
|
532 |
mAbstractDelegate->exec(QVariant(list));
|
31
|
533 |
}
|
57
|
534 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
535 |
}
|
|
536 |
|
57
|
537 |
void BtcpuiDeviceView::pairDevice()
|
31
|
538 |
{
|
57
|
539 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
540 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
541 |
{
|
|
542 |
QVariant params;
|
|
543 |
params.setValue(mDeviceIndex);
|
|
544 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
545 |
BtDelegate::PairDevice, mSettingModel, mDeviceModel);
|
|
546 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(pairDelegateCompleted(int)) );
|
31
|
547 |
mAbstractDelegate->exec(params);
|
|
548 |
}
|
57
|
549 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
550 |
}
|
|
551 |
|
57
|
552 |
void BtcpuiDeviceView::pairDelegateCompleted(int status)
|
31
|
553 |
{
|
67
|
554 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, status );
|
31
|
555 |
Q_UNUSED(status);
|
|
556 |
//TODO: handle the error here
|
|
557 |
if (mAbstractDelegate)
|
|
558 |
{
|
|
559 |
delete mAbstractDelegate;
|
|
560 |
mAbstractDelegate = 0;
|
|
561 |
}
|
57
|
562 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
563 |
}
|
|
564 |
|
57
|
565 |
void BtcpuiDeviceView::unpairDevice()
|
31
|
566 |
{
|
57
|
567 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
568 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
569 |
{
|
57
|
570 |
QList<QVariant>list;
|
|
571 |
list.append(mDeviceBdAddr);
|
|
572 |
list.append(QVariant(BtUnpair));
|
|
573 |
|
31
|
574 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
575 |
BtDelegate::UnpairDevice, mSettingModel, mDeviceModel);
|
|
576 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
|
|
577 |
SLOT(unpairDelegateCompleted(int)) );
|
|
578 |
mAbstractDelegate->exec(QVariant(list));
|
31
|
579 |
}
|
57
|
580 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
581 |
}
|
|
582 |
|
57
|
583 |
void BtcpuiDeviceView::unpairDelegateCompleted(int status)
|
31
|
584 |
{
|
57
|
585 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
586 |
Q_UNUSED(status);
|
|
587 |
//TODO: handle the error here
|
|
588 |
if (mAbstractDelegate)
|
|
589 |
{
|
|
590 |
delete mAbstractDelegate;
|
|
591 |
mAbstractDelegate = 0;
|
|
592 |
}
|
57
|
593 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
594 |
}
|
|
595 |
|
57
|
596 |
void BtcpuiDeviceView::connectDevice()
|
31
|
597 |
{
|
57
|
598 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
599 |
|
|
600 |
if (!mAbstractDelegate) { //if there is no other delegate running
|
31
|
601 |
QVariant params;
|
|
602 |
params.setValue(mDeviceIndex);
|
|
603 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
604 |
BtDelegate::ConnectService, mSettingModel, mDeviceModel);
|
|
605 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(connectDelegateCompleted(int)) );
|
31
|
606 |
mAbstractDelegate->exec(params);
|
|
607 |
}
|
57
|
608 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
609 |
}
|
|
610 |
|
57
|
611 |
void BtcpuiDeviceView::connectDelegateCompleted(int status)
|
31
|
612 |
{
|
57
|
613 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
614 |
Q_UNUSED(status);
|
57
|
615 |
if (mAbstractDelegate) {
|
31
|
616 |
delete mAbstractDelegate;
|
|
617 |
mAbstractDelegate = 0;
|
|
618 |
}
|
57
|
619 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
620 |
}
|
|
621 |
|
57
|
622 |
void BtcpuiDeviceView::disconnectDevice()
|
31
|
623 |
{
|
57
|
624 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
625 |
if (!mAbstractDelegate) { //if there is no other delegate running
|
|
626 |
QList<QVariant>list;
|
|
627 |
list.append(QVariant(ServiceLevel));
|
|
628 |
list.append(mDeviceBdAddr);
|
|
629 |
|
|
630 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
631 |
BtDelegate::DisconnectService, mSettingModel, mDeviceModel);
|
|
632 |
// todo: check return value of connect
|
67
|
633 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
|
|
634 |
SLOT(disconnectDelegateCompleted(int)) );
|
57
|
635 |
mAbstractDelegate->exec(QVariant(list));
|
|
636 |
}
|
|
637 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
638 |
}
|
|
639 |
|
57
|
640 |
void BtcpuiDeviceView::disconnectDelegateCompleted(int status)
|
31
|
641 |
{
|
57
|
642 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
643 |
Q_UNUSED(status);
|
|
644 |
if (mAbstractDelegate)
|
|
645 |
{
|
|
646 |
delete mAbstractDelegate;
|
|
647 |
mAbstractDelegate = 0;
|
47
|
648 |
}
|
57
|
649 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
47
|
650 |
}
|
|
651 |
|
57
|
652 |
void BtcpuiDeviceView::setPrevBtDeviceName()
|
47
|
653 |
{
|
57
|
654 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
47
|
655 |
QString deviceName = (mDeviceModel->data(mDeviceIndex,
|
|
656 |
BtDeviceModel::NameAliasRole)).toString();
|
|
657 |
mDeviceName->setText(deviceName);
|
57
|
658 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
659 |
}
|
|
660 |
|
57
|
661 |
void BtcpuiDeviceView::changeBtDeviceName()
|
|
662 |
{
|
|
663 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
664 |
if (!mAbstractDelegate){
|
|
665 |
//if there is no other delegate running
|
42
|
666 |
QList<QVariant>list;
|
|
667 |
|
|
668 |
QVariant index;
|
|
669 |
index.setValue(mDeviceIndex);
|
|
670 |
|
|
671 |
QVariant name;
|
|
672 |
name.setValue(mDeviceName->text());
|
|
673 |
|
|
674 |
list.append(index);
|
|
675 |
list.append(name);
|
|
676 |
|
|
677 |
QVariant params;
|
|
678 |
params.setValue(list);
|
|
679 |
|
|
680 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
70
|
681 |
BtDelegate::ChangeDeviceFriendlyName, mSettingModel, mDeviceModel);
|
|
682 |
|
|
683 |
bool ok(false);
|
|
684 |
ok =connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
685 |
this, SLOT(changeDevNameDelegateCompleted(int)) );
|
|
686 |
BTUI_ASSERT_X( ok, "BtcpuiDeviceView", "changeDevName: fail to connect signal" );
|
|
687 |
|
|
688 |
mAbstractDelegate->exec(params);
|
42
|
689 |
}
|
47
|
690 |
else {
|
|
691 |
setPrevBtDeviceName();
|
|
692 |
}
|
57
|
693 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
694 |
}
|
|
695 |
|
57
|
696 |
void BtcpuiDeviceView::changeDevNameDelegateCompleted(int status)
|
|
697 |
{
|
|
698 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
699 |
if(KErrNone != status) {
|
47
|
700 |
setPrevBtDeviceName();
|
42
|
701 |
}
|
57
|
702 |
|
|
703 |
if (mAbstractDelegate){
|
42
|
704 |
delete mAbstractDelegate;
|
|
705 |
mAbstractDelegate = 0;
|
57
|
706 |
}
|
|
707 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
708 |
}
|
57
|
709 |
|
|
710 |
void BtcpuiDeviceView::updateButton(HbPushButton *button, const QString &iconName, const QString &text)
|
|
711 |
{
|
|
712 |
HbIcon icon(iconName);
|
|
713 |
icon.setIconName(iconName);
|
|
714 |
button->setIcon(icon);
|
|
715 |
button->setText(text);
|
|
716 |
}
|