mirror of
https://github.com/status-im/dotherside.git
synced 2025-02-11 20:16:47 +00:00
Creating a cache for network requests
This commit is contained in:
parent
1d57c85694
commit
5012620a2f
@ -139,11 +139,15 @@ DOS_API void DOS_CALL dos_qapplication_delete(void);
|
|||||||
/// \note The returned QQmlApplicationEngine should be freed by using dos_qqmlapplicationengine_delete(DosQQmlApplicationEngine*)
|
/// \note The returned QQmlApplicationEngine should be freed by using dos_qqmlapplicationengine_delete(DosQQmlApplicationEngine*)
|
||||||
DOS_API DosQQmlApplicationEngine *DOS_CALL dos_qqmlapplicationengine_create(void);
|
DOS_API DosQQmlApplicationEngine *DOS_CALL dos_qqmlapplicationengine_create(void);
|
||||||
|
|
||||||
|
DOS_API DosQQmlNetworkAccessManagerFactory *DOS_CALL dos_qqmlnetworkaccessmanagerfactory_create(const char* tmpPath);
|
||||||
|
|
||||||
/// \brief Calls the QQmlApplicationEngine::load function
|
/// \brief Calls the QQmlApplicationEngine::load function
|
||||||
/// \param vptr The QQmlApplicationEngine
|
/// \param vptr The QQmlApplicationEngine
|
||||||
/// \param filename The file to load. The file is relative to the directory that contains the application executable
|
/// \param filename The file to load. The file is relative to the directory that contains the application executable
|
||||||
DOS_API void DOS_CALL dos_qqmlapplicationengine_load(DosQQmlApplicationEngine *vptr, const char *filename);
|
DOS_API void DOS_CALL dos_qqmlapplicationengine_load(DosQQmlApplicationEngine *vptr, const char *filename);
|
||||||
|
|
||||||
|
DOS_API void DOS_CALL dos_qqmlapplicationengine_setNetworkAccessManagerFactory(DosQQmlApplicationEngine *vptr, DosQQmlNetworkAccessManagerFactory *factory);
|
||||||
|
|
||||||
/// \brief Calls the QQmlApplicationEngine::load function
|
/// \brief Calls the QQmlApplicationEngine::load function
|
||||||
/// \param vptr The QQmlApplicationEngine
|
/// \param vptr The QQmlApplicationEngine
|
||||||
/// \param url The QUrl of the file to load
|
/// \param url The QUrl of the file to load
|
||||||
|
@ -77,6 +77,8 @@ typedef void DosQUrl;
|
|||||||
/// A pointer to a QNetworkConfigurationManager
|
/// A pointer to a QNetworkConfigurationManager
|
||||||
typedef void DosQNetworkConfigurationManager;
|
typedef void DosQNetworkConfigurationManager;
|
||||||
|
|
||||||
|
typedef void DosQQmlNetworkAccessManagerFactory;
|
||||||
|
|
||||||
/// A pointer to a QMetaObject
|
/// A pointer to a QMetaObject
|
||||||
typedef void DosQMetaObject;
|
typedef void DosQMetaObject;
|
||||||
|
|
||||||
|
@ -26,10 +26,13 @@
|
|||||||
#include <QtCore/QModelIndex>
|
#include <QtCore/QModelIndex>
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
#include <QtCore/QResource>
|
#include <QtCore/QResource>
|
||||||
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
|
#include <QtNetwork/QNetworkDiskCache>
|
||||||
#include <QtNetwork/QNetworkConfigurationManager>
|
#include <QtNetwork/QNetworkConfigurationManager>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QIcon>
|
||||||
#include <QtQml/QQmlContext>
|
#include <QtQml/QQmlContext>
|
||||||
|
#include <QtQml/QQmlNetworkAccessManagerFactory>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QtGui/QPixmap>
|
#include <QtGui/QPixmap>
|
||||||
@ -67,6 +70,35 @@ void register_meta_types()
|
|||||||
// jrainville: I'm not sure where to put this, but it works like so
|
// jrainville: I'm not sure where to put this, but it works like so
|
||||||
QTranslator *m_translator = new QTranslator();
|
QTranslator *m_translator = new QTranslator();
|
||||||
|
|
||||||
|
class QMLNetworkAccessFactory : public QQmlNetworkAccessManagerFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString tmpPath;
|
||||||
|
|
||||||
|
QMLNetworkAccessFactory()
|
||||||
|
: QQmlNetworkAccessManagerFactory()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkAccessManager* create(QObject* parent);
|
||||||
|
|
||||||
|
void setTmpPath(const char* path);
|
||||||
|
};
|
||||||
|
|
||||||
|
QString QMLNetworkAccessFactory::tmpPath = "";
|
||||||
|
|
||||||
|
QNetworkAccessManager* QMLNetworkAccessFactory::create(QObject* parent)
|
||||||
|
{
|
||||||
|
QNetworkAccessManager* manager = new QNetworkAccessManager(parent);
|
||||||
|
QNetworkDiskCache* cache = new QNetworkDiskCache(manager);
|
||||||
|
qDebug() << "Network Cache Dir: " << QMLNetworkAccessFactory::tmpPath ;
|
||||||
|
cache->setCacheDirectory(QMLNetworkAccessFactory::tmpPath);
|
||||||
|
manager->setCache(cache);
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *convert_to_cstring(const QByteArray &array)
|
char *convert_to_cstring(const QByteArray &array)
|
||||||
{
|
{
|
||||||
return qstrdup(array.data());
|
return qstrdup(array.data());
|
||||||
@ -158,6 +190,19 @@ void dos_qapplication_quit()
|
|||||||
return new QQmlApplicationEngine();
|
return new QQmlApplicationEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::DosQQmlNetworkAccessManagerFactory *dos_qqmlnetworkaccessmanagerfactory_create(const char* tmpPath)
|
||||||
|
{
|
||||||
|
QMLNetworkAccessFactory::tmpPath = tmpPath;
|
||||||
|
return new QMLNetworkAccessFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
void dos_qqmlapplicationengine_setNetworkAccessManagerFactory(::DosQQmlApplicationEngine *vptr, ::DosQQmlNetworkAccessManagerFactory *factory)
|
||||||
|
{
|
||||||
|
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
||||||
|
auto namFactory = static_cast<QMLNetworkAccessFactory *>(factory);
|
||||||
|
engine->setNetworkAccessManagerFactory(namFactory);
|
||||||
|
}
|
||||||
|
|
||||||
void dos_qqmlapplicationengine_load(::DosQQmlApplicationEngine *vptr, const char *filename)
|
void dos_qqmlapplicationengine_load(::DosQQmlApplicationEngine *vptr, const char *filename)
|
||||||
{
|
{
|
||||||
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user