From c863feef58709b38c4f453a46ca7ee1db8760006 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sun, 25 Mar 2018 20:40:59 +0200 Subject: [PATCH] Optionally include sms app Creates a tiny messaging app that uses KPeople to query the contacts and KDE connect telephony plugins to send plugins. To be ready, still needs some work on the contacts sync side and some messages history would be nice. --- CMakeLists.txt | 6 ++ interfaces/CMakeLists.txt | 1 + interfaces/dbusinterfaces.cpp | 7 ++ interfaces/dbusinterfaces.h | 10 ++ .../kdeconnectdeclarativeplugin.cpp | 8 ++ plugins/telephony/telephonyplugin.cpp | 1 + smsapp/CMakeLists.txt | 7 ++ smsapp/main.cpp | 54 +++++++++++ smsapp/org.kde.kdeconnect.sms.desktop | 12 +++ smsapp/qml/ContactList.qml | 96 +++++++++++++++++++ smsapp/qml/ConversationDisplay.qml | 65 +++++++++++++ smsapp/qml/main.qml | 37 +++++++ smsapp/resources.qrc | 7 ++ 13 files changed, 311 insertions(+) create mode 100644 smsapp/CMakeLists.txt create mode 100644 smsapp/main.cpp create mode 100644 smsapp/org.kde.kdeconnect.sms.desktop create mode 100644 smsapp/qml/ContactList.qml create mode 100644 smsapp/qml/ConversationDisplay.qml create mode 100644 smsapp/qml/main.qml create mode 100644 smsapp/resources.qrc diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d5d0229b..a8fd43e39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,12 @@ add_subdirectory(indicator) add_subdirectory(fileitemactionplugin) add_subdirectory(urlhandler) add_subdirectory(nautilus-extension) + +option(SMSAPP_ENABLED OFF) +if(SMSAPP_ENABLED) + find_package(KF5People REQUIRED) + add_subdirectory(smsapp) +endif() if(KF5DocTools_FOUND) add_subdirectory(doc) endif() diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index 806ff36e7..db8a12e0c 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -44,6 +44,7 @@ geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecontrol/remotecontrolplugin.h rem geninterface(${CMAKE_SOURCE_DIR}/plugins/lockdevice/lockdeviceplugin.h lockdeviceinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecommands/remotecommandsplugin.h remotecommandsinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/remotekeyboard/remotekeyboardplugin.h remotekeyboardinterface) +geninterface(${CMAKE_SOURCE_DIR}/plugins/telephony/telephonyplugin.h telephonyinterface) add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC}) diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp index fbe93caca..53b175376 100644 --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -164,3 +164,10 @@ RemoteKeyboardDbusInterface::RemoteKeyboardDbusInterface(const QString& deviceId } RemoteKeyboardDbusInterface::~RemoteKeyboardDbusInterface() = default; + +TelephonyDbusInterface::TelephonyDbusInterface(const QString& deviceId, QObject* parent): + OrgKdeKdeconnectDeviceTelephonyInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/telephony", QDBusConnection::sessionBus(), parent) +{ +} + +TelephonyDbusInterface::~TelephonyDbusInterface() = default; diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h index 4b2029d06..fbf2395f1 100644 --- a/interfaces/dbusinterfaces.h +++ b/interfaces/dbusinterfaces.h @@ -35,6 +35,7 @@ #include "interfaces/lockdeviceinterface.h" #include "interfaces/remotecommandsinterface.h" #include "interfaces/remotekeyboardinterface.h" +#include "interfaces/telephonyinterface.h" /** * Using these "proxy" classes just in case we need to rename the @@ -196,6 +197,15 @@ Q_SIGNALS: void remoteStateChanged(bool state); }; +class KDECONNECTINTERFACES_EXPORT TelephonyDbusInterface + : public OrgKdeKdeconnectDeviceTelephonyInterface +{ + Q_OBJECT +public: + explicit TelephonyDbusInterface(const QString& deviceId, QObject* parent = nullptr); + ~TelephonyDbusInterface() override; +}; + template static void setWhenAvailable(const QDBusPendingReply& pending, W func, QObject* parent) { diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index f53b050b6..dd9f2fc3b 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -74,6 +74,11 @@ QObject* createDeviceLockInterface(const QVariant& deviceId) return new LockDeviceDbusInterface(deviceId.toString()); } +QObject* createTelephonyInterface(const QVariant& deviceId) +{ + return new TelephonyDbusInterface(deviceId.toString()); +} + QObject* createDBusResponse() { return new DBusAsyncResponse(); @@ -124,6 +129,9 @@ void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const cha engine->rootContext()->setContextProperty(QStringLiteral("LockDeviceDbusInterfaceFactory") , new ObjectFactory(engine, createDeviceLockInterface)); + + engine->rootContext()->setContextProperty(QStringLiteral("TelephonyDbusInterfaceFactory") + , new ObjectFactory(engine, createTelephonyInterface)); engine->rootContext()->setContextProperty(QStringLiteral("DBusResponseFactory") , new ObjectFactory(engine, createDBusResponse)); diff --git a/plugins/telephony/telephonyplugin.cpp b/plugins/telephony/telephonyplugin.cpp index 91ea2a8ce..5c50efa2f 100644 --- a/plugins/telephony/telephonyplugin.cpp +++ b/plugins/telephony/telephonyplugin.cpp @@ -148,6 +148,7 @@ void TelephonyPlugin::sendSms(const QString& phoneNumber, const QString& message {"phoneNumber", phoneNumber}, {"messageBody", messageBody} }); + qDebug() << "sending sms!"; sendPacket(np); } diff --git a/smsapp/CMakeLists.txt b/smsapp/CMakeLists.txt new file mode 100644 index 000000000..8aadde5db --- /dev/null +++ b/smsapp/CMakeLists.txt @@ -0,0 +1,7 @@ +qt5_add_resources(KCSMS_SRCS resources.qrc) + +add_executable(kdeconnect-sms main.cpp ${KCSMS_SRCS}) +target_link_libraries(kdeconnect-sms Qt5::Quick Qt5::Widgets KF5::DBusAddons KF5::CoreAddons KF5::I18n) + +install(TARGETS kdeconnect-sms ${INSTALL_TARGETS_DEFAULT_ARGS}) +install(PROGRAMS org.kde.kdeconnect.sms.desktop DESTINATION ${KDE_INSTALL_APPDIR}) diff --git a/smsapp/main.cpp b/smsapp/main.cpp new file mode 100644 index 000000000..58c6dc64b --- /dev/null +++ b/smsapp/main.cpp @@ -0,0 +1,54 @@ +/* + * This file is part of KDE Telepathy Chat + * + * Copyright (C) 2015 Aleix Pol Gonzalez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "kdeconnect-version.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + KAboutData aboutData("org.kde.kdeconnect.sms", i18n("SMS Instant Messaging"), QStringLiteral(KDECONNECT_VERSION_STRING), i18n("KDE Connect SMS"), KAboutLicense::GPL, i18n("(c) 2018, Aleix Pol Gonzalez")); + aboutData.addAuthor(i18n("Aleix Pol Gonzalez"), {}, "aleixpol@kde.org"); + KAboutData::setApplicationData(aboutData); + + { + QCommandLineParser parser; + aboutData.setupCommandLine(&parser); + parser.addVersionOption(); + parser.addHelpOption(); + parser.process(app); + aboutData.processCommandLine(&parser); + } + + KDBusService service(KDBusService::Unique); + + QQmlApplicationEngine engine; + engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); + engine.load(QUrl("qrc:/qml/main.qml")); + + return app.exec(); +} diff --git a/smsapp/org.kde.kdeconnect.sms.desktop b/smsapp/org.kde.kdeconnect.sms.desktop new file mode 100644 index 000000000..addeaf37d --- /dev/null +++ b/smsapp/org.kde.kdeconnect.sms.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Name=KDE Connect SMS +GenericName=SMS +Comment=Text Messaging +Exec=kdeconnect-sms +Icon=kdeconnect +Type=Application +Terminal=false +Categories=Qt;KDE;Network;InstantMessaging + +X-DBUS-StartupType=Unique +X-DBUS-ServiceName=org.kde.kdeconnect.sms diff --git a/smsapp/qml/ContactList.qml b/smsapp/qml/ContactList.qml new file mode 100644 index 000000000..babf418a4 --- /dev/null +++ b/smsapp/qml/ContactList.qml @@ -0,0 +1,96 @@ +/* + * This file is part of KDE Telepathy Chat + * + * Copyright (C) 2015 Aleix Pol Gonzalez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import org.kde.people 1.0 +import org.kde.plasma.core 2.0 as Core +import org.kde.kirigami 2.3 as Kirigami +import org.kde.kdeconnect 1.0 + +Kirigami.ScrollablePage +{ + Component { + id: chatView + ConversationDisplay {} + } + + ListView { + id: view + spacing: 3 + currentIndex: 0 + + model: PersonsSortFilterProxyModel { + requiredProperties: ["phoneNumber"] + sortRole: Qt.DisplayRole + sortCaseSensitivity: Qt.CaseInsensitive + sourceModel: PersonsModel { + id: people + } + } + + header: TextField { + id: filter + placeholderText: i18n("Filter...") + Layout.fillWidth: true + onTextChanged: { + view.model.filterRegExp = new RegExp(filter.text) + view.currentIndex = 0 + } + Keys.onUpPressed: view.currentIndex = Math.max(view.currentIndex-1, 0) + Keys.onDownPressed: view.currentIndex = Math.min(view.currentIndex+1, view.count-1) + onAccepted: { + view.currentItem.startChat() + } + Shortcut { + sequence: "Ctrl+F" + onActivated: filter.forceActiveFocus() + } + } + + delegate: Kirigami.BasicListItem + { + id: mouse + hoverEnabled: true + + readonly property var person: PersonData { + personUri: model.personUri + } + + label: display + icon: decoration + function startChat() { + applicationWindow().pageStack.push(chatView, { person: person.person, device: Qt.binding(function() {return devicesCombo.device })}) + } + onClicked: { startChat(); } + } + + } + footer: ComboBox { + id: devicesCombo + readonly property QtObject device: model.data(model.index(currentIndex, 0), DevicesModel.DeviceRole) + model: DevicesSortProxyModel { + //TODO: make it possible to sort only if they can do sms + sourceModel: DevicesModel { displayFilter: DevicesModel.Paired | DevicesModel.Reachable } + } + textRole: "display" + } +} diff --git a/smsapp/qml/ConversationDisplay.qml b/smsapp/qml/ConversationDisplay.qml new file mode 100644 index 000000000..edd7bb09a --- /dev/null +++ b/smsapp/qml/ConversationDisplay.qml @@ -0,0 +1,65 @@ +/* + * This file is part of KDE Telepathy Chat + * + * Copyright (C) 2015 Aleix Pol Gonzalez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +import QtQuick 2.1 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import org.kde.kirigami 2.4 as Kirigami + +Kirigami.ScrollablePage +{ + id: page + title: i18n("%1: %2", person.name, person.phone) + property QtObject person + property QtObject device + + readonly property QtObject telephony: TelephonyDbusInterfaceFactory.create(device.id()) + + Kirigami.CardsListView { + model: ListModel { + ListElement { display: "aaa"; fromMe: true } + ListElement { display: "aaa" } + ListElement { display: "aaa"; fromMe: true } + ListElement { display: "aaa" } + ListElement { display: "aaa" } + ListElement { display: "aaa" } + } + delegate: Kirigami.AbstractCard { + readonly property real margin: 100 + x: fromMe ? Kirigami.Units.gridUnit : margin + width: parent.width - margin - Kirigami.Units.gridUnit + contentItem: Label { text: model.display } + } + } + footer: RowLayout { + TextField { + id: message + Layout.fillWidth: true + placeholderText: i18n("Say hi...") + } + Button { + text: "Send" + onClicked: { + console.log("sending sms", page.person.phone) + page.telephony.sendSms(page.person.phone, message.text) + } + } + } +} diff --git a/smsapp/qml/main.qml b/smsapp/qml/main.qml new file mode 100644 index 000000000..f7bdf4465 --- /dev/null +++ b/smsapp/qml/main.qml @@ -0,0 +1,37 @@ +/* + * This file is part of KDE Telepathy Chat + * + * Copyright (C) 2014 Aleix Pol Gonzalez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +import QtQuick 2.1 +import QtQuick.Controls 2.3 +import org.kde.kirigami 2.3 as Kirigami + +Kirigami.ApplicationWindow +{ + id: root + visible: true + width: 800 + height: 600 + + header: Kirigami.ToolBarApplicationHeader {} + + pageStack.initialPage: ContactList { + title: i18n("KDE Connect SMS") + } +} diff --git a/smsapp/resources.qrc b/smsapp/resources.qrc new file mode 100644 index 000000000..a53e8c51f --- /dev/null +++ b/smsapp/resources.qrc @@ -0,0 +1,7 @@ + + + qml/main.qml + qml/ContactList.qml + qml/ConversationDisplay.qml + +