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
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.5
|
|
|
|
import QtQuick.Controls 2.1
|
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
import org.kde.people 1.0
|
2020-05-06 19:19:02 +01:00
|
|
|
import org.kde.kirigami 2.12 as Kirigami
|
2018-10-30 20:01:13 +00:00
|
|
|
import org.kde.kdeconnect 1.0
|
|
|
|
import org.kde.kdeconnect.sms 1.0
|
|
|
|
|
|
|
|
Kirigami.ScrollablePage
|
|
|
|
{
|
2019-01-23 01:27:10 +00:00
|
|
|
id: page
|
2019-03-18 21:58:34 +00:00
|
|
|
ToolTip {
|
|
|
|
id: noDevicesWarning
|
2019-08-24 18:18:17 +01:00
|
|
|
visible: !page.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
|
|
|
|
// TODO: Wrap text if line is too long for the screen
|
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
|
2022-02-09 03:47:36 +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
|
[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 {
|
|
|
|
iconName: "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
|
|
|
property int devicesCount
|
2018-10-30 20:01:13 +00:00
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
readonly property bool deviceConnected: devicesCount > 0
|
|
|
|
property string currentSearchText
|
2018-10-30 20:01:13 +00:00
|
|
|
|
2019-03-08 21:18:51 +00:00
|
|
|
Component {
|
2018-10-30 20:01:13 +00:00
|
|
|
id: chatView
|
2019-01-23 01:27:10 +00:00
|
|
|
ConversationDisplay {
|
|
|
|
deviceConnected: page.deviceConnected
|
|
|
|
}
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
titleDelegate: RowLayout {
|
|
|
|
id: headerLayout
|
|
|
|
width: parent.width
|
|
|
|
Keys.forwardTo: [filter]
|
|
|
|
Kirigami.SearchField {
|
|
|
|
/**
|
|
|
|
* Used as the filter of the list of messages
|
|
|
|
*/
|
|
|
|
id: filter
|
|
|
|
placeholderText: i18nd("kdeconnect-sms", "Search or start conversation...")
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
onTextChanged: {
|
|
|
|
currentSearchText = filter.text;
|
|
|
|
if (filter.text != "") {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
Keys.onReturnPressed: {
|
|
|
|
event.accepted = true
|
|
|
|
view.currentItem.startChat()
|
|
|
|
}
|
|
|
|
Keys.onEscapePressed: {
|
|
|
|
event.accepted = filter.text != ""
|
|
|
|
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"
|
|
|
|
text: i18nd("kdeconnect-sms", "New")
|
|
|
|
visible: true
|
|
|
|
enabled: SmsHelper.isAddressValid(filter.text) && deviceConnected
|
|
|
|
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"
|
|
|
|
onActivated: newButton.onClicked()
|
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
|
|
|
|
2022-02-09 03:47:36 +00:00
|
|
|
property alias conversationListModel: conversationListModel
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: view
|
|
|
|
currentIndex: 0
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Keys.forwardTo: [headerItem]
|
|
|
|
|
2020-05-06 19:19:02 +01:00
|
|
|
delegate: Kirigami.BasicListItem
|
2018-10-30 20:01:13 +00:00
|
|
|
{
|
2019-07-21 11:35:04 +01:00
|
|
|
id: listItem
|
2020-05-06 19:19:02 +01:00
|
|
|
icon: decoration
|
|
|
|
reserveSpaceForIcon: true
|
|
|
|
label: display
|
|
|
|
subtitle: toolTip
|
2019-07-21 11:35:04 +01:00
|
|
|
|
2020-09-27 04:51:17 +01:00
|
|
|
property var thumbnail: attachmentPreview
|
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, {
|
2019-07-19 18:33:15 +01:00
|
|
|
addresses: addresses,
|
2018-10-30 20:01:13 +00:00
|
|
|
conversationId: model.conversationId,
|
2019-07-19 16:29:28 +01:00
|
|
|
isMultitarget: 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: {
|
|
|
|
startChat();
|
|
|
|
view.currentIndex = index
|
|
|
|
}
|
2020-09-27 04:51:17 +01:00
|
|
|
|
|
|
|
Kirigami.Icon {
|
|
|
|
id: thumbnailItem
|
|
|
|
source: {
|
|
|
|
if (!listItem.thumbnail) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
if (listItem.thumbnail.hasOwnProperty) {
|
|
|
|
if (listItem.thumbnail.hasOwnProperty("name") && listItem.thumbnail.name !== "")
|
|
|
|
return listItem.thumbnail.name;
|
|
|
|
if (listItem.thumbnail.hasOwnProperty("source"))
|
|
|
|
return listItem.thumbnail.source;
|
|
|
|
}
|
|
|
|
return listItem.thumbnail;
|
|
|
|
}
|
|
|
|
property int size: Kirigami.Units.iconSizes.huge
|
|
|
|
Layout.minimumHeight: size
|
|
|
|
Layout.maximumHeight: size
|
|
|
|
Layout.minimumWidth: size
|
|
|
|
selected: (listItem.highlighted || listItem.checked || (listItem.pressed && listItem.supportsMouseEvents))
|
|
|
|
opacity: 1
|
|
|
|
visible: source != undefined
|
|
|
|
}
|
|
|
|
|
2019-02-27 05:45:54 +00:00
|
|
|
// Keep the currently-open chat highlighted even if this element is not focused
|
2020-05-06 19:19:02 +01:00
|
|
|
highlighted: view.currentIndex == index
|
2019-02-27 05:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
currentIndex = -1
|
|
|
|
focus = true
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
2021-06-08 15:30:14 +01:00
|
|
|
|
|
|
|
Kirigami.PlaceholderMessage {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: parent.width - (Kirigami.Units.largeSpacing * 4)
|
2022-02-09 03:47:36 +00:00
|
|
|
visible: deviceConnected && view.count == 0 && currentSearchText.length != 0
|
2021-06-08 15:30:14 +01:00
|
|
|
text: i18ndc("kdeconnect-sms", "Placeholder message text when no messages are found", "No matches")
|
|
|
|
}
|
2018-10-30 20:01:13 +00:00
|
|
|
}
|
|
|
|
}
|