42
|
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 |
|
|
19 |
#include "btdelegateinquiry.h"
|
|
20 |
#include "btdelegatefactory.h"
|
|
21 |
#include "btqtconstants.h"
|
|
22 |
|
|
23 |
#include <btsettingmodel.h>
|
|
24 |
#include <btdevicemodel.h>
|
|
25 |
#include <bluetoothuitrace.h>
|
|
26 |
|
|
27 |
|
|
28 |
BtDelegateInquiry::BtDelegateInquiry(
|
|
29 |
BtSettingModel* settingModel,
|
|
30 |
BtDeviceModel* deviceModel, QObject* parent )
|
|
31 |
:BtAbstractDelegate( settingModel, deviceModel, parent )
|
|
32 |
{
|
|
33 |
mAbstractDelegate = NULL;
|
|
34 |
}
|
|
35 |
|
|
36 |
BtDelegateInquiry::~BtDelegateInquiry()
|
|
37 |
{
|
|
38 |
|
|
39 |
}
|
|
40 |
|
|
41 |
void BtDelegateInquiry::exec( const QVariant& params )
|
|
42 |
{
|
|
43 |
Q_UNUSED(params);
|
|
44 |
|
|
45 |
if(isBtPowerOn()) {
|
|
46 |
exec_inquiry();
|
|
47 |
}
|
|
48 |
else {
|
|
49 |
//If Bt Power is off, switch it on and then perform pairing.
|
|
50 |
//todo: Do we ask for user confirmation here..?
|
|
51 |
if (!mAbstractDelegate) {
|
|
52 |
mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower,
|
|
53 |
getSettingModel(), getDeviceModel() );
|
|
54 |
connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
|
|
55 |
mAbstractDelegate->exec(QVariant(BtPowerOn));
|
|
56 |
}
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
void BtDelegateInquiry::powerDelegateCompleted(int error)
|
|
61 |
{
|
|
62 |
if (mAbstractDelegate) {
|
|
63 |
disconnect(mAbstractDelegate);
|
|
64 |
delete mAbstractDelegate;
|
|
65 |
mAbstractDelegate = 0;
|
|
66 |
}
|
|
67 |
if ( error == KErrNone ) {
|
|
68 |
exec_inquiry();
|
|
69 |
}
|
|
70 |
else {
|
|
71 |
// error
|
|
72 |
emit commandCompleted(error);
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
void BtDelegateInquiry::exec_inquiry()
|
|
77 |
{
|
|
78 |
bool err = getDeviceModel()->searchDevice();
|
|
79 |
|
|
80 |
emit commandCompleted(err); // in case of error, passing original error back
|
|
81 |
}
|
|
82 |
|
|
83 |
void BtDelegateInquiry::cancel()
|
|
84 |
{
|
|
85 |
getDeviceModel()->cancelSearchDevice();
|
|
86 |
}
|