Compare commits

...

Author SHA1 Message Date
  Maciek Borzecki 01b298b0e9 mconnectctl: realign command description in --help output 7 years ago
  Maciek Borzecki ad905bf40b mconnectctl: update send SMS help description 7 years ago
  Maciek Borzecki 517a27d518 mconnectctl: find-my-phone command 7 years ago
  Maciek Borzecki fe1cded886 find-my-phone: support for 'find my phone' 7 years ago
  Maciek Borzecki d3b6534bc2 packet: allow empty body 7 years ago
8 changed files with 172 additions and 10 deletions
Split View
  1. +3
    -0
      meson.build
  2. +44
    -0
      src/mconnect/find-my-phone-proxy.vala
  3. +56
    -0
      src/mconnect/find-my-phone.vala
  4. +8
    -3
      src/mconnect/packet.vala
  5. +3
    -0
      src/mconnect/packethandlers-proxy.vala
  6. +2
    -0
      src/mconnect/packethandlers.vala
  7. +26
    -0
      src/mconnectctl/find-my-phone-iface.vala
  8. +30
    -7
      src/mconnectctl/main.vala

+ 3
- 0
meson.build View File

@ -40,6 +40,8 @@ mconnect_src = [
'src/mconnect/battery-proxy.vala',
'src/mconnect/telephony.vala',
'src/mconnect/telephony-proxy.vala',
'src/mconnect/find-my-phone.vala',
'src/mconnect/find-my-phone-proxy.vala',
'src/mconnect/mousepad.vala',
'src/mconnect/ping.vala',
'src/mconnect/ping-proxy.vala',
@ -75,6 +77,7 @@ mconnectctl_src = [
'src/mconnectctl/device-iface.vala',
'src/mconnectctl/share-iface.vala',
'src/mconnectctl/telephony-iface.vala',
'src/mconnectctl/find-my-phone-iface.vala',
]
executable('mconnectctl', mconnectctl_src,
dependencies : [glib_dep, gobject_dep,


+ 44
- 0
src/mconnect/find-my-phone-proxy.vala View File

@ -0,0 +1,44 @@
/**
* 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 find_my_phone_handler = null;
public FindMyPhoneHandlerProxy.for_device_handler (Device dev,
PacketHandlerInterface iface) {
this.device = dev;
this.find_my_phone_handler = (FindMyPhoneHandler) iface;
}
[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 ring () {
this.find_my_phone_handler.ring (this.device);
}
}

+ 56
- 0
src/mconnect/find-my-phone.vala View File

@ -0,0 +1,56 @@
/**
* 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 ping", 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) {
return;
}
private Packet make_find_my_phone_packet () {
var pkt = new Packet (FIND_MY_PHONE, null);
return pkt;
}
public void ring (Device dev) {
dev.send (make_find_my_phone_packet ());
}
}

+ 8
- 3
src/mconnect/packet.vala View File

@ -45,14 +45,14 @@ class Packet : GLib.Object {
public int64 id {
get; private set; default = 0;
}
public Json.Object body {
public Json.Object ? body {
get; private set; default = null;
}
public Payload ? payload {
get; set; default = null;
}
public Packet (string type, Json.Object body, int64 id = 0) {
public Packet (string type, Json.Object ? body, int64 id = 0) {
this.pkt_type = type;
this.body = body;
if (id == 0) {
@ -162,7 +162,12 @@ class Packet : GLib.Object {
var root_obj = new Json.Object ();
root_obj.set_string_member ("type", pkt_type);
root_obj.set_int_member ("id", id);
root_obj.set_object_member ("body", body);
if (this.body != null)
root_obj.set_object_member ("body", body);
else
root_obj.set_object_member ("body", new Json.Object ());
if (this.payload != null) {
root_obj.set_int_member ("payloadSize", (int64) this.payload.size);
var pti = new Json.Object ();


+ 3
- 0
src/mconnect/packethandlers-proxy.vala View File

@ -36,6 +36,9 @@ 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 ());


+ 2
- 0
src/mconnect/packethandlers.vala View File

@ -43,6 +43,7 @@ class PacketHandlers : Object {
var mousepad = MousepadHandler.instance ();
var ping = PingHandler.instance ();
var share = ShareHandler.instance ();
var fmp = FindMyPhoneHandler.instance ();
hnd.@set (notification.get_pkt_type (), notification);
hnd.@set (battery.get_pkt_type (), battery);
@ -50,6 +51,7 @@ class PacketHandlers : Object {
hnd.@set (mousepad.get_pkt_type (), mousepad);
hnd.@set (ping.get_pkt_type (), ping);
hnd.@set (share.get_pkt_type (), share);
hnd.@set (fmp.get_pkt_type (), fmp);
return hnd;
}


+ 26
- 0
src/mconnectctl/find-my-phone-iface.vala View File

@ -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 ring () throws IOError;
}
}

+ 30
- 7
src/mconnectctl/main.vala View File

@ -63,15 +63,17 @@ namespace Mconnect {
var opt_context = new OptionContext ();
opt_context.set_description (
"""Available commands:
list-devices List devices
allow-device <path> Allow device
show-device <path> Show device details
list-devices List devices
allow-device <path> Allow device
show-device <path> Show device details
share-url <path> <url> Share URL with device
share-text <path> <text> Share text with device
share-file <path> <file> Share file with 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
send-sms <number> <message> Send SMS
send-sms <path> <number> <message> Send SMS
find-my-phone <path> Find my phone
"""
);
opt_context.set_help_enabled (true);
@ -98,6 +100,7 @@ namespace Mconnect {
Command ("share-text", 2, cl.cmd_share_text),
Command ("share-file", 2, cl.cmd_share_file),
Command ("send-sms", 3, cl.cmd_send_sms),
Command ("find-my-phone", 1, cl.cmd_find_my_phone),
};
handle_command (remaining, commands);
@ -214,6 +217,15 @@ namespace Mconnect {
});
}
private int cmd_find_my_phone (string[] args) {
return checked_dbus_call (() => {
var dp = args[0];
var fmp = get_find_my_phone (new ObjectPath (dp));
fmp.ring ();
return 0;
});
}
private void print_sorted_caps (string[] caps, string format) {
qsort_with_data<string>(caps, sizeof (string),
(a, b) => GLib.strcmp (a, b));
@ -345,6 +357,17 @@ namespace Mconnect {
return get_mconnect_obj_proxy (path);
}
/**
* get_find_my_phone:
*
* Obtain DBus interface to FindMyPhone of given device
*
* @return interface or null
*/
private FindMyPhoneIface ? get_find_my_phone (ObjectPath path) throws IOError {
return get_mconnect_obj_proxy (path);
}
/**
* print_paths:
* @objs: object paths


Loading…
Cancel
Save