From e779eeadeee6df80749b5fc6171bdf2d930f8d64 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Mon, 9 Oct 2017 22:46:33 +0200 Subject: [PATCH] share: allow sharing of URLs and text to the device --- src/mconnect/share.vala | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/mconnect/share.vala b/src/mconnect/share.vala index bc95285..ca62f78 100644 --- a/src/mconnect/share.vala +++ b/src/mconnect/share.vala @@ -18,8 +18,8 @@ class ShareHandler : Object, PacketHandlerInterface { - private const string SHARE = "kdeconnect.share.request"; - private const string SHARE_PKT = "kdeconnect.share"; + public const string SHARE = "kdeconnect.share.request"; + public const string SHARE_PKT = "kdeconnect.share"; private static string DOWNLOADS = null; public void use_device(Device dev) { @@ -120,4 +120,27 @@ class ShareHandler : Object, PacketHandlerInterface { dev.device_name); } } + + private Packet make_share_packet(string name, string data) { + var builder = new Json.Builder(); + builder.begin_object(); + builder.set_member_name(name); + builder.add_string_value(data); + builder.end_object(); + return new Packet(SHARE, + builder.get_root().get_object()); + } + + public void share_url(Device dev, string url) { + debug("share url %s to device %s", url, dev.to_string()); + + dev.send(make_share_packet("url", url)); + } + + public void share_text(Device dev, string text) { + debug("share text %s to device %s", text, dev.to_string()); + + dev.send(make_share_packet("text", text)); + + } } \ No newline at end of file