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

29 files changed:
make-plugins [new file with mode: 0755]
trunk/src/base/backbone/backbone.cpp
trunk/src/base/backbone/backbone.h
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/TranslationWidget.h
trunk/src/base/gui/WordListWidget.cpp
trunk/src/includes/DictDialog.h
trunk/src/plugins/xdxf/src/TranslationXdxf.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/src/TranslationXdxf.h [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfDictDialog.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfDictDialog.h [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfLoadDialog.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfLoadDialog.h [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfPlugin.pro [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfPlugin/TranslationXdxf.cpp [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/TranslationXdxf.h [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp [deleted file]
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h [deleted file]
trunk/src/plugins/xdxf/src/xdxfplugin.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/src/xdxfplugin.h [new file with mode: 0644]
trunk/tests/mDictionaryTests/CommonDictInterfaceMock.h
trunk/tests/mDictionaryTests/tst_Backbone.cpp

diff --git a/make-plugins b/make-plugins
new file mode 100755 (executable)
index 0000000..40377d1
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+path="trunk/src/plugins/"
+pushd $path
+
+for pro in  *; do
+    if [ -d "$pro" ] ; then  
+            pushd $pro/src/
+           qmake *.pro
+           make clean
+           make
+            mv `find . -name "*.so.*" -type f` "../../../base/$pro.so"
+            popd
+    fi
+done
+popd
+    
index 9be3804..f0251c5 100644 (file)
 
 #include "backbone.h"
 #include <QDebug>
+
+void Backbone::init() {
+   _searchLimit = 10;
+   _interval = 250; //msec
+   loadPlugins();
+   if(!connect(&_timer, SIGNAL(timeout()), this, SLOT(translation())))
+       qDebug() << "Timer signal not connected";
+}
+
 Backbone::Backbone(QObject *parent)
     : QObject(parent)
 {
-   searchLimitv = 10;
-   loadPlugins();
+    init();
 }
 
 
 
 Backbone::~Backbone()
 {
-    QListIterator<CommonDictInterface*> it(dicts.keys());
+    QListIterator<CommonDictInterface*> it(_dicts.keys());
 
     while(it.hasNext())
         delete it.next();
 
-    it = QListIterator<CommonDictInterface*>(plugins);
+    it = QListIterator<CommonDictInterface*>(_plugins);
     while(it.hasNext())
         delete it.next();
 
@@ -53,31 +61,32 @@ Backbone::~Backbone()
 
 
 Backbone::Backbone(const Backbone &b) :QObject(b.parent()) {
-    dicts = QHash<CommonDictInterface*, bool > (b.dicts);
-    plugins = QList<CommonDictInterface* > (b.plugins);
+    init();
+    _dicts = QHash<CommonDictInterface*, bool > (b._dicts);
+    _plugins = QList<CommonDictInterface* > (b._plugins);
     _result = QHash<QString, Translation* > (b._result);
-    searchLimitv = b.searchLimit();
+    _searchLimit = b.searchLimit();
 }
 
 
 
 
 int Backbone::searchLimit() const {
-    return searchLimitv;
+    return _searchLimit;
 }
 
 
 
 
 QHash<CommonDictInterface*, bool > Backbone::getDictionaries() {
-    return dicts;
+    return _dicts;
 }
 
 
 
 
 QList<CommonDictInterface* > Backbone::getPlugins() {
-    return plugins;
+    return _plugins;
 }
 
 
@@ -98,7 +107,9 @@ QMultiHash<QString, Translation*> Backbone::result() {
 
 
 void Backbone::stopSearching() {
-    foreach(CommonDictInterface* dict, dicts.keys())
+    _timer.stop();
+    _innerResult.clear();
+    foreach(CommonDictInterface* dict, _dicts.keys())
         dict->stop();
 }
 
@@ -107,40 +118,39 @@ void Backbone::stopSearching() {
 
 void Backbone::search(QString word) {
     //TODO add running searches in new threads
+    _timer.stop();
     _result.clear();
-    activeSearchNum = 0;
-    foreach(CommonDictInterface* dict, dicts.keys())
-        if(dicts[dict] == 1) {
-            activeSearchNum ++;
+    _innerResult.clear();
+
+    _timer.start(_interval);
+    foreach(CommonDictInterface* dict, _dicts.keys())
+        if(_dicts[dict] == 1) {
+            QFuture<QList<Translation*> > tr =
+                    QtConcurrent::run(dict,
+                                      &CommonDictInterface::searchWordList,word,
+                                                             searchLimit());
+            _innerResult.append(tr);
         }
 
-    foreach(CommonDictInterface* dict, dicts.keys())
-        if(dicts[dict] == 1) {
-            translation(dict->searchWordList(word, searchLimit()));
-        }
 }
 
 
 
 
  void Backbone::selectedDictionaries(QList<CommonDictInterface* > activeDicts) {
-     foreach(CommonDictInterface* dict, dicts.keys())
+     foreach(CommonDictInterface* dict, _dicts.keys())
          if(activeDicts.contains(dict))
-             dicts[dict] = 1;
+             _dicts[dict] = 1;
          else
-             dicts[dict] = 0;
+             _dicts[dict] = 0;
  }
 
 
 
 
  void Backbone::addDictionary(CommonDictInterface* dict) {
-     dicts[dict] = 1;
-
-     //connect(dict, SIGNAL(finalTranslation()),
-      //       this, SLOT(translation()),
-      //       Qt::UniqueConnection);
-
+     dict->setHash(_dicts.size()+1);
+     _dicts[dict] = 1;
  }
 
 
@@ -153,21 +163,24 @@ void Backbone::search(QString word) {
 
 
 int Backbone::activeSearches() const {
-    return activeSearchNum;
+    return _innerResult.size();
 }
 
 
 
-void Backbone::translation(QList<Translation *> trans) {
-    activeSearchNum--;
-    foreach(Translation* t, trans)
-    {
-        _result.insert(t->key(), t);
-        qDebug()<<t->key();
+void Backbone::translation() {
+    foreach(QFuture<QList<Translation*> > trans, _innerResult) {
+        if(!trans.isFinished())
+            continue;
+        QList<Translation*> tList = trans.result();
+        foreach(Translation* t, tList)
+            _result.insert(t->key(), t);
+        _innerResult.removeOne(trans);
     }
-
-    if(activeSearchNum < 1)
+    if(!_innerResult.size()) {
+        _timer.stop();
         Q_EMIT ready();
+    }
 }
 
 
@@ -175,8 +188,7 @@ void Backbone::translation(QList<Translation *> trans) {
 
 void Backbone::loadPlugins() {
     QPluginLoader loader("xdxf.so");
-    if(!loader.load())
-    {
+    if(!loader.load()) {
         qDebug()<<loader.errorString();
         return;
     }
@@ -184,8 +196,8 @@ void Backbone::loadPlugins() {
 
     qDebug()<<"loaded";
     CommonDictInterface *plugin = qobject_cast<CommonDictInterface*>(pl);
-    plugins.append(plugin);
-    addDictionary(plugin);
+    _plugins.append(plugin);
+    addDictionary(plugin->getNew(0)); //TODO change 0 to real settings
 }
 
 
index 76dff08..fa4cba8 100644 (file)
 #include <QList>
 #include <QHash>
 #include <QPluginLoader>
+#include <QFuture>
+#include <QtConcurrentRun>
+#include <QTimer>
+#include <QTime>
 #include "../../includes/CommonDictInterface.h"
 #include "../../includes/settings.h"
 #include "../../includes/translation.h"
@@ -80,7 +84,7 @@ public Q_SLOTS:
 
 
     //! Fired when dictionary call finalTranslation(..) with translation ready
-    void translation(QList<Translation*>);
+    void translation();
 
     // TODO void removeDictionary(CommonDictInterface* dict);
     // TODO addToBookmark(Translation*);
@@ -98,11 +102,17 @@ Q_SIGNALS:
 
 private:
     void loadPlugins(); //< locate and load plugins
-    QHash<CommonDictInterface*, bool> dicts;
-    QList<CommonDictInterface*> plugins;
+    QHash<CommonDictInterface*, bool> _dicts;
+    QList<CommonDictInterface*> _plugins;
+    QList<QFuture<QList<Translation*> > > _innerResult;
     QMultiHash<QString, Translation*> _result;
-    int searchLimitv;
-    int activeSearchNum;
+    QTimer _timer;
+    int _searchLimit;
+    int _activeSearchNum;
+    QTime _time;
+    int _interval; //Search fetching timer.timeout interval in msec
+
+    void init();
 
 };
 
index 35675d7..53a2eb6 100644 (file)
@@ -31,7 +31,10 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     this->backbone = backbone;
 
     ui->setupUi(this);
-    //setAttribute(Qt::WA_Maemo5StackedWindow);
+
+    #ifdef Q_WS_MAEMO_5
+        setAttribute(Qt::WA_Maemo5StackedWindow);
+    #endif
 
     searchBarWidget = new SearchBarWidget(backbone);
     wordListWidget = new WordListWidget(backbone);
index 4009da1..a73e6d4 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "SearchBarWidget.h"
 #include <QDebug>
-
+#include "../../includes/DictDialog.h"
 
 
 SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
@@ -88,7 +88,7 @@ void SearchBarWidget::initializeUI() {
 
 
     clearSearchWordToolButton = new QToolButton();
-    clearSearchWordToolButton->setIcon(QIcon("sowa.svg"));
+    clearSearchWordToolButton->setIcon(QIcon::fromTheme("gtk-delete"));
     //tool buttons will have size 2 times smaller
     clearSearchWordToolButton->setMaximumSize(
             clearSearchWordToolButton->sizeHint().width()/2,
@@ -96,21 +96,21 @@ void SearchBarWidget::initializeUI() {
 
 
     historyNextToolButton = new QToolButton();
-    historyNextToolButton->setIcon(QIcon("sowa.svg"));
+    historyNextToolButton->setIcon(QIcon::fromTheme("gtk-go-forward"));
     historyNextToolButton->setMaximumSize(
             historyNextToolButton->sizeHint().width()/2,
             historyNextToolButton->sizeHint().height()/2);
 
 
     historyPrevToolButton = new QToolButton();
-    historyPrevToolButton->setIcon(QIcon("sowa.svg"));
+    historyPrevToolButton->setIcon(QIcon::fromTheme("gtk-go-back"));
     historyPrevToolButton->setMaximumSize(
             historyPrevToolButton->sizeHint().width()/2,
             historyPrevToolButton->sizeHint().height()/2);
 
 
     historyShowToolButton = new QToolButton();
-    historyShowToolButton->setIcon(QIcon("sowa.svg"));
+    historyShowToolButton->setIcon(QIcon::fromTheme("gtk-go-up"));
     historyShowToolButton->setMaximumSize(
             historyShowToolButton->sizeHint().width()/2,
             historyShowToolButton->sizeHint().height()/2);
@@ -179,6 +179,8 @@ void SearchBarWidget::searchFinished() {
 
 void SearchBarWidget::historyNextToolButtonClicked() {
 
+    CommonDictInterface*p = backbone->getPlugins()[0];
+    p->dictDialog()->addNewDictionary(this);
 }
 
 void SearchBarWidget::historyPrevToolButtonClicked() {
index 0fd0042..658426f 100644 (file)
 #include <QDebug>
 
 TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
-    QWidget(parent) {
+    QTextEdit(parent) {
 
     this->backbone = backbone;
 
-    //setAttribute(Qt::WA_Maemo5StackedWindow);
+
+    #ifdef Q_WS_MAEMO_5
+        setAttribute(Qt::WA_Maemo5StackedWindow);
+    #endif
     setWindowFlags(windowFlags() | Qt::Window);
 
+    setContextMenuPolicy(Qt::CustomContextMenu);
+
+    setReadOnly(true);
+
+    connect(this, SIGNAL(customContextMenuRequested(QPoint)),
+            this, SLOT(showContextMenu(QPoint)));
+
     initializeUI();
 }
 
 void TranslationWidget::show(QModelIndex index) {
     QWidget::show();
+    clear();
     QString v = index.model()->data(index, Qt::DisplayRole).toString();
     Translation* t = backbone->result().value(v);
-    translationTextEdit->setText(t->toHtml());
+    setText(t->toHtml());
+    update();
 }
 
 void TranslationWidget::initializeUI() {
-    verticalLayout = new QVBoxLayout;
-
-    translationTextEdit = new QTextEdit;
+    contextMenu = new QMenu;
 
-    verticalLayout->addWidget(translationTextEdit);
+    contextMenu->addAction(tr("Copy"), this, SLOT(copy()));
+    contextMenu->addAction(tr("Paste"), this, SLOT(paste()));
+    contextMenu->addAction(tr("Select all"), this, SLOT(selectAll()));
+}
 
-    setLayout(verticalLayout);
+void TranslationWidget::showContextMenu(QPoint pos) {
+    contextMenu->exec(pos);
 }
 
index 721f702..f4afadd 100644 (file)
@@ -33,7 +33,7 @@
 /*!
     Display many translation of word, formatted as html.
 */
-class TranslationWidget : public QWidget {
+class TranslationWidget : public QTextEdit {
     Q_OBJECT
 public:
     explicit TranslationWidget(Backbone* backbone, QWidget *parent = 0);
@@ -44,10 +44,13 @@ public Q_SLOTS:
     //! Request to show translation of word passed as QModelIndex from word list
     void show(QModelIndex);
 
+private Q_SLOTS:
+    void showContextMenu(QPoint pos);
+
 private:
     Backbone *backbone;
-    QTextEdit* translationTextEdit;
-    QVBoxLayout* verticalLayout;
+    QMenu *contextMenu;
+
 
     void initializeUI();
 
index 3174537..2ad4e49 100644 (file)
@@ -67,5 +67,5 @@ void WordListWidget::showSearchResults() {
          addWord(i.key(), i.value());
     }
 
-    wordListModel->sort(0, Qt::DescendingOrder);
+    wordListModel->sort(0, Qt::AscendingOrder);
 }
index 0e32ee1..7932404 100644 (file)
 
 class Settings;
 
+//! Interface for plugin dialog provider
 class DictDialog : public QObject {
     Q_OBJECT
 
 public:
     DictDialog(QObject*parent=0) : QObject(parent) {}
+
+    /*!
+      Shows add new dictionary dialog and returns settings of new dict
+      \param parent parent widget on which will be displayed dialog
+      */
     virtual Settings* addNewDictionary(QWidget*parent=0)=0;
+
+    /*!
+      Shows settings dialog and save new settings in plugin
+      \param parent parent widget on which will be displayed dialog
+      */
     virtual void changeSettings(QWidget*parent=0)=0;
 };
 
diff --git a/trunk/src/plugins/xdxf/src/TranslationXdxf.cpp b/trunk/src/plugins/xdxf/src/TranslationXdxf.cpp
new file mode 100644 (file)
index 0000000..0c3fcfb
--- /dev/null
@@ -0,0 +1,51 @@
+/*******************************************************************************
+
+    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"
+
+
+TranslationXdxf::TranslationXdxf() {
+}
+
+TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo, XdxfPlugin *xdxfPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
+    this->xdxfPlugin=xdxfPlugin;
+}
+
+QString TranslationXdxf::key() const {
+    return _key;
+}
+
+QString TranslationXdxf::dictionaryInfo() const {
+    return _dictionaryInfo;
+}
+
+QString TranslationXdxf::toHtml() const {
+    return xdxfPlugin->search(_key);
+}
+
+void TranslationXdxf::setKey(QString _key) {
+    this->_key=_key;
+}
+
+void TranslationXdxf::setDictionaryInfo(QString _dictionaryInfo) {
+    this->_dictionaryInfo=_dictionaryInfo;
+}
+
diff --git a/trunk/src/plugins/xdxf/src/TranslationXdxf.h b/trunk/src/plugins/xdxf/src/TranslationXdxf.h
new file mode 100644 (file)
index 0000000..a691d9a
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************
+
+    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
+
+#include <QString>
+#include "../../../includes/translation.h"
+#include "xdxfplugin.h"
+
+class TranslationXdxf : public Translation
+{
+public:
+    TranslationXdxf();
+    TranslationXdxf(QString _key,QString _dictionaryInfo, XdxfPlugin *xdxfPlugin);
+
+    //! \return word to be translated
+    QString key() const;
+
+    //! \returns dictionary information (plugin name, languages, <logo> etc)\
+    //!    to be displayed in translation table header
+    QString dictionaryInfo() const;
+
+    //! \return parsed raw format into html
+    QString toHtml() const;
+
+    //! sets the word for which we want to find a translation
+    void setKey(QString);
+
+    //! sets information about dictionary
+    void setDictionaryInfo(QString);
+
+
+private:
+    QString _key;
+    QString _dictionaryInfo;
+    XdxfPlugin *xdxfPlugin;
+
+};
+
+#endif // TRANSLATIONXDXF_H
+
diff --git a/trunk/src/plugins/xdxf/src/XdxfDictDialog.cpp b/trunk/src/plugins/xdxf/src/XdxfDictDialog.cpp
new file mode 100644 (file)
index 0000000..0e672ce
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************
+
+    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.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "XdxfDictDialog.h"
+#include "XdxfLoadDialog.h"
+
+XdxfDictDialog::XdxfDictDialog(QObject *parent) :
+    DictDialog(parent) {
+
+}
+
+
+Settings* XdxfDictDialog::addNewDictionary(QWidget *parent) {
+    return XdxfLoadDialog::getSettings(parent);
+}
+
+void XdxfDictDialog::changeSettings(QWidget *) {
+
+}
diff --git a/trunk/src/plugins/xdxf/src/XdxfDictDialog.h b/trunk/src/plugins/xdxf/src/XdxfDictDialog.h
new file mode 100644 (file)
index 0000000..4384fcd
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************
+
+    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.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef XDXFDICTDIALOG_H
+#define XDXFDICTDIALOG_H
+
+#include "../../../includes/DictDialog.h"
+#include "XdxfLoadDialog.h"
+
+
+//! Implementation of DictDialog interface for xdxf plugin
+class XdxfDictDialog : public DictDialog {
+    Q_OBJECT
+public:
+    explicit XdxfDictDialog(QObject *parent = 0);
+
+    /*!
+      Shows add new xdxf dictionary dialog and returns settings of new dict
+      \param parent parent widget on which will be displayed dialog
+      */
+    Settings* addNewDictionary(QWidget *parent);
+
+    /*!
+      Shows settings dialog and save new settings in plugin
+      \param parent parent widget on which will be displayed dialog
+      */
+    void changeSettings(QWidget *parent);
+};
+
+#endif // XDXFDICTDIALOG_H
diff --git a/trunk/src/plugins/xdxf/src/XdxfLoadDialog.cpp b/trunk/src/plugins/xdxf/src/XdxfLoadDialog.cpp
new file mode 100644 (file)
index 0000000..2666ffa
--- /dev/null
@@ -0,0 +1,110 @@
+/*******************************************************************************
+
+    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.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "XdxfLoadDialog.h"
+
+XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
+    QDialog(parent) {
+    verticalLayout = new QVBoxLayout;
+    setLayout(verticalLayout);
+
+    setWindowTitle(tr("Add new XDXF dictionary"));
+
+    browseLayout = new QHBoxLayout;
+    verticalLayout->addLayout(browseLayout);
+
+    browseButton =  new QPushButton(tr("Browse"));
+    browseLabel = new QLabel(tr("Dictionary file: not selected"));
+
+    browseLayout->addWidget(browseLabel);
+    browseLayout->addWidget(browseButton,0, Qt::AlignRight);
+
+
+    cacheLayout = new QHBoxLayout;
+    verticalLayout->addLayout(cacheLayout);
+
+    cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"));
+    cacheCheckBox->setChecked(true);
+    cacheLayout->addWidget(cacheCheckBox);
+
+    addButton = new QPushButton(tr("Add"));
+
+    verticalLayout->addWidget(addButton);
+
+    setModal(true);
+
+    connect(browseButton, SIGNAL(clicked()),
+            this, SLOT(selectFile()));
+
+    connect(addButton, SIGNAL(clicked()),
+            this, SLOT(addDictionary()));
+
+    _dicitonaryFilePath = QString();
+}
+
+void XdxfLoadDialog::selectFile() {
+    QString fileName = QFileDialog::getOpenFileName(this,
+                                     tr("Select dictionary file"),
+                                     "",
+                                     tr("XDXF Files (*.xdxf)"),
+                                     NULL,
+                                     NULL);
+    if (!fileName.isEmpty()) {
+        browseLabel->setText(tr("Dictionary file: ") + fileName);
+        _dicitonaryFilePath = fileName;
+    }
+}
+
+void XdxfLoadDialog::addDictionary() {
+    _generateCache = cacheCheckBox->isChecked();
+    accept();
+}
+
+QString XdxfLoadDialog::dicitonaryFilePath() {
+    return _dicitonaryFilePath;
+}
+
+bool XdxfLoadDialog::generateCache() {
+    return _generateCache;
+}
+
+Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
+    XdxfLoadDialog loadDialog(parent);
+    Settings* settings = new Settings;
+
+    if(loadDialog.exec()==QDialog::Accepted) {
+        settings->setValue("dictionaryFile", loadDialog.dicitonaryFilePath());
+        if(loadDialog.generateCache()) {
+            settings->setValue("cache", "1");
+        }
+        else {
+            settings->setValue("cache", "0");
+        }
+
+        return settings;
+    }
+
+    return NULL;
+}
+
+
diff --git a/trunk/src/plugins/xdxf/src/XdxfLoadDialog.h b/trunk/src/plugins/xdxf/src/XdxfLoadDialog.h
new file mode 100644 (file)
index 0000000..3b102fc
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+
+    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.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef XDXFLOADDIALOG_H
+#define XDXFLOADDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#include "../../../includes/settings.h"
+
+//! Displays dialog which allow user to add new xdxf dictionary
+class XdxfLoadDialog : public QDialog {
+    Q_OBJECT
+public:
+    explicit XdxfLoadDialog(QWidget *parent = 0);
+
+    /*! Displays dialog and returns settings of new dictionary
+        \return Setting object containing new dictionary settings or NULL in
+        case which user cancel dialog
+    */
+    static Settings* getSettings(QWidget *parent);
+
+    //! Returns choosen by user dictionary file path
+    QString dicitonaryFilePath();
+
+    //! Returns if user want to cache dictionary
+    bool generateCache();
+
+signals:
+
+public slots:
+
+private Q_SLOTS:
+    void selectFile();
+    void addDictionary();
+
+private:
+    QPushButton* addButton;
+    QPushButton* browseButton;
+    QLabel* browseLabel;
+    QCheckBox* cacheCheckBox;
+    QVBoxLayout* verticalLayout;
+    QHBoxLayout* browseLayout;
+    QHBoxLayout* cacheLayout;
+    QString _dicitonaryFilePath;
+    bool _generateCache;
+
+};
+
+#endif // XDXFLOADDIALOG_H
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin.pro b/trunk/src/plugins/xdxf/src/XdxfPlugin.pro
new file mode 100644 (file)
index 0000000..0c4b06b
--- /dev/null
@@ -0,0 +1,28 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-08-03T09:33:52
+#
+#-------------------------------------------------
+
+QT       += core xml gui
+
+
+TARGET = XdxfPlugin
+TEMPLATE = lib
+
+SOURCES +=  \
+    xdxfplugin.cpp \
+    TranslationXdxf.cpp \
+    XdxfLoadDialog.cpp \
+    XdxfDictDialog.cpp
+
+
+HEADERS += \
+    xdxfplugin.h \
+    TranslationXdxf.h \
+    XdxfLoadDialog.h \
+    ../../../includes/DictDialog.h \
+    XdxfDictDialog.h \
+    ../../../includes/translation.h \
+    ../../../includes/settings.h \
+    ../../../includes/CommonDictInterface.h \
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/TranslationXdxf.cpp b/trunk/src/plugins/xdxf/src/XdxfPlugin/TranslationXdxf.cpp
deleted file mode 100644 (file)
index 0c3fcfb..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
-
-    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"
-
-
-TranslationXdxf::TranslationXdxf() {
-}
-
-TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo, XdxfPlugin *xdxfPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
-    this->xdxfPlugin=xdxfPlugin;
-}
-
-QString TranslationXdxf::key() const {
-    return _key;
-}
-
-QString TranslationXdxf::dictionaryInfo() const {
-    return _dictionaryInfo;
-}
-
-QString TranslationXdxf::toHtml() const {
-    return xdxfPlugin->search(_key);
-}
-
-void TranslationXdxf::setKey(QString _key) {
-    this->_key=_key;
-}
-
-void TranslationXdxf::setDictionaryInfo(QString _dictionaryInfo) {
-    this->_dictionaryInfo=_dictionaryInfo;
-}
-
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/TranslationXdxf.h b/trunk/src/plugins/xdxf/src/XdxfPlugin/TranslationXdxf.h
deleted file mode 100644 (file)
index 1450b6a..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
-
-    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
-
-#include <QString>
-#include "../../../../includes/translation.h"
-#include "xdxfplugin.h"
-
-class TranslationXdxf : public Translation
-{
-public:
-    TranslationXdxf();
-    TranslationXdxf(QString _key,QString _dictionaryInfo, XdxfPlugin *xdxfPlugin);
-
-    //! \return word to be translated
-    QString key() const;
-
-    //! \returns dictionary information (plugin name, languages, <logo> etc)\
-    //!    to be displayed in translation table header
-    QString dictionaryInfo() const;
-
-    //! \return parsed raw format into html
-    QString toHtml() const;
-
-    //! sets the word for which we want to find a translation
-    void setKey(QString);
-
-    //! sets information about dictionary
-    void setDictionaryInfo(QString);
-
-
-private:
-    QString _key;
-    QString _dictionaryInfo;
-    XdxfPlugin *xdxfPlugin;
-
-};
-
-#endif // TRANSLATIONXDXF_H
-
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp
deleted file mode 100644 (file)
index 14f875c..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
-
-    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.
-
-*******************************************************************************/
-
-//Created by Mateusz Półrola
-
-#include "XdxfDictDialog.h"
-#include "XdxfLoadDialog.h"
-
-XdxfDictDialog::XdxfDictDialog(QObject *parent) :
-    DictDialog(parent) {
-
-}
-
-
-Settings* XdxfDictDialog::addNewDictionary(QWidget *parent) {
-    return XdxfLoadDialog::getSettings(parent);
-}
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h
deleted file mode 100644 (file)
index 1dd98c2..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
-
-    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.
-
-*******************************************************************************/
-
-//Created by Mateusz Półrola
-
-#ifndef XDXFDICTDIALOG_H
-#define XDXFDICTDIALOG_H
-
-#include "../../../../includes/DictDialog.h"
-#include "XdxfLoadDialog.h"
-
-
-class XdxfDictDialog : public DictDialog {
-    Q_OBJECT
-public:
-    explicit XdxfDictDialog(QObject *parent = 0);
-
-    Settings* addNewDictionary(QWidget *parent);
-    void changeSettings(QWidget *parent);
-};
-
-#endif // XDXFDICTDIALOG_H
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp
deleted file mode 100644 (file)
index 1db0e05..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
-
-    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.
-
-*******************************************************************************/
-
-//Created by Mateusz Półrola
-
-#include "XdxfLoadDialog.h"
-
-XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
-    QDialog(parent) {
-    verticalLayout = new QVBoxLayout;
-    setLayout(verticalLayout);
-
-    setWindowTitle(tr("Add new XDXF dictionary"));
-
-    browseLayout = new QHBoxLayout;
-    verticalLayout->addLayout(browseLayout);
-
-    browseButton =  new QPushButton(tr("Browse"));
-    browseLabel = new QLabel(tr("Dictionary file: not selected"));
-
-    browseLayout->addWidget(browseLabel);
-    browseLayout->addWidget(browseButton,0, Qt::AlignRight);
-
-
-    cacheLayout = new QHBoxLayout;
-    verticalLayout->addLayout(cacheLayout);
-
-    cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"));
-    cacheCheckBox->setChecked(true);
-    cacheLayout->addWidget(cacheCheckBox);
-
-    addButton = new QPushButton(tr("Add"));
-
-    verticalLayout->addWidget(addButton);
-
-    setModal(true);
-
-    connect(browseButton, SIGNAL(clicked()),
-            this, SLOT(selectFile()));
-
-    connect(addButton, SIGNAL(clicked()),
-            this, SLOT(addDictionary()));
-
-    dicitonaryFilePath = QString();
-}
-
-void XdxfLoadDialog::selectFile() {
-    QString fileName = QFileDialog::getOpenFileName(this,
-                                     tr("Select dictionary file"),
-                                     "",
-                                     tr("XDXF Files (*.xdxf)"),
-                                     NULL,
-                                     NULL);
-    if (!fileName.isEmpty()) {
-        browseLabel->setText(tr("Dictionary file: ") + fileName);
-        dicitonaryFilePath = fileName;
-    }
-}
-
-void XdxfLoadDialog::addDictionary() {
-    generateCache = cacheCheckBox->isChecked();
-    accept();
-}
-
-Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
-    XdxfLoadDialog loadDialog(parent);
-    Settings* settings = new Settings;
-
-    if(loadDialog.exec()==0) {
-        settings->setValue("dictionaryFile", dicitonaryFilePath);
-        if(generateCache) {
-            settings->setValue("cache", "1");
-        }
-        else {
-            settings->setValue("cache", "0");
-        }
-
-        return settings;
-    }
-
-    return NULL;
-}
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h
deleted file mode 100644 (file)
index 99c8368..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
-
-    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.
-
-*******************************************************************************/
-
-//Created by Mateusz Półrola
-
-#ifndef XDXFLOADDIALOG_H
-#define XDXFLOADDIALOG_H
-
-#include <QDialog>
-#include <QtGui>
-#include "../../../../includes/settings.h"
-
-
-class XdxfLoadDialog : public QDialog {
-    Q_OBJECT
-public:
-    explicit XdxfLoadDialog(QWidget *parent = 0);
-    static Settings* getSettings(QWidget *parent);
-
-signals:
-
-public slots:
-
-private Q_SLOTS:
-    void selectFile();
-    void addDictionary();
-
-private:
-    QPushButton* addButton;
-    QPushButton* browseButton;
-    QLabel* browseLabel;
-    QCheckBox* cacheCheckBox;
-    QVBoxLayout* verticalLayout;
-    QHBoxLayout* browseLayout;
-    QHBoxLayout* cacheLayout;
-    static QString dicitonaryFilePath;
-    static bool generateCache;
-};
-
-#endif // XDXFLOADDIALOG_H
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro
deleted file mode 100644 (file)
index 26b1c12..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2010-08-03T09:33:52
-#
-#-------------------------------------------------
-
-QT       += core xml gui
-
-
-TARGET = XdxfPlugin
-TEMPLATE = lib
-
-SOURCES +=  \
-    xdxfplugin.cpp \
-    TranslationXdxf.cpp \
-    XdxfLoadDialog.cpp \
-    XdxfDictDialog.cpp
-
-
-HEADERS += \
-    xdxfplugin.h \
-    ../../../../includes/translation.h \
-    ../../../../includes/settings.h \
-    ../../../../includes/CommonDictInterface.h \
-    TranslationXdxf.h \
-    XdxfLoadDialog.h \
-    ../../../../includes/DictDialog.h \
-    XdxfDictDialog.h
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp b/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp
deleted file mode 100644 (file)
index ae28a81..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-/*******************************************************************************
-
-    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>
-#include <QXmlStreamReader>
-#include <QtPlugin>
-#include "TranslationXdxf.h"
-#include "../../../../includes/settings.h"
-
-XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
-                    _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
-                    _type(tr("xdxf")), _infoNote(tr("")) {
-    _settings = new Settings();
-    _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::langTo() const {
-    return  _langTo;
-}
-
-QString XdxfPlugin::name() const {
-    return  _name;
-}
-
-QString XdxfPlugin::type() const {
-//    return _settings->value("type");
-    return _type;
-}
-
-QString XdxfPlugin::infoNote() const {
-    return  _infoNote;
-}
-
-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);
-    if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
-        qDebug()<<"Error: could not open file";
-        return translations.toList();
-    }
-
-    /*read information about dictionary*/
-    QXmlStreamReader dictionaryReader(&dictionaryFile);
-    dictionaryReader.readNextStartElement();
-    if(dictionaryReader.name()=="xdxf") {
-      if(dictionaryReader.attributes().hasAttribute("lang_from"))
-        _langFrom = dictionaryReader.attributes().value("lang_from").toString();
-      if(dictionaryReader.attributes().hasAttribute("lang_to"))
-        _langTo = dictionaryReader.attributes().value("lang_to").toString();
-    }
-    dictionaryReader.readNextStartElement();
-    if(dictionaryReader.name()=="full_name")
-        _name=dictionaryReader.readElementText();
-    dictionaryReader.readNextStartElement();
-    if(dictionaryReader.name()=="description")
-        _infoNote=dictionaryReader.readElementText();
-
-    /*search words list*/
-    QString a;
-    int i=0;
-    while(!dictionaryReader.atEnd() && !stopped){
-        dictionaryReader.readNextStartElement();
-        if(dictionaryReader.name()=="ar"){
-            while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
-                dictionaryReader.readNextStartElement();
-            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 && limit!=0)
-                    break;
-            }
-        }
-    }
-    stopped=false;
-    dictionaryFile.close();
-    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 "";
-    }
-    QXmlStreamReader dictionaryReader(&dictionaryFile);
-
-    QString a;
-    bool match =false;
-    while (!dictionaryReader.atEnd()) {
-        dictionaryReader.readNext();
-        if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
-            if(dictionaryReader.name()=="k") {
-                a = dictionaryReader.readElementText();
-                if(a==key)
-                    match = true;
-            }
-        }
-        else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)  {
-            if(match) {
-                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;
-            }
-        }
-    }
-    dictionaryFile.close();
-    return resultString;
-}
-
-void XdxfPlugin::stop() {
-    stopped=true;
-}
-
-DictDialog* XdxfPlugin::dictDialog() {
-     return NULL;
-}
-
-void XdxfPlugin::setPath(QString path){
-    this->path=path;
-    _settings->setValue("path",path);
-}
-
-
-CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
-    XdxfPlugin *plugin = new XdxfPlugin();
-    plugin->setPath(settings->value("path"));
-    return  new XdxfPlugin();//plugin;
-}
-
-bool XdxfPlugin::isAvailable() const {
-    return true;
-}
-
-void XdxfPlugin::setHash(uint _hash)
-{
-    this->_hash=_hash;
-}
-
-uint XdxfPlugin::hash() const
-{
-   return _hash;
-}
-
-Settings* XdxfPlugin::settings() {
-    return _settings;
-}
-
-bool XdxfPlugin::isCached()
-{
-    return false;
-}
-
-Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h b/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h
deleted file mode 100644 (file)
index 6ec53dd..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*******************************************************************************
-
-    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
-
-#include "../../../../includes/CommonDictInterface.h"
-#include <QObject>
-#include <QDialog>
-#include <QRegExp>
-#include <QTime>
-
-class TranslationXdxf;
-
-class XdxfPlugin : public CommonDictInterface
-{
-    Q_OBJECT
-    Q_INTERFACES(CommonDictInterface)
-public:
-    XdxfPlugin(QObject *parent=0);
-
-    //! returns source language code iso 639-2
-    QString langFrom() const;
-
-    //! returns destination language code iso 639-2
-    QString langTo() const;
-
-    //! returns dictionary name (like "old english" or so)
-    QString name() const;
-
-    //! returns dictionary type (xdxf, google translate, etc)
-    QString type() const;
-
-    //! returns information about dictionary in html (name, authors, etc)
-    QString infoNote() const;
-
-    /*! returns DictDialog object that creates dialogs
-        for adding new dictionary and change plugin settings
-      */
-    DictDialog* dictDialog();
-
-
-    //! returns new, clean copy of plugin with setting set as in Settings*
-    CommonDictInterface* getNew(const Settings*) const;
-
-    //! returns whether plugin can start searching
-    bool isAvailable() const;
-
-    //! returns a description of a word given by a QString
-    QString search(QString key);
-
-    //! returns a unique hash for a dictionary
-    uint hash() const;
-
-    //! set unique value (unique for every dictionary not plugin)
-    void setHash(uint);
-
-    //! returns current plugin settings
-    Settings* settings();
-
-public Q_SLOTS:
-    /*! performs search in dictionary
-      \param  word word to search in dictionary
-      \param limit limit on number of results
-
-      After finishing search it has to emit
-      \see CommonDictInterface:finalTranslation  finalTranslation
-    */
-    QList<Translation*> searchWordList(QString word, int limit);
-
-    //! stop current operation
-    void stop();
-
-private:
-    bool isCached();
-    void setPath(QString);
-    QString _langFrom;
-    QString _langTo;
-    QString _name;
-    QString _type;
-    QString _infoNote;
-    QDialog *_loadDialog;
-    QDialog *_settingsDialog;
-    QString path;
-    uint _hash;
-    bool stopped;   /*volatile*/
-    Settings *_settings;
-};
-
-#endif // XDXFPLUGIN_H
-
-
diff --git a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp
new file mode 100644 (file)
index 0000000..98cf0d3
--- /dev/null
@@ -0,0 +1,210 @@
+/*******************************************************************************
+
+    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>
+#include <QXmlStreamReader>
+#include <QtPlugin>
+#include "TranslationXdxf.h"
+#include "../../../includes/settings.h"
+
+XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
+                    _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
+                    _type(tr("xdxf")), _infoNote(tr("")) {
+    _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::langTo() const {
+    return  _langTo;
+}
+
+QString XdxfPlugin::name() const {
+    return  _name;
+}
+
+QString XdxfPlugin::type() const {
+//    return _settings->value("type");
+    return _type;
+}
+
+QString XdxfPlugin::infoNote() const {
+    return  _infoNote;
+}
+
+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);
+    if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        qDebug()<<"Error: could not open file";
+        return translations.toList();
+    }
+
+    /*read information about dictionary*/
+    QXmlStreamReader dictionaryReader(&dictionaryFile);
+    dictionaryReader.readNextStartElement();
+    if(dictionaryReader.name()=="xdxf") {
+      if(dictionaryReader.attributes().hasAttribute("lang_from"))
+        _langFrom = dictionaryReader.attributes().value("lang_from").toString();
+      if(dictionaryReader.attributes().hasAttribute("lang_to"))
+        _langTo = dictionaryReader.attributes().value("lang_to").toString();
+    }
+    dictionaryReader.readNextStartElement();
+    if(dictionaryReader.name()=="full_name")
+        _name=dictionaryReader.readElementText();
+    dictionaryReader.readNextStartElement();
+    if(dictionaryReader.name()=="description")
+        _infoNote=dictionaryReader.readElementText();
+
+    /*search words list*/
+    QString a;
+    int i=0;
+    while(!dictionaryReader.atEnd() && !stopped){
+        dictionaryReader.readNextStartElement();
+        if(dictionaryReader.name()=="ar"){
+            while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
+                dictionaryReader.readNextStartElement();
+            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 && limit!=0)
+                    break;
+            }
+        }
+    }
+    stopped=false;
+    dictionaryFile.close();
+    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 "";
+    }
+    QXmlStreamReader dictionaryReader(&dictionaryFile);
+
+    QString a;
+    bool match =false;
+    while (!dictionaryReader.atEnd()) {
+        dictionaryReader.readNext();
+        if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
+            if(dictionaryReader.name()=="k") {
+                a = dictionaryReader.readElementText();
+                if(a==key)
+                    match = true;
+            }
+        }
+        else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)  {
+            if(match) {
+                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;
+            }
+        }
+    }
+    dictionaryFile.close();
+    return resultString;
+}
+
+void XdxfPlugin::stop() {
+    stopped=true;
+}
+
+DictDialog* XdxfPlugin::dictDialog() {
+     return _dictDialog;
+}
+
+void XdxfPlugin::setPath(QString path){
+    this->path=path;
+    _settings->setValue("path",path);
+}
+
+
+CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
+    XdxfPlugin *plugin = new XdxfPlugin();
+    plugin->setPath(settings->value("path"));
+    return  new XdxfPlugin();//plugin;
+}
+
+bool XdxfPlugin::isAvailable() const {
+    return true;
+}
+
+void XdxfPlugin::setHash(uint _hash)
+{
+    this->_hash=_hash;
+}
+
+uint XdxfPlugin::hash() const
+{
+   return _hash;
+}
+
+Settings* XdxfPlugin::settings() {
+    return _settings;
+}
+
+bool XdxfPlugin::isCached()
+{
+    return false;
+}
+
+Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
diff --git a/trunk/src/plugins/xdxf/src/xdxfplugin.h b/trunk/src/plugins/xdxf/src/xdxfplugin.h
new file mode 100644 (file)
index 0000000..ce2dbca
--- /dev/null
@@ -0,0 +1,112 @@
+/*******************************************************************************
+
+    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
+
+#include "../../../includes/CommonDictInterface.h"
+#include <QObject>
+#include <QDialog>
+#include <QRegExp>
+#include <QTime>
+#include "XdxfDictDialog.h"
+
+class TranslationXdxf;
+
+class XdxfPlugin : public CommonDictInterface
+{
+    Q_OBJECT
+    Q_INTERFACES(CommonDictInterface)
+public:
+    XdxfPlugin(QObject *parent=0);
+
+    //! returns source language code iso 639-2
+    QString langFrom() const;
+
+    //! returns destination language code iso 639-2
+    QString langTo() const;
+
+    //! returns dictionary name (like "old english" or so)
+    QString name() const;
+
+    //! returns dictionary type (xdxf, google translate, etc)
+    QString type() const;
+
+    //! returns information about dictionary in html (name, authors, etc)
+    QString infoNote() const;
+
+    /*! returns DictDialog object that creates dialogs
+        for adding new dictionary and change plugin settings
+      */
+    DictDialog* dictDialog();
+
+
+    //! returns new, clean copy of plugin with setting set as in Settings*
+    CommonDictInterface* getNew(const Settings*) const;
+
+    //! returns whether plugin can start searching
+    bool isAvailable() const;
+
+    //! returns a description of a word given by a QString
+    QString search(QString key);
+
+    //! returns a unique hash for a dictionary
+    uint hash() const;
+
+    //! set unique value (unique for every dictionary not plugin)
+    void setHash(uint);
+
+    //! returns current plugin settings
+    Settings* settings();
+
+public Q_SLOTS:
+    /*! performs search in dictionary
+      \param  word word to search in dictionary
+      \param limit limit on number of results
+
+      After finishing search it has to emit
+      \see CommonDictInterface:finalTranslation  finalTranslation
+    */
+    QList<Translation*> searchWordList(QString word, int limit);
+
+    //! stop current operation
+    void stop();
+
+private:
+    bool isCached();
+    void setPath(QString);
+    QString _langFrom;
+    QString _langTo;
+    QString _name;
+    QString _type;
+    QString _infoNote;
+    QDialog *_loadDialog;
+    QDialog *_settingsDialog;
+    QString path;
+    uint _hash;
+    bool stopped;   /*volatile*/
+    Settings *_settings;
+    XdxfDictDialog* _dictDialog;
+};
+
+#endif // XDXFPLUGIN_H
+
+
index 1dc77e5..c4d0db0 100644 (file)
@@ -35,6 +35,7 @@ class CommonDictInterfaceMock : public CommonDictInterface
 public:
     QString fromv, tov, namev, typev, infoNotev;
     bool available,stopped;
+    uint _hash;
     CommonDictInterfaceMock(QObject* parent = 0) :
             CommonDictInterface(parent) {}
 
@@ -47,22 +48,23 @@ public:
     QDialog* settingsDialog() {return 0;}
     CommonDictInterface* getNew(const Settings *) const { return 0;}
     bool isAvailable() const {return available;}
-    uint hash() const { return namev.length() + 10*typev.length();}
+    uint hash() const { return _hash;}
+    void setHash(uint h) {_hash = h;}
     void stop() {stopped = 1;}
     QString search(QString key) {}
     QList<Translation*> searchWordList(QString word, int limit) {
+        qDebug() << "search " << this->thread()->currentThreadId();
         stopped = 0;
         QList<Translation*> list;
 
         TranslationMock *tm = new TranslationMock();
-        tm->_key = fromv;
-        tm->_translation = tov;
+        tm->_key = langFrom();
+        tm->_translation = langTo();
         TranslationMock *tm1 = new TranslationMock();
-        tm1->_key = namev;
-        tm1->_translation = typev;
+        tm1->_key = name();
+        tm1->_translation = type();
         list << tm << tm1;
 
-        Q_EMIT finalTranslation();
         return list;
     }
 
index 8098aed..047ebe1 100644 (file)
@@ -37,6 +37,7 @@ class BackboneTest : public QObject
     QList<CommonDictInterface*> dict;
     int total;
     Backbone* back;
+
 public:
     BackboneTest();
 
@@ -151,7 +152,9 @@ void BackboneTest::searchTest() {
         QCOMPARE(m->stopped, 1);
     }
 
+    qDebug() << "main " << this->thread()->currentThreadId();
     back->search("pigwa");
+    usleep(2000);
 
     for(int i = 0; i < total; i++) {
         CommonDictInterfaceMock *m = (CommonDictInterfaceMock*)dict[i];
@@ -167,20 +170,15 @@ void BackboneTest::translationTest() {
     QSignalSpy translatS(back, SIGNAL(ready()));
     QVERIFY2 (translatS.isValid() == true, "ready() signal is invalid");
 
-    qRegisterMetaType<Translation*>("Translation*");
-    qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
     for(int i = 0; i < total; i++) {
         CommonDictInterfaceMock *m = (CommonDictInterfaceMock*) dict[i];
         m->stopped = 1;
         back->addDictionary(dict[i]);
-        ss.append(new QSignalSpy(m,SIGNAL(finalTranslation())));
-        QVERIFY2(ss[i]->isValid() == 1, "Signal invalid");
     }
 
     back->search("nic");
-    for(int i = 0; i < total; i++) {
-        QVERIFY2(ss[i]->count() == 1, "Translation signal lost");
-    }
+    usleep(2000);
+    back->translation();
 
     QVERIFY2(translatS.count() == 1, "Lost finall 'ready()' signal");
     QVERIFY2(back->result().size() == total*2, "Lost some of translations");