Fix random error when remove word from bookmark. Fix show all bookmark feature.
[mdictionary] / src / mdictionary / backbone / backbone.h
index 89a9da7..f59bc3d 100644 (file)
 #include <QTime>
 #include <QDir>
 #include <QThread>
+#include <QDebug>
 #include <QSettings>
 #include <QFutureWatcher>
+#include <QMultiMap>
 #include "../../include/CommonDictInterface.h"
 #include "../../include/settings.h"
 #include "../../include/translation.h"
@@ -60,7 +62,7 @@
   new searches and threads, merging search results from multiple dictionaries.
 
   Each plugin may live in multiple instances - each with its own dictionary,
-  backbone must provide way to create them at start (with specific Settings) and
+  backbone must provide a way to create them at start (with specific Settings) and
   distinguish each ditionary.
 
   Backbone also manages bookmarks and history: providing interface to GUI.
@@ -80,7 +82,7 @@
      * search_bookmarks - true/false, whether search in bookmarks
 
     Searching schema:
-        At first GUI should ask for list of words matching given pattern,
+        At first GUI should ask for a list of words matching a given pattern,
         then each Translation object is capable of finding its own final translation
 
       List of words:
         - GUI calls result()
 
       Final translation:
-         - GUI calls searchHtml()
-         - Backbone starts toHtml for each translation object in separate threads
-         - Backbone sets FutureWatcher to be notified after last toHtml returns
+         - GUI calls searchXml()
+         - Backbone starts toXml for each translation object in separate threads
+         - Backbone sets FutureWatcher to be notified after last toXml returns
          - Backbone fetches translation from Future<...> objects and calls
-             htmlReady()
-         - Gui calls htmlResult()
+             xmlReady()
+         - Gui calls xmlResult()
 
 */
 class Backbone : public QObject
@@ -105,9 +107,9 @@ class Backbone : public QObject
     Q_OBJECT
 
 public:
-    /*!\param pluginPath path to plugins (leave blank for default)
-      \param configPath path to folder with configuration files
-      \param dry dry run is mode without paying attention to configuration etc
+    /*! \param pluginPath path to plugins (leave blank for default)
+        \param configPath path to folder with configuration files
+        \param dry dry run is mode without paying attention to configuration etc
           mainly for testing
       */
     Backbone(QString pluginPath="", QString configPath="",
@@ -124,14 +126,14 @@ public:
     //! \return history of performed searches
     History* history();
 
-    //! \return return search fesult
+    //! \return search fesult
     QMultiHash<QString, Translation*> result();
 
     //! \return maximum number of words that plugin could find
     int searchLimit() const;
 
-    //! \return final translation (after searching for html)
-    QStringList htmls();
+    //! \return final translation (after searching for xml)
+    QStringList xmls();
 
     /*! maximum number of translations that each plugin may return; it must be
         public static because of QtConcurent::mapped restrictions about
@@ -145,16 +147,16 @@ public Q_SLOTS:
     void stopSearching();
 
     /*! searches for a word translation
-       \param word to be translated
+       \param word word to be translated
       */
     void search(QString word);
 
-    /*! sets active dictionaries (searches are performed only in active dicts
+    /*! sets active dictionaries (searches are performed only in active dicts)
        \param List of dictionaries to be activated
       */
-    void selectedDictionaries(QList<CommonDictInterface* >);
+    void selectedDictionaries(QList<CommonDictInterface*>);
 
-    /*! adds new dictionary and activates it
+    /*! adds a new dictionary and activates it
       \param dict dictionary to be added
       \param active decides whether searches are perfomed in given dictionaries
       */
@@ -165,7 +167,7 @@ public Q_SLOTS:
     void quit();
 
 
-    /*! Fired by FutureWatcher when list of words is ready (after calling search)
+    /*! Fired by FutureWatcher when a list of words is ready (after calling search),
         fetch Future<...> to final result
       */
     void translationReady();
@@ -173,9 +175,9 @@ public Q_SLOTS:
     /*! Fired by FutureWatcher when search result is ready, fetch Future to
         final result
       */
-    void htmlTranslationReady();
+    void xmlTranslationReady();
 
-    /*! Removes given dictionary
+    /*! Removes a given dictionary
         \param dict dictionary to be deleted
       */
     void removeDictionary(CommonDictInterface* dict);
@@ -183,25 +185,21 @@ public Q_SLOTS:
     /*! Saves plugins new state/configuration after each change */
     void dictUpdated();
 
-    /*! Performs search for final translation (html/xml) form
+    /*! Performs search for final translation (xml) form
       \param list of Translation* to be searched for
       */
-    void searchHtml(QList<Translation*>);
+    void searchXml(QList<Translation*>);
 
 
     /*! adds bookmarks to given translations (translation object is fetched and
       added to bookmarks data base (key and translation stored in db))
-      \param translation translation object to be stored in db
+      \param translations list of Translation objects to be stored in db
       */
-    void addBookmark(QList<Translation*> translations) {
-        foreach(Translation* translation, translations)
-            //_bookmarks.add(translation);
-            QtConcurrent::run(_bookmarks, &Bookmarks::add, translation);
-    }
+    void addBookmark(QList<Translation*> translations);
 
 
     /*! Removes bookmarks to given translations
-      \param translation remove bookmark to this translation
+      \param translations remove bookmark to these translations
       */
     void removeBookmark(QList<Translation*> translations) {
         foreach(Translation* translation, translations)
@@ -217,9 +215,9 @@ public Q_SLOTS:
     }
 
 
-   /*! Searching for list of bookmarks may take some time, so I moved it to
+   /*! Searching a list of bookmarks may take some time, so it's moved to a
        new thread (to avoid GUI blocking), further it's consistent with ordinary
-       searching for list of words (\see search)
+       searching a list of words (\see search)
        */
    void fetchBookmarks() {
         _result.clear();
@@ -231,9 +229,10 @@ public Q_SLOTS:
         _innerBookmarks = QtConcurrent::run(_bookmarks,
                 &Bookmarks::list);
         _bookmarkSearchWatcher.setFuture(_innerBookmarks);
-   }
-
 
+        Q_EMIT bookmarkMode();
+        qDebug()<<"1";
+   }
 
    /*! Sets settings for backbone: history_size, search_limit,
        searching backends (search_bookmarks, search_dictionaries)
@@ -241,7 +240,6 @@ public Q_SLOTS:
        */
     void setSettings(Settings* settings);
 
-
     /*! \return corresponding settings object with history_size, search_limit,
        searching backends (search_bookmarks, search_dictionaries)
        */
@@ -260,8 +258,8 @@ Q_SIGNALS:
     //! emitted when there are search results ready to fetch
     void ready();
 
-    //! emitted when html result is ready to fetch
-    void htmlReady();
+    //! emitted when xml result is ready to fetch
+    void xmlReady();
 
     //! thrown when searches are stopped
     void searchCanceled();
@@ -272,10 +270,14 @@ Q_SIGNALS:
     /*! emitted by direct connection to plugins notifying signals
         \param Notify::NotifyType GUI may decide to show different types in
             different ways
-        \param QString text of the notification
+        \param text of the notification
     */
     void notify(Notify::NotifyType, QString);
 
+    void bookmarkReady();
+
+    void bookmarkMode();
+
 private Q_SLOTS:
     void bookmarksListReady();
 
@@ -286,13 +288,13 @@ private:
 
 
     QFuture<QList<Translation*> > _innerResult; //Res of concurrent word search
-    QFuture<QString> _innerHtmlResult;  // Result of html search
+    QFuture<QString> _innerXmlResult;  // Result of xml search
     QFuture<QList<Translation*> > _innerBookmarks; //Res of search in bookmarks
     QFuture<QList<Translation*> > _innerListBookmarks; //Res of search in bookmarks
-    QFuture<QStringList> _innerHtmlBookmarks; //Html result of bookmarks search
+    QFuture<QStringList> _innerXmlBookmarks; //Xml result of bookmarks search
 
     QMultiHash<QString, Translation*> _result; //Final result of word search
-    QStringList _htmlResult; // Final result of html search
+    QStringList _xmlResult; // Final result of xml search
     QList<Translation*> _bookmarksResult; // Final result of search in bookmarks
 
 
@@ -300,7 +302,7 @@ private:
     QFutureWatcher<QList<Translation*> > _resultWatcher;
     QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
     QFutureWatcher<QList<Translation*> > _bookmarkSearchWatcher;
-    QFutureWatcher<QString> _htmlResultWatcher;
+    QFutureWatcher<QString> _xmlResultWatcher;
 
 
     QString _pluginPath;
@@ -328,7 +330,7 @@ private:
     void addInternalDictionary(CommonDictInterface*, bool);
     void savePrefs(QSettings*);
 
-    CommonDictInterface* plugin(QString type); // searches for plugin of given type
+    CommonDictInterface* plugin(QString type); // searches for plugin of a given type
     QList<CommonDictInterface*> activeDicts();
     bool containsDict(uint hash) const;
     int _dictNum;