#include <QTime>
#include <QDir>
#include <QThread>
+#include <QDebug>
#include <QSettings>
#include <QFutureWatcher>
-#include "../../common/CommonDictInterface.h"
-#include "../../common/settings.h"
-#include "../../common/translation.h"
-#include "../../common/History.h"
-#include "../../common/Notify.h"
+#include <QMultiMap>
+#include "../../include/CommonDictInterface.h"
+#include "../../include/settings.h"
+#include "../../include/translation.h"
+#include "../../include/History.h"
+#include "../../include/Notify.h"
#include "ConfigGenerator.h"
#include "Bookmarks.h"
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.
+ Backbone also manages bookmarks and history: providing interface to GUI.
Backbone is also responsible for saving and spawning session via configs
file (stored in ~/.mdictionary) -> configs are kind of tricky because
configuration (apart from dictionaries and plugin ones).
Other modules may set some internal backbone behaviour via \see setSettings():
- Settings object with option given:
+ Settings object with options given:
* history_size - int, size of stored searches
* search_limit - int, how many different words each dictionary may return
* search_dictionaries - true/false, whether search in dictionaries
* search_bookmarks - true/false, whether search in bookmarks
Searching schema:
- 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 search(...)
+ - GUI calls search(...)
- Backbone calls plugins searchWordList(...) in idealThreadCount()+1 threads
- - Backbone sets the FutureWatcher to be notifed when plugins are done
- - Backbone fetches results from Future<..> and formats it for gui then
+ - Backbone sets the FutureWatcher to be notified when plugins are done
+ - Backbone fetches results from Future<..> and formats it for GUI, then
emits ready()
- - Gui calls result()
+ - GUI calls result()
Final translation:
- - Gui calls searchHtml()
- - Backbone starts for each translation object toHtml 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
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="",
//! \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
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
*/
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();
/*! 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);
/*! 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)
}
- /*! Searching for list of bookmarks may take some time, so I moved it to
- new thread (to avoid gui blocking), further it's consistent with ordinary
- searching for list of words (\see search)
+ /*! 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 a list of words (\see search)
*/
void fetchBookmarks() {
_result.clear();
_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)
*/
void setSettings(Settings* settings);
-
/*! \return corresponding settings object with history_size, search_limit,
searching backends (search_bookmarks, search_dictionaries)
*/
//! 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();
void bookmarksReady();
/*! emitted by direct connection to plugins notifying signals
- \param Notify::NotifyType gui may decide to show different types in
+ \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();
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
QFutureWatcher<QList<Translation*> > _resultWatcher;
QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
QFutureWatcher<QList<Translation*> > _bookmarkSearchWatcher;
- QFutureWatcher<QString> _htmlResultWatcher;
+ QFutureWatcher<QString> _xmlResultWatcher;
QString _pluginPath;
bool dryRun; // mainly for testing - when true then doesn't bother configs etc
bool stopped; // true when user stops searching/fetching
- bool bookmarkFin, dictFin; // inform whether given search type is ready
+ bool bookmarkFin, dictFin; // informs whether given search type is ready
bool _searchDicts, _searchBookmarks; // whether search performed in given source
Bookmarks _bookmarks;
void addInternalDictionary(CommonDictInterface*, bool);
void savePrefs(QSettings*);
- CommonDictInterface* plugin(QString type); // search for given type plugin
+ CommonDictInterface* plugin(QString type); // searches for plugin of a given type
QList<CommonDictInterface*> activeDicts();
bool containsDict(uint hash) const;
int _dictNum;