Fix imageprovider.

This commit is contained in:
Black Hat 2018-07-07 19:06:13 +08:00
parent 17fa7cc7da
commit b3c0dc9421
12 changed files with 66 additions and 51 deletions

View File

@ -37,7 +37,9 @@ int main(int argc, char *argv[])
ImageProvider* m_provider = new ImageProvider(); ImageProvider* m_provider = new ImageProvider();
engine.rootContext()->setContextProperty("imageProvider", m_provider->getConnection()); engine.rootContext()->setContextProperty("imageProvider", m_provider->getConnection());
engine.addImageProvider(QLatin1String("mxc"), m_provider); engine.addImageProvider(QLatin1String("mxc"), m_provider);
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())

View File

@ -18,7 +18,8 @@ SOURCES += main.cpp \
matrix/controller.cpp \ matrix/controller.cpp \
matrix/roomlistmodel.cpp \ matrix/roomlistmodel.cpp \
matrix/imageprovider.cpp \ matrix/imageprovider.cpp \
matrix/messageeventmodel.cpp matrix/messageeventmodel.cpp \
matrix/imageproviderconnection.cpp
RESOURCES += \ RESOURCES += \
res.qrc res.qrc
@ -52,4 +53,5 @@ HEADERS += \
matrix/controller.h \ matrix/controller.h \
matrix/roomlistmodel.h \ matrix/roomlistmodel.h \
matrix/imageprovider.h \ matrix/imageprovider.h \
matrix/messageeventmodel.h matrix/messageeventmodel.h \
matrix/imageproviderconnection.h

View File

@ -10,7 +10,7 @@ Controller::Controller(QObject *parent) : QObject(parent) {
} }
Controller::~Controller() { Controller::~Controller() {
m_connection->stopSync();
} }
void Controller::login() { void Controller::login() {

View File

@ -10,14 +10,6 @@
using QMatrixClient::MediaThumbnailJob; using QMatrixClient::MediaThumbnailJob;
ImageProviderConnection::ImageProviderConnection(QObject* parent) : QObject(parent) {
}
ImageProviderConnection::~ImageProviderConnection() {
}
ImageProvider::ImageProvider(QObject* parent) ImageProvider::ImageProvider(QObject* parent)
: QQuickImageProvider(QQmlImageProviderBase::Image, : QQuickImageProvider(QQmlImageProviderBase::Image,
QQmlImageProviderBase::ForceAsynchronousImageLoading) QQmlImageProviderBase::ForceAsynchronousImageLoading)

View File

@ -6,28 +6,7 @@
#include <QObject> #include <QObject>
#include "libqmatrixclient/connection.h" #include "libqmatrixclient/connection.h"
#include "imageproviderconnection.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; }
Q_INVOKABLE void setConnection(QMatrixClient::Connection* connection) {
qDebug() << "Connection changed.";
emit connectionChanged();
m_connection = connection;
}
private:
QMatrixClient::Connection* m_connection;
signals:
void connectionChanged();
};
class ImageProvider: public QQuickImageProvider class ImageProvider: public QQuickImageProvider
{ {

View File

@ -0,0 +1,9 @@
#include "imageproviderconnection.h"
ImageProviderConnection::ImageProviderConnection(QObject* parent) : QObject(parent) {
}
ImageProviderConnection::~ImageProviderConnection() {
}

View File

@ -0,0 +1,29 @@
#ifndef IMAGEPROVIDERCONNECTION_H
#define IMAGEPROVIDERCONNECTION_H
#include <QObject>
#include "libqmatrixclient/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) {
emit connectionChanged();
m_connection = connection;
}
private:
QMatrixClient::Connection* m_connection;
signals:
void connectionChanged();
};
#endif // IMAGEPROVIDERCONNECTION_H

View File

@ -70,12 +70,12 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const
} }
if( role == Qt::DecorationRole ) if( role == Qt::DecorationRole )
{ {
if(room->avatarUrl().toString() != "") { if ( room->avatarUrl().toString() != "" ) {
return room->avatarUrl(); return room->avatarUrl();
} }
return QVariant(); return QVariant();
} }
if (role == Qt::StatusTipRole ) if ( role == Qt::StatusTipRole )
{ {
return room->topic(); return room->topic();
} }

View File

@ -22,14 +22,13 @@ Page {
id: roomListForm id: roomListForm
Layout.fillHeight: true Layout.fillHeight: true
// Layout.preferredWidth: { Layout.preferredWidth: {
// if (page.width > 560) { if (page.width > 560) {
// return page.width * 0.4; return page.width * 0.4;
// } else { } else {
// return 80; return 80;
// } }
// } }
Layout.preferredWidth: 320
Layout.maximumWidth: 360 Layout.maximumWidth: 360
listModel: roomListModel listModel: roomListModel

View File

@ -45,6 +45,8 @@ Item {
Layout.fillHeight: true Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
visible: parent.width > 80
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
@ -79,9 +81,9 @@ Item {
var roomCount = listModel.rowCount(); var roomCount = listModel.rowCount();
for (var i = 0; i < roomCount; i++){ for (var i = 0; i < roomCount; i++){
var roomName = ""; var roomName = "";
if (listModel.roomAt(i).name != "") { if (listModel.roomAt(i).name !== "") {
roomName = listModel.roomAt(i).name; roomName = listModel.roomAt(i).name;
} else if (model.alias != "") { } else if (model.alias !== "") {
roomName = listModel.roomAt(i).alias; roomName = listModel.roomAt(i).alias;
} else { } else {
roomName = listModel.roomAt(i).id; roomName = listModel.roomAt(i).id;

View File

@ -16,7 +16,7 @@ Item {
background: Item { background: Item {
anchors.fill: parent anchors.fill: parent
visible: currentRoom == null visible: currentRoom === null
Pane { Pane {
anchors.fill: parent anchors.fill: parent
} }
@ -32,7 +32,7 @@ Item {
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
visible: currentRoom != null visible: currentRoom !== null
Pane { Pane {
z: 10 z: 10
@ -61,7 +61,7 @@ Item {
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: currentRoom != null ? currentRoom.name : "" text: currentRoom !== null ? currentRoom.displayName : ""
font.pointSize: 16 font.pointSize: 16
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
@ -69,7 +69,7 @@ Item {
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: currentRoom != null ? currentRoom.topic : "" text: currentRoom !== null ? currentRoom.topic : ""
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }

View File

@ -138,7 +138,9 @@ ApplicationWindow {
SideNavButton { SideNavButton {
contentItem: MaterialIcon { icon: "\ue879"; color: "white" } contentItem: MaterialIcon { icon: "\ue879"; color: "white" }
onClicked: Qt.quit() onClicked: {
Qt.quit();
}
} }
} }
} }
@ -153,7 +155,6 @@ ApplicationWindow {
} }
Component.onCompleted: { Component.onCompleted: {
imageProvider.setConnection(matriqueController.connection)
imageProvider.connection = matriqueController.connection imageProvider.connection = matriqueController.connection
console.log(matriqueController.homeserver, matriqueController.userID, matriqueController.token) console.log(matriqueController.homeserver, matriqueController.userID, matriqueController.token)