diff --git a/matrique.pro b/matrique.pro index 4cd7c0b..85e6a42 100644 --- a/matrique.pro +++ b/matrique.pro @@ -26,7 +26,6 @@ SOURCES += src/main.cpp \ src/roomlistmodel.cpp \ src/imageprovider.cpp \ src/messageeventmodel.cpp \ - src/imageproviderconnection.cpp \ src/emojimodel.cpp \ src/matriqueroom.cpp \ src/userlistmodel.cpp \ @@ -87,7 +86,6 @@ HEADERS += \ src/roomlistmodel.h \ src/imageprovider.h \ src/messageeventmodel.h \ - src/imageproviderconnection.h \ src/emojimodel.h \ src/matriqueroom.h \ src/userlistmodel.h \ diff --git a/src/imageprovider.cpp b/src/imageprovider.cpp index fad23a6..85aad34 100644 --- a/src/imageprovider.cpp +++ b/src/imageprovider.cpp @@ -13,13 +13,13 @@ using QMatrixClient::MediaThumbnailJob; ImageProvider::ImageProvider(QObject* parent) - : QQuickImageProvider( + : QObject(parent), + QQuickImageProvider( QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) { #if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0)) qRegisterMetaType(); #endif - m_connection = new ImageProviderConnection(); } QImage ImageProvider::requestImage(const QString& id, QSize* pSize, @@ -49,13 +49,10 @@ QImage ImageProvider::requestImage(const QString& id, QSize* pSize, #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) QMetaObject::invokeMethod( m_connection, - [=] { - return m_connection->getConnection()->getThumbnail(mxcUri, - requestedSize); - }, + [=] { return m_connection->getThumbnail(mxcUri, requestedSize); }, Qt::BlockingQueuedConnection, &job); #else - QMetaObject::invokeMethod(m_connection->getConnection(), "getThumbnail", + QMetaObject::invokeMethod(m_connection, "getThumbnail", Qt::BlockingQueuedConnection, Q_RETURN_ARG(MediaThumbnailJob*, job), Q_ARG(QUrl, mxcUri), Q_ARG(QSize, requestedSize)); diff --git a/src/imageprovider.h b/src/imageprovider.h index 6133b09..5de4ae1 100644 --- a/src/imageprovider.h +++ b/src/imageprovider.h @@ -6,9 +6,11 @@ #include #include "connection.h" -#include "imageproviderconnection.h" -class ImageProvider : public QQuickImageProvider { +class ImageProvider : public QObject, public QQuickImageProvider { + Q_OBJECT + Q_PROPERTY(QMatrixClient::Connection* connection READ connection WRITE + setConnection NOTIFY connectionChanged) public: explicit ImageProvider(QObject* parent = nullptr); @@ -17,11 +19,20 @@ class ImageProvider : public QQuickImageProvider { void initializeEngine(QQmlEngine* engine, const char* uri); - ImageProviderConnection* getConnection() { return m_connection; } + QMatrixClient::Connection* connection() { return m_connection; } + void setConnection(QMatrixClient::Connection* newConnection) { + if (m_connection != newConnection) { + m_connection = newConnection; + emit connectionChanged(); + } + } + + signals: + void connectionChanged(); private: QReadWriteLock m_lock; - ImageProviderConnection* m_connection; + QMatrixClient::Connection* m_connection; }; #endif // IMAGEPROVIDER_H diff --git a/src/imageproviderconnection.cpp b/src/imageproviderconnection.cpp deleted file mode 100644 index 40f3db0..0000000 --- a/src/imageproviderconnection.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "imageproviderconnection.h" - -ImageProviderConnection::ImageProviderConnection(QObject* parent) - : QObject(parent) {} - -ImageProviderConnection::~ImageProviderConnection() {} diff --git a/src/imageproviderconnection.h b/src/imageproviderconnection.h deleted file mode 100644 index d044b50..0000000 --- a/src/imageproviderconnection.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef IMAGEPROVIDERCONNECTION_H -#define IMAGEPROVIDERCONNECTION_H - -#include - -#include "connection.h" - -class ImageProviderConnection : public QObject { - Q_OBJECT - - Q_PROPERTY(QMatrixClient::Connection* connection READ getConnection WRITE - setConnection NOTIFY connectionChanged) - - public: - explicit ImageProviderConnection(QObject* parent = nullptr); - ~ImageProviderConnection(); - - QMatrixClient::Connection* getConnection() { return m_connection; } - void setConnection(QMatrixClient::Connection* connection) { - m_connection = connection; - emit connectionChanged(); - } - - private: - QMatrixClient::Connection* m_connection; - signals: - void connectionChanged(); -}; - -#endif // IMAGEPROVIDERCONNECTION_H diff --git a/src/main.cpp b/src/main.cpp index a661494..3636474 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,9 +3,9 @@ #include #include -#include "imageitem.h" #include "controller.h" #include "emojimodel.h" +#include "imageitem.h" #include "imageprovider.h" #include "matriqueroom.h" #include "messageeventmodel.h" @@ -52,8 +52,7 @@ int main(int argc, char *argv[]) { ImageProvider *m_provider = new ImageProvider(); - engine.rootContext()->setContextProperty("imageProvider", - m_provider->getConnection()); + engine.rootContext()->setContextProperty("imageProvider", m_provider); engine.addImageProvider(QLatin1String("mxc"), m_provider);