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 );
74 QString outputFile = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
83 connect( &timer, &QTimer::timeout,
this, &QgsFileDownloaderAlgorithm::sendProgressFeedback );
90 bool exists = QFileInfo::exists( outputFile );
95 outputs.insert( QStringLiteral(
"OUTPUT" ), exists ? outputFile : QString() );
99 void QgsFileDownloaderAlgorithm::reportErrors(
const QStringList &errors )
104 void QgsFileDownloaderAlgorithm::sendProgressFeedback()
106 if ( !mReceived.isEmpty() && mLastReport != mReceived )
108 mLastReport = mReceived;
109 if ( mTotal.isEmpty() )
110 mFeedback->pushInfo( tr(
"%1 downloaded." ).arg( mReceived ) );
112 mFeedback->pushInfo( tr(
"%1 of %2 downloaded." ).arg( mReceived, mTotal ) );
116 void QgsFileDownloaderAlgorithm::receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal )
119 if ( bytesTotal > 0 )
121 if ( mTotal.isEmpty() )
124 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)
Return 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 cancelation has been processed.
void downloadExited()
Emitted always when the downloader exits.
A string parameter for processing algorithms.