bluetoothengine/btui/btuidelegate/btdelegatepower.cpp
changeset 41 0b2439c3e397
parent 40 997690c3397a
child 52 4545c04e61e1
equal deleted inserted replaced
40:997690c3397a 41:0b2439c3e397
    65     
    65     
    66     // verify requested power is not the same as current status
    66     // verify requested power is not the same as current status
    67     if ( mReqPowerState == curPowerState ) {
    67     if ( mReqPowerState == curPowerState ) {
    68         // no need to do anything
    68         // no need to do anything
    69         emit commandCompleted( KErrNone );
    69         emit commandCompleted( KErrNone );
       
    70         return;
    70     }
    71     }
    71     
    72     
    72     // perform power on/off operation
    73     // perform power on/off operation
    73     if ( mReqPowerState == EBTPowerOff ){ 
    74     if ( mReqPowerState == EBTPowerOff ){ 
    74         switchBTOff();     
    75         switchBTOff();     
   148     CBTEngConnMan *btengConnMan = 0;
   149     CBTEngConnMan *btengConnMan = 0;
   149     TRAP(err, btengConnMan = CBTEngConnMan::NewL(this));
   150     TRAP(err, btengConnMan = CBTEngConnMan::NewL(this));
   150     Q_CHECK_PTR( btengConnMan );
   151     Q_CHECK_PTR( btengConnMan );
   151     RBTDevAddrArray devAddrArray;
   152     RBTDevAddrArray devAddrArray;
   152     err = btengConnMan->GetConnectedAddresses(devAddrArray);
   153     err = btengConnMan->GetConnectedAddresses(devAddrArray);
       
   154     if ( err != KErrNone) {
       
   155        //TODO: handle the error here
       
   156        emit commandCompleted(err);
       
   157        return;
       
   158     }
   153     int count = devAddrArray.Count();
   159     int count = devAddrArray.Count();
   154     //int count =3;
       
   155     devAddrArray.Close();
   160     devAddrArray.Close();
   156     delete btengConnMan;
   161     delete btengConnMan;
   157     if( !err &&  count> 0 ){
   162     if( count> 0 ){
   158             HbMessageBox::question( hbTrId("Turn Bluetooth off? There is an active connection." ),this, 
   163         mActiveHandling = true;
   159                         SLOT(btOffDialogClose(HbAction*)));
   164         disconnectOngoingConnections(); 
   160             
   165     }
       
   166     else{
       
   167         mActiveHandling = true;
       
   168         err = mBtengSettings->SetPowerState(EBTPowerOff);
       
   169         
       
   170         if ( err ) {
       
   171            //TODO: handle the error here
       
   172            emit commandCompleted(KErrGeneral);
   161         }
   173         }
   162         else{
       
   163             mActiveHandling = true;
       
   164             err = mBtengSettings->SetPowerState(EBTPowerOff);
       
   165             
       
   166             if ( err ) {
       
   167                //TODO: handle the error here
       
   168                emit commandCompleted(KErrGeneral);
       
   169             }
       
   170         
   174         
   171         }    
   175     }    
   172 }
   176 }
   173 
   177 /*
   174 void BtDelegatePower::btOffDialogClose(HbAction *action)
   178 void BtDelegatePower::btOffDialogClose(HbAction *action)
   175 {
   179 {
   176     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   180     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
   177     if(action == dlg->actions().at(0)) 
   181     if(action == dlg->actions().at(0)) 
   178     {
   182     {
   186         emit commandCompleted(KErrNone);
   190         emit commandCompleted(KErrNone);
   187            
   191            
   188     }     
   192     }     
   189     
   193     
   190 }
   194 }
   191 
   195 */
   192 void BtDelegatePower::disconnectOngoingConnections(){
   196 void BtDelegatePower::disconnectOngoingConnections(){
   193     if (! mDisconnectDelegate){
   197     if (! mDisconnectDelegate){
   194         mDisconnectDelegate = BtDelegateFactory::newDelegate(
   198         mDisconnectDelegate = BtDelegateFactory::newDelegate(
   195                                                 BtDelegate::Disconnect, getSettingModel(), getDeviceModel()); 
   199                                                 BtDelegate::Disconnect, getSettingModel(), getDeviceModel()); 
   196         connect( mDisconnectDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
   200         connect( mDisconnectDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );