Warning, /network/kdeconnect-kde/smsapp/qml/SendingArea.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * SPDX-FileCopyrightText: 2020 Aniket Kumar <anikketkumar786@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtQuick 0008 import QtCore 0009 import QtQuick.Controls as Controls 0010 import QtQuick.Layouts 0011 import org.kde.kirigami as Kirigami 0012 import Qt5Compat.GraphicalEffects 0013 import QtQuick.Dialogs 0014 import org.kde.kdeconnect.sms 0015 0016 ColumnLayout { 0017 id: root 0018 property var addresses 0019 property var selectedFileUrls: [] 0020 readonly property int maxMessageSize: 600000 0021 property alias text: messageField.text 0022 0023 MessageDialog { 0024 id: messageDialog 0025 title: i18nd("kdeconnect-sms", "Failed to send") 0026 text: i18nd("kdeconnect-sms", "Max message size limit exceeded.") 0027 0028 onAccepted: { 0029 messageDialog.close() 0030 } 0031 } 0032 0033 FileDialog { 0034 id: fileDialog 0035 currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0] 0036 fileMode: FileDialog.OpenFiles 0037 0038 onAccepted: { 0039 root.selectedFileUrls = fileDialog.fileUrls 0040 fileDialog.close() 0041 } 0042 } 0043 0044 Controls.Pane { 0045 id: sendingArea 0046 enabled: page.deviceConnected 0047 layer.enabled: sendingArea.enabled 0048 layer.effect: DropShadow { 0049 verticalOffset: 1 0050 color: Kirigami.Theme.disabledTextColor 0051 samples: 20 0052 spread: 0.3 0053 } 0054 Layout.fillWidth: true 0055 padding: 0 0056 wheelEnabled: true 0057 background: Rectangle { 0058 color: Kirigami.Theme.backgroundColor 0059 } 0060 0061 RowLayout { 0062 anchors.fill: parent 0063 0064 Controls.ScrollView { 0065 Layout.fillWidth: true 0066 Layout.maximumHeight: page.height > 300 ? page.height / 3 : 2 * page.height / 3 0067 contentWidth: page.width - sendButtonArea.width 0068 clip: true 0069 Controls.ScrollBar.horizontal.policy: Controls.ScrollBar.AlwaysOff 0070 0071 Controls.TextArea { 0072 width: parent.width 0073 id: messageField 0074 placeholderText: i18nd("kdeconnect-sms", "Compose message") 0075 wrapMode: TextEdit.Wrap 0076 topPadding: Kirigami.Units.gridUnit * 0.5 0077 bottomPadding: topPadding 0078 selectByMouse: true 0079 hoverEnabled: true 0080 background: MouseArea { 0081 hoverEnabled: true 0082 acceptedButtons: Qt.NoButton 0083 cursorShape: Qt.IBeamCursor 0084 z: 1 0085 } 0086 Keys.onReturnPressed: { 0087 if (event.key === Qt.Key_Return) { 0088 if (event.modifiers & Qt.ShiftModifier) { 0089 messageField.append("") 0090 } else { 0091 sendButton.clicked() 0092 event.accepted = true 0093 } 0094 } 0095 } 0096 } 0097 } 0098 0099 ColumnLayout { 0100 id: sendButtonArea 0101 Layout.alignment: Qt.AlignBottom 0102 0103 RowLayout { 0104 Controls.ToolButton { 0105 id: attachFilesButton 0106 enabled: true 0107 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0108 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 0109 padding: 0 0110 Text { 0111 id: attachedFilesCount 0112 text: selectedFileUrls.length 0113 color: "red" 0114 visible: selectedFileUrls.length > 0 0115 } 0116 Kirigami.Icon { 0117 source: "insert-image" 0118 isMask: true 0119 smooth: true 0120 anchors.centerIn: parent 0121 width: Kirigami.Units.gridUnit * 1.5 0122 height: width 0123 } 0124 0125 onClicked: { 0126 fileDialog.open() 0127 } 0128 } 0129 0130 Controls.ToolButton { 0131 id: clearAttachmentButton 0132 visible: selectedFileUrls.length > 0 0133 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0134 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 0135 padding: 0 0136 Kirigami.Icon { 0137 id: cancelIcon 0138 source: "edit-clear" 0139 isMask: true 0140 smooth: true 0141 anchors.centerIn: parent 0142 width: Kirigami.Units.gridUnit * 1.5 0143 height: width 0144 } 0145 0146 onClicked: { 0147 selectedFileUrls = [] 0148 } 0149 } 0150 0151 Controls.ToolButton { 0152 property bool isSendingInProcess: false 0153 0154 id: sendButton 0155 enabled: (messageField.text.length || selectedFileUrls.length) && !isSendingInProcess 0156 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0157 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 0158 padding: 0 0159 Kirigami.Icon { 0160 source: "document-send" 0161 enabled: sendButton.enabled 0162 isMask: true 0163 smooth: true 0164 anchors.centerIn: parent 0165 width: Kirigami.Units.gridUnit * 1.5 0166 height: width 0167 } 0168 0169 property bool messageSent: false 0170 0171 onClicked: { 0172 0173 // prevent sending the same message several times 0174 // and don't touch enabled property 0175 if (isSendingInProcess){ 0176 return; 0177 } 0178 isSendingInProcess = true 0179 0180 if (SmsHelper.totalMessageSize(selectedFileUrls, messageField.text) > maxMessageSize) { 0181 messageDialog.visible = true 0182 } else if (page.conversationId === page.invalidId) { 0183 messageSent = conversationModel.startNewConversation(messageField.text, addresses, selectedFileUrls) 0184 } else { 0185 messageSent = conversationModel.sendReplyToConversation(messageField.text, selectedFileUrls) 0186 } 0187 0188 if (messageSent) { 0189 messageField.text = "" 0190 selectedFileUrls = [] 0191 } 0192 isSendingInProcess = false 0193 } 0194 } 0195 } 0196 0197 Controls.Label { 0198 id: charCount 0199 text: conversationModel.getCharCountInfo(messageField.text) 0200 visible: text.length > 0 0201 Layout.minimumWidth: Math.max(Layout.minimumWidth, width) // Make this label only grow, never shrink 0202 } 0203 } 0204 } 0205 } 0206 }