Fixed a bug that caused wlan connections to not being found in daemon.
[jenirok] / src / daemon / calllistener.cpp
index 4a2f1c5..9110ff7 100644 (file)
@@ -77,8 +77,6 @@ bool CallListener::begin()
                        this,
                        SLOT(callTerminate()));
 
-    findGprsId();
-
     qDebug() << "Starting...";
 
     return true;
@@ -289,11 +287,6 @@ void CallListener::callTerminate()
     }
 
     searchClose();
-
-    if(gprsId_.isEmpty())
-    {
-        findGprsId();
-    }
 }
 
 void CallListener::showDelayedResult(QString const& text, int delay)
@@ -411,9 +404,14 @@ bool CallListener::handleConnection()
     }
 
     int cretries = 0;
+    int scans = 0;
+    bool found = false;
+    int maxScans = GPRS_SCANS;
 
-    bool tryGprs = (!gprsId_.isEmpty() &&
-                   (configType == Settings::ANY || configType == Settings::GPRS));
+    if(lookupType == ConnectionManager::WLAN)
+    {
+        maxScans = WLAN_SCANS;
+    }
 
     while(cretries < CONNECTION_LOOKUP_RETRIES)
     {
@@ -422,26 +420,32 @@ bool CallListener::handleConnection()
             return false;
         }
 
-        if(cm.getBestConnection(best, lookupType))
+        if(scans < maxScans)
         {
-            break;
+            if(cm.getBestConnection(best, lookupType))
+            {
+                found = true;
+            }
+
+            scans++;
         }
 
-        // ICD doesn't always find gprs connection during call, so
-        // try to use gprs anyway.
-        if(tryGprs && is3g())
+        // If there is only gprs connection available,
+        // make sure that we are on 3g network
+        if(found && (best.type != ConnectionManager::GPRS || is3g()))
         {
-            best.id = gprsId_;
-            qDebug() << "Trying gprs";
             break;
         }
 
+        if(found)
+        {
+            sleep(WAIT_BETWEEN_RETRIES);
+        }
+
         qDebug() << "No connections found, retrying...";
 
         cretries++;
 
-        sleep(WAIT_BETWEEN_RETRIES);
-
     }
 
     if(cretries >= CONNECTION_LOOKUP_RETRIES)
@@ -459,6 +463,8 @@ bool CallListener::handleConnection()
             return false;
         }
 
+        qDebug() << "Connecting to " << best.name;
+
         if(cm.connect(best.id))
         {
             break;
@@ -488,6 +494,12 @@ bool CallListener::handleConnection()
 void CallListener::showError(QString const& msg, int timeout)
 {
     qDebug() << "Error: " << msg;
+
+    if(!initialized_ || !box_)
+    {
+        return;
+    }
+
     box_->setTimeout(ERROR_BANNER_TIMEOUT);
 
     if(timeout)
@@ -500,41 +512,6 @@ void CallListener::showError(QString const& msg, int timeout)
     }
 }
 
-void CallListener::timerEvent(QTimerEvent* event)
-{
-    Q_UNUSED(event);
-    killTimer(timer_);
-    timer_ = 0;
-}
-
-void CallListener::sleep(int ms)
-{
-    if(timer_)
-    {
-        killTimer(timer_);
-    }
-
-    timer_ = startTimer(ms);
-
-    while(timer_)
-    {
-        QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
-    }
-}
-
-void CallListener::findGprsId()
-{
-    ConnectionManager cm;
-
-    QList<ConnectionManager::Connection> connections;
-
-    if(cm.scanConnections(connections, ConnectionManager::GPRS) &&
-       connections.size() > 0)
-    {
-        gprsId_ = connections.at(0).id;
-    }
-}
-
 bool CallListener::is3g()
 {
     QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.phone.net",
@@ -564,3 +541,25 @@ bool CallListener::is3g()
     // Something else
     return false;
 }
+
+void CallListener::timerEvent(QTimerEvent* event)
+{
+    Q_UNUSED(event);
+    killTimer(timer_);
+    timer_ = 0;
+}
+
+void CallListener::sleep(int ms)
+{
+    if(timer_)
+    {
+        killTimer(timer_);
+    }
+
+    timer_ = startTimer(ms);
+
+    while(timer_)
+    {
+        QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+    }
+}