From b7a9e838eaf1539637b2bf46a1907d7aa604bcd9 Mon Sep 17 00:00:00 2001 From: eshe Date: Tue, 15 Jun 2010 13:43:49 +0100 Subject: [PATCH] Some connection handling improvements made for daemon. Changelog updated to newest version. --- debian/changelog | 8 +++++ src/common/connectionmanager.cpp | 46 +++++++++++++++++------- src/common/connectionmanager.h | 2 +- src/common/contactmanager.cpp | 3 +- src/daemon/calllistener.cpp | 71 ++++++++++++++++++++++++++++++++++---- src/daemon/calllistener.h | 3 ++ src/daemon/main.cpp | 2 ++ src/gui/buttonselector.cpp | 2 ++ src/gui/connectionselector.cpp | 1 + src/gui/settingsdialog.cpp | 7 +++- 10 files changed, 122 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index 165227f..029e8bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Tue, 15 Jun 2010 13:14:57 +0100 + jenirok (0.1-7) unstable; urgency=low * Decreased daemon's memory usage. diff --git a/src/common/connectionmanager.cpp b/src/common/connectionmanager.cpp index d6bddff..dfee7d6 100644 --- a/src/common/connectionmanager.cpp +++ b/src/common/connectionmanager.cpp @@ -26,10 +26,11 @@ #include #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 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(ICD_CONNECTION_FLAG_UI_EVENT); - } - else - { - flags = static_cast(ICD_CONNECTION_FLAG_USER_EVENT); - } + flags = static_cast(ICD_CONNECTION_FLAG_USER_EVENT); icd2interface_->call(ICD_DBUS_API_DISCONNECT_REQ, QVariant(flags)); connected_ = false; diff --git a/src/common/connectionmanager.h b/src/common/connectionmanager.h index 547163d..b92cca2 100644 --- a/src/common/connectionmanager.h +++ b/src/common/connectionmanager.h @@ -77,7 +77,7 @@ private: bool stateReady_; bool connectionReady_; bool scanReady_; - bool connected_; + static bool connected_; bool timeout_; int numberOfConnections_; int scannedConnections_; diff --git a/src/common/contactmanager.cpp b/src/common/contactmanager.cpp index 114c2d3..e387e22 100644 --- a/src/common/contactmanager.cpp +++ b/src/common/contactmanager.cpp @@ -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; } diff --git a/src/daemon/calllistener.cpp b/src/daemon/calllistener.cpp index c44e5ce..4a2f1c5 100644 --- a/src/daemon/calllistener.cpp +++ b/src/daemon/calllistener.cpp @@ -77,6 +77,7 @@ bool CallListener::begin() this, SLOT(callTerminate())); + findGprsId(); qDebug() << "Starting..."; @@ -208,9 +209,9 @@ void CallListener::requestFinished(QVector 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 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; +} diff --git a/src/daemon/calllistener.h b/src/daemon/calllistener.h index d842f81..2ec5b7f 100644 --- a/src/daemon/calllistener.h +++ b/src/daemon/calllistener.h @@ -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 diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index f011649..863942b 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -20,6 +20,8 @@ #include #include "calllistener.h" #include "settings.h" +#include "connectionmanager.h" +#include int main(int argc, char *argv[]) { diff --git a/src/gui/buttonselector.cpp b/src/gui/buttonselector.cpp index 9c7ff39..14534ef 100644 --- a/src/gui/buttonselector.cpp +++ b/src/gui/buttonselector.cpp @@ -17,6 +17,7 @@ */ #include +#include #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() diff --git a/src/gui/connectionselector.cpp b/src/gui/connectionselector.cpp index 8a148af..62657c9 100644 --- a/src/gui/connectionselector.cpp +++ b/src/gui/connectionselector.cpp @@ -49,6 +49,7 @@ void ConnectionSelector::updateConnections() } selectByValue(currentValue); + loaded_ = true; } diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 10e4e2d..9c40744 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -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())); -- 1.7.9.5