| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import "../" |
| 6 |
import QtQuick 2.9 |
| 7 |
import QtQuick.Controls 2.3 |
| 8 |
import QtQuick.Layouts 1.2 |
| 9 |
import im.nheko 1.0 |
| 10 |
|
| 11 |
Rectangle { |
| 12 |
visible: CallManager.isOnCall |
| 13 |
color: callInviteBar.color |
| 14 |
implicitHeight: visible ? rowLayout.height + 8 : 0 |
| 15 |
|
| 16 |
MouseArea { |
| 17 |
anchors.fill: parent |
| 18 |
onClicked: { |
| 19 |
if (CallManager.callType != Voip.VOICE) |
| 20 |
stackLayout.currentIndex = stackLayout.currentIndex ? 0 : 1; |
| 21 |
|
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
RowLayout { |
| 26 |
id: rowLayout |
| 27 |
|
| 28 |
anchors.left: parent.left |
| 29 |
anchors.right: parent.right |
| 30 |
anchors.verticalCenter: parent.verticalCenter |
| 31 |
anchors.leftMargin: 8 |
| 32 |
|
| 33 |
Avatar { |
| 34 |
implicitWidth: Nheko.avatarSize |
| 35 |
implicitHeight: Nheko.avatarSize |
| 36 |
url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/") |
| 37 |
userid: CallManager.callParty |
| 38 |
displayName: CallManager.callPartyDisplayName |
| 39 |
onClicked: TimelineManager.openImageOverlay(room, room.avatarUrl(userid), room.data.eventId) |
| 40 |
} |
| 41 |
|
| 42 |
Label { |
| 43 |
Layout.leftMargin: 8 |
| 44 |
font.pointSize: fontMetrics.font.pointSize * 1.1 |
| 45 |
text: CallManager.callPartyDisplayName |
| 46 |
color: "#000000" |
| 47 |
} |
| 48 |
|
| 49 |
Image { |
| 50 |
id: callTypeIcon |
| 51 |
|
| 52 |
Layout.leftMargin: 4 |
| 53 |
Layout.preferredWidth: 24 |
| 54 |
Layout.preferredHeight: 24 |
| 55 |
} |
| 56 |
|
| 57 |
Item { |
| 58 |
states: [ |
| 59 |
State { |
| 60 |
name: "VOICE" |
| 61 |
when: CallManager.callType == Voip.VOICE |
| 62 |
|
| 63 |
PropertyChanges { |
| 64 |
callTypeIcon.source: "qrc:/icons/icons/ui/place-call.svg" |
| 65 |
} |
| 66 |
|
| 67 |
}, |
| 68 |
State { |
| 69 |
name: "VIDEO" |
| 70 |
when: CallManager.callType == Voip.VIDEO |
| 71 |
|
| 72 |
PropertyChanges { |
| 73 |
callTypeIcon.source: "qrc:/icons/icons/ui/video.svg" |
| 74 |
} |
| 75 |
|
| 76 |
}, |
| 77 |
State { |
| 78 |
name: "SCREEN" |
| 79 |
when: CallManager.callType == Voip.SCREEN |
| 80 |
|
| 81 |
PropertyChanges { |
| 82 |
callTypeIcon.source: "qrc:/icons/icons/ui/screen-share.svg" |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
] |
| 87 |
} |
| 88 |
|
| 89 |
Label { |
| 90 |
id: callStateLabel |
| 91 |
|
| 92 |
font.pointSize: fontMetrics.font.pointSize * 1.1 |
| 93 |
color: "#000000" |
| 94 |
} |
| 95 |
|
| 96 |
Item { |
| 97 |
states: [ |
| 98 |
State { |
| 99 |
name: "OFFERSENT" |
| 100 |
when: CallManager.callState == Voip.OFFERSENT |
| 101 |
|
| 102 |
PropertyChanges { |
| 103 |
callStateLabel.text: qsTr("Calling...") |
| 104 |
} |
| 105 |
|
| 106 |
}, |
| 107 |
State { |
| 108 |
name: "CONNECTING" |
| 109 |
when: CallManager.callState == Voip.CONNECTING |
| 110 |
|
| 111 |
PropertyChanges { |
| 112 |
callStateLabel.text: qsTr("Connecting...") |
| 113 |
} |
| 114 |
|
| 115 |
}, |
| 116 |
State { |
| 117 |
name: "ANSWERSENT" |
| 118 |
when: CallManager.callState == Voip.ANSWERSENT |
| 119 |
|
| 120 |
PropertyChanges { |
| 121 |
callStateLabel.text: qsTr("Connecting...") |
| 122 |
} |
| 123 |
|
| 124 |
}, |
| 125 |
State { |
| 126 |
name: "CONNECTED" |
| 127 |
when: CallManager.callState == Voip.CONNECTED |
| 128 |
|
| 129 |
PropertyChanges { |
| 130 |
callStateLabel.text: "00:00" |
| 131 |
} |
| 132 |
|
| 133 |
PropertyChanges { |
| 134 |
callTimer.startTime: Math.floor((new Date()).getTime() / 1000) |
| 135 |
} |
| 136 |
|
| 137 |
// HACK(Nico): Somehow this causes a crash when not using the custom parser for that property change... |
| 138 |
//PropertyChanges { |
| 139 |
// stackLayout.currentIndex: CallManager.callType != Voip.VOICE ? 1 : 0 |
| 140 |
//} |
| 141 |
|
| 142 |
PropertyChanges { |
| 143 |
target: stackLayout |
| 144 |
currentIndex: CallManager.callType != Voip.VOICE ? 1 : 0 // qmllint disable Quick.property-changes-parsed |
| 145 |
} |
| 146 |
|
| 147 |
}, |
| 148 |
State { |
| 149 |
name: "DISCONNECTED" |
| 150 |
when: CallManager.callState == Voip.DISCONNECTED |
| 151 |
|
| 152 |
PropertyChanges { |
| 153 |
callStateLabel.text: "" |
| 154 |
} |
| 155 |
|
| 156 |
// HACK(Nico): Somehow this causes a crash when not using the custom parser for that property change... |
| 157 |
//PropertyChanges { |
| 158 |
// stackLayout.currentIndex: 0 |
| 159 |
//} |
| 160 |
PropertyChanges { |
| 161 |
target: stackLayout |
| 162 |
currentIndex: 0 // qmllint disable Quick.property-changes-parsed |
| 163 |
} |
| 164 |
|
| 165 |
} |
| 166 |
] |
| 167 |
} |
| 168 |
|
| 169 |
Timer { |
| 170 |
id: callTimer |
| 171 |
|
| 172 |
property int startTime |
| 173 |
|
| 174 |
function pad(n) { |
| 175 |
return (n < 10) ? ("0" + n) : n; |
| 176 |
} |
| 177 |
|
| 178 |
interval: 1000 |
| 179 |
running: CallManager.callState == Voip.CONNECTED |
| 180 |
repeat: true |
| 181 |
onTriggered: { |
| 182 |
var d = new Date(); |
| 183 |
let seconds = Math.floor(d.getTime() / 1000 - startTime); |
| 184 |
let s = Math.floor(seconds % 60); |
| 185 |
let m = Math.floor(seconds / 60) % 60; |
| 186 |
let h = Math.floor(seconds / 3600); |
| 187 |
callStateLabel.text = (h ? (pad(h) + ":") : "") + pad(m) + ":" + pad(s); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
Label { |
| 192 |
Layout.leftMargin: 16 |
| 193 |
visible: CallManager.callType == Voip.SCREEN && CallManager.callState == Voip.CONNECTED |
| 194 |
text: qsTr("You are screen sharing") |
| 195 |
font.pointSize: fontMetrics.font.pointSize * 1.1 |
| 196 |
color: "#000000" |
| 197 |
} |
| 198 |
|
| 199 |
Item { |
| 200 |
Layout.fillWidth: true |
| 201 |
} |
| 202 |
|
| 203 |
ImageButton { |
| 204 |
visible: CallManager.haveLocalPiP |
| 205 |
Layout.preferredWidth: 24 |
| 206 |
Layout.preferredHeight: 24 |
| 207 |
buttonTextColor: "#000000" |
| 208 |
image: ":/icons/icons/ui/picture-in-picture.svg" |
| 209 |
hoverEnabled: true |
| 210 |
ToolTip.visible: hovered |
| 211 |
ToolTip.text: qsTr("Hide/Show Picture-in-Picture") |
| 212 |
onClicked: CallManager.toggleLocalPiP() |
| 213 |
} |
| 214 |
|
| 215 |
ImageButton { |
| 216 |
Layout.leftMargin: 8 |
| 217 |
Layout.rightMargin: 16 |
| 218 |
Layout.preferredWidth: 24 |
| 219 |
Layout.preferredHeight: 24 |
| 220 |
buttonTextColor: "#000000" |
| 221 |
image: CallManager.isMicMuted ? ":/icons/icons/ui/microphone-unmute.svg" : ":/icons/icons/ui/microphone-mute.svg" |
| 222 |
hoverEnabled: true |
| 223 |
ToolTip.visible: hovered |
| 224 |
ToolTip.text: CallManager.isMicMuted ? qsTr("Unmute Mic") : qsTr("Mute Mic") |
| 225 |
onClicked: CallManager.toggleMicMute() |
| 226 |
} |
| 227 |
|
| 228 |
} |
| 229 |
|
| 230 |
} |