From 1277aea783f9b818fb81799f6c84ab496747af15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mateusz=20P=C3=B3=C5=82rola?= Date: Tue, 28 Sep 2010 10:48:15 +0200 Subject: [PATCH] Added xdxf dict downloader --- debian/mdictionary.install | 2 +- src/plugins/xdxf/XdxfCachingDialog.h | 3 +- src/plugins/xdxf/XdxfDialog.cpp | 19 ++++- src/plugins/xdxf/XdxfDialog.h | 2 + .../xdxf/XdxfDictDownloadProgressDialog.cpp | 78 ++++++++++++++++++++ src/plugins/xdxf/XdxfDictDownloadProgressDialog.h | 53 +++++++++++++ src/plugins/xdxf/XdxfDictDownloader.cpp | 36 +++++++++ src/plugins/xdxf/XdxfDictDownloader.h | 43 +++++++++++ src/plugins/xdxf/XdxfDictSelectDialog.cpp | 74 +++++++++++++++++++ src/plugins/xdxf/XdxfDictSelectDialog.h | 46 ++++++++++++ src/plugins/xdxf/xdxf.pro | 13 +++- src/plugins/xdxf/xdxfplugin.cpp | 3 + src/plugins/xdxf/xdxfplugin.h | 3 +- 13 files changed, 367 insertions(+), 8 deletions(-) create mode 100644 src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp create mode 100644 src/plugins/xdxf/XdxfDictDownloadProgressDialog.h create mode 100644 src/plugins/xdxf/XdxfDictDownloader.cpp create mode 100644 src/plugins/xdxf/XdxfDictDownloader.h create mode 100644 src/plugins/xdxf/XdxfDictSelectDialog.cpp create mode 100644 src/plugins/xdxf/XdxfDictSelectDialog.h diff --git a/debian/mdictionary.install b/debian/mdictionary.install index b67ebf1..80cb872 100644 --- a/debian/mdictionary.install +++ b/debian/mdictionary.install @@ -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 diff --git a/src/plugins/xdxf/XdxfCachingDialog.h b/src/plugins/xdxf/XdxfCachingDialog.h index 1e42a0b..4b39953 100644 --- a/src/plugins/xdxf/XdxfCachingDialog.h +++ b/src/plugins/xdxf/XdxfCachingDialog.h @@ -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; diff --git a/src/plugins/xdxf/XdxfDialog.cpp b/src/plugins/xdxf/XdxfDialog.cpp index e4ca1bf..6949e9a 100644 --- a/src/plugins/xdxf/XdxfDialog.cpp +++ b/src/plugins/xdxf/XdxfDialog.cpp @@ -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) { diff --git a/src/plugins/xdxf/XdxfDialog.h b/src/plugins/xdxf/XdxfDialog.h index ec50274..f6d7e7c 100644 --- a/src/plugins/xdxf/XdxfDialog.h +++ b/src/plugins/xdxf/XdxfDialog.h @@ -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 index 0000000..d42bca3 --- /dev/null +++ b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp @@ -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 . + + 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 index 0000000..69e6439 --- /dev/null +++ b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef XDXFDICTDOWNLOADPROGRESSDIALOG_H +#define XDXFDICTDOWNLOADPROGRESSDIALOG_H + +#include +#include + +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 index 0000000..e0e99ba --- /dev/null +++ b/src/plugins/xdxf/XdxfDictDownloader.cpp @@ -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 . + + 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 index 0000000..da82b23 --- /dev/null +++ b/src/plugins/xdxf/XdxfDictDownloader.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef XDXFDICTDOWNLOADER_H +#define XDXFDICTDOWNLOADER_H + +#include +#include "XdxfDictSelectDialog.h" +#include + +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 index 0000000..897cae9 --- /dev/null +++ b/src/plugins/xdxf/XdxfDictSelectDialog.cpp @@ -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 . + + 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 index 0000000..34a8677 --- /dev/null +++ b/src/plugins/xdxf/XdxfDictSelectDialog.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef XDXFDICTSELECTDIALOG_H +#define XDXFDICTSELECTDIALOG_H + +#include +#include + +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 diff --git a/src/plugins/xdxf/xdxf.pro b/src/plugins/xdxf/xdxf.pro index ef29877..3b32087 100644 --- a/src/plugins/xdxf/xdxf.pro +++ b/src/plugins/xdxf/xdxf.pro @@ -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 diff --git a/src/plugins/xdxf/xdxfplugin.cpp b/src/plugins/xdxf/xdxfplugin.cpp index ee8ee03..8237bc6 100644 --- a/src/plugins/xdxf/xdxfplugin.cpp +++ b/src/plugins/xdxf/xdxfplugin.cpp @@ -27,6 +27,9 @@ #include #include "../../include/Notify.h" + +XdxfDictDownloader XdxfPlugin::dictDownloader; + XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent), _langFrom(""), _langTo(""),_name(""), _infoNote("") { _settings = new Settings(); diff --git a/src/plugins/xdxf/xdxfplugin.h b/src/plugins/xdxf/xdxfplugin.h index 334a506..38ab6e6 100644 --- a/src/plugins/xdxf/xdxfplugin.h +++ b/src/plugins/xdxf/xdxfplugin.h @@ -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 -- 1.7.9.5