From 09c041c8ac40d2d3608c7224614fde69e1e4f08b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 28 Aug 2021 00:38:33 +0200 Subject: Use in memory media player instead of storing unencrypted files on disk --- resources/qml/ForwardCompleter.qml | 5 +-- resources/qml/MessageInput.qml | 9 ++--- resources/qml/QuickSwitcher.qml | 5 +-- resources/qml/delegates/PlayableMediaMessage.qml | 50 +++++++++++------------- 4 files changed, 30 insertions(+), 39 deletions(-) (limited to 'resources') diff --git a/resources/qml/ForwardCompleter.qml b/resources/qml/ForwardCompleter.qml index fdfcec6f..eccd6ce9 100644 --- a/resources/qml/ForwardCompleter.qml +++ b/resources/qml/ForwardCompleter.qml @@ -85,11 +85,10 @@ Popup { completerPopup.up(); } else if ((event.key == Qt.Key_Down || event.key == Qt.Key_Tab) && completerPopup.opened) { event.accepted = true; - if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) { + if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) completerPopup.up(); - } else { + else completerPopup.down(); - } } else if (event.matches(StandardKey.InsertParagraphSeparator)) { completerPopup.finishCompletion(); event.accepted = true; diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index 36d8fbce..e1bf3f06 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -134,9 +134,9 @@ Rectangle { return ; room.input.updateState(selectionStart, selectionEnd, cursorPosition, text); - if (popup.opened && cursorPosition <= completerTriggeredAt) { + if (popup.opened && cursorPosition <= completerTriggeredAt) popup.close(); - } + if (popup.opened) popup.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)); @@ -195,11 +195,10 @@ Rectangle { } else if (event.key == Qt.Key_Tab) { event.accepted = true; if (popup.opened) { - if (event.modifiers & Qt.ShiftModifier) { + if (event.modifiers & Qt.ShiftModifier) popup.down(); - } else { + else popup.up(); - } } else { var pos = cursorPosition - 1; while (pos > -1) { diff --git a/resources/qml/QuickSwitcher.qml b/resources/qml/QuickSwitcher.qml index fe1936af..c7141c81 100644 --- a/resources/qml/QuickSwitcher.qml +++ b/resources/qml/QuickSwitcher.qml @@ -44,11 +44,10 @@ Popup { completerPopup.up(); } else if ((event.key == Qt.Key_Down || event.key == Qt.Key_Tab) && completerPopup.opened) { event.accepted = true; - if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) { + if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) completerPopup.up(); - } else { + else completerPopup.down(); - } } else if (event.matches(StandardKey.InsertParagraphSeparator)) { completerPopup.finishCompletion(); event.accepted = true; diff --git a/resources/qml/delegates/PlayableMediaMessage.qml b/resources/qml/delegates/PlayableMediaMessage.qml index 73c74ec0..94c058ab 100644 --- a/resources/qml/delegates/PlayableMediaMessage.qml +++ b/resources/qml/delegates/PlayableMediaMessage.qml @@ -3,9 +3,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later import "../" -import QtMultimedia 5.6 -import QtQuick 2.12 -import QtQuick.Controls 2.1 +import QtMultimedia 5.15 +import QtQuick 2.15 +import QtQuick.Controls 2.15 import QtQuick.Layouts 1.2 import im.nheko 1.0 @@ -55,7 +55,8 @@ Rectangle { VideoOutput { anchors.fill: parent fillMode: VideoOutput.PreserveAspectFit - source: media + flushMode: VideoOutput.FirstFrame + source: mxcmedia } } @@ -93,15 +94,15 @@ Rectangle { return hh + ":" + mm + ":" + ss; } - positionText.text = formatTime(new Date(media.position)); - durationText.text = formatTime(new Date(media.duration)); + positionText.text = formatTime(new Date(mxcmedia.position)); + durationText.text = formatTime(new Date(mxcmedia.duration)); } Layout.fillWidth: true - value: media.position + value: mxcmedia.position from: 0 - to: media.duration - onMoved: media.seek(value) + to: mxcmedia.duration + onMoved: mxcmedia.position = value onValueChanged: updatePositionTexts() palette: Nheko.colors } @@ -132,15 +133,15 @@ Rectangle { onClicked: { switch (button.state) { case "": - room.cacheMedia(eventId); + mxcmedia.eventId = eventId; break; case "stopped": - media.play(); + mxcmedia.play(); console.log("play"); button.state = "playing"; break; case "playing": - media.pause(); + mxcmedia.pause(); console.log("pause"); button.state = "stopped"; break; @@ -172,29 +173,22 @@ Rectangle { cursorShape: Qt.PointingHandCursor } - MediaPlayer { - id: media + MxcMedia { + id: mxcmedia + roomm: room onError: console.log(errorString) - onStatusChanged: { - if (status == MediaPlayer.Loaded) + onMediaStatusChanged: { + if (status == MxcMedia.LoadedMedia) { progress.updatePositionTexts(); - + button.state = "stopped"; + } } - onStopped: button.state = "stopped" - } - - Connections { - function onMediaCached(mxcUrl, cacheUrl) { - if (mxcUrl == url) { - media.source = cacheUrl; + onStateChanged: { + if (state == MxcMedia.StoppedState) { button.state = "stopped"; - console.log("media loaded: " + mxcUrl + " at " + cacheUrl); } - console.log("media cached: " + mxcUrl + " at " + cacheUrl); } - - target: room } } -- cgit 1.4.1