projects
/
mdictionary
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
81f6d28
)
Added download progress notification
author
Mateusz Półrola
<mateusz.polrola@comarch.pl>
Tue, 5 Oct 2010 08:21:52 +0000
(10:21 +0200)
committer
Mateusz Półrola
<mateusz.polrola@comarch.pl>
Tue, 5 Oct 2010 08:21:52 +0000
(10:21 +0200)
src/plugins/xdxf/HttpDownloader.cpp
patch
|
blob
|
history
src/plugins/xdxf/HttpDownloader.h
patch
|
blob
|
history
src/plugins/xdxf/XdxfDialog.cpp
patch
|
blob
|
history
src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
patch
|
blob
|
history
src/plugins/xdxf/XdxfDictDownloadProgressDialog.h
patch
|
blob
|
history
src/plugins/xdxf/XdxfDictDownloader.cpp
patch
|
blob
|
history
src/plugins/xdxf/XdxfDictDownloader.h
patch
|
blob
|
history
diff --git
a/src/plugins/xdxf/HttpDownloader.cpp
b/src/plugins/xdxf/HttpDownloader.cpp
index
e693c92
..
54f8273
100644
(file)
--- 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)");
// 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) {
}
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;
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);
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);
}
else {
QFile resultFile(destFile);
diff --git
a/src/plugins/xdxf/HttpDownloader.h
b/src/plugins/xdxf/HttpDownloader.h
index
ec6ac27
..
76f27d1
100644
(file)
--- 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);
Q_SIGNALS:
void finished();
void error(QString);
+ void progress(qint64,qint64);
private:
QHttp *http;
QNetworkAccessManager *manager;
QString destFile;
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
(file)
--- a/
src/plugins/xdxf/XdxfDialog.cpp
+++ b/
src/plugins/xdxf/XdxfDialog.cpp
@@
-245,7
+245,6
@@
void XdxfDialog::selectFile() {
}
void XdxfDialog::downloadFile() {
}
void XdxfDialog::downloadFile() {
- qDebug()<<"a";
XdxfPlugin::dictDownloader.download(this);
}
XdxfPlugin::dictDownloader.download(this);
}
diff --git
a/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
b/src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
index
2e95783
..
9d730bf
100644
(file)
--- a/
src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
+++ b/
src/plugins/xdxf/XdxfDictDownloadProgressDialog.cpp
@@
-57,6
+57,10
@@
XdxfDictDownloadProgressDialog::XdxfDictDownloadProgressDialog(QWidget*parent):
#endif
}
#endif
}
+void XdxfDictDownloadProgressDialog::show() {
+ downloadProgressBar->setMaximum(0);
+ QDialog::show();
+}
void XdxfDictDownloadProgressDialog::setText(QString text) {
setWindowTitle(text);
void XdxfDictDownloadProgressDialog::setText(QString text) {
setWindowTitle(text);
@@
-65,6
+69,13
@@
void XdxfDictDownloadProgressDialog::setText(QString text) {
#endif
}
#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();
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
(file)
--- 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);
//! 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();
Q_SIGNALS:
//! signal emitted when user cancels downloading of a dictionary
void cancelDownloading();
+
private:
QLabel* downloadLabel;
QProgressBar* downloadProgressBar;
private:
QLabel* downloadLabel;
QProgressBar* downloadProgressBar;
diff --git
a/src/plugins/xdxf/XdxfDictDownloader.cpp
b/src/plugins/xdxf/XdxfDictDownloader.cpp
index
38066f4
..
908f1ef
100644
(file)
--- 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(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) {
}
void XdxfDictDownloader::download(QWidget *parent) {
@@
-62,6
+65,9
@@
void XdxfDictDownloader::download(QWidget *parent) {
connect(progressDialog, SIGNAL(cancelDownloading()),
this, SLOT(breakDownloading()));
connect(progressDialog, SIGNAL(cancelDownloading()),
this, SLOT(breakDownloading()));
+ connect(this, SIGNAL(downloadProgress(float)),
+ progressDialog, SLOT(updateProgress(float)));
+
progressDialog->setText(tr("Downloading dictionaries list"));
progressDialog->show();
}
progressDialog->setText(tr("Downloading dictionaries list"));
progressDialog->show();
}
@@
-70,6
+76,10
@@
QString XdxfDictDownloader::downloadedFile() {
return _downloadedFile;
}
return _downloadedFile;
}
+void XdxfDictDownloader::updateDownloadProgress(qint64 downloaded,
+ qint64 total) {
+ Q_EMIT downloadProgress(float(downloaded) / float(total));
+}
void XdxfDictDownloader::downloadingError(QString error) {
breakDownloading();
void XdxfDictDownloader::downloadingError(QString error) {
breakDownloading();
diff --git
a/src/plugins/xdxf/XdxfDictDownloader.h
b/src/plugins/xdxf/XdxfDictDownloader.h
index
2f7dd98
..
6d14407
100644
(file)
--- 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);
//! 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*);
private Q_SLOTS:
//! obtained list of dictionaries from website
void dictListReceived(QNetworkReply*);
@@
-76,6
+78,8
@@
private Q_SLOTS:
void downloadingError(QString);
void downloadingError(QString);
+ void updateDownloadProgress(qint64, qint64);
+
private:
//! dict is downloaded and unpacked
void downloadComplete();
private:
//! dict is downloaded and unpacked
void downloadComplete();