author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include <QtGui> |
|
42 |
#include <QtNetwork> |
|
43 |
||
44 |
#include "httpwindow.h" |
|
45 |
#include "ui_authenticationdialog.h" |
|
46 |
||
47 |
HttpWindow::HttpWindow(QWidget *parent) |
|
48 |
: QDialog(parent) |
|
49 |
{ |
|
50 |
#ifndef QT_NO_OPENSSL |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
51 |
urlLineEdit = new QLineEdit("https://qt.nokia.com/"); |
0 | 52 |
#else |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
53 |
urlLineEdit = new QLineEdit("http://qt.nokia.com/"); |
0 | 54 |
#endif |
55 |
||
56 |
urlLabel = new QLabel(tr("&URL:")); |
|
57 |
urlLabel->setBuddy(urlLineEdit); |
|
58 |
statusLabel = new QLabel(tr("Please enter the URL of a file you want to " |
|
59 |
"download.")); |
|
60 |
||
61 |
downloadButton = new QPushButton(tr("Download")); |
|
62 |
downloadButton->setDefault(true); |
|
63 |
quitButton = new QPushButton(tr("Quit")); |
|
64 |
quitButton->setAutoDefault(false); |
|
65 |
||
66 |
buttonBox = new QDialogButtonBox; |
|
67 |
buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole); |
|
68 |
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); |
|
69 |
||
70 |
progressDialog = new QProgressDialog(this); |
|
71 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
connect(urlLineEdit, SIGNAL(textChanged(QString)), |
0 | 73 |
this, SLOT(enableDownloadButton())); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
74 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
75 |
connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
76 |
this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*))); |
0 | 77 |
#ifndef QT_NO_OPENSSL |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
78 |
connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
79 |
this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); |
0 | 80 |
#endif |
81 |
connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); |
|
82 |
connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); |
|
83 |
connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); |
|
84 |
||
85 |
QHBoxLayout *topLayout = new QHBoxLayout; |
|
86 |
topLayout->addWidget(urlLabel); |
|
87 |
topLayout->addWidget(urlLineEdit); |
|
88 |
||
89 |
QVBoxLayout *mainLayout = new QVBoxLayout; |
|
90 |
mainLayout->addLayout(topLayout); |
|
91 |
mainLayout->addWidget(statusLabel); |
|
92 |
mainLayout->addWidget(buttonBox); |
|
93 |
setLayout(mainLayout); |
|
94 |
||
95 |
setWindowTitle(tr("HTTP")); |
|
96 |
urlLineEdit->setFocus(); |
|
97 |
} |
|
98 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
99 |
void HttpWindow::startRequest(QUrl url) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
100 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
101 |
reply = qnam.get(QNetworkRequest(url)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
102 |
connect(reply, SIGNAL(finished()), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
103 |
this, SLOT(httpFinished())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
104 |
connect(reply, SIGNAL(readyRead()), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
105 |
this, SLOT(httpReadyRead())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
106 |
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
107 |
this, SLOT(updateDataReadProgress(qint64,qint64))); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
108 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
109 |
|
0 | 110 |
void HttpWindow::downloadFile() |
111 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
112 |
url = urlLineEdit->text(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
113 |
|
0 | 114 |
QFileInfo fileInfo(url.path()); |
115 |
QString fileName = fileInfo.fileName(); |
|
116 |
if (fileName.isEmpty()) |
|
117 |
fileName = "index.html"; |
|
118 |
||
119 |
if (QFile::exists(fileName)) { |
|
120 |
if (QMessageBox::question(this, tr("HTTP"), |
|
121 |
tr("There already exists a file called %1 in " |
|
122 |
"the current directory. Overwrite?").arg(fileName), |
|
123 |
QMessageBox::Yes|QMessageBox::No, QMessageBox::No) |
|
124 |
== QMessageBox::No) |
|
125 |
return; |
|
126 |
QFile::remove(fileName); |
|
127 |
} |
|
128 |
||
129 |
file = new QFile(fileName); |
|
130 |
if (!file->open(QIODevice::WriteOnly)) { |
|
131 |
QMessageBox::information(this, tr("HTTP"), |
|
132 |
tr("Unable to save the file %1: %2.") |
|
133 |
.arg(fileName).arg(file->errorString())); |
|
134 |
delete file; |
|
135 |
file = 0; |
|
136 |
return; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
progressDialog->setWindowTitle(tr("HTTP")); |
|
141 |
progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); |
|
142 |
downloadButton->setEnabled(false); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
143 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
144 |
// schedule the request |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
145 |
httpRequestAborted = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
146 |
startRequest(url); |
0 | 147 |
} |
148 |
||
149 |
void HttpWindow::cancelDownload() |
|
150 |
{ |
|
151 |
statusLabel->setText(tr("Download canceled.")); |
|
152 |
httpRequestAborted = true; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
153 |
reply->abort(); |
0 | 154 |
downloadButton->setEnabled(true); |
155 |
} |
|
156 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
157 |
void HttpWindow::httpFinished() |
0 | 158 |
{ |
159 |
if (httpRequestAborted) { |
|
160 |
if (file) { |
|
161 |
file->close(); |
|
162 |
file->remove(); |
|
163 |
delete file; |
|
164 |
file = 0; |
|
165 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
166 |
reply->deleteLater(); |
0 | 167 |
progressDialog->hide(); |
168 |
return; |
|
169 |
} |
|
170 |
||
171 |
progressDialog->hide(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
172 |
file->flush(); |
0 | 173 |
file->close(); |
174 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
175 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
176 |
QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
177 |
if (reply->error()) { |
0 | 178 |
file->remove(); |
179 |
QMessageBox::information(this, tr("HTTP"), |
|
180 |
tr("Download failed: %1.") |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
181 |
.arg(reply->errorString())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
182 |
downloadButton->setEnabled(true); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
183 |
} else if (!redirectionTarget.isNull()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
184 |
QUrl newUrl = url.resolved(redirectionTarget.toUrl()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
185 |
if (QMessageBox::question(this, tr("HTTP"), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
186 |
tr("Redirect to %1 ?").arg(newUrl.toString()), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
187 |
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
188 |
url = newUrl; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
189 |
reply->deleteLater(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
190 |
file->open(QIODevice::WriteOnly); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
191 |
file->resize(0); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
192 |
startRequest(url); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
193 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
194 |
} |
0 | 195 |
} else { |
196 |
QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); |
|
197 |
statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
198 |
downloadButton->setEnabled(true); |
0 | 199 |
} |
200 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
201 |
reply->deleteLater(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
202 |
reply = 0; |
0 | 203 |
delete file; |
204 |
file = 0; |
|
205 |
} |
|
206 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
207 |
void HttpWindow::httpReadyRead() |
0 | 208 |
{ |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
209 |
// this slot gets called everytime the QNetworkReply has new data. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
210 |
// We read all of its new data and write it into the file. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
211 |
// That way we use less RAM than when reading it at the finished() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
212 |
// signal of the QNetworkReply |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
213 |
if (file) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
214 |
file->write(reply->readAll()); |
0 | 215 |
} |
216 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
217 |
void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes) |
0 | 218 |
{ |
219 |
if (httpRequestAborted) |
|
220 |
return; |
|
221 |
||
222 |
progressDialog->setMaximum(totalBytes); |
|
223 |
progressDialog->setValue(bytesRead); |
|
224 |
} |
|
225 |
||
226 |
void HttpWindow::enableDownloadButton() |
|
227 |
{ |
|
228 |
downloadButton->setEnabled(!urlLineEdit->text().isEmpty()); |
|
229 |
} |
|
230 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
231 |
void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator) |
0 | 232 |
{ |
233 |
QDialog dlg; |
|
234 |
Ui::Dialog ui; |
|
235 |
ui.setupUi(&dlg); |
|
236 |
dlg.adjustSize(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
237 |
ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
238 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
239 |
// Did the URL have information? Fill the UI |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
240 |
// This is only relevant if the URL-supplied credentials were wrong |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
241 |
ui.userEdit->setText(url.userName()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
242 |
ui.passwordEdit->setText(url.password()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
243 |
|
0 | 244 |
if (dlg.exec() == QDialog::Accepted) { |
245 |
authenticator->setUser(ui.userEdit->text()); |
|
246 |
authenticator->setPassword(ui.passwordEdit->text()); |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
#ifndef QT_NO_OPENSSL |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
251 |
void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors) |
0 | 252 |
{ |
253 |
QString errorString; |
|
254 |
foreach (const QSslError &error, errors) { |
|
255 |
if (!errorString.isEmpty()) |
|
256 |
errorString += ", "; |
|
257 |
errorString += error.errorString(); |
|
258 |
} |
|
259 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
260 |
if (QMessageBox::warning(this, tr("HTTP"), |
0 | 261 |
tr("One or more SSL errors has occurred: %1").arg(errorString), |
262 |
QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
263 |
reply->ignoreSslErrors(); |
0 | 264 |
} |
265 |
} |
|
266 |
#endif |