Added tohtml handling in separate thread
authorBartosz Szatkowski <bulislaw@linux.com>
Tue, 10 Aug 2010 09:45:27 +0000 (11:45 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Tue, 10 Aug 2010 09:45:27 +0000 (11:45 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/tests/mDictionaryTests/tst_Backbone.cpp

index f49dff4..b1f9421 100644 (file)
@@ -39,8 +39,9 @@ void Backbone::init() {
    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)
@@ -120,7 +121,7 @@ QMultiHash<QString, Translation*> Backbone::result() {
 
 
 void Backbone::stopSearching() {
-    _timer.stop();
+    _timerSearch.stop();
     _innerResult.clear();
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
@@ -130,11 +131,11 @@ void Backbone::stopSearching() {
 
 
 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) {
@@ -195,7 +196,7 @@ int Backbone::activeSearches() const {
 
 
 
-void Backbone::translation() {
+void Backbone::translationReady() {
     foreach(QFuture<QList<Translation*> > trans, _innerResult) {
         if(!trans.isFinished())
             continue;
@@ -206,7 +207,7 @@ void Backbone::translation() {
         _innerResult.removeOne(trans);
     }
     if(!_innerResult.size()) {
-        _timer.stop();
+        _timerSearch.stop();
         Q_EMIT ready();
     }
 }
@@ -301,6 +302,8 @@ void Backbone::loadDicts() {
     }
 }
 
+
+
 void Backbone::dictUpdated() {
     QDir confDir(_configPath);
     if(!confDir.exists())
@@ -310,6 +313,8 @@ void Backbone::dictUpdated() {
         saveState(&set, dict->settings(), _dicts[dict], dict->hash());
 }
 
+
+
 void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
                          , uint hash) {
     if(!set || !plugSet)
@@ -321,3 +326,26 @@ void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
         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() {
+
+}
index fee6e60..8a1b29d 100644 (file)
@@ -78,6 +78,15 @@ public:
     //! \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();
@@ -106,7 +115,12 @@ public Q_SLOTS:
     /*! 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
@@ -127,14 +141,19 @@ Q_SIGNALS:
     //! 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;
index 1867828..01f6a77 100644 (file)
@@ -198,7 +198,7 @@ void BackboneTest::translationTest() {
     qDebug() << "Time for backbone.search: " << time.elapsed();
     usleep(2000);
     time.start();
-    back->translation();
+    back->translationReady();
     qDebug() << "Time for backbone->translation: " << time.elapsed();
 
     QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");