Some memory usage improvements to daemon.
authoreshe <jessehakanen@gmail.com>
Sun, 30 May 2010 10:36:18 +0000 (11:36 +0100)
committereshe <jessehakanen@gmail.com>
Sun, 30 May 2010 10:36:18 +0000 (11:36 +0100)
src/common/connectionmanager.cpp
src/common/connectionmanager.h
src/common/contactmanager.cpp
src/daemon/calllistener.cpp
src/daemon/calllistener.h
src/daemon/main.cpp

index 14c0b0a..07f277e 100644 (file)
@@ -45,6 +45,19 @@ timer_(0)
 
 }
 
+ConnectionManager::~ConnectionManager()
+{
+    QDBusConnection systemBus = QDBusConnection::systemBus();
+
+    systemBus.disconnect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH,
+                         ICD_DBUS_API_INTERFACE, ICD_DBUS_API_STATE_SIG,
+                         this, SLOT(stateChange(const QDBusMessage&)));
+
+    systemBus.disconnect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH,
+                         ICD_DBUS_API_INTERFACE, ICD_DBUS_API_CONNECT_SIG,
+                         this, SLOT(connectionChange(const QDBusMessage&)));
+}
+
 bool ConnectionManager::connect()
 {
     ready_ = false;
@@ -99,39 +112,30 @@ void ConnectionManager::stateChange(const QDBusMessage& rep)
     switch(status)
     {
     case ICD_STATE_CONNECTING:
-        qDebug() << "Connecting";
         break;
     case ICD_STATE_CONNECTED:
         connected_ = true;
         ready_ = true;
-        qDebug() << "Connected";
         break;
     case ICD_STATE_DISCONNECTING:
-        qDebug() << "Disconnecting";
         break;
     case ICD_STATE_DISCONNECTED:
         connected_ = false;
         ready_ = true;
-        qDebug() << "Disconnected";
         break;
     case ICD_STATE_LIMITED_CONN_ENABLED:
         connected_ = true;
         ready_ = true;
-        qDebug() << "Limited connection enabled";
         break;
     case ICD_STATE_LIMITED_CONN_DISABLED:
         connected_ = false;
         ready_ = true;
-        qDebug() << "Limited connection disabled";
         break;
     case ICD_STATE_SEARCH_START:
-        qDebug() << "Search start";
         break;
     case ICD_STATE_SEARCH_STOP:
-        qDebug() << "Search stop";
         break;
     case ICD_STATE_INTERNAL_ADDRESS_ACQUIRED:
-        qDebug() << "Internal address acquired";
         break;
     default:
         qDebug() << "Unknown connection status";
@@ -149,17 +153,14 @@ void ConnectionManager::connectionChange(const QDBusMessage& rep)
     case ICD_CONNECTION_SUCCESSFUL:
         connected_ = true;
         ready_ = true;
-        qDebug() << "Connection successful";
         break;
     case ICD_CONNECTION_NOT_CONNECTED:
         connected_ = false;
         ready_ = true;
-        qDebug() << "Connection not connected";
         break;
     case ICD_CONNECTION_DISCONNECTED:
         connected_ = false;
         ready_ = true;
-        qDebug() << "Connection disconnected";
         break;
     default:
         qDebug() << "Unknown connection status";
index 0c12a0d..e19f4e5 100644 (file)
@@ -30,6 +30,7 @@ class ConnectionManager : public QObject
 
 public:
     ConnectionManager(QObject* parent = 0);
+    ~ConnectionManager();
     bool connect();
     bool disconnect();
     bool isConnected();
index 0a49a7c..c2e886f 100644 (file)
@@ -54,6 +54,8 @@ bool ContactManager::numberExists(QString const& number)
         return false;
     }
 
+    e_book_query_unref(query);
+
     if (g_contacts == 0)
     {
         qDebug() << "no contacts";
@@ -112,23 +114,17 @@ bool ContactManager::load()
         return true;
     }
 
-    qDebug() << "Loading addressbook";
-
     GError *error;
     error = 0;
     book_ = e_book_new_system_addressbook(&error);
 
-    qDebug() << "Loaded almost";
-
     if (!book_)
     {
-        qDebug() << "Couldn't open addressbook: %s" <<  error->message;
+        qDebug() << "Couldn't open addressbook: %s" << error->message;
         g_error_free(error);
         return false;
     }
 
-    qDebug() << "Addressbook loaded";
-
     /* Open connection to the address book */
     if (!e_book_open(book_, FALSE, &error))
     {
@@ -137,8 +133,6 @@ bool ContactManager::load()
         return false;
     }
 
-    qDebug() << "Addressbook opened";
-
     return true;
 
 }
index 1237b7c..cbeb837 100644 (file)
@@ -65,7 +65,6 @@ void CallListener::begin()
                        SLOT(callTerminate()));
 
     contactManager_ = new ContactManager;
-    connectionManager_ = new ConnectionManager;
 
     eniro_ = new Eniro(Eniro::stringToSite(Settings::instance()->get("site")));
 
@@ -132,7 +131,15 @@ void CallListener::search(Eniro::SearchDetails const& details)
     {
         showResult(tr("Searching..."));
         retries_ = 0;
-        currentSearch_ = details;
+        currentSearch_ = details.query;
+
+        if(connectionManager_)
+        {
+            delete connectionManager_;
+            connectionManager_ = 0;
+        }
+
+        connectionManager_ = new ConnectionManager;
 
         if(!connectionManager_->isConnected())
         {
@@ -153,8 +160,6 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
                                    Eniro::SearchDetails const& details,
                                    bool error)
 {
-    qDebug() << "Found: " << results.size();
-
     // If box is not visible, the call must have been terminated already
     if(!box_->isVisible())
     {
@@ -170,7 +175,7 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
         if(retries_ < NUMBER_OF_RETRIES && retries_ >= 0)
         {
             retries_++;
-            eniro_->search(currentSearch_);
+            eniro_->search(Eniro::SearchDetails(currentSearch_));
             return;
         }
         else
@@ -191,6 +196,7 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
     }
 
     retries_ = -1;
+    currentSearch_ = "";
 
     if(closeConnection_)
     {
@@ -198,7 +204,8 @@ void CallListener::requestFinished(QVector <Eniro::Result> const& results,
         closeConnection_ = false;
     }
 
-    timedMessage_ = message;
+    delete connectionManager_;
+    connectionManager_ = 0;
 
     showResult(message);
 
@@ -231,6 +238,7 @@ void CallListener::showResult(QString const& text)
     {
         box_->hide();
     }
+
     box_->show();
 }
 
@@ -266,11 +274,14 @@ void CallListener::callTerminate()
         box_->hide();
     }
 
-    if(closeConnection_)
+    if(closeConnection_ && connectionManager_)
     {
         connectionManager_->disconnect();
         closeConnection_ = false;
     }
+
+    delete connectionManager_;
+    connectionManager_ = 0;
 }
 
 void CallListener::showDelayedResult(QString const& text, int delay)
index 346b6f5..164e10b 100644 (file)
@@ -31,7 +31,6 @@
 
 class CallListener: public QObject
 {
-
     Q_OBJECT
 
 public:
@@ -65,7 +64,7 @@ private:
     QLabel* label_;
     static QDBusConnection systemBus_;
     int retries_;
-    Eniro::SearchDetails currentSearch_;
+    QString currentSearch_;
 };
 
 #endif // CALLLISTENER_H
index 56b176d..7613a15 100644 (file)
 #include <QtCore/QLocale>
 #include <QtCore/QString>
 #include <QtGui/QApplication>
-#include <QDebug>
 #include "calllistener.h"
 #include "settings.h"
-#include "connectionmanager.h"
 
 int main(int argc, char *argv[])
 {