Some fixes to connection manager.
[jenirok] / src / common / connectionmanager.cpp
index e8d9ad4..f7b0f32 100644 (file)
@@ -77,6 +77,12 @@ bool ConnectionManager::connect()
     icd2interface_->call(ICD_DBUS_API_CONNECT_REQ, QVariant(flags));
 
     waitSignal(&connectionReady_);
+
+    if(connected_)
+    {
+        sleep(WAIT_AFTER_CONNECT);
+    }
+
     return connected_;
 }
 
@@ -121,6 +127,8 @@ bool ConnectionManager::connect(QString const& id)
 
     connected_ = true;
 
+    sleep(WAIT_AFTER_CONNECT);
+
     return true;
 }
 
@@ -192,13 +200,6 @@ bool ConnectionManager::disconnect(bool force)
 {
     if(force)
     {
-        // Do not allow forced disconnection if connection was not started
-        // by this class.
-        if(!connected_)
-        {
-            return false;
-        }
-
         QDBusMessage msg = QDBusMessage::createSignal("/com/nokia/icd_ui",
                                                       "com.nokia.icd_ui",
                                                       "disconnect");
@@ -406,7 +407,7 @@ void ConnectionManager::scanResult(const QDBusMessage& rep)
         {
             if(status == ICD_SCAN_NEW)
             {
-                connections_->insert(i, connection);
+                connections_->replace(i, connection);
             }
 
             return;
@@ -428,15 +429,31 @@ bool ConnectionManager::waitSignal(bool* ready)
 
     killTimer(timer_);
 
+    if(timeout_)
+    {
+        qDebug() << "Connection request timed out";
+    }
+
     return *ready || !timeout_;
 }
 
+void ConnectionManager::sleep(unsigned int ms)
+{
+    timeout_ = false;
+    timer_ = startTimer(ms);
+
+    while(!timeout_)
+    {
+        QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+    }
+
+    killTimer(timer_);
+}
+
 void ConnectionManager::timerEvent(QTimerEvent* event)
 {
     Q_UNUSED(event);
     killTimer(timer_);
     timeout_ = true;
     timer_ = 0;
-
-    qDebug() << "Connection request timed out";
 }