2018-10-30 20:01:13 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
|
|
|
|
* SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
|
2018-10-30 20:01:13 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2018-10-30 20:01:13 +00:00
|
|
|
*/
|
|
|
|
|
2023-12-23 16:48:04 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Layouts
|
2023-10-12 19:26:53 +01:00
|
|
|
import org.kde.kirigami as Kirigami
|
|
|
|
import org.kde.kirigami.delegates as KirigamiDelegates
|
2023-12-23 16:48:04 +00:00
|
|
|
import org.kde.kdeconnect.sms
|
2018-10-30 20:01:13 +00:00
|
|
|
|
|
|
|
Kirigami.ScrollablePage
|
|
|
|
{
|
2019-01-23 01:27:10 +00:00
|
|
|
id: page
|
2024-03-17 12:41:42 +00:00
|
|
|
|
2019-03-18 21:58:34 +00:00
|
|
|
ToolTip {
|
2024-03-17 12:41:42 +00:00
|
|
|
visible: !deviceConnected
|
2019-03-18 21:58:34 +00:00
|
|
|
timeout: -1
|
2019-12-21 07:59:36 +00:00
|
|
|
text: "⚠️ " + i18nd("kdeconnect-sms", "No devices available") + " ⚠️"
|
2019-03-18 21:58:34 +00:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
// Detect mouseover and show another tooltip with more information
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
|
|
ToolTip.visible: containsMouse
|
|
|
|
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
|
2019-12-21 07:59:36 +00:00
|
|
|
ToolTip.text: i18nd("kdeconnect-sms", "No new messages can be sent or received, but you can browse cached content")
|
2019-03-18 21:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 18:18:17 +01:00
|
|
|
ColumnLayout {
|
|
|
|
id: loadingMessage
|
2024-03-17 12:41:42 +00:00
|
|
|
visible: deviceConnected && view.count === 0 && currentSearchText.length == 0
|
2019-08-24 18:18:17 +01:00
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
BusyIndicator {
|
2022-02-09 03:47:36 +00:00
|
|
|
visible: loadingMessage.visible
|
2019-08-24 18:18:17 +01:00
|
|
|
running: loadingMessage.visible
|
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
|
|
|
}
|
2020-02-03 01:37:25 +00:00
|
|
|
|
|
|
|
Label {
|
2022-02-09 03:47:36 +00:00
|
|
|
text: i18nd("kdeconnect-sms", "Loading conversations from device. If this takes a long time, please wake up your device and then click Refresh.")
|
2020-02-03 01:37:25 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
|
|
|
Layout.preferredWidth: page.width / 2
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
2022-02-09 03:47:36 +00:00
|
|
|
text: i18nd("kdeconnect-sms", "Tip: If you plug in your device, it should not go into doze mode and should load quickly.")
|
2020-02-03 01:37:25 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
|
|
|
Layout.preferredWidth: page.width / 2
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
}
|
2022-02-09 03:47:36 +00:00
|
|
|
|
|
|
|
Button {
|
|
|
|
text: i18nd("kdeconnect-sms", "Refresh")
|
|
|
|
icon.name: "view-refresh"
|
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
|
|
|
onClicked: {
|
|
|
|
conversationListModel.refresh();
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 18:18:17 +01:00
|
|
|
}
|
|
|
|
|
2022-05-12 19:34:24 +01:00
|
|
|
property string initialMessage : AppData.initialMessage
|
2024-03-17 12:41:42 +00:00
|
|
|
property string currentSearchText
|
|
|
|
property alias conversationListModel: conversationListModel
|
|
|
|
property int devicesCount
|
|
|
|
readonly property bool deviceConnected: devicesCount > 0
|
[SMS App] Allow passing a message via args
Summary:
Add --message option to kdeconnect-sms to pass a message. The user only needs to choose a recepient and the message will be sent. Useful for integration with 3rd party
apps, e.g. via Purpose
Test Plan:
kdeconnect-sms --message "Hello World", choose chat, message is sent
Click another chat, no message sent
kdeconnect-sms without args, no message sent
Reviewers: #kde_connect, sredman
Reviewed By: #kde_connect, sredman
Subscribers: andyholmes, sredman, apol, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D17292
2019-03-09 21:32:36 +00:00
|
|
|
|
|
|
|
header: Kirigami.InlineMessage {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
visible: page.initialMessage.length > 0
|
2019-12-21 07:59:36 +00:00
|
|
|
text: i18nd("kdeconnect-sms", "Choose recipient")
|
[SMS App] Allow passing a message via args
Summary:
Add --message option to kdeconnect-sms to pass a message. The user only needs to choose a recepient and the message will be sent. Useful for integration with 3rd party
apps, e.g. via Purpose
Test Plan:
kdeconnect-sms --message "Hello World", choose chat, message is sent
Click another chat, no message sent
kdeconnect-sms without args, no message sent
Reviewers: #kde_connect, sredman
Reviewed By: #kde_connect, sredman
Subscribers: andyholmes, sredman, apol, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D17292
2019-03-09 21:32:36 +00:00
|
|
|
|
|
|
|
actions: [
|
|
|
|
Kirigami.Action {
|
2023-09-21 18:23:06 +01:00
|
|
|
icon.name: "dialog-cancel"
|
2019-12-21 07:59:36 +00:00
|
|
|
text: i18nd("kdeconnect-sms", "Cancel")
|
[SMS App] Allow passing a message via args
Summary:
Add --message option to kdeconnect-sms to pass a message. The user only needs to choose a recepient and the message will be sent. Useful for integration with 3rd party
apps, e.g. via Purpose
Test Plan:
kdeconnect-sms --message "Hello World", choose chat, message is sent
Click another chat, no message sent
kdeconnect-sms without args, no message sent
Reviewers: #kde_connect, sredman
Reviewed By: #kde_connect, sredman
Subscribers: andyholmes, sredman, apol, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D17292
2019-03-09 21:32:36 +00:00
|
|
|
onTriggered: initialMessage = ""
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
titleDelegate: RowLayout {
|
|
|
|
Keys.forwardTo: [filter]
|
2024-03-17 12:41:42 +00:00
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
Kirigami.SearchField {
|
|
|
|
/**
|
|
|
|
* Used as the filter of the list of messages
|
|
|
|
*/
|
|
|
|
id: filter
|
|
|
|
Layout.fillWidth: true
|
2024-03-16 12:38:32 +00:00
|
|
|
placeholderText: i18nd("kdeconnect-sms", "Search or start a conversation")
|
2022-02-09 03:47:36 +00:00
|
|
|
onTextChanged: {
|
|
|
|
currentSearchText = filter.text;
|
2024-03-17 12:41:42 +00:00
|
|
|
if (filter.text !== "") {
|
2022-02-09 03:47:36 +00:00
|
|
|
view.model.setConversationsFilterRole(ConversationListModel.AddressesRole)
|
|
|
|
} else {
|
|
|
|
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
|
|
|
|
}
|
|
|
|
view.model.setFilterFixedString(SmsHelper.canonicalizePhoneNumber(filter.text))
|
2018-10-30 20:01:13 +00:00
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
view.currentIndex = 0
|
|
|
|
filter.forceActiveFocus();
|
|
|
|
}
|
2024-03-11 23:49:45 +00:00
|
|
|
Keys.onReturnPressed: event => {
|
2022-02-09 03:47:36 +00:00
|
|
|
event.accepted = true
|
|
|
|
view.currentItem.startChat()
|
|
|
|
}
|
2024-03-11 23:49:45 +00:00
|
|
|
Keys.onEscapePressed: event => {
|
2024-03-17 12:41:42 +00:00
|
|
|
event.accepted = filter.text !== ""
|
2022-02-09 03:47:36 +00:00
|
|
|
filter.text = ""
|
|
|
|
}
|
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+F"
|
|
|
|
onActivated: filter.forceActiveFocus()
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
Button {
|
|
|
|
id: newButton
|
|
|
|
icon.name: "list-add"
|
|
|
|
enabled: SmsHelper.isAddressValid(filter.text) && deviceConnected
|
2024-03-17 12:41:42 +00:00
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
ToolTip.visible: hovered
|
|
|
|
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
|
|
|
|
ToolTip.text: i18nd("kdeconnect-sms", "Start new conversation")
|
2020-03-21 22:57:28 +00:00
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
onClicked: {
|
|
|
|
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
|
|
|
|
filter.enabled = false
|
|
|
|
|
|
|
|
// If the address entered by the user already exists then ignore adding new contact
|
|
|
|
if (!view.model.doesAddressExists(filter.text) && SmsHelper.isAddressValid(filter.text)) {
|
|
|
|
conversationListModel.createConversationForAddress(filter.text)
|
2020-04-13 03:20:04 +01:00
|
|
|
view.currentIndex = 0
|
|
|
|
}
|
2022-02-09 03:47:36 +00:00
|
|
|
filter.enabled = true
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
Shortcut {
|
|
|
|
sequence: "Ctrl+N"
|
2024-01-10 17:29:10 +00:00
|
|
|
onActivated: newButton.clicked()
|
2020-04-08 18:15:20 +01:00
|
|
|
}
|
2020-03-22 09:33:04 +00:00
|
|
|
}
|
2022-02-09 03:47:36 +00:00
|
|
|
}
|
2020-03-22 09:33:04 +00:00
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
Component {
|
|
|
|
id: chatView
|
|
|
|
ConversationDisplay {
|
|
|
|
deviceConnected: page.deviceConnected
|
|
|
|
}
|
|
|
|
}
|
2022-02-09 03:47:36 +00:00
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: view
|
|
|
|
model: QSortFilterProxyModel {
|
|
|
|
sortOrder: Qt.DescendingOrder
|
|
|
|
filterCaseSensitivity: Qt.CaseInsensitive
|
|
|
|
sourceModel: ConversationListModel {
|
|
|
|
id: conversationListModel
|
2022-05-30 21:29:17 +01:00
|
|
|
deviceId: AppData.deviceId
|
2022-02-09 03:47:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-13 03:20:04 +01:00
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
currentIndex = -1
|
|
|
|
focus = true
|
|
|
|
}
|
|
|
|
|
|
|
|
Kirigami.PlaceholderMessage {
|
|
|
|
// FIXME: not accessible. screen readers won't read this.
|
|
|
|
// https://invent.kde.org/frameworks/kirigami/-/merge_requests/1482
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: parent.width - (Kirigami.Units.largeSpacing * 4)
|
|
|
|
visible: deviceConnected && view.count === 0 && currentSearchText.length != 0
|
|
|
|
text: i18ndc("kdeconnect-sms", "Placeholder message text when no messages are found", "No matches")
|
|
|
|
}
|
|
|
|
|
2020-04-13 03:20:04 +01:00
|
|
|
Keys.forwardTo: [headerItem]
|
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
delegate: ItemDelegate {
|
2019-07-21 11:35:04 +01:00
|
|
|
id: listItem
|
2023-12-23 20:33:08 +00:00
|
|
|
text: displayNames
|
2024-03-17 12:41:42 +00:00
|
|
|
icon.name: decoration
|
2023-10-12 19:26:53 +01:00
|
|
|
width: view.width
|
2019-07-21 11:35:04 +01:00
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
required property string displayNames
|
|
|
|
required property string toolTip
|
|
|
|
required property string decoration
|
|
|
|
required property var attachmentPreview
|
|
|
|
required property int index
|
|
|
|
required property var addresses
|
|
|
|
required property bool isMultitarget
|
|
|
|
required property int conversationId
|
|
|
|
|
|
|
|
// Keep the currently-open chat highlighted even if this element is not focused
|
|
|
|
highlighted: ListView.isCurrentItem
|
2018-10-30 20:01:13 +00:00
|
|
|
|
|
|
|
function startChat() {
|
2022-02-09 03:47:36 +00:00
|
|
|
view.currentItem.forceActiveFocus();
|
2018-10-30 20:01:13 +00:00
|
|
|
applicationWindow().pageStack.push(chatView, {
|
2024-03-17 12:41:42 +00:00
|
|
|
addresses: listItem.addresses,
|
|
|
|
conversationId: listItem.conversationId,
|
|
|
|
isMultitarget: listItem.isMultitarget,
|
2022-05-30 21:29:17 +01:00
|
|
|
initialMessage: page.initialMessage})
|
[SMS App] Allow passing a message via args
Summary:
Add --message option to kdeconnect-sms to pass a message. The user only needs to choose a recepient and the message will be sent. Useful for integration with 3rd party
apps, e.g. via Purpose
Test Plan:
kdeconnect-sms --message "Hello World", choose chat, message is sent
Click another chat, no message sent
kdeconnect-sms without args, no message sent
Reviewers: #kde_connect, sredman
Reviewed By: #kde_connect, sredman
Subscribers: andyholmes, sredman, apol, kdeconnect
Tags: #kde_connect
Differential Revision: https://phabricator.kde.org/D17292
2019-03-09 21:32:36 +00:00
|
|
|
initialMessage = ""
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
2020-03-21 22:57:28 +00:00
|
|
|
|
2019-02-27 05:45:54 +00:00
|
|
|
onClicked: {
|
|
|
|
view.currentIndex = index
|
2023-10-12 19:26:53 +01:00
|
|
|
startChat();
|
2019-02-27 05:45:54 +00:00
|
|
|
}
|
2020-09-27 04:51:17 +01:00
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
// Note: Width calcs to account for scrollbar coming and going
|
|
|
|
contentItem: RowLayout {
|
|
|
|
spacing: Kirigami.Units.smallSpacing
|
|
|
|
implicitWidth: view.width - Kirigami.Units.largeSpacing
|
|
|
|
|
|
|
|
Kirigami.Icon {
|
|
|
|
id: thumbnailItem
|
|
|
|
source: {
|
|
|
|
if (!listItem.attachmentPreview) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listItem.attachmentPreview.hasOwnProperty("name") && listItem.attachmentPreview.name !== "")
|
|
|
|
return listItem.attachmentPreview.name;
|
|
|
|
if (listItem.attachmentPreview.hasOwnProperty("source"))
|
|
|
|
return listItem.attachmentPreview.source;
|
|
|
|
return listItem.attachmentPreview;
|
2020-09-27 04:51:17 +01:00
|
|
|
}
|
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
width: Kirigami.Units.iconSizes.small
|
|
|
|
height: Kirigami.Units.iconSizes.small
|
2019-02-27 05:45:54 +00:00
|
|
|
|
2024-03-17 12:41:42 +00:00
|
|
|
visible: source !== undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set width here to force elide and account for scrollbar
|
|
|
|
KirigamiDelegates.TitleSubtitle {
|
|
|
|
title: listItem.text
|
|
|
|
subtitle: listItem.toolTip
|
|
|
|
elide: Text.ElideRight
|
|
|
|
implicitWidth: view.width - Kirigami.Units.largeSpacing*2
|
|
|
|
}
|
|
|
|
}
|
2021-06-08 15:30:14 +01:00
|
|
|
|
|
|
|
}
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
|
|
|
}
|