Skip to content
Snippets Groups Projects
Commit 90e9a36a authored by Sébastien Blin's avatar Sébastien Blin
Browse files

datatransfer: allow to download a cancelled file

Change-Id: If94c5e1c24d1a90f7a20f29bafc087d26782fe67
GitLab: #1523
parent 95e36ef8
No related branches found
No related tags found
No related merge requests found
...@@ -34,17 +34,19 @@ Loader { ...@@ -34,17 +34,19 @@ Loader {
property bool showTime property bool showTime
property bool showDay property bool showDay
property int timestamp: Timestamp property int timestamp: Timestamp
property string formattedTime: MessagesAdapter.getFormattedTime(Timestamp) property string formattedTime: MessagesAdapter.getFormattedTime(root.timestamp)
property string formattedDay: MessagesAdapter.getFormattedDay(Timestamp) property string formattedDay: MessagesAdapter.getFormattedDay(root.timestamp)
property int seq: MsgSeq.single property int seq: MsgSeq.single
property string author: Author property string author: Author
property string body: Body
property var status: Status
width: ListView.view ? ListView.view.width : 0 width: ListView.view ? ListView.view.width : 0
sourceComponent: { sourceComponent: {
if (Status === Interaction.Status.TRANSFER_FINISHED) { if (root.status === Interaction.Status.TRANSFER_FINISHED) {
mediaInfo = MessagesAdapter.getMediaInfo(Body) mediaInfo = MessagesAdapter.getMediaInfo(root.body)
if (Object.keys(mediaInfo).length !== 0 && WITH_WEBENGINE) if (Object.keys(mediaInfo).length !== 0 && WITH_WEBENGINE)
return localMediaMsgComp return localMediaMsgComp
} }
...@@ -61,8 +63,9 @@ Loader { ...@@ -61,8 +63,9 @@ Loader {
SBSMessageBase { SBSMessageBase {
id: dataTransferItem id: dataTransferItem
property var transferStats: MessagesAdapter.getTransferStats(Id, Status) transferId: Id
property bool canOpen: Status === Interaction.Status.TRANSFER_FINISHED || isOutgoing property var transferStats: MessagesAdapter.getTransferStats(transferId, root.Status)
property bool canOpen: root.status === Interaction.Status.TRANSFER_FINISHED || isOutgoing
property real maxMsgWidth: root.width - senderMargin - property real maxMsgWidth: root.width - senderMargin -
2 * hPadding - avatarBlockWidth 2 * hPadding - avatarBlockWidth
- buttonsLoader.width - 24 - 6 - 24 - buttonsLoader.width - 24 - 6 - 24
...@@ -73,7 +76,6 @@ Loader { ...@@ -73,7 +76,6 @@ Loader {
author: Author author: Author
location: Body location: Body
transferName: TransferName transferName: TransferName
transferId: Id
readers: Readers readers: Readers
timestamp: root.timestamp timestamp: root.timestamp
formattedTime: root.formattedTime formattedTime: root.formattedTime
...@@ -90,7 +92,7 @@ Loader { ...@@ -90,7 +92,7 @@ Loader {
enabled: canOpen enabled: canOpen
onHoveredChanged: { onHoveredChanged: {
if (enabled && hovered) { if (enabled && hovered) {
dataTransferItem.hoveredLink = UtilsAdapter.urlFromLocalPath(Body) dataTransferItem.hoveredLink = UtilsAdapter.urlFromLocalPath(location)
} else { } else {
dataTransferItem.hoveredLink = "" dataTransferItem.hoveredLink = ""
} }
...@@ -101,33 +103,30 @@ Loader { ...@@ -101,33 +103,30 @@ Loader {
} }
Loader { Loader {
id: buttonsLoader id: buttonsLoader
objectName: "buttonsLoader"
property string iconSourceA property string iconSource
property string iconSourceB
Layout.margins: 8 Layout.margins: 8
sourceComponent: { sourceComponent: {
switch (Status) { switch (root.status) {
case Interaction.Status.TRANSFER_CREATED:
case Interaction.Status.TRANSFER_FINISHED:
iconSource = JamiResources.link_black_24dp_svg
return terminatedComp
case Interaction.Status.TRANSFER_CANCELED: case Interaction.Status.TRANSFER_CANCELED:
case Interaction.Status.TRANSFER_ERROR: case Interaction.Status.TRANSFER_ERROR:
case Interaction.Status.TRANSFER_UNJOINABLE_PEER: case Interaction.Status.TRANSFER_UNJOINABLE_PEER:
case Interaction.Status.TRANSFER_TIMEOUT_EXPIRED: case Interaction.Status.TRANSFER_TIMEOUT_EXPIRED:
iconSourceA = JamiResources.error_outline_black_24dp_svg
return terminatedComp
case Interaction.Status.TRANSFER_CREATED:
case Interaction.Status.TRANSFER_FINISHED:
iconSourceA = JamiResources.link_black_24dp_svg
return terminatedComp
case Interaction.Status.TRANSFER_AWAITING_HOST: case Interaction.Status.TRANSFER_AWAITING_HOST:
iconSourceA = JamiResources.download_black_24dp_svg iconSource = JamiResources.download_black_24dp_svg
iconSourceB = JamiResources.close_black_24dp_svg
return optionsComp return optionsComp
case Interaction.Status.TRANSFER_ONGOING: case Interaction.Status.TRANSFER_ONGOING:
iconSourceA = JamiResources.close_black_24dp_svg iconSource = JamiResources.close_black_24dp_svg
return optionsComp return optionsComp
default: default:
iconSourceA = JamiResources.error_outline_black_24dp_svg iconSource = JamiResources.error_outline_black_24dp_svg
return terminatedComp return terminatedComp
} }
} }
...@@ -146,41 +145,22 @@ Loader { ...@@ -146,41 +145,22 @@ Loader {
} }
contentItem: ResponsiveImage { contentItem: ResponsiveImage {
source: buttonsLoader.iconSourceA source: buttonsLoader.iconSource
color: UtilsAdapter.luma(bubble.color) ? JamiTheme.fileIconLightColor : JamiTheme.fileIconDarkColor color: UtilsAdapter.luma(bubble.color) ? JamiTheme.fileIconLightColor : JamiTheme.fileIconDarkColor
} }
} }
} }
Component { Component {
id: optionsComp id: optionsComp
ColumnLayout { PushButton {
Layout.leftMargin: 12 source: buttonsLoader.iconSource
PushButton { normalColor: JamiTheme.chatviewBgColor
source: buttonsLoader.iconSourceA imageColor: JamiTheme.chatviewButtonColor
normalColor: JamiTheme.chatviewBgColor onClicked: {
imageColor: JamiTheme.chatviewButtonColor if (root.status === Interaction.Status.TRANSFER_ONGOING) {
onClicked: { return MessagesAdapter.cancelFile(transferId)
switch (Status) { } else {
case Interaction.Status.TRANSFER_ONGOING: return MessagesAdapter.acceptFile(transferId)
return MessagesAdapter.cancelFile(Id)
case Interaction.Status.TRANSFER_AWAITING_HOST:
return MessagesAdapter.acceptFile(Id)
default: break
}
}
}
PushButton {
visible: !CurrentConversation.isSwarm
height: visible * implicitHeight
source: buttonsLoader.iconSourceB
normalColor: JamiTheme.chatviewBgColor
imageColor: JamiTheme.chatviewButtonColor
onClicked: {
switch (Status) {
case Interaction.Status.TRANSFER_AWAITING_HOST:
return MessagesAdapter.cancelFile(Id)
default: break
}
} }
} }
} }
...@@ -190,13 +170,11 @@ Loader { ...@@ -190,13 +170,11 @@ Loader {
Layout.rightMargin: 24 Layout.rightMargin: 24
spacing: 4 spacing: 4
TextEdit { TextEdit {
id: transferName
width: Math.min(implicitWidth, maxMsgWidth) width: Math.min(implicitWidth, maxMsgWidth)
topPadding: 10 topPadding: 10
text: CurrentConversation.isSwarm ? text: CurrentConversation.isSwarm ?
TransferName : transferName :
Body location
wrapMode: Label.WrapAtWordBoundaryOrAnywhere wrapMode: Label.WrapAtWordBoundaryOrAnywhere
font.pointSize: 11 font.pointSize: 11
renderType: Text.NativeRendering renderType: Text.NativeRendering
...@@ -211,7 +189,7 @@ Loader { ...@@ -211,7 +189,7 @@ Loader {
Qt.ArrowCursor Qt.ArrowCursor
onClicked: function (mouse) { onClicked: function (mouse) {
if (canOpen) { if (canOpen) {
dataTransferItem.hoveredLink = UtilsAdapter.urlFromLocalPath(Body) dataTransferItem.hoveredLink = UtilsAdapter.urlFromLocalPath(location)
Qt.openUrlExternally(new Url(dataTransferItem.hoveredLink)) Qt.openUrlExternally(new Url(dataTransferItem.hoveredLink))
} else { } else {
dataTransferItem.hoveredLink = "" dataTransferItem.hoveredLink = ""
...@@ -248,7 +226,7 @@ Loader { ...@@ -248,7 +226,7 @@ Loader {
,ProgressBar { ,ProgressBar {
id: progressBar id: progressBar
visible: Status === Interaction.Status.TRANSFER_ONGOING visible: root.status === Interaction.Status.TRANSFER_ONGOING
height: visible * implicitHeight height: visible * implicitHeight
value: transferStats.progress / transferStats.totalSize value: transferStats.progress / transferStats.totalSize
width: transferItem.width width: transferItem.width
...@@ -265,16 +243,16 @@ Loader { ...@@ -265,16 +243,16 @@ Loader {
id: localMediaMsgItem id: localMediaMsgItem
isOutgoing: Author === CurrentAccount.uri isOutgoing: Author === CurrentAccount.uri
property var transferStats: MessagesAdapter.getTransferStats(Id, Status) transferId: Id
property var transferStats: MessagesAdapter.getTransferStats(transferId, root.status)
showTime: root.showTime showTime: root.showTime
seq: root.seq seq: root.seq
author: Author author: Author
location: Body location: Body
transferName: TransferName transferName: TransferName
transferId: Id
readers: Readers readers: Readers
formattedTime: MessagesAdapter.getFormattedTime(Timestamp) formattedTime: MessagesAdapter.getFormattedTime(root.timestamp)
formattedDay: MessagesAdapter.getFormattedDay(Timestamp) formattedDay: MessagesAdapter.getFormattedDay(root.timestamp)
property real contentWidth property real contentWidth
...@@ -420,7 +398,7 @@ Loader { ...@@ -420,7 +398,7 @@ Loader {
readonly property real aspectRatio: paintedWidth / paintedHeight readonly property real aspectRatio: paintedWidth / paintedHeight
readonly property real idealWidth: innerContent.width - senderMargin readonly property real idealWidth: innerContent.width - senderMargin
onStatusChanged: { onStatusChanged: {
if (status == Image.Ready && aspectRatio) { if (root.status == Image.Ready && aspectRatio) {
height = Qt.binding(() => JamiQmlUtils.clamp(idealWidth / aspectRatio, 64, 256)) height = Qt.binding(() => JamiQmlUtils.clamp(idealWidth / aspectRatio, 64, 256))
width = Qt.binding(() => height * aspectRatio) width = Qt.binding(() => height * aspectRatio)
......
/*
* Copyright (C) 2024 Savoir-faire Linux Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
import QtTest
import net.jami.Adapters 1.1
import net.jami.Models 1.1
import net.jami.Constants 1.1
import net.jami.Enums 1.1
import "../../../src/app/"
import "../../../src/app/mainview"
import "../../../src/app/mainview/components"
import "../../../src/app/commoncomponents"
DataTransferMessageDelegate {
id: uut
timestamp: 0
status: Interaction.Status.TRANSFER_FINISHED
author: ""
body: ""
TestCase {
name: "Check basic visibility for header buttons"
function test_checkBasicVisibility() {
var buttonsLoader = findChild(uut, "buttonsLoader")
uut.status = Interaction.Status.TRANSFER_AWAITING_HOST
compare(buttonsLoader.iconSource, JamiResources.download_black_24dp_svg)
uut.status = Interaction.Status.TRANSFER_FINISHED
compare(buttonsLoader.iconSource, JamiResources.link_black_24dp_svg)
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment