From b1b4f13dd37467b14e6e4dff216bbe8a26bea016 Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Fri, 16 Mar 2018 15:19:46 +0300 Subject: [PATCH] Handle open arguments --- .gitignore | 3 ++- src/Transporter.vala | 24 +++++++++++++++++++++++- src/Utils.vala | 14 ++++++-------- src/View/DropView.vala | 17 ++++++++++++++--- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index bdf43a2..22282ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ _ignore build build.sh -build-po.sh \ No newline at end of file +build-po.sh +install.sh \ No newline at end of file diff --git a/src/Transporter.vala b/src/Transporter.vala index 7a67c65..6af7062 100644 --- a/src/Transporter.vala +++ b/src/Transporter.vala @@ -8,13 +8,18 @@ public class Transporter : Granite.Application { construct { application_id = "com.github.bleakgrey.transporter"; - flags = ApplicationFlags.FLAGS_NONE; + flags = ApplicationFlags.HANDLES_OPEN; program_name = "Transporter"; build_version = "1.2.0"; } public static int main (string[] args) { Gtk.init (ref args); + + foreach (var arg in args) { + info(arg); + } + instance = new Transporter(); return instance.run (args); } @@ -34,4 +39,21 @@ public class Transporter : Granite.Application { window.present (); } + public override void open (File[] files, string hint) { + string[] paths = {}; + foreach (var file in files) { + var path = file.get_path (); + if(path != null){ + info(path); + paths += path; + } + } + + activate(); + + var view = new DropView(window); + window.addScreen(view); + view.send(paths); + } + } \ No newline at end of file diff --git a/src/Utils.vala b/src/Utils.vala index e96e775..14639c1 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -3,15 +3,13 @@ public class Utils{ private const string dir = "/tmp/Transporter"; private static string zip = null; - public static string get_send_path(string[] uris){ + public static string[] paths = {}; + + public static string get_send_path(){ int files = 0; int dirs = 0; - string[] paths = {}; - - foreach (string uri in uris) { - var path = GLib.Filename.from_uri(uri); - paths += path; + foreach (var path in paths) { if(is_directory (path)) dirs++; else @@ -20,9 +18,9 @@ public class Utils{ info("Sending %d files and %d directories".printf(files, dirs)); - if(uris.length == 1 && files == 1) + if(paths.length == 1 && files == 1) return paths[0]; - else if(uris.length == 1 && dirs == 1) + else if(paths.length == 1 && dirs == 1) return paths[0]; else return get_archive_path(paths); diff --git a/src/View/DropView.vala b/src/View/DropView.vala index c576fbf..6554262 100644 --- a/src/View/DropView.vala +++ b/src/View/DropView.vala @@ -69,22 +69,33 @@ public class DropView : Gtk.Box { private void on_drag_data_received (Gdk.DragContext drag_context, int x, int y, Gtk.SelectionData data, uint info, uint time){ Gtk.drag_finish (drag_context, true, false, time); + string[] paths = {}; + var uris = data.get_uris (); + foreach (var uri in uris) { + var path = GLib.Filename.from_uri(uri); + paths += path; + } + + send(paths); + } + + public void send(string[] paths){ var display = window.get_display (); var clipboard = Gtk.Clipboard.get_for_display (display, Gdk.SELECTION_CLIPBOARD); window.prevScreen(); window.addScreen (new SendView (window, clipboard)); - var uris = data.get_uris (); + Utils.paths = paths; try{ if(Thread.supported ()){ new Thread.try ("PackThread", () => { - var path = Utils.get_send_path (uris); + var path = Utils.get_send_path (); wormhole.send (path); return false; }); } else{ - var path = Utils.get_send_path (uris); + var path = Utils.get_send_path (); wormhole.send (path); } }