22 #include <QNetworkRequest> |
22 #include <QNetworkRequest> |
23 #include <QNetworkReply> |
23 #include <QNetworkReply> |
24 #include <QFileInfo> |
24 #include <QFileInfo> |
25 #include <QFileDialog> |
25 #include <QFileDialog> |
26 #include <QTextBrowser> |
26 #include <QTextBrowser> |
27 |
27 #include <QDebug> |
|
28 #include <QProgressBar> |
28 |
29 |
29 #include "pagedata.h" |
30 #include "pagedata.h" |
|
31 |
|
32 #include "quazip.h" |
30 |
33 |
31 PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent) |
34 PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent) |
32 { |
35 { |
33 QGridLayout * pageLayout = new QGridLayout(this); |
36 QGridLayout * pageLayout = new QGridLayout(this); |
34 pageLayout->setColumnStretch(0, 1); |
37 pageLayout->setColumnStretch(0, 1); |
35 pageLayout->setColumnStretch(1, 1); |
38 pageLayout->setColumnStretch(1, 1); |
36 pageLayout->setColumnStretch(2, 1); |
39 pageLayout->setColumnStretch(2, 1); |
37 |
40 |
38 BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true); |
41 BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
39 |
42 |
40 web = new QTextBrowser(this); |
43 web = new QTextBrowser(this); |
41 connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(install(const QUrl&))); |
44 connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(install(const QUrl&))); |
42 web->setOpenLinks(false); |
45 web->setOpenLinks(false); |
43 //web->setSource(); |
|
44 //web->load(QUrl("http://m8y.org/hw/downloads/")); |
|
45 //web->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); |
|
46 pageLayout->addWidget(web, 0, 0, 1, 3); |
46 pageLayout->addWidget(web, 0, 0, 1, 3); |
47 |
47 |
|
48 progressBarsLayout = new QVBoxLayout(this); |
|
49 pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3); |
48 |
50 |
49 QNetworkRequest newRequest(QUrl("http://m8y.org/hw/downloads/index.xhtml")); |
51 fetchList(); |
50 //newRequest.setAttribute(QNetworkRequest::User, fileName); |
|
51 |
|
52 QNetworkAccessManager *manager = new QNetworkAccessManager(this); |
|
53 QNetworkReply *reply = manager->get(newRequest); |
|
54 connect(reply, SIGNAL(finished()), this, SLOT(downloadIssueFinished())); |
|
55 } |
52 } |
56 |
53 |
57 void PageDataDownload::install(const QUrl &url) |
54 void PageDataDownload::install(const QUrl &url) |
58 { |
55 { |
59 qWarning("Download Request"); |
56 qWarning() << "Download Request" << url.toString(); |
60 QString fileName = QFileInfo(url.toString()).fileName(); |
57 QString fileName = QFileInfo(url.toString()).fileName(); |
61 |
58 |
62 QNetworkRequest newRequest(url); |
59 QNetworkRequest newRequest(url); |
63 newRequest.setAttribute(QNetworkRequest::User, fileName); |
60 newRequest.setAttribute(QNetworkRequest::User, fileName); |
64 |
61 |
65 QNetworkAccessManager *manager = new QNetworkAccessManager(this); |
62 QNetworkAccessManager *manager = new QNetworkAccessManager(this); |
66 QNetworkReply *reply = manager->get(newRequest); |
63 QNetworkReply *reply = manager->get(newRequest); |
67 //connect( reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)) ); |
64 connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded())); |
|
65 connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); |
|
66 |
|
67 QProgressBar *progressBar = new QProgressBar(this); |
|
68 progressBarsLayout->addWidget(progressBar); |
|
69 progressBars.insert(reply, progressBar); |
68 } |
70 } |
69 |
71 |
70 |
72 |
71 void PageDataDownload::downloadIssueFinished() |
73 void PageDataDownload::pageDownloaded() |
72 { |
74 { |
73 QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
75 QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
74 |
76 |
75 if(reply) |
77 if(reply) |
76 { |
78 { |
77 web->setHtml(QString::fromUtf8(reply->readAll())); |
79 web->setHtml(QString::fromUtf8(reply->readAll())); |
78 } |
80 } |
79 } |
81 } |
80 |
82 |
|
83 void PageDataDownload::fileDownloaded() |
|
84 { |
|
85 QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
81 |
86 |
|
87 if(reply) |
|
88 { |
|
89 QByteArray fileContents = reply->readAll(); |
|
90 QProgressBar *progressBar = progressBars.value(reply, 0); |
82 |
91 |
|
92 if(progressBar) |
|
93 { |
|
94 progressBars.remove(reply); |
|
95 progressBar->deleteLater(); |
|
96 } |
|
97 } |
|
98 } |
83 |
99 |
|
100 void PageDataDownload::downloadProgress(qint64 bytesRecieved, qint64 bytesTotal) |
|
101 { |
|
102 QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
|
103 |
|
104 if(reply) |
|
105 { |
|
106 QProgressBar *progressBar = progressBars.value(reply, 0); |
|
107 |
|
108 if(progressBar) |
|
109 { |
|
110 progressBar->setValue(bytesRecieved); |
|
111 progressBar->setMaximum(bytesTotal); |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 void PageDataDownload::fetchList() |
|
117 { |
|
118 QNetworkRequest newRequest(QUrl("http://hedgewars.org/download.html")); |
|
119 |
|
120 QNetworkAccessManager *manager = new QNetworkAccessManager(this); |
|
121 QNetworkReply *reply = manager->get(newRequest); |
|
122 connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded())); |
|
123 } |