[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
This commit is contained in:
parent
97705c3c76
commit
fd99d84ead
4 changed files with 39 additions and 4 deletions
|
@ -41,13 +41,20 @@ int main(int argc, char *argv[])
|
|||
aboutData.addAuthor(i18n("Simon Redman"), {}, "simon@ergotech.com");
|
||||
KAboutData::setApplicationData(aboutData);
|
||||
|
||||
QString initialMessage;
|
||||
|
||||
{
|
||||
QCommandLineParser parser;
|
||||
aboutData.setupCommandLine(&parser);
|
||||
parser.addVersionOption();
|
||||
parser.addHelpOption();
|
||||
parser.addOption(QCommandLineOption(QStringLiteral("message"), i18n("Send a message"), i18n("message")));
|
||||
parser.process(app);
|
||||
aboutData.processCommandLine(&parser);
|
||||
|
||||
if (parser.isSet(QStringLiteral("message"))) {
|
||||
initialMessage = parser.value(QStringLiteral("message"));
|
||||
}
|
||||
}
|
||||
|
||||
KDBusService service(KDBusService::Unique);
|
||||
|
@ -58,6 +65,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("_initialMessage"), QVariant(initialMessage));
|
||||
engine.load(QUrl("qrc:/qml/main.qml"));
|
||||
|
||||
return app.exec();
|
||||
|
|
|
@ -37,11 +37,20 @@ Kirigami.ScrollablePage
|
|||
|
||||
property bool deviceConnected
|
||||
property string deviceId
|
||||
property int conversationId
|
||||
// property QtObject device
|
||||
property string conversationId
|
||||
property string initialMessage
|
||||
|
||||
property string phoneNumber
|
||||
title: person.person && person.person.name ? person.person.name : phoneNumber
|
||||
|
||||
Component.onCompleted: {
|
||||
if (initialMessage.length > 0) {
|
||||
message.text = initialMessage;
|
||||
initialMessage = ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a chat message which is representative of all chat messages
|
||||
*
|
||||
|
|
|
@ -24,13 +24,29 @@ import QtQuick 2.5
|
|||
import QtQuick.Controls 2.1
|
||||
import QtQuick.Layouts 1.1
|
||||
import org.kde.people 1.0
|
||||
import org.kde.kirigami 2.2 as Kirigami
|
||||
import org.kde.kirigami 2.4 as Kirigami
|
||||
import org.kde.kdeconnect 1.0
|
||||
import org.kde.kdeconnect.sms 1.0
|
||||
|
||||
Kirigami.ScrollablePage
|
||||
{
|
||||
id: page
|
||||
property string initialMessage
|
||||
|
||||
header: Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
visible: page.initialMessage.length > 0
|
||||
text: i18n("Choose recipient")
|
||||
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
iconName: "dialog-cancel"
|
||||
text: "Cancel"
|
||||
onTriggered: initialMessage = ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
footer: ComboBox {
|
||||
id: devicesCombo
|
||||
enabled: count > 0
|
||||
|
@ -120,7 +136,9 @@ Kirigami.ScrollablePage
|
|||
personUri: model.personUri,
|
||||
phoneNumber: address,
|
||||
conversationId: model.conversationId,
|
||||
})
|
||||
initialMessage: page.initialMessage,
|
||||
device: device})
|
||||
initialMessage = ""
|
||||
}
|
||||
onClicked: {
|
||||
startChat();
|
||||
|
@ -134,6 +152,5 @@ Kirigami.ScrollablePage
|
|||
currentIndex = -1
|
||||
focus = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,5 +33,6 @@ Kirigami.ApplicationWindow
|
|||
|
||||
pageStack.initialPage: ConversationList {
|
||||
title: i18n("KDE Connect SMS")
|
||||
initialMessage: _initialMessage
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue