Page MenuHomePhorge

D192.1732583015.diff
No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None

D192.1732583015.diff

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -231,6 +231,7 @@
Notifier.qml
NotificationAction.qml
AvatarAdapter.qml
+ ImageAdapter.qml
FileDialogAdapter.qml
FolderDialogAdapter.qml
ScrollablePageAdapter.qml
diff --git a/src/contents/ui/AvatarAdapter.qml b/src/contents/ui/AvatarAdapter.qml
--- a/src/contents/ui/AvatarAdapter.qml
+++ b/src/contents/ui/AvatarAdapter.qml
@@ -6,6 +6,32 @@
import QtQuick 2.15
import org.kde.kirigamiaddons.components 1.0 as KAC
+import '.' as Kazv
KAC.Avatar {
+ id: avatar
+ property string mxcUri
+ readonly property var manager: kazvIOManager
+ readonly property var sdk: matrixSdk
+ source: fileHandler?.localFile || ''
+
+ property var fileHandlerComp: Component {
+ Kazv.FileHandler {
+ autoCache: true
+ kazvIOManager: avatar.manager
+ matrixSdk: avatar.sdk
+ }
+ }
+ property var fileHandler: null
+
+ onMxcUriChanged: {
+ if (fileHandler) {
+ fileHandler.destroy();
+ fileHandler = null;
+ }
+
+ fileHandler = fileHandlerComp.createObject(avatar, {
+ eventContent: ({ url: avatar.mxcUri }),
+ });
+ }
}
diff --git a/src/contents/ui/Completion.qml b/src/contents/ui/Completion.qml
--- a/src/contents/ui/Completion.qml
+++ b/src/contents/ui/Completion.qml
@@ -49,7 +49,7 @@
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
name: nameProvider.name
- source: member.avatarMxcUri ? matrixSdk.mxcUriToHttp(member.avatarMxcUri) : ''
+ mxcUri: member.avatarMxcUri
}
ColumnLayout {
Label {
diff --git a/src/contents/ui/EventReadIndicator.qml b/src/contents/ui/EventReadIndicator.qml
--- a/src/contents/ui/EventReadIndicator.qml
+++ b/src/contents/ui/EventReadIndicator.qml
@@ -37,7 +37,7 @@
}
Layout.preferredWidth: readIndicator.avatarSize
Layout.preferredHeight: readIndicator.avatarSize
- source: member.avatarMxcUri ? matrixSdk.mxcUriToHttp(member.avatarMxcUri) : ''
+ mxcUri: member.avatarMxcUri
name: nameProvider.name
}
}
@@ -82,7 +82,7 @@
objectName: `readIndicatorAvatar${index}`
Layout.preferredWidth: readIndicator.avatarSize
Layout.preferredHeight: readIndicator.avatarSize
- source: member.avatarMxcUri ? matrixSdk.mxcUriToHttp(member.avatarMxcUri) : ''
+ mxcUri: member.avatarMxcUri
name: nameProvider.name
}
diff --git a/src/contents/ui/FileHandler.qml b/src/contents/ui/FileHandler.qml
--- a/src/contents/ui/FileHandler.qml
+++ b/src/contents/ui/FileHandler.qml
@@ -37,6 +37,7 @@
property var iv: ""
property var kazvIOJob
+ readonly property url localFile: kazvIOJob ? '' : cachedFile
property real percent: fileHandler.kazvIOJob ? fileHandler.kazvIOJob.progress : 0.0 // from 0 to 1
property var result
property bool success: fileHandler.result == MK.KazvIOBaseJob.NoError
diff --git a/src/contents/ui/ImageAdapter.qml b/src/contents/ui/ImageAdapter.qml
new file mode 100644
--- /dev/null
+++ b/src/contents/ui/ImageAdapter.qml
@@ -0,0 +1,36 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick
+import '.' as Kazv
+
+Image {
+ id: image
+ property string mxcUri
+ readonly property var manager: kazvIOManager
+ readonly property var sdk: matrixSdk
+ source: fileHandler?.localFile || ''
+
+ property var fileHandlerComp: Component {
+ Kazv.FileHandler {
+ autoCache: true
+ kazvIOManager: image.manager
+ matrixSdk: image.sdk
+ }
+ }
+ property var fileHandler: null
+
+ onMxcUriChanged: {
+ if (fileHandler) {
+ fileHandler.destroy();
+ fileHandler = null;
+ }
+
+ fileHandler = fileHandlerComp.createObject(image, {
+ eventContent: ({ url: image.mxcUri }),
+ });
+ }
+}
diff --git a/src/contents/ui/RoomListViewItemDelegate.qml b/src/contents/ui/RoomListViewItemDelegate.qml
--- a/src/contents/ui/RoomListViewItemDelegate.qml
+++ b/src/contents/ui/RoomListViewItemDelegate.qml
@@ -45,7 +45,7 @@
contentItem: RowLayout {
Kazv.AvatarAdapter {
- source: item.roomOrHeroAvatarMxcUri ? matrixSdk.mxcUriToHttp(item.roomOrHeroAvatarMxcUri) : ''
+ mxcUri: item.roomOrHeroAvatarMxcUri
name: Helpers.roomAvatarPlaceholderName(item)
}
diff --git a/src/contents/ui/RoomMemberListViewItemDelegate.qml b/src/contents/ui/RoomMemberListViewItemDelegate.qml
--- a/src/contents/ui/RoomMemberListViewItemDelegate.qml
+++ b/src/contents/ui/RoomMemberListViewItemDelegate.qml
@@ -23,7 +23,7 @@
contentItem: RowLayout {
Kazv.AvatarAdapter {
- source: member.avatarMxcUri ? matrixSdk.mxcUriToHttp(member.avatarMxcUri) : ''
+ mxcUri: member.avatarMxcUri
name: displayName
Layout.preferredWidth: iconSize
}
diff --git a/src/contents/ui/StickerPicker.qml b/src/contents/ui/StickerPicker.qml
--- a/src/contents/ui/StickerPicker.qml
+++ b/src/contents/ui/StickerPicker.qml
@@ -62,12 +62,12 @@
height: stickerPicker.stickerSize + stickerPicker.stickerMargin
width: stickerPicker.stickerSize + stickerPicker.stickerMargin
- Image {
+ Kazv.ImageAdapter {
anchors.centerIn: parent
fillMode: Image.PreserveAspectFit
height: stickerPicker.stickerSize
width: stickerPicker.stickerSize
- source: matrixSdk.mxcUriToHttp(sticker.mxcUri)
+ mxcUri: sticker.mxcUri
}
Rectangle {
diff --git a/src/contents/ui/UserPage.qml b/src/contents/ui/UserPage.qml
--- a/src/contents/ui/UserPage.qml
+++ b/src/contents/ui/UserPage.qml
@@ -157,7 +157,7 @@
Layout.alignment: Qt.AlignHCenter
Layout.preferredHeight: Kirigami.Units.iconSizes.enormous
Layout.preferredWidth: Kirigami.Units.iconSizes.enormous
- source: userPage.user.avatarMxcUri ? matrixSdk.mxcUriToHttp(userPage.user.avatarMxcUri) : ''
+ mxcUri: userPage.user.avatarMxcUri
name: nameProvider.name
}
diff --git a/src/contents/ui/event-types/Simple.qml b/src/contents/ui/event-types/Simple.qml
--- a/src/contents/ui/event-types/Simple.qml
+++ b/src/contents/ui/event-types/Simple.qml
@@ -60,7 +60,7 @@
id: avatar
objectName: 'senderAvatar'
Layout.alignment: Qt.AlignTop
- source: sender.avatarMxcUri ? matrixSdk.mxcUriToHttp(sender.avatarMxcUri) : ''
+ mxcUri: sender.avatarMxcUri
name: senderNickname
visible: !compactMode && !shouldCollapseSender
@@ -88,7 +88,7 @@
id: avatarCompact
Layout.preferredWidth: Kirigami.Units.iconSizes.sizeForLabels
Layout.preferredHeight: Kirigami.Units.iconSizes.sizeForLabels
- source: sender.avatarMxcUri ? matrixSdk.mxcUriToHttp(sender.avatarMxcUri) : ''
+ mxcUri: sender.avatarMxcUri
name: senderNickname
visible: compactMode
}
diff --git a/src/contents/ui/room-settings/RoomSettingsPage.qml b/src/contents/ui/room-settings/RoomSettingsPage.qml
--- a/src/contents/ui/room-settings/RoomSettingsPage.qml
+++ b/src/contents/ui/room-settings/RoomSettingsPage.qml
@@ -134,8 +134,7 @@
}
Layout.preferredHeight: Kirigami.Units.iconSizes.huge
Layout.preferredWidth: Kirigami.Units.iconSizes.huge
- source: member.avatarMxcUri ?
- matrixSdk.mxcUriToHttp(member.avatarMxcUri) : ''
+ mxcUri: member.avatarMxcUri
name: nameProvider.name
}
}
diff --git a/src/contents/ui/settings/ProfileSettings.qml b/src/contents/ui/settings/ProfileSettings.qml
--- a/src/contents/ui/settings/ProfileSettings.qml
+++ b/src/contents/ui/settings/ProfileSettings.qml
@@ -25,7 +25,7 @@
Layout.alignment: Qt.AlignHCenter
Layout.preferredHeight: Kirigami.Units.iconSizes.enormous
Layout.preferredWidth: Kirigami.Units.iconSizes.enormous
- source: profileSettings.avatarUrl ? matrixSdk.mxcUriToHttp(profileSettings.avatarUrl) : ''
+ mxcUri: profileSettings.avatarUrl
}
property var saveAvatarUrl: Kazv.AsyncHandler {
diff --git a/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml b/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml
--- a/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml
+++ b/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml
@@ -20,6 +20,7 @@
])
property var deleteDownloadJob: mockHelper.noop()
property var deleteUploadJob: mockHelper.noop()
+ property var cacheFile: mockHelper.noop()
function getDownloadJob (jobId) {
const component = Qt.createComponent("KazvIOJobMock.qml");
diff --git a/src/tests/quick-tests/tst_AvatarImageAdapters.qml b/src/tests/quick-tests/tst_AvatarImageAdapters.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_AvatarImageAdapters.qml
@@ -0,0 +1,48 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick
+import QtQuick.Layouts
+import QtTest
+import '../../contents/ui' as Kazv
+import './test-helpers' as QmlHelpers
+
+QmlHelpers.TestItem {
+ id: item
+
+ ColumnLayout {
+ Kazv.AvatarAdapter {
+ id: avatar
+ mxcUri: 'mxc://example.com/xxx'
+ }
+ Kazv.ImageAdapter {
+ id: image
+ mxcUri: 'mxc://example.com/yyy'
+ }
+ }
+
+ TestCase {
+ id: avatarImageAdaptersTest
+ name: 'AvatarImageAdaptersTest'
+ when: windowShown
+
+ function init() {
+ item.mockHelper.clearAll();
+ }
+
+ function test_avatarReactive() {
+ compare(item.kazvIOManager.cacheFile.calledTimes(), 0);
+ avatar.mxcUri = 'mxc://example.com/zzz';
+ compare(item.kazvIOManager.cacheFile.calledTimes(), 1);
+ }
+
+ function test_imageReactive() {
+ compare(item.kazvIOManager.cacheFile.calledTimes(), 0);
+ image.mxcUri = 'mxc://example.com/zzz';
+ compare(item.kazvIOManager.cacheFile.calledTimes(), 1);
+ }
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 5:03 PM (12 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39904
Default Alt Text
D192.1732583015.diff (9 KB)

Event Timeline