--- /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 <QtSql/QSqlQuery>
+#include <QtSql/QSqlError>
+#include <QtCore/QVariant>
+#include <QDebug>
+#include "cache.h"
+#include "db.h"
+#include "settings.h"
+
+Cache* Cache::instance_ = 0;
+
+Cache::Cache()
+{
+}
+
+int Cache::clear()
+{
+ bool connected = DB::connected();
+
+ if(!connected)
+ {
+ DB::connect();
+ }
+
+ QSqlQuery query;
+ int ret = -1;
+
+ if(query.exec("DELETE FROM cache"))
+ {
+ ret = query.numRowsAffected();
+ }
+
+ if(!connected)
+ {
+ DB::disconnect();
+ }
+
+ return ret;
+}
+bool Cache::findItem(QString const& number, Eniro::Result& result)
+{
+ bool connected = DB::connected();
+
+ if(!connected)
+ {
+ DB::connect();
+ }
+
+ QSqlQuery query;
+ query.prepare("SELECT name, street, city FROM cache WHERE number = :number");
+ query.bindValue(":number", number);
+
+ bool ret = false;
+
+ if(query.exec() && query.next())
+ {
+ result.number = number;
+ result.name = query.value(0).toString();
+ result.street = query.value(1).toString();
+ result.city = query.value(2).toString();
+
+ ret = true;
+ }
+
+ if(!connected)
+ {
+ DB::disconnect();
+ }
+
+ return ret;
+}
+
+bool Cache::addItem(Eniro::Result const& result)
+{
+ bool connected = DB::connected();
+
+ if(!connected)
+ {
+ DB::connect();
+ }
+
+ bool ret = true;
+
+ QSqlQuery query;
+
+ query.prepare("INSERT INTO cache(number, name, street, city) VALUES(:number, :name, :street, :city)");
+ query.bindValue(":number", result.number);
+ query.bindValue(":name", result.name);
+ query.bindValue(":street", result.street);
+ query.bindValue(":city", result.city);
+
+
+ if(!query.exec())
+ {
+ ret = false;
+ }
+
+ query.clear();
+
+ QString cacheSize = Settings::instance()->get("cache_size");
+
+ int cacheLimit = 0;
+
+ // Delete old entries from cache
+ if((cacheLimit = cacheSize.toInt()) > 0)
+ {
+ if(query.exec("SELECT COUNT(*) FROM cache") && query.next())
+ {
+ int itemsToDelete = query.value(0).toInt() - cacheLimit;
+
+ for(int i = 0; i < itemsToDelete; i++)
+ {
+ query.clear();
+
+ if(!query.exec("DELETE FROM cache WHERE id = (SELECT MIN(id) FROM cache)"))
+ {
+ QSqlError error = query.lastError();
+ qDebug() << "Unable to delete old cache entries: " << error.text();
+ ret = false;
+ }
+ }
+ }
+ else
+ {
+ QSqlError error = query.lastError();
+ qDebug() << "Unable to get count for cache entries: " << error.text();
+ ret = false;
+ }
+
+ }
+
+ if(!connected)
+ {
+ DB::disconnect();
+ }
+
+ return ret;
+
+}
+
+Cache& Cache::instance()
+{
+ if(!instance_)
+ {
+ instance_ = new Cache;
+ }
+
+ return *instance_;
+}
--- /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 CACHE_H
+#define CACHE_H
+
+#include "eniro.h"
+
+class Cache
+{
+
+public:
+ static Cache& instance();
+ int clear();
+ bool findItem(QString const& number, Eniro::Result& result);
+ bool addItem(Eniro::Result const& result);
+
+private:
+ Cache();
+ static Cache* instance_;
+};
+
+#endif
};
static const QString INVALID_LOGIN_STRING = "Invalid login details";
+ static const QString TIMEOUT_STRING = "Request timed out";
static const QString PERSON_REGEXP = "<td class=\"hTd2\">(.*)<b>(.*)</td>";
static const QString YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\"\\}>(.*)</td>";
static const QString NUMBER_REGEXP = "<div class=\"callRow\">(.*)</div>";
Eniro::Eniro(Site site, QObject *parent): QObject(parent), site_(site),
username_(""), password_(""), loggedIn_(false), error_(NO_ERROR),
-errorString_(""), maxResults_(10), findNumber_(true),
+errorString_(""), maxResults_(10), timeout_(0), timerId_(0), findNumber_(true),
pendingSearches_(), pendingNumberRequests_()
{
connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
site_ = site;
}
+void Eniro::setTimeout(unsigned int ms)
+{
+ timeout_ = ms;
+ resetTimeout();
+}
+
+void Eniro::resetTimeout()
+{
+ if(timerId_)
+ {
+ killTimer(timerId_);
+ }
+ if(timeout_)
+ {
+ timerId_ = startTimer(timeout_);
+ }
+}
+
+void Eniro::timerEvent(QTimerEvent* t)
+{
+ if(t->timerId() == timerId_)
+ {
+ int currentId = http_.currentId();
+
+ if(currentId)
+ {
+ searchMap::const_iterator it = pendingSearches_.find(currentId);
+
+ if(it != pendingSearches_.end())
+ {
+ QVector <Eniro::Result> results = it.value()->results;
+ SearchDetails details = it.value()->details;
+
+ abort();
+
+ error_ = TIMEOUT;
+ errorString_ = TIMEOUT_STRING;
+
+ emit requestFinished(results, details, true);
+ }
+ }
+
+ }
+}
+
void Eniro::login(QString const& username,
QString const& password)
{
bool Eniro::search(SearchDetails const& details)
{
+ resetTimeout();
+
SearchType type = details.type;
// Only logged in users can use other than person search
#include <QtCore/QSet>
#include <QtCore/QRegExp>
#include <QtCore/QUrl>
+#include <QtCore/QTimerEvent>
#include <QtNetwork/QHttp>
class Eniro: public QObject
enum SearchType {YELLOW_PAGES, PERSONS};
- enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN};
+ enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT};
struct Result
{
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;
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);
Error error_;
QString errorString_;
unsigned int maxResults_;
+ unsigned int timeout_;
+ int timerId_;
bool findNumber_;
typedef QMap <int, SearchData*> searchMap;
typedef QMap <int, NumberData*> numberMap;
<name>DetailWindow</name>
<message>
<location filename="../../gui/detailwindow.cpp" line="39"/>
- <location filename="../../gui/detailwindow.cpp" line="108"/>
+ <location filename="../../gui/detailwindow.cpp" line="106"/>
<source>Add to contacts</source>
<translation>Lisää yhteistietoihin</translation>
</message>
</message>
<message>
<location filename="../../gui/detailwindow.cpp" line="46"/>
- <location filename="../../gui/detailwindow.cpp" line="111"/>
+ <location filename="../../gui/detailwindow.cpp" line="109"/>
<source>Name</source>
<translation>Nimi</translation>
</message>
<translation>Puhelinnumero</translation>
</message>
<message>
- <location filename="../../gui/detailwindow.cpp" line="112"/>
+ <location filename="../../gui/detailwindow.cpp" line="110"/>
<source>Add</source>
<translation>Lisää</translation>
</message>
<message>
- <location filename="../../gui/detailwindow.cpp" line="135"/>
+ <location filename="../../gui/detailwindow.cpp" line="133"/>
<source>Contact was successfully added to contacts.</source>
<translation>Yhteystieto lisättiin onnistuneesti.</translation>
</message>
<message>
- <location filename="../../gui/detailwindow.cpp" line="139"/>
+ <location filename="../../gui/detailwindow.cpp" line="137"/>
<source>Error</source>
<translation>Virhe</translation>
</message>
<message>
- <location filename="../../gui/detailwindow.cpp" line="139"/>
+ <location filename="../../gui/detailwindow.cpp" line="137"/>
<source>Unable to add contact.</source>
<translation>Yhteystiedon lisääminen epäonnistui,</translation>
</message>
<message>
- <location filename="../../gui/detailwindow.cpp" line="147"/>
+ <location filename="../../gui/detailwindow.cpp" line="145"/>
<source>Number was successfully copied to clipboard.</source>
<translation>Numero kopioitiin onnistuneesti leikepöydälle.</translation>
</message>
<name>SearchDialog</name>
<message>
<location filename="../../gui/searchdialog.cpp" line="30"/>
- <location filename="../../gui/searchdialog.cpp" line="54"/>
+ <location filename="../../gui/searchdialog.cpp" line="55"/>
<source>Search</source>
<translation>Haku</translation>
</message>
<context>
<name>SettingsDialog</name>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="38"/>
+ <location filename="../../gui/settingsdialog.cpp" line="40"/>
<source>Settings</source>
<translation>Asetukset</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="48"/>
+ <location filename="../../gui/settingsdialog.cpp" line="50"/>
<source>Eniro username</source>
<translation>Eniro-tunnus</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="51"/>
+ <location filename="../../gui/settingsdialog.cpp" line="53"/>
<source>Eniro password</source>
<translation>Eniro-salasana</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="54"/>
+ <location filename="../../gui/settingsdialog.cpp" line="56"/>
<source>Cache size (numbers)</source>
<translation>Välimuistin koko (numeroa)</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="58"/>
+ <location filename="../../gui/settingsdialog.cpp" line="59"/>
+ <source>Clear</source>
+ <translation>Tyhjennä</translation>
+ </message>
+ <message>
+ <location filename="../../gui/settingsdialog.cpp" line="62"/>
<source>Eniro site</source>
<translation>Eniro-sivusto</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="69"/>
+ <location filename="../../gui/settingsdialog.cpp" line="73"/>
<source>Finnish</source>
<translation>Suomi</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="72"/>
+ <location filename="../../gui/settingsdialog.cpp" line="76"/>
<source>Swedish</source>
<translation>Ruotsi</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="75"/>
+ <location filename="../../gui/settingsdialog.cpp" line="79"/>
<source>Danish</source>
<translation>Tanska</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="91"/>
+ <location filename="../../gui/settingsdialog.cpp" line="96"/>
<source>Autostart</source>
<translation>Käynnistä automaattisesti</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="93"/>
+ <location filename="../../gui/settingsdialog.cpp" line="98"/>
<source>Enabled</source>
<translation>Kyllä</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="94"/>
+ <location filename="../../gui/settingsdialog.cpp" line="99"/>
<source>Disabled</source>
<translation>Ei</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="97"/>
+ <location filename="../../gui/settingsdialog.cpp" line="102"/>
<source>Save</source>
<translation>Tallenna</translation>
</message>
<message>
- <location filename="../../gui/settingsdialog.cpp" line="138"/>
+ <location filename="../../gui/settingsdialog.cpp" line="148"/>
<source>Restarting daemon...</source>
<translation>Käynnistetään palvelu uudelleen...</translation>
</message>
+ <message numerus="yes">
+ <location filename="../../gui/settingsdialog.cpp" line="185"/>
+ <source>%n number(s) were deleted from cache</source>
+ <translation>
+ <numerusform>Poistettiin %n numero välimuistista</numerusform>
+ <numerusform>Poistettiin %n numeroa välimuistista</numerusform>
+ </translation>
+ </message>
</context>
</TS>
#############################################################################
# Makefile for building: jenirokd
-# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Apr 17 12:38:30 2010
+# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Apr 17 16:35:57 2010
# Project: daemon.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile daemon.pro
../common/contactmanager.cpp \
../common/db.cpp \
../common/settings.cpp \
- ../common/connectionmanager.cpp moc_calllistener.cpp \
+ ../common/connectionmanager.cpp \
+ ../common/cache.cpp moc_calllistener.cpp \
moc_informationbox.cpp \
moc_eniro.cpp \
moc_connectionmanager.cpp \
db.o \
settings.o \
connectionmanager.o \
+ cache.o \
moc_calllistener.o \
moc_informationbox.o \
moc_eniro.o \
dist:
@$(CHK_DIR_EXISTS) .tmp/jenirokd1.0.0 || $(MKDIR) .tmp/jenirokd1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents calllistener.h informationbox.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents ../common/translations.grc .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents main.cpp calllistener.cpp informationbox.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents ../common/translations/fi_FI.ts .tmp/jenirokd1.0.0/ && (cd `dirname .tmp/jenirokd1.0.0` && $(TAR) jenirokd1.0.0.tar jenirokd1.0.0 && $(COMPRESS) jenirokd1.0.0.tar) && $(MOVE) `dirname .tmp/jenirokd1.0.0`/jenirokd1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/jenirokd1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents calllistener.h informationbox.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h ../common/cache.h .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents ../common/translations.grc .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents main.cpp calllistener.cpp informationbox.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp ../common/cache.cpp .tmp/jenirokd1.0.0/ && $(COPY_FILE) --parents ../common/translations/fi_FI.ts .tmp/jenirokd1.0.0/ && (cd `dirname .tmp/jenirokd1.0.0` && $(TAR) jenirokd1.0.0.tar jenirokd1.0.0 && $(COMPRESS) jenirokd1.0.0.tar) && $(MOVE) `dirname .tmp/jenirokd1.0.0`/jenirokd1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/jenirokd1.0.0
clean:compiler_clean
connectionmanager.o: ../common/connectionmanager.cpp ../common/connectionmanager.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o connectionmanager.o ../common/connectionmanager.cpp
+cache.o: ../common/cache.cpp ../common/cache.h \
+ ../common/eniro.h \
+ ../common/db.h \
+ ../common/settings.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o cache.o ../common/cache.cpp
+
moc_calllistener.o: moc_calllistener.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_calllistener.o moc_calllistener.cpp
#include <QtCore/QDebug>
#include <QtSql/QSqlQuery>
+#include <QtSql/QSqlError>
#include "calllistener.h"
#include "settings.h"
-#include "db.h"
+#include "cache.h"
namespace
{
eniro_->setMaxResults(1);
eniro_->setFindNumber(false);
+ eniro_->setTimeout(REQUEST_TIMEOUT);
connect(eniro_, SIGNAL(requestFinished(QVector <Eniro::Result> const&,
Eniro::SearchDetails const&, bool)),
box_ = new InformationBox();
label_ = new QLabel("", box_);
- label_->setMargin(10);
+ label_->setMargin(8);
box_->setWidget(label_);
}
void CallListener::search(Eniro::SearchDetails const& details)
{
- label_->setText(tr("Searching..."));
- box_->show();
-
- DB::connect();
-
- QSqlQuery query;
- query.prepare("SELECT name, street, city FROM cache WHERE number = :number");
- query.bindValue(":number", details.query);
+ Eniro::Result result;
- if(query.exec() && query.next())
+ if(Cache::instance().findItem(details.query, result))
{
- showResult(createResult(query.value(0).toString(),
- query.value(1).toString(),
- query.value(2).toString()));
+ showResult(createResult(result.name,
+ result.street,
+ result.city));
}
else
{
+ showResult(tr("Searching..."));
eniro_->search(details);
}
- DB::disconnect();
-
}
void CallListener::requestFinished(QVector <Eniro::Result> const& results,
if(error)
{
qDebug() << "Error: " << eniro_->errorString();
- message = tr("Search failed:") + " " + eniro_->errorString();
+ message = tr("Search failed:") + " " + eniro_->errorString() + ".";
}
else if(results.size() == 0)
{
else
{
message = createResult(results.at(0).name, results.at(0).street, results.at(0).city);
- QSqlQuery query;
-
- DB::connect();
-
- query.prepare("INSERT INTO cache(number, name, street, city) VALUES(:number, :name, :street, :city)");
- query.bindValue(":number", details.query);
- query.bindValue(":name", results.at(0).name);
- query.bindValue(":street", results.at(0).street);
- query.bindValue(":city", results.at(0).city);
-
- if(!query.exec())
- {
- qDebug() << "Unable to save cache";
- }
-
- QString cacheSize = Settings::instance()->get("cache_size");
-
- // Delete old entries from cache
- if(cacheSize.toInt() > 0)
- {
- if(!query.exec("DELETE c1 FROM cache AS c1 LEFT JOIN (SELECT id FROM cache ORDER BY id DESC LIMIT " + cacheSize + ") AS c2 ON c1.id = c2.id WHERE c2.id IS NULL"))
- {
- qDebug() << "Unable to delete old cache entries";
- }
- }
-
- DB::disconnect();
+ Eniro::Result result = results.at(0);
+ result.number = details.query;
+ Cache::instance().addItem(result);
}
showResult(message);
void CallListener::showResult(QString const& text)
{
- label_->setText(text);
- box_->hide();
+ label_->setText("<font color='black'>" + text + "</font>");
+
+ if(box_->isVisible())
+ {
+ box_->hide();
+ }
box_->show();
}
~CallListener();
void begin();
void end();
+ static const int REQUEST_TIMEOUT = 10000;
private slots:
void requestFinished(QVector <Eniro::Result> const& results, Eniro::SearchDetails const& details, bool error);
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
-HEADERS += calllistener.h informationbox.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h
+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
TRANSLATIONS = ../common/translations/fi_FI.ts
RESOURCES = ../common/translations.grc
INCLUDEPATH += ../common
//move(0, 56 /*HILDON_WINDOW_TITLEBAR_HEIGHT*/);
}
+
/*!
Destroys the information box.
*/
PropModeReplace, (unsigned char *) type, qstrlen(type));
}
+
/*!
\property InformationBox::timeout
\brief the timeout after which the informaton box should automatically be
#############################################################################
# Makefile for building: jenirok
-# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Apr 17 12:38:19 2010
+# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Apr 17 16:30:11 2010
# Project: gui.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile gui.pro
../common/contactmanager.cpp \
../common/db.cpp \
../common/settings.cpp \
- ../common/connectionmanager.cpp moc_mainwindow.cpp \
+ ../common/connectionmanager.cpp \
+ ../common/cache.cpp moc_mainwindow.cpp \
moc_searchdialog.cpp \
moc_resultwindow.cpp \
moc_detailwindow.cpp \
db.o \
settings.o \
connectionmanager.o \
+ cache.o \
moc_mainwindow.o \
moc_searchdialog.o \
moc_resultwindow.o \
dist:
@$(CHK_DIR_EXISTS) .tmp/jenirok1.0.0 || $(MKDIR) .tmp/jenirok1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents mainwindow.h searchdialog.h resultwindow.h detailwindow.h settingsdialog.h buttonselector.h daemon.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents icons.grc ../common/translations.grc .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp buttonselector.cpp daemon.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents ../common/translations/fi_FI.ts .tmp/jenirok1.0.0/ && (cd `dirname .tmp/jenirok1.0.0` && $(TAR) jenirok1.0.0.tar jenirok1.0.0 && $(COMPRESS) jenirok1.0.0.tar) && $(MOVE) `dirname .tmp/jenirok1.0.0`/jenirok1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/jenirok1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents mainwindow.h searchdialog.h resultwindow.h detailwindow.h settingsdialog.h buttonselector.h daemon.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h ../common/cache.h .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents icons.grc ../common/translations.grc .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp buttonselector.cpp daemon.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp ../common/cache.cpp .tmp/jenirok1.0.0/ && $(COPY_FILE) --parents ../common/translations/fi_FI.ts .tmp/jenirok1.0.0/ && (cd `dirname .tmp/jenirok1.0.0` && $(TAR) jenirok1.0.0.tar jenirok1.0.0 && $(COMPRESS) jenirok1.0.0.tar) && $(MOVE) `dirname .tmp/jenirok1.0.0`/jenirok1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/jenirok1.0.0
clean:compiler_clean
connectionmanager.o: ../common/connectionmanager.cpp ../common/connectionmanager.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o connectionmanager.o ../common/connectionmanager.cpp
+cache.o: ../common/cache.cpp ../common/db.h \
+ ../common/settings.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o cache.o ../common/cache.cpp
+
moc_mainwindow.o: moc_mainwindow.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp
QT += network sql maemo5
TARGET = jenirok
TEMPLATE = app
-SOURCES += main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp buttonselector.cpp daemon.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp
-HEADERS += mainwindow.h searchdialog.h resultwindow.h detailwindow.h settingsdialog.h buttonselector.h daemon.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h
+SOURCES += main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp buttonselector.cpp daemon.cpp ../common/eniro.cpp ../common/contactmanager.cpp ../common/db.cpp ../common/settings.cpp ../common/connectionmanager.cpp ../common/cache.cpp
+HEADERS += mainwindow.h searchdialog.h resultwindow.h detailwindow.h settingsdialog.h buttonselector.h daemon.h ../common/eniro.h ../common/contactmanager.h ../common/db.h ../common/settings.h ../common/connectionmanager.h ../common/cache.h
TRANSLATIONS = ../common/translations/fi_FI.ts
RESOURCES = icons.grc ../common/translations.grc
INCLUDEPATH += ../common
#include "detailwindow.h"\r
#include "eniro.h"\r
\r
-#include "contactmanager.h"\r
-\r
int main(int argc, char *argv[])\r
{\r
QApplication app(argc, argv);\r
#include "resultwindow.h"
#include "settings.h"
#include "db.h"
+#include "cache.h"
ResultWindow::ResultWindow(QWidget* parent): QMainWindow(parent),
eniro_(0), list_(0)
{
Q_UNUSED(details);
+ if(!result.number.isEmpty())
+ {
+ Cache::instance().addItem(result);
+ }
+
QString row = result.name;
if(!result.street.isEmpty())
leftLayout->addWidget(selector_);
QDialogButtonBox* buttons = new QDialogButtonBox;
+ buttons->setCenterButtons(false);
QPushButton* submitButton = new QPushButton(tr("Search"));
buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
connect(submitButton, SIGNAL(pressed()), this, SLOT(searchPressed()));
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QIntValidator>
+#include <QtGui/QDialogButtonBox>
#include <QMaemo5ValueButton>
#include <QMaemo5InformationBox>
#include <QDebug>
#include "settings.h"
#include "db.h"
#include "daemon.h"
+#include "cache.h"
QMap <Eniro::Site, Eniro::SiteDetails> SettingsDialog::sites_ = Eniro::getSites();
QLabel* cacheLabel = new QLabel(tr("Cache size (numbers)"));
cacheInput_ = new QLineEdit(Settings::instance()->get("cache_size"));
cacheInput_->setValidator(new QIntValidator(0, 10000, this));
+ 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");
autostartSelector_->addItem(tr("Disabled"), "0");
autostartSelector_->setCurrentIndex(autostart == "1" ? 0 : 1);
- QPushButton* submitButton = new QPushButton(tr("Save"));
+ QPushButton* submitButton = new QPushButton(tr("Save"), this);
connect(submitButton, SIGNAL(pressed()), this, SLOT(saveSettings()));
username->addWidget(usernameLabel);
password->addWidget(passwordInput_);
cache->addWidget(cacheLabel);
cache->addWidget(cacheInput_);
+ cache->addWidget(cacheResetButton);
left->addLayout(username);
left->addLayout(password);
left->addLayout(cache);
left->addWidget(siteSelector_);
left->addWidget(autostartSelector_);
+ QDialogButtonBox* buttons = new QDialogButtonBox;
+ buttons->setCenterButtons(false);
+ buttons->addButton(submitButton, QDialogButtonBox::AcceptRole);
+
mainLayout->addLayout(left);
- mainLayout->addWidget(submitButton);
+ mainLayout->addWidget(buttons);
setLayout(mainLayout);
}
}
+
+void SettingsDialog::resetCache()
+{
+ int ret = Cache::instance().clear();
+
+ if(ret >= 0)
+ {
+ QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret));
+ }
+}
public slots:
void saveSettings();
void setVisible(bool visible);
+ void resetCache();
private:
static QMap <Eniro::Site, Eniro::SiteDetails> sites_;