Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Jenirok
Summary Tracker SCM Files
authoreshe <jessehakanen@gmail.com>
Thu, 10 Jun 2010 19:06:38 +0000 (20:06 +0100)
committereshe <jessehakanen@gmail.com>
Thu, 10 Jun 2010 19:06:38 +0000 (20:06 +0100)
24 files changed:
Makefile
debian/control
debian/postinst
src/common/connectionmanager.cpp
src/common/connectionmanager.h
src/common/eniro.cpp
src/common/settings.cpp
src/common/settings.h
src/common/translations/fi_FI.qm
src/common/translations/fi_FI.ts
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/daemon.pro
src/daemon/main.cpp
src/gui/aboutdialog.cpp
src/gui/buttonselector.cpp
src/gui/buttonselector.h
src/gui/connectionselector.cpp [new file with mode: 0644]
src/gui/connectionselector.h [new file with mode: 0644]
src/gui/gui.pro
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/gui/settingsdialog.cpp
src/gui/settingsdialog.h

index 8b630ff..b7355fa 100644 (file)
--- 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
index b3df750..fa1e74a 100644 (file)
@@ -2,7 +2,7 @@ Source: jenirok
 Section: user/utilities
 Priority: optional
 Maintainer: Jesse Hakanen <jessehakanen@gmail.com>
-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
index b09638f..79fb6dd 100644 (file)
@@ -2,6 +2,4 @@
 
 gtk-update-icon-cache -f /usr/share/icons/hicolor
 
-/etc/init.d/jenirokd start
-
 exit 0
index 8196520..caf6709 100644 (file)
@@ -20,6 +20,7 @@
 #include <QApplication>
 #include <QtCore/QTimerEvent>
 #include <QtCore/QVariant>
+#include <QtCore/QStringList>
 #include <QtDBus/QDBusArgument>
 #include <QtDBus/QDBusConnection>
 #include <icd/dbus_api.h>
@@ -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<ConnectionManager::Connection>& connections)
+bool ConnectionManager::scanConnections(QList<ConnectionManager::Connection>& connections,
+                                        ConnectionManager::ConnectionType type)
 {
     unsigned int flags = static_cast<unsigned int>(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<ConnectionManager::Connection>& 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_;
index 49e6dfc..547163d 100644 (file)
@@ -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<Connection>& connections);
-    NetworkMode getNetworkMode();
+    bool scanConnections(QList<Connection>& connections, ConnectionType type = NO_TYPE);
     Error error() const;
     static unsigned int const TIMEOUT = 20000;
 
index b28760c..acf5e6d 100644 (file)
@@ -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 = "<td class=\"hTd2\">(.*)<b>(.*)</td>";
     static const QString YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\"\\}>(.*)</td>";
     static const QString NUMBER_REGEXP = "<div class=\"callRow\">(.*)</div>";
index 85534d7..46ea56e 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <QtSql/QSqlQuery>
 #include <QtCore/QVariant>
+#include <QDebug>
+#include <gconf/gconf-client.h>
 #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<QString> 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()
 {
 }
index 6649071..92e6e3d 100644 (file)
@@ -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:
index 0ae88bc..b0be15e 100644 (file)
Binary files a/src/common/translations/fi_FI.qm and b/src/common/translations/fi_FI.qm differ
index a4bff39..e493015 100644 (file)
         <translation>Haetaan...</translation>
     </message>
     <message>
-        <source>Search failed:</source>
+        <source>Request timed out</source>
+        <translation>Pyyntö aikakatkaistiin</translation>
+    </message>
+    <message>
+        <source>Searching failed:</source>
         <translation>Haku epäonnistui:</translation>
     </message>
     <message>
         <translation>Numeroa ei löytynyt</translation>
     </message>
     <message>
-        <source>No network connections found.</source>
-        <translation>Käytettävissä olevia verkkoyhteyksiä ei löytynyt.</translation>
+        <source>Automatic connecting is not allowed by settings.</source>
+        <translation>Automaattista yhteyden muodostamista ei ole sallittu asetuksista.</translation>
     </message>
     <message>
-        <source>Selected access point doesn&apos;t exist.</source>
-        <translation>Valittua yhteysosoitetta ei löytynyt.</translation>
+        <source>Connecting...</source>
+        <translation>Yhdistetään...</translation>
+    </message>
+    <message>
+        <source>No available 3G or WLAN networks found.</source>
+        <translation>Käytettävissä olevia 3G- tai WLAN-verkkoja ei löytynyt.</translation>
     </message>
     <message>
-        <source>No 3G or WLAN network available.</source>
-        <translation>Ei saatavilla olevaa 3G- tai WLAN-verkkoa.</translation>
+        <source>Selected access point doesn&apos;t exist.</source>
+        <translation>Valittua yhteysosoitetta ei löytynyt.</translation>
     </message>
     <message>
         <source>Unable to connect to network.</source>
 <context>
     <name>ConnectionSelector</name>
     <message>
-        <location filename="../../gui/connectionselector.cpp" line="35"/>
-        <source>Choose automatically</source>
-        <translation>Valitse automaattisesti</translation>
+        <location filename="../../gui/connectionselector.cpp" line="69"/>
+        <source>Use global setting</source>
+        <translation>Käytä järj. asetusta</translation>
+    </message>
+    <message>
+        <location filename="../../gui/connectionselector.cpp" line="70"/>
+        <source>WLAN connection</source>
+        <translation>WLAN-yhteys</translation>
+    </message>
+    <message>
+        <location filename="../../gui/connectionselector.cpp" line="71"/>
+        <source>GPRS connection</source>
+        <translation>GPRS-yhteys</translation>
+    </message>
+    <message>
+        <location filename="../../gui/connectionselector.cpp" line="72"/>
+        <source>Any connection</source>
+        <translation>Mikä tahansa yhteys</translation>
     </message>
 </context>
 <context>
 <context>
     <name>MainWindow</name>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="44"/>
+        <location filename="../../gui/mainwindow.cpp" line="46"/>
         <source>Jenirok</source>
         <translation>Jenirok</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="50"/>
-        <location filename="../../gui/mainwindow.cpp" line="115"/>
+        <location filename="../../gui/mainwindow.cpp" line="52"/>
+        <location filename="../../gui/mainwindow.cpp" line="149"/>
         <source>Stop daemon</source>
         <translation>Pysäytä</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="56"/>
-        <location filename="../../gui/mainwindow.cpp" line="108"/>
+        <location filename="../../gui/mainwindow.cpp" line="58"/>
+        <location filename="../../gui/mainwindow.cpp" line="115"/>
         <source>Start daemon</source>
         <translation>Käynnistä</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="61"/>
+        <location filename="../../gui/mainwindow.cpp" line="63"/>
         <source>Search</source>
         <translation>Hae</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="78"/>
+        <location filename="../../gui/mainwindow.cpp" line="80"/>
         <source>Settings</source>
         <translation>Asetukset</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="79"/>
+        <location filename="../../gui/mainwindow.cpp" line="81"/>
         <source>About</source>
         <translation>Tietoa</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="106"/>
+        <location filename="../../gui/mainwindow.cpp" line="113"/>
         <source>Daemon was successfully stopped.</source>
         <translation>Palvelu pysäytettiin onnistuneesti.</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="107"/>
+        <location filename="../../gui/mainwindow.cpp" line="114"/>
         <source>Unable to stop daemon.</source>
         <translation>Palvelun pysäyttäminen ei onnistunut.</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="113"/>
+        <location filename="../../gui/mainwindow.cpp" line="125"/>
+        <source>Unable to start daemon</source>
+        <translation>Palvelun käynnistäminen ei onnistunut</translation>
+    </message>
+    <message>
+        <location filename="../../gui/mainwindow.cpp" line="127"/>
+        <source>Daemon cannot be started because it&apos;s not allowed to connect to the Internet. You have to either allow automatic Internet connection in Jenirok settings or in global Maemo settings.</source>
+        <translation>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.</translation>
+    </message>
+    <message>
+        <location filename="../../gui/mainwindow.cpp" line="131"/>
+        <source>Open settings</source>
+        <translation>Avaa asetukset</translation>
+    </message>
+    <message>
+        <location filename="../../gui/mainwindow.cpp" line="133"/>
+        <source>Close</source>
+        <translation>Sulje</translation>
+    </message>
+    <message>
+        <location filename="../../gui/mainwindow.cpp" line="147"/>
         <source>Daemon was successfully started.</source>
         <translation>Palvelu käynnistettiin onnistuneesti.</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="114"/>
+        <location filename="../../gui/mainwindow.cpp" line="148"/>
         <source>Unable to start daemon.</source>
         <translation>Palvelun käynnistäminen ei onnistunut.</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="121"/>
+        <location filename="../../gui/mainwindow.cpp" line="155"/>
         <source>Error</source>
         <translation>Virhe</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="144"/>
+        <location filename="../../gui/mainwindow.cpp" line="178"/>
         <source>Info</source>
         <translation>Info</translation>
     </message>
     <message>
-        <location filename="../../gui/mainwindow.cpp" line="144"/>
+        <location filename="../../gui/mainwindow.cpp" line="178"/>
         <source>You need to set Eniro login details in settings before using this feature.</source>
         <translation>Sinun täytyy asettaa Eniro-tunnus ja -salasana asetuksista ennen kuin voit käyttää tätä ominaisuutta.</translation>
     </message>
 </context>
 <context>
-    <name>QObject</name>
-    <message>
-        <location filename="../eniro.cpp" line="45"/>
-        <source>Invalid login details</source>
-        <translation>Virheellinen tunnus tai salasana</translation>
-    </message>
-    <message>
-        <location filename="../eniro.cpp" line="46"/>
-        <source>Request timed out</source>
-        <translation>Pyyntö aikakatkaistiin</translation>
-    </message>
-</context>
-<context>
     <name>ResultWindow</name>
     <message>
         <location filename="../../gui/resultwindow.cpp" line="34"/>
 <context>
     <name>Settings</name>
     <message>
-        <location filename="../settings.cpp" line="119"/>
+        <location filename="../settings.cpp" line="121"/>
         <source>fi</source>
         <translation>fi</translation>
     </message>
     </message>
     <message>
         <location filename="../../gui/settingsdialog.cpp" line="111"/>
-        <source>Allow daemon to connect automatically</source>
-        <translation>Salli automaattinen verkkoyht. muodostus</translation>
+        <source>Connect automatically on</source>
+        <translation>Yhdistä automaattisesti</translation>
     </message>
     <message>
         <location filename="../../gui/settingsdialog.cpp" line="115"/>
-        <source>Connection to use</source>
-        <translation>Käytettävä yhteys</translation>
-    </message>
-    <message>
-        <location filename="../../gui/settingsdialog.cpp" line="119"/>
         <source>Save</source>
         <translation>Tallenna</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="150"/>
+        <location filename="../../gui/settingsdialog.cpp" line="145"/>
         <source>General</source>
         <translation>Yleiset</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="151"/>
+        <location filename="../../gui/settingsdialog.cpp" line="146"/>
         <source>Daemon</source>
         <translation>Taustaprosessi</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="185"/>
+        <location filename="../../gui/settingsdialog.cpp" line="177"/>
         <source>Restarting daemon...</source>
         <translation>Käynnistetään palvelu uudelleen...</translation>
     </message>
     <message numerus="yes">
-        <location filename="../../gui/settingsdialog.cpp" line="211"/>
+        <location filename="../../gui/settingsdialog.cpp" line="202"/>
         <source>%n number(s) were deleted from cache</source>
         <translation>
             <numerusform>Poistettiin %n numero välimuistista</numerusform>
index 149e441..821c073 100644 (file)
 
 #include <QtCore/QDebug>
 #include <QtCore/QTimer>
-#include <QtSql/QSqlQuery>
-#include <QtSql/QSqlError>
 #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 <Eniro::Result> 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 <Eniro::Result> 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 <Eniro::Result> 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);
+    }
+}
index 54677f1..a07743e 100644 (file)
@@ -26,7 +26,6 @@
 #include <QtDBus/QDBusObjectPath>
 #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 <Eniro::Result> 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_;
 };
 
index 252661b..07edb06 100644 (file)
@@ -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
index ef17c49..307bb4d 100644 (file)
@@ -45,7 +45,10 @@ int main(int argc, char *argv[])
 
     CallListener listener;
 
-    listener.begin();
+    if(!listener.begin())
+    {
+        return 1;
+    }
 
     return app.exec();
 
index 68a948a..8e4172d 100644 (file)
@@ -33,6 +33,7 @@ AboutDialog::AboutDialog(QWidget* parent): QDialog(parent)
     mainLayout->addWidget(image, 0, Qt::AlignLeft);
     mainLayout->addSpacing(20);
     QLabel* text = new QLabel("<font size='4'><b>Jenirok</b></font><br>(c) 2010 Jesse Hakanen<br><a href='http://jenirok.garage.maemo.org'>http://jenirok.garage.maemo.org</a>");
+    text->setOpenExternalLinks(true);
     mainLayout->addWidget(text, 10, Qt::AlignLeft);
 
     setLayout(mainLayout);
index fafb52c..6ba49da 100644 (file)
@@ -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);
+}
index b2a20fc..ae494a2 100644 (file)
@@ -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 (file)
index 0000000..740e2a8
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QList>
+#include <QtCore/QVariant>
+#include <QDebug>
+#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<ConnectionManager::Connection> 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 (file)
index 0000000..23015ef
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#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
index 566689f..4ed5de4 100644 (file)
@@ -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
index 1e4de14..f16e852 100644 (file)
@@ -22,6 +22,8 @@
 #include <QtGui/QWidget>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QMessageBox>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QTextEdit>
 #include <QMaemo5InformationBox>
 #include <QDebug>
 #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");
index 43d71b7..b8e88aa 100644 (file)
@@ -53,6 +53,7 @@ private:
     QToolButton* toggleButton_;
     SearchDialog* searchDialog_;
     AboutDialog* aboutDialog_;
+    QDialog* warning_;
 
 };
 
index f9dd623..11f0649 100644 (file)
@@ -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();
     }
 
 }
index 6bd9939..d150d4a 100644 (file)
@@ -50,10 +50,8 @@ private:
     ButtonSelector* siteSelector_;
     ButtonSelector* autostartSelector_;
     ConnectionSelector* connectionSelector_;
-    QCheckBox* autoconnectCheck_;
     QString currentSite_;
     QString currentConnection_;
-    bool currentAutoconnect_;
 };
 
 #endif

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment