--- a/QTfrontend/pagedata.cpp Sun Sep 04 10:58:42 2011 +0400
+++ b/QTfrontend/pagedata.cpp Sun Sep 04 11:48:01 2011 +0400
@@ -24,10 +24,13 @@
#include <QFileInfo>
#include <QFileDialog>
#include <QTextBrowser>
-
+#include <QDebug>
+#include <QProgressBar>
#include "pagedata.h"
+#include "quazip.h"
+
PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent)
{
QGridLayout * pageLayout = new QGridLayout(this);
@@ -35,40 +38,39 @@
pageLayout->setColumnStretch(1, 1);
pageLayout->setColumnStretch(2, 1);
- BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
+ BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
web = new QTextBrowser(this);
connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(install(const QUrl&)));
web->setOpenLinks(false);
- //web->setSource();
- //web->load(QUrl("http://m8y.org/hw/downloads/"));
- //web->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
pageLayout->addWidget(web, 0, 0, 1, 3);
-
- QNetworkRequest newRequest(QUrl("http://m8y.org/hw/downloads/index.xhtml"));
- //newRequest.setAttribute(QNetworkRequest::User, fileName);
+ progressBarsLayout = new QVBoxLayout(this);
+ pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3);
- QNetworkAccessManager *manager = new QNetworkAccessManager(this);
- QNetworkReply *reply = manager->get(newRequest);
- connect(reply, SIGNAL(finished()), this, SLOT(downloadIssueFinished()));
+ fetchList();
}
void PageDataDownload::install(const QUrl &url)
{
-qWarning("Download Request");
-QString fileName = QFileInfo(url.toString()).fileName();
+ qWarning() << "Download Request" << url.toString();
+ QString fileName = QFileInfo(url.toString()).fileName();
+
+ QNetworkRequest newRequest(url);
+ newRequest.setAttribute(QNetworkRequest::User, fileName);
-QNetworkRequest newRequest(url);
-newRequest.setAttribute(QNetworkRequest::User, fileName);
+ QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+ QNetworkReply *reply = manager->get(newRequest);
+ connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded()));
+ connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
-QNetworkAccessManager *manager = new QNetworkAccessManager(this);
-QNetworkReply *reply = manager->get(newRequest);
-//connect( reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)) );
+ QProgressBar *progressBar = new QProgressBar(this);
+ progressBarsLayout->addWidget(progressBar);
+ progressBars.insert(reply, progressBar);
}
-void PageDataDownload::downloadIssueFinished()
+void PageDataDownload::pageDownloaded()
{
QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
@@ -78,6 +80,44 @@
}
}
+void PageDataDownload::fileDownloaded()
+{
+ QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
+ if(reply)
+ {
+ QByteArray fileContents = reply->readAll();
+ QProgressBar *progressBar = progressBars.value(reply, 0);
+
+ if(progressBar)
+ {
+ progressBars.remove(reply);
+ progressBar->deleteLater();
+ }
+ }
+}
+
+void PageDataDownload::downloadProgress(qint64 bytesRecieved, qint64 bytesTotal)
+{
+ QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
+ if(reply)
+ {
+ QProgressBar *progressBar = progressBars.value(reply, 0);
+ if(progressBar)
+ {
+ progressBar->setValue(bytesRecieved);
+ progressBar->setMaximum(bytesTotal);
+ }
+ }
+}
+
+void PageDataDownload::fetchList()
+{
+ QNetworkRequest newRequest(QUrl("http://hedgewars.org/download.html"));
+
+ QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+ QNetworkReply *reply = manager->get(newRequest);
+ connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded()));
+}