25 QMap<QString, QgsFetchedContent *>::const_iterator it = mFileRegistry.constBegin();
26 for ( ; it != mFileRegistry.constEnd(); ++it )
30 mFileRegistry.clear();
36 if ( mFileRegistry.contains( url ) )
38 return mFileRegistry.value( url );
43 mFileRegistry.insert( url, content );
54 QFile *file =
nullptr;
55 QString path = filePathOrUrl;
57 if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
59 if ( mFileRegistry.contains( path ) )
64 file = content->
file();
78 file =
new QFile( filePathOrUrl );
85 QString path = filePathOrUrl;
87 if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
89 if ( mFileRegistry.contains( path ) )
139 if ( mFetchingTask && mFetchingTask->canCancel() )
141 mFetchingTask->cancel();
145 mFile->deleteLater();
146 mFilePath = QString();
151 void QgsFetchedContent::taskCompleted()
153 if ( !mFetchingTask || !mFetchingTask->reply() )
157 mError = QNetworkReply::OperationCanceledError;
158 mFilePath = QString();
162 QNetworkReply *reply = mFetchingTask->reply();
163 if ( reply->error() == QNetworkReply::NoError )
165 QTemporaryFile *tf =
new QTemporaryFile( QStringLiteral(
"XXXXXX" ) );
168 mFile->write( reply->readAll() );
170 mFilePath = tf->fileName();
177 mError = reply->error();
178 mFilePath = QString();
void taskCompleted()
Will be emitted by task to indicate its successful completion.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
QString localPath(const QString &filePathOrUrl)
Returns the path to a local file or to a temporary file previously fetched by the registry...
The download will start immediately, not need to run QgsFecthedContent::download() ...
Handles HTTP network content fetching in a background task.
QFile * file() const
Returns a pointer to the local file, or nullptr if the file is not accessible yet.
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling...
FetchedContent holds useful information about a network content being fetched.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Download finished and successful.
No download started for such URL.
QFile * localFile(const QString &filePathOrUrl)
Returns a QFile from a local file or to a temporary file previously fetched by the registry...
FetchingMode
Enum to determine when the download should start.
ContentStatus status() const
Returns the status of the download.
void cancel()
Cancel the download operation.
const QString filePath() const
Returns the path to the local file, an empty string if the file is not accessible yet...
const QgsFetchedContent * fetch(const QString &url, FetchingMode fetchingMode=DownloadLater)
Initialize a download for the given URL.
~QgsNetworkContentFetcherRegistry() override
void download(bool redownload=false)
Start the download.