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

Commit

Permalink
Merge pull request #17 from bleakgrey/launch-params
Browse files Browse the repository at this point in the history
  • Loading branch information
bleakgrey authored Mar 16, 2018
2 parents 28dd743 + dda7d96 commit dc3c5b9
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 15 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
6 changes: 6 additions & 0 deletions data/com.github.bleakgrey.transporter.contract
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Contractor Entry]
Name=Transport
Description=Send files to another computer with Transporter
Icon=com.github.bleakgrey.transporter
MimeType=inode;application;audio;video;text;multipart;archive;
Exec=com.github.bleakgrey.transporter %F
11 changes: 10 additions & 1 deletion data/com.github.bleakgrey.transporter.desktop.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ Terminal=false
Categories=GNOME;GTK;Utility;Network;FileTransfer;
Keywords=share;files;send;receive;wormhole;transfer;
MimeType=text/plain;
StartupNotify=true
StartupNotify=true
Actions=ShowSend;ShowReceive;

[Desktop Action ShowSend]
Exec=com.github.bleakgrey.transporter --send
Name=Send Files

[Desktop Action ShowReceive]
Exec=com.github.bleakgrey.transporter --receive
Name=Receive Files
6 changes: 5 additions & 1 deletion data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ foreach i : icon_sizes
endforeach

install_data(
'com.github.bleakgrey.transporter.gschema.xml',
meson.project_name() + '.gschema.xml',
install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas')
)
install_data(
meson.project_name() + '.contract',
install_dir: join_paths(get_option('prefix'), 'share', 'contractor')
)

i18n.merge_file(
input: meson.project_name() + '.desktop.in',
Expand Down
38 changes: 37 additions & 1 deletion src/Transporter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@ using Granite;
public class Transporter : Granite.Application {

public static Transporter instance;
public static bool open_send = false;
public static bool open_receive = false;
public TransporterWindow window;

private const GLib.OptionEntry[] options = {
{ "send", 0, 0, OptionArg.NONE, ref open_send, "Open Send view", null },
{ "receive", 0, 0, OptionArg.NONE, ref open_receive, "Open Receive view", null },
{ null }
};

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);
var opt_context = new OptionContext ("- Options");
opt_context.add_main_entries (options, null);
opt_context.parse (ref args);

instance = new Transporter();
return instance.run (args);
}
Expand All @@ -32,6 +44,30 @@ public class Transporter : Granite.Application {

protected override void activate () {
window.present ();

if(open_send)
window.addScreen (new DropView (window));
else if(open_receive)
window.addScreen (new ReceiveView (window));
}

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();

if(paths.length > 0){
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 dc3c5b9

Please sign in to comment.