QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsfiledownloaderdialog.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsfiledownloaderdialog.cpp
3
--------------------------------------
4
Date : November 2016
5
Copyright : (C) 2016 by Alessandro Pasotti
6
Email : apasotti at boundlessgeo dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsfiledownloaderdialog.h
"
17
18
#include "
qgsfiledownloader.h
"
19
#include "
qgsfileutils.h
"
20
21
#include <QMessageBox>
22
#include <QString>
23
24
#include "moc_qgsfiledownloaderdialog.cpp"
25
26
using namespace
Qt::StringLiterals;
27
28
QgsFileDownloaderDialog::QgsFileDownloaderDialog
(
const
QUrl &url,
const
QString &outputFileName,
const
QString &authcfg )
29
: mOutputFileName( outputFileName )
30
, mDownloader( new
QgsFileDownloader
( url, outputFileName, authcfg, true ) )
31
{
32
setWindowTitle( tr(
"Download"
) );
33
setLabelText( tr(
"Downloading %1."
).arg( outputFileName ) );
34
show();
35
36
connect(
this
, &QProgressDialog::canceled, mDownloader, &
QgsFileDownloader::cancelDownload
);
37
connect( mDownloader, &
QgsFileDownloader::downloadError
,
this
, &QgsFileDownloaderDialog::onError );
38
connect( mDownloader, &
QgsFileDownloader::downloadProgress
,
this
, &QgsFileDownloaderDialog::onDownloadProgress );
39
connect( mDownloader, &
QgsFileDownloader::downloadExited
,
this
, &QgsFileDownloaderDialog::deleteLater );
40
41
connect( mDownloader, &
QgsFileDownloader::downloadCompleted
,
this
, &
QgsFileDownloaderDialog::downloadCompleted
);
42
connect( mDownloader, &
QgsFileDownloader::downloadCanceled
,
this
, &
QgsFileDownloaderDialog::downloadCanceled
);
43
connect( mDownloader, &
QgsFileDownloader::downloadExited
,
this
, &
QgsFileDownloaderDialog::downloadExited
);
44
connect( mDownloader, &
QgsFileDownloader::downloadError
,
this
, &
QgsFileDownloaderDialog::downloadError
);
45
connect( mDownloader, &
QgsFileDownloader::downloadProgress
,
this
, &
QgsFileDownloaderDialog::downloadProgress
);
46
mDownloader->startDownload();
47
}
48
49
void
QgsFileDownloaderDialog::onError(
const
QStringList &errors )
50
{
51
QMessageBox::warning(
nullptr
, tr(
"Download File"
), errors.join(
"<br>"
_L1 ) );
52
}
53
54
void
QgsFileDownloaderDialog::onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
55
{
56
setMaximum( bytesTotal );
57
setValue( bytesReceived );
58
setLabelText( tr(
"Downloading %1 of %2 %3."
).arg(
QgsFileUtils::representFileSize
( bytesReceived ),
QgsFileUtils::representFileSize
( bytesTotal ), mOutputFileName ) );
59
}
QgsFileDownloaderDialog::downloadCompleted
void downloadCompleted()
Emitted when the download has completed successfully.
QgsFileDownloaderDialog::QgsFileDownloaderDialog
QgsFileDownloaderDialog(const QUrl &url, const QString &outputFileName, const QString &authcfg=QString())
QgsFileDownloader.
Definition
qgsfiledownloaderdialog.cpp:28
QgsFileDownloaderDialog::downloadExited
void downloadExited()
Emitted always when the downloader exits.
QgsFileDownloaderDialog::downloadError
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
QgsFileDownloaderDialog::downloadCanceled
void downloadCanceled()
Emitted when the download was canceled by the user.
QgsFileDownloaderDialog::downloadProgress
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
QgsFileDownloader
A utility class for downloading files.
Definition
qgsfiledownloader.h:46
QgsFileDownloader::cancelDownload
void cancelDownload()
Call to abort the download and delete this object after the cancellation has been processed.
Definition
qgsfiledownloader.cpp:116
QgsFileDownloader::downloadExited
void downloadExited()
Emitted always when the downloader exits.
QgsFileDownloader::downloadCanceled
void downloadCanceled()
Emitted when the download was canceled by the user.
QgsFileDownloader::downloadError
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
QgsFileDownloader::downloadCompleted
void downloadCompleted(const QUrl &url)
Emitted when the download has completed successfully.
QgsFileDownloader::downloadProgress
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
QgsFileUtils::representFileSize
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
Definition
qgsfileutils.cpp:49
qgsfiledownloader.h
qgsfiledownloaderdialog.h
qgsfileutils.h
Generated on
for QGIS API Documentation by
1.17.0