Merge branch 'master' into google
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 15 Sep 2010 08:44:12 +0000 (10:44 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 15 Sep 2010 08:44:12 +0000 (10:44 +0200)
24 files changed:
mdictionary.pro
src/include/CommonDictInterface.h
src/include/translation.h
src/mdictionary/backbone/BookmarkTranslations.h
src/mdictionary/backbone/Bookmarks.cpp
src/mdictionary/backbone/Bookmarks.h
src/mdictionary/backbone/History.cpp
src/mdictionary/backbone/backbone.cpp
src/mdictionary/backbone/backbone.h
src/mdictionary/gui/MainWindow.cpp
src/mdictionary/gui/TranslationWidget.h
src/plugins/google/GoogleDialog.cpp
src/plugins/google/GooglePlugin.h
src/plugins/google/TranslationGoogle.cpp
src/plugins/google/TranslationGoogle.h
src/plugins/xdxf/TranslationXdxf.cpp
src/plugins/xdxf/TranslationXdxf.h
src/plugins/xdxf/xdxfplugin.cpp
src/plugins/xdxf/xdxfplugin.h
tests/GooglePluginTests/GooglePluginTests.pro
tests/GooglePluginTests/test.h
tests/XdxfPluginTests/XdxfPluginTests.pro
tests/XdxfPluginTests/test.cpp
tests/mDictionaryTests/TranslationMock.h

index c4d2a13..d11caec 100644 (file)
@@ -1,11 +1,11 @@
 TEMPLATE = subdirs
-SUBDIRS = src
+SUBDIRS = src 
 CONFIG += ordered
 include (mdictionary.pri)
 
 
 check.CONFIG += recursive
-check.recurse = src
+check.recurse = src 
 QMAKE_EXTRA_TARGETS += check
 
 
index af0079a..0f0c415 100644 (file)
@@ -59,7 +59,7 @@ class CommonDictInterface : public QObject, public AccentsNormalizer {
     //! \returns dictionary type (xdxf, google translate, etc)
     virtual QString type() const = 0;
 
-    //! \returns information about dictionary in html (name, authors, etc)
+    //! returns information about dictionary (name, authors, etc)
     virtual QString infoNote() const = 0;
 
     /*! \returns DictDialog object that creates dialogs
index bc24bac..2d7407e 100644 (file)
@@ -51,8 +51,8 @@ class Translation {
         return this->key()==translation->key();
     }
 
-    //! \return parsed raw format into html
-    virtual QString toHtml() const = 0;
+    //! \return parsed raw format into xml
+    virtual QString toXml() const = 0;
 
     //! \return whether given translation is taken from bookmarks
     virtual int isBookmark() const {
index 3b31871..286a7af 100644 (file)
@@ -50,8 +50,8 @@ public:
         return _key;
     }
 
-    //! \return parsed raw format into html
-    QString toHtml() const {
+    //! \return parsed raw format into xml
+    QString toXml() const {
         if(!_key.size() || !_bookmarks)
             return "";
 
index 5583368..a2f55c8 100644 (file)
@@ -66,7 +66,7 @@ void Bookmarks::add(Translation* translation) {
     cur.prepare("insert into bookmarks values (?,?,?)");
     cur.addBindValue(translation->key());
     cur.addBindValue(removeAccents(translation->key()));
-    cur.addBindValue(translation->toHtml());
+    cur.addBindValue(translation->toXml());
     cur.exec();
 }
 
index 370f42f..74e4721 100644 (file)
@@ -80,7 +80,7 @@ public:
     QList<Translation*> searchWordList(QString word);
 
     /*! Searches for final translation of a given word
-      \return word translation list in text format xml or html to be formatted
+      \return word translation list in text format xml to be formatted
         and displayed
       \param word word to search for
       */
index 3d4fc54..154abfa 100644 (file)
@@ -34,7 +34,6 @@ History::History(int maxSize, QObject *parent) :
     _listAvailable = false;
 }
 
-
 void History::setMaxSize(int size) {
     if(maxSize() <= 0) return;
     if(size > _maxSize) {
index 356c701..c754c52 100644 (file)
@@ -63,7 +63,7 @@ public:
     /*! \return translation text for corresponding Translation object */
     QString toHtml() const {
         QString trans;
-        trans = _tr->toHtml();
+        trans = _tr->toXml();
         return trans;
 
     }
@@ -91,8 +91,8 @@ void Backbone::init() {
    loadDicts(_configPath);
 
    connect(&_resultWatcher, SIGNAL(finished()), this, SLOT(translationReady()));
-   connect(&_htmlResultWatcher, SIGNAL(finished()), this,
-           SLOT(htmlTranslationReady()));
+   connect(&_xmlResultWatcher, SIGNAL(finished()), this,
+           SLOT(xmlTranslationReady()));
    connect(&_bookmarkWatcher, SIGNAL(finished()), this,
            SLOT(bookmarksListReady()));
    connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this,
@@ -192,7 +192,7 @@ void Backbone::stopSearching() {
     foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
     stopped = true;
-    _innerHtmlResult.cancel();
+    _innerXmlResult.cancel();
     _innerResult.cancel();
     Q_EMIT searchCanceled();
 }
@@ -510,25 +510,20 @@ void Backbone::saveState(QSettings* set, Settings* plugSet, bool active
 
 
 
-QStringList Backbone::htmls() {
-    return _htmlResult;
+QStringList Backbone::xmls() {
+    return _xmlResult;
 }
 
 
 
-void Backbone::searchHtml(QList<Translation *> translations) {
-    _htmlResult.clear();
+void Backbone::searchXml(QList<Translation *> translations) {
+    _xmlResult.clear();
 
     QList<TranslationPtr> dummy;
     stopped = false;
     foreach(Translation* tr, translations) {
          if(containsDict(tr->dict()) || !tr->dict())
             dummy.append(TranslationPtr(tr));
-  /*      foreach(CommonDictInterface* dict, activeDicts()) {
-            Translation* trans = dict->getTranslationFor(tr->key());
-            if(trans)
-                dummy.append(TranslationPtr(trans));
-        } */
     }
     if(translations.size()>0) {
         Translation *tr = translations.at(0);
@@ -539,24 +534,24 @@ void Backbone::searchHtml(QList<Translation *> translations) {
         }
     }
 
-   _innerHtmlResult = QtConcurrent::mapped(dummy,
+   _innerXmlResult = QtConcurrent::mapped(dummy,
                                             &TranslationPtr::toHtml);
-   _htmlResultWatcher.setFuture(_innerHtmlResult);
+   _xmlResultWatcher.setFuture(_innerXmlResult);
 }
 
 
 
-void Backbone::htmlTranslationReady() {
+void Backbone::xmlTranslationReady() {
 
-    QFutureIterator<QString> it(_innerHtmlResult);
+    QFutureIterator<QString> it(_innerXmlResult);
     QSet<QString> uniqe;
     while(it.hasNext())
         uniqe.insert(it.next());
-    _htmlResult.clear();
-    _htmlResult = uniqe.toList();
+    _xmlResult.clear();
+    _xmlResult = uniqe.toList();
 
     if(!stopped)
-        Q_EMIT htmlReady();
+        Q_EMIT xmlReady();
 
 }
 
index 66ebea4..be84df7 100644 (file)
         - GUI calls result()
 
       Final translation:
-         - GUI calls searchHtml()
-         - Backbone starts toHtml for each translation object 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
@@ -130,8 +130,8 @@ public:
     //! \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
@@ -173,7 +173,7 @@ public Q_SLOTS:
     /*! Fired by FutureWatcher when search result is ready, fetch Future to
         final result
       */
-    void htmlTranslationReady();
+    void xmlTranslationReady();
 
     /*! Removes a given dictionary
         \param dict dictionary to be deleted
@@ -183,10 +183,10 @@ public Q_SLOTS:
     /*! Saves plugins new state/configuration after each change */
     void dictUpdated();
 
-    /*! Performs search for final translation (html/xml) from a list
+    /*! 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
@@ -260,8 +260,8 @@ Q_SIGNALS:
     //! 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();
@@ -286,13 +286,13 @@ private:
 
 
     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
 
 
@@ -300,7 +300,7 @@ private:
     QFutureWatcher<QList<Translation*> > _resultWatcher;
     QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
     QFutureWatcher<QList<Translation*> > _bookmarkSearchWatcher;
-    QFutureWatcher<QString> _htmlResultWatcher;
+    QFutureWatcher<QString> _xmlResultWatcher;
 
 
     QString _pluginPath;
index c7356f8..4cade09 100644 (file)
@@ -254,7 +254,7 @@ void MainWindow::translationsReady() {
         hideWelcomeScreen();
     #endif
 
-    Q_EMIT showTranslation(backbone->htmls());
+    Q_EMIT showTranslation(backbone->xmls());
     #ifdef Q_WS_MAEMO_5
         notifyManager->screenChanged();
     #endif
@@ -416,7 +416,7 @@ void MainWindow::connectBackbone() {
             backbone, SLOT(search(QString)));
 
     connect(this, SIGNAL(searchTranslations(QList<Translation*>)),
-            backbone, SLOT(searchHtml(QList<Translation*>)));
+            backbone, SLOT(searchXml(QList<Translation*>)));
 
     connect(this, SIGNAL(stopSearching()),
             backbone, SLOT(stopSearching()));
@@ -437,14 +437,14 @@ void MainWindow::connectBackbone() {
     connect(backbone, SIGNAL(ready()),
             this, SIGNAL(setIdle()));
 
-    connect(backbone, SIGNAL(htmlReady()),
+    connect(backbone, SIGNAL(xmlReady()),
             this, SIGNAL(setIdle()));
 
 
     connect(backbone, SIGNAL(ready()),
             this, SLOT(wordListReady()));
 
-    connect(backbone, SIGNAL(htmlReady()),
+    connect(backbone, SIGNAL(xmlReady()),
             this, SLOT(translationsReady()));
 
     connect(backbone, SIGNAL(searchCanceled()),
index a051c22..9e3e36c 100644 (file)
@@ -36,7 +36,7 @@
 
 //! Displays translation of a word found in dictionaries
 /*!
-    Displays many translations of word, formatted as html.
+    Displays many translations of word, formatted as xml.
 */
 class TranslationWidget : public QScrollArea {
     Q_OBJECT
index 9b00ee6..16d931f 100644 (file)
@@ -106,15 +106,19 @@ void GoogleDialog::initializeUI() {
     langToComboBox = new QComboBox;
 
     int i=0;
+    int j=0;
     int actualLangTo=0;
     int actualLangFrom=0;
 
     foreach(QString langs, GooglePlugin::languages.keys()){
         if(langs==_langTo)
-            actualLangTo=i;
+            actualLangTo=j;
         if(langs==_langFrom)
             actualLangFrom=i;
-        langToComboBox->addItem(langs);
+        if(langs!="Detect langlage"){
+            langToComboBox->addItem(langs);
+            j++;
+        }
         langFromComboBox->addItem(langs);
         i++;
     }
index d8f65b3..01097bb 100644 (file)
@@ -62,7 +62,7 @@ public:
     //! \returns dictionary type (xdxf, google translate, etc)
     QString type() const;
 
-    //! \returns information about dictionary in html (name, authors, etc)
+    //! returns information about dictionary (name, authors, etc)
     QString infoNote() const;
 
     //! sets the language to which the translation is done
index 52c0778..f0355e7 100644 (file)
@@ -47,7 +47,7 @@ QString TranslationGoogle::key() const{
     return _key;
 }
 
-QString TranslationGoogle::toHtml() const {
+QString TranslationGoogle::toXml() const {
     QString result("");
     if(!googlePlugin)
         return result;   
@@ -57,12 +57,15 @@ QString TranslationGoogle::toHtml() const {
     else
         result+="bookmark=\"false\" >";
 
+    //qDebug()<<"trans: "<<_trans;
+
     if(_trans!="")
         return result+=_dictionaryInfo+ "</info>"+_trans +"</dict>";
 
     QList<Translation*> translations=googlePlugin->searchWordList(_key);
+    //qDebug()<<"test: "<<translations.size();
     if(translations.size()>0 && translations.at(0))
-        return translations.at(0)->toHtml();
+        return translations.at(0)->toXml();
     return "";
 
 }
index 51bbe04..5ce1f76 100644 (file)
@@ -42,8 +42,8 @@ public:
     //! \return word to be translated
     QString key() const;
 
-    //! \return parsed raw format into html
-    QString toHtml() const;
+    //! \return parsed raw format into xml
+    QString toXml() const;
 
     /*! sets the word for which we want to find a translation
         \param word for which we want to find a translation */
index 394ab81..fe228b5 100644 (file)
@@ -43,7 +43,7 @@ QString TranslationXdxf::key() const {
     return _key;
 }
 
-QString TranslationXdxf::toHtml() const { 
+QString TranslationXdxf::toXml() const { 
     QString result("");
     if(!xdxfPlugin)
         return result;
index 42d504a..e438bbc 100644 (file)
@@ -38,8 +38,8 @@ public:
     //! \return word to be translated
     QString key() const;
 
-    //! \return parsed raw format into html
-    QString toHtml() const;
+    //! \return parsed raw format into xml
+    QString toXml() const;
 
     /*! sets the word for which we want to find a translation
         \param word for which we want to find a translation */
index 3f39521..ee8ee03 100644 (file)
@@ -99,7 +99,6 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
 
 
 QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
-    int i=0;
     QSet<Translation*> translations;
     QString cacheFilePath = _settings->value("cache_path");
 
@@ -130,21 +129,10 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         cur.addBindValue(limit);
     cur.exec();
 
-    bool in = false;
-    while(cur.next() && (i<limit || limit==0 ) ) {
-        in = true;
-        bool ok=true;
-        Translation *tran;
-        foreach(tran,translations) {
-            if(tran->key().toLower()==cur.value(0).toString().toLower())
-                    ok=false;
-        }
-        if(ok) {  /*add key word to list*/
-            translations.insert(new TranslationXdxf(
-                    cur.value(0).toString().toLower(),
-                    _dictionaryInfo, this));
-            i++;
-        }
+    while(cur.next() && (translations.size()<limit || limit==0)) {
+       translations.insert(new TranslationXdxf(
+            cur.value(0).toString(),
+            _dictionaryInfo, this));
     }
     db.close();
     return translations.toList();
@@ -184,19 +172,11 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
                 readKey = reader.readElementText();
             if((regWord.exactMatch(readKey)
                     || regWord.exactMatch(removeAccents(readKey)))
-                    && (i<limit || limit==0)) {
-                bool ok=true;
-                Translation *tran;
-                foreach(tran,translations) {
-                    if(tran->key().toLower()==readKey.toLower())
-                        ok=false; /*if key is in the dictionary more that one */
-                }
-                if(ok) {  /*add key word to list*/
-                    translations<<(new TranslationXdxf(readKey.toLower(),
-                                    _dictionaryInfo,this));
-                    i++;
-                }
-                if(i>=limit && limit!=0)
+                    && (i<limit || limit==0) && !reader.atEnd())  {
+ //               qDebug()<<readKey;
+                translations<<(new TranslationXdxf(readKey.toLower(),
+                               _dictionaryInfo,this));
+                if(translations.size()==limit && limit!=0)
                     break;
             }
         }
@@ -308,6 +288,7 @@ QString XdxfPlugin::searchFile(QString key) {
 
 
 void XdxfPlugin::stop() {
+   //qDebug()<<"stop";
     stopped=true;
 }
 
@@ -441,9 +422,13 @@ bool XdxfPlugin::getDictionaryInfo() {
     reader.readNextStartElement();
     if(reader.name()=="full_name")
         _name=reader.readElementText();
+    else
+        qDebug()<<"no full_name";
     reader.readNextStartElement();
     if(reader.name()=="description")
         _infoNote=reader.readElementText();
+    else
+        qDebug()<<"no description";
 
     _dictionaryInfo= _name + " [" + _langFrom + "-"
                 + _langTo + "]";
@@ -494,11 +479,10 @@ bool XdxfPlugin::makeCache(QString) {
 
     XdxfCachingDialog d(_dictDialog->lastDialogParent());
 
-    qDebug()<<_dictDialog->lastDialogParent();
+//    qDebug()<<_dictDialog->lastDialogParent();
 
     connect(&d, SIGNAL(cancelCaching()),
             this, SLOT(stop()));
-
     connect(this, SIGNAL(updateCachingProgress(int,int)),
             &d, SLOT(updateCachingProgress(int,int)));
 
@@ -598,8 +582,8 @@ bool XdxfPlugin::makeCache(QString) {
             temp="<key>" + readKey + "</key>" + "<t>" + temp+ "</t>";
             match=false;
             cur.prepare("insert into dict values(?,?,?)");
-            cur.addBindValue(readKey);
-            cur.addBindValue(removeAccents(readKey));
+            cur.addBindValue(readKey.toLower());
+            cur.addBindValue(removeAccents(readKey).toLower());
             cur.addBindValue(temp);
             cur.exec();
             counter++;
@@ -620,24 +604,24 @@ bool XdxfPlugin::makeCache(QString) {
         Q_EMIT notify(Notify::Warning,
                 QString(tr("Database caching error, please try again.")));
         db.close();
+        _settings->setValue("cache_path", cachePathN);
+        if(stopped)
+            clean();
+        _settings->setValue("cache_path","");
         return false;
     }
 
     _settings->setValue("cache_path", cachePathN);
     _settings->setValue("cached", "true");
 
-
     disconnect(&d, SIGNAL(cancelCaching()),
             this, SLOT(stop()));
-
     disconnect(this, SIGNAL(updateCachingProgress(int,int)),
             &d, SLOT(updateCachingProgress(int,int)));
-
     db.close();
     return true;
 }
 
-
 void XdxfPlugin::clean() {
     if(QFile::exists(_settings->value("cache_path"))) {
         QFile(_settings->value("cache_path")).remove();
index 555b7a1..334a506 100644 (file)
@@ -36,6 +36,7 @@
 #include <QFile>
 #include <QXmlStreamReader>
 #include <QtPlugin>
+#include <QHash>
 
 #include "../../include/CommonDictInterface.h"
 #include "../../include/settings.h"
@@ -66,7 +67,7 @@ public:
     //! \returns dictionary type (xdxf, google translate, etc)
     QString type() const;
 
-    //! \returns information about dictionary in html (name, authors, etc)
+    //! returns information about dictionary in xml (name, authors, etc)
     QString infoNote() const;
 
     /*! \returns DictDialog object that creates dialogs
index 33c891a..65372eb 100644 (file)
@@ -17,13 +17,16 @@ HEADERS += test.h \
     ../../src/include/CommonDictInterface.h \
     ../../src/plugins/google/TranslationGoogle.h \
     ../../src/plugins/google/GoogleDictDialog.h \
-    ../../src/plugins/google/GoogleSettingsDialog.h
+    ../../src/plugins/google/GoogleDialog.h
 
 SOURCES += test.cpp \
     ../../src/plugins/google/GooglePlugin.cpp \
     ../../src/plugins/google/TranslationGoogle.cpp \
     ../../src/plugins/google/GoogleDictDialog.cpp \
-    ../../src/plugins/google/GoogleSettingsDialog.cpp
+    ../../src/plugins/google/GoogleDialog.cpp
+
+
+
 
 target.path = .
 target.commands = ./GooglePluginTests
index 20a518e..5e9a287 100644 (file)
@@ -24,6 +24,9 @@
 
 #include <QtTest/QtTest>
 #include "../../src/plugins/google/GooglePlugin.h"
+#include "../../src/plugins/google/TranslationGoogle.h"
+#include "../../src/plugins/google/GoogleDictDialog.h"
+#include "../../src/plugins/google/GoogleDialog.h"
 
 
  class GoogleTest: public QObject
index 8375447..b3c42f2 100644 (file)
@@ -17,18 +17,17 @@ HEADERS += test.h \
     ../../src/include/DictDialog.h \
     ../../src/include/CommonDictInterface.h \
     ../../src/plugins/xdxf/XdxfDictDialog.h \
-    ../../src/plugins/xdxf/XdxfLoadDialog.h \
-    ../../src/plugins/xdxf/XdxfSettingsDialog.h \
+    ../../src/plugins/xdxf/XdxfDialog.h \
     ../../src/plugins/xdxf/XdxfCachingDialog.h
 
 
 SOURCES += test.cpp \
     ../../src/plugins/xdxf/xdxfplugin.cpp \
     ../../src/plugins/xdxf/TranslationXdxf.cpp \
-    ../../src/plugins/xdxf/XdxfLoadDialog.cpp \
+    ../../src/plugins/xdxf/XdxfDialog.cpp \
     ../../src/plugins/xdxf/XdxfDictDialog.cpp \
     ../../src/plugins/xdxf/XdxfCachingDialog.cpp \
-    ../../src/plugins/xdxf/XdxfSettingsDialog.cpp
+
 
 target.path = .
 target.commands = ./xdxfPluginTests
index b6f4b70..c55ed80 100644 (file)
@@ -161,8 +161,11 @@ void XdxfTest::searchWordListFile() {
     QList<Translation*> te4 = xdxfPlugin->searchWordList("ho*SE", 10);
         QCOMPARE(te4.at(0)->key(), QString("house"));
 
+    qDebug()<<"\n\n\n";
     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
-        QCOMPARE(te5.size(), 9);
+    qDebug()<<"\n\n\n";
+    QCOMPARE(te5.size(), 9);
+
 
     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
         QCOMPARE(te6.size(), 8);
index d38a552..a16cf5f 100644 (file)
 class TranslationMock : public Translation
 {
 public:
+
+    ~TranslationMock () {}
     QString _key, _translation;
     QString key() const {return _key;}
-    QString toHtml() const {return _translation;}
+    QString toXml() const {return _translation;}
 };
 
 #endif // TRANSLATIONMOCK_H