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 );
 
   87   connect( &timer, &QTimer::timeout, 
this, &QgsFileDownloaderAlgorithm::sendProgressFeedback );
 
   94   bool exists = QFileInfo::exists( outputFile );
 
   98   url = downloadedUrl.toDisplayString();
 
   99   feedback->
pushInfo( QObject::tr( 
"Successfully downloaded %1" ).arg( url ) );
 
  104     const int length = url.size();
 
  105     const int lastDotIndex = url.lastIndexOf( 
"." );
 
  106     const int lastSlashIndex = url.lastIndexOf( 
"/" );
 
  107     if ( lastDotIndex > -1 && lastDotIndex > lastSlashIndex && length - lastDotIndex <= 6 )
 
  109       QFile tmpFile( outputFile );
 
  110       tmpFile.rename( tmpFile.fileName() + url.mid( lastDotIndex ) );
 
  111       outputFile += url.mid( lastDotIndex );
 
  116   outputs.insert( QStringLiteral( 
"OUTPUT" ), exists ? outputFile : QString() );
 
  120 void QgsFileDownloaderAlgorithm::reportErrors( 
const QStringList &errors )
 
  125 void QgsFileDownloaderAlgorithm::sendProgressFeedback()
 
  127   if ( !mReceived.isEmpty() && mLastReport != mReceived )
 
  129     mLastReport = mReceived;
 
  130     if ( mTotal.isEmpty() )
 
  131       mFeedback->pushInfo( tr( 
"%1 downloaded." ).arg( mReceived ) );
 
  133       mFeedback->pushInfo( tr( 
"%1 of %2 downloaded." ).arg( mReceived, mTotal ) );
 
  137 void QgsFileDownloaderAlgorithm::receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal )
 
  140   if ( bytesTotal > 0 )
 
  142     if ( mTotal.isEmpty() )
 
  145     mFeedback->setProgress( ( bytesReceived * 100 ) / bytesTotal );
 
void canceled()
Internal routines can connect to this signal if they use event loop.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
QgsFileDownloader is a utility class for downloading files.
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.
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
void startDownload()
Called to start the download.
void downloadCompleted(const QUrl &url)
Emitted when the download has completed successfully.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
A string parameter for processing algorithms.
static QString tempFolder()
Returns a session specific processing temporary folder for use in processing algorithms.