loadPlugins();
loadDicts();
- if(!connect(&_timer, SIGNAL(timeout()), this, SLOT(translation())))
- qDebug() << "Timer signal not connected";
+ connect(&_timerSearch, SIGNAL(timeout()), this, SLOT(translationReady()));
+ connect(&_timerHtmlSearch, SIGNAL(timeout()), this,
+ SLOT(htmlTranslationReady()));
}
Backbone::Backbone(QString pluginPath, QString configPath, QObject *parent)
void Backbone::stopSearching() {
- _timer.stop();
+ _timerSearch.stop();
_innerResult.clear();
foreach(CommonDictInterface* dict, _dicts.keys())
dict->stop();
void Backbone::search(QStringList words) {
- _timer.stop();
+ _timerSearch.stop();
_result.clear();
_innerResult.clear();
- _timer.start(_interval);
+ _timerSearch.start(_interval);
foreach(QString word, words)
foreach(CommonDictInterface* dict, _dicts.keys())
if(_dicts[dict] == 1) {
-void Backbone::translation() {
+void Backbone::translationReady() {
foreach(QFuture<QList<Translation*> > trans, _innerResult) {
if(!trans.isFinished())
continue;
_innerResult.removeOne(trans);
}
if(!_innerResult.size()) {
- _timer.stop();
+ _timerSearch.stop();
Q_EMIT ready();
}
}
}
}
+
+
void Backbone::dictUpdated() {
QDir confDir(_configPath);
if(!confDir.exists())
saveState(&set, dict->settings(), _dicts[dict], dict->hash());
}
+
+
void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
, uint hash) {
if(!set || !plugSet)
set->setValue(section + "/" + key, plugSet->value(key));
set->setValue(section + "/active", active);
}
+
+
+
+QStringList Backbone::htmls() {
+ return _htmlResult;
+}
+
+
+
+void Backbone::searchHtml(QList<Translation *> translations) {
+ _timerHtmlSearch.stop();
+ _htmlResult.clear();
+ _innerHtmlResult.clear();
+ _timerHtmlSearch.start();
+
+ foreach(Translation* trans, translations)
+ _innerHtmlResult.append(
+ QtConcurrent::run(trans, &Translation::toHtml()));
+}
+
+void Backbone::htmlTranslationReady() {
+
+}
//! \return number of active searches
int activeSearches() const;
+ /*! Performs search for final translation (html/xml) form
+ \param list of Translation* to be searched for
+ */
+ void searchHtml(QList<Translation*>);
+
+ //! \return final translation (after searching for html)
+ QStringList htmls();
+
+
public Q_SLOTS:
//! stops all current searches
void stopSearching();
/*! Fired with given interval during searches -
checking if translation is ready
*/
- void translation();
+ void translationReady();
+
+ /*! Fired with given interval during html searches -
+ checking if html is ready
+ */
+ void htmlTranslationReady();
/*! Removes given dictionary
\param dict dictionary to be deleted
//! emitted when there are search result ready to fetch
void ready();
+ //! emitted when html result is ready to fetch
+ void htmlReady();
+
private:
QHash<CommonDictInterface*, bool> _dicts;
QList<CommonDictInterface*> _plugins;
QList<QFuture<QList<Translation*> > > _innerResult;
+ QList<QFuture<QString> > _innerHtmlResult;
QMultiHash<QString, Translation*> _result;
- QTimer _timer;
+ QStringList _htmlResult;
+ QTimer _timerSearch, _timerHtmlSearch;
QTime _time;
QString _pluginPath;
QString _configPath;