src/hbcore/devicedialogbase/hbdevicedialogsym_p.cpp
changeset 28 b7da29130b0e
parent 5 627c4a0fd0e7
child 30 80e4d18b72f5
--- a/src/hbcore/devicedialogbase/hbdevicedialogsym_p.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/devicedialogbase/hbdevicedialogsym_p.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -108,7 +108,53 @@
             return KErrNoMemory;
         }
     }
+
     int error = mHbSession.Connect();
+        
+    TRACE_EXIT_ARGS("error" << error)
+    return error;
+}
+
+/*!
+    \internal
+
+    Connects to server asynchronously.
+*/
+
+int HbDeviceDialogPrivate::connect()
+{
+    if (!iBuffer) {
+        TRAP_IGNORE(iBuffer = HBufC8::NewL(64));
+        if (iBuffer) {
+            iDataPtr.Set(iBuffer->Des());
+        } else {
+          TRACE_EXIT_ARGS("error " << KErrNoMemory)
+            return KErrNoMemory;
+        }
+    }
+    
+    int error(HbDeviceDialogNoError);
+    
+    if (!IsActive() && !iConnecting) {
+        bool connected = mHbSession.Handle() != 0;
+        error = mHbSession.Connect(&iStatus);    
+
+        // If not connected yet, connect and wait for eventloop to stop. Eventloop is
+        // stopped in the RunL funtion.
+        if (error == KErrNone && !connected && !mEventLoop) {
+            iConnecting = ETrue;
+            SetActive();
+            QPointer<HbDeviceDialog> guard = q_ptr;
+            QEventLoop eventLoop;
+            mEventLoop = &eventLoop;
+            error = eventLoop.exec(QEventLoop::AllEvents);
+            error = symToDeviceDialogError(error);
+            if (guard.isNull()) {
+                return false;
+            }
+            mEventLoop = 0;
+        }
+    }
     TRACE_EXIT_ARGS("error" << error)
     return error;
 }
@@ -299,6 +345,13 @@
     TRACE_ENTRY
     TInt completionCode = iStatus.Int();
     int errorCode = symToDeviceDialogError(completionCode);
+    if (iConnecting) {
+        iConnecting = EFalse;
+        if (mEventLoop && mEventLoop->isRunning()) {
+            mEventLoop->exit(errorCode);
+        }
+        return;
+    }
 
     if (completionCode < KErrNone) {
         // Any Symbian error, stop requesting