28 QString QgsFileDownloaderAlgorithm::name()
const 30 return QStringLiteral(
"filedownloader" );
33 QString QgsFileDownloaderAlgorithm::displayName()
const 35 return tr(
"Download file" );
38 QStringList QgsFileDownloaderAlgorithm::tags()
const 40 return tr(
"file,downloader,internet,url,fetch,get,https" ).split(
',' );
43 QString QgsFileDownloaderAlgorithm::group()
const 45 return tr(
"File tools" );
48 QString QgsFileDownloaderAlgorithm::groupId()
const 50 return QStringLiteral(
"filetools" );
53 QString QgsFileDownloaderAlgorithm::shortHelpString()
const 55 return tr(
"This algorithm downloads a URL on the file system." );
58 QgsFileDownloaderAlgorithm *QgsFileDownloaderAlgorithm::createInstance()
const 60 return new QgsFileDownloaderAlgorithm();
63 void QgsFileDownloaderAlgorithm::initAlgorithm(
const QVariantMap & )
67 tr(
"File destination" ), QObject::tr(
"All files (*.*)" ), QVariant(),
true ) );
73 QString url = parameterAsString( parameters, QStringLiteral(
"URL" ), context );
76 QString outputFile = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
85 connect( &timer, &QTimer::timeout,
this, &QgsFileDownloaderAlgorithm::sendProgressFeedback );
92 bool exists = QFileInfo::exists( outputFile );
97 outputs.insert( QStringLiteral(
"OUTPUT" ), exists ? outputFile : QString() );
101 void QgsFileDownloaderAlgorithm::reportErrors(
const QStringList &errors )
106 void QgsFileDownloaderAlgorithm::sendProgressFeedback()
108 if ( !mReceived.isEmpty() && mLastReport != mReceived )
110 mLastReport = mReceived;
111 if ( mTotal.isEmpty() )
112 mFeedback->pushInfo( tr(
"%1 downloaded." ).arg( mReceived ) );
114 mFeedback->pushInfo( tr(
"%1 of %2 downloaded." ).arg( mReceived, mTotal ) );
118 void QgsFileDownloaderAlgorithm::receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal )
121 if ( bytesTotal > 0 )
123 if ( mTotal.isEmpty() )
126 mFeedback->setProgress( ( bytesReceived * 100 ) / bytesTotal );
void startDownload()
Called to start the download.
Base class for providing feedback from a processing algorithm.
void canceled()
Internal routines can connect to this signal if they use event loop.
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
Custom exception class for processing related exceptions.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
QgsFileDownloader is a utility class for downloading files.
bool isCanceled() const
Tells whether the operation has been canceled already.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
Contains information about the context in which a processing algorithm is executed.
void cancelDownload()
Call to abort the download and delete this object after the cancellation has been processed...
void downloadExited()
Emitted always when the downloader exits.
A string parameter for processing algorithms.