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>
|
|
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>
|
67
|
33 |
#include <QString>
|
|
34 |
#include <QStringList>
|
|
35 |
#include <QDebug>
|
31
|
36 |
#include <bluetoothuitrace.h>
|
|
37 |
#include <btabstractdelegate.h>
|
|
38 |
#include <btdelegatefactory.h>
|
42
|
39 |
#include "btuiiconutil.h"
|
|
40 |
#include "btuidevtypemap.h"
|
57
|
41 |
#include "btqtconstants.h"
|
42
|
42 |
#include "btcpuidevicedetail.h"
|
57
|
43 |
#include "btcpuiviewmgr.h"
|
31
|
44 |
|
|
45 |
// docml to load
|
|
46 |
const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
|
|
47 |
|
67
|
48 |
|
|
49 |
// ToDo: should use base class delegate instead of mAbstractDelegate, also base class createDelegate()
|
|
50 |
// and createExecuteDelegate()
|
|
51 |
|
57
|
52 |
BtcpuiDeviceView::BtcpuiDeviceView(BtSettingModel &settingModel,
|
31
|
53 |
BtDeviceModel &deviceModel,
|
|
54 |
QGraphicsItem *parent) :
|
57
|
55 |
BtcpuiBaseView(settingModel,deviceModel,parent),
|
|
56 |
mComboboxIndex(-1), mAbstractDelegate(0), mDeviceDetail(0)
|
31
|
57 |
{
|
57
|
58 |
mDeviceIndex = QModelIndex(); // initialize to zero
|
31
|
59 |
|
|
60 |
// read view info from docml file
|
|
61 |
|
|
62 |
// Create view for the application.
|
|
63 |
// Set the name for the view. The name should be same as the view's
|
|
64 |
// name in docml.
|
|
65 |
setObjectName("bt_device_view");
|
|
66 |
|
42
|
67 |
mLoader = new HbDocumentLoader();
|
|
68 |
// Pass the view to documentloader. Document loader uses this view
|
|
69 |
// when docml is parsed, instead of creating new view.
|
31
|
70 |
QObjectList objectList;
|
|
71 |
objectList.append(this);
|
|
72 |
mLoader->setObjectTree(objectList);
|
|
73 |
|
|
74 |
bool ret = false;
|
|
75 |
|
57
|
76 |
mLoader->load( BTUI_DEVICEVIEW_DOCML, &ret );
|
31
|
77 |
// Exit if the file format is invalid
|
57
|
78 |
BTUI_ASSERT_X( ret, "bt-device-view", "Invalid docml file" );
|
42
|
79 |
// listen for orientation changes
|
|
80 |
ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
|
|
81 |
this, SLOT(changeOrientation(Qt::Orientation)));
|
|
82 |
BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView()", "connect orientationChanged() failed");
|
|
83 |
|
31
|
84 |
// assign automatically created widgets to local variables
|
57
|
85 |
|
31
|
86 |
mDeviceIcon=0;
|
|
87 |
mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) );
|
|
88 |
BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" );
|
|
89 |
|
|
90 |
mDeviceName=0;
|
42
|
91 |
mDeviceName = qobject_cast<HbLineEdit *>( mLoader->findWidget( "deviceName" ) );
|
31
|
92 |
BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" );
|
|
93 |
ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName()));
|
|
94 |
|
|
95 |
mDeviceCategory=0;
|
|
96 |
mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) );
|
|
97 |
BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" );
|
|
98 |
|
|
99 |
mDeviceStatus=0;
|
|
100 |
mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );
|
|
101 |
BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
|
|
102 |
|
42
|
103 |
|
57
|
104 |
mConnectionDataForm = 0;
|
|
105 |
mConnectionDataForm = qobject_cast<HbDataForm *>( mLoader->findWidget( "connectionCombobox" ) );
|
|
106 |
BTUI_ASSERT_X( mConnectionDataForm != 0, "bt-device-view", "connection combobox not found" );
|
42
|
107 |
|
57
|
108 |
mConnectionComboboxModel = new HbDataFormModel( this );
|
42
|
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 |
|
|
125 |
setConnectionCombobox();
|
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;
|
57
|
314 |
// Avoid unnecessary actions:
|
|
315 |
// The device model has been modified and need to be reflected
|
|
316 |
// in the UI however if we don't disable the signal before the UI update
|
|
317 |
// the connectionPreferenceChanged function will be called and trigger
|
|
318 |
// unnecessary update of the model by the device view.
|
|
319 |
mConnectionDataForm->removeConnection(mCombobox, SIGNAL(currentIndexChanged (int)),
|
|
320 |
this, SLOT(connectionPreferenceChanged(int)));
|
42
|
321 |
if (majorRole & BtuiDevProperty::Bonded &&
|
|
322 |
majorRole & BtuiDevProperty::Trusted &&
|
|
323 |
majorRole & BtuiDevProperty::Connected ) {
|
|
324 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
|
57
|
325 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
|
|
326 |
mComboboxIndex = ConnectionAutomatic;
|
42
|
327 |
}
|
|
328 |
else if (majorRole & BtuiDevProperty::Bonded &&
|
|
329 |
majorRole & BtuiDevProperty::Connected ) {
|
|
330 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
|
57
|
331 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
|
|
332 |
mComboboxIndex = ConnectionAlwaysAsk;
|
31
|
333 |
}
|
42
|
334 |
else if (majorRole & BtuiDevProperty::Bonded &&
|
|
335 |
majorRole & BtuiDevProperty::Trusted ) {
|
|
336 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
|
57
|
337 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
|
|
338 |
mComboboxIndex = ConnectionAutomatic;
|
|
339 |
}
|
|
340 |
else if (majorRole & BtuiDevProperty::Connected &&
|
|
341 |
majorRole & BtuiDevProperty::Trusted ) {
|
|
342 |
mDeviceStatus->setPlainText(hbTrId("Trusted, Connected")); // ToDo: missing textId!
|
|
343 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
|
|
344 |
mComboboxIndex = ConnectionAutomatic;
|
|
345 |
}
|
|
346 |
else if (majorRole & BtuiDevProperty::Trusted ) {
|
|
347 |
mDeviceStatus->setPlainText(hbTrId("Trusted")); // ToDo: missing textId!
|
|
348 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAutomatic );
|
|
349 |
mComboboxIndex = ConnectionAutomatic;
|
42
|
350 |
}
|
|
351 |
else if (majorRole & BtuiDevProperty::Bonded) {
|
|
352 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
|
57
|
353 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
|
|
354 |
mComboboxIndex = ConnectionAlwaysAsk;
|
42
|
355 |
}
|
|
356 |
else if (majorRole & BtuiDevProperty::Connected) {
|
|
357 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
|
57
|
358 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
|
|
359 |
mComboboxIndex = ConnectionAlwaysAsk;
|
31
|
360 |
}
|
42
|
361 |
else if (majorRole & BtuiDevProperty::Blocked) {
|
|
362 |
mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
|
57
|
363 |
mCombobox->setContentWidgetData("currentIndex", ConnectionBlocked );
|
|
364 |
mComboboxIndex = ConnectionBlocked;
|
42
|
365 |
}
|
|
366 |
else {
|
57
|
367 |
// device not paired, connected, trusted or blocked.
|
|
368 |
mDeviceStatus->setPlainText(" ");
|
|
369 |
mCombobox->setContentWidgetData("currentIndex", ConnectionAlwaysAsk );
|
|
370 |
mComboboxIndex = ConnectionAlwaysAsk;
|
42
|
371 |
}
|
57
|
372 |
mConnectionDataForm->addConnection(mCombobox, SIGNAL(currentIndexChanged (int)),
|
|
373 |
this, SLOT(connectionPreferenceChanged(int)));
|
|
374 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
375 |
}
|
|
376 |
|
57
|
377 |
void BtcpuiDeviceView::setConnectionCombobox()
|
|
378 |
{
|
|
379 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
380 |
//create a model class
|
57
|
381 |
mCombobox = mConnectionComboboxModel->appendDataFormItem(
|
|
382 |
HbDataFormModelItem::ComboBoxItem, hbTrId("txt_bt_setlabel_connection"),
|
|
383 |
mConnectionComboboxModel->invisibleRootItem());
|
31
|
384 |
|
57
|
385 |
QStringList connList;
|
|
386 |
connList.append( hbTrId("txt_bt_setlabel_bluetooth_val_automatic") );
|
|
387 |
connList.append( hbTrId("txt_bt_setlabel_bluetooth_val_always_ask") );
|
|
388 |
connList.append( hbTrId("txt_bt_setlabel_bluetooth_val_blocked") );
|
|
389 |
mCombobox->setContentWidgetData( "items", connList );
|
|
390 |
|
42
|
391 |
//set the model to the view, once model and data class are created
|
57
|
392 |
mConnectionDataForm->setModel(mConnectionComboboxModel);
|
|
393 |
mConnectionDataForm->addConnection(mCombobox, SIGNAL(currentIndexChanged (int)),
|
|
394 |
this, SLOT(connectionPreferenceChanged(int)));
|
|
395 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
396 |
}
|
|
397 |
|
57
|
398 |
void BtcpuiDeviceView::setTextAndVisibilityOfButtons(int majorProperty)
|
42
|
399 |
{
|
57
|
400 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
401 |
disconnect(mPair_Unpair, 0, 0, 0);
|
|
402 |
disconnect(mConnect_Disconnect, 0, 0, 0);
|
47
|
403 |
|
57
|
404 |
if (majorProperty & BtuiDevProperty::Blocked) {
|
|
405 |
mPair_Unpair->setVisible(false);
|
|
406 |
mConnect_Disconnect->setVisible(false);
|
|
407 |
mDeviceSetting->setVisible(false);
|
|
408 |
return;
|
31
|
409 |
}
|
57
|
410 |
bool ret;
|
|
411 |
mPair_Unpair->setVisible(true);
|
|
412 |
mPair_Unpair->setStretched(true);
|
|
413 |
if (majorProperty & BtuiDevProperty::Bonded) {
|
|
414 |
updateButton(mPair_Unpair, "qtg_mono_bt_unpair", hbTrId("txt_bt_button_unpair"));
|
|
415 |
ret = connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(unpairDevice()));
|
|
416 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect unpair button" );
|
42
|
417 |
}
|
|
418 |
else {
|
57
|
419 |
updateButton(mPair_Unpair, "qtg_mono_bt_pair", hbTrId("txt_bt_button_pair"));
|
|
420 |
ret = connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairDevice()));
|
|
421 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect pair button" );
|
42
|
422 |
}
|
57
|
423 |
|
|
424 |
if (majorProperty & BtuiDevProperty::Connectable ) {
|
|
425 |
mConnect_Disconnect->setVisible(true);
|
|
426 |
mConnect_Disconnect->setStretched(true);
|
|
427 |
if (majorProperty & BtuiDevProperty::Connected) {
|
|
428 |
updateButton(mConnect_Disconnect, "qtg_mono_speaker_off", hbTrId("txt_bt_button_disconnect"));
|
|
429 |
ret = connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(disconnectDevice()));
|
|
430 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect disconnect button" );
|
|
431 |
}
|
|
432 |
else {
|
|
433 |
updateButton(mConnect_Disconnect, "qtg_mono_speaker", hbTrId("txt_bt_button_connect"));
|
|
434 |
ret = connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(connectDevice()));
|
|
435 |
BTUI_ASSERT_X( ret, "BtcpuiDeviceView::BtcpuiDeviceView", "can't connect connect button" );
|
47
|
436 |
}
|
31
|
437 |
}
|
42
|
438 |
else {
|
31
|
439 |
//it is not possible to connect, set the button invisible
|
|
440 |
mConnect_Disconnect->setVisible(false);
|
|
441 |
}
|
57
|
442 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
443 |
}
|
|
444 |
|
|
445 |
void BtcpuiDeviceView::connectionPreferenceChanged(int index)
|
|
446 |
{
|
|
447 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
448 |
if ((index >= ConnectionAutomatic)&&(index != mComboboxIndex)) {
|
|
449 |
switch ( index )
|
|
450 |
{
|
|
451 |
case ConnectionAutomatic:
|
|
452 |
setDeviceAuthorised();
|
|
453 |
break;
|
|
454 |
case ConnectionAlwaysAsk:
|
|
455 |
setDeviceAlwaysAsk();
|
|
456 |
break;
|
|
457 |
case ConnectionBlocked:
|
|
458 |
setDeviceBlocked();
|
|
459 |
break;
|
|
460 |
default:
|
|
461 |
BTUI_ASSERT_X( 0, "BtCpUiDeviceView::connectionPreferenceChanged()", "wrong index" );
|
|
462 |
}
|
|
463 |
}
|
|
464 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
|
465 |
}
|
|
466 |
|
|
467 |
void BtcpuiDeviceView::setDeviceAuthorised()
|
|
468 |
{
|
|
469 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
470 |
if (!mAbstractDelegate){
|
|
471 |
//if there is no other delegate running
|
|
472 |
QList<QVariant>list;
|
|
473 |
list.append(mDeviceBdAddr);
|
|
474 |
|
|
475 |
if (mComboboxIndex != ConnectionAutomatic) { // transition: (always ask|blocked) --> automatic
|
|
476 |
// unblock the device
|
|
477 |
list.append(QVariant(BtAuthorize));
|
|
478 |
}
|
|
479 |
else {
|
|
480 |
// do nothing, state is already correct
|
|
481 |
return;
|
|
482 |
}
|
|
483 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
484 |
BtDelegate::TrustDevice, mSettingModel, mDeviceModel);
|
|
485 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
486 |
this, SLOT(unpairDelegateCompleted(int)) );
|
|
487 |
mAbstractDelegate->exec(QVariant(list));
|
|
488 |
}
|
|
489 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
490 |
}
|
|
491 |
|
57
|
492 |
void BtcpuiDeviceView::setDeviceAlwaysAsk()
|
31
|
493 |
{
|
57
|
494 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
495 |
if (!mAbstractDelegate){
|
|
496 |
//if there is no other delegate running
|
|
497 |
QList<QVariant>list;
|
|
498 |
BtDelegate::EditorType type;
|
|
499 |
list.append(mDeviceBdAddr);
|
|
500 |
if (mComboboxIndex == ConnectionAutomatic) { // transition: automatic --> always ask
|
|
501 |
// unauthorize the device
|
|
502 |
list.append(QVariant(BtUnauthorize));
|
|
503 |
type = BtDelegate::UntrustDevice;
|
|
504 |
}
|
|
505 |
else if (mComboboxIndex == ConnectionBlocked) { // transition: blocked --> always ask
|
|
506 |
// unblock the device
|
|
507 |
list.append(QVariant(BtUnblock));
|
|
508 |
type = BtDelegate::UnblockDevice;
|
|
509 |
}
|
|
510 |
else {
|
|
511 |
// do nothing, state is already correct
|
|
512 |
return;
|
|
513 |
}
|
|
514 |
|
|
515 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
516 |
type, mSettingModel, mDeviceModel);
|
|
517 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
518 |
this, SLOT(unpairDelegateCompleted(int)) );
|
|
519 |
mAbstractDelegate->exec(QVariant(list));
|
|
520 |
}
|
|
521 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
522 |
}
|
|
523 |
|
57
|
524 |
void BtcpuiDeviceView::setDeviceBlocked()
|
31
|
525 |
{
|
57
|
526 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
527 |
//simple version of the delegate
|
|
528 |
//TODO: disconnect after blocking
|
|
529 |
if (!mAbstractDelegate){
|
|
530 |
//if there is no other delegate running
|
|
531 |
QList<QVariant> list;
|
|
532 |
list.append(mDeviceBdAddr);
|
|
533 |
|
|
534 |
if ( mComboboxIndex == ConnectionAutomatic ||
|
|
535 |
mComboboxIndex == ConnectionAlwaysAsk ) { // transition: automatic|always ask --> blocked
|
|
536 |
// to unauthorized the device
|
|
537 |
list.append(QVariant(BtBlock));
|
|
538 |
}
|
|
539 |
else{
|
|
540 |
// do nothing, state is already correct
|
|
541 |
return;
|
|
542 |
}
|
|
543 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
544 |
BtDelegate::BlockDevice, mSettingModel, mDeviceModel);
|
|
545 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
546 |
this, SLOT(unpairDelegateCompleted(int)) );
|
|
547 |
mAbstractDelegate->exec(QVariant(list));
|
31
|
548 |
}
|
57
|
549 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
550 |
}
|
|
551 |
|
57
|
552 |
void BtcpuiDeviceView::pairDevice()
|
31
|
553 |
{
|
57
|
554 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
555 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
556 |
{
|
|
557 |
QVariant params;
|
|
558 |
params.setValue(mDeviceIndex);
|
|
559 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
560 |
BtDelegate::PairDevice, mSettingModel, mDeviceModel);
|
|
561 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(pairDelegateCompleted(int)) );
|
31
|
562 |
mAbstractDelegate->exec(params);
|
|
563 |
}
|
57
|
564 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
565 |
}
|
|
566 |
|
57
|
567 |
void BtcpuiDeviceView::pairDelegateCompleted(int status)
|
31
|
568 |
{
|
67
|
569 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, status );
|
31
|
570 |
Q_UNUSED(status);
|
|
571 |
//TODO: handle the error here
|
|
572 |
if (mAbstractDelegate)
|
|
573 |
{
|
|
574 |
delete mAbstractDelegate;
|
|
575 |
mAbstractDelegate = 0;
|
|
576 |
}
|
57
|
577 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
578 |
}
|
|
579 |
|
57
|
580 |
void BtcpuiDeviceView::unpairDevice()
|
31
|
581 |
{
|
57
|
582 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
583 |
if (!mAbstractDelegate)//if there is no other delegate running
|
|
584 |
{
|
57
|
585 |
QList<QVariant>list;
|
|
586 |
list.append(mDeviceBdAddr);
|
|
587 |
list.append(QVariant(BtUnpair));
|
|
588 |
|
31
|
589 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
590 |
BtDelegate::UnpairDevice, mSettingModel, mDeviceModel);
|
|
591 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
|
|
592 |
SLOT(unpairDelegateCompleted(int)) );
|
|
593 |
mAbstractDelegate->exec(QVariant(list));
|
31
|
594 |
}
|
57
|
595 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
596 |
}
|
|
597 |
|
57
|
598 |
void BtcpuiDeviceView::unpairDelegateCompleted(int status)
|
31
|
599 |
{
|
57
|
600 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
601 |
Q_UNUSED(status);
|
|
602 |
//TODO: handle the error here
|
|
603 |
if (mAbstractDelegate)
|
|
604 |
{
|
|
605 |
delete mAbstractDelegate;
|
|
606 |
mAbstractDelegate = 0;
|
|
607 |
}
|
57
|
608 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
609 |
}
|
|
610 |
|
57
|
611 |
void BtcpuiDeviceView::connectDevice()
|
31
|
612 |
{
|
57
|
613 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
614 |
|
|
615 |
if (!mAbstractDelegate) { //if there is no other delegate running
|
31
|
616 |
QVariant params;
|
|
617 |
params.setValue(mDeviceIndex);
|
|
618 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
619 |
BtDelegate::ConnectService, mSettingModel, mDeviceModel);
|
|
620 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(connectDelegateCompleted(int)) );
|
31
|
621 |
mAbstractDelegate->exec(params);
|
|
622 |
}
|
57
|
623 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
624 |
}
|
|
625 |
|
57
|
626 |
void BtcpuiDeviceView::connectDelegateCompleted(int status)
|
31
|
627 |
{
|
57
|
628 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
629 |
Q_UNUSED(status);
|
57
|
630 |
if (mAbstractDelegate) {
|
31
|
631 |
delete mAbstractDelegate;
|
|
632 |
mAbstractDelegate = 0;
|
|
633 |
}
|
57
|
634 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
635 |
}
|
|
636 |
|
57
|
637 |
void BtcpuiDeviceView::disconnectDevice()
|
31
|
638 |
{
|
57
|
639 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
640 |
if (!mAbstractDelegate) { //if there is no other delegate running
|
|
641 |
QList<QVariant>list;
|
|
642 |
list.append(QVariant(ServiceLevel));
|
|
643 |
list.append(mDeviceBdAddr);
|
|
644 |
|
|
645 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
|
646 |
BtDelegate::DisconnectService, mSettingModel, mDeviceModel);
|
|
647 |
// todo: check return value of connect
|
67
|
648 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this,
|
|
649 |
SLOT(disconnectDelegateCompleted(int)) );
|
57
|
650 |
mAbstractDelegate->exec(QVariant(list));
|
|
651 |
}
|
|
652 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
653 |
}
|
|
654 |
|
57
|
655 |
void BtcpuiDeviceView::disconnectDelegateCompleted(int status)
|
31
|
656 |
{
|
57
|
657 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
658 |
Q_UNUSED(status);
|
|
659 |
if (mAbstractDelegate)
|
|
660 |
{
|
|
661 |
delete mAbstractDelegate;
|
|
662 |
mAbstractDelegate = 0;
|
47
|
663 |
}
|
57
|
664 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
47
|
665 |
}
|
|
666 |
|
57
|
667 |
void BtcpuiDeviceView::setPrevBtDeviceName()
|
47
|
668 |
{
|
57
|
669 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
47
|
670 |
QString deviceName = (mDeviceModel->data(mDeviceIndex,
|
|
671 |
BtDeviceModel::NameAliasRole)).toString();
|
|
672 |
mDeviceName->setText(deviceName);
|
57
|
673 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
31
|
674 |
}
|
|
675 |
|
57
|
676 |
void BtcpuiDeviceView::changeBtDeviceName()
|
|
677 |
{
|
|
678 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
679 |
if (!mAbstractDelegate){
|
|
680 |
//if there is no other delegate running
|
42
|
681 |
QList<QVariant>list;
|
|
682 |
|
|
683 |
QVariant index;
|
|
684 |
index.setValue(mDeviceIndex);
|
|
685 |
|
|
686 |
QVariant name;
|
|
687 |
name.setValue(mDeviceName->text());
|
|
688 |
|
|
689 |
list.append(index);
|
|
690 |
list.append(name);
|
|
691 |
|
|
692 |
QVariant params;
|
|
693 |
params.setValue(list);
|
|
694 |
|
|
695 |
mAbstractDelegate = BtDelegateFactory::newDelegate(
|
57
|
696 |
BtDelegate::ChangeDeviceFriendlyName, mSettingModel, mDeviceModel);
|
|
697 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
698 |
this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
|
42
|
699 |
mAbstractDelegate->exec(params);
|
|
700 |
}
|
47
|
701 |
else {
|
|
702 |
setPrevBtDeviceName();
|
|
703 |
}
|
57
|
704 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
705 |
}
|
|
706 |
|
57
|
707 |
void BtcpuiDeviceView::changeDevNameDelegateCompleted(int status)
|
|
708 |
{
|
|
709 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
710 |
if(KErrNone != status) {
|
47
|
711 |
setPrevBtDeviceName();
|
42
|
712 |
}
|
57
|
713 |
|
|
714 |
if (mAbstractDelegate){
|
42
|
715 |
delete mAbstractDelegate;
|
|
716 |
mAbstractDelegate = 0;
|
57
|
717 |
}
|
|
718 |
BOstraceFunctionExit0(DUMMY_DEVLIST);
|
42
|
719 |
}
|
57
|
720 |
|
|
721 |
void BtcpuiDeviceView::updateButton(HbPushButton *button, const QString &iconName, const QString &text)
|
|
722 |
{
|
|
723 |
HbIcon icon(iconName);
|
|
724 |
icon.setIconName(iconName);
|
|
725 |
button->setIcon(icon);
|
|
726 |
button->setText(text);
|
|
727 |
}
|