59 |
63 |
60 mCod = (mIndex.data(BtDeviceModel::CoDRole)).toInt(); |
64 mCod = (mIndex.data(BtDeviceModel::CoDRole)).toInt(); |
61 mMajorProperty = (mIndex.data(BtDeviceModel::MajorPropertyRole)).toInt(); |
65 mMajorProperty = (mIndex.data(BtDeviceModel::MajorPropertyRole)).toInt(); |
62 |
66 |
63 // first turn on power if needed |
67 // first turn on power if needed |
64 QModelIndex powerIndex = getSettingModel()->index(BtSettingModel::PowerStateRow, 0); |
68 if (!isBtPowerOn()) { |
65 PowerStateQtValue powerState = (PowerStateQtValue)getSettingModel()->data(powerIndex, Qt::EditRole).toInt(); |
|
66 if (powerState == BtPowerOff) { |
|
67 if (!mAbstractDelegate) //if there is no other delegate running |
69 if (!mAbstractDelegate) //if there is no other delegate running |
68 { |
70 { |
69 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, |
71 mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, |
70 getSettingModel(), getDeviceModel() ); |
72 getSettingModel(), getDeviceModel() ); |
71 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) ); |
73 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) ); |
113 if( error ) { |
120 if( error ) { |
114 emitCommandComplete(error); |
121 emitCommandComplete(error); |
115 } |
122 } |
116 } |
123 } |
117 |
124 |
|
125 /*! |
|
126 * connect callback from CBTengConnMan |
|
127 */ |
118 void BtDelegateConnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, |
128 void BtDelegateConnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, |
119 RBTDevAddrArray* aConflicts ) |
129 RBTDevAddrArray* aConflicts ) |
120 { |
130 { |
121 // It is possible that another audio device has just connected to phone when we are |
131 // It is possible that another audio device has just connected to phone when we are |
122 // connecting to this audio device. Or a device is connected while this command |
132 // connecting to this audio device. Or a device is connected while this command |
123 // is idle. No handling for these cases. |
133 // is idle. No handling for these cases. |
124 if ( mAddr != aAddr || !mActiveHandling ) { |
134 if ( mAddr != aAddr || !mActiveHandling ) { |
125 return; |
|
126 } |
|
127 |
|
128 // bteng calls ConnectComplete even if cancelConnect is called, |
|
129 // we won't signal the interested party in this case. |
|
130 // ToDo: is this needed? |
|
131 if ( aErr == KErrCancel ) { |
|
132 mActiveHandling = false; |
|
133 return; |
135 return; |
134 } |
136 } |
135 |
137 |
136 // conflict could occur as well if another audio device is already connected |
138 // conflict could occur as well if another audio device is already connected |
137 // since currently we don't support multiple audio device connections. |
139 // since currently we don't support multiple audio device connections. |
189 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) ); |
194 connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) ); |
190 mAbstractDelegate->exec(paramsList); |
195 mAbstractDelegate->exec(paramsList); |
191 } |
196 } |
192 } |
197 } |
193 else { |
198 else { |
194 // Cancel |
199 // Cancel connect operation |
195 emitCommandComplete(KErrCancel); |
200 emitCommandComplete(KErrCancel); |
196 } |
201 } |
197 } |
202 } |
198 /*! |
203 |
199 * returns true if call is ongoing |
204 /*! |
|
205 * returns true if phone call is ongoing |
200 */ |
206 */ |
201 bool BtDelegateConnect::callOngoing() |
207 bool BtDelegateConnect::callOngoing() |
202 { |
208 { |
|
209 // ToDo: check if there exists Qt PS key for ongoing call |
203 int callState; |
210 int callState; |
204 int err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState); |
211 int err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState); |
205 if (!err && (callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized)) { |
212 if (!err && (callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized)) { |
206 return false; |
213 return false; |
207 } |
214 } |
208 else { |
215 else { |
209 return true; |
216 return true; |
210 } |
217 } |
211 } |
218 } |
|
219 |
|
220 /*! |
|
221 * disconnecting conflict device has completed, continue connecting |
|
222 */ |
212 void BtDelegateConnect::disconnectDelegateCompleted(int status) |
223 void BtDelegateConnect::disconnectDelegateCompleted(int status) |
213 { |
224 { |
|
225 if (mAbstractDelegate) |
|
226 { |
|
227 disconnect(mAbstractDelegate); |
|
228 delete mAbstractDelegate; |
|
229 mAbstractDelegate = 0; |
|
230 } |
214 // finished disconnecting conflict device, now reconnect to original device |
231 // finished disconnecting conflict device, now reconnect to original device |
215 if ( status == KErrNone ) { |
232 if ( status == KErrNone ) { |
216 exec_connect(); |
233 exec_connect(); |
217 } |
234 } |
218 else { |
235 else { |
219 // disconnect failed, abort |
236 // disconnect failed, abort |
220 emitCommandComplete( status ); |
237 emitCommandComplete( status ); |
221 } |
238 } |
222 } |
239 } |
223 |
240 |
|
241 /*! |
|
242 * not used here |
|
243 */ |
224 void BtDelegateConnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) |
244 void BtDelegateConnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ) |
225 { |
245 { |
226 Q_UNUSED(aAddr); |
246 Q_UNUSED(aAddr); |
227 Q_UNUSED(aErr); |
247 Q_UNUSED(aErr); |
228 } |
248 } |
229 |
249 |
230 |
250 /*! |
|
251 * cancel connect operation |
|
252 * ConnectComplete() callback will be called upon completion of cancel with KErrCancel |
|
253 */ |
231 void BtDelegateConnect::cancel() |
254 void BtDelegateConnect::cancel() |
232 { |
255 { |
233 if ( mBtengConnMan ) { |
256 if ( mBtengConnMan ) { |
234 mBtengConnMan->CancelConnect(mAddr); |
257 mBtengConnMan->CancelConnect(mAddr); |
235 } |
258 } |
236 } |
259 } |
237 |
260 |
|
261 /*! |
|
262 * shows user notes with connection success/failure information |
|
263 * cancel operation is handled without a user note |
|
264 */ |
238 void BtDelegateConnect::emitCommandComplete(int error) |
265 void BtDelegateConnect::emitCommandComplete(int error) |
239 { |
266 { |
240 if ( error == KErrNone ) { |
267 if ( error == KErrNone ) { |
241 // success, show indicator with connection status |
268 // success, show indicator with connection status |
242 |
269 |
243 HbIcon icon = getBadgedDeviceTypeIcon( mCod, mMajorProperty, 0); // no badging required, only icon |
270 HbIcon icon = getBadgedDeviceTypeIcon( mCod, mMajorProperty, BtuiNoCorners); |
244 QString str(hbTrId("txt_bt_dpopinfo_connected_to_1")); |
271 QString str(hbTrId("txt_bt_dpopinfo_connected_to_1")); |
245 HbNotificationDialog::launchDialog( icon, hbTrId("txt_bt_dpophead_connected"), |
272 HbNotificationDialog::launchDialog( icon, hbTrId("txt_bt_dpophead_connected"), |
246 str.arg(mDeviceName) ); |
273 str.arg(mDeviceName) ); |
247 } |
274 } |
248 else if ( error == KErrCancel ) { |
275 else if ( error == KErrCancel ) { |
249 // no user note, return success |
276 // no user note, return success since cancel operation completed successfully |
250 error = KErrNone; |
277 error = KErrNone; |
251 } |
278 } |
252 else { |
279 else { |
253 // failure to connect, show user note |
280 // failure to connect, show user note |
254 QString err(hbTrId("txt_bt_info_unable_to_connect_with_bluetooth")); |
281 QString err(hbTrId("txt_bt_info_unable_to_connect_with_bluetooth")); |