Stuffed another memory leak
[mdictionary] / trunk / src / base / backbone / backbone.cpp
index 4708367..360448d 100644 (file)
 #include "backbone.h"
 #include <QDebug>
 
+int Backbone::_searchLimit;
+
+// Sadly QtConcurent mapped dont let me use something like calling method of
+// some class with supplied argument
 QString mappedSearch;
 QList<Translation*> mapSearch(CommonDictInterface *dict) {
     if(dict)
-        return dict->searchWordList(mappedSearch, 15);
+        return dict->searchWordList(mappedSearch, Backbone::_searchLimit);
     return QList<Translation*>();
 }
 
@@ -81,6 +85,7 @@ void Backbone::init() {
            QThreadPool::globalInstance()->maxThreadCount()+1);
 
    _history = new History(5, this);
+   _dictNum = 0;
 }
 
 
@@ -215,7 +220,7 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
 
  void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
-     dict->setHash(_dicts.size()+1);
+     dict->setHash(++_dictNum);
      _dicts[dict] = active;
      connect(dict, SIGNAL(settingsChanged()), this, SLOT(dictUpdated()));
      connect(dict, SIGNAL(notify(Notify::NotifyType,QString)), this,
@@ -224,6 +229,7 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
  void Backbone::removeDictionary(CommonDictInterface *dict) {
      _dicts.remove(dict);
+     delete dict;
      dictUpdated();
 
  }
@@ -464,8 +470,10 @@ void Backbone::searchHtml(QList<Translation *> translations) {
 
     QList<TranslationPtr> dummy;
     stopped = false;
-    foreach(Translation* tr, translations)
-        dummy.append(TranslationPtr(tr));
+    foreach(Translation* tr, translations) {
+        if(containsDict(tr->dict()) || !tr->dict())
+            dummy.append(TranslationPtr(tr));
+  }
 
    _innerHtmlResult = QtConcurrent::mapped(dummy,
                                             &TranslationPtr::toHtml);
@@ -535,3 +543,14 @@ Settings* Backbone::settings() {
         settings->setValue("search_dictionaries", "false");
     return settings;
 }
+
+
+bool Backbone::containsDict(uint hash) const {
+    QHashIterator<CommonDictInterface*, bool> it(_dicts);
+    if (!hash)
+        return false;
+    while(it.hasNext())
+        if(it.next().key()->hash() == hash)
+            return true;
+    return false;
+}