--- /dev/null
+#!/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
+
#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();
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;
}
void Backbone::stopSearching() {
- foreach(CommonDictInterface* dict, dicts.keys())
+ _timer.stop();
+ _innerResult.clear();
+ foreach(CommonDictInterface* dict, _dicts.keys())
dict->stop();
}
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;
}
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();
+ }
}
void Backbone::loadPlugins() {
QPluginLoader loader("xdxf.so");
- if(!loader.load())
- {
+ if(!loader.load()) {
qDebug()<<loader.errorString();
return;
}
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
}
#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"
//! Fired when dictionary call finalTranslation(..) with translation ready
- void translation(QList<Translation*>);
+ void translation();
// TODO void removeDictionary(CommonDictInterface* dict);
// TODO addToBookmark(Translation*);
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();
};
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);
#include "SearchBarWidget.h"
#include <QDebug>
-
+#include "../../includes/DictDialog.h"
SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
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,
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);
void SearchBarWidget::historyNextToolButtonClicked() {
+ CommonDictInterface*p = backbone->getPlugins()[0];
+ p->dictDialog()->addNewDictionary(this);
}
void SearchBarWidget::historyPrevToolButtonClicked() {
#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);
}
/*!
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);
//! 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();
addWord(i.key(), i.value());
}
- wordListModel->sort(0, Qt::DescendingOrder);
+ wordListModel->sort(0, Qt::AscendingOrder);
}
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;
};
--- /dev/null
+/*******************************************************************************
+
+ 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;
+}
+
--- /dev/null
+/*******************************************************************************
+
+ 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
+
--- /dev/null
+/*******************************************************************************
+
+ 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 *) {
+
+}
--- /dev/null
+/*******************************************************************************
+
+ 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
--- /dev/null
+/*******************************************************************************
+
+ 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;
+}
+
+
--- /dev/null
+/*******************************************************************************
+
+ 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
--- /dev/null
+#-------------------------------------------------
+#
+# 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 \
+++ /dev/null
-/*******************************************************************************
-
- 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;
-}
-
+++ /dev/null
-/*******************************************************************************
-
- 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
-
+++ /dev/null
-/*******************************************************************************
-
- 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);
-}
+++ /dev/null
-/*******************************************************************************
-
- 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
+++ /dev/null
-/*******************************************************************************
-
- 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;
-}
+++ /dev/null
-/*******************************************************************************
-
- 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
+++ /dev/null
-#-------------------------------------------------
-#
-# 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
+++ /dev/null
-/*******************************************************************************
-
- 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)
+++ /dev/null
-/*******************************************************************************
-
- 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
-
-
--- /dev/null
+/*******************************************************************************
+
+ 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)
--- /dev/null
+/*******************************************************************************
+
+ 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
+
+
public:
QString fromv, tov, namev, typev, infoNotev;
bool available,stopped;
+ uint _hash;
CommonDictInterfaceMock(QObject* parent = 0) :
CommonDictInterface(parent) {}
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;
}
QList<CommonDictInterface*> dict;
int total;
Backbone* back;
+
public:
BackboneTest();
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];
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");