Added basic plugin loader and cleanup for backbone
authorBartosz Szatkowski <bulislaw@linux.com>
Wed, 4 Aug 2010 09:48:51 +0000 (11:48 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Wed, 4 Aug 2010 09:48:51 +0000 (11:48 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/includes/CommonDictInterface.h
trunk/tests/mDictionaryTests/tst_Backbone.cpp

index ef05d42..e712512 100644 (file)
@@ -29,43 +29,81 @@ Backbone::Backbone(QObject *parent)
    searchLimitv = 10;
 }
 
+
+
 Backbone::~Backbone()
 {
+    QListIterator<CommonDictInterface*> it(dicts.keys());
+
+    while(it.hasNext())
+        delete it.next();
+
+    it = QListIterator<CommonDictInterface*>(plugins);
+    while(it.hasNext())
+        delete it.next();
+
+    QHashIterator<QString, Translation*> it2(_result);
+    while(it2.hasNext())
+        delete it2.next().value();
 
 }
 
-Backbone::Backbone(const Backbone &b){
+
+
+
+Backbone::Backbone(const Backbone &b) :QObject(b.parent()) {
     dicts = QHash<CommonDictInterface*, bool > (b.dicts);
     plugins = QList<CommonDictInterface* > (b.plugins);
     _result = QHash<QString, Translation* > (b._result);
     searchLimitv = b.searchLimit();
 }
 
+
+
+
 int Backbone::searchLimit() const {
     return searchLimitv;
 }
 
+
+
+
 QHash<CommonDictInterface*, bool > Backbone::getDictionaries() {
     return dicts;
 }
 
+
+
+
 QList<CommonDictInterface* > Backbone::getPlugins() {
     return plugins;
 }
 
+
+
+
 QList<QString> Backbone::getHistory() {
     //TODO code needed
 }
 
+
+
+
 QMultiHash<QString, Translation*> Backbone::result() {
     return _result;
 }
 
+
+
+
 void Backbone::stopSearching() {
     foreach(CommonDictInterface* dict, dicts.keys())
         dict->stop();
 }
 
+
+
+
 void Backbone::search(QString word) {
     //TODO add running searches in new threads
     _result.clear();
@@ -81,6 +119,9 @@ void Backbone::search(QString word) {
         }
 }
 
+
+
+
  void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
      foreach(CommonDictInterface* dict, dicts.keys())
          if(activeDicts.contains(dict))
@@ -89,6 +130,9 @@ void Backbone::search(QString word) {
              dicts[dict] = 0;
  }
 
+
+
+
  void Backbone::addDictionary(CommonDictInterface* dict) {
      dicts[dict] = 1;
      connect(dict, SIGNAL(finalTranslation(QList<Translation*>)),
@@ -96,6 +140,8 @@ void Backbone::search(QString word) {
              Qt::UniqueConnection);
  }
 
+
+
  void Backbone::quit() {
     stopSearching();
     Q_EMIT closeOk();
@@ -120,3 +166,15 @@ void Backbone::translation(QList<Translation *> trans) {
 
 
 
+
+void Backbone::loadPlugins() {
+    QObject *pl = QPluginLoader("xdxf.so").instance();
+    if(!pl)
+        return;
+    CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
+    plugins.append(plugin);
+    addDictionary(plugin);
+}
+
+
+
index ea97550..76dff08 100644 (file)
@@ -27,6 +27,7 @@
 #include <QObject>
 #include <QList>
 #include <QHash>
+#include <QPluginLoader>
 #include "../../includes/CommonDictInterface.h"
 #include "../../includes/settings.h"
 #include "../../includes/translation.h"
@@ -96,6 +97,7 @@ Q_SIGNALS:
 
 
 private:
+    void loadPlugins(); //< locate and load plugins
     QHash<CommonDictInterface*, bool> dicts;
     QList<CommonDictInterface*> plugins;
     QMultiHash<QString, Translation*> _result;
index 7ece263..62c6874 100644 (file)
@@ -90,4 +90,6 @@ class CommonDictInterface : public QObject {
     //! emited after dictionary is ready to use afer being loaded
     void loaded(CommonDictInterface*);
 };
+
+Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1");
 #endif
index b0145ab..cbc13ce 100644 (file)
@@ -76,8 +76,6 @@ void BackboneTest::init()
 
 void BackboneTest::cleanup()
 {
-    for(int i = 0; i < total; i++)
-        delete dict[i];
     delete back;
 }