Fixed a bug that caused connections to not being found when keyboard is closed during...
authoreshe <jessehakanen@gmail.com>
Wed, 16 Jun 2010 13:28:53 +0000 (14:28 +0100)
committereshe <jessehakanen@gmail.com>
Wed, 16 Jun 2010 13:28:53 +0000 (14:28 +0100)
src/common/connectionmanager.cpp
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/main.cpp

index 4f0d99e..e8d9ad4 100644 (file)
@@ -363,7 +363,7 @@ void ConnectionManager::scanResult(const QDBusMessage& rep)
         return;
     }
 
-    if(status != ICD_SCAN_NEW)
+    if(status != ICD_SCAN_NEW && status != ICD_SCAN_NOTIFY)
     {
         return;
     }
@@ -400,6 +400,19 @@ void ConnectionManager::scanResult(const QDBusMessage& rep)
     connection.name = args.value(8).toString();
     connection.strength = args.value(11).toInt();
 
+    for(int i = 0; i < connections_->size(); i++)
+    {
+        if(connections_->at(i).id == connection.id)
+        {
+            if(status == ICD_SCAN_NEW)
+            {
+                connections_->insert(i, connection);
+            }
+
+            return;
+        }
+    }
+
     connections_->push_back(connection);
 }
 
index 9110ff7..343ecf7 100644 (file)
@@ -145,6 +145,13 @@ void CallListener::requestFinished(QVector <Source::Result> const& results,
                                    Source::SearchDetails const& details,
                                    bool error)
 {
+    if(closeConnection_)
+    {
+        closeConnection_ = false;
+        ConnectionManager cm;
+        cm.disconnect(true);
+    }
+
     // If box is not visible, the call must have been terminated already
     if(!initialized_ || !box_->isVisible())
     {
@@ -204,13 +211,6 @@ void CallListener::requestFinished(QVector <Source::Result> const& results,
 
     retries_ = -1;
     currentSearch_ = "";
-
-    if(closeConnection_)
-    {
-        closeConnection_ = false;
-        ConnectionManager cm;
-        cm.disconnect(true);
-    }
 }
 
 QString CallListener::createResult(QString const& name, QString const& street, QString const& city)
@@ -276,14 +276,7 @@ void CallListener::callTerminate()
 {
     if(box_ && box_->isVisible())
     {
-        box_->hide();
-    }
-
-    if(closeConnection_)
-    {
-        closeConnection_ = false;
-        ConnectionManager cm;
-        cm.disconnect(true);
+        box_->close();
     }
 
     searchClose();
@@ -357,6 +350,13 @@ void CallListener::searchClose()
     delete box_;
     box_ = 0;
     label_ = 0;
+
+    if(closeConnection_)
+    {
+        closeConnection_ = false;
+        ConnectionManager cm;
+        cm.disconnect(true);
+    }
 }
 
 bool CallListener::handleConnection()
@@ -408,7 +408,7 @@ bool CallListener::handleConnection()
     bool found = false;
     int maxScans = GPRS_SCANS;
 
-    if(lookupType == ConnectionManager::WLAN)
+    if(lookupType != ConnectionManager::GPRS)
     {
         maxScans = WLAN_SCANS;
     }
@@ -475,16 +475,26 @@ bool CallListener::handleConnection()
             return false;
         }
 
-        sleep(WAIT_BETWEEN_RETRIES);
+        retries++;
 
         qDebug() << "Unable to connect, retrying...";
-        retries++;
+
+        if(retries < CONNECT_RETRIES)
+        {
+            sendRetrySignal(best.id, initialized_);
+        }
 
     }
 
-    if(initialized_ && retries >= CONNECT_RETRIES)
+    if(retries >= CONNECT_RETRIES)
     {
-        showError(tr("Unable to connect to network."));
+        sendRetrySignal(best.id, false);
+
+        if(initialized_)
+        {
+            showError(tr("Unable to connect to network."));
+        }
+
         return false;
     }
 
@@ -529,19 +539,30 @@ bool CallListener::is3g()
 
     uint status = rep.arguments().value(6).toUInt();
 
-    if(status & 0x10) // 3.5G (HSUPA)
-    {
-        return true;
-    }
-    else if(status & 0x08) // 3G (HSDPA)
+    if(status & 0x10 || status & 0x08)
     {
         return true;
     }
 
-    // Something else
     return false;
 }
 
+void CallListener::sendRetrySignal(QString const& iap, bool retry)
+{
+    QDBusMessage msg = QDBusMessage::createSignal("/com/nokia/icd_ui",
+                                                  "com.nokia.icd_ui",
+                                                  "retry");
+
+    QList<QVariant> arguments;
+    arguments.append(QVariant(iap));
+    arguments.append(QVariant(retry));
+    msg.setArguments(arguments);
+
+    QDBusConnection::systemBus().send(msg);
+
+    qDebug() << "Retry signal sent";
+}
+
 void CallListener::timerEvent(QTimerEvent* event)
 {
     Q_UNUSED(event);
index cf47953..cbc4698 100644 (file)
@@ -39,8 +39,8 @@ public:
     static const int REQUEST_TIMEOUT = 10000;
     static const int BANNER_DELAY = 350;
     static const int SEARCH_RETRIES = 2;
-    static const int CONNECT_RETRIES = 3;
-    static const int CONNECTION_LOOKUP_RETRIES = 10;
+    static const int CONNECT_RETRIES = 2;
+    static const int CONNECTION_LOOKUP_RETRIES = 8;
     static const int GPRS_SCANS = 2;
     static const int WLAN_SCANS = 5;
     static const int WAIT_BETWEEN_RETRIES = 500;
@@ -67,6 +67,7 @@ private:
     void showError(QString const& msg, int delay = 0);
     bool is3g();
     void sleep(int ms);
+    void sendRetrySignal(QString const& iap, bool retry);
     QString createResult(QString const& name, QString const& street, QString const& city);
     QString timedMessage_;
     Source* source_;
index 3d3b672..69964f3 100644 (file)
@@ -20,7 +20,7 @@
 #include <QtGui/QApplication>
 #include "calllistener.h"
 #include "settings.h"
-#include "connectionmanager.h"
+
 
 int main(int argc, char *argv[])
 {