bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp
changeset 57 5ebadcda06cb
parent 51 625f43ae9362
child 67 16e4b9007960
--- a/bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp	Fri Aug 06 16:43:21 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateconnect.cpp	Fri Sep 03 16:17:59 2010 +0300
@@ -36,12 +36,24 @@
     BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0),
     mAbstractDelegate(0), mActiveHandling(false)
 {
-    
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );   
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 BtDelegateConnect::~BtDelegateConnect()
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );   
     delete mBtengConnMan;
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
+}
+
+/*!
+    Returns the supported editor types.
+    \return the sum of supported editor types
+ */
+int BtDelegateConnect::supportedEditorTypes() const
+{
+    return BtDelegate::ConnectService;
 }
 
 /*!
@@ -50,16 +62,20 @@
  */
 void BtDelegateConnect::exec( const QVariant &params )
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );  
     if ( mActiveHandling ) {
-        emit commandCompleted( KErrAlreadyExists );
+        emit delegateCompleted( KErrAlreadyExists, this );
+        BOstraceFunctionExit1( DUMMY_DEVLIST, this );
         return;
     }
     mIndex = params.value<QModelIndex>();
     mActiveHandling = true;
     // save needed values from model
     mDeviceName = (mIndex.data(BtDeviceModel::NameAliasRole)).toString();
+    BtTraceQString1( TRACE_DEBUG, DUMMY_DEVLIST, "device name=", mDeviceName);
     QString addrStr = (mIndex.data(BtDeviceModel::ReadableBdaddrRole)).toString(); 
     addrReadbleStringToSymbian( addrStr, mAddr );  
+    BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", mAddr );
     
     mCod = (mIndex.data(BtDeviceModel::CoDRole)).toInt();
     mMajorProperty = (mIndex.data(BtDeviceModel::MajorPropertyRole)).toInt();
@@ -69,8 +85,8 @@
         if (!mAbstractDelegate) //if there is no other delegate running
         { 
             mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, 
-                    getSettingModel(), getDeviceModel() ); 
-            connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
+                    settingModel(), deviceModel() ); 
+            connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(powerDelegateCompleted(int)) );
             mAbstractDelegate->exec(QVariant(BtPowerOn));
         }
     } 
@@ -78,6 +94,7 @@
         // power is already on
         exec_connect();
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -85,9 +102,9 @@
  */
 void BtDelegateConnect::powerDelegateCompleted(int status)
 {
+    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, status );  
     if (mAbstractDelegate)
     {
-        disconnect(mAbstractDelegate);
         delete mAbstractDelegate;
         mAbstractDelegate = 0;
     }
@@ -99,6 +116,7 @@
         // error
         emitCommandComplete(status);
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -106,6 +124,7 @@
  */
 void BtDelegateConnect::exec_connect()
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );  
     int error = KErrNone;
     
     if ( ! mBtengConnMan ){
@@ -120,6 +139,7 @@
     if( error ) {
         emitCommandComplete(error);
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -128,24 +148,31 @@
 void BtDelegateConnect::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, 
                                    RBTDevAddrArray* aConflicts )
 {
+    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aErr );  
+    BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", aAddr );
     // It is possible that another audio device has just connected to phone when we are
     // connecting to this audio device. Or a device is connected while this command
     // is idle. No handling for these cases.
     if ( mAddr != aAddr || !mActiveHandling ) {  
+        BOstraceFunctionExit1( DUMMY_DEVLIST, this );
         return;
     }
     
+    QModelIndex conflictDevIndex;
     // conflict could occur as well if another audio device is already connected
     // since currently we don't support multiple audio device connections.
     if ( aErr && aConflicts && aConflicts->Count() ) {
         // get the display name of the device that is 
         // causing the conflict 
-        QString conflictDevAddr;
-        addrSymbianToReadbleString(conflictDevAddr, (*aConflicts)[0] );
-        QModelIndex start = getDeviceModel()->index(0,0);
-        QModelIndexList indexList = getDeviceModel()->match(start, BtDeviceModel::ReadableBdaddrRole, conflictDevAddr);
+        
+        addrSymbianToReadbleString(mConflictDevAddr, (*aConflicts)[0] );
+        QModelIndex start = deviceModel()->index(0,0);
+        QModelIndexList indexList = deviceModel()->match(start, BtDeviceModel::ReadableBdaddrRole, 
+                QVariant(mConflictDevAddr));
+        // ToDo:  change assert to normal error handling;  
+        // is it possible that device is not in model or registry?
         BTUI_ASSERT_X(indexList.count(), "BtDelegateConnect::ConnectComplete()", "device missing from model!");
-        mConflictDevIndex = indexList.at(0);
+        conflictDevIndex = indexList.at(0);
       
         // check if conflict device is being used in a call
         // Note:  actually only checking if *any* audio device is involved in a call, not necessarily the
@@ -157,19 +184,20 @@
         }
         else {
             // no call, check if user wants to disconnect conflict device 
-            QString conflictDevName = (mConflictDevIndex.data(BtDeviceModel::NameAliasRole)).toString();    
+            QString conflictDevName = (conflictDevIndex.data(BtDeviceModel::NameAliasRole)).toString();    
     
             QString questionText(hbTrId("txt_bt_info_to_connect_1_2_needs_to_be_disconnec")
                     .arg(mDeviceName).arg(conflictDevName));
             
             HbMessageBox::question( questionText, this, SLOT(handleUserAnswer(int)), 
-                    HbMessageBox::Continue | HbMessageBox::Cancel );       
+                    HbMessageBox::Continue | HbMessageBox::Cancel );
         }
     }
     else {
         // command is finished
         emitCommandComplete(aErr);
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -177,27 +205,27 @@
  */
 void BtDelegateConnect::handleUserAnswer( int answer )
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );  
     if( answer == HbMessageBox::Continue ) { 
         // Continue, ie. disconnect conflict device and then try reconnecting again
         if (!mAbstractDelegate) //if there is no other delegate running
         { 
             QList<QVariant>list;
-            QVariant paramFirst;
-            paramFirst.setValue(mConflictDevIndex);    
-            QVariant paramSecond(ServiceLevel);
-            list.append(paramFirst);
+            QVariant paramSecond;
+            paramSecond.setValue(mConflictDevAddr);    
+            list.append(QVariant(ServiceLevel));
             list.append(paramSecond);
-            QVariant paramsList(list);
-            mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::Disconnect, 
-                    getSettingModel(), getDeviceModel() ); 
-            connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
-            mAbstractDelegate->exec(paramsList);
+            mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DisconnectService, 
+                    settingModel(), deviceModel() ); 
+            connect( mAbstractDelegate, SIGNAL(delegateCompleted(int,BtAbstractDelegate*)), this, SLOT(disconnectDelegateCompleted(int)) );
+            mAbstractDelegate->exec(QVariant(list));
         }
     }
     else {
         // Cancel connect operation
         emitCommandComplete(KErrCancel);
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -205,15 +233,19 @@
  */
 bool BtDelegateConnect::callOngoing()
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );  
     // ToDo:  check if there exists Qt PS key for ongoing call
     int callState;
+    bool retVal;
     int err = RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState);
     if (!err && (callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized)) {
-        return false;
+        retVal = false;
     }
     else {
-        return true;
+        retVal =  true;
     }
+    BOstraceFunctionExitExt( DUMMY_DEVLIST, this, retVal );
+    return retVal;
 }
 
 /*!
@@ -221,9 +253,9 @@
  */
 void BtDelegateConnect::disconnectDelegateCompleted(int status)
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );  
     if (mAbstractDelegate)
     {
-        disconnect(mAbstractDelegate);
         delete mAbstractDelegate;
         mAbstractDelegate = 0;
     }
@@ -235,6 +267,7 @@
         // disconnect failed, abort
         emitCommandComplete( status );
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -242,8 +275,11 @@
  */
 void BtDelegateConnect::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
 {
+    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aErr );  
+    BtTraceBtAddr1( TRACE_DEBUG, DUMMY_DEVLIST, "device addr=", aAddr );
     Q_UNUSED(aAddr);
     Q_UNUSED(aErr);    
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -252,9 +288,11 @@
  */
 void BtDelegateConnect::cancel()
 {
+    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );  
     if ( mBtengConnMan ) {
         mBtengConnMan->CancelConnect(mAddr);
     }
+    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
 }
 
 /*!
@@ -263,26 +301,15 @@
  */
 void BtDelegateConnect::emitCommandComplete(int error)
 {
-    if ( error == KErrNone ) {
-        // success, show indicator with connection status
-        
-        HbIcon icon = getBadgedDeviceTypeIcon( mCod, mMajorProperty, BtuiNoCorners); 
-        QString str(hbTrId("txt_bt_dpopinfo_connected_to_1"));
-        HbNotificationDialog::launchDialog( icon, hbTrId("txt_bt_dpophead_connected"), 
-            str.arg(mDeviceName) );  
-    }
-    else if ( error == KErrCancel ) {
+    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, error );  
+    if ( error == KErrCancel ) {
         // no user note, return success since cancel operation completed successfully
         error = KErrNone;
     }
-    else {
-        // failure to connect, show user note
-        QString err(hbTrId("txt_bt_info_unable_to_connect_with_bluetooth"));
-        HbMessageBox::warning(err.arg(mDeviceName));
-    }
     mActiveHandling = false;
     
-    emit commandCompleted(error);
+    emit delegateCompleted(error, this);
+    BOstraceFunctionExitExt( DUMMY_DEVLIST, this, error );
 }