Skip to content

Commit

Permalink
Merge pull request #6872 from 3nids/fetchregistry
Browse files Browse the repository at this point in the history
QgsNetworkContentFetcherRegistry: a registry for temporary downloaded files
  • Loading branch information
3nids committed May 7, 2018
2 parents ba04dea + b4d00d9 commit 3fef9cd
Show file tree
Hide file tree
Showing 10 changed files with 698 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -336,6 +336,7 @@
%Include qgsmessageoutput.sip
%Include qgsnetworkaccessmanager.sip
%Include qgsnetworkcontentfetcher.sip
%Include qgsnetworkcontentfetcherregistry.sip
%Include qgsnetworkcontentfetchertask.sip
%Include qgsofflineediting.sip
%Include qgspluginlayer.sip
Expand Down
7 changes: 7 additions & 0 deletions python/core/qgsapplication.sip.in
Expand Up @@ -641,6 +641,13 @@ Returns the application's SVG cache, used for caching SVG images and handling pa
within SVG files.

.. versionadded:: 3.0
%End

static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry();
%Docstring
Returns the application's network content registry used for fetching temporary files during QGIS session

.. versionadded:: 3.2
%End

static QgsSymbolLayerRegistry *symbolLayerRegistry();
Expand Down
156 changes: 156 additions & 0 deletions python/core/qgsnetworkcontentfetcherregistry.sip.in
@@ -0,0 +1,156 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsnetworkcontentfetcherregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/








class QgsFetchedContent : QObject
{
%Docstring
FetchedContent holds useful information about a network content being fetched

.. seealso:: :py:class:`QgsNetworkContentFetcherRegistry`

.. versionadded:: 3.2
%End

%TypeHeaderCode
#include "qgsnetworkcontentfetcherregistry.h"
%End
public:
enum ContentStatus
{
NotStarted,
Downloading,
Finished,
Failed
};

explicit QgsFetchedContent( QTemporaryFile *file = 0, ContentStatus status = NotStarted );
%Docstring
Constructs a FetchedContent with pointer to the downloaded file and status of the download
%End
~QgsFetchedContent();



const QString filePath() const;
%Docstring
Return the path to the local file, an empty string if the file is not accessible yet.
%End

ContentStatus status() const;
%Docstring
Return the status of the download
%End

QNetworkReply::NetworkError error() const;
%Docstring
Return the potential error of the download
%End

public slots:

void download( bool redownload = false );
%Docstring
Start the download

:param redownload: if set to true, it will restart any achieved or pending download.
%End

void cancel();
%Docstring
Cancel the download operation
%End

signals:
void fetched();
%Docstring
Emitted when the file is fetched and accessible
%End

void downloadStarted( const bool redownload );
%Docstring
Emitted when the download actually starts
%End

void cancelTriggered();
%Docstring
Emitted when download is canceled.
%End

void taskCompleted();
%Docstring
Emitted when the download is finished (although file not accessible yet)
%End

};

class QgsNetworkContentFetcherRegistry : QObject
{
%Docstring
Registry for temporary fetched files

This provides a simple way of downloading and accessing
remote files during QGIS application running.

.. seealso:: :py:class:`QgsFetchedContent`

.. versionadded:: 3.2
%End

%TypeHeaderCode
#include "qgsnetworkcontentfetcherregistry.h"
%End
public:
enum FetchingMode
{
DownloadLater,
DownloadImmediately,
};

explicit QgsNetworkContentFetcherRegistry();
%Docstring
Create the registry for temporary downloaded files
%End

~QgsNetworkContentFetcherRegistry();

const QgsFetchedContent *fetch( const QUrl &url, const FetchingMode fetchingMode = DownloadLater );
%Docstring
Initialize a download for the given URL

:param url: the URL to be fetched
:param fetchingMode: defines if the download will start immediately or shall be manually triggered

.. note::

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

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsnetworkcontentfetcherregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -238,6 +238,7 @@ SET(QGIS_CORE_SRCS
qgsnetworkaccessmanager.cpp
qgsnetworkdiskcache.cpp
qgsnetworkcontentfetcher.cpp
qgsnetworkcontentfetcherregistry.cpp
qgsnetworkcontentfetchertask.cpp
qgsnetworkreplyparser.cpp
qgsobjectcustomproperties.cpp
Expand Down Expand Up @@ -625,6 +626,7 @@ SET(QGIS_CORE_MOC_HDRS
qgsnetworkaccessmanager.h
qgsnetworkdiskcache.h
qgsnetworkcontentfetcher.h
qgsnetworkcontentfetcherregistry.h
qgsnetworkcontentfetchertask.h
qgsnetworkreplyparser.h
qgsofflineediting.h
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgslogger.h"
#include "qgsproject.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsnetworkcontentfetcherregistry.h"
#include "qgsproviderregistry.h"
#include "qgsexpression.h"
#include "qgsactionscoperegistry.h"
Expand Down Expand Up @@ -1664,6 +1665,11 @@ QgsSvgCache *QgsApplication::svgCache()
return members()->mSvgCache;
}

QgsNetworkContentFetcherRegistry *QgsApplication::networkContentFetcherRegistry()
{
return members()->mNetworkContentFetcherRegistry;
}

QgsSymbolLayerRegistry *QgsApplication::symbolLayerRegistry()
{
return members()->mSymbolLayerRegistry;
Expand Down Expand Up @@ -1743,6 +1749,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mAnnotationRegistry = new QgsAnnotationRegistry();
m3DRendererRegistry = new Qgs3DRendererRegistry();
mProjectStorageRegistry = new QgsProjectStorageRegistry();
mNetworkContentFetcherRegistry = new QgsNetworkContentFetcherRegistry();
}

QgsApplication::ApplicationMembers::~ApplicationMembers()
Expand All @@ -1766,6 +1773,7 @@ QgsApplication::ApplicationMembers::~ApplicationMembers()
delete mSvgCache;
delete mSymbolLayerRegistry;
delete mTaskManager;
delete mNetworkContentFetcherRegistry;
}

QgsApplication::ApplicationMembers *QgsApplication::members()
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsapplication.h
Expand Up @@ -46,6 +46,7 @@ class QgsUserProfileManager;
class QgsPageSizeRegistry;
class QgsLayoutItemRegistry;
class QgsAuthManager;
class QgsNetworkContentFetcherRegistry;

/**
* \ingroup core
Expand Down Expand Up @@ -586,6 +587,12 @@ class CORE_EXPORT QgsApplication : public QApplication
*/
static QgsSvgCache *svgCache();

/**
* Returns the application's network content registry used for fetching temporary files during QGIS session
* \since QGIS 3.2
*/
static QgsNetworkContentFetcherRegistry *networkContentFetcherRegistry();

/**
* Returns the application's symbol layer registry, used for managing symbol layers.
* \since QGIS 3.0
Expand Down Expand Up @@ -802,6 +809,7 @@ class CORE_EXPORT QgsApplication : public QApplication
QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
QgsFieldFormatterRegistry *mFieldFormatterRegistry = nullptr;
QgsGpsConnectionRegistry *mGpsConnectionRegistry = nullptr;
QgsNetworkContentFetcherRegistry *mNetworkContentFetcherRegistry = nullptr;
QgsMessageLog *mMessageLog = nullptr;
QgsPaintEffectRegistry *mPaintEffectRegistry = nullptr;
QgsPluginLayerRegistry *mPluginLayerRegistry = nullptr;
Expand Down

0 comments on commit 3fef9cd

Please sign in to comment.