2
* \file downloaddialog.cpp
3
* Dialog displayed during a download.
9
* Copyright (C) 2008-2009 Urs Fleisch
11
* This file is part of Kid3.
13
* Kid3 is free software; you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation; either version 2 of the License, or
16
* (at your option) any later version.
18
* Kid3 is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include "downloaddialog.h"
28
#include "httpclient.h"
30
#include "qtcompatmac.h"
35
* @param parent parent widget
36
* @param caption dialog title
38
DownloadDialog::DownloadDialog(QWidget* parent, const QString& caption) :
39
QProgressDialog(parent), m_client(0)
41
QCM_setWindowTitle(caption);
42
connect(this, SIGNAL(canceled()),
43
this, SLOT(cancelDownload()));
49
DownloadDialog::~DownloadDialog()
56
* Display message in status bar.
58
* @param msg status message
59
* @param receivedBytes bytes received
60
* @param totalBytes total bytes
62
void DownloadDialog::updateProgressStatus(const QString& msg,
63
int receivedBytes, int totalBytes)
65
setLabelText(m_url + '\n' + msg);
66
if (receivedBytes >= 0 && totalBytes >= 0) {
67
#if QT_VERSION >= 0x040000
68
setRange(0, totalBytes);
69
setValue(receivedBytes);
71
setProgress(receivedBytes, totalBytes);
77
* Send a download request.
79
* @param hostName server
80
* @param path path on server
82
void DownloadDialog::startDownload(const QString& hostName, const QString& path)
85
m_client = new HttpClient;
86
connect(m_client, SIGNAL(bytesReceived(const QByteArray&)),
87
this, SLOT(requestFinished(const QByteArray&)));
88
connect(m_client, SIGNAL(progress(const QString&, int, int)),
89
this, SLOT(updateProgressStatus(const QString&, int, int)));
96
updateProgressStatus(i18n("Ready."),
97
HttpClient::CS_RequestConnection,
98
HttpClient::CS_EstimatedBytes);
99
m_client->sendRequest(hostName, path);
106
void DownloadDialog::cancelDownload()
114
* Handle response when request is finished.
115
* downloadFinished() is emitted.
117
* @param data received data
119
void DownloadDialog::requestFinished(const QByteArray& data)
121
if (!wasCanceled()) {
122
emit downloadFinished(data, m_client->getContentType(), m_url);