+++ /dev/null
-#############################################################################
-# Makefile for building: jenirok
-# Generated by qmake (2.01a) (Qt 4.6.2) on: Thu Jun 10 20:41:54 2010
-# Project: jenirok.pro
-# Template: subdirs
-# Command: /usr/bin/qmake -unix -o Makefile jenirok.pro
-#############################################################################
-
-first: make_default
-MAKEFILE = Makefile
-QMAKE = /usr/bin/qmake
-DEL_FILE = rm -f
-CHK_DIR_EXISTS= test -d
-MKDIR = mkdir -p
-COPY = cp -f
-COPY_FILE = $(COPY)
-COPY_DIR = $(COPY) -r
-INSTALL_FILE = install -m 644 -p
-INSTALL_PROGRAM = install -m 755 -p
-INSTALL_DIR = $(COPY_DIR)
-DEL_FILE = rm -f
-SYMLINK = ln -f -s
-DEL_DIR = rmdir
-MOVE = mv -f
-CHK_DIR_EXISTS= test -d
-MKDIR = mkdir -p
-SUBTARGETS = \
- sub-src-gui \
- sub-src-daemon
-
-src/gui/$(MAKEFILE):
- @$(CHK_DIR_EXISTS) src/gui/ || $(MKDIR) src/gui/
- cd src/gui/ && $(QMAKE) /home/maemo/workspace/jenirok/src/gui/gui.pro -unix -o $(MAKEFILE)
-sub-src-gui-qmake_all: FORCE
- @$(CHK_DIR_EXISTS) src/gui/ || $(MKDIR) src/gui/
- cd src/gui/ && $(QMAKE) /home/maemo/workspace/jenirok/src/gui/gui.pro -unix -o $(MAKEFILE)
-sub-src-gui: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE)
-sub-src-gui-make_default: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE)
-sub-src-gui-make_first: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE) first
-sub-src-gui-all: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE) all
-sub-src-gui-clean: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE) clean
-sub-src-gui-distclean: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE) distclean
-sub-src-gui-install_subtargets: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE) install
-sub-src-gui-uninstall_subtargets: src/gui/$(MAKEFILE) FORCE
- cd src/gui/ && $(MAKE) -f $(MAKEFILE) uninstall
-src/daemon/$(MAKEFILE):
- @$(CHK_DIR_EXISTS) src/daemon/ || $(MKDIR) src/daemon/
- cd src/daemon/ && $(QMAKE) /home/maemo/workspace/jenirok/src/daemon/daemon.pro -unix -o $(MAKEFILE)
-sub-src-daemon-qmake_all: FORCE
- @$(CHK_DIR_EXISTS) src/daemon/ || $(MKDIR) src/daemon/
- cd src/daemon/ && $(QMAKE) /home/maemo/workspace/jenirok/src/daemon/daemon.pro -unix -o $(MAKEFILE)
-sub-src-daemon: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE)
-sub-src-daemon-make_default: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE)
-sub-src-daemon-make_first: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE) first
-sub-src-daemon-all: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE) all
-sub-src-daemon-clean: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE) clean
-sub-src-daemon-distclean: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE) distclean
-sub-src-daemon-install_subtargets: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE) install
-sub-src-daemon-uninstall_subtargets: src/daemon/$(MAKEFILE) FORCE
- cd src/daemon/ && $(MAKE) -f $(MAKEFILE) uninstall
-
-Makefile: jenirok.pro /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/linux-g++-maemo5/qmake.conf /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/unix.conf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/linux.conf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/qconfig.pri \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_functions.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_config.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_pre.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/release.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_post.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/warn_on.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/unix/thread.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/moc.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/resources.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/uic.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/yacc.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/lex.prf \
- /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/include_source_dir.prf
- $(QMAKE) -unix -o Makefile jenirok.pro
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/unix.conf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/linux.conf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/qconfig.pri:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_functions.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_config.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_pre.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/release.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_post.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/warn_on.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/unix/thread.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/moc.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/resources.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/uic.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/yacc.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/lex.prf:
-/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/include_source_dir.prf:
-qmake: qmake_all FORCE
- @$(QMAKE) -unix -o Makefile jenirok.pro
-
-qmake_all: sub-src-gui-qmake_all sub-src-daemon-qmake_all FORCE
-
-make_default: sub-src-gui-make_default sub-src-daemon-make_default FORCE
-make_first: sub-src-gui-make_first sub-src-daemon-make_first FORCE
-all: sub-src-gui-all sub-src-daemon-all FORCE
-clean: sub-src-gui-clean sub-src-daemon-clean FORCE
-distclean: sub-src-gui-distclean sub-src-daemon-distclean FORCE
- -$(DEL_FILE) Makefile
-install_subtargets: sub-src-gui-install_subtargets sub-src-daemon-install_subtargets FORCE
-uninstall_subtargets: sub-src-gui-uninstall_subtargets sub-src-daemon-uninstall_subtargets FORCE
-
-mocclean: compiler_moc_header_clean compiler_moc_source_clean
-
-mocables: compiler_moc_header_make_all compiler_moc_source_make_all
-install: install_subtargets FORCE
-
-uninstall: uninstall_subtargets FORCE
-
-FORCE:
-
return ret;
}
-bool Cache::findItem(QString const& number, Eniro::Result& result)
+bool Cache::findItem(QString const& number, Source::Result& result)
{
bool connected = DB::connected();
return ret;
}
-bool Cache::addItem(Eniro::Result const& result)
+bool Cache::addItem(Source::Result const& result)
{
bool connected = DB::connected();
#ifndef CACHE_H
#define CACHE_H
-#include "eniro.h"
+#include "source.h"
class Cache
{
public:
static Cache& instance();
int clear();
- bool findItem(QString const& number, Eniro::Result& result);
- bool addItem(Eniro::Result const& result);
+ bool findItem(QString const& number, Source::Result& result);
+ bool addItem(Source::Result const& result);
private:
Cache();
void DB::removeDatabase()
{
+ if(!initialized_)
+ {
+ return;
+ }
+
db_.close();
db_ = QSqlDatabase();
QSqlDatabase::removeDatabase(QSqlDatabase::defaultConnection);
--- /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 "emptycoreconfig.h"
+
+EmptyCoreConfig::EmptyCoreConfig(): SourceCoreConfig()
+{
+}
+
+EmptyCoreConfig::~EmptyCoreConfig()
+{
+}
+
+bool EmptyCoreConfig::apply(Source* source)
+{
+ Q_UNUSED(source);
+ return true;
+}
+
+void EmptyCoreConfig::getConfig(QMap<QString, QString>& config)
+{
+ Q_UNUSED(config);
+}
+
+void EmptyCoreConfig::loadFromConfig(QMap<QString, QString> const& config)
+{
+ Q_UNUSED(config);
+}
+
+void EmptyCoreConfig::store()
+{
+}
+
+bool EmptyCoreConfig::readyToSearch()
+{
+ return true;
+}
+
--- /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 EMPTYCORECONFIG_H
+#define EMPTYCORECONFIG_H
+
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include "sourcecoreconfig.h"
+
+class EmptyCoreConfig : public SourceCoreConfig
+{
+
+public:
+ EmptyCoreConfig();
+ virtual ~EmptyCoreConfig();
+ virtual bool apply(Source* source);
+ void store();
+ virtual void getConfig(QMap<QString, QString>& config);
+ virtual void loadFromConfig(QMap<QString, QString> const& config);
+ virtual bool readyToSearch();
+
+private:
+
+};
+
+#endif
static const QString LOGIN_CHECK = "<input class=\"inpTxt\" id=\"loginformUsername\"";
}
-// Regexp used to remove numbers from string
-QRegExp Eniro::numberCleaner_ = QRegExp("([^0-9]+)");
-
-// Removes html tags from string
-QRegExp Eniro::tagStripper_ = QRegExp("<([^>]+)>");
-
-Eniro::Eniro(Site site, QObject *parent): QObject(parent), site_(site),
-username_(""), password_(""), loggedIn_(false), error_(NO_ERROR),
-errorString_(""), maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0),
-findNumber_(true), pendingSearches_(), pendingNumberRequests_()
+Eniro::Eniro(QObject *parent): Source(parent), site_(Eniro::FI),
+loggedIn_(false), username_(""), password_(""),
+timerId_(0), pendingSearches_(), pendingNumberRequests_()
{
- connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
}
Eniro::~Eniro()
{
- abort();
}
void Eniro::abort()
{
- http_.abort();
+ Source::abort();
for(searchMap::iterator sit = pendingSearches_.begin();
sit != pendingSearches_.end(); sit++)
pendingLoginRequests_.clear();
}
-void Eniro::setMaxResults(unsigned int value)
-{
- maxResults_ = value;
-}
-
-void Eniro::setFindNumber(bool value)
-{
- findNumber_ = value;
-}
-
void Eniro::setSite(Eniro::Site site)
{
site_ = site;
}
-void Eniro::setTimeout(unsigned int ms)
+void Eniro::timerEvent(QTimerEvent* t)
{
- timeout_ = ms;
- resetTimeout();
-}
+ Q_UNUSED(t);
-void Eniro::resetTimeout()
-{
- if(timerId_)
- {
- killTimer(timerId_);
- }
- if(timeout_)
- {
- timerId_ = startTimer(timeout_);
- }
-}
+ int currentId = http_.currentId();
-void Eniro::timerEvent(QTimerEvent* t)
-{
- if(t->timerId() == timerId_)
+ if(currentId)
{
- int currentId = http_.currentId();
+ searchMap::const_iterator it = pendingSearches_.find(currentId);
- if(currentId)
+ if(it != pendingSearches_.end())
{
- searchMap::const_iterator it = pendingSearches_.find(currentId);
+ QVector <Eniro::Result> results = it.value()->results;
+ SearchDetails details = it.value()->details;
- if(it != pendingSearches_.end())
- {
- QVector <Eniro::Result> results = it.value()->results;
- SearchDetails details = it.value()->details;
+ abort();
- abort();
+ setError(TIMEOUT, TIMEOUT_STRING);
- error_ = TIMEOUT;
- errorString_ = TIMEOUT_STRING;
-
- emit requestFinished(results, details, true);
- }
+ emit requestFinished(results, details, true);
}
-
}
}
loggedIn_ = false;
}
-void Eniro::testLogin()
-{
- QUrl url = createUrl("", "");
-
- url.addQueryItem("what", "mobwp");
- http_.setHost(url.host(), url.port(80));
- int id = http_.get(url.encodedPath() + '?' + url.encodedQuery());
-
- pendingLoginRequests_.insert(id);
-}
-
-bool Eniro::search(SearchDetails const& details)
+void Eniro::search(SearchDetails const& details)
{
resetTimeout();
http_.setHost(url.host(), url.port(80));
int id = http_.get(url.encodedPath() + '?' + url.encodedQuery());
- QVector <Result> results;
+ QVector <Source::Result> results;
// Store search data for later identification
SearchData* newData = new SearchData;
// Store request id so that it can be identified later
pendingSearches_[id] = newData;
- return true;
-}
-
-Eniro::Error Eniro::error() const
-{
- return error_;
}
-const QString& Eniro::errorString() const
+void Eniro::handleHttpData(int id, QString const& data)
{
- return errorString_;
-}
-
-void Eniro::httpReady(int id, bool error)
-{
- if(error)
- {
- qDebug() << "Error: " << http_.errorString();
- }
-
+ qDebug() << "Handle:" << id;
searchMap::const_iterator searchIt;
numberMap::const_iterator numberIt;
if((searchIt = pendingSearches_.find(id)) !=
pendingSearches_.end())
{
- if(error)
- {
- error_ = CONNECTION_FAILURE;
- errorString_ = http_.errorString();
- emitRequestFinished(id, searchIt.value(), true);
- return;
- }
-
- QString result(http_.readAll());
-
+ qDebug() << "Load results";
// Load results from html data
- loadResults(id, result);
+ loadResults(id, data);
}
// Check if request is pending number requests
else if((numberIt = pendingNumberRequests_.find(id)) !=
pendingNumberRequests_.end())
{
- if(error)
- {
- error_ = CONNECTION_FAILURE;
- errorString_ = http_.errorString();
- delete pendingNumberRequests_[id];
- pendingNumberRequests_.remove(id);
- return;
- }
-
- QString result(http_.readAll());
-
// Load number from html data
- loadNumber(id, result);
+ loadNumber(id, data);
}
// Check for login request
{
bool success = true;
- if(!error)
- {
- QString result(http_.readAll());
-
- // If html source contains LOGIN_CHECK, login failed
- if(result.indexOf(LOGIN_CHECK) != -1)
- {
- success = false;
- }
- }
- else
+ // If html source contains LOGIN_CHECK, login failed
+ if(data.indexOf(LOGIN_CHECK) != -1)
{
success = false;
}
}
+void Eniro::handleHttpError(int id)
+{
+ searchMap::const_iterator searchIt;
+ numberMap::const_iterator numberIt;
+
+ // Check if request is pending search request
+ if((searchIt = pendingSearches_.find(id)) !=
+ pendingSearches_.end())
+ {
+ setError(CONNECTION_FAILURE, http_.errorString());
+ emitRequestFinished(id, searchIt.value(), true);
+ }
+
+ // Check if request is pending number requests
+ else if((numberIt = pendingNumberRequests_.find(id)) !=
+ pendingNumberRequests_.end())
+ {
+ setError(CONNECTION_FAILURE, http_.errorString());
+ delete pendingNumberRequests_[id];
+ pendingNumberRequests_.remove(id);
+ }
+
+ // Check for login request
+ else if(pendingLoginRequests_.find(id) !=
+ pendingLoginRequests_.end())
+ {
+ emit loginStatus(false);
+
+ }
+}
+
// Loads results from html source code
void Eniro::loadResults(int id, QString const& httpData)
{
// If phone number searh is enabled, we have to make another
// request to find it out
- if(findNumber_ && size < 4 && loggedIn_ &&
+ if(getFindNumber() && size < 4 && loggedIn_ &&
it.value()->details.type != YELLOW_PAGES)
{
requestsPending = true;
emit resultAvailable(result, it.value()->details);
}
+ unsigned int maxResults = getMaxResults();
+
// Stop searching if max results is reached
- if(maxResults_ && (foundResults >= maxResults_))
+ if(maxResults && (foundResults >= maxResults))
{
break;
}
if(httpData.indexOf(LOGIN_CHECK) != -1)
{
- error_ = INVALID_LOGIN;
- errorString_ = INVALID_LOGIN_STRING;
+ setError(INVALID_LOGIN, INVALID_LOGIN_STRING),
error = true;
}
if(error)
{
- error_ = INVALID_LOGIN;
- errorString_ = INVALID_LOGIN;
+ setError(INVALID_LOGIN, INVALID_LOGIN_STRING);
emitRequestFinished(searchIt.key(), searchIt.value(), true);
}
url.addQueryItem("geo_area", location);
}
- if(maxResults_)
+ unsigned int maxResults = getMaxResults();
+
+ if(maxResults)
{
- url.addQueryItem("hpp", QString::number(maxResults_));
+ url.addQueryItem("hpp", QString::number(maxResults));
}
if(loggedIn_)
{
url.addQueryItem("login_password", password_);
}
- QByteArray path = url.encodedQuery().replace('+', "%2B");
- url.setEncodedQuery(path);
+ fixUrl(url);
return url;
}
void Eniro::emitRequestFinished(int key, SearchData* data, bool error)
{
-
- // Do not emit "Request aborted" error
- if(!(error && (http_.error() == QHttp::Aborted)))
- {
- emit requestFinished(data->results, data->details, error);
- }
-
+ emit requestFinished(data->results, data->details, error);
delete pendingSearches_[key];
pendingSearches_[key] = 0;
pendingSearches_.remove(key);
}
-QString Eniro::ucFirst(QString& str)
-{
- if (str.size() < 1) {
- return "";
- }
-
- QStringList tokens = str.split(" ");
- QList<QString>::iterator tokItr;
-
- for (tokItr = tokens.begin(); tokItr != tokens.end(); ++tokItr)
- {
- (*tokItr) = (*tokItr).at(0).toUpper() + (*tokItr).mid(1);
- }
-
- return tokens.join(" ");
-}
-
-QString& Eniro::cleanUpNumber(QString& number)
-{
- return number.replace(numberCleaner_, "");
-}
-
-QString& Eniro::stripTags(QString& string)
-{
- return string.replace(tagStripper_, "");
-}
QMap <Eniro::Site, Eniro::SiteDetails> Eniro::getSites()
{
if(lower == SITE_NAMES[i] || lower == SITE_IDS[i])
{
site = static_cast <Site> (i);
+ break;
}
}
return site;
}
-
-Eniro::SearchDetails::SearchDetails(QString const& q,
- QString const& loc,
- SearchType t)
-{
- query = q;
- location = loc;
- type = t;
-}
#include <QtCore/QUrl>
#include <QtCore/QTimerEvent>
#include <QtNetwork/QHttp>
+#include "source.h"
-class Eniro: public QObject
+class Eniro: public Source
{
Q_OBJECT
public:
enum Site {FI, SE, DK};
- static const int SITE_COUNT = 3;
-
- enum SearchType {YELLOW_PAGES, PERSONS};
-
- enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT};
-
- struct Result
- {
- QString name;
- QString street;
- QString city;
- QString number;
- };
-
- struct SearchDetails
- {
- QString query;
- QString location;
- SearchType type;
- SearchDetails(QString const& query = "",
- QString const& location = "",
- SearchType type = PERSONS);
- };
struct SiteDetails
{
QString id;
};
- static unsigned int const DEFAULT_MAX_RESULTS = 30;
-
- Eniro(Site site, QObject *parent = 0);
+ static const int SITE_COUNT = 3;
+ Eniro(QObject *parent = 0);
~Eniro();
-
void login(QString const& username, QString const& password);
void logout();
- void testLogin();
void setSite(Site);
- void setMaxResults(unsigned int value);
- void setFindNumber(bool value);
- void setTimeout(unsigned int ms);
- bool search(SearchDetails const& details);
- void abort();
- Error error() const;
- const QString& errorString() const;
+ virtual void search(Source::SearchDetails const& details);
+ virtual void abort();
static QMap<Site, SiteDetails> getSites();
static Site stringToSite(QString const& str);
signals:
- void resultAvailable(Eniro::Result const& result, Eniro::SearchDetails const& details);
- void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
void loginStatus(bool success);
-private slots:
- void httpReady(int id, bool error);
-
private:
Q_DISABLE_COPY(Eniro);
struct SearchData
{
- SearchDetails details;
- QVector <Result> results;
+ Source::SearchDetails details;
+ QVector <Source::Result> results;
unsigned int foundNumbers;
unsigned int numbersTotal;
};
+ virtual void handleHttpData(int id, QString const& data);
+ virtual void handleHttpError(int id);
QUrl createUrl(QString const& query, QString const& location);
void loadResults(int id, QString const& data);
void loadNumber(int id, QString const& data);
void getNumberForResult(int id, int index, SearchDetails const& details);
void emitRequestFinished(int key, SearchData* data, bool error);
- void resetTimeout();
- void timerEvent(QTimerEvent *te);
- QString ucFirst(QString& string);
- QString& cleanUpNumber(QString& number);
- QString& stripTags(QString& string);
+ void timerEvent(QTimerEvent *t);
- QHttp http_;
Site site_;
+ bool loggedIn_;
QString username_;
QString password_;
- bool loggedIn_;
- Error error_;
- QString errorString_;
- unsigned int maxResults_;
- unsigned int timeout_;
int timerId_;
- bool findNumber_;
typedef QMap <int, SearchData*> searchMap;
typedef QMap <int, NumberData*> numberMap;
searchMap pendingSearches_;
--- /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/QDebug>
+#include "enirocoreconfig.h"
+#include "eniro.h"
+#include "settings.h"
+
+namespace
+{
+ QString const COLUMN_PREFIX = "eniro_";
+ QString const USERNAME_COLUMN = COLUMN_PREFIX + "username";
+ QString const PASSWORD_COLUMN = COLUMN_PREFIX + "password";
+ QString const SITE_COLUMN = COLUMN_PREFIX + "site";
+}
+
+EniroCoreConfig::EniroCoreConfig(): SourceCoreConfig(), loaded_(false)
+{
+}
+
+EniroCoreConfig::~EniroCoreConfig()
+{
+}
+
+bool EniroCoreConfig::apply(Source* source)
+{
+ Eniro* eniro = dynamic_cast<Eniro*>(source);
+
+ if(!eniro)
+ {
+ return false;
+ }
+
+ load();
+
+ QString username = config_[USERNAME_COLUMN];
+ QString password = config_[PASSWORD_COLUMN];
+
+ if(!username.isEmpty() && !password.isEmpty())
+ {
+ eniro->login(username, password);
+ }
+
+ eniro->setSite(Eniro::stringToSite(config_[SITE_COLUMN]));
+
+ return true;
+}
+
+void EniroCoreConfig::getConfig(QMap<QString, QString>& config)
+{
+ load();
+
+ config = config_;
+}
+
+void EniroCoreConfig::loadFromConfig(QMap<QString, QString> const& config)
+{
+ config_[USERNAME_COLUMN] = config[USERNAME_COLUMN];
+ config_[PASSWORD_COLUMN] = config[PASSWORD_COLUMN];
+ config_[SITE_COLUMN] = config[SITE_COLUMN];
+
+ loaded_ = true;
+}
+
+void EniroCoreConfig::store()
+{
+ Settings::instance()->set(USERNAME_COLUMN, config_[USERNAME_COLUMN]);
+ Settings::instance()->set(PASSWORD_COLUMN, config_[PASSWORD_COLUMN]);
+ Settings::instance()->set(SITE_COLUMN, config_[SITE_COLUMN]);
+}
+
+bool EniroCoreConfig::readyToSearch()
+{
+ load();
+
+ return !config_[USERNAME_COLUMN].isEmpty() && !config_[PASSWORD_COLUMN].isEmpty();
+}
+
+void EniroCoreConfig::setUsername(QString const& username)
+{
+ config_[USERNAME_COLUMN] = username;
+}
+
+void EniroCoreConfig::setPassword(QString const& password)
+{
+ config_[PASSWORD_COLUMN] = password;
+}
+
+void EniroCoreConfig::setSite(QString const& site)
+{
+ config_[SITE_COLUMN] = site;
+}
+
+QString EniroCoreConfig::getUsername() const
+{
+ return config_[USERNAME_COLUMN];
+}
+
+QString EniroCoreConfig::getPassword() const
+{
+ return config_[PASSWORD_COLUMN];
+}
+
+QString EniroCoreConfig::getSite() const
+{
+ return config_[SITE_COLUMN];
+}
+
+void EniroCoreConfig::load()
+{
+ if(loaded_)
+ {
+ return;
+ }
+
+ Settings::instance()->startEdit();
+
+ config_[USERNAME_COLUMN] = Settings::instance()->get(USERNAME_COLUMN);
+ config_[PASSWORD_COLUMN] = Settings::instance()->get(PASSWORD_COLUMN);
+ config_[SITE_COLUMN] = Settings::instance()->get(SITE_COLUMN);
+
+ Settings::instance()->endEdit();
+
+ loaded_ = true;
+}
--- /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 ENIROCORECONFIG_H
+#define ENIROCORECONFIG_H
+
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include "sourcecoreconfig.h"
+
+class EniroCoreConfig : public SourceCoreConfig
+{
+
+public:
+ EniroCoreConfig();
+ virtual ~EniroCoreConfig();
+ virtual bool apply(Source* source);
+ void store();
+ virtual void getConfig(QMap<QString, QString>& config);
+ virtual void loadFromConfig(QMap<QString, QString> const& config);
+ virtual bool readyToSearch();
+
+protected:
+ void setUsername(QString const& username);
+ void setPassword(QString const& password);
+ void setSite(QString const& site);
+ void load();
+ QString getUsername() const;
+ QString getPassword() const;
+ QString getSite() const;
+
+private:
+ QMap<QString, QString> config_;
+ bool loaded_;
+};
+
+#endif
--- /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/QDebug>
+#include "mobil1881.h"
+
+
+Mobil1881::Mobil1881(QObject* parent): Source(parent)
+{
+}
+
+Mobil1881::~Mobil1881()
+{
+ abort();
+}
+
+void Mobil1881::abort()
+{
+ Source::abort();
+
+ for(int i = 0; i < pendingSearches_.size(); i++)
+ {
+ delete pendingSearches_[i];
+ pendingSearches_[i] = 0;
+ }
+
+ pendingSearches_.clear();
+
+}
+
+void Mobil1881::search(Source::SearchDetails const& details)
+{
+ resetTimeout();
+
+ int id = sendQuery(details, 1);
+
+ SearchData* newData = new SearchData;
+ newData->details = details;
+ newData->searchIds.insert(id);
+ newData->currentPage = 1;
+
+ pendingSearches_.push_back(newData);
+}
+
+void Mobil1881::handleHttpData(int id, QString const& data)
+{
+ for(int i = 0; i < pendingSearches_.size(); i++)
+ {
+ if(pendingSearches_.at(i) && pendingSearches_.at(i)->searchIds.find(id) !=
+ pendingSearches_.at(i)->searchIds.end())
+ {
+
+ addNumbers(pendingSearches_.at(i), data, i);
+ break;
+ }
+ }
+}
+
+void Mobil1881::handleHttpError(int id)
+{
+ for(int i = 0; i < pendingSearches_.size(); i++)
+ {
+ if(pendingSearches_.at(i) && pendingSearches_.at(i)->searchIds.find(id) !=
+ pendingSearches_.at(i)->searchIds.end())
+ {
+
+ setError(Source::CONNECTION_FAILURE, http_.errorString());
+ emitRequestFinished(pendingSearches_.at(i), true, i);
+ break;
+ }
+ }
+}
+
+void Mobil1881::addNumbers(SearchData* searchData,
+ QString const& data,
+ int index)
+{
+ if(data.indexOf("<b>Last ned vCard</b>") > 0)
+ {
+ addOnlyNumber(searchData, data, index);
+ return;
+ }
+
+ int pos = 0;
+ QRegExp rx("<td valign=\"top\" width=\"99%\">(.*)</td>");
+ QRegExp name("<div class=\"srln\">(.*)</div>");
+ QRegExp address("<div class=\"srla\">(.*),<br/>(.*)</div>");
+ QRegExp number("<div class=\"srlp\">(.*)</div>");
+ rx.setMinimal(true);
+ name.setMinimal(true);
+ address.setMinimal(true);
+ number.setMinimal(true);
+
+ int maxResults = getMaxResults();
+
+ while((pos = rx.indexIn(data, pos)) != -1)
+ {
+ pos += rx.matchedLength();
+
+ if(searchData->results.size() >= maxResults)
+ {
+ break;
+ }
+
+ QString part = rx.cap(1);
+ Source::Result result;
+ QString nameStr;
+ QString numberStr;
+ QString streetStr;
+ QString cityStr;
+
+ if(name.indexIn(part) != -1)
+ {
+ nameStr = name.cap(1);
+ }
+
+ if(address.indexIn(part) != -1)
+ {
+ streetStr = address.cap(1);
+ cityStr = address.cap(2);
+ }
+
+ if(number.indexIn(part) != -1)
+ {
+ numberStr = number.cap(1);
+ }
+
+ if(formatResult(nameStr, numberStr, streetStr,
+ cityStr, result))
+ {
+ emit resultAvailable(result, searchData->details);
+ searchData->results.push_back(result);
+ }
+
+ }
+
+ if(searchData->results.size() >= maxResults)
+ {
+ emitRequestFinished(searchData, false, index);
+ }
+ else
+ {
+
+ if(data.indexOf("Neste") > 0)
+ {
+ searchData->currentPage++;
+ int id = sendQuery(searchData->details, searchData->currentPage);
+ searchData->searchIds.insert(id);
+ }
+ else
+ {
+ emitRequestFinished(searchData, false, index);
+ }
+ }
+
+}
+
+void Mobil1881::addOnlyNumber(SearchData* searchData,
+ QString const& data,
+ int index)
+{
+ QRegExp name("<div class=\"srsln\">(.*)</div>");
+ QRegExp number("class=\"srlttxt\"><b>(.*)</b>");
+ QRegExp address("class=\"srlttxt\"><span>(.*),<br/>(.*)</span>");
+ name.setMinimal(true);
+ number.setMinimal(true);
+ address.setMinimal(true);
+
+ Source::Result result;
+
+ QString nameStr;
+ QString numberStr;
+ QString streetStr;
+ QString cityStr;
+
+ if(name.indexIn(data) != -1)
+ {
+ nameStr = name.cap(1);
+ }
+
+ if(number.indexIn(data) != -1)
+ {
+ numberStr = number.cap(1);
+ }
+
+ if(address.indexIn(data) != -1)
+ {
+ streetStr = address.cap(1);
+ cityStr = address.cap(2);
+ }
+
+ if(formatResult(nameStr, numberStr, streetStr,
+ cityStr, result))
+ {
+ searchData->results.push_back(result);
+ emit resultAvailable(result, searchData->details);
+ }
+
+ emitRequestFinished(searchData, false, index);
+}
+
+bool Mobil1881::formatResult(QString& name, QString& number,
+ QString& street, QString& city,
+ Source::Result& result)
+{
+ name = stripTags(name);
+ result.name = name.trimmed();
+ number = stripTags(number);
+ number = cleanUpNumber(number);
+ result.number = number.trimmed();
+ street = stripTags(street);
+ city = stripTags(city);
+ result.street = street.trimmed();
+ result.city = city.trimmed();
+
+ if(!result.name.isEmpty() && !result.number.isEmpty())
+ {
+ return true;
+ }
+
+ return false;
+}
+
+void Mobil1881::emitRequestFinished(SearchData* data,
+ bool error, int index)
+{
+ QVector<Source::Result> results = data->results;
+ Source::SearchDetails details = data->details;
+
+ emit requestFinished(results, details, error);
+ delete pendingSearches_[index];
+ pendingSearches_[index] = 0;
+ pendingSearches_.removeAt(index);
+}
+
+int Mobil1881::sendQuery(Source::SearchDetails const& details,
+ int page)
+{
+ QUrl url("http://wap.1881.no/");
+ url.addQueryItem("i", "4854");
+ url.addQueryItem("showonly", "1");
+ QString query = details.query;
+
+ if(!details.location.isEmpty())
+ {
+ query += details.location;
+ }
+
+ url.addQueryItem("s", query);
+ if(details.type == Source::YELLOW_PAGES)
+ {
+ url.addQueryItem("t", "c");
+ }
+ else
+ {
+ url.addQueryItem("t", "p");
+ }
+
+ if(page > 1)
+ {
+ url.addQueryItem("p", QString::number(page));
+ }
+
+ fixUrl(url);
+
+ http_.setHost(url.host(), url.port(80));
+ return http_.get(url.encodedPath() + '?' + url.encodedQuery());
+}
--- /dev/null
+#ifndef MOBIL1881_H
+#define MOBIL1881_H
+
+#include <QtCore/QList>
+#include <QtCore/QSet>
+#include <QtCore/QVector>
+#include "source.h"
+
+class Mobil1881 : public Source
+{
+public:
+ Mobil1881(QObject* parent = 0);
+ ~Mobil1881();
+ virtual void abort();
+ virtual void search(Source::SearchDetails const& details);
+
+private:
+
+ struct SearchData
+ {
+ QSet<int> searchIds;
+ Source::SearchDetails details;
+ QVector<Source::Result> results;
+ int currentPage;
+ };
+
+ void addNumbers(SearchData* searchData, QString const& data, int index);
+ void addOnlyNumber(SearchData* searchData, QString const& data, int index);
+ bool formatResult(QString& name, QString& number, QString& street, QString& city, Source::Result& result);
+ void emitRequestFinished(SearchData* data, bool error, int index);
+ int sendQuery(Source::SearchDetails const& details, int page = 1);
+
+ QList<SearchData*> pendingSearches_;
+
+ Q_DISABLE_COPY(Mobil1881);
+ virtual void handleHttpData(int id, QString const& data);
+ virtual void handleHttpError(int id);
+};
+
+#endif // MOBIL1881_H
#include <QtSql/QSqlQuery>
#include <QtCore/QVariant>
#include <QtCore/QDebug>
+#include <QtCore/QTranslator>
+#include <QtCore/QLocale>
#include <gconf/gconf-client.h>
#include "settings.h"
#include "db.h"
+namespace
+{
+ static int const LANGUAGE_COUNT = 2;
+
+ static QString const LANGUAGE_NAMES[LANGUAGE_COUNT] = {
+ "English",
+ "Suomi"
+ };
+
+ static QString const LANGUAGE_IDS[LANGUAGE_COUNT] = {
+ "en_US",
+ "fi_FI"
+ };
+}
+
Settings* Settings::instance_ = 0;
Settings* Settings::instance()
return instance_;
}
+void Settings::getLanguages(QList<Settings::Language>& languages)
+{
+ for(int i = 0; i < LANGUAGE_COUNT; i++)
+ {
+ Language lang;
+ lang.name = LANGUAGE_NAMES[i];
+ lang.id = LANGUAGE_IDS[i];
+ languages.push_back(lang);
+ }
+}
+
+void Settings::loadLanguage(QApplication& app)
+{
+ QString language = get("language");
+
+ if(language.isEmpty())
+ {
+ language = QLocale::system().name();
+ }
+
+ QTranslator* translator = new QTranslator(&app);
+ translator->load(":/translations/" + language);
+ app.installTranslator(translator);
+}
+
void Settings::close()
{
delete instance_;
instance_ = 0;
}
-bool Settings::set(QString const& name, QString const& value)
+void Settings::startEdit()
{
- bool connected = DB::connected();
+ if(!editing_ && !DB::connected())
+ {
+ editing_ = DB::connect();
+ }
+}
- if(!connected)
+void Settings::endEdit()
+{
+ if(editing_)
{
- if(!DB::connect())
- {
- return false;
- }
+ DB::disconnect();
+ editing_ = false;
}
+}
+
+bool Settings::set(QString const& name, QString const& value)
+{
+ bool close = !editing_;
+
+ startEdit();
QSqlQuery deleteQuery;
deleteQuery.prepare("DELETE FROM settings WHERE name = :name");
bool returnValue = query.exec();
- if(!connected)
+ if(close)
{
- DB::disconnect();
+ endEdit();
}
return returnValue;
{
QString result = "";
- bool connected = DB::connected();
+ bool close = !editing_;
- if(!connected)
- {
- if(!DB::connect())
- {
- return result;
- }
- }
+ startEdit();
QSqlQuery query;
result = getDefaultValue(name);
}
- if(!connected)
+ if(close)
{
- DB::disconnect();
+ endEdit();
}
return result;
bool Settings::reset()
{
- bool connected = DB::connected();
+ bool close = !editing_;
- if(!connected)
- {
- if(!DB::connect())
- {
- return false;
- }
- }
+ startEdit();
QSqlQuery query;
bool ret = query.exec("DELETE FROM settings");
- if(!connected)
+ if(close)
{
- DB::disconnect();
+ endEdit();
}
return ret;
return ALWAYS_ASK;
}
-Settings::Settings()
+Settings::Settings(): editing_(false)
+{
+}
+
+Settings::~Settings()
{
+ DB::removeDatabase();
}
#define SETTINGS_H
#include <QtCore/QString>
-#include <QCoreApplication>
+#include <QtCore/QList>
+#include <QtGui/QApplication>
class Settings;
enum ConnectionType {ALWAYS_ASK, WLAN, GPRS, ANY};
+ struct Language
+ {
+ QString name;
+ QString id;
+ };
+
static Settings* instance();
+ static void getLanguages(QList<Language>& languages);
+ ~Settings();
static void close();
+ void startEdit();
+ void endEdit();
+ void loadLanguage(QApplication& app);
bool set(QString const& name, QString const& value);
QString get(QString const& name);
QString getDefaultValue(QString const& name);
private:
Settings();
static Settings* instance_;
+ bool editing_;
};
--- /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/QDebug>
+#include "source.h"
+#include "eniro.h"
+#include "mobil1881.h"
+
+namespace
+{
+ static const QString SOURCE_NAMES[Source::SOURCE_COUNT] =
+ {
+ "Eniro (FI, SE, DK)",
+ "1881 Mobil (NO)"
+ };
+
+ static const QString SOURCE_IDS[Source::SOURCE_COUNT] =
+ {
+ "eniro",
+ "1881mobil"
+ };
+
+}
+
+// Regexp used to remove everything except numbers from string
+QRegExp Source::numberCleaner_ = QRegExp("([^0-9]+)");
+
+// Removes html tags from string
+QRegExp Source::tagStripper_ = QRegExp("<([^>]+)>");
+
+Source* Source::getSource(Source::SourceId id, QObject* parent)
+{
+ switch(id)
+ {
+ case ENIRO:
+ return new Eniro(parent);
+ break;
+ case MOBIL1881:
+ return new Mobil1881(parent);
+ break;
+ default:
+ qDebug() << "Unknown source:" << id;
+ }
+
+ return 0;
+}
+
+Source::SourceId Source::stringToId(QString const& str)
+{
+ for(int i = 0; i < SOURCE_COUNT; i++)
+ {
+ if(SOURCE_IDS[i] == str || SOURCE_NAMES[i] == str)
+ {
+ return static_cast<SourceId>(i);
+ }
+ }
+
+ return ENIRO;
+}
+
+void Source::getSources(QList<SourceDetails>& list)
+{
+ for(int i = 0; i < SOURCE_COUNT; i++)
+ {
+ SourceDetails details;
+ details.type = static_cast<SourceId>(i);
+ details.name = SOURCE_NAMES[i];
+ details.id = SOURCE_IDS[i];
+ list.push_back(details);
+ }
+}
+
+Source::Source(QObject* parent): QObject(parent),
+maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(false),
+error_(NO_ERROR), loggedIn_(false)
+{
+ connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
+}
+
+Source::~Source()
+{
+ abort();
+}
+
+void Source::abort()
+{
+ http_.abort();
+}
+
+void Source::setMaxResults(unsigned int results)
+{
+ maxResults_ = results;
+}
+
+unsigned int Source::getMaxResults() const
+{
+ return maxResults_;
+}
+
+void Source::setTimeout(unsigned int timeout)
+{
+ timeout_ = timeout;
+ resetTimeout();
+}
+
+unsigned int Source::getTimeout() const
+{
+ return timeout_;
+}
+
+void Source::resetTimeout()
+{
+ if(timerId_)
+ {
+ killTimer(timerId_);
+ }
+ if(timeout_)
+ {
+ timerId_ = startTimer(timeout_);
+ }
+}
+
+void Source::timerEvent(QTimerEvent* t)
+{
+ Q_UNUSED(t);
+}
+
+void Source::setFindNumber(bool value)
+{
+ findNumber_ = value;
+}
+
+bool Source::getFindNumber() const
+{
+ return findNumber_;
+}
+
+Source::Error Source::error() const
+{
+ return error_;
+}
+
+const QString& Source::errorString() const
+{
+ return errorString_;
+}
+
+void Source::setError(Source::Error error, QString const& errorString)
+{
+ error_ = error;
+ errorString_ = errorString;
+}
+
+void Source::httpReady(int id, bool error)
+{
+
+ if(error)
+ {
+ if(http_.error() == QHttp::Aborted)
+ {
+ return;
+ }
+
+ qDebug() << "Error: " << http_.errorString();
+ handleHttpError(id);
+ }
+ else
+ {
+ QString result(http_.readAll());
+ handleHttpData(id, result);
+ }
+}
+
+QString Source::ucFirst(QString& str)
+{
+ if (str.size() < 1) {
+ return "";
+ }
+
+ QStringList tokens = str.split(" ");
+ QList<QString>::iterator tokItr;
+
+ for (tokItr = tokens.begin(); tokItr != tokens.end(); ++tokItr)
+ {
+ (*tokItr) = (*tokItr).at(0).toUpper() + (*tokItr).mid(1);
+ }
+
+ return tokens.join(" ");
+}
+
+QString& Source::cleanUpNumber(QString& number)
+{
+ return number.replace(numberCleaner_, "");
+}
+
+QString& Source::stripTags(QString& string)
+{
+ return string.replace(tagStripper_, "");
+}
+
+void Source::fixUrl(QUrl& url)
+{
+ QByteArray path = url.encodedQuery().replace('+', "%2B");
+ url.setEncodedQuery(path);
+}
+
+Source::SearchDetails::SearchDetails(QString const& q,
+ QString const& loc,
+ SearchType t)
+{
+ query = q;
+ location = loc;
+ type = t;
+}
--- /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 SOURCE_H
+#define SOURCE_H
+
+#include <QtCore/QObject>
+#include <QtCore/QString>
+#include <QtCore/QTimerEvent>
+#include <QtCore/QUrl>
+#include <QtNetwork/QHttp>
+
+class Source : public QObject
+{
+
+ Q_OBJECT
+
+public:
+
+ struct Result
+ {
+ QString name;
+ QString street;
+ QString city;
+ QString number;
+ };
+
+ enum SearchType {YELLOW_PAGES, PERSONS};
+
+ struct SearchDetails
+ {
+ QString query;
+ QString location;
+ SearchType type;
+ SearchDetails(QString const& query = "",
+ QString const& location = "",
+ SearchType type = PERSONS);
+ };
+
+
+ enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT};
+ enum SourceId {ENIRO, MOBIL1881};
+ static int const SOURCE_COUNT = 2;
+
+ struct SourceDetails
+ {
+ SourceId type;
+ QString name;
+ QString id;
+ };
+
+ static unsigned int const DEFAULT_MAX_RESULTS = 30;
+
+ static Source* getSource(SourceId id, QObject* parent = 0);
+ static void getSources(QList<SourceDetails>& list);
+ static SourceId stringToId(QString const& str);
+ Source(QObject* parent = 0);
+ virtual ~Source();
+ static Source* getSource();
+ virtual void abort();
+ virtual void search(SearchDetails const& details) = 0;
+ void setMaxResults(unsigned int results);
+ unsigned int getMaxResults() const;
+ void setTimeout(unsigned int ms);
+ unsigned int getTimeout() const;
+ void resetTimeout();
+ void setFindNumber(bool value);
+ bool getFindNumber() const;
+ Error error() const;
+ const QString& errorString() const;
+
+signals:
+ void resultAvailable(Source::Result const& result, Source::SearchDetails const& details);
+ void requestFinished(QVector <Source::Result> const& results, Source::SearchDetails const& details, bool error);
+
+protected:
+ void setError(Error error, QString const& errorString = "");
+ virtual void timerEvent(QTimerEvent *te);
+ QString ucFirst(QString& string);
+ QString& cleanUpNumber(QString& number);
+ QString& stripTags(QString& string);
+ void fixUrl(QUrl& url);
+ QHttp http_;
+
+private slots:
+ void httpReady(int id, bool error);
+
+private:
+ Q_DISABLE_COPY(Source);
+ virtual void handleHttpData(int id, QString const& data) = 0;
+ virtual void handleHttpError(int id) = 0;
+ unsigned int maxResults_;
+ unsigned int timeout_;
+ int timerId_;
+ bool findNumber_;
+ Error error_;
+ QString errorString_;
+ QString username_;
+ QString password_;
+ bool loggedIn_;
+
+ static QRegExp numberCleaner_;
+ static QRegExp tagStripper_;
+
+};
+
+#endif
--- /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/QDebug>
+#include "sourcecoreconfig.h"
+#include "enirocoreconfig.h"
+#include "emptycoreconfig.h"
+
+SourceCoreConfig::SourceCoreConfig()
+{
+}
+
+SourceCoreConfig::~SourceCoreConfig()
+{
+}
+
+SourceCoreConfig* SourceCoreConfig::getCoreConfig(Source::SourceId id)
+{
+ switch(id)
+ {
+ case Source::ENIRO:
+ return new EniroCoreConfig();
+ break;
+ case Source::MOBIL1881:
+ return new EmptyCoreConfig(); // No configuration
+ break;
+ default:
+ qDebug() << "Unknown source id: " << id;
+ }
+
+ return 0;
+}
--- /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 SOURCECORECONFIG_H
+#define SOURCECORECONFIG_H
+
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include "source.h"
+
+class SourceCoreConfig
+{
+
+public:
+
+ static SourceCoreConfig* getCoreConfig(Source::SourceId id);
+ SourceCoreConfig();
+ virtual ~SourceCoreConfig();
+ virtual bool apply(Source* source) = 0;
+ virtual void getConfig(QMap<QString, QString>& config) = 0;
+ virtual void loadFromConfig(QMap<QString, QString> const& config) = 0;
+ virtual void store() = 0;
+ virtual bool readyToSearch() = 0;
+};
+
+#endif
</message>
</context>
<context>
+ <name>EmptyGuiConfig</name>
+ <message>
+ <location filename="../../gui/emptyguiconfig.cpp" line="27"/>
+ <source>Selected phonebook has no settings to configure.</source>
+ <translation>Valitussa puhelinluettelossa ei ole muokattavia asetuksia.</translation>
+ </message>
+</context>
+<context>
+ <name>EniroGuiConfig</name>
+ <message>
+ <location filename="../../gui/eniroguiconfig.cpp" line="36"/>
+ <source>Eniro username</source>
+ <translation>Eniro-tunnus</translation>
+ </message>
+ <message>
+ <location filename="../../gui/eniroguiconfig.cpp" line="39"/>
+ <source>Eniro password</source>
+ <translation>Eniro-salasana</translation>
+ </message>
+ <message>
+ <location filename="../../gui/eniroguiconfig.cpp" line="45"/>
+ <source>Eniro site</source>
+ <translation>Eniro-sivusto</translation>
+ </message>
+ <message>
+ <location filename="../../gui/eniroguiconfig.cpp" line="57"/>
+ <source>Finnish</source>
+ <translation>Suomi</translation>
+ </message>
+ <message>
+ <location filename="../../gui/eniroguiconfig.cpp" line="60"/>
+ <source>Swedish</source>
+ <translation>Ruotsi</translation>
+ </message>
+ <message>
+ <location filename="../../gui/eniroguiconfig.cpp" line="63"/>
+ <source>Danish</source>
+ <translation>Tanska</translation>
+ </message>
+</context>
+<context>
<name>MainWindow</name>
<message>
- <location filename="../../gui/mainwindow.cpp" line="46"/>
+ <location filename="../../gui/mainwindow.cpp" line="48"/>
<source>Jenirok</source>
<translation>Jenirok</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="52"/>
- <location filename="../../gui/mainwindow.cpp" line="149"/>
+ <location filename="../../gui/mainwindow.cpp" line="54"/>
+ <location filename="../../gui/mainwindow.cpp" line="151"/>
<source>Stop daemon</source>
<translation>Pysäytä</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="58"/>
- <location filename="../../gui/mainwindow.cpp" line="115"/>
+ <location filename="../../gui/mainwindow.cpp" line="60"/>
+ <location filename="../../gui/mainwindow.cpp" line="117"/>
<source>Start daemon</source>
<translation>Käynnistä</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="63"/>
+ <location filename="../../gui/mainwindow.cpp" line="65"/>
<source>Search</source>
<translation>Hae</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="80"/>
+ <location filename="../../gui/mainwindow.cpp" line="82"/>
<source>Settings</source>
<translation>Asetukset</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="81"/>
+ <location filename="../../gui/mainwindow.cpp" line="83"/>
<source>About</source>
<translation>Tietoa</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="113"/>
+ <location filename="../../gui/mainwindow.cpp" line="115"/>
<source>Daemon was successfully stopped.</source>
<translation>Palvelu pysäytettiin onnistuneesti.</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="114"/>
+ <location filename="../../gui/mainwindow.cpp" line="116"/>
<source>Unable to stop daemon.</source>
<translation>Palvelun pysäyttäminen ei onnistunut.</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="125"/>
+ <location filename="../../gui/mainwindow.cpp" line="127"/>
<source>Unable to start daemon</source>
<translation>Palvelun käynnistäminen ei onnistunut</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="127"/>
+ <location filename="../../gui/mainwindow.cpp" line="129"/>
<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"/>
+ <location filename="../../gui/mainwindow.cpp" line="133"/>
<source>Open settings</source>
<translation>Avaa asetukset</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="133"/>
+ <location filename="../../gui/mainwindow.cpp" line="135"/>
<source>Close</source>
<translation>Sulje</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="147"/>
+ <location filename="../../gui/mainwindow.cpp" line="149"/>
<source>Daemon was successfully started.</source>
<translation>Palvelu käynnistettiin onnistuneesti.</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="148"/>
+ <location filename="../../gui/mainwindow.cpp" line="150"/>
<source>Unable to start daemon.</source>
<translation>Palvelun käynnistäminen ei onnistunut.</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="155"/>
+ <location filename="../../gui/mainwindow.cpp" line="157"/>
<source>Error</source>
<translation>Virhe</translation>
</message>
<message>
- <location filename="../../gui/mainwindow.cpp" line="178"/>
+ <location filename="../../gui/mainwindow.cpp" line="181"/>
<source>Info</source>
<translation>Info</translation>
</message>
<message>
- <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>
+ <location filename="../../gui/mainwindow.cpp" line="181"/>
+ <source>You need to set login details or other options in settings before using this feature.</source>
+ <translation>Sinun täytyy asettaa kirjautumistiedot tai muita asetuksia ennen kuin voit käyttää tätä ominaisuutta.</translation>
</message>
</context>
<context>
<name>ResultWindow</name>
<message>
- <location filename="../../gui/resultwindow.cpp" line="34"/>
+ <location filename="../../gui/resultwindow.cpp" line="36"/>
<source>Search results</source>
<translation>Hakutulokset</translation>
</message>
<message>
- <location filename="../../gui/resultwindow.cpp" line="166"/>
+ <location filename="../../gui/resultwindow.cpp" line="163"/>
<source>Connection to server failed</source>
<translation>Palvelimelle yhdistäminen epäonnistui</translation>
</message>
<message>
- <location filename="../../gui/resultwindow.cpp" line="169"/>
+ <location filename="../../gui/resultwindow.cpp" line="166"/>
<source>Invalid login details</source>
<translation>Virheellinen tunnus tai salasana</translation>
</message>
<message>
- <location filename="../../gui/resultwindow.cpp" line="172"/>
+ <location filename="../../gui/resultwindow.cpp" line="169"/>
<source>Request timed out</source>
<translation>Pyyntö aikakatkaistiin</translation>
</message>
<message>
- <location filename="../../gui/resultwindow.cpp" line="175"/>
+ <location filename="../../gui/resultwindow.cpp" line="172"/>
<source>Searching failed:</source>
<translation>Haku epäonnistui:</translation>
</message>
<message>
- <location filename="../../gui/resultwindow.cpp" line="179"/>
+ <location filename="../../gui/resultwindow.cpp" line="176"/>
<source>Error</source>
<translation>Virhe</translation>
</message>
<message>
- <location filename="../../gui/resultwindow.cpp" line="184"/>
+ <location filename="../../gui/resultwindow.cpp" line="181"/>
<source>No results found</source>
<translation>Ei hakutuloksia</translation>
</message>
</message>
<message>
<location filename="../../gui/searchdialog.cpp" line="46"/>
- <source>Yellow pages</source>
- <translation>Keltaiset sivut</translation>
+ <source>Companies</source>
+ <translation>Yritykset</translation>
</message>
</context>
<context>
<name>Settings</name>
<message>
- <location filename="../settings.cpp" line="121"/>
+ <location filename="../settings.cpp" line="168"/>
<source>fi</source>
<translation>fi</translation>
</message>
<context>
<name>SettingsDialog</name>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="41"/>
+ <location filename="../../gui/settingsdialog.cpp" line="44"/>
<source>Settings</source>
<translation>Asetukset</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="52"/>
- <source>Eniro username</source>
- <translation>Eniro-tunnus</translation>
- </message>
- <message>
- <location filename="../../gui/settingsdialog.cpp" line="55"/>
- <source>Eniro password</source>
- <translation>Eniro-salasana</translation>
- </message>
- <message>
- <location filename="../../gui/settingsdialog.cpp" line="59"/>
+ <location filename="../../gui/settingsdialog.cpp" line="58"/>
<source>Cache size (numbers)</source>
<translation>Välimuistin koko (numeroa)</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="62"/>
+ <location filename="../../gui/settingsdialog.cpp" line="61"/>
<source>Clear</source>
<translation>Tyhjennä</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="65"/>
- <source>Eniro site</source>
- <translation>Eniro-sivusto</translation>
+ <location filename="../../gui/settingsdialog.cpp" line="64"/>
+ <source>Language</source>
+ <translation>Kieli</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="82"/>
- <source>Finnish</source>
- <translation>Suomi</translation>
- </message>
- <message>
- <location filename="../../gui/settingsdialog.cpp" line="85"/>
- <source>Swedish</source>
- <translation>Ruotsi</translation>
+ <location filename="../../gui/settingsdialog.cpp" line="65"/>
+ <source>Automatic</source>
+ <translation>Automaattinen</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="88"/>
- <source>Danish</source>
- <translation>Tanska</translation>
+ <location filename="../../gui/settingsdialog.cpp" line="82"/>
+ <source>Phonebook</source>
+ <translation>Puhelinluettelo</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="105"/>
+ <location filename="../../gui/settingsdialog.cpp" line="102"/>
<source>Autostart</source>
<translation>Käynnistä automaattisesti</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="107"/>
+ <location filename="../../gui/settingsdialog.cpp" line="104"/>
<source>Enabled</source>
<translation>Kyllä</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="108"/>
+ <location filename="../../gui/settingsdialog.cpp" line="105"/>
<source>Disabled</source>
<translation>Ei</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="111"/>
+ <location filename="../../gui/settingsdialog.cpp" line="108"/>
<source>Connect automatically on</source>
<translation>Yhdistä automaattisesti</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="115"/>
+ <location filename="../../gui/settingsdialog.cpp" line="112"/>
<source>Save</source>
<translation>Tallenna</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="145"/>
+ <location filename="../../gui/settingsdialog.cpp" line="137"/>
<source>General</source>
<translation>Yleiset</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="146"/>
+ <location filename="../../gui/settingsdialog.cpp" line="138"/>
<source>Daemon</source>
<translation>Taustaprosessi</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="177"/>
+ <location filename="../../gui/settingsdialog.cpp" line="139"/>
+ <location filename="../../gui/settingsdialog.cpp" line="208"/>
+ <source>Phonebook settings</source>
+ <translation>Puhelinluettelo</translation>
+ </message>
+ <message>
+ <location filename="../../gui/settingsdialog.cpp" line="170"/>
<source>Restarting daemon...</source>
<translation>Käynnistetään palvelu uudelleen...</translation>
</message>
+ <message>
+ <location filename="../../gui/settingsdialog.cpp" line="176"/>
+ <source>You need to restart Jenirok for language change to take effect.</source>
+ <translation>Jenirok täytyy käynnistää uudelleen, jotta uudet kieliasetukset tulevat voimaan.</translation>
+ </message>
<message numerus="yes">
- <location filename="../../gui/settingsdialog.cpp" line="202"/>
+ <location filename="../../gui/settingsdialog.cpp" line="188"/>
<source>%n number(s) were deleted from cache</source>
<translation>
<numerusform>Poistettiin %n numero välimuistista</numerusform>
#include "cache.h"
#include "contactmanager.h"
#include "connectionmanager.h"
+#include "sourcecoreconfig.h"
#include "db.h"
namespace
QDBusConnection CallListener::systemBus_ = QDBusConnection::systemBus();
-CallListener::CallListener(): eniro_(0),
+CallListener::CallListener(): source_(0),
closeConnection_(false), initialized_(false), box_(0), label_(0),
-retries_(-1), site_(Eniro::FI), timer_(0)
+retries_(-1), timer_(0)
{
}
CallListener::~CallListener()
{
end();
- DB::removeDatabase();
}
bool CallListener::begin()
return false;
}
+ sourceId_ = Source::stringToId(Settings::instance()->get("source"));
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId_);
+ config->getConfig(sourceConfig_);
+ delete config;
+
systemBus_.connect(CALL_SERVICE_NAME,
CALL_SERVICE_PATH,
CALL_SERVICE_INTERFACE,
this,
SLOT(callTerminate()));
- site_ = Eniro::stringToSite(Settings::instance()->get("site"));
qDebug() << "Starting...";
SLOT(callTerminate()));
searchClose();
+ sourceConfig_.clear();
}
-void CallListener::search(Eniro::SearchDetails const& details)
+void CallListener::search(Source::SearchDetails const& details)
{
qDebug() << "Search called";
searchInit();
- Eniro::Result result;
+ Source::Result result;
if(Cache::instance().findItem(details.query, result))
{
qDebug() << "Starting to search...";
- eniro_->search(details);
+ source_->search(details);
}
}
-void CallListener::requestFinished(QVector <Eniro::Result> const& results,
- Eniro::SearchDetails const& details,
+void CallListener::requestFinished(QVector <Source::Result> const& results,
+ Source::SearchDetails const& details,
bool error)
{
// If box is not visible, the call must have been terminated already
if(error)
{
- qDebug() << "Error: " << eniro_->errorString();
+ qDebug() << "Error: " << source_->errorString();
if(retries_ < SEARCH_RETRIES && retries_ >= 0)
{
retries_++;
- eniro_->search(Eniro::SearchDetails(currentSearch_));
+ source_->search(Source::SearchDetails(currentSearch_));
return;
}
else
{
timedMessage_ = "";
QString errorString;
- Eniro::Error error = eniro_->error();
+ Source::Error error = source_->error();
switch(error)
{
- case Eniro::TIMEOUT:
+ case Source::TIMEOUT:
errorString = tr("Request timed out");
break;
default:
- errorString = eniro_->errorString();
+ errorString = source_->errorString();
break;
}
message = createResult(results.at(0).name, results.at(0).street,
results.at(0).city);
showResult(message);
- Eniro::Result result = results.at(0);
+ Source::Result result = results.at(0);
result.number = details.query;
Cache::instance().addItem(result);
}
this,
SLOT(callTerminate()));
- search(Eniro::SearchDetails(number));
+ search(Source::SearchDetails(number));
}
else
{
return;
}
- eniro_ = new Eniro(site_);
- eniro_->setMaxResults(1);
- eniro_->setFindNumber(false);
- eniro_->setTimeout(REQUEST_TIMEOUT);
-
- connect(eniro_, SIGNAL(requestFinished(QVector <Eniro::Result> const&,
- Eniro::SearchDetails const&, bool)),
- this, SLOT(requestFinished(QVector <Eniro::Result> const&,
- Eniro::SearchDetails const&, bool)));
+ source_ = Source::getSource(sourceId_);
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId_);
+ config->loadFromConfig(sourceConfig_);
+ config->apply(source_);
+ delete config;
+ source_->setMaxResults(1);
+ source_->setFindNumber(false);
+ source_->setTimeout(REQUEST_TIMEOUT);
+
+ connect(source_, SIGNAL(requestFinished(QVector <Source::Result> const&,
+ Source::SearchDetails const&, bool)),
+ this, SLOT(requestFinished(QVector <Source::Result> const&,
+ Source::SearchDetails const&, bool)));
box_ = new InformationBox;
label_ = new QLabel("", box_);
label_->setMargin(8);
qDebug() << "Closing search...";
- if(eniro_)
+ if(source_)
{
- disconnect(eniro_, SIGNAL(requestFinished(QVector <Eniro::Result> const&,
- Eniro::SearchDetails const&, bool)),
- this, SLOT(requestFinished(QVector <Eniro::Result> const&,
- Eniro::SearchDetails const&, bool)));
+ disconnect(source_, SIGNAL(requestFinished(QVector <Source::Result> const&,
+ Source::SearchDetails const&, bool)),
+ this, SLOT(requestFinished(QVector <Source::Result> const&,
+ Source::SearchDetails const&, bool)));
}
- delete eniro_;
- eniro_ = 0;
+ delete source_;
+ source_ = 0;
delete box_;
box_ = 0;
label_ = 0;
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusObjectPath>
#include "informationbox.h"
-#include "eniro.h"
+#include "source.h"
class CallListener: public QObject
{
virtual void timerEvent(QTimerEvent* event);
private slots:
- void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
+ void requestFinished(QVector <Source::Result> const& results, Source::SearchDetails const& details, bool error);
void incomingCall(QDBusObjectPath path, QString numbe);
void callTerminate();
void showTimedMessage();
private:
Q_DISABLE_COPY(CallListener);
- void search(Eniro::SearchDetails const& details);
+ void search(Source::SearchDetails const& details);
void showResult(QString const& text);
void showDelayedResult(QString const& text, int delay);
void searchInit();
void sleep(int ms);
QString createResult(QString const& name, QString const& street, QString const& city);
QString timedMessage_;
- Eniro* eniro_;
+ Source* source_;
+ Source::SourceId sourceId_;
+ QMap<QString, QString> sourceConfig_;
bool closeConnection_;
bool initialized_;
InformationBox* box_;
static QDBusConnection systemBus_;
int retries_;
QString currentSearch_;
- Eniro::Site site_;
int timer_;
};
TARGET = jenirokd
CONFIG += qdbus
TEMPLATE = app
-SOURCES += main.cpp calllistener.cpp informationbox.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp ../common/cache.cpp
-HEADERS += calllistener.h informationbox.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h ../common/cache.h
+SOURCES += main.cpp \
+ calllistener.cpp \
+ informationbox.cpp \
+ ../common/source.cpp \
+ ../common/eniro.cpp \
+ ../common/mobil1881.cpp \
+ ../common/sourcecoreconfig.cpp \
+ ../common/enirocoreconfig.cpp \
+ ../common/emptycoreconfig.cpp \
+ ../common/contactmanager.cpp \
+ ../common/db.cpp \
+ ../common/settings.cpp \
+ ../common/connectionmanager.cpp \
+ ../common/cache.cpp
+HEADERS += calllistener.h \
+ informationbox.h \
+ ../common/source.h \
+ ../common/eniro.h \
+ ../common/mobil1881.h \
+ ../common/enirocoreconfig.h \
+ ../common/sourcecoreconfig.h \
+ ../common/emptycoreconfig.h \
+ ../common/contactmanager.h \
+ ../common/db.h \
+ ../common/settings.h \
+ ../common/connectionmanager.h \
+ ../common/cache.h
TRANSLATIONS = ../common/translations/fi_FI.ts
RESOURCES = ../common/translations.grc
INCLUDEPATH += ../common
*
*/
-#include <QtCore/QCoreApplication>
-#include <QtCore/QTranslator>
-#include <QtCore/QLocale>
#include <QtCore/QString>
#include <QtGui/QApplication>
#include "calllistener.h"
QApplication app(argc, argv);
- QTranslator translator;
- translator.load(":/translations/" + QLocale::system().name());
- app.installTranslator(&translator);
+ Settings::instance()->loadLanguage(app);
CallListener listener;
{
setValueLayout(QMaemo5ValueButton::ValueBesideText);
selector_ = new QMaemo5ListPickSelector(this);
+ connect(selector_, SIGNAL(selected(QString const&)), this, SLOT(onSelected(QString const&)));
model_ = new QStandardItemModel(0, 1);
selector_->setModel(model_);
setPickSelector(selector_);
bool ButtonSelector::changeItem(unsigned int index,
QString const& text)
{
- changeItem(index, text, QVariant(text));
+ return changeItem(index, text, QVariant(text));
}
bool ButtonSelector::changeItem(unsigned int index,
{
return model_->removeRow(index);
}
+
+void ButtonSelector::onSelected(QString const& text)
+{
+ emit selected(currentIndex(), text, value());
+}
QString text() const;
QVariant value() const;
+signals:
+ void selected(unsigned int index, QString const& text, QVariant const& value);
+
+private slots:
+ void onSelected(QString const& text);
+
private:
QMaemo5ListPickSelector* selector_;
QStandardItemModel* model_;
setCentralWidget(area_);
}
-void DetailWindow::loadData(Eniro::Result const& details)
+void DetailWindow::loadData(Source::Result const& details)
{
setWindowTitle(details.name);
nameButton_->setValueText(details.name);
DetailWindow(QWidget* parent = 0);
public slots:
- void loadData(Eniro::Result const& details);
+ void loadData(Source::Result const& details);
private slots:
void makeCall();
--- /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 <QtGui/QVBoxLayout>
+#include <QtGui/QLabel>
+#include "emptyguiconfig.h"
+
+EmptyGuiConfig::EmptyGuiConfig(QWidget* parent):
+SourceGuiConfig(parent), EmptyCoreConfig()
+{
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ QLabel* info = new QLabel(tr("Selected phonebook has no settings to configure."));
+ info->setAlignment(Qt::AlignCenter);
+ info->setWordWrap(true);
+ layout->addWidget(info);
+ setLayout(layout);
+}
+
+EmptyGuiConfig::~EmptyGuiConfig()
+{
+}
+
+void EmptyGuiConfig::save()
+{
+}
--- /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 EMPTYGUICONFIG_H
+#define EMPTYGUICONFIG_H
+
+#include "sourceguiconfig.h"
+#include "emptycoreconfig.h"
+
+class EmptyGuiConfig : public SourceGuiConfig, public EmptyCoreConfig
+{
+
+ Q_OBJECT
+
+public:
+ EmptyGuiConfig(QWidget* parent = 0);
+ virtual ~EmptyGuiConfig();
+ virtual void save();
+
+private:
+
+};
+
+#endif
--- /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/QDebug>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QLabel>
+#include "eniroguiconfig.h"
+#include "eniro.h"
+
+EniroGuiConfig::EniroGuiConfig(QWidget* parent):
+SourceGuiConfig(parent), EniroCoreConfig()
+{
+ load();
+
+ QVBoxLayout* layout = new QVBoxLayout;
+
+ QHBoxLayout* username = new QHBoxLayout;
+ QHBoxLayout* password = new QHBoxLayout;
+
+ QLabel* usernameLabel = new QLabel(tr("Eniro username"));
+ usernameInput_ = new QLineEdit(getUsername());
+
+ QLabel* passwordLabel = new QLabel(tr("Eniro password"));
+ passwordInput_ = new QLineEdit(getPassword());
+ passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit);
+
+ QMap <Eniro::Site, Eniro::SiteDetails> sites = Eniro::getSites();
+
+ siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
+ QString site = getSite();
+ int i = 0;
+
+ QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
+ for(it = sites.begin(); it != sites.end(); it++)
+ {
+ QString name;
+
+ switch(it.key())
+ {
+ case Eniro::FI:
+ name = tr("Finnish");
+ break;
+ case Eniro::SE:
+ name = tr("Swedish");
+ break;
+ case Eniro::DK:
+ name = tr("Danish");
+ break;
+ default:
+ qDebug() << "Unknown site";
+ continue;
+
+ }
+ siteSelector_->addItem(name, it.value().id);
+
+ if(it.value().id == site)
+ {
+ siteSelector_->setCurrentIndex(i);
+ }
+
+ i++;
+ }
+
+ username->addWidget(usernameLabel);
+ username->addWidget(usernameInput_);
+ password->addWidget(passwordLabel);
+ password->addWidget(passwordInput_);
+
+ layout->addLayout(username);
+ layout->addLayout(password);
+ layout->addWidget(siteSelector_);
+
+ setLayout(layout);
+}
+
+EniroGuiConfig::~EniroGuiConfig()
+{
+}
+
+void EniroGuiConfig::save()
+{
+ setUsername(usernameInput_->text());
+ setPassword(passwordInput_->text());
+ setSite(siteSelector_->value().toString());
+
+ store();
+}
--- /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 ENIROGUICONFIG_H
+#define ENIROGUICONFIG_H
+
+#include <QtGui/QLineEdit>
+#include "buttonselector.h"
+#include "enirocoreconfig.h"
+#include "sourceguiconfig.h"
+
+class EniroGuiConfig : public SourceGuiConfig, public EniroCoreConfig
+{
+
+ Q_OBJECT
+
+public:
+ EniroGuiConfig(QWidget* parent = 0);
+ virtual ~EniroGuiConfig();
+ virtual void save();
+
+private:
+ QLineEdit* usernameInput_;
+ QLineEdit* passwordInput_;
+ ButtonSelector* siteSelector_;
+
+};
+
+#endif
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 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
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ searchdialog.cpp \
+ resultwindow.cpp \
+ detailwindow.cpp \
+ settingsdialog.cpp \
+ aboutdialog.cpp \
+ buttonselector.cpp \
+ connectionselector.cpp \
+ daemon.cpp \
+ ../common/source.cpp \
+ ../common/eniro.cpp \
+ ../common/mobil1881.cpp \
+ ../common/sourcecoreconfig.cpp \
+ ../common/emptycoreconfig.cpp \
+ sourceguiconfig.cpp \
+ ../common/enirocoreconfig.cpp \
+ eniroguiconfig.cpp \
+ emptyguiconfig.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/source.h \
+ ../common/eniro.h \
+ ../common/mobil1881.h \
+ ../common/sourcecoreconfig.h \
+ ../common/emptycoreconfig.h \
+ sourceguiconfig.h \
+ ../common/enirocoreconfig.h \
+ eniroguiconfig.h \
+ emptyguiconfig.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
*
*/
-#include <QtCore/QTranslator>
-#include <QtCore/QLocale>
#include <QtCore/QObject>
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "resultwindow.h"
#include "detailwindow.h"
#include "eniro.h"
+#include "settings.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QTranslator translator;
- translator.load(":/translations/" + QLocale::system().name());
- app.installTranslator(&translator);
+ Settings::instance()->loadLanguage(app);
MainWindow window;
ResultWindow results(&window);
QObject::connect(&window, SIGNAL(search(SearchDialog::SearchDetails&)),
&results, SLOT(search(SearchDialog::SearchDetails&)));
- QObject::connect(&results, SIGNAL(itemSelected(Eniro::Result const&)),
- &details, SLOT(loadData(Eniro::Result const&)));
+ QObject::connect(&results, SIGNAL(itemSelected(Source::Result const&)),
+ &details, SLOT(loadData(Source::Result const&)));
return app.exec();
}
#include "daemon.h"
#include "settings.h"
#include "db.h"
+#include "source.h"
+#include "sourcecoreconfig.h"
namespace
{
void MainWindow::openSearch()
{
- DB::connect();
+ Source::SourceId sourceId = Source::stringToId(Settings::instance()->get("source"));
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId);
- QString username = Settings::instance()->get("eniro_username");
- QString password = Settings::instance()->get("eniro_password");
+ Q_ASSERT(config != 0);
- DB::disconnect();
+ bool readyToSearch = config->readyToSearch();
+ delete config;
- if(username.isEmpty() || password.isEmpty())
+ if(!readyToSearch)
{
- QMessageBox::information(this, tr("Info"), tr("You need to set Eniro login details in settings before using this feature."));
+ QMessageBox::information(this, tr("Info"), tr("You need to set login details or other options in settings before using this feature."));
return;
}
#include "settings.h"
#include "db.h"
#include "cache.h"
+#include "source.h"
+#include "sourcecoreconfig.h"
ResultWindow::ResultWindow(QWidget* parent): QMainWindow(parent),
-eniro_(0), list_(0), connectionManager_(0)
+source_(0), list_(0), connectionManager_(0)
{
setAttribute(Qt::WA_Maemo5StackedWindow);
setWindowTitle(tr("Search results"));
list_->clear();
}
- DB::connect();
+ Source::SourceId sourceId = Source::stringToId(Settings::instance()->get("source"));
- Eniro::Site selectedSite = Eniro::stringToSite(Settings::instance()->get("site"));
-
- if(!eniro_)
+ if(!source_)
{
- eniro_ = new Eniro(selectedSite, this);
- eniro_->setTimeout(REQUEST_TIMEOUT);
-
- connect(eniro_, SIGNAL(resultAvailable(Eniro::Result const&,
- Eniro::SearchDetails const&)),
- this, SLOT(resultAvailable(Eniro::Result const&,
- Eniro::SearchDetails const&)));
-
- connect(eniro_, SIGNAL(requestFinished(QVector <Eniro::Result> const&,
- Eniro::SearchDetails const&, bool)),
- this, SLOT(requestFinished(QVector <Eniro::Result> const&,
- Eniro::SearchDetails const&, bool)));
+ source_ = Source::getSource(sourceId);
+ Q_ASSERT(source_ != 0);
+ source_->setTimeout(REQUEST_TIMEOUT);
+
+ connect(source_, SIGNAL(resultAvailable(Source::Result const&,
+ Source::SearchDetails const&)),
+ this, SLOT(resultAvailable(Source::Result const&,
+ Source::SearchDetails const&)));
+
+ connect(source_, SIGNAL(requestFinished(QVector <Source::Result> const&,
+ Source::SearchDetails const&, bool)),
+ this, SLOT(requestFinished(QVector <Source::Result> const&,
+ Source::SearchDetails const&, bool)));
}
- QString username = Settings::instance()->get("eniro_username");
- QString password = Settings::instance()->get("eniro_password");
-
- if(!username.isEmpty() && !password.isEmpty())
- {
- eniro_->login(username, password);
- }
+ SourceCoreConfig* config = SourceCoreConfig::getCoreConfig(sourceId);
- eniro_->setSite(selectedSite);
+ Q_ASSERT(config != 0);
- DB::disconnect();
+ config->apply(source_);
+ delete config;
- Eniro::SearchType type;
+ Source::SearchType type;
switch(details.type)
{
case 0:
- type = Eniro::PERSONS;
+ type = Source::PERSONS;
break;
case 1:
- type = Eniro::YELLOW_PAGES;
+ type = Source::YELLOW_PAGES;
break;
default:
+ qDebug() << "Unknown search type: " << details.type;
return;
}
connectionManager_->connect();
- eniro_->abort();
- eniro_->search(Eniro::SearchDetails(details.name, details.location, type));
+ source_->abort();
+ source_->search(Source::SearchDetails(details.name, details.location, type));
}
-void ResultWindow::resultAvailable(Eniro::Result const& result,
- Eniro::SearchDetails const& details)
+void ResultWindow::resultAvailable(Source::Result const& result,
+ Source::SearchDetails const& details)
{
Q_UNUSED(details);
list_->addItem(item);
}
-void ResultWindow::requestFinished(QVector <Eniro::Result> const& results,
- Eniro::SearchDetails const& details,
+void ResultWindow::requestFinished(QVector <Source::Result> const& results,
+ Source::SearchDetails const& details,
bool error)
{
Q_UNUSED(details);
if(error)
{
QString errorString;
- Eniro::Error error = eniro_->error();
+ Source::Error error = source_->error();
switch(error)
{
- case Eniro::CONNECTION_FAILURE:
+ case Source::CONNECTION_FAILURE:
errorString = tr("Connection to server failed");
break;
- case Eniro::INVALID_LOGIN:
+ case Source::INVALID_LOGIN:
errorString = tr("Invalid login details");
break;
- case Eniro::TIMEOUT:
+ case Source::TIMEOUT:
errorString = tr("Request timed out");
break;
default:
- errorString = tr("Searching failed:") + " " + eniro_->errorString();
+ errorString = tr("Searching failed:") + " " + source_->errorString();
break;
}
void ResultWindow::itemClicked(QListWidgetItem* item)
{
QMap <QString, QVariant> data = item->data(Qt::UserRole).toMap();
- Eniro::Result details;
+ Source::Result details;
details.name = data["name"].toString();
details.street = data["street"].toString();
details.city = data["city"].toString();
emit itemSelected(details);
}
+void ResultWindow::setVisible(bool visible)
+{
+ QMainWindow::setVisible(visible);
+
+ if(!visible && source_)
+ {
+ source_->abort();
+ }
+}
+
+
#include <QtGui/QListWidget>
#include <QtGui/QListWidgetItem>
#include "searchdialog.h"
-#include "eniro.h"
+#include "source.h"
#include "connectionmanager.h"
class ResultWindow : public QMainWindow
static const int REQUEST_TIMEOUT = 30000;
signals:
- void itemSelected(Eniro::Result const& result);
+ void itemSelected(Source::Result const& result);
public slots:
void search(SearchDialog::SearchDetails& details);
+ virtual void setVisible(bool visible);
private slots:
- void resultAvailable(Eniro::Result const& result, Eniro::SearchDetails const& details);
- void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
+ void resultAvailable(Source::Result const& result, Source::SearchDetails const& details);
+ void requestFinished(QVector <Source::Result> const& results, Source::SearchDetails const& details, bool error);
void itemClicked(QListWidgetItem* item);
private:
- Eniro* eniro_;
+ Source* source_;
QListWidget* list_;
ConnectionManager* connectionManager_;
selector_ = new ButtonSelector(tr("Type"), this);
selector_->addItem(tr("Persons"));
- selector_->addItem(tr("Yellow pages"));
+ selector_->addItem(tr("Companies"));
QVBoxLayout* leftLayout = new QVBoxLayout;
leftLayout->addLayout(numberLayout);
void SearchDialog::setVisible(bool visible)
{
- QDialog::setVisible(visible);
- numberInput_->setFocus();
+ QDialog::setVisible(visible);
+
+ if(visible)
+ {
+ numberInput_->setFocus();
+ }
}
#include "db.h"
#include "daemon.h"
#include "cache.h"
+#include "buttonselector.h"
+#include "connectionselector.h"
+#include "sourceguiconfig.h"
-QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_;
+QList<Source::SourceDetails> SettingsDialog::sources_;
SettingsDialog::SettingsDialog(QWidget* parent): QDialog(parent),
-usernameInput_(0), passwordInput_(0), cacheInput_(0), siteSelector_(0),
-autostartSelector_(0)
+sourceConfig_(0), cacheInput_(0), sourceSelector_(0),
+autostartSelector_(0), connectionSelector_(0), tabs_(0)
{
setWindowTitle(tr("Settings"));
- DB::connect();
-
QVBoxLayout* general = new QVBoxLayout;
QVBoxLayout* daemon = new QVBoxLayout;
QHBoxLayout* mainLayout = new QHBoxLayout;
- QHBoxLayout* username = new QHBoxLayout;
- QHBoxLayout* password = new QHBoxLayout;
+
QHBoxLayout* cache = new QHBoxLayout;
- QLabel* usernameLabel = new QLabel(tr("Eniro username"));
- usernameInput_ = new QLineEdit(Settings::instance()->get("eniro_username"));
+ currentSource_ = Settings::instance()->get("source");
+ Source::SourceId sourceId = Source::stringToId(currentSource_);
+ sourceConfig_ = SourceGuiConfig::getGuiConfig(sourceId, this);
- QLabel* passwordLabel = new QLabel(tr("Eniro password"));
- passwordInput_ = new QLineEdit(Settings::instance()->get("eniro_password"));
- passwordInput_->setEchoMode(QLineEdit::PasswordEchoOnEdit);
+ Q_ASSERT(sourceConfig_ != 0);
QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
QPushButton* cacheResetButton = new QPushButton(tr("Clear"), this);
connect(cacheResetButton, SIGNAL(pressed()), this, SLOT(resetCache()));
- siteSelector_ = new ButtonSelector(tr("Eniro site"), this);
- QString site = Settings::instance()->get("eniro_site");
- int i = 0;
+ languageSelector_ = new ButtonSelector(tr("Language"), this);
+ languageSelector_->addItem(tr("Automatic"), "");
- if(sites_.empty())
- {
- sites_ = Eniro::getSites();
- }
+ selectedLanguage_ = Settings::instance()->get("language");
- QMap <Eniro::Site, Eniro::SiteDetails>::const_iterator it;
- for(it = sites_.begin(); it != sites_.end(); it++)
+ QList<Settings::Language> langs;
+ Settings::getLanguages(langs);
+
+ for(int i = 0; i < langs.size(); i++)
{
- QString name;
+ languageSelector_->addItem(langs.at(i).name, langs.at(i).id);
- switch(it.key())
+ if(langs.at(i).id == selectedLanguage_)
{
- case Eniro::FI:
- name = tr("Finnish");
- break;
- case Eniro::SE:
- name = tr("Swedish");
- break;
- case Eniro::DK:
- name = tr("Danish");
- break;
- default:
- qDebug() << "Unknown site";
- continue;
-
+ languageSelector_->setCurrentIndex(i + 1);
}
- siteSelector_->addItem(name, it.value().id);
+ }
+
+ sourceSelector_ = new ButtonSelector(tr("Phonebook"), this);
+
+ if(sources_.isEmpty())
+ {
+ Source::getSources(sources_);
+ }
+
+ for(int i = 0; i < sources_.size(); i++)
+ {
+ sourceSelector_->addItem(sources_.at(i).name, sources_.at(i).id);
- if(it.value().id == site)
+ if(sources_.at(i).id == currentSource_)
{
- siteSelector_->setCurrentIndex(i);
+ sourceSelector_->setCurrentIndex(i);
}
-
- i++;
}
+ connect(sourceSelector_, SIGNAL(selected(unsigned int, QString const&, QVariant const&)),
+ this, SLOT(onSourceSelected(unsigned int, QString const&, QVariant const&)));
+
autostartSelector_ = new ButtonSelector(tr("Autostart"), this);
QString autostart = Settings::instance()->get("autostart");
autostartSelector_->addItem(tr("Enabled"), "1");
QPushButton* submitButton = new QPushButton(tr("Save"), this);
connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
- username->addWidget(usernameLabel);
- username->addWidget(usernameInput_);
- password->addWidget(passwordLabel);
- password->addWidget(passwordInput_);
cache->addWidget(cacheLabel);
cache->addWidget(cacheInput_);
cache->addWidget(cacheResetButton);
- general->addLayout(username);
- general->addLayout(password);
general->addLayout(cache);
- general->addWidget(siteSelector_);
+ general->addWidget(languageSelector_);
+ general->addWidget(sourceSelector_);
daemon->addWidget(autostartSelector_);
daemon->addWidget(connectionSelector_);
buttons->setCenterButtons(false);
buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
- QTabWidget* tabs = new 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"));
+ tabs_->addTab(generalTab, tr("General"));
+ tabs_->addTab(daemonTab, tr("Daemon"));
+ tabs_->addTab(sourceConfig_, tr("Phonebook settings"));
- mainLayout->addWidget(tabs);
+ mainLayout->addWidget(tabs_);
mainLayout->addWidget(buttons);
setLayout(mainLayout);
- DB::disconnect();
}
void SettingsDialog::saveSettings()
{
hide();
- DB::connect();
+ Settings::instance()->startEdit();
- Settings::instance()->set("eniro_username", usernameInput_->text());
- Settings::instance()->set("eniro_password", passwordInput_->text());
+ sourceConfig_->save();
Settings::instance()->set("cache_size", cacheInput_->text());
- QString site = siteSelector_->value().toString();
- Settings::instance()->set("site", site);
+ QString source = sourceSelector_->value().toString();
+ Settings::instance()->set("source", source);
QString autostart = autostartSelector_->value().toString();
Settings::instance()->set("autostart", autostart);
QString connection = connectionSelector_->value().toString();
Settings::instance()->set("connection", connection);
Settings::instance()->set("connection_name", connectionSelector_->text());
+ QString language = languageSelector_->value().toString();
+ Settings::instance()->set("language", language);
- DB::disconnect();
+ Settings::instance()->endEdit();
- if(site != currentSite_ && Daemon::isRunning())
+ if(Daemon::isRunning())
{
QMaemo5InformationBox::information(this, tr("Restarting daemon..."));
Daemon::restart();
- currentSite_ = site;
}
-}
-
-void SettingsDialog::setVisible(bool visible)
-{
- QDialog::setVisible(visible);
-
- if(visible)
+ if(language != selectedLanguage_)
{
- currentSite_ = siteSelector_->value().toString();
+ QMaemo5InformationBox::information(this, tr("You need to restart Jenirok for language change to take effect."));
+ selectedLanguage_ = language;
}
}
QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret));
}
}
+
+void SettingsDialog::onSourceSelected(unsigned int index,
+ QString const& text,
+ QVariant const& value)
+{
+ Q_UNUSED(index);
+ Q_UNUSED(text);
+
+ QString source = value.toString();
+
+ if(source != currentSource_)
+ {
+ tabs_->removeTab(tabs_->count() - 1);
+ delete sourceConfig_;
+ Source::SourceId sourceId = Source::stringToId(value.toString());
+ sourceConfig_ = SourceGuiConfig::getGuiConfig(sourceId, this);
+ Q_ASSERT(sourceConfig_ != 0);
+ tabs_->addTab(sourceConfig_, tr("Phonebook settings"));
+ currentSource_ = source;
+ }
+}
#include <QtCore/QMap>
#include <QtCore/QString>
+#include <QtCore/QVariant>
#include <QtGui/QDialog>
#include <QtGui/QWidget>
#include <QtGui/QLineEdit>
#include <QtGui/QCheckBox>
+#include <QtGui/QTabWidget>
#include <QMaemo5ListPickSelector>
-#include "eniro.h"
-#include "buttonselector.h"
-#include "connectionselector.h"
+#include "source.h"
+
+class SourceGuiConfig;
+class ButtonSelector;
+class ConnectionSelector;
+
class SettingsDialog : public QDialog
{
public slots:
void saveSettings();
- void setVisible(bool visible);
void resetCache();
+private slots:
+ void onSourceSelected(unsigned int index, QString const& text, QVariant const& value);
+
private:
- static QMap <Eniro::Site, Eniro::SiteDetails> sites_;
- QLineEdit* usernameInput_;
- QLineEdit* passwordInput_;
+ static QList<Source::SourceDetails> sources_;
+ SourceGuiConfig* sourceConfig_;
QLineEdit* cacheInput_;
- ButtonSelector* siteSelector_;
+ ButtonSelector* languageSelector_;
+ ButtonSelector* sourceSelector_;
ButtonSelector* autostartSelector_;
ConnectionSelector* connectionSelector_;
- QString currentSite_;
+ QString currentSource_;
+ QString selectedLanguage_;
+ QTabWidget* tabs_;
};
#endif
--- /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/QDebug>
+#include <QtGui/QLabel>
+#include <QtGui/QVBoxLayout>
+#include "sourceguiconfig.h"
+#include "eniroguiconfig.h"
+#include "emptyguiconfig.h"
+
+SourceGuiConfig::SourceGuiConfig(QWidget* parent): QWidget(parent)
+{
+}
+
+SourceGuiConfig::~SourceGuiConfig()
+{
+}
+
+SourceGuiConfig* SourceGuiConfig::getGuiConfig(Source::SourceId id, QWidget* parent)
+{
+ switch(id)
+ {
+ case Source::ENIRO:
+ return new EniroGuiConfig(parent);
+ break;
+ case Source::MOBIL1881:
+ return new EmptyGuiConfig(parent); // No configuration
+ break;
+ default:
+ qDebug() << "Unknown source id: " << id;
+ }
+
+ return 0;
+}
--- /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 SOURCEGUICONFIG_H
+#define SOURCEGUICONFIG_H
+
+#include <QtGui/QWidget>
+#include "source.h"
+
+class SourceGuiConfig : public QWidget
+{
+
+ Q_OBJECT
+
+public:
+
+ static SourceGuiConfig* getGuiConfig(Source::SourceId id, QWidget* parent = 0);
+ SourceGuiConfig(QWidget* parent = 0);
+ virtual ~SourceGuiConfig();
+ virtual void save() = 0;
+};
+
+#endif