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 );