Merge branch 'master' into google
[mdictionary] / src / mdictionary / backbone / backbone.cpp
index bdbb11a..4ab57cc 100644 (file)
@@ -63,9 +63,8 @@ public:
     /*! \return translation text for corresponding Translation object */
     QString toHtml() const {
         QString trans;
-        trans = _tr->toHtml();
+        trans = _tr->toXml();
         return trans;
-
     }
 };
 
@@ -81,7 +80,7 @@ void Backbone::init() {
 
    //Install default config files
    ConfigGenerator confGen;
-   confGen.generateCss(_dir + "style.css");
+   ///confGen.generateCss(_dir + "style.css");
    confGen.generateDefaultConfig(_configPath);
 
    loadPrefs(_configPath);
@@ -91,15 +90,15 @@ void Backbone::init() {
    loadDicts(_configPath);
 
    connect(&_resultWatcher, SIGNAL(finished()), this, SLOT(translationReady()));
-   connect(&_htmlResultWatcher, SIGNAL(finished()), this,
-           SLOT(htmlTranslationReady()));
+   connect(&_xmlResultWatcher, SIGNAL(finished()), this,
+           SLOT(xmlTranslationReady()));
    connect(&_bookmarkWatcher, SIGNAL(finished()), this,
            SLOT(bookmarksListReady()));
    connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this,
            SLOT(translationReady()));
 
    // In common opinion perfect thread count is cores_number+1 (in qt perfect
-   // thread count is set to cores number)
+   // thread count is set to cores number) so iam changin it
    QThreadPool::globalInstance()->setMaxThreadCount(
            QThreadPool::globalInstance()->maxThreadCount()+1);
 
@@ -138,6 +137,7 @@ Backbone::~Backbone()
     while(it2.hasNext())
         delete it2.next().value();
 
+    delete _history;
 }
 
 
@@ -191,7 +191,7 @@ void Backbone::stopSearching() {
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
     stopped = true;
-    _innerHtmlResult.cancel();
+    _innerXmlResult.cancel();
     _innerResult.cancel();
     Q_EMIT searchCanceled();
 }
@@ -263,19 +263,18 @@ void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
 
  void Backbone::removeDictionary(CommonDictInterface *dict) {
      _dicts.remove(dict);
-     if(dict)
+     if(dict) {
         dict->clean();
-     else
-        qDebug()<<"delete empty dict";
-     delete dict;
+        delete dict;
+     }
      dictUpdated();
-
  }
 
 
 
  void Backbone::quit() {
     stopSearching();
+    usleep(100);
     Q_EMIT closeOk();
 }
 
@@ -365,6 +364,8 @@ void Backbone::loadPlugins() {
         if(!exists) {
             _plugins.append(plugin);
             plugin->retranslate();
+            connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+                    this, SIGNAL(notify(Notify::NotifyType,QString)));
         }
     }
 }
@@ -470,7 +471,7 @@ void Backbone::dictUpdated() {
 
     // For convienence this function is called for each change in dictionaries
     // and each call dumps configuration for all dictionaries into file.
-    // Maybe better way would be to store new/changed configuration but
+    // Maybe a better way would be to store new/changed configuration but
     // parsing settings file and figuring out what was changed, in my opinion,
     // would take more time
     _history->setMaxSize(_historyLen);
@@ -509,25 +510,20 @@ void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
 
 
 
-QStringList Backbone::htmls() {
-    return _htmlResult;
+QStringList Backbone::xmls() {
+    return _xmlResult;
 }
 
 
 
-void Backbone::searchHtml(QList<Translation *> translations) {
-    _htmlResult.clear();
+void Backbone::searchXml(QList<Translation *> translations) {
+    _xmlResult.clear();
 
     QList<TranslationPtr> dummy;
     stopped = false;
     foreach(Translation* tr, translations) {
          if(containsDict(tr->dict()) || !tr->dict())
             dummy.append(TranslationPtr(tr));
-  /*      foreach(CommonDictInterface* dict, activeDicts()) {
-            Translation* trans = dict->getTranslationFor(tr->key());
-            if(trans)
-                dummy.append(TranslationPtr(trans));
-        } */
     }
     if(translations.size()>0) {
         Translation *tr = translations.at(0);
@@ -538,24 +534,24 @@ void Backbone::searchHtml(QList<Translation *> translations) {
         }
     }
 
-   _innerHtmlResult = QtConcurrent::mapped(dummy,
+   _innerXmlResult = QtConcurrent::mapped(dummy,
                                             &TranslationPtr::toHtml);
-   _htmlResultWatcher.setFuture(_innerHtmlResult);
+   _xmlResultWatcher.setFuture(_innerXmlResult);
 }
 
 
 
-void Backbone::htmlTranslationReady() {
+void Backbone::xmlTranslationReady() {
 
-    QFutureIterator<QString> it(_innerHtmlResult);
+    QFutureIterator<QString> it(_innerXmlResult);
     QSet<QString> uniqe;
     while(it.hasNext())
         uniqe.insert(it.next());
-    _htmlResult.clear();
-    _htmlResult = uniqe.toList();
+    _xmlResult.clear();
+    _xmlResult = uniqe.toList();
 
     if(!stopped)
-        Q_EMIT htmlReady();
+        Q_EMIT xmlReady();
 
 }