Merge branch 'xdxf'
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Fri, 6 Aug 2010 06:37:32 +0000 (08:37 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Fri, 6 Aug 2010 06:37:32 +0000 (08:37 +0200)
Conflicts:
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

trunk/src/base/gui/TranslationWidget.cpp
trunk/src/plugins/xdxf/src/TranslationXdxf.cpp
trunk/src/plugins/xdxf/src/TranslationXdxf.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.h
trunk/src/plugins/xdxf/tests/test.cpp
trunk/src/plugins/xdxf/tests/test.h

index 89aba5b..658426f 100644 (file)
@@ -29,6 +29,7 @@ TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
 
     this->backbone = backbone;
 
+
     #ifdef Q_WS_MAEMO_5
         setAttribute(Qt::WA_Maemo5StackedWindow);
     #endif
index c2bb1a7..0c3fcfb 100644 (file)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
 #include "TranslationXdxf.h"
 
 
index 0c65eb4..a691d9a 100644 (file)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
 #ifndef TRANSLATIONXDXF_H
 #define TRANSLATIONXDXF_H
 
index c1c161f..98cf0d3 100644 (file)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
 #include "xdxfplugin.h"
 #include <QDebug>
 #include <QFile>
 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
                     _type(tr("xdxf")), _infoNote(tr("")) {
-    path="dict.xdxf";
-    stopped = false;
     _settings = new Settings();
     _dictDialog = new XdxfDictDialog(this);
+    _settings->setValue("type","xdxf");
+    if(isCached())
+        _settings->setValue("Cached","true");
+    else
+        _settings->setValue("Cached","false");
+    setPath("dict.xdxf");
+    stopped = false;
+
 }
 
-QString XdxfPlugin::langFrom() const {
-    return  _langFrom;
+QString XdxfPlugin::langFrom() const {   
+    return _langFrom;
 }
 
 QString XdxfPlugin::langTo() const {
@@ -28,6 +55,7 @@ QString XdxfPlugin::name() const {
 }
 
 QString XdxfPlugin::type() const {
+//    return _settings->value("type");
     return _type;
 }
 
@@ -35,18 +63,22 @@ QString XdxfPlugin::infoNote() const {
     return  _infoNote;
 }
 
-QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
+QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) { 
+    QSet<Translation*> translations;
+    QFile dictionaryFile(path);
+
     stopped = false;
+    if(word.indexOf("*")==-1)
+        word+="*";
     QRegExp regWord(word);
     regWord.setCaseSensitivity(Qt::CaseInsensitive);
     regWord.setPatternSyntax(QRegExp::Wildcard);
-
-    QList<Translation*> translations;
-    QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
-        return translations;
+        return translations.toList();
     }
+
+    /*read information about dictionary*/
     QXmlStreamReader dictionaryReader(&dictionaryFile);
     dictionaryReader.readNextStartElement();
     if(dictionaryReader.name()=="xdxf") {
@@ -61,6 +93,8 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
     dictionaryReader.readNextStartElement();
     if(dictionaryReader.name()=="description")
         _infoNote=dictionaryReader.readElementText();
+
+    /*search words list*/
     QString a;
     int i=0;
     while(!dictionaryReader.atEnd() && !stopped){
@@ -68,22 +102,32 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
         if(dictionaryReader.name()=="ar"){
             while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
                 dictionaryReader.readNextStartElement();
-           a = dictionaryReader.readElementText();
-           if(regWord.exactMatch(a) && i<limit) {
-                translations.append(new TranslationXdxf(a,_infoNote,this));
+            if(!dictionaryReader.atEnd())
+                a = dictionaryReader.readElementText();
+            if(regWord.exactMatch(a) && i<limit) {
+                bool ok=true;
+                Translation *tran;
+                foreach(tran,translations)
+                {
+                    if(tran->key()==a)
+                        ok=false;  /*if key word is in the dictionary more that one */
+                }
+                if(ok)  /*add key word to list*/
+                    translations<<(new TranslationXdxf(a,_infoNote,this));
                 i++;
-                if(i>=limit)
+                if(i>=limit && limit!=0)
                     break;
             }
         }
     }
     stopped=false;
     dictionaryFile.close();
-    return translations;
+    return translations.toList();
 }
 
 QString XdxfPlugin::search(QString key) {
     QFile dictionaryFile(path);
+    QString resultString("");
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
         return "";
@@ -103,13 +147,21 @@ QString XdxfPlugin::search(QString key) {
         }
         else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)  {
             if(match) {
-              QString temp(dictionaryReader.text().toString().replace("\n",""));
-              dictionaryFile.close();
-              return temp;
+                QString temp(dictionaryReader.text().toString());
+                temp.replace("\n","");
+                if(temp == ""){
+                    while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()){
+                        dictionaryReader.readNext();
+                        temp+=dictionaryReader.text().toString();
+                    }
+                }
+                resultString+=temp.replace("\n","");
+                match=false;
             }
         }
     }
-    return "";
+    dictionaryFile.close();
+    return resultString;
 }
 
 void XdxfPlugin::stop() {
@@ -120,9 +172,16 @@ DictDialog* XdxfPlugin::dictDialog() {
      return _dictDialog;
 }
 
+void XdxfPlugin::setPath(QString path){
+    this->path=path;
+    _settings->setValue("path",path);
+}
+
 
-CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
-  return new XdxfPlugin();
+CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
+    XdxfPlugin *plugin = new XdxfPlugin();
+    plugin->setPath(settings->value("path"));
+    return  new XdxfPlugin();//plugin;
 }
 
 bool XdxfPlugin::isAvailable() const {
@@ -143,4 +202,9 @@ Settings* XdxfPlugin::settings() {
     return _settings;
 }
 
+bool XdxfPlugin::isCached()
+{
+    return false;
+}
+
 Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
index f1f1e1a..ce2dbca 100644 (file)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
 #ifndef XDXFPLUGIN_H
 #define XDXFPLUGIN_H
 
@@ -71,6 +92,7 @@ public Q_SLOTS:
 
 private:
     bool isCached();
+    void setPath(QString);
     QString _langFrom;
     QString _langTo;
     QString _name;
index 4bba1f5..c5d5337 100644 (file)
@@ -1,42 +1,49 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
 #include "test.h"
 #include <QSignalSpy>
 
 void Testowanie::search()
 {
     XdxfPlugin xdxfPlugin(this);
-    xdxfPlugin.loadDialog();
-    xdxfPlugin.searchWordList("Cain",10);
-    xdxfPlugin.search("Cain");
-    QCOMPARE(xdxfPlugin.search("Apacz"), QString("Apachee"));
- //   QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
- //   QCOMPARE(xdxfPlugin.search("boss"), QString(""));
-}
-
-void Testowanie::langFrom()
-{
-    XdxfPlugin xdxfPlugin(this);
-    xdxfPlugin.loadDialog();
-    xdxfPlugin.searchWordList("rope",10);
-    QCOMPARE(xdxfPlugin.langFrom(), QString("ENG"));
+    xdxfPlugin.search("wino");
+//   QCOMPARE(xdxfPlugin.search("afera"), QString("scam"));
+//   QCOMPARE(xdxfPlugin.search("grzech"), QString("sin"));
+    QCOMPARE(xdxfPlugin.search("Advent"), QString("Adwent"));
 }
 
-void Testowanie::hash()
+void Testowanie::searchWordList()
 {
     XdxfPlugin xdxfPlugin(this);
-    xdxfPlugin.loadDialog();
-    xdxfPlugin.hash();
+    QList<Translation*> te=xdxfPlugin.searchWordList("Adventeee",10);
+    if(te.size()>0)
+        QCOMPARE(te.at(0)->key(), QString("Advent"));
 }
 
-void Testowanie::sig()
+void Testowanie::langFrom()
 {
     XdxfPlugin xdxfPlugin(this);
-    xdxfPlugin.loadDialog();
-
-    QSignalSpy spy(&xdxfPlugin, SIGNAL(finalTranslation()));
-
-    xdxfPlugin.searchWordList("Apacz",10);
-
-    QCOMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
+    xdxfPlugin.searchWordList("rope",10);
+    QCOMPARE(xdxfPlugin.langFrom(), QString("POL"));
 }
 
 QTEST_MAIN(Testowanie)
index 389c754..45c5fd1 100644 (file)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
 #ifndef TEST_H
 #define TEST_H
 
@@ -16,9 +37,8 @@
 
  private slots:
      void search();
+     void searchWordList();
      void langFrom();
-     void sig();
-     void hash();
  };