Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Jenirok
Summary Tracker SCM Files
authoreshe <jessehakanen@gmail.com>
Wed, 9 Jun 2010 18:13:02 +0000 (19:13 +0100)
committereshe <jessehakanen@gmail.com>
Wed, 9 Jun 2010 18:13:02 +0000 (19:13 +0100)
14 files changed:
Makefile
src/common/connectionmanager.cpp
src/common/connectionmanager.h
src/common/settings.cpp
src/common/translations/fi_FI.qm
src/common/translations/fi_FI.ts
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/main.cpp
src/gui/buttonselector.cpp
src/gui/buttonselector.h
src/gui/gui.pro
src/gui/settingsdialog.cpp
src/gui/settingsdialog.h

index 9619b44..8b630ff 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: jenirok
-# Generated by qmake (2.01a) (Qt 4.6.2) on: Fri Jun 4 22:53:04 2010
+# Generated by qmake (2.01a) (Qt 4.6.2) on: Wed Jun 9 14:23:12 2010
 # Project:  jenirok.pro
 # Template: subdirs
 # Command: /usr/bin/qmake -unix -o Makefile jenirok.pro
index f45b0e2..8196520 100644 (file)
@@ -21,6 +21,7 @@
 #include <QtCore/QTimerEvent>
 #include <QtCore/QVariant>
 #include <QtDBus/QDBusArgument>
+#include <QtDBus/QDBusConnection>
 #include <icd/dbus_api.h>
 #include "connectionmanager.h"
 
@@ -28,7 +29,7 @@
 ConnectionManager::ConnectionManager(QObject* parent): QObject(parent),
 blocking_(true), stateReady_(false), connectionReady_(false), scanReady_(false),
 connected_(false), timeout_(false), numberOfConnections_(0),
-scannedConnections_(0), timer_(0), connections_(false)
+scannedConnections_(0), timer_(0), error_(NO_ERROR), connections_(0)
 {
     QDBusConnection systemBus = QDBusConnection::systemBus();
 
@@ -89,32 +90,129 @@ bool ConnectionManager::connect()
 
 bool ConnectionManager::connect(ConnectionManager::Connection const& connection)
 {
-    connectionReady_ = false;
-    QDBusArgument arg;
-    arg.beginStructure();
-    arg << connection.serviceType
-        << connection.serviceAttributes
-        << connection.serviceID
-        << connection.networkType
-        << connection.networkAttributes
-        << connection.networkID;
-    arg.endStructure();
+    return connect(connection.id);
+}
 
-    unsigned int flags = static_cast<unsigned int>(ICD_CONNECTION_FLAG_USER_EVENT);
-    QDBusMessage rep = icd2interface_->call(ICD_DBUS_API_CONNECT_REQ,
-                                            flags, arg.asVariant());
+bool ConnectionManager::connect(QString const& id)
+{
+    QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.icd",
+                                                      "/com/nokia/icd",
+                                                      "com.nokia.icd",
+                                                      "connect");
+    QList<QVariant> arguments;
 
-    qDebug() << rep.errorName() << rep.errorMessage();
+    arguments.append(QVariant(id));
 
-    if(blocking_)
+    unsigned int val = 0;
+
+    arguments.append(QVariant(val));
+
+    msg.setArguments(arguments);
+
+    QDBusMessage rep = QDBusConnection::systemBus().call(msg);
+
+    if(rep.type() == QDBusMessage::ErrorMessage)
     {
-        waitSignal(&connectionReady_);
-        return connected_;
+        if(rep.errorName() == "com.nokia.icd.error.invalid_iap")
+        {
+            error_ = INVALID_IAP;
+        }
+        else
+        {
+            error_ = UNKNOWN_ERROR;
+        }
+
+        return false;
     }
 
     return true;
 }
 
+bool ConnectionManager::getBestConnection(Connection& connection)
+{
+    bool blockingValue = blocking_;
+
+    blocking_ = true;
+
+    QList<Connection> connections;
+
+    if(!scanConnections(connections))
+    {
+        return false;
+    }
+
+    blocking_ = blockingValue;
+
+    if(connections.size() == 0)
+    {
+        qDebug() << "No connections";
+        error_ = NO_AVAILABLE_CONNECTIONS;
+        return false;
+    }
+
+    int biggestWlan = -1;
+    int biggestGprs = -1;
+    int bestWlan = -1;
+    int bestGprs = -1;
+
+    for(int i = 0; i < connections.size(); i++)
+    {
+       switch(connections.at(i).type)
+       {
+       case WLAN:
+           if(connections.at(i).strength > biggestWlan)
+           {
+               biggestWlan = connections.at(i).strength;
+               bestWlan = i;
+           }
+           break;
+
+       case GPRS:
+           if(connections.at(i).strength > biggestGprs)
+           {
+               biggestGprs = connections.at(i).strength;
+               bestGprs = i;
+           }
+           break;
+
+       default:
+           qDebug() << "Unknown connection type";
+       }
+    }
+
+    if(bestWlan >= 0)
+    {
+        connection = connections.at(bestWlan);
+        return true;
+    }
+    else if(bestGprs >= 0)
+    {
+        connection = connections.at(bestGprs);
+        return true;
+    }
+    else
+    {
+        error_ = NO_AVAILABLE_CONNECTIONS;
+        return false;
+    }
+
+}
+
+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
@@ -165,7 +263,7 @@ bool ConnectionManager::isConnected()
 
 bool ConnectionManager::scanConnections(QList<ConnectionManager::Connection>& connections)
 {
-    unsigned int flags = static_cast<unsigned int>(ICD_SCAN_REQUEST_ACTIVE);
+    unsigned int flags = static_cast<unsigned int>(ICD_SCAN_REQUEST_ACTIVE_SAVED);
     scanReady_ = false;
     scannedConnections_ = 0;
     connections_ = &connections;
@@ -189,6 +287,51 @@ 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_;
+}
+
 void ConnectionManager::stateChange(const QDBusMessage& rep)
 {
     unsigned int status = rep.arguments().value(7).value<unsigned int>();
@@ -281,6 +424,7 @@ void ConnectionManager::scanResult(const QDBusMessage& rep)
     if(scannedConnections_ >= numberOfConnections_)
     {
         scanReady_ = true;
+        connections_ = 0;
         emit scanReady();
         return;
     }
@@ -291,13 +435,25 @@ void ConnectionManager::scanResult(const QDBusMessage& rep)
     }
 
     Connection connection;
-    connection.serviceType = args.value(2).toString();
-    connection.serviceAttributes = args.value(4).value<unsigned int>();
-    connection.serviceID = args.value(5).toString();
-    connection.networkName = args.value(8).toString();
-    connection.networkType = args.value(7).toString();
-    connection.networkAttributes = args.value(9).value<unsigned int>();
-    connection.networkID = args.value(10).toByteArray();
+    connection.id = QString(args.value(10).toByteArray());
+    connection.name = args.value(8).toString();
+    connection.strength = args.value(11).toInt();
+
+    QString type = args.value(7).toString();
+
+    if(type == "GPRS")
+    {
+        connection.type = GPRS;
+    }
+    else if(type == "WLAN_INFRA" || type == "WLAN_ADHOC")
+    {
+        connection.type = WLAN;
+    }
+    else
+    {
+        qDebug() << "Unknown connection type: " << type;
+        return;
+    }
 
     emit newConnection(connection);
 
index 9261eb3..49e6dfc 100644 (file)
@@ -33,15 +33,16 @@ class ConnectionManager : public QObject
 
 public:
 
+    enum ConnectionType {WLAN, GPRS};
+    enum NetworkMode {NETWORK_UNKNOWN, NETWORK_2G, NETWORK_2_5G, NETWORK_3G, NETWORK_3_5G};
+    enum Error {NO_ERROR, NO_AVAILABLE_CONNECTIONS, INVALID_IAP, UNKNOWN_ERROR};
+
     struct Connection
     {
-        QString serviceType;
-        unsigned int serviceAttributes;
-        QString serviceID;
-        QString networkName;
-        QString networkType;
-        unsigned int networkAttributes;
-        QByteArray networkID;
+        ConnectionType type;
+        QString id;
+        QString name;
+        int strength;
     };
 
     ConnectionManager(QObject* parent = 0);
@@ -49,10 +50,15 @@ public:
     void setBlocking(bool value);
     bool connect();
     bool connect(Connection const& connection);
+    bool connect(QString const& id);
+    bool getBestConnection(Connection& connection);
+    bool autoConnect();
     bool disconnect(bool force = false);
     bool isConnected();
     bool scanConnections(QList<Connection>& connections);
-    static unsigned int const TIMEOUT = 25000;
+    NetworkMode getNetworkMode();
+    Error error() const;
+    static unsigned int const TIMEOUT = 20000;
 
 signals:
     void connectReply(bool connected);
@@ -79,6 +85,7 @@ private:
     int numberOfConnections_;
     int scannedConnections_;
     int timer_;
+    Error error_;
     QList<Connection>* connections_;
     QDBusInterface* icd2interface_;
 };
index 1333c21..85534d7 100644 (file)
@@ -118,6 +118,8 @@ QString Settings::getDefaultValue(QString const& name)
         defaultValues["autostart"] = "1";
         defaultValues["eniro_site"] = tr("fi");
         defaultValues["cache_size"] = "200";
+        defaultValues["connection"] = "0";
+        defaultValues["autoconnect"] = "0";
         defaultValuesLoaded = true;
     }
 
index e48e59f..0ae88bc 100644 (file)
Binary files a/src/common/translations/fi_FI.qm and b/src/common/translations/fi_FI.qm differ
index 7c7f6ae..a4bff39 100644 (file)
         <source>Phone number was not found</source>
         <translation>Numeroa ei löytynyt</translation>
     </message>
+    <message>
+        <source>No network connections found.</source>
+        <translation>Käytettävissä olevia verkkoyhteyksiä ei löytynyt.</translation>
+    </message>
+    <message>
+        <source>Selected access point doesn&apos;t exist.</source>
+        <translation>Valittua yhteysosoitetta ei löytynyt.</translation>
+    </message>
+    <message>
+        <source>No 3G or WLAN network available.</source>
+        <translation>Ei saatavilla olevaa 3G- tai WLAN-verkkoa.</translation>
+    </message>
+    <message>
+        <source>Unable to connect to network.</source>
+        <translation>Yhteyden muodostaminen ei onnistunut.</translation>
+    </message>
+</context>
+<context>
+    <name>ConnectionSelector</name>
+    <message>
+        <location filename="../../gui/connectionselector.cpp" line="35"/>
+        <source>Choose automatically</source>
+        <translation>Valitse automaattisesti</translation>
+    </message>
 </context>
 <context>
     <name>DetailWindow</name>
 <context>
     <name>Settings</name>
     <message>
-        <location filename="../settings.cpp" line="113"/>
+        <location filename="../settings.cpp" line="119"/>
         <source>fi</source>
         <translation>fi</translation>
     </message>
 <context>
     <name>SettingsDialog</name>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="40"/>
+        <location filename="../../gui/settingsdialog.cpp" line="41"/>
         <source>Settings</source>
         <translation>Asetukset</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="50"/>
+        <location filename="../../gui/settingsdialog.cpp" line="52"/>
         <source>Eniro username</source>
         <translation>Eniro-tunnus</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="53"/>
+        <location filename="../../gui/settingsdialog.cpp" line="55"/>
         <source>Eniro password</source>
         <translation>Eniro-salasana</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="57"/>
+        <location filename="../../gui/settingsdialog.cpp" line="59"/>
         <source>Cache size (numbers)</source>
         <translation>Välimuistin koko (numeroa)</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="60"/>
+        <location filename="../../gui/settingsdialog.cpp" line="62"/>
         <source>Clear</source>
         <translation>Tyhjennä</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="63"/>
+        <location filename="../../gui/settingsdialog.cpp" line="65"/>
         <source>Eniro site</source>
         <translation>Eniro-sivusto</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="80"/>
+        <location filename="../../gui/settingsdialog.cpp" line="82"/>
         <source>Finnish</source>
         <translation>Suomi</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="83"/>
+        <location filename="../../gui/settingsdialog.cpp" line="85"/>
         <source>Swedish</source>
         <translation>Ruotsi</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="86"/>
+        <location filename="../../gui/settingsdialog.cpp" line="88"/>
         <source>Danish</source>
         <translation>Tanska</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="103"/>
+        <location filename="../../gui/settingsdialog.cpp" line="105"/>
         <source>Autostart</source>
         <translation>Käynnistä automaattisesti</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="105"/>
+        <location filename="../../gui/settingsdialog.cpp" line="107"/>
         <source>Enabled</source>
         <translation>Kyllä</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="106"/>
+        <location filename="../../gui/settingsdialog.cpp" line="108"/>
         <source>Disabled</source>
         <translation>Ei</translation>
     </message>
     <message>
-        <location filename="../../gui/settingsdialog.cpp" line="109"/>
+        <location filename="../../gui/settingsdialog.cpp" line="111"/>
+        <source>Allow daemon to connect automatically</source>
+        <translation>Salli automaattinen verkkoyht. muodostus</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="155"/>
+        <location filename="../../gui/settingsdialog.cpp" line="150"/>
+        <source>General</source>
+        <translation>Yleiset</translation>
+    </message>
+    <message>
+        <location filename="../../gui/settingsdialog.cpp" line="151"/>
+        <source>Daemon</source>
+        <translation>Taustaprosessi</translation>
+    </message>
+    <message>
+        <location filename="../../gui/settingsdialog.cpp" line="185"/>
         <source>Restarting daemon...</source>
         <translation>Käynnistetään palvelu uudelleen...</translation>
     </message>
     <message numerus="yes">
-        <location filename="../../gui/settingsdialog.cpp" line="179"/>
+        <location filename="../../gui/settingsdialog.cpp" line="211"/>
         <source>%n number(s) were deleted from cache</source>
         <translation>
             <numerusform>Poistettiin %n numero välimuistista</numerusform>
index 4f2f4b6..149e441 100644 (file)
@@ -40,7 +40,7 @@ QDBusConnection CallListener::systemBus_ = QDBusConnection::systemBus();
 
 CallListener::CallListener(): eniro_(0), connectionManager_(0),
 closeConnection_(false), initialized_(false), box_(0), label_(0),
-retries_(-1), site_(Eniro::FI)
+retries_(-1), site_(Eniro::FI), autoconnect_(false)
 {
 }
 
@@ -66,6 +66,8 @@ 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...";
@@ -116,14 +118,10 @@ void CallListener::search(Eniro::SearchDetails const& details)
 
         showDelayedResult(tr("Searching..."), BANNER_DELAY);
 
-        if(!connectionManager_->isConnected())
+        if(!handleConnection())
         {
-            connectionManager_->connect();
-            closeConnection_ = true;
-        }
-        else
-        {
-            closeConnection_ = false;
+            qDebug() << "Unable to connect";
+            return;
         }
 
         qDebug() << "Starting to search...";
@@ -158,8 +156,7 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
         else
         {
             timedMessage_ = "";
-            message = tr("Search failed:") + " " + eniro_->errorString() + ".";
-            showResult(message);
+            showError(tr("Search failed:") + " " + eniro_->errorString() + ".");
         }
     }
     else
@@ -337,3 +334,100 @@ void CallListener::searchClose()
     box_ = 0;
     label_ = 0;
 }
+
+bool CallListener::handleConnection()
+{
+    if(!connectionManager_)
+    {
+        qDebug() << "Error: connection manager not initialized";
+        return false;
+    }
+
+    if(connectionManager_->isConnected())
+    {
+        closeConnection_ = false;
+        return true;
+    }
+
+    closeConnection_ = true;
+    int retries = 0;
+
+    if(autoconnect_)
+    {
+        QString conn;
+
+        if(connectionName_.size() != 0 && connectionName_ != "0")
+        {
+            conn = connectionName_;
+        }
+        else
+        {
+            ConnectionManager::Connection best;
+
+            if(!connectionManager_->getBestConnection(best))
+            {
+                showError(tr("No network connections found."));
+                return false;
+            }
+
+            conn = best.id;
+        }
+
+        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;
+            }
+
+            retries++;
+        }
+    }
+    else
+    {
+        while(retries < CONNECT_RETRIES)
+        {
+            if(connectionManager_->connect())
+            {
+                break;
+            }
+            else
+            {
+                qDebug() << "Automatic connection failed";
+            }
+
+            retries++;
+        }
+    }
+
+    if(retries >= CONNECT_RETRIES)
+    {
+        ConnectionManager::NetworkMode mode = connectionManager_->getNetworkMode();
+
+        if(mode != ConnectionManager::NETWORK_3G &&
+           mode != ConnectionManager::NETWORK_3_5G)
+        {
+            showError(tr("No 3G or WLAN network available."));
+        }
+        else
+        {
+            showError(tr("Unable to connect to network."));
+        }
+
+        return false;
+    }
+
+    return true;
+}
+
+void CallListener::showError(QString const& msg)
+{
+    qDebug() << "Error: " << msg;
+    box_->setTimeout(ERROR_BANNER_TIMEOUT);
+    showResult(msg);
+}
index 4fe29b4..54677f1 100644 (file)
@@ -39,7 +39,9 @@ public:
     void end();
     static const int REQUEST_TIMEOUT = 10000;
     static const int BANNER_DELAY = 350;
-    static const int NUMBER_OF_RETRIES = 3;
+    static const int NUMBER_OF_RETRIES = 2;
+    static const int CONNECT_RETRIES = 2;
+    static const int ERROR_BANNER_TIMEOUT = 5000;
 
 private slots:
     void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
@@ -55,6 +57,8 @@ private:
     void showDelayedResult(QString const& text, int delay);
     void searchInit();
     void searchClose();
+    bool handleConnection();
+    void showError(QString const& msg);
     QString createResult(QString const& name, QString const& street, QString const& city);
     QString timedMessage_;
     Eniro* eniro_;
@@ -67,6 +71,8 @@ private:
     int retries_;
     QString currentSearch_;
     Eniro::Site site_;
+    QString connectionName_;
+    bool autoconnect_;
 };
 
 #endif // CALLLISTENER_H
index a07d28e..ef17c49 100644 (file)
@@ -20,9 +20,8 @@
 #include <QtCore/QTranslator>
 #include <QtCore/QLocale>
 #include <QtCore/QString>
-#include <QtCore/QList>
-#include <QDebug>
 #include <QtGui/QApplication>
+#include <QDebug>
 #include "calllistener.h"
 #include "settings.h"
 
index d41ff9e..fafb52c 100644 (file)
@@ -58,6 +58,22 @@ void ButtonSelector::setCurrentIndex(int index)
     selector_->setCurrentIndex(index);
 }
 
+bool ButtonSelector::selectByValue(QVariant const& value)
+{
+    for(int i = 0; i < model_->rowCount(); i++)
+    {
+        QStandardItem* item = model_->item(i);
+
+        if(item && item->data(Qt::UserRole) == value)
+        {
+            setCurrentIndex(i);
+            return true;
+        }
+    }
+
+    return false;
+}
+
 int ButtonSelector::currentIndex() const
 {
     return selector_->currentIndex();
index cb05209..b2a20fc 100644 (file)
 
 class ButtonSelector : public QMaemo5ValueButton
 {
+
+Q_OBJECT
+
 public:
     ButtonSelector(QString const& text, QWidget* parent = 0);
     void addItem(QString const& text);
     void addItem(QString const& text, QVariant const& value);
     void clear();
     void setCurrentIndex(int index);
+    bool selectByValue(QVariant const& value);
     int currentIndex() const;
     QString text() const;
     QVariant value() const;
index 5ba8594..566689f 100644 (file)
@@ -1,8 +1,8 @@
 QT += network sql maemo5
 TARGET = jenirok
 TEMPLATE = app
-SOURCES += main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp aboutdialog.cpp buttonselector.cpp daemon.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp ../common/cache.cpp
-HEADERS += mainwindow.h searchdialog.h resultwindow.h detailwindow.h settingsdialog.h aboutdialog.h buttonselector.h daemon.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h ../common/cache.h
+SOURCES += main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp aboutdialog.cpp buttonselector.cpp connectionselector.cpp daemon.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp ../common/cache.cpp
+HEADERS += mainwindow.h searchdialog.h resultwindow.h detailwindow.h settingsdialog.h aboutdialog.h buttonselector.h connectionselector.h daemon.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h ../common/cache.h
 TRANSLATIONS = ../common/translations/fi_FI.ts
 RESOURCES = icons.grc ../common/translations.grc
 INCLUDEPATH += ../common
index 9b9ed10..f9dd623 100644 (file)
@@ -22,6 +22,7 @@
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QIntValidator>
 #include <QtGui/QDialogButtonBox>
+#include <QtGui/QTabWidget>
 #include <QMaemo5ValueButton>
 #include <QMaemo5InformationBox>
 #include <QDebug>
@@ -41,7 +42,8 @@ autostartSelector_(0)
 
     DB::connect();
 
-    QVBoxLayout* left = new QVBoxLayout;
+    QVBoxLayout* general = new QVBoxLayout;
+    QVBoxLayout* daemon = new QVBoxLayout;
     QHBoxLayout* mainLayout = new QHBoxLayout;
     QHBoxLayout* username = new QHBoxLayout;
     QHBoxLayout* password = new QHBoxLayout;
@@ -52,7 +54,7 @@ autostartSelector_(0)
 
     QLabel* passwordLabel = new QLabel(tr("Eniro password"));
     passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
-    passwordInput_->setEchoMode(QLineEdit::Password);
+    passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit);
 
     QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
     cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
@@ -106,6 +108,19 @@ 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);
+    QString selectedConnection = Settings::instance()->get("connection");
+
+    if(selectedConnection != "0")
+    {
+        connectionSelector_->addItem(Settings::instance()->get("connection_name"), selectedConnection);
+        connectionSelector_->selectByValue(selectedConnection);
+    }
+
     QPushButton* submitButton = new QPushButton(tr("Save"), this);
     connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
 
@@ -116,17 +131,31 @@ autostartSelector_(0)
     cache->addWidget(cacheLabel);
     cache->addWidget(cacheInput_);
     cache->addWidget(cacheResetButton);
-    left->addLayout(username);
-    left->addLayout(password);
-    left->addLayout(cache);
-    left->addWidget(siteSelector_);
-    left->addWidget(autostartSelector_);
+    general->addLayout(username);
+    general->addLayout(password);
+    general->addLayout(cache);
+    general->addWidget(siteSelector_);
+
+    daemon->addWidget(autostartSelector_);
+    daemon->addWidget(autoconnectCheck_);
+    daemon->addWidget(connectionSelector_);
 
     QDialogButtonBox* buttons = new QDialogButtonBox;
     buttons->setCenterButtons(false);
     buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
 
-    mainLayout->addLayout(left);
+    QTabWidget* tabs = new QTabWidget;
+
+    QWidget* generalTab = new QWidget;
+    generalTab->setLayout(general);
+
+    QWidget* daemonTab = new QWidget;
+    daemonTab->setLayout(daemon);
+
+    tabs->addTab(generalTab, tr("General"));
+    tabs->addTab(daemonTab, tr("Daemon"));
+
+    mainLayout->addWidget(tabs);
     mainLayout->addWidget(buttons);
 
     setLayout(mainLayout);
@@ -136,6 +165,8 @@ autostartSelector_(0)
 
 void SettingsDialog::saveSettings()
 {
+    hide();
+
     DB::connect();
 
     Settings::instance()->set("eniro_username", usernameInput_->text());
@@ -145,12 +176,17 @@ 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();
 
-    hide();
-
-    if(site != currentSite_ && Daemon::isRunning())
+    if((site != currentSite_ ||
+        autoconnect != currentAutoconnect_ ||
+        connection != currentConnection_) && Daemon::isRunning())
     {
         QMaemo5InformationBox::information(this, tr("Restarting daemon..."));
         Daemon::restart();
@@ -166,6 +202,8 @@ void SettingsDialog::setVisible(bool visible)
     if(visible)
     {
         currentSite_ = siteSelector_->value().toString();
+        currentConnection_ = connectionSelector_->value().toString();
+        currentAutoconnect_ = autoconnectCheck_->isChecked();
     }
 
 }
index 7ad2a8d..6bd9939 100644 (file)
 #include <QtGui/QDialog>
 #include <QtGui/QWidget>
 #include <QtGui/QLineEdit>
+#include <QtGui/QCheckBox>
 #include <QMaemo5ListPickSelector>
 #include "eniro.h"
 #include "buttonselector.h"
+#include "connectionselector.h"
 
 class SettingsDialog : public QDialog
 {
@@ -47,8 +49,11 @@ private:
     QLineEdit* cacheInput_;
     ButtonSelector* siteSelector_;
     ButtonSelector* autostartSelector_;
+    ConnectionSelector* connectionSelector_;
+    QCheckBox* autoconnectCheck_;
     QString currentSite_;
-    QString currentAutostart_;
+    QString currentConnection_;
+    bool currentAutoconnect_;
 };
 
 #endif

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment