#############################################################################
# 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
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
gtk-update-icon-cache -f /usr/share/icons/hicolor
-/etc/init.d/jenirokd start
-
exit 0
#include <QApplication>
#include <QtCore/QTimerEvent>
#include <QtCore/QVariant>
+#include <QtCore/QStringList>
#include <QtDBus/QDBusArgument>
#include <QtDBus/QDBusConnection>
#include <icd/dbus_api.h>
return true;
}
-bool ConnectionManager::getBestConnection(Connection& connection)
+bool ConnectionManager::getBestConnection(Connection& connection, ConnectionType type)
{
bool blockingValue = blocking_;
if(connections.size() == 0)
{
- qDebug() << "No connections";
error_ = NO_AVAILABLE_CONNECTIONS;
return false;
}
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;
break;
case GPRS:
- if(connections.at(i).strength > biggestGprs)
+ if(type != WLAN && connections.at(i).strength > biggestGprs)
{
biggestGprs = connections.at(i).strength;
bestGprs = i;
}
-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
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;
}
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_;
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
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;
"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>";
#include <QtSql/QSqlQuery>
#include <QtCore/QVariant>
+#include <QDebug>
+#include <gconf/gconf-client.h>
#include "settings.h"
#include "db.h"
defaultValues["autostart"] = "1";
defaultValues["eniro_site"] = tr("fi");
defaultValues["cache_size"] = "200";
- defaultValues["connection"] = "0";
- defaultValues["autoconnect"] = "0";
+ defaultValues["connection"] = "global";
defaultValuesLoaded = true;
}
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()
{
}
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:
<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'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'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'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>
#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
{
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,
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()
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);
{
qDebug() << "Error: " << eniro_->errorString();
- if(retries_ < NUMBER_OF_RETRIES && retries_ >= 0)
+ if(retries_ < SEARCH_RETRIES && retries_ >= 0)
{
retries_++;
eniro_->search(Eniro::SearchDetails(currentSearch_));
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
retries_ = -1;
currentSearch_ = "";
- if(closeConnection_ && connectionManager_)
+ if(closeConnection_)
{
- connectionManager_->disconnect(true);
+ ConnectionManager cm;
+ cm.disconnect(true);
closeConnection_ = false;
}
}
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;
}
return;
}
- connectionManager_ = new ConnectionManager;
-
eniro_ = new Eniro(site_);
eniro_->setMaxResults(1);
eniro_->setFindNumber(false);
box_ = new InformationBox;
label_ = new QLabel("", box_);
label_->setMargin(8);
+ label_->setWordWrap(true);
box_->setWidget(label_);
initialized_ = true;
}
Eniro::SearchDetails const&, bool)));
}
- delete connectionManager_;
- connectionManager_ = 0;
delete eniro_;
eniro_ = 0;
delete box_;
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)
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);
+ }
+}
#include <QtDBus/QDBusObjectPath>
#include "informationbox.h"
#include "eniro.h"
-#include "connectionmanager.h"
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);
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_;
QString currentSearch_;
Eniro::Site site_;
QString connectionName_;
+ int timer_;
bool autoconnect_;
};
RESOURCES = ../common/translations.grc
INCLUDEPATH += ../common
CONFIG += link_pkgconfig
-PKGCONFIG += libebook-1.2
+PKGCONFIG += libebook-1.2 gconf-2.0
unix {
#VARIABLES
CallListener listener;
- listener.begin();
+ if(!listener.begin())
+ {
+ return 1;
+ }
return app.exec();
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);
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++)
{
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
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);
+}
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;
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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
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
#include <QtGui/QWidget>
#include <QtGui/QHBoxLayout>
#include <QtGui/QMessageBox>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QTextEdit>
#include <QMaemo5InformationBox>
#include <QDebug>
#include "mainwindow.h"
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);
void MainWindow::showSettings()
{
+ if(warning_ && warning_->isVisible())
+ {
+ warning_->hide();
+ }
+
if(!settingsDialog_)
{
settingsDialog_ = new SettingsDialog(this);
}
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");
QToolButton* toggleButton_;
SearchDialog* searchDialog_;
AboutDialog* aboutDialog_;
+ QDialog* warning_;
};
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()));
general->addWidget(siteSelector_);
daemon->addWidget(autostartSelector_);
- daemon->addWidget(autoconnectCheck_);
daemon->addWidget(connectionSelector_);
QDialogButtonBox* buttons = new QDialogButtonBox;
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();
{
currentSite_ = siteSelector_->value().toString();
currentConnection_ = connectionSelector_->value().toString();
- currentAutoconnect_ = autoconnectCheck_->isChecked();
}
}
ButtonSelector* siteSelector_;
ButtonSelector* autostartSelector_;
ConnectionSelector* connectionSelector_;
- QCheckBox* autoconnectCheck_;
QString currentSite_;
QString currentConnection_;
- bool currentAutoconnect_;
};
#endif