Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Albert Babí <albert.babi@savoirfairelinux.com>
*
* 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 2.15
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.3
import QtGraphicalEffects 1.0
import net.jami.Models 1.0
import "../../commoncomponents"
Rectangle {
enum States {
INIT,
RECORDING,
REC_SUCCESS
}
id:recBox
color: "#FFFFFF"
width: 320
height: 240
radius: 5
border.color: JamiTheme.tabbarBorderColor
property string pathRecorder: ""
property string timeText: "00:00"
property int duration: 0
property int state: RecordBox.States.INIT
property bool isVideo: false
property bool previewAvailable: false
property int h_offset: -65
property int v_offset: -65
function openRecorder(set_x, set_y, vid) {
focus = true
visible = true
x = set_x+(width/2)+h_offset
y = set_y-(height/2)+v_offset
updateState(RecordBox.States.INIT)
isVideo = vid
if (isVideo){
ClientWrapper.accountAdaptor.startPreviewing(false)
previewAvailable = true
}
}
onActiveFocusChanged: {
if (visible) {
closeRecorder()
}
}
onVisibleChanged: {
if(!visible) {
closeRecorder()
}
}
function closeRecorder() {
if (isVideo && ClientWrapper.accountAdaptor.isPreviewing()) {
ClientWrapper.accountAdaptor.stopPreviewing()
}
stopRecording()
visible = false
}
function updateState(new_state) {
state = new_state
recordButton.visible = (state == RecordBox.States.INIT)
btnStop.visible = (state == RecordBox.States.RECORDING)
btnRestart.visible = (state == RecordBox.States.REC_SUCCESS)
btnSend.visible = (state == RecordBox.States.REC_SUCCESS)
if (state == RecordBox.States.INIT) {
duration = 0
time.text = "00:00"
timer.stop()
} else if (state == RecordBox.States.REC_SUCCESS) {
timer.stop()
}
}
function startRecording() {
timer.start()
pathRecorder = ClientWrapper.avmodel.startLocalRecorder(!isVideo)
if (pathRecorder == "") {
timer.stop()
}
}
function stopRecording() {
if (pathRecorder != "") {
ClientWrapper.avmodel.stopLocalRecorder(pathRecorder)
}
}
function sendRecord() {
if (pathRecorder != "") {
MessagesAdapter.sendFile(pathRecorder)
}
}
function updateTimer() {
duration += 1
var m = Math.trunc(duration / 60)
var s = (duration % 60)
var min = (m < 10) ? "0" + String(m) : String(m)
var sec = (s < 10) ? "0" + String(s) : String(s)
time.text = min + ":" + sec;
}
Connections{
target: ClientWrapper.renderManager
}
Rectangle {
id: rectBox
visible: (isVideo && previewAvailable)
Layout.alignment: Qt.AlignHCenter
anchors.fill: parent
color: "black"
radius: 5
PreviewRenderer{
id: previewWidget
anchors.fill: rectBox
anchors.centerIn: rectBox
layer.enabled: true
layer.effect: OpacityMask {
maskSource: rectBox
}
}
}
Label {
visible: (isVideo && !previewAvailable)
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
text: qsTr("Preview unavailable")
font.pointSize: 10
font.kerning: true
}
Timer {
id: timer
interval: 1000;
running: false;
repeat: true
onTriggered: updateTimer()
}
Text {
id: time
visible: true
text: "00:00"
color: (isVideo ? "white" : "black")
font.pointSize: (isVideo ? 12 : 20)
anchors.horizontalCenter: parent.horizontalCenter
anchors.horizontalCenterOffset: (isVideo ? 100 : 0)
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenterOffset: (isVideo ? 100 : 0)
}
HoverableRadiusButton {
id: recordButton
Layout.maximumWidth: 30
Layout.preferredWidth: 30
Layout.minimumWidth: 30
Layout.maximumHeight: 30
Layout.preferredHeight: 30
Layout.minimumHeight: 30
buttonImageHeight: height
buttonImageWidth: height
backgroundColor: isVideo? "#000000cc" : "white"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
radius: height / 2
icon.source: "qrc:/images/icons/av_icons/fiber_manual_record-24px.svg"
icon.height: 24
icon.width: 24
icon.color: "#dc2719"
onClicked: {
updateState(RecordBox.States.RECORDING)
startRecording()
}
}
HoverableRadiusButton {
id: btnStop
Layout.maximumWidth: 30
Layout.preferredWidth: 30
Layout.minimumWidth: 30
Layout.maximumHeight: 30
Layout.preferredHeight: 30
Layout.minimumHeight: 30
buttonImageHeight: height
buttonImageWidth: height
backgroundColor: isVideo? "#000000cc" : "white"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
radius: height / 2
icon.source: "qrc:/images/icons/av_icons/stop-24px-red.svg"
icon.height: 24
icon.width: 24
icon.color: isVideo? "white" : "black"
onClicked: {
stopRecording()
updateState(RecordBox.States.REC_SUCCESS)
}
}
HoverableRadiusButton {
id: btnRestart
Layout.maximumWidth: 30
Layout.preferredWidth: 30
Layout.minimumWidth: 30
Layout.maximumHeight: 30
Layout.preferredHeight: 30
Layout.minimumHeight: 30
buttonImageHeight: height
buttonImageWidth: height
backgroundColor: isVideo? "#000000cc" : "white"
anchors.horizontalCenter: parent.horizontalCenter
anchors.right: btnRestart.left
anchors.rightMargin: 5
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
radius: height / 2
icon.source: "qrc:/images/icons/av_icons/re-record-24px.svg"
icon.height: 24
icon.width: 24
icon.color: isVideo? "white" : "black"
onClicked: {
stopRecording()
updateState(RecordBox.States.INIT)
}
}
HoverableRadiusButton {
id: btnSend
Layout.maximumWidth: 30
Layout.preferredWidth: 30
Layout.minimumWidth: 30
Layout.maximumHeight: 30
Layout.preferredHeight: 30
Layout.minimumHeight: 30
buttonImageHeight: height
buttonImageWidth: height
backgroundColor: isVideo? "#000000cc" : "white"
anchors.left: btnRestart.right
anchors.leftMargin: 5
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
radius: height / 2
icon.source: "qrc:/images/icons/av_icons/send-24px.svg"
icon.height: 24
icon.width: 24
icon.color: isVideo? "white" : "black"
onClicked: {
stopRecording()
sendRecord()
closeRecorder()
updateState(RecordBox.States.INIT)
}
}
}