From 0ed51b7c86d6373452cf6c4db2b8e6bda59ff501 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mateusz=20P=C3=B3=C5=82rola?= Date: Thu, 5 Aug 2010 13:33:15 +0200 Subject: [PATCH] Added DictDialog interface, XdxfDictDialog class and XdxfLoadDialog class, modified CommonDictInterface --- trunk/src/includes/CommonDictInterface.h | 14 ++- trunk/src/includes/DictDialog.h | 40 ++++++++ trunk/src/includes/settings.h | 4 +- .../plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp | 35 +++++++ .../plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h | 40 ++++++++ .../plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp | 100 ++++++++++++++++++++ .../plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h | 58 ++++++++++++ .../src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro | 9 +- .../src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp | 13 ++- trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h | 13 ++- 10 files changed, 308 insertions(+), 18 deletions(-) create mode 100644 trunk/src/includes/DictDialog.h create mode 100644 trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp create mode 100644 trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h create mode 100644 trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp create mode 100644 trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h diff --git a/trunk/src/includes/CommonDictInterface.h b/trunk/src/includes/CommonDictInterface.h index 450ce47..d03fbc2 100644 --- a/trunk/src/includes/CommonDictInterface.h +++ b/trunk/src/includes/CommonDictInterface.h @@ -29,6 +29,8 @@ #include #include #include "translation.h" + +class DictDialog; class Settings; @@ -53,12 +55,11 @@ class CommonDictInterface : public QObject { //! returns information about dictionary in html (name, authors, etc) virtual QString infoNote() const = 0; - //! return dialog that creates new dictionary and fills necesary options - //! QDialog should returns Setting* object after being showed - virtual QDialog* loadDialog() = 0; + /*! returns DictDialog object that creates dialogs + for adding new dictionary and change plugin settings + */ + virtual DictDialog* dictDialog() = 0; - //! return dialog with dictionary settings - virtual QDialog* settingsDialog() = 0; //! return new, clean copy of plugin with setting set as in Settings* virtual CommonDictInterface* getNew(const Settings*) const = 0; @@ -75,6 +76,9 @@ class CommonDictInterface : public QObject { //! set unique value (unique for every dictionary not plugin) virtual void setHash(uint) = 0; + //! returns current plugin settings + virtual Settings* settings() = 0; + public Q_SLOTS: /*! performs search in dictionary \param word word to search in dictionary diff --git a/trunk/src/includes/DictDialog.h b/trunk/src/includes/DictDialog.h new file mode 100644 index 0000000..0e32ee1 --- /dev/null +++ b/trunk/src/includes/DictDialog.h @@ -0,0 +1,40 @@ +/******************************************************************************* + + 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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef DICTDIALOG_H +#define DICTDIALOG_H + +#include + +class Settings; + +class DictDialog : public QObject { + Q_OBJECT + +public: + DictDialog(QObject*parent=0) : QObject(parent) {} + virtual Settings* addNewDictionary(QWidget*parent=0)=0; + virtual void changeSettings(QWidget*parent=0)=0; +}; + +#endif // DICTDIALOG_H diff --git a/trunk/src/includes/settings.h b/trunk/src/includes/settings.h index 6a05410..9434fb6 100644 --- a/trunk/src/includes/settings.h +++ b/trunk/src/includes/settings.h @@ -37,7 +37,9 @@ class Settings { //! \retrun value fo given key //! \param key QString value(const QString key) const { - if(!settings.contains(key)) return QString; + if(!settings.contains(key)) { + return QString(); + } return settings[key]; } diff --git a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp new file mode 100644 index 0000000..14f875c --- /dev/null +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp @@ -0,0 +1,35 @@ +/******************************************************************************* + + 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 . + + 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 new file mode 100644 index 0000000..1dd98c2 --- /dev/null +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h @@ -0,0 +1,40 @@ +/******************************************************************************* + + 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 . + + 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 new file mode 100644 index 0000000..1db0e05 --- /dev/null +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp @@ -0,0 +1,100 @@ +/******************************************************************************* + + 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 . + + 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 new file mode 100644 index 0000000..99c8368 --- /dev/null +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h @@ -0,0 +1,58 @@ +/******************************************************************************* + + 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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef XDXFLOADDIALOG_H +#define XDXFLOADDIALOG_H + +#include +#include +#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 index 3677e33..26b1c12 100644 --- a/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro @@ -12,7 +12,9 @@ TEMPLATE = lib SOURCES += \ xdxfplugin.cpp \ - TranslationXdxf.cpp + TranslationXdxf.cpp \ + XdxfLoadDialog.cpp \ + XdxfDictDialog.cpp HEADERS += \ @@ -20,4 +22,7 @@ HEADERS += \ ../../../../includes/translation.h \ ../../../../includes/settings.h \ ../../../../includes/CommonDictInterface.h \ - TranslationXdxf.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 index be0e716..78a3b19 100644 --- a/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp @@ -4,12 +4,14 @@ #include #include #include "TranslationXdxf.h" +#include "../../../../includes/settings.h" XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent), _langFrom(tr("")), _langTo(tr("")),_name(tr("")), _type(tr("xdxf")), _infoNote(tr("")) { path="dict.xdxf"; stopped = false; + _settings = new Settings(); } QString XdxfPlugin::langFrom() const { @@ -113,13 +115,10 @@ void XdxfPlugin::stop() { stopped=true; } -QDialog* XdxfPlugin::loadDialog() { - path="dict.xdxf"; +DictDialog* XdxfPlugin::dictDialog() { + return NULL; } -QDialog* XdxfPlugin::settingsDialog() { - path="dict.xdxf"; -} CommonDictInterface* XdxfPlugin::getNew(const Settings*) const { // CommonDictInterface *commonDictInterface= new @@ -140,4 +139,8 @@ uint XdxfPlugin::hash() const return _hash; } +Settings* XdxfPlugin::settings() { + return _settings; +} + 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 index 8f3fbf5..bb37196 100644 --- a/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h +++ b/trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h @@ -31,12 +31,11 @@ public: //! returns information about dictionary in html (name, authors, etc) QString infoNote() const; - //! returns dialog that creates new dictionary and fills necessary options - //! QDialog should return Setting* object after being shown - QDialog* loadDialog(); + /*! returns DictDialog object that creates dialogs + for adding new dictionary and change plugin settings + */ + DictDialog* dictDialog(); - //! returns dialog with dictionary settings - QDialog* settingsDialog(); //! returns new, clean copy of plugin with setting set as in Settings* CommonDictInterface* getNew(const Settings*) const; @@ -53,6 +52,9 @@ public: //! 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 @@ -78,6 +80,7 @@ private: QString path; uint _hash; bool stopped; /*volatile*/ + Settings *_settings; }; #endif // XDXFPLUGIN_H -- 1.7.9.5