Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Jenirok
Summary Tracker SCM Files
authoreshe <jessehakanen@gmail.com>
Sat, 5 Jun 2010 09:23:22 +0000 (10:23 +0100)
committereshe <jessehakanen@gmail.com>
Sat, 5 Jun 2010 09:23:22 +0000 (10:23 +0100)
Makefile
debian/changelog
src/common/connectionmanager.h
src/common/settings.cpp
src/common/settings.h
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/daemon.pro

index 166a6f3..a5cdae3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: jenirok
-# Generated by qmake (2.01a) (Qt 4.6.2) on: Fri Jun 4 18:33:00 2010
+# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Jun 5 10:22:03 2010
 # Project:  jenirok.pro
 # Template: subdirs
 # Command: /usr/bin/qmake -unix -o Makefile jenirok.pro
index 139ca56..5fd71f3 100644 (file)
@@ -1,3 +1,9 @@
+jenirok (0.1-7) unstable; urgency=low
+
+  * Decreased daemon's memory usage.
+
+ -- Jesse Hakanen <jessehakanen@gmail.com>  Sat,  5 Jun 2010 10:20:47 +0100
+
 jenirok (0.1-6) unstable; urgency=low
 
   * Added missing Finnish translations for several error messages.
index 6c5e2a1..9261eb3 100644 (file)
@@ -80,7 +80,7 @@ private:
     int scannedConnections_;
     int timer_;
     QList<Connection>* connections_;
-    QDBusInterface *icd2interface_;
+    QDBusInterface* icd2interface_;
 };
 
 #endif
index 91b289d..1333c21 100644 (file)
@@ -33,6 +33,12 @@ Settings* Settings::instance()
     return instance_;
 }
 
+void Settings::close()
+{
+    delete instance_;
+    instance_ = 0;
+}
+
 bool Settings::set(QString const& name, QString const& value)
 {
     bool connected = DB::connected();
index 2263beb..6649071 100644 (file)
@@ -30,6 +30,7 @@ class Settings
 
 public:
     static Settings* instance();
+    static void close();
     bool set(QString const& name, QString const& value);
     QString get(QString const& name);
     QString getDefaultValue(QString const& name);
index 5c640bb..d53da0a 100644 (file)
@@ -23,6 +23,7 @@
 #include "calllistener.h"
 #include "settings.h"
 #include "cache.h"
+#include "contactmanager.h"
 
 namespace
 {
@@ -37,9 +38,9 @@ namespace
 
 QDBusConnection CallListener::systemBus_ = QDBusConnection::systemBus();
 
-CallListener::CallListener(): eniro_(0), contactManager_(0),
-connectionManager_(0), closeConnection_(false), box_(0), label_(0),
-retries_(-1)
+CallListener::CallListener(): eniro_(0), connectionManager_(0),
+closeConnection_(false), initialized_(false), box_(0), label_(0),
+retries_(-1), site_(Eniro::FI)
 {
 }
 
@@ -64,23 +65,8 @@ void CallListener::begin()
                        this,
                        SLOT(callTerminate()));
 
-    contactManager_ = new ContactManager;
-
-    eniro_ = new Eniro(Eniro::stringToSite(Settings::instance()->get("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)));
-
-    box_ = new InformationBox();
-    label_ = new QLabel("", box_);
-    label_->setMargin(8);
-    box_->setWidget(label_);
+    site_ = Eniro::stringToSite(Settings::instance()->get("site"));
+    Settings::close();
 
     qDebug() << "Starting...";
 
@@ -102,27 +88,23 @@ void CallListener::end()
                           this,
                           SLOT(callTerminate()));
 
-    delete contactManager_;
-    contactManager_ = 0;
-    delete connectionManager_;
-    connectionManager_ = 0;
-    delete eniro_;
-    eniro_ = 0;
-    delete box_;
-    box_ = 0;
-    delete label_;
-    label_ = 0;
+    searchClose();
+
 }
 
 void CallListener::search(Eniro::SearchDetails const& details)
 {
     qDebug() << "Search called";
 
+    searchInit();
+
     Eniro::Result result;
 
     if(Cache::instance().findItem(details.query, result))
     {
 
+        qDebug() << "Found from cache";
+
         showDelayedResult(createResult(result.name,
                                        result.street,
                                        result.city), BANNER_DELAY);
@@ -132,14 +114,6 @@ void CallListener::search(Eniro::SearchDetails const& details)
         retries_ = 0;
         currentSearch_ = details.query;
 
-        if(connectionManager_)
-        {
-            delete connectionManager_;
-            connectionManager_ = 0;
-        }
-
-        connectionManager_ = new ConnectionManager;
-
         if(!connectionManager_->isConnected())
         {
             connectionManager_->connect();
@@ -151,6 +125,9 @@ void CallListener::search(Eniro::SearchDetails const& details)
         }
 
         showDelayedResult(tr("Searching..."), BANNER_DELAY);
+
+        qDebug() << "Starting to search...";
+
         eniro_->search(details);
     }
 
@@ -161,7 +138,7 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
                                    bool error)
 {
     // If box is not visible, the call must have been terminated already
-    if(!box_->isVisible())
+    if(!initialized_ || !box_->isVisible())
     {
         return;
     }
@@ -213,10 +190,6 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
         connectionManager_->disconnect(true);
         closeConnection_ = false;
     }
-
-    delete connectionManager_;
-    connectionManager_ = 0;
-
 }
 
 QString CallListener::createResult(QString const& name, QString const& street, QString const& city)
@@ -240,6 +213,11 @@ QString CallListener::createResult(QString const& name, QString const& street, Q
 
 void CallListener::showResult(QString const& text)
 {
+    if(!initialized_)
+    {
+        return;
+    }
+
     label_->setText("<font color='black'>" + text + "</font>");
 
     if(box_->isVisible())
@@ -254,7 +232,9 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number)
 {
     qDebug() << "Incoming: " << number;
 
-    if(!contactManager_->numberExists(number))
+    ContactManager cm;
+
+    if(!cm.numberExists(number))
     {
         qDebug() << "Number doesn't exist";
 
@@ -265,8 +245,6 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number)
                            this,
                            SLOT(callTerminate()));
 
-        qDebug() << "Going to search";
-
         search(Eniro::SearchDetails(number));
     }
     else
@@ -277,7 +255,7 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number)
 
 void CallListener::callTerminate()
 {
-    if(box_->isVisible())
+    if(initialized_ && box_ && box_->isVisible())
     {
         box_->hide();
     }
@@ -288,8 +266,7 @@ void CallListener::callTerminate()
         closeConnection_ = false;
     }
 
-    delete connectionManager_;
-    connectionManager_ = 0;
+    searchClose();
 }
 
 void CallListener::showDelayedResult(QString const& text, int delay)
@@ -300,7 +277,7 @@ void CallListener::showDelayedResult(QString const& text, int delay)
 
 void CallListener::showTimedMessage()
 {
-    if(timedMessage_.size() == 0)
+    if(timedMessage_.size() == 0 || !initialized_)
     {
         return;
     }
@@ -309,3 +286,47 @@ void CallListener::showTimedMessage()
 
     timedMessage_ = "";
 }
+
+void CallListener::searchInit()
+{
+    qDebug() << "Initializing search...";
+
+    connectionManager_ = new ConnectionManager;
+
+    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)));
+    box_ = new InformationBox;
+    label_ = new QLabel("", box_);
+    label_->setMargin(8);
+    box_->setWidget(label_);
+    initialized_ = true;
+}
+
+void CallListener::searchClose()
+{
+    initialized_ = false;
+
+    qDebug() << "Closing search...";
+
+    if(eniro_)
+    {
+        disconnect(eniro_, SIGNAL(requestFinished(QVector <Eniro::Result> const&,
+                                                  Eniro::SearchDetails const&, bool)),
+                                                  this, SLOT(requestFinished(QVector <Eniro::Result> const&,
+                                                                             Eniro::SearchDetails const&, bool)));
+    }
+
+    delete connectionManager_;
+    connectionManager_ = 0;
+    delete eniro_;
+    eniro_ = 0;
+    delete box_;
+    box_ = 0;
+}
index 8d098c8..4fe29b4 100644 (file)
@@ -26,7 +26,6 @@
 #include <QtDBus/QDBusObjectPath>
 #include "informationbox.h"
 #include "eniro.h"
-#include "contactmanager.h"
 #include "connectionmanager.h"
 
 class CallListener: public QObject
@@ -39,7 +38,7 @@ public:
     void begin();
     void end();
     static const int REQUEST_TIMEOUT = 10000;
-    static const int BANNER_DELAY = 400;
+    static const int BANNER_DELAY = 350;
     static const int NUMBER_OF_RETRIES = 3;
 
 private slots:
@@ -54,17 +53,20 @@ private:
     void search(Eniro::SearchDetails const& details);
     void showResult(QString const& text);
     void showDelayedResult(QString const& text, int delay);
+    void searchInit();
+    void searchClose();
     QString createResult(QString const& name, QString const& street, QString const& city);
     QString timedMessage_;
     Eniro* eniro_;
-    ContactManager* contactManager_;
     ConnectionManager* connectionManager_;
     bool closeConnection_;
+    bool initialized_;
     InformationBox* box_;
     QLabel* label_;
     static QDBusConnection systemBus_;
     int retries_;
     QString currentSearch_;
+    Eniro::Site site_;
 };
 
 #endif // CALLLISTENER_H
index c7fb9b2..252661b 100644 (file)
@@ -8,7 +8,7 @@ TRANSLATIONS = ../common/translations/fi_FI.ts
 RESOURCES = ../common/translations.grc
 INCLUDEPATH += ../common
 CONFIG += link_pkgconfig
-PKGCONFIG += libebook-1.2 glib-2.0
+PKGCONFIG += libebook-1.2
 
 unix {
   #VARIABLES

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment