From b7f8ceefcf7ef7c0c2a4bca56b232c2d0f225ef8 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sat, 20 Jul 2019 16:02:38 +0200 Subject: [PATCH] sms: Added opening kdeconnect-sms on the plasmoid and indicator Add a menu entry on the kdeconnect-indicator within devices' submenu that opens kdeconnect-sms. Also add it in the plasmoid in the device delegate. --- indicator/deviceindicator.cpp | 10 +++++++++- indicator/main.cpp | 2 +- interfaces/devicesmodel.h | 2 +- plasmoid/package/contents/ui/DeviceDelegate.qml | 17 +++++++++++++++++ plugins/sms/smsplugin.cpp | 7 ++++++- plugins/sms/smsplugin.h | 2 ++ smsapp/main.cpp | 15 +++++++++------ smsapp/qml/ConversationList.qml | 6 +++++- 8 files changed, 50 insertions(+), 11 deletions(-) diff --git a/indicator/deviceindicator.cpp b/indicator/deviceindicator.cpp index e80368fc9..8369f95d7 100644 --- a/indicator/deviceindicator.cpp +++ b/indicator/deviceindicator.cpp @@ -113,10 +113,18 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface* device) setWhenAvailable(device->hasPlugin(QStringLiteral("kdeconnect_share")), [sendFile](bool available) { sendFile->setVisible(available); }, this); + + if (!QStandardPaths::findExecutable(QStringLiteral("kdeconnect-sms")).isEmpty()) { + auto smsapp = addAction(QIcon::fromTheme(QStringLiteral("message-new")), i18n("SMS Messages...")); + QObject::connect(smsapp, &QAction::triggered, device, [device] () { + QProcess::startDetached(QLatin1String("kdeconnect-sms"), { QStringLiteral("--device"), device->id() }); + }); + setWhenAvailable(device->hasPlugin(QStringLiteral("kdeconnect_sms")), [smsapp](bool available) { smsapp->setVisible(available); }, this); + } + QMenu* remoteCommandsMenu = new QMenu(i18n("Run command"), this); QAction* menuAction = remoteCommandsMenu->menuAction(); QAction* addCommandAction = remoteCommandsMenu->addAction(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add commands")); - connect(addCommandAction, &QAction::triggered, m_remoteCommandsInterface, &RemoteCommandsDbusInterface::editCommands); addAction(menuAction); diff --git a/indicator/main.cpp b/indicator/main.cpp index d7d684949..5cef0a78d 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char** argv) // Get bundle path CFURLRef url = (CFURLRef)CFAutorelease((CFURLRef)CFBundleCopyBundleURL(CFBundleGetMainBundle())); QString basePath = QUrl::fromCFURL(url).path(); - + // Start kdeconnectd QProcess kdeconnectdProcess; kdeconnectdProcess.startDetached(basePath + QStringLiteral("Contents/MacOS/kdeconnectd")); diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index dcd0c946f..763eecda6 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -71,7 +71,7 @@ public: Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const; QHash roleNames() const override; - int rowForDevice(const QString& id) const; + Q_SCRIPTABLE int rowForDevice(const QString& id) const; private Q_SLOTS: void deviceAdded(const QString& id); diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index 0eac563e1..233c45978 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -142,6 +142,23 @@ PlasmaComponents.ListItem } } + //SMS + PlasmaComponents.Button + { + SMS { + id: sms + device: root.device + } + + iconSource: "message-new'" + visible: sms.available + tooltip: i18n("SMS Messages") + + onClicked: { + sms.plugin.launchApp() + } + } + height: browse.height width: parent.width } diff --git a/plugins/sms/smsplugin.cpp b/plugins/sms/smsplugin.cpp index 2f9c3cd4b..52da9c440 100644 --- a/plugins/sms/smsplugin.cpp +++ b/plugins/sms/smsplugin.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -116,11 +117,15 @@ bool SmsPlugin::handleBatchMessages(const NetworkPacket& np) return true; } - QString SmsPlugin::dbusPath() const { return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/sms"); } +void SmsPlugin::launchApp() +{ + QProcess::startDetached(QLatin1String("kdeconnect-sms"), { QStringLiteral("--device"), device()->id() }); +} + #include "smsplugin.moc" diff --git a/plugins/sms/smsplugin.h b/plugins/sms/smsplugin.h index 5cfbe33e8..ac5719e78 100644 --- a/plugins/sms/smsplugin.h +++ b/plugins/sms/smsplugin.h @@ -140,6 +140,8 @@ public Q_SLOTS: */ Q_SCRIPTABLE void requestConversation(const qint64& conversationID) const; + Q_SCRIPTABLE void launchApp(); + private: /** diff --git a/smsapp/main.cpp b/smsapp/main.cpp index e4a20af24..70e0a9862 100644 --- a/smsapp/main.cpp +++ b/smsapp/main.cpp @@ -41,20 +41,20 @@ int main(int argc, char *argv[]) aboutData.addAuthor(i18n("Nicolas Fella"), {}, QStringLiteral("nicolas.fella@gmx.de")); KAboutData::setApplicationData(aboutData); - QString initialMessage; + QString initialMessage, deviceid; { QCommandLineParser parser; aboutData.setupCommandLine(&parser); parser.addVersionOption(); parser.addHelpOption(); + parser.addOption(QCommandLineOption(QStringLiteral("device"), i18n("Select a device"), i18n("id"))); 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")); - } + initialMessage = parser.value(QStringLiteral("message")); + deviceid = parser.value(QStringLiteral("device")); } KDBusService service(KDBusService::Unique); @@ -66,8 +66,11 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); - engine.rootContext()->setContextProperty(QStringLiteral("_initialMessage"), QVariant(initialMessage)); - engine.rootContext()->setContextProperty(QStringLiteral("aboutData"), QVariant::fromValue(KAboutData::applicationData())); + engine.rootContext()->setContextProperties({ + { QStringLiteral("initialMessage"), initialMessage }, + { QStringLiteral("initialDevice"), deviceid }, + { QStringLiteral("aboutData"), QVariant::fromValue(KAboutData::applicationData()) } + }); engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); return app.exec(); diff --git a/smsapp/qml/ConversationList.qml b/smsapp/qml/ConversationList.qml index 9f0671205..4b2dfcfd4 100644 --- a/smsapp/qml/ConversationList.qml +++ b/smsapp/qml/ConversationList.qml @@ -73,6 +73,7 @@ Kirigami.ScrollablePage } property string initialMessage + property string initialDevice header: Kirigami.InlineMessage { Layout.fillWidth: true @@ -97,7 +98,10 @@ Kirigami.ScrollablePage //TODO: make it possible to filter if they can do sms sourceModel: DevicesModel { displayFilter: DevicesModel.Paired | DevicesModel.Reachable } onRowsInserted: if (devicesCombo.currentIndex < 0) { - devicesCombo.currentIndex = 0 + if (page.initialDevice) + devicesCombo.currentIndex = devicesModel.rowForDevice(page.initialDevice); + else + devicesCombo.currentIndex = 0 } } textRole: "display"