2020-08-31 11:05:25 +01:00
|
|
|
/**
|
2019-10-27 17:08:51 +00:00
|
|
|
* SPDX-FileCopyrightText: 2020 Aniket Kumar <anikketkumar786@gmail.com>
|
2020-08-31 11:05:25 +01:00
|
|
|
*
|
2019-10-27 17:08:51 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2020-08-31 11:05:25 +01:00
|
|
|
*/
|
|
|
|
|
2023-12-23 16:48:04 +00:00
|
|
|
import QtQuick
|
2023-12-23 20:22:04 +00:00
|
|
|
import QtCore
|
2023-12-23 16:48:04 +00:00
|
|
|
import QtQuick.Controls as Controls
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import org.kde.kirigami as Kirigami
|
2023-09-21 18:23:06 +01:00
|
|
|
import Qt5Compat.GraphicalEffects
|
|
|
|
import QtQuick.Dialogs
|
2023-12-23 16:48:04 +00:00
|
|
|
import org.kde.kdeconnect.sms
|
2020-08-31 11:05:25 +01:00
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: root
|
|
|
|
property var addresses
|
|
|
|
property var selectedFileUrls: []
|
|
|
|
readonly property int maxMessageSize: 600000
|
2022-05-12 19:34:24 +01:00
|
|
|
property alias text: messageField.text
|
2020-08-31 11:05:25 +01:00
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
id: messageDialog
|
|
|
|
title: i18nd("kdeconnect-sms", "Failed to send")
|
|
|
|
text: i18nd("kdeconnect-sms", "Max message size limit exceeded.")
|
|
|
|
|
|
|
|
onAccepted: {
|
|
|
|
messageDialog.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: fileDialog
|
2023-12-23 20:22:04 +00:00
|
|
|
currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]
|
2023-09-21 18:23:06 +01:00
|
|
|
fileMode: FileDialog.OpenFiles
|
2020-08-31 11:05:25 +01:00
|
|
|
|
|
|
|
onAccepted: {
|
|
|
|
root.selectedFileUrls = fileDialog.fileUrls
|
|
|
|
fileDialog.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controls.Pane {
|
|
|
|
id: sendingArea
|
|
|
|
enabled: page.deviceConnected
|
|
|
|
layer.enabled: sendingArea.enabled
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
verticalOffset: 1
|
|
|
|
color: Kirigami.Theme.disabledTextColor
|
|
|
|
samples: 20
|
|
|
|
spread: 0.3
|
|
|
|
}
|
|
|
|
Layout.fillWidth: true
|
|
|
|
padding: 0
|
|
|
|
wheelEnabled: true
|
|
|
|
background: Rectangle {
|
2021-05-23 18:49:40 +01:00
|
|
|
color: Kirigami.Theme.backgroundColor
|
2020-08-31 11:05:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
Controls.ScrollView {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.maximumHeight: page.height > 300 ? page.height / 3 : 2 * page.height / 3
|
|
|
|
contentWidth: page.width - sendButtonArea.width
|
|
|
|
clip: true
|
|
|
|
Controls.ScrollBar.horizontal.policy: Controls.ScrollBar.AlwaysOff
|
|
|
|
|
|
|
|
Controls.TextArea {
|
2023-04-21 17:28:58 +01:00
|
|
|
width: parent.width
|
2020-08-31 11:05:25 +01:00
|
|
|
id: messageField
|
|
|
|
placeholderText: i18nd("kdeconnect-sms", "Compose message")
|
|
|
|
wrapMode: TextEdit.Wrap
|
|
|
|
topPadding: Kirigami.Units.gridUnit * 0.5
|
|
|
|
bottomPadding: topPadding
|
|
|
|
selectByMouse: true
|
2022-02-09 03:47:36 +00:00
|
|
|
hoverEnabled: true
|
|
|
|
background: MouseArea {
|
|
|
|
hoverEnabled: true
|
|
|
|
acceptedButtons: Qt.NoButton
|
|
|
|
cursorShape: Qt.IBeamCursor
|
|
|
|
z: 1
|
|
|
|
}
|
2024-03-11 23:49:45 +00:00
|
|
|
Keys.onReturnPressed: event => {
|
2020-08-31 11:05:25 +01:00
|
|
|
if (event.key === Qt.Key_Return) {
|
|
|
|
if (event.modifiers & Qt.ShiftModifier) {
|
|
|
|
messageField.append("")
|
|
|
|
} else {
|
2024-01-10 17:29:10 +00:00
|
|
|
sendButton.clicked()
|
2020-08-31 11:05:25 +01:00
|
|
|
event.accepted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: sendButtonArea
|
2022-02-09 03:47:36 +00:00
|
|
|
Layout.alignment: Qt.AlignBottom
|
2020-08-31 11:05:25 +01:00
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Controls.ToolButton {
|
|
|
|
id: attachFilesButton
|
|
|
|
enabled: true
|
|
|
|
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
|
|
|
|
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
|
|
|
|
padding: 0
|
|
|
|
Text {
|
|
|
|
id: attachedFilesCount
|
|
|
|
text: selectedFileUrls.length
|
|
|
|
color: "red"
|
|
|
|
visible: selectedFileUrls.length > 0
|
|
|
|
}
|
|
|
|
Kirigami.Icon {
|
|
|
|
source: "insert-image"
|
|
|
|
isMask: true
|
|
|
|
smooth: true
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: Kirigami.Units.gridUnit * 1.5
|
|
|
|
height: width
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
fileDialog.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controls.ToolButton {
|
|
|
|
id: clearAttachmentButton
|
|
|
|
visible: selectedFileUrls.length > 0
|
|
|
|
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
|
|
|
|
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
|
|
|
|
padding: 0
|
|
|
|
Kirigami.Icon {
|
|
|
|
id: cancelIcon
|
|
|
|
source: "edit-clear"
|
|
|
|
isMask: true
|
|
|
|
smooth: true
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: Kirigami.Units.gridUnit * 1.5
|
|
|
|
height: width
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
selectedFileUrls = []
|
|
|
|
}
|
|
|
|
}
|
2022-02-09 03:47:36 +00:00
|
|
|
|
|
|
|
Controls.ToolButton {
|
2023-04-21 17:28:58 +01:00
|
|
|
property bool isSendingInProcess: false
|
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
id: sendButton
|
2023-04-21 17:28:58 +01:00
|
|
|
enabled: (messageField.text.length || selectedFileUrls.length) && !isSendingInProcess
|
2022-02-09 03:47:36 +00:00
|
|
|
Layout.preferredWidth: Kirigami.Units.gridUnit * 2
|
|
|
|
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
|
|
|
|
padding: 0
|
|
|
|
Kirigami.Icon {
|
|
|
|
source: "document-send"
|
|
|
|
enabled: sendButton.enabled
|
|
|
|
isMask: true
|
|
|
|
smooth: true
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: Kirigami.Units.gridUnit * 1.5
|
|
|
|
height: width
|
|
|
|
}
|
|
|
|
|
|
|
|
property bool messageSent: false
|
|
|
|
|
|
|
|
onClicked: {
|
2023-04-21 17:28:58 +01:00
|
|
|
|
|
|
|
// prevent sending the same message several times
|
|
|
|
// and don't touch enabled property
|
|
|
|
if (isSendingInProcess){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isSendingInProcess = true
|
2022-02-09 03:47:36 +00:00
|
|
|
|
|
|
|
if (SmsHelper.totalMessageSize(selectedFileUrls, messageField.text) > maxMessageSize) {
|
|
|
|
messageDialog.visible = true
|
|
|
|
} else if (page.conversationId === page.invalidId) {
|
|
|
|
messageSent = conversationModel.startNewConversation(messageField.text, addresses, selectedFileUrls)
|
|
|
|
} else {
|
|
|
|
messageSent = conversationModel.sendReplyToConversation(messageField.text, selectedFileUrls)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageSent) {
|
|
|
|
messageField.text = ""
|
|
|
|
selectedFileUrls = []
|
|
|
|
}
|
2023-04-21 17:28:58 +01:00
|
|
|
isSendingInProcess = false
|
2022-02-09 03:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-31 11:05:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Controls.Label {
|
2023-04-21 17:28:58 +01:00
|
|
|
id: charCount
|
2020-08-31 11:05:25 +01:00
|
|
|
text: conversationModel.getCharCountInfo(messageField.text)
|
|
|
|
visible: text.length > 0
|
|
|
|
Layout.minimumWidth: Math.max(Layout.minimumWidth, width) // Make this label only grow, never shrink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|