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"
|
31
|
20 |
#include <btsettingmodel.h>
|
|
21 |
#include <btdevicemodel.h>
|
29
|
22 |
#include <hbmessagebox.h>
|
|
23 |
#include <bluetoothuitrace.h>
|
|
24 |
#include <hbaction.h>
|
|
25 |
|
|
26 |
/*!
|
|
27 |
Constructor.
|
|
28 |
*/
|
31
|
29 |
BtDelegatePower::BtDelegatePower(
|
|
30 |
BtSettingModel* settingModel,
|
|
31 |
BtDeviceModel* deviceModel, QObject *parent )
|
|
32 |
: BtAbstractDelegate( settingModel, deviceModel, parent )
|
29
|
33 |
{
|
|
34 |
TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) );
|
|
35 |
Q_CHECK_PTR( mBtengSettings );
|
|
36 |
|
|
37 |
}
|
|
38 |
|
|
39 |
/*!
|
|
40 |
Destructor.
|
|
41 |
*/
|
|
42 |
BtDelegatePower::~BtDelegatePower()
|
|
43 |
{
|
|
44 |
delete mBtengSettings;
|
|
45 |
|
|
46 |
}
|
|
47 |
|
|
48 |
void BtDelegatePower::exec( const QVariant ¶ms )
|
|
49 |
{
|
|
50 |
if (params.toInt()){//turn power OFF
|
|
51 |
|
|
52 |
switchBTOff();
|
|
53 |
}
|
|
54 |
else{//turn power ON
|
|
55 |
|
|
56 |
switchBTOn();
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
void BtDelegatePower::switchBTOn()
|
|
63 |
{
|
|
64 |
int err = 0;
|
|
65 |
|
|
66 |
//check if device is in OFFLINE mode first
|
|
67 |
TBTEnabledInOfflineMode enabledInOffline = EBTDisabledInOfflineMode;
|
|
68 |
if (checkOfflineMode(enabledInOffline)){
|
|
69 |
//if (1){
|
|
70 |
if (enabledInOffline){
|
|
71 |
//if (1){
|
|
72 |
// BT is allowed to be enabled in offline mode, show query.
|
31
|
73 |
HbMessageBox::question( tr("Turn Bluetooth on in offline mode?"),this,
|
|
74 |
SLOT(btOnQuestionClose(HbAction*)));
|
29
|
75 |
|
|
76 |
}
|
|
77 |
else{
|
|
78 |
//if BT is not allowed to be enabled in offline mode, show message and complete
|
31
|
79 |
HbMessageBox::warning(tr("Bluetooth not allowed to be turned on in offline mode"),this,
|
|
80 |
SLOT(btOnWarningClose()));
|
29
|
81 |
}
|
|
82 |
|
|
83 |
}
|
|
84 |
else{
|
|
85 |
//set BT on if the not in offline mode
|
|
86 |
err = mBtengSettings->SetPowerState((TBTPowerStateValue)(1));
|
|
87 |
}
|
|
88 |
|
|
89 |
if ( err ) {
|
|
90 |
QString info = "Unable to switch BT power ON" ;
|
|
91 |
emit commandCompleted(KErrGeneral);
|
|
92 |
}
|
|
93 |
|
|
94 |
}
|
|
95 |
|
|
96 |
void BtDelegatePower::btOnQuestionClose(HbAction *action)
|
|
97 |
{
|
|
98 |
HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
|
|
99 |
int err = 0;
|
|
100 |
if(action == dlg->actions().at(0))
|
|
101 |
{
|
|
102 |
//user chooses "yes" for using BT in offline
|
|
103 |
err = mBtengSettings->SetPowerState((TBTPowerStateValue)(1));
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
//if user chooses "NO", emits the signal
|
|
108 |
emit commandCompleted(KErrNone);
|
|
109 |
|
|
110 |
}
|
|
111 |
if ( err ) {
|
|
112 |
QString info = "Unable to switch BT power ON" ;
|
|
113 |
emit commandCompleted(KErrGeneral);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
void BtDelegatePower::btOnWarningClose()
|
|
118 |
{
|
|
119 |
emit commandCompleted(KErrNone);
|
|
120 |
}
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
void BtDelegatePower::switchBTOff()
|
|
125 |
{
|
|
126 |
int err = 0;
|
|
127 |
err = mBtengSettings->SetPowerState((TBTPowerStateValue)(0));
|
|
128 |
|
|
129 |
if ( err ) {
|
|
130 |
QString info = "Unable to switch BT power OFF" ;
|
|
131 |
emit commandCompleted(KErrGeneral);
|
|
132 |
}
|
|
133 |
|
|
134 |
}
|
|
135 |
|
|
136 |
void BtDelegatePower::btOffDialogClose(HbAction *action)
|
|
137 |
{
|
|
138 |
Q_UNUSED( action );
|
|
139 |
|
|
140 |
}
|
|
141 |
|
|
142 |
void BtDelegatePower::PowerStateChanged( TBTPowerStateValue aState )
|
|
143 |
{
|
|
144 |
Q_UNUSED( aState );
|
|
145 |
emit commandCompleted(KErrNone);
|
|
146 |
}
|
|
147 |
|
|
148 |
//Method derived from MBTEngSettingsObserver, no need to be implemented here
|
|
149 |
void BtDelegatePower::VisibilityModeChanged( TBTVisibilityMode aState )
|
|
150 |
{
|
|
151 |
Q_UNUSED( aState );
|
|
152 |
}
|
|
153 |
|
|
154 |
bool BtDelegatePower::checkOfflineMode(TBTEnabledInOfflineMode& aEnabledInOffline)
|
|
155 |
{
|
|
156 |
TCoreAppUIsNetworkConnectionAllowed offline = ECoreAppUIsNetworkConnectionAllowed;
|
|
157 |
|
|
158 |
mBtengSettings->GetOfflineModeSettings(offline, aEnabledInOffline);
|
|
159 |
return (!offline);
|
|
160 |
|
|
161 |
}
|
|
162 |
|
|
163 |
/*if (params.toBool()) { // turning power on
|
|
164 |
|
|
165 |
// find out if local device is in offline mode
|
|
166 |
QModelIndex idx = mModel->index( Btuim::OfflineMode, 0);
|
|
167 |
QVariant var = mModel->data( idx, Qt::EditRole );
|
|
168 |
bool offlineMode = var.toBool();
|
|
169 |
|
|
170 |
// find out whether BT is allowed in offline mode
|
|
171 |
var = mModel->data( idx, Btuim::SettingAdditionalParam );
|
|
172 |
bool activationAllowed = var.toBool();
|
|
173 |
|
|
174 |
if (offlineMode) {
|
|
175 |
// in offline mode
|
|
176 |
if (activationAllowed) {
|
|
177 |
HbMessageBox *messageBox = new HbMessageBox();
|
|
178 |
// BT is allowed to be enabled in offline mode, show query.
|
|
179 |
if (messageBox->question( tr("Activate Bluetooth in offline mode?") )) {
|
|
180 |
ret = mModel->setData(index, value, role);
|
|
181 |
}
|
|
182 |
delete messageBox;
|
|
183 |
}
|
|
184 |
else {
|
|
185 |
// BT is not allowed to be activated in offline mode, show note.
|
|
186 |
|
|
187 |
HbDialog *mShowOnlyPopup = new HbDialog();
|
|
188 |
mShowOnlyPopup->setAttribute(Qt::WA_DeleteOnClose);
|
|
189 |
mShowOnlyPopup->setModal(false);
|
|
190 |
mShowOnlyPopup->setBackgroundFaded(false);
|
|
191 |
mShowOnlyPopup->setDismissPolicy( HbPopup::NoDismiss );
|
|
192 |
mShowOnlyPopup->setTimeout( 5000 ); // 5 sec
|
|
193 |
HbLabel *label = new HbLabel( tr("Bluetooth is not allowed in offline mode") );
|
|
194 |
label->setAlignment(Qt::AlignCenter);
|
|
195 |
QSizeF popupSize(350,100);
|
|
196 |
mShowOnlyPopup->setMinimumSize(popupSize);
|
|
197 |
mShowOnlyPopup->setContentWidget(label);
|
|
198 |
mShowOnlyPopup->show();
|
|
199 |
}
|
|
200 |
}
|
|
201 |
else {
|
|
202 |
// not in offline mode, forward the request to model.
|
|
203 |
ret = mModel->setData(index, value, role);
|
|
204 |
}
|
|
205 |
}
|
|
206 |
else { // turning power off
|
|
207 |
// first check if existing connections
|
|
208 |
QModelIndex idx = mModel->index(Btuim::BtConnections, 0);
|
|
209 |
QVariant var = mModel->data(idx, Qt::EditRole);
|
|
210 |
bool ok;
|
|
211 |
TInt connNum = var.toInt( &ok );
|
|
212 |
BTUI_ASSERT_X( ok, "BtUiSettingsDelegate::setData", "wrong qvariant type");
|
|
213 |
if (connNum) {
|
|
214 |
// there is at least 1 active connection, show query.
|
|
215 |
HbMessageBox *messageBox = new HbMessageBox();
|
|
216 |
if (messageBox->question( tr("Turn Bluetooth off even though connections exist?") )) {
|
|
217 |
ret = mModel->setData(index, value, role);
|
|
218 |
}
|
|
219 |
delete messageBox;
|
|
220 |
}
|
|
221 |
else {
|
|
222 |
// no active connections exist, forward the request to model.
|
|
223 |
ret = mModel->setData(index, value, role);
|
|
224 |
}
|
|
225 |
}*/
|
|
226 |
//emit commandCompleted(err);
|
|
227 |
//return ret;
|
|
228 |
//return false;
|