Skip to content

Commit

Permalink
Add findmyphone
Browse files Browse the repository at this point in the history
Signed-off-by: Jo De Boeck <[email protected]>
  • Loading branch information
grimpy committed Dec 18, 2020
1 parent 2a632ad commit 6d9fbad
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 1 deletion.
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mconnect_src = [
'src/mconnect/notification.vala',
'src/mconnect/battery.vala',
'src/mconnect/battery-proxy.vala',
'src/mconnect/findmyphone-proxy.vala',
'src/mconnect/findmyphone.vala',
'src/mconnect/telephony.vala',
'src/mconnect/telephony-proxy.vala',
'src/mconnect/mousepad.vala',
Expand Down Expand Up @@ -83,6 +85,7 @@ mconnectctl_src = [
'src/mconnectctl/device-manager-iface.vala',
'src/mconnectctl/device-iface.vala',
'src/mconnectctl/share-iface.vala',
'src/mconnectctl/findmyphone-iface.vala',
'src/mconnectctl/telephony-iface.vala',
]
executable('mconnectctl', mconnectctl_src,
Expand Down
54 changes: 54 additions & 0 deletions src/mconnect/findmyphone-proxy.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* Maciek Borzecki <maciek.borzecki (at] gmail.com>
*/

[DBus (name = "org.mconnect.Device.FindMyPhone")]
class FindMyPhoneHandlerProxy : Object, PacketHandlerInterfaceProxy {

private Device device = null;
private FindMyPhoneHandler findmyphone_handler = null;

public FindMyPhoneHandlerProxy.for_device_handler (Device dev,
PacketHandlerInterface iface) {
this.device = dev;
this.findmyphone_handler = (FindMyPhoneHandler) iface;
this.findmyphone_handler.find_my_phone.connect (this.find_cb);
}

[DBus (visible = false)]
public void bus_register (DBusConnection conn, string path) throws IOError {
conn.register_object (path, this);
}

[DBus (visible = false)]
public void bus_unregister (DBusConnection conn) throws IOError {
// conn.unregister_object(this);
}

public void find() throws Error {
this.findmyphone_handler.find (this.device);
}

private void find_cb (Device dev) {
if (this.device != dev)
return;

find ();
}

public signal void find_my_phone ();
}
59 changes: 59 additions & 0 deletions src/mconnect/findmyphone.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* Maciek Borzecki <maciek.borzecki (at] gmail.com>
*/

class FindMyPhoneHandler : Object, PacketHandlerInterface {

public const string FIND_MY_PHONE = "kdeconnect.findmyphone.request";

public string get_pkt_type () {
return FIND_MY_PHONE;
}

private FindMyPhoneHandler () {
}

public static FindMyPhoneHandler instance () {
return new FindMyPhoneHandler ();
}

public void use_device (Device dev) {
debug ("use device %s for findphone", dev.to_string ());
dev.message.connect (this.message);
}

public void release_device (Device dev) {
debug ("release device %s", dev.to_string ());
dev.message.disconnect (this.message);
}

public void message (Device dev, Packet pkt) {
if (pkt.pkt_type != FIND_MY_PHONE) {
return;
}

GLib.message ("phone find from device %s", dev.to_string ());
find_my_phone (dev);
}

public void find (Device dev) {
var pkt = new Packet (FIND_MY_PHONE, new Json.Object ());
dev.send (pkt);
}

public signal void find_my_phone (Device dev);
}
5 changes: 4 additions & 1 deletion src/mconnect/packethandlers-proxy.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ class PacketHandlersProxy : Object {
case TelephonyHandler.TELEPHONY: {
return new TelephonyHandlerProxy.for_device_handler (dev, iface);
}
case FindMyPhoneHandler.FIND_MY_PHONE: {
return new FindMyPhoneHandlerProxy.for_device_handler (dev, iface);
}
default:
warning ("cannot register bus handler for %s",
iface.get_pkt_type ());
break;
}
return null;
}
}
}
2 changes: 2 additions & 0 deletions src/mconnect/packethandlers.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ class PacketHandlers : Object {
var share = ShareHandler.instance ();
var mpris = MprisHandler.instance ();
var clipboard = ClipboardHandler.instance ();
var findmyphone = FindMyPhoneHandler.instance ();

hnd.@set (notification.get_pkt_type (), notification);
hnd.@set (battery.get_pkt_type (), battery);
hnd.@set (telephony.get_pkt_type (), telephony);
hnd.@set (mousepad.get_pkt_type (), mousepad);
hnd.@set (ping.get_pkt_type (), ping);
hnd.@set (runcommand.get_pkt_type (), runcommand);
hnd.@set (findmyphone.get_pkt_type (), findmyphone);
hnd.@set (runqcommand.get_pkt_type (), runqcommand);
hnd.@set (share.get_pkt_type (), share);
hnd.@set (mpris.get_pkt_type (), mpris);
Expand Down
26 changes: 26 additions & 0 deletions src/mconnectctl/findmyphone-iface.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* AUTHORS
* Maciek Borzecki <maciek.borzecki (at] gmail.com>
*/

namespace Mconnect {

[DBus (name = "org.mconnect.Device.FindMyPhone")]
public interface FindMyPhoneIface : Object {

public abstract void find () throws Error;
}
}
25 changes: 25 additions & 0 deletions src/mconnectctl/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ namespace Mconnect {
allow-device <path> Allow device
show-device <path> Show device details
find-device <path> Find the device
share-url <path> <url> Share URL with device
share-text <path> <text> Share text with device
share-file <path> <file> Share file with device
Expand All @@ -94,6 +96,7 @@ namespace Mconnect {
Command[] commands = {
Command ("list-devices", 0, cl.cmd_list_devices),
Command ("allow-device", 1, cl.cmd_allow_device),
Command ("find-device", 1, cl.cmd_find_device),
Command ("show-device", 1, cl.cmd_show_device),
Command ("share-url", 2, cl.cmd_share_url),
Command ("share-text", 2, cl.cmd_share_text),
Expand Down Expand Up @@ -192,6 +195,16 @@ namespace Mconnect {
});
}


private int cmd_find_device (string[] args) {
return checked_dbus_call (() => {
var dp = args[0];
var device = get_find_my_phone (new ObjectPath (dp));
device.find ();
return 0;
});
}

private int cmd_share_file (string[] args) {
return checked_dbus_call (() => {
var dp = args[0];
Expand Down Expand Up @@ -335,6 +348,18 @@ namespace Mconnect {
return get_mconnect_obj_proxy (path);
}


/**
* get_find_my_phone:
*
* Obtain DBus interface to Share of given device
*
* @return interface or null
*/
private FindMyPhoneIface ? get_find_my_phone (ObjectPath path) throws IOError {
return get_mconnect_obj_proxy (path);
}

/**
* get_telephony:
*
Expand Down

0 comments on commit 6d9fbad

Please sign in to comment.