Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Jenirok
Summary Tracker SCM Files
authoreshe <jessehakanen@gmail.com>
Sat, 17 Apr 2010 16:34:58 +0000 (17:34 +0100)
committereshe <jessehakanen@gmail.com>
Sat, 17 Apr 2010 16:34:58 +0000 (17:34 +0100)
18 files changed:
src/common/cache.cpp [new file with mode: 0644]
src/common/cache.h [new file with mode: 0644]
src/common/eniro.cpp
src/common/eniro.h
src/common/translations/fi_FI.qm
src/common/translations/fi_FI.ts
src/daemon/Makefile
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/daemon.pro
src/daemon/informationbox.cpp
src/gui/Makefile
src/gui/gui.pro
src/gui/main.cpp
src/gui/resultwindow.cpp
src/gui/searchdialog.cpp
src/gui/settingsdialog.cpp
src/gui/settingsdialog.h

diff --git a/src/common/cache.cpp b/src/common/cache.cpp
new file mode 100644 (file)
index 0000000..3f5bd4e
--- /dev/null
@@ -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 <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_;
+}
diff --git a/src/common/cache.h b/src/common/cache.h
new file mode 100644 (file)
index 0000000..dca1369
--- /dev/null
@@ -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 <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
index 20af69c..896a788 100644 (file)
@@ -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 = "<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>";
@@ -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 <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)
 {
@@ -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
index 50b0aba..0a810dc 100644 (file)
@@ -25,6 +25,7 @@
 #include <QtCore/QSet>
 #include <QtCore/QRegExp>
 #include <QtCore/QUrl>
+#include <QtCore/QTimerEvent>
 #include <QtNetwork/QHttp>
 
 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 <int, SearchData*> searchMap;
     typedef QMap <int, NumberData*> numberMap;
index bbbfaef..0aaa36e 100644 (file)
Binary files a/src/common/translations/fi_FI.qm and b/src/common/translations/fi_FI.qm differ
index e6bd91e..eed27cf 100644 (file)
@@ -20,7 +20,7 @@
     <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>
@@ -31,7 +31,7 @@
     </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>
index 196f428..a1974a5 100644 (file)
@@ -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
 
index 9071713..114a05e 100644 (file)
 
 #include <QtCore/QDebug>
 #include <QtSql/QSqlQuery>
+#include <QtSql/QSqlError>
 #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 <Eniro::Result> 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 <Eniro::Result> const& results,
@@ -147,7 +141,7 @@ 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)
     {
@@ -156,33 +150,9 @@ void CallListener::requestFinished(QVector <Eniro::Result> 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("<font color='black'>" + text + "</font>");
+
+    if(box_->isVisible())
+    {
+        box_->hide();
+    }
     box_->show();
 }
 
index d066a47..a252b0c 100644 (file)
@@ -38,6 +38,7 @@ public:
     ~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);
index 3a8b219..a6bc1fc 100644 (file)
@@ -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
index e0795a3..189da71 100644 (file)
@@ -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
index 1ccf24e..b7a1344 100644 (file)
@@ -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
 
index cddf745..cd5c6b3 100644 (file)
@@ -1,8 +1,8 @@
 QT += network sql maemo5
 TARGET = jenirok
 TEMPLATE = app
-SOURCES += main.cpp mainwindow.cpp searchdialog.cpp resultwindow.cpp detailwindow.cpp settingsdialog.cpp 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
index 8a3ebf2..649f4a7 100644 (file)
@@ -26,8 +26,6 @@
 #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
index 179eac8..11e6fc1 100644 (file)
@@ -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())
index a56838e..16636c1 100644 (file)
@@ -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()));
index 757a0ff..f84f8c8 100644 (file)
@@ -21,6 +21,7 @@
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QHBoxLayout>
 #include <QtGui/QIntValidator>
+#include <QtGui/QDialogButtonBox>
 #include <QMaemo5ValueButton>
 #include <QMaemo5InformationBox>
 #include <QDebug>
@@ -28,6 +29,7 @@
 #include "settings.h"
 #include "db.h"
 #include "daemon.h"
+#include "cache.h"
 
 QMap <Eniro::Site, Eniro::SiteDetails> 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));
+    }
+}
index eebdc92..7ad2a8d 100644 (file)
@@ -38,6 +38,7 @@ public:
 public slots:
     void saveSettings();
     void setVisible(bool visible);
+    void resetCache();
 
 private:
     static QMap <Eniro::Site, Eniro::SiteDetails> sites_;

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment