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.
This commit is contained in:
Aleix Pol 2018-03-25 20:40:59 +02:00
parent 33c2a100b1
commit c863feef58
13 changed files with 311 additions and 0 deletions

View file

@ -59,6 +59,12 @@ add_subdirectory(indicator)
add_subdirectory(fileitemactionplugin) add_subdirectory(fileitemactionplugin)
add_subdirectory(urlhandler) add_subdirectory(urlhandler)
add_subdirectory(nautilus-extension) add_subdirectory(nautilus-extension)
option(SMSAPP_ENABLED OFF)
if(SMSAPP_ENABLED)
find_package(KF5People REQUIRED)
add_subdirectory(smsapp)
endif()
if(KF5DocTools_FOUND) if(KF5DocTools_FOUND)
add_subdirectory(doc) add_subdirectory(doc)
endif() endif()

View file

@ -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/lockdevice/lockdeviceplugin.h lockdeviceinterface)
geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecommands/remotecommandsplugin.h remotecommandsinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecommands/remotecommandsplugin.h remotecommandsinterface)
geninterface(${CMAKE_SOURCE_DIR}/plugins/remotekeyboard/remotekeyboardplugin.h remotekeyboardinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/remotekeyboard/remotekeyboardplugin.h remotekeyboardinterface)
geninterface(${CMAKE_SOURCE_DIR}/plugins/telephony/telephonyplugin.h telephonyinterface)
add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC}) add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC})

View file

@ -164,3 +164,10 @@ RemoteKeyboardDbusInterface::RemoteKeyboardDbusInterface(const QString& deviceId
} }
RemoteKeyboardDbusInterface::~RemoteKeyboardDbusInterface() = default; RemoteKeyboardDbusInterface::~RemoteKeyboardDbusInterface() = default;
TelephonyDbusInterface::TelephonyDbusInterface(const QString& deviceId, QObject* parent):
OrgKdeKdeconnectDeviceTelephonyInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/telephony", QDBusConnection::sessionBus(), parent)
{
}
TelephonyDbusInterface::~TelephonyDbusInterface() = default;

View file

@ -35,6 +35,7 @@
#include "interfaces/lockdeviceinterface.h" #include "interfaces/lockdeviceinterface.h"
#include "interfaces/remotecommandsinterface.h" #include "interfaces/remotecommandsinterface.h"
#include "interfaces/remotekeyboardinterface.h" #include "interfaces/remotekeyboardinterface.h"
#include "interfaces/telephonyinterface.h"
/** /**
* Using these "proxy" classes just in case we need to rename the * Using these "proxy" classes just in case we need to rename the
@ -196,6 +197,15 @@ Q_SIGNALS:
void remoteStateChanged(bool state); void remoteStateChanged(bool state);
}; };
class KDECONNECTINTERFACES_EXPORT TelephonyDbusInterface
: public OrgKdeKdeconnectDeviceTelephonyInterface
{
Q_OBJECT
public:
explicit TelephonyDbusInterface(const QString& deviceId, QObject* parent = nullptr);
~TelephonyDbusInterface() override;
};
template <typename T, typename W> template <typename T, typename W>
static void setWhenAvailable(const QDBusPendingReply<T>& pending, W func, QObject* parent) static void setWhenAvailable(const QDBusPendingReply<T>& pending, W func, QObject* parent)
{ {

View file

@ -74,6 +74,11 @@ QObject* createDeviceLockInterface(const QVariant& deviceId)
return new LockDeviceDbusInterface(deviceId.toString()); return new LockDeviceDbusInterface(deviceId.toString());
} }
QObject* createTelephonyInterface(const QVariant& deviceId)
{
return new TelephonyDbusInterface(deviceId.toString());
}
QObject* createDBusResponse() QObject* createDBusResponse()
{ {
return new DBusAsyncResponse(); return new DBusAsyncResponse();
@ -125,6 +130,9 @@ void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const cha
engine->rootContext()->setContextProperty(QStringLiteral("LockDeviceDbusInterfaceFactory") engine->rootContext()->setContextProperty(QStringLiteral("LockDeviceDbusInterfaceFactory")
, new ObjectFactory(engine, createDeviceLockInterface)); , new ObjectFactory(engine, createDeviceLockInterface));
engine->rootContext()->setContextProperty(QStringLiteral("TelephonyDbusInterfaceFactory")
, new ObjectFactory(engine, createTelephonyInterface));
engine->rootContext()->setContextProperty(QStringLiteral("DBusResponseFactory") engine->rootContext()->setContextProperty(QStringLiteral("DBusResponseFactory")
, new ObjectFactory(engine, createDBusResponse)); , new ObjectFactory(engine, createDBusResponse));

View file

@ -148,6 +148,7 @@ void TelephonyPlugin::sendSms(const QString& phoneNumber, const QString& message
{"phoneNumber", phoneNumber}, {"phoneNumber", phoneNumber},
{"messageBody", messageBody} {"messageBody", messageBody}
}); });
qDebug() << "sending sms!";
sendPacket(np); sendPacket(np);
} }

7
smsapp/CMakeLists.txt Normal file
View file

@ -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})

54
smsapp/main.cpp Normal file
View file

@ -0,0 +1,54 @@
/*
* This file is part of KDE Telepathy Chat
*
* Copyright (C) 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* 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 <QApplication>
#include <QQmlApplicationEngine>
#include <QCommandLineParser>
#include <QQmlContext>
#include <KAboutData>
#include <KLocalizedString>
#include <KLocalizedContext>
#include <KDBusService>
#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();
}

View file

@ -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

View file

@ -0,0 +1,96 @@
/*
* This file is part of KDE Telepathy Chat
*
* Copyright (C) 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* 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"
}
}

View file

@ -0,0 +1,65 @@
/*
* This file is part of KDE Telepathy Chat
*
* Copyright (C) 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* 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)
}
}
}
}

37
smsapp/qml/main.qml Normal file
View file

@ -0,0 +1,37 @@
/*
* This file is part of KDE Telepathy Chat
*
* Copyright (C) 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* 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")
}
}

7
smsapp/resources.qrc Normal file
View file

@ -0,0 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>qml/main.qml</file>
<file>qml/ContactList.qml</file>
<file>qml/ConversationDisplay.qml</file>
</qresource>
</RCC>