diff --git a/src/Application.vala b/src/Application.vala index 5b93ac2..a75be6a 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -65,7 +65,7 @@ namespace Gabut { get_css_online.begin ("https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css", create_folder (".bootstrap.min.css")); } var gabutserver = new GabutServer (); - gabutserver.set_listent_all.begin (int.parse (get_dbsetting (DBSettings.PORTLOCAL))); + gabutserver.set_listent.begin (int.parse (get_dbsetting (DBSettings.PORTLOCAL))); gabutserver.send_post_data.connect (dialog_server); gabutserver.address_url.connect ((url, options, later, linkmode)=> { gabutwindow.add_url_box (url, options, later, linkmode); @@ -78,11 +78,13 @@ namespace Gabut { gabutserver.stop_server (); }); gabutwindow.get_host.connect (()=> { + gabutserver.stop_server (); + gabutserver.set_listent.begin (int.parse (get_dbsetting (DBSettings.PORTLOCAL))); return gabutserver.get_address (); }); gabutwindow.restart_server.connect (()=> { gabutserver.stop_server (); - gabutserver.set_listent_all.begin (int.parse (get_dbsetting (DBSettings.PORTLOCAL))); + gabutserver.set_listent.begin (int.parse (get_dbsetting (DBSettings.PORTLOCAL))); }); downloaders = new GLib.List (); succesdls = new GLib.List (); diff --git a/src/GabutServer.vala b/src/GabutServer.vala index 3fbb667..48c53b7 100644 --- a/src/GabutServer.vala +++ b/src/GabutServer.vala @@ -27,8 +27,8 @@ namespace Gabut { public signal GLib.List get_dl_row (int status); private SourceFunc callback; - public async void set_listent_all (int port) throws Error { - callback = set_listent_all.callback; + public async void set_listent (int port) throws Error { + callback = set_listent.callback; this.add_handler ("/", home_handler); this.add_handler ("/Upload", upload_handler); this.add_handler ("/Downloading", gabut_handler); @@ -36,7 +36,11 @@ namespace Gabut { this.add_handler ("/Complete", gabut_handler); this.add_handler ("/Waiting", gabut_handler); this.add_handler ("/Error", gabut_handler); - this.listen_all (port, Soup.ServerListenOptions.IPV4_ONLY); + if (!bool.parse (get_dbsetting (DBSettings.IPLOCAL))) { + this.listen_all (port, Soup.ServerListenOptions.IPV4_ONLY); + } else { + this.listen_local (port, Soup.ServerListenOptions.IPV4_ONLY); + } yield; } @@ -171,14 +175,18 @@ namespace Gabut { } public string get_address () { - try { - var resolver = Resolver.get_default (); - var addresses = resolver.lookup_by_name ("www.google.com"); - var client = new SocketClient (); - var conn = client.connect (new InetSocketAddress (addresses.nth_data (0), 80)); - InetSocketAddress local = conn.get_local_address () as InetSocketAddress; - return @"http://$(local.get_address ()):$(get_uris ().nth_data (0).port)"; - } catch (Error e) { + if (!bool.parse (get_dbsetting (DBSettings.IPLOCAL))) { + try { + var resolver = Resolver.get_default (); + var addresses = resolver.lookup_by_name ("www.google.com"); + var client = new SocketClient (); + var conn = client.connect (new InetSocketAddress (addresses.nth_data (0), 80)); + InetSocketAddress local = conn.get_local_address () as InetSocketAddress; + return @"http://$(local.get_address ()):$(get_uris ().nth_data (0).port)"; + } catch (Error e) { + return @"$(e.message)"; + } + } else { return @"http://$(get_listeners ().nth_data (0).local_address)"; } } diff --git a/src/QrCode.vala b/src/QrCode.vala index d25638f..5700c96 100644 --- a/src/QrCode.vala +++ b/src/QrCode.vala @@ -24,6 +24,8 @@ namespace Gabut { public signal string get_host (); private Gtk.Image imageqr; private Gtk.LinkButton linkbutton; + private Gtk.Button host_button; + private bool local_server; public QrCode (Gtk.Application application) { Object (application: application, @@ -84,7 +86,7 @@ namespace Gabut { header.pack_start (header_grid); imageqr = new Gtk.Image (); - linkbutton = new Gtk.LinkButton (get_dbsetting (DBSettings.IPLOCAL)); + linkbutton = new Gtk.LinkButton (""); var link_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { margin_top = 10, @@ -98,8 +100,8 @@ namespace Gabut { destroy (); }); - var host_button = new Gtk.Button.with_label (_("Reload")); - host_button.clicked.connect (reload_host); + host_button = new Gtk.Button.with_label (_("Share Host")); + host_button.clicked.connect (share_server); var box_action = new Gtk.Grid () { width_request = 200, @@ -131,14 +133,23 @@ namespace Gabut { public override void show () { base.show (); - create_qrcode (get_dbsetting (DBSettings.IPLOCAL)); + local_server = bool.parse (get_dbsetting (DBSettings.IPLOCAL)); + Idle.add (load_host); } - private void reload_host () { + private void share_server () { + local_server = !local_server; + set_dbsetting (DBSettings.IPLOCAL, @"$(local_server)"); + load_host (); + } + + private bool load_host () { + host_button.label = local_server? _("Share Host") : _("Local Host"); string host = get_host (); - create_qrcode (set_dbsetting (DBSettings.IPLOCAL, host)); + create_qrcode (host); linkbutton.uri = host; linkbutton.label = host; + return false; } private void create_qrcode (string strinput) { diff --git a/src/Utils.vala b/src/Utils.vala index 96ecead..978950b 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -1433,7 +1433,7 @@ namespace Gabut { portlocal TEXT NOT NULL, seedtime TEXT NOT NULL); INSERT INTO settings (id, rpcport, maxtries, connserver, timeout, dir, retry, rpcsize, btmaxpeers, diskcache, maxactive, bttimeouttrack, split, maxopenfile, dialognotif, systemnotif, onbackground, iplocal, portlocal, seedtime) - VALUES (1, \"6807\", \"5\", \"6\", \"60\", \"$(dir)\", \"0\", \"2097152\", \"55\", \"16777216\", \"5\", \"60\", \"5\", \"100\", \"true\", \"true\", \"true\", \"127.0.0.1\", \"2021\", \"0\");", null, null); + VALUES (1, \"6807\", \"5\", \"6\", \"60\", \"$(dir)\", \"0\", \"2097152\", \"55\", \"16777216\", \"5\", \"60\", \"5\", \"100\", \"true\", \"true\", \"true\", \"true\", \"2021\", \"0\");", null, null); return opendb; }