From 4a9690bd6f3d972d36976863607f9353a5d62301 Mon Sep 17 00:00:00 2001 From: eshe Date: Thu, 10 Jun 2010 20:06:38 +0100 Subject: [PATCH] Connection handling improved again. Added ability to bybass general Maemo connectivity settings. Error handling improved especially when 3G or WLAN network is not available. --- Makefile | 2 +- debian/control | 2 +- debian/postinst | 2 - src/common/connectionmanager.cpp | 86 +++++----------- src/common/connectionmanager.h | 9 +- src/common/eniro.cpp | 4 +- src/common/settings.cpp | 91 ++++++++++++++++- src/common/settings.h | 4 + src/common/translations/fi_FI.qm | Bin 6926 -> 7992 bytes src/common/translations/fi_FI.ts | 125 +++++++++++++---------- src/daemon/calllistener.cpp | 203 ++++++++++++++++++++++++-------------- src/daemon/calllistener.h | 17 ++-- src/daemon/daemon.pro | 2 +- src/daemon/main.cpp | 5 +- src/gui/aboutdialog.cpp | 1 + src/gui/buttonselector.cpp | 51 +++++++++- src/gui/buttonselector.h | 7 +- src/gui/connectionselector.cpp | 75 ++++++++++++++ src/gui/connectionselector.h | 42 ++++++++ src/gui/gui.pro | 2 +- src/gui/mainwindow.cpp | 36 ++++++- src/gui/mainwindow.h | 1 + src/gui/settingsdialog.cpp | 21 +--- src/gui/settingsdialog.h | 2 - 24 files changed, 556 insertions(+), 234 deletions(-) create mode 100644 src/gui/connectionselector.cpp create mode 100644 src/gui/connectionselector.h diff --git a/Makefile b/Makefile index 8b630ff..b7355fa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: jenirok -# Generated by qmake (2.01a) (Qt 4.6.2) on: Wed Jun 9 14:23:12 2010 +# Generated by qmake (2.01a) (Qt 4.6.2) on: Thu Jun 10 20:04:24 2010 # Project: jenirok.pro # Template: subdirs # Command: /usr/bin/qmake -unix -o Makefile jenirok.pro diff --git a/debian/control b/debian/control index b3df750..fa1e74a 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: jenirok Section: user/utilities Priority: optional Maintainer: Jesse Hakanen -Build-Depends: debhelper (>= 5), libqt4-dev, libebook-dev, libx11-dev, icd2-dev, gnupg +Build-Depends: debhelper (>= 5), libqt4-dev, libebook-dev, libx11-dev, icd2-dev, gnupg, libgconf2-dev Standards-Version: 3.7.2 Package: jenirok diff --git a/debian/postinst b/debian/postinst index b09638f..79fb6dd 100644 --- a/debian/postinst +++ b/debian/postinst @@ -2,6 +2,4 @@ gtk-update-icon-cache -f /usr/share/icons/hicolor -/etc/init.d/jenirokd start - exit 0 diff --git a/src/common/connectionmanager.cpp b/src/common/connectionmanager.cpp index 8196520..caf6709 100644 --- a/src/common/connectionmanager.cpp +++ b/src/common/connectionmanager.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -128,7 +129,7 @@ bool ConnectionManager::connect(QString const& id) return true; } -bool ConnectionManager::getBestConnection(Connection& connection) +bool ConnectionManager::getBestConnection(Connection& connection, ConnectionType type) { bool blockingValue = blocking_; @@ -145,7 +146,6 @@ bool ConnectionManager::getBestConnection(Connection& connection) if(connections.size() == 0) { - qDebug() << "No connections"; error_ = NO_AVAILABLE_CONNECTIONS; return false; } @@ -160,7 +160,7 @@ bool ConnectionManager::getBestConnection(Connection& connection) switch(connections.at(i).type) { case WLAN: - if(connections.at(i).strength > biggestWlan) + if(type != GPRS && connections.at(i).strength > biggestWlan) { biggestWlan = connections.at(i).strength; bestWlan = i; @@ -168,7 +168,7 @@ bool ConnectionManager::getBestConnection(Connection& connection) break; case GPRS: - if(connections.at(i).strength > biggestGprs) + if(type != WLAN && connections.at(i).strength > biggestGprs) { biggestGprs = connections.at(i).strength; bestGprs = i; @@ -198,21 +198,6 @@ bool ConnectionManager::getBestConnection(Connection& connection) } -bool ConnectionManager::autoConnect() -{ - Connection best; - - if(!getBestConnection(best)) - { - return false; - } - - qDebug() << "Best connection: " << best.name; - - return connect(best.id); - -} - bool ConnectionManager::disconnect(bool force) { // Forced disconnect is not allowed if connection @@ -261,19 +246,38 @@ bool ConnectionManager::isConnected() return true; } -bool ConnectionManager::scanConnections(QList& connections) +bool ConnectionManager::scanConnections(QList& connections, + ConnectionManager::ConnectionType type) { unsigned int flags = static_cast(ICD_SCAN_REQUEST_ACTIVE_SAVED); scanReady_ = false; scannedConnections_ = 0; connections_ = &connections; - QDBusMessage rep = icd2interface_->call(ICD_DBUS_API_SCAN_REQ, QVariant(flags)); + + QStringList networks; + + switch(type) + { + case WLAN: + networks << "WLAN_INFRA" << "WLAN_ADHOC"; + break; + case GPRS: + networks << "GPRS"; + break; + default: + break; + } + + QDBusMessage rep = icd2interface_->call(ICD_DBUS_API_SCAN_REQ, + QVariant(flags), + QVariant(networks)); numberOfConnections_ = rep.arguments().value(0).toList().size(); if(numberOfConnections_ == 0) { connections_ = 0; + qDebug() << "No connections"; return false; } @@ -287,46 +291,6 @@ bool ConnectionManager::scanConnections(QList& co return true; } -ConnectionManager::NetworkMode ConnectionManager::getNetworkMode() -{ - QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.phone.net", - "/com/nokia/phone/net", - "Phone.Net", - "get_registration_status"); - - QDBusMessage rep = QDBusConnection::systemBus().call(msg); - - if(rep.type() == QDBusMessage::ErrorMessage) - { - qDebug() << rep.errorMessage(); - - return NETWORK_UNKNOWN; - } - - char services = rep.arguments().value(6).toChar().toAscii(); - - qDebug() << services; - - if(services & 0x08) - { - return NETWORK_3_5G; - } - else if(services & 0x04) - { - return NETWORK_3G; - } - else if(services & 0x01) - { - return NETWORK_2_5G; - } - else if(services & 0x02) - { - return NETWORK_2G; - } - - return NETWORK_UNKNOWN; -} - ConnectionManager::Error ConnectionManager::error() const { return error_; diff --git a/src/common/connectionmanager.h b/src/common/connectionmanager.h index 49e6dfc..547163d 100644 --- a/src/common/connectionmanager.h +++ b/src/common/connectionmanager.h @@ -33,8 +33,7 @@ class ConnectionManager : public QObject public: - enum ConnectionType {WLAN, GPRS}; - enum NetworkMode {NETWORK_UNKNOWN, NETWORK_2G, NETWORK_2_5G, NETWORK_3G, NETWORK_3_5G}; + enum ConnectionType {NO_TYPE, WLAN, GPRS}; enum Error {NO_ERROR, NO_AVAILABLE_CONNECTIONS, INVALID_IAP, UNKNOWN_ERROR}; struct Connection @@ -51,12 +50,10 @@ public: bool connect(); bool connect(Connection const& connection); bool connect(QString const& id); - bool getBestConnection(Connection& connection); - bool autoConnect(); + bool getBestConnection(Connection& connection, ConnectionType type = NO_TYPE); bool disconnect(bool force = false); bool isConnected(); - bool scanConnections(QList& connections); - NetworkMode getNetworkMode(); + bool scanConnections(QList& connections, ConnectionType type = NO_TYPE); Error error() const; static unsigned int const TIMEOUT = 20000; diff --git a/src/common/eniro.cpp b/src/common/eniro.cpp index b28760c..acf5e6d 100644 --- a/src/common/eniro.cpp +++ b/src/common/eniro.cpp @@ -42,8 +42,8 @@ namespace "dk" }; - static const QString INVALID_LOGIN_STRING = QObject::tr("Invalid login details"); - static const QString TIMEOUT_STRING = QObject::tr("Request timed out"); + static const QString INVALID_LOGIN_STRING = "Invalid login details"; + static const QString TIMEOUT_STRING = "Request timed out"; static const QString PERSON_REGEXP = "(.*)(.*)"; static const QString YELLOW_REGEXP = "(.*)(.*)"; static const QString NUMBER_REGEXP = "
(.*)
"; diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 85534d7..46ea56e 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include "settings.h" #include "db.h" @@ -118,8 +120,7 @@ QString Settings::getDefaultValue(QString const& name) defaultValues["autostart"] = "1"; defaultValues["eniro_site"] = tr("fi"); defaultValues["cache_size"] = "200"; - defaultValues["connection"] = "0"; - defaultValues["autoconnect"] = "0"; + defaultValues["connection"] = "global"; defaultValuesLoaded = true; } @@ -158,6 +159,92 @@ bool Settings::reset() return ret; } +Settings::ConnectionType Settings::getConnectionType() +{ + QString value = get("connection"); + + if(value == "any") + { + return ANY; + } + else if(value == "wlan") + { + return WLAN; + } + else if(value == "gprs") + { + return GPRS; + } + else + { + if(value != "global") + { + qDebug() << "Unknown connection type in settings, using default"; + } + + QList values; + + GConfClient* gcClient = NULL; + gcClient = gconf_client_get_default(); + + g_assert(GCONF_IS_CLIENT(gcClient)); + + GError* error = NULL; + GSList* list = NULL; + list = gconf_client_get_list(gcClient, + "/system/osso/connectivity/network_type/auto_connect", + GCONF_VALUE_STRING, + &error); + + if(error) + { + qDebug() << "Error: " << error->message; + g_error_free(error); + } + else + { + while(list) + { + values.push_back((char *)list->data); + list = list->next; + } + + } + + g_object_unref(gcClient); + + if(values.size() == 0) + { + return ALWAYS_ASK; + } + else + { + QString value = values.at(0); + + if(value == "*") + { + return ANY; + } + else if(value == "GPRS") + { + return GPRS; + } + else if(value == "WLAN_INFRA" || value == "WLAN_ADHOC" || value == "WLAN") + { + return WLAN; + } + else + { + qDebug() << "Unknown connection type: " << value; + return ALWAYS_ASK; + } + } + + } + + return ALWAYS_ASK; +} + Settings::Settings() { } diff --git a/src/common/settings.h b/src/common/settings.h index 6649071..92e6e3d 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -29,11 +29,15 @@ class Settings Q_DECLARE_TR_FUNCTIONS(Settings) public: + + enum ConnectionType {ALWAYS_ASK, WLAN, GPRS, ANY}; + static Settings* instance(); static void close(); bool set(QString const& name, QString const& value); QString get(QString const& name); QString getDefaultValue(QString const& name); + ConnectionType getConnectionType(); bool reset(); private: diff --git a/src/common/translations/fi_FI.qm b/src/common/translations/fi_FI.qm index 0ae88bc4d3766cb61635d7e4570f5fb5c4adc121..b0be15eb68f7de78dfd864f49a65baa12bc07ad7 100644 GIT binary patch delta 1874 zcmZ`(e{2(V6o1#=bwAo(w{>gRZNitxKmt^afYA`l7%&*y+!$ma#N@Ue?ACIJy=#~H z#~O)IA_*D}#|Fe~0fD$bFfrO4ew=?Kj)0rkJ{@c^E|98ZZJa4oe1%UTF z6GF;FpbR#UbxS-KHlfEgpLu?{a2pl5=at&OMd<_HqhHU3{u%GFL$9Kg9p21k0IY46 zSEiu%*UM+#>_x_+{M(&bM5SBhzm9~_^A_LQ8wa3QbFy;OHx-%!5TAz2PM`+lv3uOJ z?LkMmb2l~EKS@Fc_vg&L?We_b}seAx{>UF#Z< zI!Xa2jvn@tT8Jn$Mh#Qtr7vw&G`&mHdyN4BED?r~0PlGMU5>(!GbG1}1X!V=JBmH# z_NRDf7U3)ct%*0c<9y(3;RTz?Bkmc2E{?3HS@*9_^H_}5p|}=oVvxM|8W!(81Ae}X zDcYajGBSI6y|tS-pnfT*JftAC+^x=0nhmq*U4o z4{mK>m#6!~U>C#op}|N&`GB_{tWwmShR%8vozFtI%1ld%S$rJS9wm+zYu5akb7C2J z@-S?zK9#N0Ej0!rhuIb*&ia&u%1=}cXR+LPF{LnotMbpNUbk?luTFi*#xn%MQ zfqI%@tsG|IESw&6pAx)vpjiUx@HQ*VZ2uC#09r>hDy3vAM} zLkNhbeabsK?UI)`U?!(4%0Cv}FLokqm=m2VwlgK=_qKW2`Y6Vq(k&+l7pPBqGds(M00~gue(R5TDYx3q4=HJbAzG zyzldK&bRA#J+r&E@EqWr18RnWj$?r13dCd+AT)@>-w}6167zs(5Yon0K)MHMat5e# zK>9%ksvlta=x>0%8y$P6QGOm{mB6OxcA)lWyu3fjzS#Fh_ObCxP9M;0+iKKs6GgIuT{{$ zRhpb4ado|Pa0eSa^A)WANt)V8hpyM8xnB>E@T@a%rk(G_oo`H^X99mZ=T10Sf8xA* z`Uw)8bv_J_QQ)BS;W;KNb-V6;Jr3B;xf6|Tob#T0&)D4pqu*Z@)Q!}|veLD1na&htJa&}xqRJUt zmck!Yux_35^J$B#&z<<#@JxgVgPG5V0 z=e`rZZ$3^@aj);jO*(SF9^e6fPc@-n99fv4tAb9GT-_-8$lnSf}f2LbV(EOf##iT0UnEXgQ-t zOQ%PzHrKLZm-{VgA{Zzp0y}Ni%9<<1LU66!GQughtLxR|Hfpf0i>}3@_(kZVkUJ57 zOhY14Jh|on-kKTI0P^&j;?7b|9@)j9Ry?0hnHaetaan... - Search failed: + Request timed out + Pyyntö aikakatkaistiin + + + Searching failed: Haku epäonnistui: @@ -24,16 +28,20 @@ Numeroa ei löytynyt - No network connections found. - Käytettävissä olevia verkkoyhteyksiä ei löytynyt. + Automatic connecting is not allowed by settings. + Automaattista yhteyden muodostamista ei ole sallittu asetuksista. - Selected access point doesn't exist. - Valittua yhteysosoitetta ei löytynyt. + Connecting... + Yhdistetään... + + + No available 3G or WLAN networks found. + Käytettävissä olevia 3G- tai WLAN-verkkoja ei löytynyt. - No 3G or WLAN network available. - Ei saatavilla olevaa 3G- tai WLAN-verkkoa. + Selected access point doesn't exist. + Valittua yhteysosoitetta ei löytynyt. Unable to connect to network. @@ -43,9 +51,24 @@ ConnectionSelector - - Choose automatically - Valitse automaattisesti + + Use global setting + Käytä järj. asetusta + + + + WLAN connection + WLAN-yhteys + + + + GPRS connection + GPRS-yhteys + + + + Any connection + Mikä tahansa yhteys @@ -133,87 +156,94 @@ MainWindow - + Jenirok Jenirok - - + + Stop daemon Pysäytä - - + + Start daemon Käynnistä - + Search Hae - + Settings Asetukset - + About Tietoa - + Daemon was successfully stopped. Palvelu pysäytettiin onnistuneesti. - + Unable to stop daemon. Palvelun pysäyttäminen ei onnistunut. - + + Unable to start daemon + Palvelun käynnistäminen ei onnistunut + + + + Daemon cannot be started because it's not allowed to connect to the Internet. You have to either allow automatic Internet connection in Jenirok settings or in global Maemo settings. + Palvelua ei voida käynnistää, koska sillä ei ole oikeutta yhdistää Internetiin. Sinun täytyy sallia automaattinen yhteyden muodostaminen joko Jenirokin asetuksista tai Maemon omista Internet-asetuksista. + + + + Open settings + Avaa asetukset + + + + Close + Sulje + + + Daemon was successfully started. Palvelu käynnistettiin onnistuneesti. - + Unable to start daemon. Palvelun käynnistäminen ei onnistunut. - + Error Virhe - + Info Info - + You need to set Eniro login details in settings before using this feature. Sinun täytyy asettaa Eniro-tunnus ja -salasana asetuksista ennen kuin voit käyttää tätä ominaisuutta. - QObject - - - Invalid login details - Virheellinen tunnus tai salasana - - - - Request timed out - Pyyntö aikakatkaistiin - - - ResultWindow @@ -288,7 +318,7 @@ Settings - + fi fi @@ -357,36 +387,31 @@ - Allow daemon to connect automatically - Salli automaattinen verkkoyht. muodostus + Connect automatically on + Yhdistä automaattisesti - Connection to use - Käytettävä yhteys - - - Save Tallenna - + General Yleiset - + Daemon Taustaprosessi - + Restarting daemon... Käynnistetään palvelu uudelleen... - + %n number(s) were deleted from cache Poistettiin %n numero välimuistista diff --git a/src/daemon/calllistener.cpp b/src/daemon/calllistener.cpp index 149e441..821c073 100644 --- a/src/daemon/calllistener.cpp +++ b/src/daemon/calllistener.cpp @@ -18,12 +18,12 @@ #include #include -#include -#include #include "calllistener.h" #include "settings.h" #include "cache.h" #include "contactmanager.h" +#include "connectionmanager.h" +#include "db.h" namespace { @@ -38,19 +38,26 @@ namespace QDBusConnection CallListener::systemBus_ = QDBusConnection::systemBus(); -CallListener::CallListener(): eniro_(0), connectionManager_(0), +CallListener::CallListener(): eniro_(0), closeConnection_(false), initialized_(false), box_(0), label_(0), -retries_(-1), site_(Eniro::FI), autoconnect_(false) +retries_(-1), site_(Eniro::FI), timer_(0), autoconnect_(false) { } CallListener::~CallListener() { end(); + DB::removeDatabase(); } -void CallListener::begin() +bool CallListener::begin() { + if(Settings::instance()->getConnectionType() == Settings::ALWAYS_ASK) + { + qDebug() << "Bad connection settings, unable to start"; + return false; + } + systemBus_.connect(CALL_SERVICE_NAME, CALL_SERVICE_PATH, CALL_SERVICE_INTERFACE, @@ -66,12 +73,11 @@ void CallListener::begin() SLOT(callTerminate())); site_ = Eniro::stringToSite(Settings::instance()->get("site")); - connectionName_ = Settings::instance()->get("connection"); - autoconnect_ = (Settings::instance()->get("autoconnect") == "1"); - Settings::close(); qDebug() << "Starting..."; + return true; + } void CallListener::end() @@ -116,14 +122,14 @@ void CallListener::search(Eniro::SearchDetails const& details) retries_ = 0; currentSearch_ = details.query; - showDelayedResult(tr("Searching..."), BANNER_DELAY); - if(!handleConnection()) { qDebug() << "Unable to connect"; return; } + showDelayedResult(tr("Searching..."), BANNER_DELAY); + qDebug() << "Starting to search..."; eniro_->search(details); @@ -147,7 +153,7 @@ void CallListener::requestFinished(QVector const& results, { qDebug() << "Error: " << eniro_->errorString(); - if(retries_ < NUMBER_OF_RETRIES && retries_ >= 0) + if(retries_ < SEARCH_RETRIES && retries_ >= 0) { retries_++; eniro_->search(Eniro::SearchDetails(currentSearch_)); @@ -156,7 +162,20 @@ void CallListener::requestFinished(QVector const& results, else { timedMessage_ = ""; - showError(tr("Search failed:") + " " + eniro_->errorString() + "."); + QString errorString; + Eniro::Error error = eniro_->error(); + + switch(error) + { + case Eniro::TIMEOUT: + errorString = tr("Request timed out"); + break; + default: + errorString = eniro_->errorString(); + break; + } + + showError(tr("Searching failed:") + " " + errorString + "."); } } else @@ -182,9 +201,10 @@ void CallListener::requestFinished(QVector const& results, retries_ = -1; currentSearch_ = ""; - if(closeConnection_ && connectionManager_) + if(closeConnection_) { - connectionManager_->disconnect(true); + ConnectionManager cm; + cm.disconnect(true); closeConnection_ = false; } } @@ -252,14 +272,15 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number) void CallListener::callTerminate() { - if(initialized_ && box_ && box_->isVisible()) + if(box_ && box_->isVisible()) { box_->hide(); } - if(closeConnection_ && connectionManager_) + if(closeConnection_) { - connectionManager_->disconnect(true); + ConnectionManager cm; + cm.disconnect(true); closeConnection_ = false; } @@ -294,8 +315,6 @@ void CallListener::searchInit() return; } - connectionManager_ = new ConnectionManager; - eniro_ = new Eniro(site_); eniro_->setMaxResults(1); eniro_->setFindNumber(false); @@ -308,6 +327,7 @@ void CallListener::searchInit() box_ = new InformationBox; label_ = new QLabel("", box_); label_->setMargin(8); + label_->setWordWrap(true); box_->setWidget(label_); initialized_ = true; } @@ -326,8 +346,6 @@ void CallListener::searchClose() Eniro::SearchDetails const&, bool))); } - delete connectionManager_; - connectionManager_ = 0; delete eniro_; eniro_ = 0; delete box_; @@ -337,92 +355,109 @@ void CallListener::searchClose() bool CallListener::handleConnection() { - if(!connectionManager_) + if(!initialized_) { - qDebug() << "Error: connection manager not initialized"; return false; } - if(connectionManager_->isConnected()) + ConnectionManager cm; + + if(cm.isConnected()) { closeConnection_ = false; return true; } closeConnection_ = true; - int retries = 0; - if(autoconnect_) + Settings::ConnectionType configType = Settings::instance()->getConnectionType(); + + if(configType == Settings::ALWAYS_ASK) + { + showError(tr("Automatic connecting is not allowed by settings.")); + return false; + } + + showDelayedResult(tr("Connecting..."), BANNER_DELAY); + + ConnectionManager::Connection best; + + ConnectionManager::ConnectionType lookupType = ConnectionManager::NO_TYPE; + + switch(configType) { - QString conn; + case Settings::WLAN: + lookupType = ConnectionManager::WLAN; + break; + case Settings::GPRS: + lookupType = ConnectionManager::GPRS; + break; + default: + lookupType = ConnectionManager::NO_TYPE; + break; + } + + int cretries = 0; - if(connectionName_.size() != 0 && connectionName_ != "0") + while(cretries < CONNECTION_LOOKUP_RETRIES) + { + if(!initialized_) { - conn = connectionName_; + return false; } - else + + if(cm.getBestConnection(best, lookupType)) { - ConnectionManager::Connection best; + break; + } - if(!connectionManager_->getBestConnection(best)) - { - showError(tr("No network connections found.")); - return false; - } + qDebug() << "No connections found, retrying..."; - conn = best.id; - } + cretries++; - while(retries < CONNECT_RETRIES) - { - if(connectionManager_->connect(conn)) - { - break; - } - else if(connectionManager_->error() == ConnectionManager::INVALID_IAP) - { - showError(tr("Selected access point doesn't exist.")); - return false; - } + sleep(WAIT_BETWEEN_RETRIES); - retries++; - } } - else - { - while(retries < CONNECT_RETRIES) - { - if(connectionManager_->connect()) - { - break; - } - else - { - qDebug() << "Automatic connection failed"; - } - retries++; - } + if(cretries >= CONNECTION_LOOKUP_RETRIES) + { + showError(tr("No available 3G or WLAN networks found.")); + return false; } - if(retries >= CONNECT_RETRIES) + int retries = 0; + + while(retries < CONNECT_RETRIES) { - ConnectionManager::NetworkMode mode = connectionManager_->getNetworkMode(); + if(!initialized_) + { + return false; + } - if(mode != ConnectionManager::NETWORK_3G && - mode != ConnectionManager::NETWORK_3_5G) + sleep(WAIT_BETWEEN_RETRIES); + + if(cm.connect(best.id)) { - showError(tr("No 3G or WLAN network available.")); + break; } - else + else if(cm.error() == ConnectionManager::INVALID_IAP) { - showError(tr("Unable to connect to network.")); + showError(tr("Selected access point doesn't exist.")); + return false; } + qDebug() << "Unable to connect, retrying..."; + retries++; + + } + + if(initialized_ && retries >= CONNECT_RETRIES) + { + showError(tr("Unable to connect to network.")); return false; } - return true; + return initialized_; } void CallListener::showError(QString const& msg) @@ -431,3 +466,25 @@ void CallListener::showError(QString const& msg) box_->setTimeout(ERROR_BANNER_TIMEOUT); showResult(msg); } + +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); + } +} diff --git a/src/daemon/calllistener.h b/src/daemon/calllistener.h index 54677f1..a07743e 100644 --- a/src/daemon/calllistener.h +++ b/src/daemon/calllistener.h @@ -26,7 +26,6 @@ #include #include "informationbox.h" #include "eniro.h" -#include "connectionmanager.h" class CallListener: public QObject { @@ -35,13 +34,18 @@ class CallListener: public QObject public: CallListener(); ~CallListener(); - void begin(); + bool begin(); void end(); static const int REQUEST_TIMEOUT = 10000; static const int BANNER_DELAY = 350; - static const int NUMBER_OF_RETRIES = 2; - static const int CONNECT_RETRIES = 2; - static const int ERROR_BANNER_TIMEOUT = 5000; + static const int SEARCH_RETRIES = 2; + static const int CONNECT_RETRIES = 3; + static const int CONNECTION_LOOKUP_RETRIES = 15; + static const int WAIT_BETWEEN_RETRIES = 1000; + static const int ERROR_BANNER_TIMEOUT = 4000; + +protected: + virtual void timerEvent(QTimerEvent* event); private slots: void requestFinished(QVector const& results, Eniro::SearchDetails const& details, bool error); @@ -59,10 +63,10 @@ private: void searchClose(); bool handleConnection(); void showError(QString const& msg); + void sleep(int ms); QString createResult(QString const& name, QString const& street, QString const& city); QString timedMessage_; Eniro* eniro_; - ConnectionManager* connectionManager_; bool closeConnection_; bool initialized_; InformationBox* box_; @@ -72,6 +76,7 @@ private: QString currentSearch_; Eniro::Site site_; QString connectionName_; + int timer_; bool autoconnect_; }; diff --git a/src/daemon/daemon.pro b/src/daemon/daemon.pro index 252661b..07edb06 100644 --- a/src/daemon/daemon.pro +++ b/src/daemon/daemon.pro @@ -8,7 +8,7 @@ TRANSLATIONS = ../common/translations/fi_FI.ts RESOURCES = ../common/translations.grc INCLUDEPATH += ../common CONFIG += link_pkgconfig -PKGCONFIG += libebook-1.2 +PKGCONFIG += libebook-1.2 gconf-2.0 unix { #VARIABLES diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index ef17c49..307bb4d 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -45,7 +45,10 @@ int main(int argc, char *argv[]) CallListener listener; - listener.begin(); + if(!listener.begin()) + { + return 1; + } return app.exec(); diff --git a/src/gui/aboutdialog.cpp b/src/gui/aboutdialog.cpp index 68a948a..8e4172d 100644 --- a/src/gui/aboutdialog.cpp +++ b/src/gui/aboutdialog.cpp @@ -33,6 +33,7 @@ AboutDialog::AboutDialog(QWidget* parent): QDialog(parent) mainLayout->addWidget(image, 0, Qt::AlignLeft); mainLayout->addSpacing(20); QLabel* text = new QLabel("Jenirok
(c) 2010 Jesse Hakanen
http://jenirok.garage.maemo.org"); + text->setOpenExternalLinks(true); mainLayout->addWidget(text, 10, Qt::AlignLeft); setLayout(mainLayout); diff --git a/src/gui/buttonselector.cpp b/src/gui/buttonselector.cpp index fafb52c..6ba49da 100644 --- a/src/gui/buttonselector.cpp +++ b/src/gui/buttonselector.cpp @@ -53,12 +53,12 @@ void ButtonSelector::clear() model_->clear(); } -void ButtonSelector::setCurrentIndex(int index) +void ButtonSelector::setCurrentIndex(unsigned int index) { selector_->setCurrentIndex(index); } -bool ButtonSelector::selectByValue(QVariant const& value) +int ButtonSelector::indexOfValue(QVariant const& value) const { for(int i = 0; i < model_->rowCount(); i++) { @@ -66,12 +66,25 @@ bool ButtonSelector::selectByValue(QVariant const& value) if(item && item->data(Qt::UserRole) == value) { - setCurrentIndex(i); - return true; + return i; } } - return false; + return -1; +} + +bool ButtonSelector::selectByValue(QVariant const& value) +{ + int index = indexOfValue(value); + + if(index < 0) + { + return false; + } + + setCurrentIndex(index); + + return true; } int ButtonSelector::currentIndex() const @@ -97,3 +110,31 @@ QVariant ButtonSelector::value() const return item->data(Qt::UserRole); } + +bool ButtonSelector::changeItem(unsigned int index, + QString const& text) +{ + changeItem(index, text, QVariant(text)); +} + +bool ButtonSelector::changeItem(unsigned int index, + QString const& text, + QVariant const& value) +{ + QStandardItem* item = model_->item(index); + + if(!item) + { + return false; + } + + item->setText(text); + item->setData(value, Qt::UserRole); + + return true; +} + +bool ButtonSelector::removeItem(unsigned int index) +{ + return model_->removeRow(index); +} diff --git a/src/gui/buttonselector.h b/src/gui/buttonselector.h index b2a20fc..ae494a2 100644 --- a/src/gui/buttonselector.h +++ b/src/gui/buttonselector.h @@ -35,9 +35,14 @@ public: void addItem(QString const& text); void addItem(QString const& text, QVariant const& value); void clear(); - void setCurrentIndex(int index); + void setCurrentIndex(unsigned int index); + int indexOfValue(QVariant const& value) const; bool selectByValue(QVariant const& value); int currentIndex() const; + bool changeItem(unsigned int index, QString const& text); + bool changeItem(unsigned int index, QString const& text, QVariant const& value); + bool removeItem(unsigned int index); + bool setValue(unsigned int index); QString text() const; QVariant value() const; diff --git a/src/gui/connectionselector.cpp b/src/gui/connectionselector.cpp new file mode 100644 index 0000000..740e2a8 --- /dev/null +++ b/src/gui/connectionselector.cpp @@ -0,0 +1,75 @@ +/* + * This file is part of Jenirok. + * + * Jenirok is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Jenirok is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jenirok. If not, see . + * + */ + +#include +#include +#include +#include "connectionselector.h" +#include "connectionmanager.h" + +ConnectionSelector::ConnectionSelector(QString const& text, QWidget* parent): +ButtonSelector(text, parent), loaded_(false), gprsIndex_(0) +{ + addItems(); +} + +void ConnectionSelector::updateConnections() +{ + QVariant currentValue = value(); + + addItems(); + + ConnectionManager cm; + + QList connections; + + if(cm.scanConnections(connections, ConnectionManager::GPRS) && + connections.size() > 0) + { + changeItem(gprsIndex_, connections.at(0).name, "gprs"); + } + else + { + qDebug() << "Unable to scan network connections"; + } + + selectByValue(currentValue); + loaded_ = true; +} + +void ConnectionSelector::setVisible(bool visible) +{ + if(visible && !loaded_) + { + updateConnections(); + } + + ButtonSelector::setVisible(visible); +} + +void ConnectionSelector::addItems() +{ + clear(); + + addItem(tr("Use global setting"), "global"); + addItem(tr("WLAN connection"), "wlan"); + addItem(tr("GPRS connection"), "gprs"); + addItem(tr("Any connection"), "any"); + + gprsIndex_ = 2; +} diff --git a/src/gui/connectionselector.h b/src/gui/connectionselector.h new file mode 100644 index 0000000..23015ef --- /dev/null +++ b/src/gui/connectionselector.h @@ -0,0 +1,42 @@ +/* + * This file is part of Jenirok. + * + * Jenirok is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Jenirok is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jenirok. If not, see . + * + */ + +#ifndef CONNECTIONSELECTOR_H +#define CONNECTIONSELECTOR_H + +#include "buttonselector.h" + +class ConnectionSelector : public ButtonSelector +{ + +Q_OBJECT + +public: + + ConnectionSelector(QString const& text, QWidget* parent = 0); + void updateConnections(); + virtual void setVisible(bool visible); + +private: + void addItems(); + bool loaded_; + unsigned int gprsIndex_; +}; + + +#endif diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 566689f..4ed5de4 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -7,7 +7,7 @@ TRANSLATIONS = ../common/translations/fi_FI.ts RESOURCES = icons.grc ../common/translations.grc INCLUDEPATH += ../common CONFIG += link_pkgconfig -PKGCONFIG += libebook-1.2 glib-2.0 +PKGCONFIG += libebook-1.2 gconf-2.0 unix { #VARIABLES diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 1e4de14..f16e852 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include "mainwindow.h" @@ -39,7 +41,7 @@ namespace MainWindow::MainWindow(QWidget* parent): QMainWindow(parent), searchResults_(0), settingsDialog_(0), running_(false), -toggleButton_(0), searchDialog_(0), aboutDialog_(0) +toggleButton_(0), searchDialog_(0), aboutDialog_(0), warning_(0) { setWindowTitle(tr("Jenirok")); setAttribute(Qt::WA_Maemo5StackedWindow); @@ -86,6 +88,11 @@ MainWindow::~MainWindow() void MainWindow::showSettings() { + if(warning_ && warning_->isVisible()) + { + warning_->hide(); + } + if(!settingsDialog_) { settingsDialog_ = new SettingsDialog(this); @@ -110,6 +117,33 @@ void MainWindow::toggleDaemon() } else { + if(Settings::instance()->getConnectionType() == Settings::ALWAYS_ASK) + { + if(!warning_) + { + warning_ = new QDialog(this); + warning_->setWindowTitle(tr("Unable to start daemon")); + QHBoxLayout* warningLayout = new QHBoxLayout; + QTextEdit* text = new QTextEdit(tr("Daemon cannot be started because it's not allowed to connect to the Internet. You have to either allow automatic Internet connection in Jenirok settings or in global Maemo settings.")); + text->setReadOnly(true); + QDialogButtonBox* buttons = new QDialogButtonBox; + buttons->setOrientation(Qt::Vertical); + QPushButton* settingsButton = new QPushButton(tr("Open settings")); + connect(settingsButton, SIGNAL(pressed()), this, SLOT(showSettings())); + QPushButton* okButton = new QPushButton(tr("Close")); + connect(okButton, SIGNAL(pressed()), warning_, SLOT(hide())); + buttons->addButton(settingsButton, QDialogButtonBox::YesRole); + buttons->addButton(okButton, QDialogButtonBox::AcceptRole); + warningLayout->addWidget(text); + warningLayout->addWidget(buttons); + warning_->setLayout(warningLayout); + } + + warning_->show(); + + return; + } + readyText = tr("Daemon was successfully started."); failText = tr("Unable to start daemon."); buttonText = tr("Stop daemon"); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 43d71b7..b8e88aa 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -53,6 +53,7 @@ private: QToolButton* toggleButton_; SearchDialog* searchDialog_; AboutDialog* aboutDialog_; + QDialog* warning_; }; diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index f9dd623..11f0649 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -108,18 +108,9 @@ autostartSelector_(0) autostartSelector_->addItem(tr("Disabled"), "0"); autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1); - autoconnectCheck_ = new QCheckBox(tr("Allow daemon to connect automatically")); - QString autoconnect = Settings::instance()->get("autoconnect"); - autoconnectCheck_->setChecked(autoconnect == "1"); - - connectionSelector_ = new ConnectionSelector(tr("Connection to use"), this); + connectionSelector_ = new ConnectionSelector(tr("Connect automatically on"), this); QString selectedConnection = Settings::instance()->get("connection"); - - if(selectedConnection != "0") - { - connectionSelector_->addItem(Settings::instance()->get("connection_name"), selectedConnection); - connectionSelector_->selectByValue(selectedConnection); - } + connectionSelector_->selectByValue(selectedConnection); QPushButton* submitButton = new QPushButton(tr("Save"), this); connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings())); @@ -137,7 +128,6 @@ autostartSelector_(0) general->addWidget(siteSelector_); daemon->addWidget(autostartSelector_); - daemon->addWidget(autoconnectCheck_); daemon->addWidget(connectionSelector_); QDialogButtonBox* buttons = new QDialogButtonBox; @@ -176,17 +166,13 @@ void SettingsDialog::saveSettings() Settings::instance()->set("site", site); QString autostart = autostartSelector_->value().toString(); Settings::instance()->set("autostart", autostart); - bool autoconnect = autoconnectCheck_->isChecked(); - Settings::instance()->set("autoconnect", autoconnect ? "1" : "0"); QString connection = connectionSelector_->value().toString(); Settings::instance()->set("connection", connection); Settings::instance()->set("connection_name", connectionSelector_->text()); DB::disconnect(); - if((site != currentSite_ || - autoconnect != currentAutoconnect_ || - connection != currentConnection_) && Daemon::isRunning()) + if(site != currentSite_ && Daemon::isRunning()) { QMaemo5InformationBox::information(this, tr("Restarting daemon...")); Daemon::restart(); @@ -203,7 +189,6 @@ void SettingsDialog::setVisible(bool visible) { currentSite_ = siteSelector_->value().toString(); currentConnection_ = connectionSelector_->value().toString(); - currentAutoconnect_ = autoconnectCheck_->isChecked(); } } diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index 6bd9939..d150d4a 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -50,10 +50,8 @@ private: ButtonSelector* siteSelector_; ButtonSelector* autostartSelector_; ConnectionSelector* connectionSelector_; - QCheckBox* autoconnectCheck_; QString currentSite_; QString currentConnection_; - bool currentAutoconnect_; }; #endif -- 1.7.9.5