author | unc0rr |
Sun, 04 Sep 2011 11:48:01 +0400 | |
changeset 5754 | 583b7a683b17 |
parent 5746 | fbc52bb92cad |
child 5755 | a079b4dea081 |
permissions | -rw-r--r-- |
5271 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QGridLayout> |
|
20 |
#include <QPushButton> |
|
5567
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
21 |
#include <QNetworkAccessManager> |
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
22 |
#include <QNetworkRequest> |
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
23 |
#include <QNetworkReply> |
5567
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
24 |
#include <QFileInfo> |
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
25 |
#include <QFileDialog> |
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
26 |
#include <QTextBrowser> |
5754 | 27 |
#include <QDebug> |
28 |
#include <QProgressBar> |
|
5271 | 29 |
|
30 |
#include "pagedata.h" |
|
31 |
||
5754 | 32 |
#include "quazip.h" |
33 |
||
5271 | 34 |
PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent) |
35 |
{ |
|
36 |
QGridLayout * pageLayout = new QGridLayout(this); |
|
37 |
pageLayout->setColumnStretch(0, 1); |
|
38 |
pageLayout->setColumnStretch(1, 1); |
|
39 |
pageLayout->setColumnStretch(2, 1); |
|
40 |
||
5754 | 41 |
BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
5271 | 42 |
|
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
43 |
web = new QTextBrowser(this); |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
44 |
connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(install(const QUrl&))); |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
45 |
web->setOpenLinks(false); |
5271 | 46 |
pageLayout->addWidget(web, 0, 0, 1, 3); |
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
47 |
|
5754 | 48 |
progressBarsLayout = new QVBoxLayout(this); |
49 |
pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3); |
|
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
50 |
|
5754 | 51 |
fetchList(); |
5271 | 52 |
} |
5567
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
53 |
|
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
54 |
void PageDataDownload::install(const QUrl &url) |
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
55 |
{ |
5754 | 56 |
qWarning() << "Download Request" << url.toString(); |
57 |
QString fileName = QFileInfo(url.toString()).fileName(); |
|
58 |
||
59 |
QNetworkRequest newRequest(url); |
|
60 |
newRequest.setAttribute(QNetworkRequest::User, fileName); |
|
5567
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
61 |
|
5754 | 62 |
QNetworkAccessManager *manager = new QNetworkAccessManager(this); |
63 |
QNetworkReply *reply = manager->get(newRequest); |
|
64 |
connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded())); |
|
65 |
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); |
|
5567
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
66 |
|
5754 | 67 |
QProgressBar *progressBar = new QProgressBar(this); |
68 |
progressBarsLayout->addWidget(progressBar); |
|
69 |
progressBars.insert(reply, progressBar); |
|
5567
44c9a577b082
Tiny bit of progress on download page - hooked it up to "Info" button for now.
nemo
parents:
5271
diff
changeset
|
70 |
} |
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
71 |
|
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
72 |
|
5754 | 73 |
void PageDataDownload::pageDownloaded() |
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
74 |
{ |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
75 |
QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
76 |
|
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
77 |
if(reply) |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
78 |
{ |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
79 |
web->setHtml(QString::fromUtf8(reply->readAll())); |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
80 |
} |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
81 |
} |
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
82 |
|
5754 | 83 |
void PageDataDownload::fileDownloaded() |
84 |
{ |
|
85 |
QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
|
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
86 |
|
5754 | 87 |
if(reply) |
88 |
{ |
|
89 |
QByteArray fileContents = reply->readAll(); |
|
90 |
QProgressBar *progressBar = progressBars.value(reply, 0); |
|
91 |
||
92 |
if(progressBar) |
|
93 |
{ |
|
94 |
progressBars.remove(reply); |
|
95 |
progressBar->deleteLater(); |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
void PageDataDownload::downloadProgress(qint64 bytesRecieved, qint64 bytesTotal) |
|
101 |
{ |
|
102 |
QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender()); |
|
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
103 |
|
5754 | 104 |
if(reply) |
105 |
{ |
|
106 |
QProgressBar *progressBar = progressBars.value(reply, 0); |
|
5746
fbc52bb92cad
Use QTextBrowser instead of WebKit for downloadable contents page (currently only shows the page itself)
unc0rr
parents:
5582
diff
changeset
|
107 |
|
5754 | 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 |
} |