Some connection handling improvements made for daemon. Changelog updated to newest...
authoreshe <jessehakanen@gmail.com>
Tue, 15 Jun 2010 12:43:49 +0000 (13:43 +0100)
committereshe <jessehakanen@gmail.com>
Tue, 15 Jun 2010 12:43:49 +0000 (13:43 +0100)
debian/changelog
src/common/connectionmanager.cpp
src/common/connectionmanager.h
src/common/contactmanager.cpp
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/main.cpp
src/gui/buttonselector.cpp
src/gui/connectionselector.cpp
src/gui/settingsdialog.cpp

index 165227f..029e8bb 100644 (file)
@@ -1,3 +1,11 @@
+jenirok (0.2-1) unstable; urgency=low
+
+  * Architecture changed to allow easier addition of new phonebook sources.
+  * Added Norwegian phonebook (1881.no)
+  * Connection handling improved especially in cases where no 3g or wlan network is available.
+
+ -- Jesse Hakanen <jessehakanen@gmail.com>  Tue, 15 Jun 2010 13:14:57 +0100
+
 jenirok (0.1-7) unstable; urgency=low
 
   * Decreased daemon's memory usage.
index d6bddff..dfee7d6 100644 (file)
 #include <icd/dbus_api.h>
 #include "connectionmanager.h"
 
+bool ConnectionManager::connected_ = false;
 
 ConnectionManager::ConnectionManager(QObject* parent): QObject(parent),
 blocking_(true), stateReady_(false), connectionReady_(false), scanReady_(false),
-connected_(false), timeout_(false), numberOfConnections_(0),
+timeout_(false), numberOfConnections_(0),
 scannedConnections_(0), timer_(0), error_(NO_ERROR), connections_(0)
 {
     QDBusConnection systemBus = QDBusConnection::systemBus();
@@ -123,9 +124,13 @@ bool ConnectionManager::connect(QString const& id)
             error_ = UNKNOWN_ERROR;
         }
 
+        connected_ = false;
+
         return false;
     }
 
+    connected_ = true;
+
     return true;
 }
 
@@ -139,6 +144,7 @@ bool ConnectionManager::getBestConnection(Connection& connection, ConnectionType
 
     if(!scanConnections(connections))
     {
+        qDebug() << "Unable to scan connections";
         return false;
     }
 
@@ -200,24 +206,38 @@ bool ConnectionManager::getBestConnection(Connection& connection, ConnectionType
 
 bool ConnectionManager::disconnect(bool force)
 {
-    // Forced disconnect is not allowed if connection
-    // was not initialized by this class
-    if(!connected_ && force)
+    if(force)
     {
-        return false;
+        // 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");
+
+        QList<QVariant> arguments;
+        bool val = true;
+        arguments.append(QVariant(val));
+        msg.setArguments(arguments);
+
+        bool ret = QDBusConnection::systemBus().send(msg);
+
+        if(ret)
+        {
+            connected_ = false;
+        }
+
+        return ret;
     }
 
     connectionReady_ = false;
     unsigned int flags;
 
-    if(force)
-    {
-        flags = static_cast<unsigned int>(ICD_CONNECTION_FLAG_UI_EVENT);
-    }
-    else
-    {
-        flags = static_cast<unsigned int>(ICD_CONNECTION_FLAG_USER_EVENT);
-    }
+    flags = static_cast<unsigned int>(ICD_CONNECTION_FLAG_USER_EVENT);
 
     icd2interface_->call(ICD_DBUS_API_DISCONNECT_REQ, QVariant(flags));
     connected_ = false;
index 547163d..b92cca2 100644 (file)
@@ -77,7 +77,7 @@ private:
     bool stateReady_;
     bool connectionReady_;
     bool scanReady_;
-    bool connected_;
+    static bool connected_;
     bool timeout_;
     int numberOfConnections_;
     int scannedConnections_;
index 114c2d3..e387e22 100644 (file)
@@ -22,7 +22,7 @@
 namespace
 {
     const int COUNTRY_CODES[] = {358, 45, 46, 47, 354};
-    const int NUM_OF_CODES = 4;
+    const int NUM_OF_CODES = 5;
 }
 
 ContactManager::ContactManager(): book_(0)
@@ -62,7 +62,6 @@ bool ContactManager::numberExists(QString const& number)
 
     if (g_contacts == 0)
     {
-        qDebug() << "no contacts";
         return false;
     }
 
index c44e5ce..4a2f1c5 100644 (file)
@@ -77,6 +77,7 @@ bool CallListener::begin()
                        this,
                        SLOT(callTerminate()));
 
+    findGprsId();
 
     qDebug() << "Starting...";
 
@@ -208,9 +209,9 @@ void CallListener::requestFinished(QVector <Source::Result> const& results,
 
     if(closeConnection_)
     {
+        closeConnection_ = false;
         ConnectionManager cm;
         cm.disconnect(true);
-        closeConnection_ = false;
     }
 }
 
@@ -252,8 +253,6 @@ void CallListener::showResult(QString const& text)
 
 void CallListener::incomingCall(QDBusObjectPath path, QString number)
 {
-    qDebug() << "Incoming: " << number;
-
     ContactManager cm;
 
     if(!cm.numberExists(number))
@@ -284,12 +283,17 @@ void CallListener::callTerminate()
 
     if(closeConnection_)
     {
+        closeConnection_ = false;
         ConnectionManager cm;
         cm.disconnect(true);
-        closeConnection_ = false;
     }
 
     searchClose();
+
+    if(gprsId_.isEmpty())
+    {
+        findGprsId();
+    }
 }
 
 void CallListener::showDelayedResult(QString const& text, int delay)
@@ -408,6 +412,9 @@ bool CallListener::handleConnection()
 
     int cretries = 0;
 
+    bool tryGprs = (!gprsId_.isEmpty() &&
+                   (configType == Settings::ANY || configType == Settings::GPRS));
+
     while(cretries < CONNECTION_LOOKUP_RETRIES)
     {
         if(!initialized_)
@@ -420,6 +427,15 @@ bool CallListener::handleConnection()
             break;
         }
 
+        // ICD doesn't always find gprs connection during call, so
+        // try to use gprs anyway.
+        if(tryGprs && is3g())
+        {
+            best.id = gprsId_;
+            qDebug() << "Trying gprs";
+            break;
+        }
+
         qDebug() << "No connections found, retrying...";
 
         cretries++;
@@ -443,8 +459,6 @@ bool CallListener::handleConnection()
             return false;
         }
 
-        sleep(WAIT_BETWEEN_RETRIES);
-
         if(cm.connect(best.id))
         {
             break;
@@ -455,6 +469,8 @@ bool CallListener::handleConnection()
             return false;
         }
 
+        sleep(WAIT_BETWEEN_RETRIES);
+
         qDebug() << "Unable to connect, retrying...";
         retries++;
 
@@ -505,3 +521,46 @@ void CallListener::sleep(int ms)
         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",
+                                                      "/com/nokia/phone/net",
+                                                      "Phone.Net",
+                                                      "get_registration_status");
+
+    QDBusMessage rep = systemBus_.call(msg);
+
+    if(rep.type() == QDBusMessage::ErrorMessage)
+    {
+        qDebug() << "Unable to get network status";
+        return false;
+    }
+
+    uint status = rep.arguments().value(6).toUInt();
+
+    if(status & 0x10) // 3.5G (HSUPA)
+    {
+        return true;
+    }
+    else if(status & 0x08) // 3G (HSDPA)
+    {
+        return true;
+    }
+
+    // Something else
+    return false;
+}
index d842f81..2ec5b7f 100644 (file)
@@ -64,6 +64,8 @@ private:
     bool handleConnection();
     void showError(QString const& msg, int delay = 0);
     void sleep(int ms);
+    void findGprsId();
+    bool is3g();
     QString createResult(QString const& name, QString const& street, QString const& city);
     QString timedMessage_;
     Source* source_;
@@ -77,6 +79,7 @@ private:
     int retries_;
     QString currentSearch_;
     int timer_;
+    QString gprsId_;
 };
 
 #endif // CALLLISTENER_H
index f011649..863942b 100644 (file)
@@ -20,6 +20,8 @@
 #include <QtGui/QApplication>
 #include "calllistener.h"
 #include "settings.h"
+#include "connectionmanager.h"
+#include <QtCore/QDebug>
 
 int main(int argc, char *argv[])
 {
index 9c7ff39..14534ef 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <QtGui/QStandardItem>
+#include <QtCore/QDebug>
 #include "buttonselector.h"
 
 ButtonSelector::ButtonSelector(QString const& text, QWidget* parent):
@@ -47,6 +48,7 @@ void ButtonSelector::addItem(QString const& text, QVariant const& value)
     {
         selector_->setCurrentIndex(0);
     }
+
 }
 
 void ButtonSelector::clear()
index 8a148af..62657c9 100644 (file)
@@ -49,6 +49,7 @@ void ConnectionSelector::updateConnections()
     }
 
     selectByValue(currentValue);
+
     loaded_ = true;
 }
 
index 10e4e2d..9c40744 100644 (file)
@@ -107,7 +107,12 @@ autostartSelector_(0), connectionSelector_(0), tabs_(0)
 
     connectionSelector_ = new ConnectionSelector(tr("Connect automatically on"), this);
     QString selectedConnection = Settings::instance()->get("connection");
-    connectionSelector_->selectByValue(selectedConnection);
+
+    if(connectionSelector_->selectByValue(selectedConnection) &&
+       selectedConnection == "gprs")
+    {
+        connectionSelector_->updateConnections();
+    }
 
     QPushButton* submitButton = new QPushButton(tr("Save"), this);
     connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));