QString toHtml() const {
if(!_key.size() || !_bookmarks)
return "";
- qDebug() << ">toHtml";
QStringList list = _bookmarks->search(_key, _dictionaryInfo);
- qDebug() << "toHtml" << list.size();
QString result;
foreach(QString translation, list)
result += translation + "\n";
- qDebug() << "<toHtml";
return result;
}
#include "backbone.h"
#include <QDebug>
+int Backbone::_searchLimit;
+
+// Sadly QtConcurent mapped dont let me use something like calling method of
+// some class with supplied argument
QString mappedSearch;
QList<Translation*> mapSearch(CommonDictInterface *dict) {
if(dict)
- return dict->searchWordList(mappedSearch, 15);
+ return dict->searchWordList(mappedSearch, Backbone::_searchLimit);
return QList<Translation*>();
}
QThreadPool::globalInstance()->maxThreadCount()+1);
_history = new History(5, this);
+ _dictNum = 0;
}
void Backbone::addInternalDictionary(CommonDictInterface* dict, bool active) {
- dict->setHash(_dicts.size()+1);
+ dict->setHash(++_dictNum);
_dicts[dict] = active;
connect(dict, SIGNAL(settingsChanged()), this, SLOT(dictUpdated()));
connect(dict, SIGNAL(notify(Notify::NotifyType,QString)), this,
void Backbone::removeDictionary(CommonDictInterface *dict) {
_dicts.remove(dict);
+ delete dict;
dictUpdated();
}
set.endGroup();
addInternalDictionary(plug->getNew(plugSet), active);
+ // if(plugSet)
+ // delete plugSet;
}
}
QList<TranslationPtr> dummy;
stopped = false;
- foreach(Translation* tr, translations)
- dummy.append(TranslationPtr(tr));
+ foreach(Translation* tr, translations) {
+ if(containsDict(tr->dict()) || !tr->dict())
+ dummy.append(TranslationPtr(tr));
+ }
_innerHtmlResult = QtConcurrent::mapped(dummy,
&TranslationPtr::toHtml);
settings->setValue("search_dictionaries", "false");
return settings;
}
+
+
+bool Backbone::containsDict(uint hash) const {
+ QHashIterator<CommonDictInterface*, bool> it(_dicts);
+ if (!hash)
+ return false;
+ while(it.hasNext())
+ if(it.next().key()->hash() == hash)
+ return true;
+ return false;
+}
* search_limit - int, how many different word may each dictionary returns
* 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
+ then eatch Translation object is capable of finging it own final translation
+
+ List of word:
+ - Gui call search(...)
+ - Backbone call plugins searchWordList(...) in idealThreadCount()+1 threads
+ - Backbone sets the FutureWatcher to be notifed when plugins are done
+ - Backbone fetch results from Future<..> and formats it for gui then
+ emits ready()
+ - Gui calls result()
+
+ Final translation:
+ - Gui call searchHtml()
+ - Backbone starts for eatch translation object toHtml in separate threads
+ - Backbone sets FutureWatcher to be notified after last toHtml returns
+ - Backbone fetch translation from Future<...> objects and calls
+ htmlReady()
+ - gui calls htmlResult()
+
*/
class Backbone : public QObject
{
public:
/*!\param pluginPath path to plugins (leave blank for default)
- \param configPath path to folder with configuration files*/
+ \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="",
bool dry = 0, QObject *parent = 0);
~Backbone();
//! \return final translation (after searching for html)
QStringList htmls();
+ /*! maximum number of translation that each plugin may return; it must be
+ public static becouse of QtConcurent::mapped restrictions about
+ what kind of function may be used there see Qt docs */
+ static int _searchLimit;
void quit();
- /*! Fired with given interval during searches -
- checking if translation is ready
+ /*! Fired by FutureWatcher when list of words is ready (after calling search)
+ fetch Future<...> to final result
*/
void translationReady();
- /*! Fired with given interval during html searches -
- checking if html is ready
+ /*! Fired by FutureWatcher when search result is ready, fetch Future to
+ final result
*/
void htmlTranslationReady();
QString _pluginPath, _defaultPluginPath;
QString _configPath;
QString _defaultConfigPath;
- int _searchLimit, _defaultSearchLimit;
+ int _defaultSearchLimit;
int _historyLen, _defaultHistoryLen;
bool dryRun; // mainly for testing - when true then dosent bother configs etc
CommonDictInterface* plugin(QString type); // search for given type plugin
QList<CommonDictInterface*> activeDicts();
+ bool containsDict(uint hash) const;
+ int _dictNum;
History* _history;
#include <QString>
#include <QMetaType>
+class CommonDictInterface;
/*! Translation is kind of GoF proxy, it stores key:translation pair and
virtual QString toHtml() const = 0;
//! \retrun whether given translation is taken from bookmarks
- bool isBookmark() const {
+ virtual bool isBookmark() const {
return _bookmark;
}
_bookmark = b;
}
+ //! returns coresponding dict object
+ virtual uint dict() const {return 0;} ;
+
protected:
bool _bookmark;
TranslationXdxf::TranslationXdxf() {
}
-TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo, XdxfPlugin *xdxfPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
+TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo,
+ XdxfPlugin *xdxfPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
this->xdxfPlugin=xdxfPlugin;
+ if(xdxfPlugin)
+ _dictHash = xdxfPlugin->hash();
}
QString TranslationXdxf::key() const {
QString TranslationXdxf::toHtml() const {
QString result("");
-// qDebug()<<xdxfPlugin->search(_key);
- result+="<dict>" + _dictionaryInfo + "<key>" + _key + "</key>" +xdxfPlugin->search(_key) + "</dict>";
+ if(!xdxfPlugin)
+ return result;
+ result+="<dict>" + _dictionaryInfo + "<key>" + _key + "</key>" +
+ xdxfPlugin->search(_key) + "</dict>";
result.replace("&","&");
-// qDebug()<<result;
return result;
}
void setDictionaryInfo(QString);
+ //! returns coresponding dict object
+ uint dict() const {return _dictHash;}
+
private:
QString _key;
QString _dictionaryInfo;
XdxfPlugin *xdxfPlugin;
+ int _dictHash;
};
settings->value("generateCache") == "true") {
plugin->makeCache("");
}
+ delete settings;
}
plugin->getDictionaryInfo();
else {
_settings->setValue("cached", "false");
}
+ delete settings;
emit settingsChanged();
}