Fix random error when remove word from bookmark. Fix show all bookmark feature.
[mdictionary] / src / mdictionary / backbone / backbone.h
index 66ebea4..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"
         - 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
@@ -130,8 +132,8 @@ public:
     //! \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
@@ -173,7 +175,7 @@ public Q_SLOTS:
     /*! Fired by FutureWatcher when search result is ready, fetch Future to
         final result
       */
-    void htmlTranslationReady();
+    void xmlTranslationReady();
 
     /*! Removes a given dictionary
         \param dict dictionary to be deleted
@@ -183,21 +185,17 @@ public Q_SLOTS:
     /*! Saves plugins new state/configuration after each change */
     void dictUpdated();
 
-    /*! Performs search for final translation (html/xml) from a list
+    /*! 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 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
@@ -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();
@@ -276,6 +274,10 @@ Q_SIGNALS:
     */
     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;