QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
17 #include "qgsfiledownloader.h"
18 #include "qgsfileutils.h"
19 #include <QMessageBox>
20 
21 QgsFileDownloaderDialog::QgsFileDownloaderDialog( const QUrl &url, const QString &outputFileName, const QString &authcfg )
22  : mOutputFileName( outputFileName ),
23  mDownloader( new QgsFileDownloader( url, outputFileName, authcfg, true ) )
24 {
25  setWindowTitle( tr( "Download" ) );
26  setLabelText( tr( "Downloading %1." ).arg( outputFileName ) );
27  show();
28 
29  connect( this, &QProgressDialog::canceled, mDownloader, &QgsFileDownloader::cancelDownload );
30  connect( mDownloader, &QgsFileDownloader::downloadError, this, &QgsFileDownloaderDialog::onError );
31  connect( mDownloader, &QgsFileDownloader::downloadProgress, this, &QgsFileDownloaderDialog::onDownloadProgress );
32  connect( mDownloader, &QgsFileDownloader::downloadExited, this, &QgsFileDownloaderDialog::deleteLater );
33 
39  mDownloader->startDownload();
40 }
41 
42 void QgsFileDownloaderDialog::onError( const QStringList &errors )
43 {
44  QMessageBox::warning( nullptr, tr( "Download File" ), errors.join( QLatin1String( "<br>" ) ) );
45 }
46 
47 void QgsFileDownloaderDialog::onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
48 {
49  setMaximum( bytesTotal );
50  setValue( bytesReceived );
51  setLabelText( tr( "Downloading %1 of %2 %3." ).arg( QgsFileUtils::representFileSize( bytesReceived ), QgsFileUtils::representFileSize( bytesTotal ), mOutputFileName ) );
52 }
53 
QgsFileDownloaderDialog::downloadError
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
QgsFileDownloader
QgsFileDownloader is a utility class for downloading files.
Definition: qgsfiledownloader.h:44
QgsFileDownloader::startDownload
void startDownload()
Called to start the download.
Definition: qgsfiledownloader.cpp:49
QgsFileDownloader::downloadExited
void downloadExited()
Emitted always when the downloader exits.
QgsFileDownloaderDialog::downloadProgress
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
QgsFileDownloaderDialog::QgsFileDownloaderDialog
QgsFileDownloaderDialog(const QUrl &url, const QString &outputFileName, const QString &authcfg=QString())
QgsFileDownloader.
Definition: qgsfiledownloaderdialog.cpp:21
QgsFileDownloader::downloadProgress
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
QgsFileDownloaderDialog::downloadExited
void downloadExited()
Emitted always when the downloader exits.
qgsfileutils.h
QgsFileDownloader::downloadCanceled
void downloadCanceled()
Emitted when the download was canceled by the user.
QgsFileDownloaderDialog::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.
qgsfiledownloaderdialog.h
QgsFileUtils::representFileSize
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
Definition: qgsfileutils.cpp:24
QgsFileDownloader::downloadCompleted
void downloadCompleted()
Emitted when the download has completed successfully.
QgsFileDownloader::cancelDownload
void cancelDownload()
Call to abort the download and delete this object after the cancellation has been processed.
Definition: qgsfiledownloader.cpp:84
qgsfiledownloader.h
QgsFileDownloaderDialog::downloadCompleted
void downloadCompleted()
Emitted when the download has completed successfully.