From: eshe Date: Sat, 17 Apr 2010 16:34:58 +0000 (+0100) Subject: Better cache handling. Added clear cache button to settings. X-Git-Url: http://git.maemo.org/git/?p=jenirok;a=commitdiff_plain;h=72f0ccb17472f83c1cba569879e185eb7cd60e31 Better cache handling. Added clear cache button to settings. --- diff --git a/src/common/cache.cpp b/src/common/cache.cpp new file mode 100644 index 0000000..3f5bd4e --- /dev/null +++ b/src/common/cache.cpp @@ -0,0 +1,166 @@ +/* + * 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 . + * + */ + +#include +#include +#include +#include +#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_; +} diff --git a/src/common/cache.h b/src/common/cache.h new file mode 100644 index 0000000..dca1369 --- /dev/null +++ b/src/common/cache.h @@ -0,0 +1,38 @@ +/* + * 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 . + * + */ + +#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 diff --git a/src/common/eniro.cpp b/src/common/eniro.cpp index 20af69c..896a788 100644 --- a/src/common/eniro.cpp +++ b/src/common/eniro.cpp @@ -43,6 +43,7 @@ namespace }; static const QString INVALID_LOGIN_STRING = "Invalid login details"; + static const QString TIMEOUT_STRING = "Request timed out"; static const QString PERSON_REGEXP = "(.*)(.*)"; static const QString YELLOW_REGEXP = "(.*)(.*)"; static const QString NUMBER_REGEXP = "
(.*)
"; @@ -57,7 +58,7 @@ QRegExp Eniro::tagStripper_ = QRegExp("<([^>]+)>"); 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))); @@ -113,6 +114,51 @@ void Eniro::setSite(Eniro::Site site) 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 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) { @@ -141,6 +187,8 @@ void Eniro::testLogin() bool Eniro::search(SearchDetails const& details) { + resetTimeout(); + SearchType type = details.type; // Only logged in users can use other than person search diff --git a/src/common/eniro.h b/src/common/eniro.h index 50b0aba..0a810dc 100644 --- a/src/common/eniro.h +++ b/src/common/eniro.h @@ -25,6 +25,7 @@ #include #include #include +#include #include class Eniro: public QObject @@ -38,7 +39,7 @@ public: enum SearchType {YELLOW_PAGES, PERSONS}; - enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN}; + enum Error {NO_ERROR, CONNECTION_FAILURE, INVALID_LOGIN, TIMEOUT}; struct Result { @@ -74,6 +75,7 @@ public: 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; @@ -112,6 +114,8 @@ private: 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); @@ -124,6 +128,8 @@ private: Error error_; QString errorString_; unsigned int maxResults_; + unsigned int timeout_; + int timerId_; bool findNumber_; typedef QMap searchMap; typedef QMap numberMap; diff --git a/src/common/translations/fi_FI.qm b/src/common/translations/fi_FI.qm index bbbfaef..0aaa36e 100644 Binary files a/src/common/translations/fi_FI.qm and b/src/common/translations/fi_FI.qm differ diff --git a/src/common/translations/fi_FI.ts b/src/common/translations/fi_FI.ts index e6bd91e..eed27cf 100644 --- a/src/common/translations/fi_FI.ts +++ b/src/common/translations/fi_FI.ts @@ -20,7 +20,7 @@ DetailWindow - + Add to contacts Lisää yhteistietoihin @@ -31,7 +31,7 @@ - + Name Nimi @@ -51,27 +51,27 @@ Puhelinnumero - + Add Lisää - + Contact was successfully added to contacts. Yhteystieto lisättiin onnistuneesti. - + Error Virhe - + Unable to add contact. Yhteystiedon lisääminen epäonnistui, - + Number was successfully copied to clipboard. Numero kopioitiin onnistuneesti leikepöydälle. @@ -163,7 +163,7 @@ SearchDialog - + Search Haku @@ -204,69 +204,82 @@ SettingsDialog - + Settings Asetukset - + Eniro username Eniro-tunnus - + Eniro password Eniro-salasana - + Cache size (numbers) Välimuistin koko (numeroa) - + + Clear + Tyhjennä + + + Eniro site Eniro-sivusto - + Finnish Suomi - + Swedish Ruotsi - + Danish Tanska - + Autostart Käynnistä automaattisesti - + Enabled Kyllä - + Disabled Ei - + Save Tallenna - + Restarting daemon... Käynnistetään palvelu uudelleen... + + + %n number(s) were deleted from cache + + Poistettiin %n numero välimuistista + Poistettiin %n numeroa välimuistista + + diff --git a/src/daemon/Makefile b/src/daemon/Makefile index 196f428..a1974a5 100644 --- a/src/daemon/Makefile +++ b/src/daemon/Makefile @@ -1,6 +1,6 @@ ############################################################################# # 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 @@ -50,7 +50,8 @@ SOURCES = main.cpp \ ../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 \ @@ -63,6 +64,7 @@ OBJECTS = main.o \ db.o \ settings.o \ connectionmanager.o \ + cache.o \ moc_calllistener.o \ moc_informationbox.o \ moc_eniro.o \ @@ -189,7 +191,7 @@ qmake: FORCE 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 @@ -287,6 +289,12 @@ settings.o: ../common/settings.cpp ../common/settings.h \ 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 diff --git a/src/daemon/calllistener.cpp b/src/daemon/calllistener.cpp index 9071713..114a05e 100644 --- a/src/daemon/calllistener.cpp +++ b/src/daemon/calllistener.cpp @@ -18,9 +18,10 @@ #include #include +#include #include "calllistener.h" #include "settings.h" -#include "db.h" +#include "cache.h" namespace { @@ -66,6 +67,7 @@ void CallListener::begin() eniro_->setMaxResults(1); eniro_->setFindNumber(false); + eniro_->setTimeout(REQUEST_TIMEOUT); connect(eniro_, SIGNAL(requestFinished(QVector const&, Eniro::SearchDetails const&, bool)), @@ -74,7 +76,7 @@ void CallListener::begin() box_ = new InformationBox(); label_ = new QLabel("", box_); - label_->setMargin(10); + label_->setMargin(8); box_->setWidget(label_); } @@ -105,29 +107,21 @@ void CallListener::end() 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 const& results, @@ -147,7 +141,7 @@ void CallListener::requestFinished(QVector 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) { @@ -156,33 +150,9 @@ void CallListener::requestFinished(QVector const& results, 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); @@ -210,8 +180,12 @@ QString CallListener::createResult(QString const& name, QString const& street, Q void CallListener::showResult(QString const& text) { - label_->setText(text); - box_->hide(); + label_->setText("" + text + ""); + + if(box_->isVisible()) + { + box_->hide(); + } box_->show(); } diff --git a/src/daemon/calllistener.h b/src/daemon/calllistener.h index d066a47..a252b0c 100644 --- a/src/daemon/calllistener.h +++ b/src/daemon/calllistener.h @@ -38,6 +38,7 @@ public: ~CallListener(); void begin(); void end(); + static const int REQUEST_TIMEOUT = 10000; private slots: void requestFinished(QVector const& results, Eniro::SearchDetails const& details, bool error); diff --git a/src/daemon/daemon.pro b/src/daemon/daemon.pro index 3a8b219..a6bc1fc 100644 --- a/src/daemon/daemon.pro +++ b/src/daemon/daemon.pro @@ -2,8 +2,8 @@ QT += network sql maemo5 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 diff --git a/src/daemon/informationbox.cpp b/src/daemon/informationbox.cpp index e0795a3..189da71 100644 --- a/src/daemon/informationbox.cpp +++ b/src/daemon/informationbox.cpp @@ -93,6 +93,7 @@ InformationBox::InformationBox(QWidget *parent) //move(0, 56 /*HILDON_WINDOW_TITLEBAR_HEIGHT*/); } + /*! Destroys the information box. */ @@ -113,6 +114,7 @@ void InformationBoxPrivate::enforceInformationType() PropModeReplace, (unsigned char *) type, qstrlen(type)); } + /*! \property InformationBox::timeout \brief the timeout after which the informaton box should automatically be diff --git a/src/gui/Makefile b/src/gui/Makefile index 1ccf24e..b7a1344 100644 --- a/src/gui/Makefile +++ b/src/gui/Makefile @@ -1,6 +1,6 @@ ############################################################################# # 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 @@ -55,7 +55,8 @@ SOURCES = main.cpp \ ../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 \ @@ -77,6 +78,7 @@ OBJECTS = main.o \ db.o \ settings.o \ connectionmanager.o \ + cache.o \ moc_mainwindow.o \ moc_searchdialog.o \ moc_resultwindow.o \ @@ -198,7 +200,7 @@ qmake: FORCE 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 @@ -335,6 +337,10 @@ settings.o: ../common/settings.cpp ../common/settings.h \ 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 diff --git a/src/gui/gui.pro b/src/gui/gui.pro index cddf745..cd5c6b3 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -1,8 +1,8 @@ QT += network sql maemo5 TARGET = jenirok TEMPLATE = app -SOURCES += main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp 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 diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 8a3ebf2..649f4a7 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -26,8 +26,6 @@ #include "detailwindow.h" #include "eniro.h" -#include "contactmanager.h" - int main(int argc, char *argv[]) { QApplication app(argc, argv); diff --git a/src/gui/resultwindow.cpp b/src/gui/resultwindow.cpp index 179eac8..11e6fc1 100644 --- a/src/gui/resultwindow.cpp +++ b/src/gui/resultwindow.cpp @@ -25,6 +25,7 @@ #include "resultwindow.h" #include "settings.h" #include "db.h" +#include "cache.h" ResultWindow::ResultWindow(QWidget* parent): QMainWindow(parent), eniro_(0), list_(0) @@ -105,6 +106,11 @@ void ResultWindow::resultAvailable(Eniro::Result const& result, { Q_UNUSED(details); + if(!result.number.isEmpty()) + { + Cache::instance().addItem(result); + } + QString row = result.name; if(!result.street.isEmpty()) diff --git a/src/gui/searchdialog.cpp b/src/gui/searchdialog.cpp index a56838e..16636c1 100644 --- a/src/gui/searchdialog.cpp +++ b/src/gui/searchdialog.cpp @@ -51,6 +51,7 @@ numberInput_(0), locationInput_(0), selector_(0) 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())); diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 757a0ff..f84f8c8 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include "settings.h" #include "db.h" #include "daemon.h" +#include "cache.h" QMap SettingsDialog::sites_ = Eniro::getSites(); @@ -54,6 +56,8 @@ autostartSelector_(0) 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"); @@ -95,7 +99,7 @@ autostartSelector_(0) 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); @@ -104,14 +108,19 @@ autostartSelector_(0) 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); @@ -166,3 +175,13 @@ void SettingsDialog::setVisible(bool visible) } } + +void SettingsDialog::resetCache() +{ + int ret = Cache::instance().clear(); + + if(ret >= 0) + { + QMaemo5InformationBox::information(this, tr("%n number(s) were deleted from cache", "", ret)); + } +} diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index eebdc92..7ad2a8d 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -38,6 +38,7 @@ public: public slots: void saveSettings(); void setVisible(bool visible); + void resetCache(); private: static QMap sites_;