Newer
Older
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Mingrui Zhang <mingrui.zhang@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.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import net.jami.Models 1.0
import net.jami.Constants 1.0
import net.jami.Adapters 1.0
import "../../commoncomponents"
import "../../commoncomponents/emojipicker"
Rectangle {
id: root
property string previousConvId: ""
function setFilePathsToSend(filePaths) {
for (var index = 0; index < filePaths.length; ++index) {
var path = UtilsAdapter.getAbsPath(filePaths[index])
dataTransferSendContainer.filesToSendListModel.addToPending(path)
}
}
implicitHeight: footerColumnLayout.implicitHeight
color: JamiTheme.primaryBackgroundColor
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
Connections {
target: LRCInstance
function onSelectedConvUidChanged() {
// Handle Draft
if (previousConvId !== "") {
LRCInstance.setContentDraft(previousConvId, LRCInstance.currentAccountId,
messageBar.text);
}
messageBar.textAreaObj.clearText()
previousConvId = LRCInstance.selectedConvUid
var restoredContent = LRCInstance.getContentDraft(LRCInstance.selectedConvUid,
LRCInstance.currentAccountId);
if (restoredContent)
messageBar.textAreaObj.insertText(restoredContent)
}
}
Connections {
target: MessagesAdapter
function onNewMessageBarPlaceholderText(placeholderText) {
messageBar.textAreaObj.placeholderText = JamiStrings.writeTo.arg(placeholderText)
}
function onNewFilePasted(filePath) {
dataTransferSendContainer.filesToSendListModel.addToPending(filePath)
}
function onNewTextPasted() {
messageBar.textAreaObj.pasteText()
}
function onChangeInvitationViewRequest(show, isSwarm) {
var footerVisibility = show ? !isSwarm : !show
messageBar.visible = footerVisibility
dataTransferSendContainer.visible = footerVisibility
root.visible = footerVisibility
}
}
RecordBox{
id: recordBox
visible: false
}
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
EmojiPicker {
id: emojiPicker
onEmojiIsPicked: messageBar.textAreaObj.insertText(content)
}
JamiFileDialog {
id: jamiFileDialog
mode: JamiFileDialog.Mode.OpenFiles
onAccepted: setFilePathsToSend(jamiFileDialog.files)
}
ColumnLayout {
id: footerColumnLayout
anchors.centerIn: root
width: root.width
spacing: 0
MessageBar {
id: messageBar
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: footerColumnLayout.width
Layout.preferredHeight: implicitHeight
onTextChanged: {
if (text)
showSendMessageButton()
else if (!dataTransferSendContainer.filesToSendCount)
hideSendMessageButton()
}
onEmojiButtonClicked: {
JamiQmlUtils.updateMessageBarButtonsPoints()
emojiPicker.parent = JamiQmlUtils.mainViewRectObj
emojiPicker.x = Qt.binding(function() {
var buttonX = JamiQmlUtils.emojiPickerButtonInMainViewPoint.x +
JamiQmlUtils.emojiPickerButtonObj.width
return buttonX - emojiPicker.width
})
emojiPicker.y = Qt.binding(function() {
var buttonY = JamiQmlUtils.audioRecordMessageButtonInMainViewPoint.y
return buttonY - emojiPicker.height - messageBar.marginSize
- JamiTheme.messageWebViewHairLineSize
})
emojiPicker.openEmojiPicker()
}
onSendFileButtonClicked: jamiFileDialog.open()
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
onSendMessageButtonClicked: {
// Send text message
if (messageBar.text)
MessagesAdapter.sendMessage(messageBar.text)
messageBar.textAreaObj.clearText()
// Send file messages
var fileCounts = dataTransferSendContainer.filesToSendListModel.rowCount()
for (var i = 0; i < fileCounts; i++) {
var currentIndex = dataTransferSendContainer.filesToSendListModel.index(i, 0)
var filePath = dataTransferSendContainer.filesToSendListModel.data(
currentIndex, FilesToSend.FilePath)
MessagesAdapter.sendFile(filePath)
}
dataTransferSendContainer.filesToSendListModel.flush()
}
onVideoRecordMessageButtonClicked: {
JamiQmlUtils.updateMessageBarButtonsPoints()
recordBox.parent = JamiQmlUtils.mainViewRectObj
recordBox.x = Qt.binding(function() {
var buttonCenterX = JamiQmlUtils.videoRecordMessageButtonInMainViewPoint.x +
JamiQmlUtils.videoRecordMessageButtonObj.width / 2
return buttonCenterX - recordBox.width / 2
})
recordBox.y = Qt.binding(function() {
var buttonY = JamiQmlUtils.videoRecordMessageButtonInMainViewPoint.y
return buttonY - recordBox.height - recordBox.spikeHeight
})
recordBox.openRecorder(true)
}
onAudioRecordMessageButtonClicked: {
JamiQmlUtils.updateMessageBarButtonsPoints()
recordBox.parent = JamiQmlUtils.mainViewRectObj
recordBox.x = Qt.binding(function() {
var buttonCenterX = JamiQmlUtils.audioRecordMessageButtonInMainViewPoint.x +
JamiQmlUtils.audioRecordMessageButtonObj.width / 2
return buttonCenterX - recordBox.width / 2
})
recordBox.y = Qt.binding(function() {
var buttonY = JamiQmlUtils.audioRecordMessageButtonInMainViewPoint.y
return buttonY - recordBox.height - recordBox.spikeHeight
})
recordBox.openRecorder(false)
}
}
FilesToSendContainer {
id: dataTransferSendContainer
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: footerColumnLayout.width
Layout.maximumWidth: JamiTheme.messageWebViewFooterContentMaximumWidth
Layout.preferredHeight: filesToSendCount ?
JamiTheme.messageWebViewFooterFileContainerPreferredHeight : 0
onFilesToSendCountChanged: {
if (filesToSendCount !== 0)
messageBar.showSendMessageButton()
else if (!messageBar.text)
messageBar.hideSendMessageButton()
}
}