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