Implement the touchpad forwarding into kcapp

This way the computer's cursor can be controlled from the device. Keyboard
is not yet implemented.
This commit is contained in:
Aleix Pol 2015-07-22 03:19:29 +02:00
parent a794d51c4e
commit 058f7c7c90
12 changed files with 254 additions and 1 deletions

View file

@ -122,6 +122,13 @@ ApplicationWindow
properties: { mprisInterface: MprisDbusInterfaceFactory.create(deviceView.currentDevice.id()) } properties: { mprisInterface: MprisDbusInterfaceFactory.create(deviceView.currentDevice.id()) }
} ); } );
} }
Button {
text: i18n("Mouse Pad")
onClicked: stack.push( {
item: "qrc:/qml/mousepad.qml",
properties: { remoteControlInterface: RemoteControlDbusInterfaceFactory.create(deviceView.currentDevice.id()) }
} );
}
Button { Button {
text: i18n("Remote touch and keyboard") text: i18n("Remote touch and keyboard")
enabled: false enabled: false

64
app/qml/mousepad.qml Normal file
View file

@ -0,0 +1,64 @@
/*
* Copyright 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.2
ColumnLayout
{
id: mousepad
property QtObject remoteControlInterface
MouseArea {
id: area
Layout.fillWidth: true
Layout.fillHeight: true
property var lastPos: Qt.point(-1, -1)
onClicked: mousepad.remoteControlInterface.sendCommand("singleclick", true);
onPositionChanged: {
if (lastPos.x > -1) {
// console.log("move", mouse.x, mouse.y, lastPos)
var delta = Qt.point(mouse.x-lastPos.x, mouse.y-lastPos.y);
remoteControlInterface.moveCursor(delta);
}
lastPos = Qt.point(mouse.x, mouse.y);
}
}
RowLayout {
Layout.fillWidth: true
Button {
Layout.fillWidth: true
onClicked: mousepad.remoteControlInterface.sendCommand("singleclick", true);
}
Button {
Layout.fillWidth: true
onClicked: mousepad.remoteControlInterface.sendCommand("middleclick", true);
}
Button {
Layout.fillWidth: true
onClicked: mousepad.remoteControlInterface.sendCommand("rightclick", true);
}
}
}

View file

@ -3,5 +3,6 @@
<file>qml/main.qml</file> <file>qml/main.qml</file>
<file>qml/DeviceDelegate.qml</file> <file>qml/DeviceDelegate.qml</file>
<file>qml/mpris.qml</file> <file>qml/mpris.qml</file>
<file>qml/mousepad.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -39,7 +39,7 @@ geninterface(${CMAKE_SOURCE_DIR}/plugins/sftp/sftpplugin.h devicesftpinterface.h
geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notificationsdbusinterface.h devicenotificationsinterface.h) geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notificationsdbusinterface.h devicenotificationsinterface.h)
geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notification.h notificationinterface.h) geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notification.h notificationinterface.h)
geninterface(${CMAKE_SOURCE_DIR}/plugins/mprisremote/mprisremoteplugin.h mprisremoteinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/mprisremote/mprisremoteplugin.h mprisremoteinterface)
geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecontrol/remotecontrolplugin.h remotecontrolinterface)
add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC}) add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC})
set_target_properties(kdeconnectinterfaces PROPERTIES set_target_properties(kdeconnectinterfaces PROPERTIES

View file

@ -113,3 +113,12 @@ MprisDbusInterface::MprisDbusInterface(const QString& id, QObject* parent)
MprisDbusInterface::~MprisDbusInterface() MprisDbusInterface::~MprisDbusInterface()
{ {
} }
RemoteControlDbusInterface::RemoteControlDbusInterface(const QString& id, QObject* parent)
: OrgKdeKdeconnectDeviceRemotecontrolInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/remotecontrol", QDBusConnection::sessionBus(), parent)
{
}
RemoteControlDbusInterface::~RemoteControlDbusInterface()
{
}

View file

@ -30,6 +30,7 @@
#include "interfaces/devicenotificationsinterface.h" #include "interfaces/devicenotificationsinterface.h"
#include "interfaces/notificationinterface.h" #include "interfaces/notificationinterface.h"
#include "interfaces/mprisremoteinterface.h" #include "interfaces/mprisremoteinterface.h"
#include "interfaces/remotecontrolinterface.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
@ -124,4 +125,13 @@ Q_SIGNALS:
void propertiesChangedProxy(); void propertiesChangedProxy();
}; };
class KDECONNECTINTERFACES_EXPORT RemoteControlDbusInterface
: public OrgKdeKdeconnectDeviceRemotecontrolInterface
{
Q_OBJECT
public:
RemoteControlDbusInterface(const QString& deviceId, QObject* parent = 0);
~RemoteControlDbusInterface() override;
};
#endif #endif

View file

@ -49,6 +49,11 @@ QObject* createSftpInterface(QVariant deviceId)
return new SftpDbusInterface(deviceId.toString()); return new SftpDbusInterface(deviceId.toString());
} }
QObject* createRemoteControlInterface(QVariant deviceId)
{
return new RemoteControlDbusInterface(deviceId.toString());
}
QObject* createMprisInterface(QVariant deviceId) QObject* createMprisInterface(QVariant deviceId)
{ {
return new MprisDbusInterface(deviceId.toString()); return new MprisDbusInterface(deviceId.toString());
@ -85,6 +90,9 @@ void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const cha
engine->rootContext()->setContextProperty("MprisDbusInterfaceFactory" engine->rootContext()->setContextProperty("MprisDbusInterfaceFactory"
, new ObjectFactory(engine, createMprisInterface)); , new ObjectFactory(engine, createMprisInterface));
engine->rootContext()->setContextProperty("RemoteControlDbusInterfaceFactory"
, new ObjectFactory(engine, createRemoteControlInterface));
engine->rootContext()->setContextProperty("DBusResponseFactory" engine->rootContext()->setContextProperty("DBusResponseFactory"
, new ObjectFactory(engine, createDBusResponse)); , new ObjectFactory(engine, createDBusResponse));

View file

@ -16,6 +16,7 @@ add_subdirectory(screensaver-inhibit)
if(EXPERIMENTALAPP_ENABLED) if(EXPERIMENTALAPP_ENABLED)
add_subdirectory(mprisremote) add_subdirectory(mprisremote)
add_subdirectory(remotecontrol)
endif() endif()
#FIXME: If we split notifications in several files, they won't appear in the same group in the Notifications KCM #FIXME: If we split notifications in several files, they won't appear in the same group in the Notifications KCM

View file

@ -0,0 +1,7 @@
kdeconnect_add_plugin(kdeconnect_remotecontrol JSON kdeconnect_remotecontrol.json SOURCES remotecontrolplugin.cpp)
target_link_libraries(kdeconnect_remotecontrol
kdeconnectcore
Qt5::DBus
KF5::I18n
)

View file

@ -0,0 +1,26 @@
{
"Encoding": "UTF-8",
"KPlugin": {
"Authors": [
{
"Email": "aleixpol@kde.org",
"Name": "Aleix Pol"
}
],
"Description": "Control Remote systems",
"EnabledByDefault": true,
"Icon": "applications-multimedia",
"Id": "kdeconnect_remotecontrol",
"License": "GPL",
"Name": "RemoteControl",
"ServiceTypes": [
"KdeConnect/Plugin"
],
"Version": "0.1",
"Website": "https://kde.org"
},
"X-KdeConnect-OutgoingPackageType": [
"kdeconnect.mousepad"
],
"X-KdeConnect-SupportedPackageType": []
}

View file

@ -0,0 +1,70 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "remotecontrolplugin.h"
#include <KLocalizedString>
#include <KPluginFactory>
#include <QDebug>
#include <QDBusConnection>
#include <QPoint>
#include <QLoggingCategory>
#include <core/device.h>
K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_remotecontrol.json", registerPlugin< RemoteControlPlugin >(); )
Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_REMOTECONTROL, "kdeconnect.plugin.remotecontrol")
RemoteControlPlugin::RemoteControlPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
{
}
RemoteControlPlugin::~RemoteControlPlugin()
{}
void RemoteControlPlugin::moveCursor(const QPoint &p)
{
NetworkPackage np(PACKAGE_TYPE_MOUSEPAD);
np.set("dx", p.x());
np.set("dy", p.y());
sendPackage(np);
}
void RemoteControlPlugin::sendCommand(const QString &name, bool val)
{
NetworkPackage np(PACKAGE_TYPE_MOUSEPAD);
np.set(name, val);
sendPackage(np);
}
void RemoteControlPlugin::connected()
{
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
}
QString RemoteControlPlugin::dbusPath() const
{
return "/modules/kdeconnect/devices/" + device()->id() + "/remotecontrol";
}
#include "remotecontrolplugin.moc"

View file

@ -0,0 +1,50 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MPRISREMOTEPLUGIN_H
#define MPRISREMOTEPLUGIN_H
#include <QObject>
#include <core/kdeconnectplugin.h>
#define PACKAGE_TYPE_MOUSEPAD QLatin1String("kdeconnect.mousepad")
class Q_DECL_EXPORT RemoteControlPlugin
: public KdeConnectPlugin
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.remotecontrol")
public:
explicit RemoteControlPlugin(QObject *parent, const QVariantList &args);
~RemoteControlPlugin() override;
bool receivePackage(const NetworkPackage& /*np*/) override { return false; }
void connected() override;
Q_INVOKABLE void moveCursor(const QPoint &p);
Q_INVOKABLE void sendCommand(const QString &name, bool val);
private:
QString dbusPath() const;
};
#endif