31
|
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 "btdelegateconnect.h"
|
42
|
19 |
#include "btuiutil.h"
|
|
20 |
#include "btqtconstants.h"
|
31
|
21 |
#include <QModelIndex>
|
42
|
22 |
#include <hblabel.h>
|
31
|
23 |
#include <btsettingmodel.h>
|
|
24 |
#include <btdevicemodel.h>
|
|
25 |
#include <hbnotificationdialog.h>
|
42
|
26 |
#include <hbmessagebox.h>
|
|
27 |
#include "btuiiconutil.h"
|
|
28 |
#include "btdelegatefactory.h"
|
|
29 |
#include <bluetoothuitrace.h>
|
|
30 |
#include <e32property.h>
|
|
31 |
#include <ctsydomainpskeys.h>
|
67
|
32 |
#include <hbparameterlengthlimiter.h>
|
31
|
33 |
|
|
34 |
BtDelegateConnect::BtDelegateConnect(
|
|
35 |
BtSettingModel* settingModel,
|
|
36 |
BtDeviceModel* deviceModel, QObject *parent) :
|
42
|
37 |
BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0),
|
|
38 |
mAbstractDelegate(0), mActiveHandling(false)
|
31
|
39 |
{
|
57
|
40 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
41 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
42 |
}
|
|
43 |
|
|
44 |
BtDelegateConnect::~BtDelegateConnect()
|
|
45 |
{
|
57
|
46 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
47 |
delete mBtengConnMan;
|
57
|
48 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
49 |
}
|
|
50 |
|
|
51 |
/*!
|
|
52 |
Returns the supported editor types.
|
|
53 |
\return the sum of supported editor types
|
|
54 |
*/
|
|
55 |
int BtDelegateConnect::supportedEditorTypes() const
|
|
56 |
{
|
|
57 |
return BtDelegate::ConnectService;
|
31
|
58 |
}
|
|
59 |
|
42
|
60 |
/*!
|
|
61 |
* execute connect operation
|
|
62 |
* first check if power is on
|
|
63 |
*/
|
31
|
64 |
void BtDelegateConnect::exec( const QVariant ¶ms )
|
|
65 |
{
|
57
|
66 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
67 |
if ( mActiveHandling ) {
|
57
|
68 |
emit delegateCompleted( KErrAlreadyExists, this );
|
|
69 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
70 |
return;
|
|
71 |
}
|
|
72 |
mIndex = params.value<QModelIndex>();
|
|
73 |
mActiveHandling = true;
|
|
74 |
// save needed values from model
|
|
75 |
mDeviceName = (mIndex.data(BtDeviceModel::NameAliasRole)).toString();
|
57
|
76 |
BtTraceQString1( TRACE_DEBUG, DUMMY_DEVLIST, "device name=", mDeviceName);
|
42
|
77 |
QString addrStr = (mIndex.data(BtDeviceModel::ReadableBdaddrRole)).toString();
|
|
78 |
addrReadbleStringToSymbian( addrStr, mAddr );
|
57
|
79 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", mAddr );
|
42
|
80 |
|
|
81 |
mCod = (mIndex.data(BtDeviceModel::CoDRole)).toInt();
|
|
82 |
mMajorProperty = (mIndex.data(BtDeviceModel::MajorPropertyRole)).toInt();
|
|
83 |
|
|
84 |
// first turn on power if needed
|
|
85 |
if (!isBtPowerOn()) {
|
|
86 |
if (!mAbstractDelegate) //if there is no other delegate running
|
|
87 |
{
|
|
88 |
mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower,
|
57
|
89 |
settingModel(), deviceModel() );
|
|
90 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(powerDelegateCompleted(int)) );
|
42
|
91 |
mAbstractDelegate->exec(QVariant(BtPowerOn));
|
|
92 |
}
|
|
93 |
}
|
|
94 |
else {
|
|
95 |
// power is already on
|
|
96 |
exec_connect();
|
|
97 |
}
|
57
|
98 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
99 |
}
|
|
100 |
|
|
101 |
/*!
|
|
102 |
* power delegate has completed, continue processing
|
|
103 |
*/
|
|
104 |
void BtDelegateConnect::powerDelegateCompleted(int status)
|
|
105 |
{
|
57
|
106 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, status );
|
42
|
107 |
if (mAbstractDelegate)
|
|
108 |
{
|
|
109 |
delete mAbstractDelegate;
|
|
110 |
mAbstractDelegate = 0;
|
|
111 |
}
|
|
112 |
if ( status == KErrNone ) {
|
|
113 |
// continue connecting
|
|
114 |
exec_connect();
|
|
115 |
}
|
|
116 |
else {
|
|
117 |
// error
|
|
118 |
emitCommandComplete(status);
|
|
119 |
}
|
57
|
120 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
121 |
}
|
|
122 |
|
|
123 |
/*!
|
|
124 |
* execute connect operation
|
|
125 |
*/
|
|
126 |
void BtDelegateConnect::exec_connect()
|
|
127 |
{
|
57
|
128 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
31
|
129 |
int error = KErrNone;
|
|
130 |
|
|
131 |
if ( ! mBtengConnMan ){
|
42
|
132 |
TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
|
31
|
133 |
}
|
42
|
134 |
|
|
135 |
if ( !error ) {
|
|
136 |
TBTDeviceClass btEngDeviceClass(mCod);
|
|
137 |
error = mBtengConnMan->Connect(mAddr, btEngDeviceClass);
|
31
|
138 |
}
|
|
139 |
|
42
|
140 |
if( error ) {
|
67
|
141 |
QString prompt = HbParameterLengthLimiter(hbTrId("txt_bt_info_unable_to_connect_with_bluetooth")).arg(mDeviceName);
|
|
142 |
HbMessageBox::warning(prompt);
|
31
|
143 |
emitCommandComplete(error);
|
|
144 |
}
|
57
|
145 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
146 |
}
|
|
147 |
|
42
|
148 |
/*!
|
|
149 |
* connect callback from CBTengConnMan
|
|
150 |
*/
|
31
|
151 |
void BtDelegateConnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr,
|
|
152 |
RBTDevAddrArray* aConflicts )
|
|
153 |
{
|
57
|
154 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aErr );
|
|
155 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", aAddr );
|
42
|
156 |
// It is possible that another audio device has just connected to phone when we are
|
|
157 |
// connecting to this audio device. Or a device is connected while this command
|
|
158 |
// is idle. No handling for these cases.
|
|
159 |
if ( mAddr != aAddr || !mActiveHandling ) {
|
57
|
160 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
161 |
return;
|
|
162 |
}
|
|
163 |
|
57
|
164 |
QModelIndex conflictDevIndex;
|
42
|
165 |
// conflict could occur as well if another audio device is already connected
|
|
166 |
// since currently we don't support multiple audio device connections.
|
|
167 |
if ( aErr && aConflicts && aConflicts->Count() ) {
|
|
168 |
// get the display name of the device that is
|
|
169 |
// causing the conflict
|
57
|
170 |
|
|
171 |
addrSymbianToReadbleString(mConflictDevAddr, (*aConflicts)[0] );
|
|
172 |
QModelIndex start = deviceModel()->index(0,0);
|
|
173 |
QModelIndexList indexList = deviceModel()->match(start, BtDeviceModel::ReadableBdaddrRole,
|
|
174 |
QVariant(mConflictDevAddr));
|
|
175 |
// ToDo: change assert to normal error handling;
|
|
176 |
// is it possible that device is not in model or registry?
|
42
|
177 |
BTUI_ASSERT_X(indexList.count(), "BtDelegateConnect::ConnectComplete()", "device missing from model!");
|
57
|
178 |
conflictDevIndex = indexList.at(0);
|
42
|
179 |
|
|
180 |
// check if conflict device is being used in a call
|
|
181 |
// Note: actually only checking if *any* audio device is involved in a call, not necessarily the
|
|
182 |
// one we are concerned with here. Btaudioman does not currently support finding out the actual
|
|
183 |
// device involved in a call.
|
|
184 |
if (callOngoing()) {
|
|
185 |
HbMessageBox::warning(hbTrId("txt_bt_info_not_possible_during_a_call"));
|
|
186 |
emitCommandComplete(KErrCancel);
|
|
187 |
}
|
|
188 |
else {
|
|
189 |
// no call, check if user wants to disconnect conflict device
|
57
|
190 |
QString conflictDevName = (conflictDevIndex.data(BtDeviceModel::NameAliasRole)).toString();
|
42
|
191 |
|
|
192 |
QString questionText(hbTrId("txt_bt_info_to_connect_1_2_needs_to_be_disconnec")
|
|
193 |
.arg(mDeviceName).arg(conflictDevName));
|
|
194 |
|
51
|
195 |
HbMessageBox::question( questionText, this, SLOT(handleUserAnswer(int)),
|
57
|
196 |
HbMessageBox::Continue | HbMessageBox::Cancel );
|
42
|
197 |
}
|
|
198 |
}
|
|
199 |
else {
|
|
200 |
// command is finished
|
67
|
201 |
if(aErr){
|
|
202 |
QString prompt = HbParameterLengthLimiter(hbTrId("txt_bt_info_unable_to_connect_with_bluetooth")).arg(mDeviceName);
|
|
203 |
HbMessageBox::warning(prompt);
|
|
204 |
}
|
42
|
205 |
emitCommandComplete(aErr);
|
|
206 |
}
|
57
|
207 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
208 |
}
|
|
209 |
|
42
|
210 |
/*!
|
|
211 |
* handle user response to query about disconnecting conflict device
|
|
212 |
*/
|
51
|
213 |
void BtDelegateConnect::handleUserAnswer( int answer )
|
42
|
214 |
{
|
57
|
215 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
51
|
216 |
if( answer == HbMessageBox::Continue ) {
|
42
|
217 |
// Continue, ie. disconnect conflict device and then try reconnecting again
|
|
218 |
if (!mAbstractDelegate) //if there is no other delegate running
|
|
219 |
{
|
|
220 |
QList<QVariant>list;
|
57
|
221 |
QVariant paramSecond;
|
|
222 |
paramSecond.setValue(mConflictDevAddr);
|
|
223 |
list.append(QVariant(ServiceLevel));
|
42
|
224 |
list.append(paramSecond);
|
57
|
225 |
mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DisconnectService,
|
|
226 |
settingModel(), deviceModel() );
|
|
227 |
connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(disconnectDelegateCompleted(int)) );
|
|
228 |
mAbstractDelegate->exec(QVariant(list));
|
42
|
229 |
}
|
|
230 |
}
|
|
231 |
else {
|
|
232 |
// Cancel connect operation
|
|
233 |
emitCommandComplete(KErrCancel);
|
|
234 |
}
|
57
|
235 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
236 |
}
|
|
237 |
|
|
238 |
/*!
|
|
239 |
* returns true if phone call is ongoing
|
|
240 |
*/
|
|
241 |
bool BtDelegateConnect::callOngoing()
|
|
242 |
{
|
57
|
243 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
244 |
// ToDo: check if there exists Qt PS key for ongoing call
|
|
245 |
int callState;
|
57
|
246 |
bool retVal;
|
42
|
247 |
int err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState);
|
|
248 |
if (!err && (callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized)) {
|
57
|
249 |
retVal = false;
|
42
|
250 |
}
|
|
251 |
else {
|
57
|
252 |
retVal = true;
|
42
|
253 |
}
|
57
|
254 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, retVal );
|
|
255 |
return retVal;
|
42
|
256 |
}
|
|
257 |
|
|
258 |
/*!
|
|
259 |
* disconnecting conflict device has completed, continue connecting
|
|
260 |
*/
|
|
261 |
void BtDelegateConnect::disconnectDelegateCompleted(int status)
|
|
262 |
{
|
57
|
263 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
264 |
if (mAbstractDelegate)
|
|
265 |
{
|
|
266 |
delete mAbstractDelegate;
|
|
267 |
mAbstractDelegate = 0;
|
|
268 |
}
|
|
269 |
// finished disconnecting conflict device, now reconnect to original device
|
|
270 |
if ( status == KErrNone ) {
|
|
271 |
exec_connect();
|
|
272 |
}
|
|
273 |
else {
|
|
274 |
// disconnect failed, abort
|
|
275 |
emitCommandComplete( status );
|
|
276 |
}
|
57
|
277 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
278 |
}
|
|
279 |
|
|
280 |
/*!
|
|
281 |
* not used here
|
|
282 |
*/
|
31
|
283 |
void BtDelegateConnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
|
|
284 |
{
|
57
|
285 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aErr );
|
|
286 |
BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", aAddr );
|
31
|
287 |
Q_UNUSED(aAddr);
|
|
288 |
Q_UNUSED(aErr);
|
57
|
289 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
290 |
}
|
|
291 |
|
42
|
292 |
/*!
|
|
293 |
* cancel connect operation
|
|
294 |
* ConnectComplete() callback will be called upon completion of cancel with KErrCancel
|
|
295 |
*/
|
31
|
296 |
void BtDelegateConnect::cancel()
|
|
297 |
{
|
57
|
298 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
299 |
if ( mBtengConnMan ) {
|
|
300 |
mBtengConnMan->CancelConnect(mAddr);
|
|
301 |
}
|
57
|
302 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
31
|
303 |
}
|
|
304 |
|
42
|
305 |
/*!
|
|
306 |
* shows user notes with connection success/failure information
|
|
307 |
* cancel operation is handled without a user note
|
|
308 |
*/
|
31
|
309 |
void BtDelegateConnect::emitCommandComplete(int error)
|
|
310 |
{
|
57
|
311 |
BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );
|
|
312 |
if ( error == KErrCancel ) {
|
42
|
313 |
// no user note, return success since cancel operation completed successfully
|
|
314 |
error = KErrNone;
|
31
|
315 |
}
|
42
|
316 |
mActiveHandling = false;
|
|
317 |
|
57
|
318 |
emit delegateCompleted(error, this);
|
|
319 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, error );
|
31
|
320 |
}
|
|
321 |
|
|
322 |
|