Added DictDialog interface, XdxfDictDialog class and XdxfLoadDialog class,
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Thu, 5 Aug 2010 11:33:15 +0000 (13:33 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Thu, 5 Aug 2010 11:33:15 +0000 (13:33 +0200)
modified CommonDictInterface

trunk/src/includes/CommonDictInterface.h
trunk/src/includes/DictDialog.h [new file with mode: 0644]
trunk/src/includes/settings.h
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfDictDialog.h [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.cpp [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfLoadDialog.h [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfPlugin/XdxfPlugin.pro
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h

index 450ce47..d03fbc2 100644 (file)
@@ -29,6 +29,8 @@
 #include <QObject>
 #include <QList>
 #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 (file)
index 0000000..0e32ee1
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef DICTDIALOG_H
+#define DICTDIALOG_H
+
+#include <QObject>
+
+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
index 6a05410..9434fb6 100644 (file)
@@ -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 (file)
index 0000000..14f875c
--- /dev/null
@@ -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 <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
new file mode 100644 (file)
index 0000000..1dd98c2
--- /dev/null
@@ -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 <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
new file mode 100644 (file)
index 0000000..1db0e05
--- /dev/null
@@ -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 <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
new file mode 100644 (file)
index 0000000..99c8368
--- /dev/null
@@ -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 <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
index 3677e33..26b1c12 100644 (file)
@@ -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
index be0e716..78a3b19 100644 (file)
@@ -4,12 +4,14 @@
 #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("")) {
     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)
index 8f3fbf5..bb37196 100644 (file)
@@ -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