Bookamarks adding, removing, searching (basic), listing -> ready
[mdictionary] / trunk / src / base / backbone / backbone.h
index 142d729..d92fa50 100644 (file)
@@ -47,6 +47,7 @@
 #include "../../includes/settings.h"
 #include "../../includes/translation.h"
 #include "../../includes/History.h"
+#include "Bookmarks.h"
 
 
 /*! Inner part of dictionary - glues together GUI and plugins
@@ -138,8 +139,43 @@ public Q_SLOTS:
       */
     void searchHtml(QList<Translation*>);
 
-    // TODO addToBookmark(Translation*);
-    // TODO removeFromBookmark(Translation*);
+
+    /*! add 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
+      */
+    void addBookmark(QList<Translation*> translations) {
+        foreach(Translation* translation, translations)
+            QtConcurrent::run(&bookmarks, &Bookmarks::add, translation);
+    }
+
+
+    /*! Remove bookmarks to given translatios
+      \param translation remove bookmark to this translation
+      */
+    void removeBookmark(QList<Translation*> translations) {
+        foreach(Translation* translation, translations)
+            bookmarks.remove(translation);
+    }
+
+
+   /*! Searching for list of bookmarks may take some time, so i moved it to
+       new thread (to avoid gui blocking), when ready bookmarksReady is emited
+       and result is returned after calling getBookmarks()
+       */
+   void fetchBookmarks() {
+       _bookmarksResult.clear();
+       _innerBookmarks = QtConcurrent::run(bookmarks, &Bookmarks::list);
+       _bookmarkWatcher.setFuture(_innerBookmarks);
+   }
+
+   /*! \return list of all bookmarks
+     */
+   QList<Translation*> getBookmarks() {
+       return _bookmarksResult;
+   }
+
+
 
 Q_SIGNALS:
     /*! emmited when backbone is ready to close - after getting stop signal it
@@ -155,6 +191,11 @@ Q_SIGNALS:
     //! throwed when searches are stopped
     void searchCanceled();
 
+    //! emmited when bookmark list is ready to fetch
+    void bookmarksReady();
+
+private Q_SLOTS:
+    void bookmarksListReady();
 
 
 private:
@@ -162,19 +203,23 @@ private:
     QList<CommonDictInterface*> _plugins;
     QFuture<QList<Translation*> > _innerResult;
     QFuture<QString> _innerHtmlResult;
+    QFuture<QList<Translation*> > _innerBookmarks;
     QMultiHash<QString, Translation*> _result;
     QStringList _htmlResult;
+    QList<Translation*> _bookmarksResult;
     //QTime _time;
     QString _pluginPath, _defaultPluginPath;
     QString _configPath;
     QString _defaultConfigPath;
     QFutureWatcher<QList<Translation*> > _resultWatcher;
+    QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
     QFutureWatcher<QString> _htmlResultWatcher;
     int _searchLimit, _defaultSearchLimit;
     int _activeSearchNum;
     int _historyLen, _defaultHistoryLen;
     bool dryRun;
     bool stopped;
+    Bookmarks bookmarks;
 
 
     void init();