diff --git a/qml/main.qml b/qml/main.qml index 038fe4702..b11161a74 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -85,12 +85,6 @@ Kirigami.ApplicationWindow { onErrorOccured: showPassiveNotification(error + ": " + detail) } - Binding { - target: imageProvider - property: "connection" - value: Controller.connection - } - RoomListModel { id: spectralRoomListModel diff --git a/src/main.cpp b/src/main.cpp index 258b5491c..57665b97f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -105,9 +105,7 @@ int main(int argc, char *argv[]) Controller::instance().setAboutData(about); engine.addImportPath("qrc:/imports"); - MatrixImageProvider *matrixImageProvider = new MatrixImageProvider(); - engine.rootContext()->setContextProperty("imageProvider", matrixImageProvider); - engine.addImageProvider(QLatin1String("mxc"), matrixImageProvider); + engine.addImageProvider(QLatin1String("mxc"), new MatrixImageProvider); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); if (engine.rootObjects().isEmpty()) diff --git a/src/matriximageprovider.cpp b/src/matriximageprovider.cpp index 41021c652..4caadd745 100644 --- a/src/matriximageprovider.cpp +++ b/src/matriximageprovider.cpp @@ -12,11 +12,12 @@ #include #include +#include "controller.h" + using Quotient::BaseJob; -ThumbnailResponse::ThumbnailResponse(Quotient::Connection *c, QString id, QSize size) - : c(c) - , mediaId(std::move(id)) +ThumbnailResponse::ThumbnailResponse(QString id, QSize size) + : mediaId(std::move(id)) , requestedSize(size) , localFile(QStringLiteral("%1/image_provider/%2-%3x%4.png").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), mediaId, QString::number(requestedSize.width()), QString::number(requestedSize.height()))) , errorStr("Image request hasn't started") @@ -39,21 +40,21 @@ ThumbnailResponse::ThumbnailResponse(Quotient::Connection *c, QString id, QSize return; } - if (!c) { + if (!Controller::instance().connection()) { qWarning() << "Current connection is null"; return; } // Execute a request on the main thread asynchronously - moveToThread(c->thread()); + moveToThread(Controller::instance().connection()->thread()); QMetaObject::invokeMethod(this, &ThumbnailResponse::startRequest, Qt::QueuedConnection); } void ThumbnailResponse::startRequest() { // Runs in the main thread, not QML thread - Q_ASSERT(QThread::currentThread() == c->thread()); - job = c->getThumbnail(mediaId, requestedSize); + Q_ASSERT(QThread::currentThread() == Controller::instance().connection()->thread()); + job = Controller::instance().connection()->getThumbnail(mediaId, requestedSize); // Connect to any possible outcome including abandonment // to make sure the QML thread is not left stuck forever. connect(job, &BaseJob::finished, this, &ThumbnailResponse::prepareResult); @@ -116,5 +117,5 @@ void ThumbnailResponse::cancel() QQuickImageResponse *MatrixImageProvider::requestImageResponse(const QString &id, const QSize &requestedSize) { - return new ThumbnailResponse(m_connection.loadRelaxed(), id, requestedSize); + return new ThumbnailResponse(id, requestedSize); } diff --git a/src/matriximageprovider.h b/src/matriximageprovider.h index 6cb7df20c..406202009 100644 --- a/src/matriximageprovider.h +++ b/src/matriximageprovider.h @@ -25,7 +25,7 @@ class ThumbnailResponse : public QQuickImageResponse { Q_OBJECT public: - ThumbnailResponse(Quotient::Connection *c, QString mediaId, QSize requestedSize); + ThumbnailResponse(QString mediaId, QSize requestedSize); ~ThumbnailResponse() override = default; private Q_SLOTS: @@ -34,7 +34,6 @@ private Q_SLOTS: void doCancel(); private: - Quotient::Connection *c; const QString mediaId; QSize requestedSize; const QString localFile; @@ -49,30 +48,10 @@ private: void cancel() override; }; -class MatrixImageProvider : public QObject, public QQuickAsyncImageProvider +class MatrixImageProvider : public QQuickAsyncImageProvider { - Q_OBJECT - Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged) public: - explicit MatrixImageProvider() = default; - QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override; - - Quotient::Connection *connection() - { - return m_connection; - } - void setConnection(Quotient::Connection *connection) - { - m_connection.storeRelaxed(connection); - Q_EMIT connectionChanged(); - } - -Q_SIGNALS: - void connectionChanged(); - -private: - QAtomicPointer m_connection; }; #endif // MatrixImageProvider_H