Warning, /network/neochat/src/qml/NeochatMaximizeComponent.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import Qt.labs.platform as Platform
0008 
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.labs.components as Components
0011 
0012 import org.kde.neochat
0013 import org.kde.neochat.config
0014 
0015 Components.AlbumMaximizeComponent {
0016     id: root
0017 
0018     /**
0019      * @brief The current room that user is viewing.
0020      */
0021     required property NeoChatRoom currentRoom
0022 
0023     readonly property string currentEventId: model.data(model.index(content.currentIndex, 0), MessageEventModel.EventIdRole)
0024 
0025     readonly property var currentAuthor: model.data(model.index(content.currentIndex, 0), MessageEventModel.AuthorRole)
0026 
0027     readonly property var currentTime: model.data(model.index(content.currentIndex, 0), MessageEventModel.TimeRole)
0028 
0029     readonly property var currentDelegateType: model.data(model.index(content.currentIndex, 0), MessageEventModel.DelegateTypeRole)
0030 
0031     readonly property string currentPlainText: model.data(model.index(content.currentIndex, 0), MessageEventModel.PlainText)
0032 
0033     readonly property var currentMimeType: model.data(model.index(content.currentIndex, 0), MessageEventModel.MimeTypeRole)
0034 
0035     readonly property var currentProgressInfo: model.data(model.index(content.currentIndex, 0), MessageEventModel.ProgressInfoRole)
0036 
0037     downloadAction: Components.DownloadAction {
0038         id: downloadAction
0039         onTriggered: {
0040             currentRoom.downloadFile(root.currentEventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + root.currentEventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(root.currentEventId))
0041         }
0042     }
0043 
0044     Connections {
0045         target: currentRoom
0046 
0047         function onFileTransferProgress(id, progress, total) {
0048             if (id == root.currentEventId) {
0049                 downloadAction.progress = progress / total * 100.0
0050             }
0051         }
0052     }
0053 
0054     Connections {
0055         target: content
0056 
0057         function onCurrentIndexChanged() {
0058             downloadAction.progress = currentProgressInfo.progress / currentProgressInfo.total * 100.0
0059         }
0060     }
0061 
0062     leading: RowLayout {
0063         Components.Avatar {
0064             id: userAvatar
0065             implicitWidth: Kirigami.Units.iconSizes.medium
0066             implicitHeight: Kirigami.Units.iconSizes.medium
0067 
0068             name: root.currentAuthor.name ?? root.currentAuthor.displayName
0069             source: root.currentAuthor.avatarSource
0070             color: root.currentAuthor.color
0071         }
0072         ColumnLayout {
0073             spacing: 0
0074             QQC2.Label {
0075                 id: userLabel
0076 
0077                 text: root.currentAuthor.name ?? root.currentAuthor.displayName
0078                 color: root.currentAuthor.color
0079                 font.weight: Font.Bold
0080                 elide: Text.ElideRight
0081             }
0082             QQC2.Label {
0083                 id: dateTimeLabel
0084                 text: root.currentTime.toLocaleString(Qt.locale(), Locale.ShortFormat)
0085                 color: Kirigami.Theme.disabledTextColor
0086                 elide: Text.ElideRight
0087             }
0088         }
0089     }
0090     onItemRightClicked: RoomManager.viewEventMenu(root.currentEventId,
0091                                                   root.currentAuthor,
0092                                                   root.currentDelegateType,
0093                                                   root.currentPlainText,
0094                                                   "",
0095                                                   "",
0096                                                   root.currentMimeType,
0097                                                   root.currentProgressInfo)
0098 
0099     onSaveItem: {
0100         var dialog = saveAsDialog.createObject(QQC2.ApplicationWindow.overlay)
0101         dialog.open()
0102         dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(root.currentEventId)
0103     }
0104 
0105     Connections {
0106         target: RoomManager
0107         function onCloseFullScreen() {
0108             root.close()
0109         }
0110     }
0111 
0112     Component {
0113         id: saveAsDialog
0114         Platform.FileDialog {
0115             fileMode: FileDialog.SaveFile
0116             folder: root.saveFolder
0117             onAccepted: {
0118                 Config.lastSaveDirectory = folder
0119                 Config.save()
0120                 if (!currentFile) {
0121                     return;
0122                 }
0123                 currentRoom.downloadFile(rooteventId, currentFile)
0124             }
0125         }
0126     }
0127 }