bluetoothengine/btui/btuidelegate/btdelegateInquiry.cpp
changeset 40 997690c3397a
parent 33 837dcc42fd6a
child 41 0b2439c3e397
--- a/bluetoothengine/btui/btuidelegate/btdelegateInquiry.cpp	Fri Jun 11 13:48:51 2010 +0300
+++ b/bluetoothengine/btui/btuidelegate/btdelegateInquiry.cpp	Wed Jun 23 18:23:52 2010 +0300
@@ -17,6 +17,9 @@
 
 
 #include "btdelegateinquiry.h"
+#include "btdelegatefactory.h"
+#include "btqtconstants.h"
+
 #include <btsettingmodel.h>
 #include <btdevicemodel.h>
 #include <bluetoothuitrace.h>
@@ -27,6 +30,7 @@
         BtDeviceModel* deviceModel, QObject* parent )
     :BtAbstractDelegate( settingModel, deviceModel, parent )
 {
+    mAbstractDelegate = NULL;
 }
 
 BtDelegateInquiry::~BtDelegateInquiry()
@@ -38,6 +42,39 @@
 {
     Q_UNUSED(params);
     
+    if(isBtPowerOn()) {
+        exec_inquiry();
+    }
+    else {
+        //If Bt Power is off, switch it on and then perform pairing.
+        //todo: Do we ask for user confirmation here..?
+        if (!mAbstractDelegate) { 
+            mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, 
+                    getSettingModel(), getDeviceModel() ); 
+            connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
+            mAbstractDelegate->exec(QVariant(BtPowerOn));
+        }
+    }
+}
+
+void BtDelegateInquiry::powerDelegateCompleted(int error)
+{
+    if (mAbstractDelegate) {
+        disconnect(mAbstractDelegate);
+        delete mAbstractDelegate;
+        mAbstractDelegate = 0;
+    }
+    if ( error == KErrNone ) {
+        exec_inquiry();
+    } 
+    else {
+        // error
+        emit commandCompleted(error);
+    }
+}
+
+void BtDelegateInquiry::exec_inquiry()
+{
     bool err = getDeviceModel()->searchDevice();
     if (!err) {
         // TODO - Verify the error code to be used.