Added xdxf dict downloader
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 28 Sep 2010 08:48:15 +0000 (10:48 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 28 Sep 2010 08:48:15 +0000 (10:48 +0200)
13 files changed:
debian/mdictionary.install
src/plugins/xdxf/XdxfCachingDialog.h
src/plugins/xdxf/XdxfDialog.cpp
src/plugins/xdxf/XdxfDialog.h
src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp [new file with mode: 0644]
src/plugins/xdxf/XdxfDictDownloadProgressDialog.h [new file with mode: 0644]
src/plugins/xdxf/XdxfDictDownloader.cpp [new file with mode: 0644]
src/plugins/xdxf/XdxfDictDownloader.h [new file with mode: 0644]
src/plugins/xdxf/XdxfDictSelectDialog.cpp [new file with mode: 0644]
src/plugins/xdxf/XdxfDictSelectDialog.h [new file with mode: 0644]
src/plugins/xdxf/xdxf.pro
src/plugins/xdxf/xdxfplugin.cpp
src/plugins/xdxf/xdxfplugin.h

index b67ebf1..80cb872 100644 (file)
@@ -7,4 +7,4 @@ usr/lib/mdictionary/plugins/eng-us.xdxf
 usr/lib/mdictionary/plugins/eng-thai.xdxf
 usr/share/mdictionary/xdxf.png
 usr/share/mdictionary/css/
-usr/share/applications/hildon/mdictionary.desktop
+usr/share/applications/mdictionary.desktop
index 1e42a0b..4b39953 100644 (file)
@@ -45,13 +45,12 @@ public:
 
 public Q_SLOTS:
     void reject();
+    void updateCachingProgress(int, int);
 
 Q_SIGNALS:
     //! signal emitted when user cancels caching of a dictionary
     void cancelCaching();
 
-private Q_SLOTS:
-    void updateCachingProgress(int, int);
 
 private:
     QLabel* cachingLabel;
index e4ca1bf..6949e9a 100644 (file)
@@ -54,6 +54,9 @@ XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
     if(type == New) {
         connect(browseButton, SIGNAL(clicked()),
                 this, SLOT(selectFile()));
+
+        connect(downloadButton, SIGNAL(clicked()),
+                this, SLOT(downloadFile()));
     }
 
     connect(confirmButton, SIGNAL(clicked()),
@@ -74,11 +77,21 @@ void XdxfDialog::initializeUI() {
         setWindowTitle(tr("Add new XDXF dictionary"));
 
         browseLayout = new QHBoxLayout;
+
+        QHBoxLayout* buttonLayout = new QHBoxLayout;
         browseButton = new QPushButton(tr("Browse"));
+        browseButton->setMaximumWidth(150);
+
+        downloadButton = new QPushButton(tr("Download"));
+        downloadButton->setMaximumWidth(150);
+
         infoLabel->setText(tr("Dictionary file: not selected"));
 
         browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
-        browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
+
+        browseLayout->addLayout(buttonLayout);
+        buttonLayout->addWidget(browseButton);
+        buttonLayout->addWidget(downloadButton);
 
         mainVerticalLayout->addLayout(browseLayout);
     }
@@ -220,6 +233,10 @@ void XdxfDialog::selectFile() {
     }
 }
 
+void XdxfDialog::downloadFile() {
+    XdxfPlugin::dictDownloader.download(this);
+}
+
 void XdxfDialog::saveSettings() {
     _settings = new Settings;
     if(plugin) {
index ec50274..f6d7e7c 100644 (file)
@@ -91,6 +91,7 @@ public Q_SLOTS:
 private Q_SLOTS:
     //! displays dialog to browse and select file
     void selectFile();
+    void downloadFile();
     void setGenerateCache(bool);
     void setAccents(bool);
 
@@ -109,6 +110,7 @@ private:
 
     QLabel* infoLabel;
     QPushButton* browseButton;
+    QPushButton* downloadButton;
     QHBoxLayout* browseLayout;
 
 
diff --git a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
new file mode 100644 (file)
index 0000000..d42bca3
--- /dev/null
@@ -0,0 +1,78 @@
+/*******************************************************************************
+
+    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 "XdxfDictDownloadProgressDialog.h"
+
+XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QWidget*parent):
+    QDialog(parent) {
+    verticalLayout = new QVBoxLayout(this);
+    setLayout(verticalLayout);
+
+    setWindowTitle(tr("Downloading dictionary, please wait"));
+    downloadProgressBar = new QProgressBar(this);
+    downloadProgressBar->setMinimum(0);
+    downloadProgressBar->setMaximum(100);
+    downloadProgressBar->setTextVisible(true);
+
+    cancelButton = new QPushButton(tr("Cancel"),this);
+
+
+    downloadTimeLabel = new QLabel(this);
+    downloadTimeLabel->hide();
+
+    #ifndef Q_WS_MAEMO_5
+            downloadLabel = new QLabel(this);
+            downloadLabel->setText(tr("Downloading dictionary, please wait"));
+            verticalLayout->addWidget(downloadLabel, 0, Qt::AlignCenter);
+    #endif
+
+
+    verticalLayout->addWidget(downloadTimeLabel);
+    verticalLayout->addWidget(downloadProgressBar);
+    verticalLayout->addWidget(cancelButton);
+
+    connect(cancelButton, SIGNAL(clicked()),
+            this, SIGNAL(cancelDownloading()));
+
+    time.start();
+
+    setModal(true);
+}
+
+
+void XdxfDictDownloadProgressDialog::reject() {
+    return;
+}
+
+void XdxfDictDownloadProgressDialog::updateDownloadProgress(int progress,
+                                                            int time) {
+    if(!downloadTimeLabel->isVisible())
+        downloadTimeLabel->show();
+
+    int seconds = float((100 - progress)*time) / (5*1000);
+
+    downloadTimeLabel->setText(tr("Estimated time left: ") +
+                          tr("%n second(s)", "", seconds));
+    if(progress >= 100)
+        this->accept();
+}
diff --git a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h
new file mode 100644 (file)
index 0000000..69e6439
--- /dev/null
@@ -0,0 +1,53 @@
+/*******************************************************************************
+
+    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 XDXFDICTDOWNLOADPROGRESSDIALOG_H
+#define XDXFDICTDOWNLOADPROGRESSDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+
+class XdxfDictDownloadProgressDialog : public QDialog {
+    Q_OBJECT
+public:
+    XdxfDictDownloadProgressDialog(QWidget *parent = 0);
+
+public Q_SLOTS:
+    void reject();
+    void updateDownloadProgress(int, int);
+
+Q_SIGNALS:
+    //! signal emitted when user cancels downloading of a dictionary
+    void cancelDownloading();
+
+private:
+    QLabel* downloadLabel;
+    QLabel* downloadTimeLabel;
+    QProgressBar* downloadProgressBar;
+    QPushButton* cancelButton;
+    QVBoxLayout* verticalLayout;
+    //! used to check the progress of dictionary downloading
+    QTime time;
+};
+
+#endif // XDXFDICTDOWNLOADPROGRESSDIALOG_H
diff --git a/src/plugins/xdxf/XdxfDictDownloader.cpp b/src/plugins/xdxf/XdxfDictDownloader.cpp
new file mode 100644 (file)
index 0000000..e0e99ba
--- /dev/null
@@ -0,0 +1,36 @@
+/*******************************************************************************
+
+    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 "XdxfDictDownloader.h"
+#include "XdxfDictDownloadProgressDialog.h"
+
+XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
+    QObject(parent)
+{
+}
+
+
+void XdxfDictDownloader::download(QWidget *parent) {
+    XdxfDictDownloadProgressDialog progress(parent);
+    //XdxfDictSelectDialog selectDialog(parent);
+}
diff --git a/src/plugins/xdxf/XdxfDictDownloader.h b/src/plugins/xdxf/XdxfDictDownloader.h
new file mode 100644 (file)
index 0000000..da82b23
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************
+
+    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 XDXFDICTDOWNLOADER_H
+#define XDXFDICTDOWNLOADER_H
+
+#include <QObject>
+#include "XdxfDictSelectDialog.h"
+#include <QTimer>
+
+class XdxfDictDownloader : public QObject
+{
+    Q_OBJECT
+public:
+    XdxfDictDownloader(QObject *parent = 0);
+
+public Q_SLOTS:
+    void download(QWidget* parent);
+
+
+};
+
+#endif // XDXFDICTDOWNLOADER_H
diff --git a/src/plugins/xdxf/XdxfDictSelectDialog.cpp b/src/plugins/xdxf/XdxfDictSelectDialog.cpp
new file mode 100644 (file)
index 0000000..897cae9
--- /dev/null
@@ -0,0 +1,74 @@
+/*******************************************************************************
+
+    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 "XdxfDictSelectDialog.h"
+
+XdxfDictSelectDialog::XdxfDictSelectDialog(QWidget *parent) :
+    QDialog(parent) {
+    layout = new QVBoxLayout;
+    setLayout(layout);
+
+    checkBoxLayout = new QHBoxLayout;
+    layout->addLayout(checkBoxLayout);
+
+    langFrom = new QComboBox;
+    langTo = new QComboBox;
+
+    checkBoxLayout->addWidget(langFrom);
+    checkBoxLayout->addWidget(langTo);
+
+
+    treeWidget = new QTreeWidget;
+    treeWidget->setRootIsDecorated(false);
+    treeWidget->setColumnCount(4);
+    QStringList headers;
+    headers << tr("From") << tr("To") << tr("Name") << tr("Size");
+    treeWidget->setHeaderLabels(headers);
+    treeWidget->setColumnWidth(0, 100);
+    treeWidget->setColumnWidth(1, 100);
+    treeWidget->setColumnWidth(2, 100);
+    treeWidget->setColumnWidth(3, 100);
+    layout->addWidget(treeWidget);
+
+
+    connect(langFrom, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(refreshDictList()));
+
+    connect(langTo, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(refreshDictList()));
+
+    #ifndef Q_WS_MAEMO_5
+        setMinimumSize(400,200);
+    #else
+        setMinimumHeight(350);
+    #endif
+
+    refreshDictList();
+}
+
+
+void XdxfDictSelectDialog::refreshDictList() {
+    QStringList l;
+    l << "pies" << "kot";
+    treeWidget->insertTopLevelItem(0, new QTreeWidgetItem(l));
+}
diff --git a/src/plugins/xdxf/XdxfDictSelectDialog.h b/src/plugins/xdxf/XdxfDictSelectDialog.h
new file mode 100644 (file)
index 0000000..34a8677
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+
+    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 XDXFDICTSELECTDIALOG_H
+#define XDXFDICTSELECTDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+
+class XdxfDictSelectDialog : public QDialog {
+    Q_OBJECT
+public:
+    explicit XdxfDictSelectDialog(QWidget *parent = 0);
+
+private:
+    QTreeWidget* treeWidget;
+    QVBoxLayout* layout;
+    QHBoxLayout* checkBoxLayout;
+    QComboBox* langFrom;
+    QComboBox* langTo;
+
+private Q_SLOTS:
+    void refreshDictList();
+};
+
+#endif // XDXFDICTSELECTDIALOG_H
index ef29877..3b32087 100644 (file)
@@ -5,7 +5,8 @@ include(../plugin.pri)
 QT = core \
     gui \
     xml \
-    sql
+    sql \
+    network
 
 maemo5:QT += maemo5
 
@@ -14,7 +15,10 @@ SOURCES +=  \
     TranslationXdxf.cpp \
     XdxfDictDialog.cpp \
     XdxfCachingDialog.cpp \
-    XdxfDialog.cpp
+    XdxfDialog.cpp \
+    XdxfDictDownloader.cpp \
+    XdxfDictSelectDialog.cpp \
+    XdxfDictDownloadProgressDialog.cpp
 
 
 HEADERS += \
@@ -26,7 +30,10 @@ HEADERS += \
     ../../include/settings.h \
     ../../include/CommonDictInterface.h \
     XdxfCachingDialog.h \
-    XdxfDialog.h
+    XdxfDialog.h \
+    XdxfDictDownloader.h \
+    XdxfDictSelectDialog.h \
+    XdxfDictDownloadProgressDialog.h
 
 RESOURCES += \
     xdxf.qrc
index ee8ee03..8237bc6 100644 (file)
@@ -27,6 +27,9 @@
 #include <QDebug>
 #include "../../include/Notify.h"
 
+
+XdxfDictDownloader XdxfPlugin::dictDownloader;
+
 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(""), _langTo(""),_name(""), _infoNote("") {
     _settings = new Settings();
index 334a506..38ab6e6 100644 (file)
@@ -43,6 +43,7 @@
 #include "XdxfDictDialog.h"
 #include "XdxfCachingDialog.h"
 #include "TranslationXdxf.h"
+#include "XdxfDictDownloader.h"
 
 class TranslationXdxf;
 
@@ -101,7 +102,7 @@ public:
         */
     void clean();
 
-
+    static XdxfDictDownloader dictDownloader;
 
 public Q_SLOTS:
     /*! performs search in a dictionary