Skip to content
Permalink
Browse files

also add localFile returning a QFile

  • Loading branch information
3nids committed Apr 30, 2018
1 parent 8308ce1 commit 9d4507745675d147e80bf2b1e4caaaf762a5643b
@@ -130,7 +130,13 @@ Create the registry for temporary downloaded files
If the download starts immediately, it will not redownload any already fetched or currently fetching file.
%End


QString localPath( const QString &filePathOrUrl );
%Docstring
Returns the path to a local file or to a temporary file previously fetched by the registry

:param filePathOrUrl: can either be a local file path or a remote content which has previously been fetched
%End

};

@@ -70,7 +70,7 @@ const QgsFetchedContent *QgsNetworkContentFetcherRegistry::fetch( const QUrl &ur
QObject::connect( content, &QgsFetchedContent::cancelTriggered, this, [ = ]()
{
QMutexLocker locker( &mMutex );
if ( content->mFetchingTask )
if ( content->mFetchingTask->canCancel() )
{
content->mFetchingTask->cancel();
}
@@ -115,6 +115,37 @@ const QgsFetchedContent *QgsNetworkContentFetcherRegistry::fetch( const QUrl &ur
return content;
}

const QFile *QgsNetworkContentFetcherRegistry::localFile( const QString &filePathOrUrl )
{
QFile *file = nullptr;
QString path = filePathOrUrl;

if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
{
if ( mFileRegistry.contains( QUrl( path ) ) )
{
const QgsFetchedContent *content = mFileRegistry.value( QUrl( path ) );
if ( content->status() == QgsFetchedContent::Finished && !content->file() )
{
file = content->file();
}
else
{
// if the file is not downloaded yet or has failed, return nullptr
}
}
else
{
// if registry doesn't contain the URL, return nullptr
}
}
else
{
file = new QFile( filePathOrUrl );
}
return file;
}

QString QgsNetworkContentFetcherRegistry::localPath( const QString &filePathOrUrl )
{
QString path = filePathOrUrl;
@@ -147,6 +147,19 @@ class CORE_EXPORT QgsNetworkContentFetcherRegistry : public QObject
*/
const QgsFetchedContent *fetch( const QUrl &url, const FetchingMode &fetchingMode = DownloadLater );

#ifndef SIP_RUN

/**
* \brief Returns a QFile from a local file or to a temporary file previously fetched by the registry
* \param filePathOrUrl can either be a local file path or a remote content which has previously been fetched
*/
const QFile *localFile( const QString &filePathOrUrl );
#endif

/**
* \brief Returns the path to a local file or to a temporary file previously fetched by the registry
* \param filePathOrUrl can either be a local file path or a remote content which has previously been fetched
*/
QString localPath( const QString &filePathOrUrl );

private:

0 comments on commit 9d45077

Please sign in to comment.
You can’t perform that action at this time.