After stoping search non of (partial) results are returned; searchCanceled signal...
authorBartosz Szatkowski <bulislaw@linux.com>
Thu, 12 Aug 2010 14:23:46 +0000 (16:23 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Thu, 12 Aug 2010 14:23:46 +0000 (16:23 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h

index bc19ac8..fac41a7 100644 (file)
@@ -79,6 +79,8 @@ void Backbone::init() {
    _history = new History(5, this);
 }
 
+
+
 Backbone::Backbone(QString pluginPath, QString configPath, bool dry,
                    QObject *parent)
     : QObject(parent)
@@ -130,51 +132,46 @@ int Backbone::searchLimit() const {
 
 
 
-
 QHash<CommonDictInterface*, bool > Backbone::getDictionaries() {
     return _dicts;
 }
 
 
 
-
 QList<CommonDictInterface* > Backbone::getPlugins() {
     return _plugins;
 }
 
 
 
-
 History* Backbone::history() {
     return _history;
 }
 
 
 
-
 QMultiHash<QString, Translation*> Backbone::result() {
     return _result;
 }
 
 
 
-
 void Backbone::stopSearching() {
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
+    stopped = true;
     _innerHtmlResult.cancel();
     _innerResult.cancel();
+    Q_EMIT searchCanceled();
 }
 
 
 
-
-
-
 void Backbone::search(QString word) {
     _result.clear();
     mappedSearch = word.toLower();
     //_time.restart();
+    stopped = false;
 
     _innerResult = QtConcurrent::mapped(activeDicts(), mapSearch);
     _resultWatcher.setFuture(_innerResult);
@@ -182,7 +179,6 @@ void Backbone::search(QString word) {
 
 
 
-
 void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
     foreach(CommonDictInterface* dict, _dicts.keys())
         if(activeDicts.contains(dict))
@@ -222,9 +218,6 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
 
 
-
-
-
 void Backbone::translationReady() {
     //if(!_innerResult.isFinished())
      //   return;
@@ -237,7 +230,8 @@ void Backbone::translationReady() {
     }
 
     //qDebug () << "time " << _time.elapsed();
-    Q_EMIT ready();
+    if(!stopped)
+        Q_EMIT ready();
 }
 
 QStringList Backbone::getFilesFromDir(QString dir, QStringList nameFilter) {
@@ -422,6 +416,7 @@ QStringList Backbone::htmls() {
 void Backbone::searchHtml(QList<Translation *> translations) {
     _htmlResult.clear();
     QList<TranslationPtr> dummy;
+    stopped = false;
     //_time.restart();
     foreach(Translation* tr, translations)
         dummy.append(TranslationPtr(tr));
@@ -440,7 +435,7 @@ void Backbone::htmlTranslationReady() {
        _htmlResult.append(it.next());
 
     //qDebug() << "time " << _time.elapsed();
-    if(_htmlResult.size())
+    if(!stopped)
         Q_EMIT htmlReady();
 
 }
index 1c8165f..5ab14dd 100644 (file)
@@ -152,6 +152,9 @@ Q_SIGNALS:
     //! emitted when html result is ready to fetch
     void htmlReady();
 
+    //! throwed when searches are stopped
+    void searchCanceled();
+
 
 
 private:
@@ -171,6 +174,7 @@ private:
     int _activeSearchNum;
     int _historyLen, _defaultHistoryLen;
     bool dryRun;
+    bool stopped;
 
 
     void init();