Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Handle open arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
bleakgrey committed Mar 16, 2018
1 parent 8d38df8 commit b1b4f13
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
_ignore
build
build.sh
build-po.sh
build-po.sh
install.sh
24 changes: 23 additions & 1 deletion src/Transporter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}

}
14 changes: 6 additions & 8 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
17 changes: 14 additions & 3 deletions src/View/DropView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>.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);
}
}
Expand Down

0 comments on commit b1b4f13

Please sign in to comment.