bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp
changeset 41 0b2439c3e397
parent 40 997690c3397a
child 52 4545c04e61e1
equal deleted inserted replaced
40:997690c3397a 41:0b2439c3e397
    42 BtDelegateConnect::~BtDelegateConnect()
    42 BtDelegateConnect::~BtDelegateConnect()
    43 {
    43 {
    44     delete mBtengConnMan;
    44     delete mBtengConnMan;
    45 }
    45 }
    46 
    46 
       
    47 /*!
       
    48  * execute connect operation
       
    49  *    first check if power is on
       
    50  */
    47 void BtDelegateConnect::exec( const QVariant &params )
    51 void BtDelegateConnect::exec( const QVariant &params )
    48 {
    52 {
    49     if ( mActiveHandling ) {
    53     if ( mActiveHandling ) {
    50         emit commandCompleted( KErrAlreadyExists );
    54         emit commandCompleted( KErrAlreadyExists );
    51         return;
    55         return;
    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)) );
    76         // power is already on
    78         // power is already on
    77         exec_connect();
    79         exec_connect();
    78     }
    80     }
    79 }
    81 }
    80 
    82 
       
    83 /*!
       
    84  * power delegate has completed, continue processing
       
    85  */
    81 void BtDelegateConnect::powerDelegateCompleted(int status)
    86 void BtDelegateConnect::powerDelegateCompleted(int status)
    82 {
    87 {
    83     //ToDo: Error handling here 
       
    84     if (mAbstractDelegate)
    88     if (mAbstractDelegate)
    85     {
    89     {
    86         disconnect(mAbstractDelegate);
    90         disconnect(mAbstractDelegate);
    87         delete mAbstractDelegate;
    91         delete mAbstractDelegate;
    88         mAbstractDelegate = 0;
    92         mAbstractDelegate = 0;
    95         // error
    99         // error
    96         emitCommandComplete(status);
   100         emitCommandComplete(status);
    97     }
   101     }
    98 }
   102 }
    99 
   103 
       
   104 /*!
       
   105  * execute connect operation
       
   106  */
   100 void BtDelegateConnect::exec_connect()
   107 void BtDelegateConnect::exec_connect()
   101 {
   108 {
   102     int error = KErrNone;
   109     int error = KErrNone;
   103     
   110     
   104     if ( ! mBtengConnMan ){
   111     if ( ! mBtengConnMan ){
   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.
   168         // command is finished
   170         // command is finished
   169         emitCommandComplete(aErr);
   171         emitCommandComplete(aErr);
   170     }
   172     }
   171 }
   173 }
   172 
   174 
       
   175 /*!
       
   176  * handle user response to query about disconnecting conflict device
       
   177  */
   173 void BtDelegateConnect::handleUserAnswer( HbAction* answer )
   178 void BtDelegateConnect::handleUserAnswer( HbAction* answer )
   174 {
   179 {
   175     HbMessageBox* dlg = static_cast<HbMessageBox*>( sender() );
   180     HbMessageBox* dlg = static_cast<HbMessageBox*>( sender() );
   176     if( dlg->actions().first() == answer ) { 
   181     if( dlg->actions().first() == answer ) { 
   177         // Continue, ie. disconnect conflict device and then try reconnecting again
   182         // Continue, ie. disconnect conflict device and then try reconnecting again
   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"));