Skip to content

Commit

Permalink
add a network access factory to qml engine
Browse files Browse the repository at this point in the history
ensure network access made via qml are using our user agent

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Nov 22, 2021
1 parent 1d704d9 commit 12c6d6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/gui/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "wheelhandler.h"
#include "tray/unifiedsearchresultimageprovider.h"
#include "configfile.h"
#include "accessmanager.h"

#include <QCursor>
#include <QGuiApplication>
Expand Down Expand Up @@ -59,6 +60,8 @@ void Systray::setTrayEngine(QQmlApplicationEngine *trayEngine)
{
_trayEngine = trayEngine;

_trayEngine->setNetworkAccessManagerFactory(&_accessManagerFactory);

_trayEngine->addImportPath("qrc:/qml/theme");
_trayEngine->addImageProvider("avatars", new ImageProvider);
_trayEngine->addImageProvider(QLatin1String("svgimage-custom-color"), new OCC::Ui::SvgImageProvider);
Expand Down Expand Up @@ -505,4 +508,14 @@ QPoint Systray::calcTrayIconCenter() const
#endif
}

AccessManagerFactory::AccessManagerFactory()
: QQmlNetworkAccessManagerFactory()
{
}

QNetworkAccessManager* AccessManagerFactory::create(QObject *parent)
{
return new AccessManager(parent);
}

} // namespace OCC
12 changes: 12 additions & 0 deletions src/gui/systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "accountmanager.h"
#include "tray/usermodel.h"

#include <QQmlNetworkAccessManagerFactory>

class QScreen;
class QQmlApplicationEngine;
class QQuickWindow;
Expand All @@ -28,6 +30,14 @@ class QQuickWindow;

namespace OCC {

class AccessManagerFactory : public QQmlNetworkAccessManagerFactory
{
public:
AccessManagerFactory();

QNetworkAccessManager* create(QObject *parent) override;
};

#ifdef Q_OS_OSX
bool canOsXSendUserNotification();
void sendOsXUserNotification(const QString &title, const QString &message);
Expand Down Expand Up @@ -105,6 +115,8 @@ private slots:
bool _isOpen = false;
bool _syncIsPaused = true;
QPointer<QQmlApplicationEngine> _trayEngine;

AccessManagerFactory _accessManagerFactory;
};

} // namespace OCC
Expand Down

0 comments on commit 12c6d6e

Please sign in to comment.