Find my phone plugin
Add a plugin that sends a package to ring an alarm on a phone Also adjusts plasmoid to have a button to invoke this.
This commit is contained in:
parent
b62349cae6
commit
9985a59608
11 changed files with 214 additions and 3 deletions
|
@ -51,6 +51,7 @@ int main(int argc, char** argv)
|
|||
parser.addOption(QCommandLineOption("id-only", i18n("Make --list-devices or --list-available print only the devices id, to ease scripting")));
|
||||
parser.addOption(QCommandLineOption("refresh", i18n("Search for devices in the network and re-establish connections")));
|
||||
parser.addOption(QCommandLineOption("pair", i18n("Request pairing to a said device")));
|
||||
parser.addOption(QCommandLineOption("ring", i18n("Find the said device by ringing it.")));
|
||||
parser.addOption(QCommandLineOption("unpair", i18n("Stop pairing to a said device")));
|
||||
parser.addOption(QCommandLineOption("ping", i18n("Sends a ping to said device")));
|
||||
parser.addOption(QCommandLineOption("ping-msg", i18n("Same as ping but you can set the message to display"), i18n("message")));
|
||||
|
@ -144,6 +145,9 @@ int main(int argc, char** argv)
|
|||
msg.setArguments(QVariantList() << message);
|
||||
}
|
||||
QDBusConnection::sessionBus().call(msg);
|
||||
} else if(parser.isSet("ring")) {
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/findmyphone", "org.kde.kdeconnect.device.findmyphone", "ring");
|
||||
QDBusConnection::sessionBus().call(msg);
|
||||
} else if(parser.isSet("list-notifications")) {
|
||||
NotificationsModel notifications;
|
||||
notifications.setDeviceId(device);
|
||||
|
|
|
@ -38,11 +38,13 @@ geninterface(${CMAKE_SOURCE_DIR}/core/device.h deviceinterface)
|
|||
geninterface(${CMAKE_SOURCE_DIR}/plugins/battery/batterydbusinterface.h devicebatteryinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/sftp/sftpplugin.h devicesftpinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notificationsdbusinterface.h devicenotificationsinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/findmyphone/findmyphoneplugin.h devicefindmyphoneinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/notifications/notification.h notificationinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/mprisremote/mprisremoteplugin.h mprisremoteinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecontrol/remotecontrolplugin.h remotecontrolinterface)
|
||||
geninterface(${CMAKE_SOURCE_DIR}/plugins/lockdevice/lockdeviceplugin.h lockdeviceinterface)
|
||||
|
||||
|
||||
add_library(kdeconnectinterfaces SHARED ${libkdeconnect_SRC})
|
||||
set_target_properties(kdeconnectinterfaces PROPERTIES
|
||||
VERSION ${KDECONNECT_VERSION}
|
||||
|
|
|
@ -137,4 +137,15 @@ LockDeviceDbusInterface::~LockDeviceDbusInterface()
|
|||
{
|
||||
}
|
||||
|
||||
FindMyPhoneDeviceDbusInterface::FindMyPhoneDeviceDbusInterface(const QString& deviceId, QObject* parent):
|
||||
OrgKdeKdeconnectDeviceFindmyphoneInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/findmyphone", QDBusConnection::sessionBus(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
FindMyPhoneDeviceDbusInterface::~FindMyPhoneDeviceDbusInterface()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "dbusinterfaces.moc"
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "interfaces/deviceinterface.h"
|
||||
#include "interfaces/devicebatteryinterface.h"
|
||||
#include "interfaces/devicesftpinterface.h"
|
||||
#include "interfaces/devicefindmyphoneinterface.h"
|
||||
#include "interfaces/devicenotificationsinterface.h"
|
||||
#include "interfaces/notificationinterface.h"
|
||||
#include "interfaces/mprisremoteinterface.h"
|
||||
|
@ -97,6 +98,7 @@ public:
|
|||
virtual ~NotificationDbusInterface();
|
||||
};
|
||||
|
||||
|
||||
class KDECONNECTINTERFACES_EXPORT SftpDbusInterface
|
||||
: public OrgKdeKdeconnectDeviceSftpInterface
|
||||
{
|
||||
|
@ -148,4 +150,13 @@ Q_SIGNALS:
|
|||
void lockedChangedProxy(bool isLocked);
|
||||
};
|
||||
|
||||
class KDECONNECTINTERFACES_EXPORT FindMyPhoneDeviceDbusInterface
|
||||
: public OrgKdeKdeconnectDeviceFindmyphoneInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FindMyPhoneDeviceDbusInterface(const QString& deviceId, QObject* parent = nullptr);
|
||||
virtual ~FindMyPhoneDeviceDbusInterface();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,11 @@ QObject* createDeviceBatteryDbusInterface(QVariant deviceId)
|
|||
return new DeviceBatteryDbusInterface(deviceId.toString());
|
||||
}
|
||||
|
||||
QObject* createFindMyPhoneInterface(QVariant deviceId)
|
||||
{
|
||||
return new FindMyPhoneDeviceDbusInterface(deviceId.toString());
|
||||
}
|
||||
|
||||
QObject* createSftpInterface(QVariant deviceId)
|
||||
{
|
||||
return new SftpDbusInterface(deviceId.toString());
|
||||
|
@ -79,6 +84,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
|||
qmlRegisterType<DevicesSortProxyModel>(uri, 1, 0, "DevicesSortProxyModel");
|
||||
qmlRegisterUncreatableType<MprisDbusInterface>(uri, 1, 0, "MprisDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
|
||||
qmlRegisterUncreatableType<LockDeviceDbusInterface>(uri, 1, 0, "LockDeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
|
||||
qmlRegisterUncreatableType<FindMyPhoneDeviceDbusInterface>(uri, 1, 0, "FindMyPhoneDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
|
||||
qmlRegisterUncreatableType<DeviceDbusInterface>(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess"));
|
||||
}
|
||||
|
||||
|
@ -92,6 +98,9 @@ void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine* engine, const cha
|
|||
engine->rootContext()->setContextProperty("DeviceBatteryDbusInterfaceFactory"
|
||||
, new ObjectFactory(engine, createDeviceBatteryDbusInterface));
|
||||
|
||||
engine->rootContext()->setContextProperty("FindMyPhoneDbusInterfaceFactory"
|
||||
, new ObjectFactory(engine, createFindMyPhoneInterface));
|
||||
|
||||
engine->rootContext()->setContextProperty("SftpDbusInterfaceFactory"
|
||||
, new ObjectFactory(engine, createSftpInterface));
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
import QtQuick 2.1
|
||||
import QtQuick.Layouts 1.2
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
import org.kde.kdeconnect 1.0
|
||||
|
@ -33,12 +34,34 @@ PlasmaComponents.ListItem
|
|||
Column {
|
||||
width: parent.width
|
||||
|
||||
Row
|
||||
RowLayout
|
||||
{
|
||||
Item {
|
||||
//spacer to make the label centre aligned in a row yet still elide and everything
|
||||
implicitWidth: ring.width + browse.width + parent.spacing
|
||||
}
|
||||
|
||||
PlasmaComponents.Label {
|
||||
width: browse.visible? parent.width - browse.width : parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
elide: Text.ElideRight
|
||||
text: display
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
PlasmaComponents.Button
|
||||
{
|
||||
FindMyPhone {
|
||||
id: findmyphone
|
||||
deviceId: root.deviceId
|
||||
}
|
||||
|
||||
id: ring
|
||||
iconSource: "preferences-desktop-notification"
|
||||
visible: findmyphone.available
|
||||
|
||||
onClicked: {
|
||||
findmyphone.ring()
|
||||
}
|
||||
}
|
||||
|
||||
PlasmaComponents.Button
|
||||
|
@ -57,7 +80,6 @@ PlasmaComponents.ListItem
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
height: browse.height
|
||||
width: parent.width
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ if(NOT WIN32)
|
|||
add_subdirectory(sftp)
|
||||
endif()
|
||||
|
||||
add_subdirectory(findmyphone)
|
||||
|
||||
if(EXPERIMENTALAPP_ENABLED)
|
||||
add_subdirectory(mprisremote)
|
||||
add_subdirectory(remotecontrol)
|
||||
|
|
9
plugins/findmyphone/CMakeLists.txt
Normal file
9
plugins/findmyphone/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
set(kdeconnect_findmyphone_SRCS
|
||||
findmyphoneplugin.cpp
|
||||
)
|
||||
|
||||
kdeconnect_add_plugin(kdeconnect_findmyphone JSON kdeconnect_findmyphone.json SOURCES ${kdeconnect_findmyphone_SRCS})
|
||||
|
||||
target_link_libraries(kdeconnect_findmyphone kdeconnectcore kdeconnectcore Qt5::Core Qt5::DBus)
|
||||
|
||||
|
62
plugins/findmyphone/findmyphoneplugin.cpp
Normal file
62
plugins/findmyphone/findmyphoneplugin.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Copyright 2014 Apoorv Parle <apparle@gmail.com>
|
||||
* Copyright 2015 David Edmundson <davidedmundson@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/>.
|
||||
*/
|
||||
|
||||
#include "findmyphoneplugin.h"
|
||||
|
||||
#include <core/device.h>
|
||||
#include <QDBusConnection>
|
||||
#include <QDebug>
|
||||
|
||||
#include <KPluginFactory>
|
||||
|
||||
K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_findmyphone.json", registerPlugin< FindMyPhonePlugin >(); )
|
||||
|
||||
FindMyPhonePlugin::FindMyPhonePlugin(QObject* parent, const QVariantList& args) : KdeConnectPlugin(parent, args)
|
||||
{
|
||||
}
|
||||
|
||||
FindMyPhonePlugin::~FindMyPhonePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
bool FindMyPhonePlugin::receivePackage(const NetworkPackage& np)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void FindMyPhonePlugin::ring()
|
||||
{
|
||||
NetworkPackage np(PACKAGE_TYPE_FINDMYPHONE);
|
||||
bool success = sendPackage(np);
|
||||
}
|
||||
|
||||
void FindMyPhonePlugin::connected()
|
||||
{
|
||||
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
|
||||
}
|
||||
|
||||
QString FindMyPhonePlugin::dbusPath() const
|
||||
{
|
||||
return "/modules/kdeconnect/devices/" + device()->id() + "/findmyphone";
|
||||
}
|
||||
|
||||
#include "findmyphoneplugin.moc"
|
||||
|
50
plugins/findmyphone/findmyphoneplugin.h
Normal file
50
plugins/findmyphone/findmyphoneplugin.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Copyright 2014 Apoorv Parle <apparle@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 PINGPLUGIN_H
|
||||
#define PINGPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <core/kdeconnectplugin.h>
|
||||
|
||||
#define PACKAGE_TYPE_FINDMYPHONE QStringLiteral("kdeconnect.findmyphone")
|
||||
|
||||
class FindMyPhonePlugin
|
||||
: public KdeConnectPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.findmyphone")
|
||||
|
||||
public:
|
||||
explicit FindMyPhonePlugin(QObject *parent, const QVariantList &args);
|
||||
virtual ~FindMyPhonePlugin();
|
||||
|
||||
Q_SCRIPTABLE void ring();
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void connected();
|
||||
virtual bool receivePackage(const NetworkPackage& np);
|
||||
|
||||
private:
|
||||
QString dbusPath() const;
|
||||
};
|
||||
|
||||
#endif
|
29
plugins/findmyphone/kdeconnect_findmyphone.json
Normal file
29
plugins/findmyphone/kdeconnect_findmyphone.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"KPlugin" : {
|
||||
"Encoding" : "UTF-8",
|
||||
"Name" : "Find My Phone",
|
||||
"Description" : "Find your lost phone by making it play an alarm sound ",
|
||||
"Id" : "kdeconnect_findmyphone",
|
||||
"Version" : "0.1",
|
||||
"Authors" : [
|
||||
{
|
||||
"Name" : "Apoorv Parle",
|
||||
"Email" : "apparle@gmail.com"
|
||||
},
|
||||
{
|
||||
"Name" : "David Edmundson",
|
||||
"Email" : "davidedmundson@kde.org"
|
||||
}
|
||||
],
|
||||
"License" : "GPL",
|
||||
"EnabledByDefault" : true,
|
||||
"ServiceTypes" : [
|
||||
"KdeConnect/Plugin"
|
||||
],
|
||||
"Website" : "http://kde.org",
|
||||
"Icon" : "edit-find"
|
||||
},
|
||||
"X-KdeConnect-OutgoingPackageType" : [
|
||||
"kdeconnect.findmyphone"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue