29
|
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 "btdelegatepower.h"
|
42
|
20 |
#include "btqtconstants.h"
|
57
|
21 |
#include <btdelegatedisconnect.h>
|
42
|
22 |
#include <btdelegatefactory.h>
|
31
|
23 |
#include <btsettingmodel.h>
|
|
24 |
#include <btdevicemodel.h>
|
29
|
25 |
#include <hbmessagebox.h>
|
|
26 |
#include <bluetoothuitrace.h>
|
|
27 |
#include <hbaction.h>
|
|
28 |
|
|
29 |
/*!
|
|
30 |
Constructor.
|
|
31 |
*/
|
31
|
32 |
BtDelegatePower::BtDelegatePower(
|
|
33 |
BtSettingModel* settingModel,
|
|
34 |
BtDeviceModel* deviceModel, QObject *parent )
|
42
|
35 |
: BtAbstractDelegate( settingModel, deviceModel, parent ),
|
|
36 |
mDisconnectDelegate(0)
|
29
|
37 |
{
|
57
|
38 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
29
|
39 |
TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) );
|
|
40 |
Q_CHECK_PTR( mBtengSettings );
|
57
|
41 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
42 |
}
|
|
43 |
|
|
44 |
/*!
|
|
45 |
Destructor.
|
|
46 |
*/
|
|
47 |
BtDelegatePower::~BtDelegatePower()
|
|
48 |
{
|
57
|
49 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
29
|
50 |
delete mBtengSettings;
|
57
|
51 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
52 |
}
|
|
53 |
|
|
54 |
/*!
|
|
55 |
Returns the supported editor types.
|
|
56 |
\return the sum of supported editor types
|
|
57 |
*/
|
|
58 |
int BtDelegatePower::supportedEditorTypes() const
|
|
59 |
{
|
|
60 |
return BtDelegate::ManagePower;
|
29
|
61 |
}
|
|
62 |
|
42
|
63 |
/*!
|
|
64 |
Turns BT power on/off
|
|
65 |
param powerState is the desired power state and is of type PowerStateQtValue
|
|
66 |
*/
|
|
67 |
void BtDelegatePower::exec( const QVariant &powerState )
|
29
|
68 |
{
|
57
|
69 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
70 |
BTUI_ASSERT_X(!isExecuting(), "BtDelegatePower::exec", "operation ongoing!");
|
|
71 |
|
42
|
72 |
mReqPowerState = BtEngPowerState((PowerStateQtValue)powerState.toInt());
|
|
73 |
BTUI_ASSERT_X( (mReqPowerState == EBTPowerOff) || (mReqPowerState == EBTPowerOn),
|
|
74 |
"BtDelegatePower::exec()", "wrong power state value" );
|
|
75 |
|
|
76 |
// get current power status
|
|
77 |
TBTPowerStateValue curPowerState(EBTPowerOff);
|
57
|
78 |
int err = mBtengSettings->GetPowerState( curPowerState );
|
42
|
79 |
|
57
|
80 |
if (!err && mReqPowerState != curPowerState) {
|
|
81 |
setExecuting(true);
|
|
82 |
// perform power on/off operation
|
|
83 |
if ( mReqPowerState == EBTPowerOff ){
|
|
84 |
switchBTOff();
|
|
85 |
}
|
|
86 |
else if ( mReqPowerState == EBTPowerOn ) {
|
|
87 |
switchBTOn();
|
|
88 |
}
|
|
89 |
} else {
|
|
90 |
// no need to do anything
|
|
91 |
completeDelegateExecution(err);
|
29
|
92 |
}
|
57
|
93 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
94 |
}
|
|
95 |
|
|
96 |
void BtDelegatePower::switchBTOn()
|
|
97 |
{
|
57
|
98 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
29
|
99 |
int err = 0;
|
57
|
100 |
|
29
|
101 |
//check if device is in OFFLINE mode first
|
42
|
102 |
bool btEnabledInOffline = false;
|
|
103 |
if (checkOfflineMode(btEnabledInOffline)){ // offline mode is active
|
|
104 |
if (btEnabledInOffline){
|
29
|
105 |
// BT is allowed to be enabled in offline mode, show query.
|
42
|
106 |
HbMessageBox::question( hbTrId("txt_bt_info_trun_bluetooth_on_ini_offline_mode" ),this,
|
57
|
107 |
SLOT(btOnQuestionClose(int)), HbMessageBox::Yes | HbMessageBox::No );
|
|
108 |
} else {
|
29
|
109 |
//if BT is not allowed to be enabled in offline mode, show message and complete
|
42
|
110 |
HbMessageBox::warning( hbTrId("txt_bt_info_bluetooth_not_allowed_to_be_turned_on" ),this,
|
31
|
111 |
SLOT(btOnWarningClose()));
|
29
|
112 |
}
|
|
113 |
}
|
42
|
114 |
else { // offline mode is not active
|
|
115 |
err = mBtengSettings->SetPowerState(EBTPowerOn);
|
57
|
116 |
}
|
29
|
117 |
if ( err ) {
|
57
|
118 |
completeDelegateExecution(err);
|
29
|
119 |
}
|
57
|
120 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
121 |
}
|
|
122 |
|
51
|
123 |
void BtDelegatePower::btOnQuestionClose(int action)
|
29
|
124 |
{
|
57
|
125 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
29
|
126 |
int err = 0;
|
57
|
127 |
if(action == HbMessageBox::Yes) {
|
29
|
128 |
//user chooses "yes" for using BT in offline
|
42
|
129 |
err = mBtengSettings->SetPowerState(EBTPowerOn);
|
57
|
130 |
} else {
|
|
131 |
err = KErrCancel;
|
29
|
132 |
}
|
|
133 |
if ( err ) {
|
57
|
134 |
completeDelegateExecution(err);
|
29
|
135 |
}
|
57
|
136 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
137 |
}
|
|
138 |
|
|
139 |
void BtDelegatePower::btOnWarningClose()
|
|
140 |
{
|
57
|
141 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
142 |
completeDelegateExecution(KErrPermissionDenied);
|
|
143 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
144 |
}
|
|
145 |
|
|
146 |
void BtDelegatePower::switchBTOff()
|
|
147 |
{
|
57
|
148 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
29
|
149 |
int err = 0;
|
|
150 |
|
57
|
151 |
CBTEngConnMan *btengConnMan(0);
|
|
152 |
TRAP(err, btengConnMan = CBTEngConnMan::NewL());
|
42
|
153 |
RBTDevAddrArray devAddrArray;
|
57
|
154 |
if (!err) {
|
|
155 |
err = btengConnMan->GetConnectedAddresses(devAddrArray);
|
42
|
156 |
}
|
57
|
157 |
if (!err && devAddrArray.Count()) {
|
|
158 |
disconnectConnections();
|
|
159 |
} else if ( !err ) {
|
|
160 |
err = mBtengSettings->SetPowerState(EBTPowerOff);
|
|
161 |
}
|
42
|
162 |
devAddrArray.Close();
|
|
163 |
delete btengConnMan;
|
57
|
164 |
|
|
165 |
if (err) {
|
|
166 |
completeDelegateExecution(err);
|
42
|
167 |
}
|
57
|
168 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
169 |
}
|
|
170 |
|
57
|
171 |
void BtDelegatePower::disconnectConnections()
|
42
|
172 |
{
|
57
|
173 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
174 |
if (! mDisconnectDelegate) {
|
|
175 |
mDisconnectDelegate = new BtDelegateDisconnect(
|
|
176 |
settingModel(), deviceModel(), this);
|
|
177 |
(void) connect(mDisconnectDelegate,
|
|
178 |
SIGNAL(delegateCompleted(int,BtAbstractDelegate*)),
|
|
179 |
this, SLOT(disconnectCompleted(int,BtAbstractDelegate*)));
|
29
|
180 |
}
|
57
|
181 |
QList<QVariant> list;
|
|
182 |
list.append(QVariant( AllOngoingConnections ));
|
|
183 |
mDisconnectDelegate->exec(QVariant(list));
|
|
184 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
185 |
}
|
|
186 |
|
57
|
187 |
void BtDelegatePower::disconnectCompleted(int err, BtAbstractDelegate *delegate)
|
|
188 |
{
|
|
189 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
|
190 |
// We will turn off power even an error was returned from disconnection.
|
|
191 |
Q_UNUSED(delegate);
|
|
192 |
err = mBtengSettings->SetPowerState(EBTPowerOff);
|
|
193 |
if ( err ) {
|
|
194 |
completeDelegateExecution(err);
|
|
195 |
}
|
|
196 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
|
197 |
}
|
42
|
198 |
|
|
199 |
void BtDelegatePower::PowerStateChanged( TBTPowerStateValue aPowerState )
|
29
|
200 |
{
|
57
|
201 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
202 |
// It is possible that others change power: no handling for these cases.
|
57
|
203 |
if ( isExecuting() ) {
|
|
204 |
int err = ( mReqPowerState == aPowerState ) ? KErrNone : KErrGeneral;
|
|
205 |
completeDelegateExecution(err);
|
42
|
206 |
}
|
57
|
207 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
29
|
208 |
}
|
|
209 |
|
|
210 |
//Method derived from MBTEngSettingsObserver, no need to be implemented here
|
|
211 |
void BtDelegatePower::VisibilityModeChanged( TBTVisibilityMode aState )
|
|
212 |
{
|
57
|
213 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
29
|
214 |
Q_UNUSED( aState );
|
57
|
215 |
BOstraceFunctionExit1( DUMMY_DEVLIST, this );
|
42
|
216 |
}
|
29
|
217 |
|
42
|
218 |
/*!
|
|
219 |
Returns true if offline mode is on, parameter returns true if BT is allowed
|
|
220 |
in offline mode
|
|
221 |
*/
|
|
222 |
bool BtDelegatePower::checkOfflineMode(bool& btEnabledInOffline)
|
|
223 |
{
|
57
|
224 |
BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
|
42
|
225 |
TCoreAppUIsNetworkConnectionAllowed offLineMode;
|
|
226 |
TBTEnabledInOfflineMode btEnabled;
|
|
227 |
|
|
228 |
mBtengSettings->GetOfflineModeSettings(offLineMode, btEnabled);
|
|
229 |
|
|
230 |
btEnabledInOffline = (btEnabled == EBTEnabledInOfflineMode);
|
57
|
231 |
BOstraceFunctionExitExt( DUMMY_DEVLIST, this, offLineMode == ECoreAppUIsNetworkConnectionNotAllowed);
|
42
|
232 |
return (offLineMode == ECoreAppUIsNetworkConnectionNotAllowed);
|
|
233 |
}
|
|
234 |
|