From a741d92096aaecbb9f9b3bd61c6ed4d92d0a4d5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mateusz=20P=C3=B3=C5=82rola?= Date: Tue, 5 Oct 2010 10:21:52 +0200 Subject: [PATCH] Added download progress notification --- src/plugins/xdxf/HttpDownloader.cpp | 10 ++++++++-- src/plugins/xdxf/HttpDownloader.h | 2 ++ src/plugins/xdxf/XdxfDialog.cpp | 1 - .../xdxf/XdxfDictDownloadProgressDialog.cpp | 11 +++++++++++ src/plugins/xdxf/XdxfDictDownloadProgressDialog.h | 5 +++++ src/plugins/xdxf/XdxfDictDownloader.cpp | 10 ++++++++++ src/plugins/xdxf/XdxfDictDownloader.h | 4 ++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/plugins/xdxf/HttpDownloader.cpp b/src/plugins/xdxf/HttpDownloader.cpp index e693c92..54f8273 100644 --- a/src/plugins/xdxf/HttpDownloader.cpp +++ b/src/plugins/xdxf/HttpDownloader.cpp @@ -46,12 +46,16 @@ void HttpDownloader::download(QUrl url, QString file) { // Following line is crucial becouse sourceforge wont redirect correctly // if no user-agent is supplied request.setRawHeader("User-Agent", "Wget/1.12 (linux-gnu)"); - manager->get(request); + currentReply = manager->get(request); + connect(currentReply, SIGNAL(downloadProgress(qint64,qint64)), + this, SIGNAL(progress(qint64,qint64))); } void HttpDownloader::downloadFinished(QNetworkReply *reply) { + disconnect(reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SIGNAL(progress(qint64,qint64))); if(reply->error() != QNetworkReply::NoError) { Q_EMIT error(reply->errorString()); return; @@ -65,7 +69,9 @@ void HttpDownloader::downloadFinished(QNetworkReply *reply) { QNetworkRequest req; req.setRawHeader("User-Agent", "Wget/1.12 (linux-gnu)"); req.setUrl(r); - manager->get(req); + currentReply = manager->get(req); + connect(currentReply, SIGNAL(downloadProgress(qint64,qint64)), + this, SIGNAL(progress(qint64,qint64))); } else { QFile resultFile(destFile); diff --git a/src/plugins/xdxf/HttpDownloader.h b/src/plugins/xdxf/HttpDownloader.h index ec6ac27..76f27d1 100644 --- a/src/plugins/xdxf/HttpDownloader.h +++ b/src/plugins/xdxf/HttpDownloader.h @@ -49,11 +49,13 @@ private Q_SLOTS: Q_SIGNALS: void finished(); void error(QString); + void progress(qint64,qint64); private: QHttp *http; QNetworkAccessManager *manager; QString destFile; + QNetworkReply* currentReply; }; diff --git a/src/plugins/xdxf/XdxfDialog.cpp b/src/plugins/xdxf/XdxfDialog.cpp index 4a918e2..f89b92b 100644 --- a/src/plugins/xdxf/XdxfDialog.cpp +++ b/src/plugins/xdxf/XdxfDialog.cpp @@ -245,7 +245,6 @@ void XdxfDialog::selectFile() { } void XdxfDialog::downloadFile() { - qDebug()<<"a"; XdxfPlugin::dictDownloader.download(this); } diff --git a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp index 2e95783..9d730bf 100644 --- a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp +++ b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp @@ -57,6 +57,10 @@ XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QWidget*parent): #endif } +void XdxfDictDownloadProgressDialog::show() { + downloadProgressBar->setMaximum(0); + QDialog::show(); +} void XdxfDictDownloadProgressDialog::setText(QString text) { setWindowTitle(text); @@ -65,6 +69,13 @@ void XdxfDictDownloadProgressDialog::setText(QString text) { #endif } +void XdxfDictDownloadProgressDialog::updateProgress(float progress) { + if(downloadProgressBar->maximum() == 0) { + downloadProgressBar->setMaximum(100); + } + downloadProgressBar->setValue(progress*100); +} + void XdxfDictDownloadProgressDialog::reject() { #ifndef Q_WS_MAEMO_5 Q_EMIT cancelDownloading(); diff --git a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h index bce23c0..9238901 100644 --- a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h +++ b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.h @@ -46,10 +46,15 @@ public Q_SLOTS: //! Set text which will be displayed to user as info about current download void setText(QString); + void updateProgress(float progress); + + void show(); + Q_SIGNALS: //! signal emitted when user cancels downloading of a dictionary void cancelDownloading(); + private: QLabel* downloadLabel; QProgressBar* downloadProgressBar; diff --git a/src/plugins/xdxf/XdxfDictDownloader.cpp b/src/plugins/xdxf/XdxfDictDownloader.cpp index 38066f4..908f1ef 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.cpp +++ b/src/plugins/xdxf/XdxfDictDownloader.cpp @@ -50,6 +50,9 @@ XdxfDictDownloader::XdxfDictDownloader(QObject *parent) : connect(&http, SIGNAL(finished()), this, SLOT(processFinished())); connect(&http, SIGNAL(error(QString)), this, SLOT(downloadingError(QString))); + connect(&http, SIGNAL(progress(qint64,qint64)), + this, SLOT(updateDownloadProgress(qint64,qint64))); + } void XdxfDictDownloader::download(QWidget *parent) { @@ -62,6 +65,9 @@ void XdxfDictDownloader::download(QWidget *parent) { connect(progressDialog, SIGNAL(cancelDownloading()), this, SLOT(breakDownloading())); + connect(this, SIGNAL(downloadProgress(float)), + progressDialog, SLOT(updateProgress(float))); + progressDialog->setText(tr("Downloading dictionaries list")); progressDialog->show(); } @@ -70,6 +76,10 @@ QString XdxfDictDownloader::downloadedFile() { return _downloadedFile; } +void XdxfDictDownloader::updateDownloadProgress(qint64 downloaded, + qint64 total) { + Q_EMIT downloadProgress(float(downloaded) / float(total)); +} void XdxfDictDownloader::downloadingError(QString error) { breakDownloading(); diff --git a/src/plugins/xdxf/XdxfDictDownloader.h b/src/plugins/xdxf/XdxfDictDownloader.h index 2f7dd98..6d14407 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.h +++ b/src/plugins/xdxf/XdxfDictDownloader.h @@ -64,6 +64,8 @@ Q_SIGNALS: //! emitted to inform user about errors and warnings void notify(Notify::NotifyType, QString); + void downloadProgress(float); + private Q_SLOTS: //! obtained list of dictionaries from website void dictListReceived(QNetworkReply*); @@ -76,6 +78,8 @@ private Q_SLOTS: void downloadingError(QString); + void updateDownloadProgress(qint64, qint64); + private: //! dict is downloaded and unpacked void downloadComplete(); -- 1.7.9.5