Skip to content

Commit

Permalink
Add QQmlNetworkAccessManagerFactory
Browse files Browse the repository at this point in the history
...to support mxc links natively in QML.
  • Loading branch information
KitsuneRal committed Nov 7, 2024
1 parent be43632 commit c3eb1bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/timelinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

using Quotient::operator""_ls;

QNetworkAccessManager* TimelineWidget::NamFactory::create(QObject* parent)
{
return new Quotient::NetworkAccessManager(parent);
}

TimelineWidget::TimelineWidget(ChatRoomWidget* chatRoomWidget)
: QQuickWidget(chatRoomWidget)
, m_messageModel(new MessageEventModel(this))
Expand All @@ -45,6 +50,7 @@ TimelineWidget::TimelineWidget(ChatRoomWidget* chatRoomWidget)
setResizeMode(SizeRootObjectToView);

engine()->addImageProvider("thumbnail"_ls, makeThumbnailProvider(this));
engine()->setNetworkAccessManagerFactory(&namFactory);

auto* ctxt = rootContext();
ctxt->setContextProperty("messageModel"_ls, m_messageModel);
Expand Down
8 changes: 8 additions & 0 deletions client/timelinewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <Quotient/eventitem.h>

#include <QtQml/QQmlNetworkAccessManagerFactory>
#include <QtQuickWidgets/QQuickWidget>

#include <QtCore/QBasicTimer>

class ChatRoomWidget;
Expand Down Expand Up @@ -55,6 +57,12 @@ public slots:
ActivityDetector activityDetector;
ChatRoomWidget* roomWidget;

class NamFactory : public QQmlNetworkAccessManagerFactory {
public:
QNetworkAccessManager* create(QObject* parent) override;
};
NamFactory namFactory;

void reStartShownTimer();
void timerEvent(QTimerEvent* qte) override;
bool pendingMarkRead() const;
Expand Down

0 comments on commit c3eb1bc

Please sign in to comment.