From 450c273dcb6edf0eea4fe016125b5c460b61b34f Mon Sep 17 00:00:00 2001 From: Micin Date: Mon, 4 Jul 2022 07:36:00 +0700 Subject: [PATCH] interface host and fix dm --- src/Application.vala | 23 ++++-- src/DownloadRow.vala | 51 +++++++------ src/Downloader.vala | 78 ++++++-------------- src/GabutServer.vala | 160 +++++++++++++++++++++++++++++----------- src/GabutWindow.vala | 157 ++++++++++++++++----------------------- src/Preferences.vala | 3 + src/ServerCss.vala | 28 ++++--- src/ServerDM.vala | 70 ++++++++++++------ src/ServerHome.vala | 6 +- src/ServerNotFound.vala | 6 +- src/ServerShare.vala | 6 +- src/ServerUpload.vala | 6 +- src/Utils.vala | 60 ++++++++++++++- 13 files changed, 382 insertions(+), 272 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 590648b..14613ac 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -123,6 +123,14 @@ namespace Gabut { gabutserver.stop_server (); gabutserver.set_listent.begin (int.parse (get_dbsetting (DBSettings.PORTLOCAL))); }); + gabutwindow.update_agid.connect ((ariagid, newgid)=> { + downloaders.foreach ((downloader)=> { + if (downloader.ariagid == ariagid) { + downloader.ariagid = newgid; + downloader.get_active_status (); + } + }); + }); gabutserver.address_url.connect ((url, options, later, linkmode)=> { gabutwindow.add_url_box (url, options, later, linkmode); }); @@ -137,12 +145,6 @@ namespace Gabut { } }); add_action (action_download); - var action_status = new SimpleAction ("status", VariantType.STRING); - action_status.activate.connect ((parameter) => { - string aria_gid = parameter.get_string (null); - gabutwindow.fast_respond (aria_gid); - }); - add_action (action_status); var action_succes = new SimpleAction ("succes", VariantType.STRING); action_succes.activate.connect ((parameter) => { string succes = parameter.get_string (null); @@ -160,6 +162,12 @@ namespace Gabut { gabutserver.get_dl_row.connect ((status)=> { return gabutwindow.get_dl_row (status); }); + gabutserver.updat_row.connect ((status)=> { + gabutwindow.server_action (status); + }); + gabutserver.delete_row.connect ((status)=> { + gabutwindow.remove_item (status); + }); clipboard = gabutwindow.get_display ().get_clipboard (); clipboard.changed.connect (on_clipboard); pantheon_theme.begin (); @@ -354,6 +362,9 @@ namespace Gabut { downloader.sendselected.connect ((ariagid, selected)=> { return gabutwindow.set_selected (ariagid, selected); }); + downloader.actions_button.connect ((ariagid, status)=> { + return gabutwindow.server_action (ariagid, status); + }); } private void on_clipboard () { diff --git a/src/DownloadRow.vala b/src/DownloadRow.vala index acecbec..676cc2b 100644 --- a/src/DownloadRow.vala +++ b/src/DownloadRow.vala @@ -22,6 +22,7 @@ namespace Gabut { public class DownloadRow : Gtk.ListBoxRow { public signal void delete_me (DownloadRow row); + public signal void update_agid (string ariagid, string newgid); private Gtk.Button start_button; private Gtk.Label transfer_rate; private Gtk.ProgressBar progressbar; @@ -123,6 +124,7 @@ namespace Gabut { if (ariagid == aria_tell_status (strgid, TellStatus.FOLLOWING)) { status = status_aria (aria_tell_status (strgid, TellStatus.STATUS)); filename = aria_tell_bittorent (strgid, TellBittorrent.NAME); + update_agid (ariagid, strgid); ariagid = strgid; linkmode = LinkMode.TORRENT; progressbar.fraction = 0.0; @@ -268,12 +270,16 @@ namespace Gabut { } set { _transferred = value.abs (); - double fraction = (double) transferred / (double) totalsize; - if (fraction > 0.0) { - progressbar.fraction = fraction; - } - if (status == StatusMode.ACTIVE) { - set_progress_visible.begin (progressbar.fraction); + if (totalsize > 0) { + double fraction = (double) transferred / (double) totalsize; + if (fraction > 0.0) { + progressbar.fraction = fraction; + } + if (status == StatusMode.ACTIVE) { + set_progress_visible.begin (progressbar.fraction); + } + } else { + progressbar.pulse (); } } } @@ -352,7 +358,8 @@ namespace Gabut { valign = Gtk.Align.CENTER }; progressbar = new Gtk.ProgressBar () { - hexpand = true + hexpand = true, + pulse_step = 0.2 }; filename_label = new Gtk.Label (filename) { @@ -366,20 +373,7 @@ namespace Gabut { valign = Gtk.Align.CENTER }; start_button.clicked.connect (()=> { - if (status == StatusMode.COMPLETE) { - send_dialog (); - return; - } - if (linkmode != LinkMode.URL) { - action_dowload (); - } else { - if (aria_geturis (ariagid) != "") { - action_dowload (); - } else { - ariagid = aria_url (url, hashoption); - status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); - } - } + action_btn (); }); var remove_button = new Gtk.Button.from_icon_name ("edit-delete") { @@ -407,6 +401,15 @@ namespace Gabut { child = grid; } + public string action_btn (int stats = 2) { + if (stats != StatusMode.NOTHING && status == StatusMode.COMPLETE) { + send_dialog (); + return ariagid; + } + action_dowload (); + return ariagid; + } + public void if_not_exist (string ariag, int linkm, int stats) { if (stats == StatusMode.COMPLETE || stats == StatusMode.ERROR) { return; @@ -448,11 +451,7 @@ namespace Gabut { } public void idle_progress () { - Idle.add (()=> { - update_progress (); - add_timeout (); - return false; - }); + Idle.add (()=> { update_progress (); return false; }); } private void action_dowload () { diff --git a/src/Downloader.vala b/src/Downloader.vala index 7a660d1..6067f3d 100644 --- a/src/Downloader.vala +++ b/src/Downloader.vala @@ -22,6 +22,7 @@ namespace Gabut { public class Downloader : Gtk.Dialog { public signal string sendselected (string ariagid, string selected); + public signal string actions_button (string ariagid, int status); private Gtk.Button start_button; private Gtk.ProgressBar progressbar; private Gtk.Label transfer_rate; @@ -43,7 +44,6 @@ namespace Gabut { private Gtk.TreeView infotorrent; private Gtk.TreeView peerstree; private Gtk.TextView commenttext; - private Gtk.Revealer download_rev; private bool stoptimer; private string _url; @@ -72,30 +72,27 @@ namespace Gabut { remove_timeout (); break; case StatusMode.COMPLETE: + start_button.set_label (_("Open")); statuslabel.label = _("Complete"); - start_button.set_label (_("Complete")); statuslabel.attributes = color_attribute (60000, 30000, 19764); remove_timeout (); - if (aria_str_files (AriaGetfiles.PATH, ariagid).contains ("[METADATA]")) { - close (); - } break; case StatusMode.WAIT: - start_button.set_label (_("Wait")); + start_button.set_label (_("Pause")); statuslabel.label = _("Waiting"); statuslabel.attributes = color_attribute (0, 0, 42588); remove_timeout (); break; case StatusMode.ERROR: + start_button.set_label (_("Resume")); statuslabel.label = _("Error"); statuslabel.attributes = color_attribute (60000, 0, 0); remove_timeout (); - close (); break; case StatusMode.NOTHING: - statuslabel.label = _("Nothing Process!, Press Download for continue"); - statuslabel.attributes = color_attribute (28705, 4000, 9882); - download_rev.reveal_child = true; + start_button.set_label (_("New Process")); + statuslabel.label = _("Nothing Process!"); + statuslabel.attributes = color_attribute (49647, 22352, 44235); remove_timeout (); break; default: @@ -148,9 +145,13 @@ namespace Gabut { set { _transferred = value; downloaded.label = GLib.format_size (_transferred, GLib.FormatSizeFlags.LONG_FORMAT); - double fraction = (double) transferred / (double) totalsize; - if (fraction > 0.0) { - progressbar.fraction = fraction; + if (totalsize > 0) { + double fraction = (double) transferred / (double) totalsize; + if (fraction > 0.0) { + progressbar.fraction = fraction; + } + } else { + progressbar.pulse (); } } } @@ -189,6 +190,7 @@ namespace Gabut { progressbar = new Gtk.ProgressBar () { hexpand = true, + pulse_step = 0.2, width_request = 600 }; @@ -417,21 +419,6 @@ namespace Gabut { boxstatus.attach (stack, 0, 1); boxstatus.attach (progressbar, 0, 2); - var download = new Gtk.Button.with_label (_("Redownload")) { - width_request = 120, - height_request = 25, - halign = Gtk.Align.START - }; - ((Gtk.Label) download.get_last_child ()).attributes = set_attribute (Pango.Weight.SEMIBOLD); - download.clicked.connect (()=> { - sendselected (ariagid, ""); - remove_timeout (); - close (); - }); - download_rev = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.CROSSFADE, - child = download - }; var close_button = new Gtk.Button.with_label (_("Close")) { width_request = 120, height_request = 25, @@ -449,14 +436,17 @@ namespace Gabut { halign = Gtk.Align.END }; ((Gtk.Label) start_button.get_last_child ()).attributes = set_attribute (Pango.Weight.SEMIBOLD); - start_button.clicked.connect (action_status); + start_button.clicked.connect (()=> { + string agid = actions_button (ariagid, status); + ariagid = agid; + get_active_status (); + }); var box_action = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5) { halign = Gtk.Align.END, margin_top = 10, margin_bottom = 10 }; - box_action.append (download_rev); box_action.append (start_button); box_action.append (close_button); @@ -493,11 +483,7 @@ namespace Gabut { public override void show () { base.show (); - Idle.add (()=> { - update_progress (); - add_timeout (); - return false; - }); + Idle.add (()=> { update_progress (); return false; }); } private Gtk.TreeViewColumn text_column (string title, int column) { @@ -573,28 +559,6 @@ namespace Gabut { status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); } - private void action_status () { - status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); - if (status == StatusMode.ACTIVE) { - aria_pause (ariagid); - remove_timeout (); - } else if (status == StatusMode.PAUSED) { - aria_unpause (ariagid); - add_timeout (); - } else if (status == StatusMode.COMPLETE) { - remove_timeout (); - } else if (status == StatusMode.WAIT) { - add_timeout (); - } else { - remove_timeout (); - close (); - } - status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); - if (status != StatusMode.COMPLETE) { - application.activate_action ("status", new Variant.string (ariagid)); - } - } - public void aria_gid (string ariagid) { this.ariagid = ariagid; down_limit.value = double.parse (aria_get_option (ariagid, AriaOptions.MAX_DOWNLOAD_LIMIT)) / 1024; diff --git a/src/GabutServer.vala b/src/GabutServer.vala index 7e858af..9a68834 100644 --- a/src/GabutServer.vala +++ b/src/GabutServer.vala @@ -21,6 +21,8 @@ namespace Gabut { public class GabutServer : Soup.Server { + public signal void updat_row (string ariagid); + public signal void delete_row (string ariagid); public signal void send_post_data (MatchInfo match_info); public signal void address_url (string url, Gee.HashMap options, bool later, int linkmode); public signal GLib.List get_dl_row (int status); @@ -86,7 +88,7 @@ namespace Gabut { if (filename != null && filename != "") { File filed = GLib.File.new_build_filename (aria_get_globalops (AriaOptions.DIR).replace ("\\/", "/"), filename); if (!filed.query_exists ()) { - write_file.begin (body, filename); + write_file.begin (body, filed.get_path ()); notify_app (_("File Transfered"), _("%s").printf (filename), new ThemedIcon (GLib.ContentType.get_generic_icon_name (headers.get_content_type (null)))); } else { notify_app (_("File Exist"), _("%s").printf (filename), new ThemedIcon (GLib.ContentType.get_generic_icon_name (headers.get_content_type (null)))); @@ -167,35 +169,7 @@ namespace Gabut { private void gabut_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { unowned GabutServer self = server as GabutServer; - string pathname = ""; - var htmlstr = "
"; - if (path.contains ("Downloading")) { - pathname = path.split ("/")[1].strip (); - get_dl_row (StatusMode.ACTIVE).foreach ((row)=> { - htmlstr += dm_div (row, "playing"); - }); - } else if (path.contains ("Paused")) { - pathname = path.split ("/")[1].strip (); - get_dl_row (StatusMode.PAUSED).foreach ((row)=> { - htmlstr += dm_div (row, "paused"); - }); - } else if (path.contains ("Complete")) { - pathname = path.split ("/")[1].strip (); - get_dl_row (StatusMode.COMPLETE).foreach ((row)=> { - htmlstr += dm_div (row, "complete"); - }); - } else if (path.contains ("Waiting")) { - pathname = path.split ("/")[1].strip (); - get_dl_row (StatusMode.WAIT).foreach ((row)=> { - htmlstr += dm_div (row, "waiting"); - }); - } else if (path.contains ("Error")) { - pathname = path.split ("/")[1].strip (); - get_dl_row (StatusMode.ERROR).foreach ((row)=> { - htmlstr += dm_div (row, "error"); - }); - } - htmlstr += "
"; + string pathname = path.split ("/")[1].strip (); self.pause_message (msg); if (msg.get_method () == "POST") { string result = (string) msg.get_request_body ().data; @@ -211,7 +185,7 @@ namespace Gabut { address_url (reslink, hashoption, false, LinkMode.URL); } } - msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, htmlstr).data); + msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path)).data); msg.set_status (Soup.Status.OK, "OK"); self.unpause_message (msg); } else if (msg.get_request_headers ().get_content_type (null) == Soup.FORM_MIME_TYPE_MULTIPART) { @@ -230,7 +204,17 @@ namespace Gabut { address_url (bencode, hashoption, false, LinkMode.METALINK); } } - msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, htmlstr).data); + msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path)).data); + msg.set_status (Soup.Status.OK, "OK"); + self.unpause_message (msg); + } else if (result.contains ("actiondm")) { + updat_row (result.slice (result.last_index_of ("+") + 1, result.last_index_of ("="))); + msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path)).data); + msg.set_status (Soup.Status.OK, "OK"); + self.unpause_message (msg); + } else if (result.contains ("actiondelete")) { + delete_row (result.slice (result.last_index_of ("+") + 1, result.last_index_of ("="))); + msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path)).data); msg.set_status (Soup.Status.OK, "OK"); self.unpause_message (msg); } else { @@ -238,12 +222,84 @@ namespace Gabut { self.unpause_message (msg); } } else if (msg.get_method () == "GET") { - msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, htmlstr).data); + msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path)).data); msg.set_status (Soup.Status.OK, "OK"); self.unpause_message (msg); } } + private string html_dm (string path) { + var htmlstr = ""; + if (path == "/Downloading") { + var dlist = get_dl_row (StatusMode.ACTIVE); + if (dlist.length () > 0) { + htmlstr = "
"; + } + dlist.foreach ((row)=> { + htmlstr += dm_div (row, "Pause", path); + }); + if (dlist.length () > 0) { + htmlstr += "
"; + } + } else if (path == "/Paused") { + var dlist = get_dl_row (StatusMode.PAUSED); + if (dlist.length () > 0) { + htmlstr = "
"; + } + dlist.foreach ((row)=> { + htmlstr += dm_div (row, "Start", path); + }); + if (dlist.length () > 0) { + htmlstr += "
"; + } + } else if (path == "/Complete") { + var dlist = get_dl_row (StatusMode.COMPLETE); + if (dlist.length () > 0) { + htmlstr = "
"; + } + dlist.foreach ((row)=> { + htmlstr += dm_div (row, "Complete", path); + }); + if (dlist.length () > 0) { + htmlstr += "
"; + } + } else if (path == "/Waiting") { + var dlist = get_dl_row (StatusMode.WAIT); + if (dlist.length () > 0) { + htmlstr = "
"; + } + dlist.foreach ((row)=> { + htmlstr += dm_div (row, "Waiting", path); + }); + if (dlist.length () > 0) { + htmlstr += "
"; + } + } else if (path == "Error") { + var dlist = get_dl_row (StatusMode.ERROR); + if (dlist.length () > 0) { + htmlstr = "
"; + } + dlist.foreach ((row)=> { + htmlstr += dm_div (row, "Error", path); + }); + if (dlist.length () > 0) { + htmlstr += "
"; + } + } + return htmlstr; + } + + private string javascr_dm (string path) { + var script = ""; + if (path == "/Downloading") { + if (get_dl_row (StatusMode.ACTIVE).length () > 0) { + script += @""; + script += ""; + } + } + return script; + } + private void share_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { unowned GabutServer self = server as GabutServer; self.pause_message (msg); @@ -265,14 +321,34 @@ namespace Gabut { self.unpause_message (msg); } - private string dm_div (DownloadRow? row, string icon) { + private string dm_div (DownloadRow? row, string action, string path) { + double fraction = ((double) row.transferred / (double) row.totalsize); var sbuilder = new StringBuilder ("
"); - sbuilder.append (@""); - sbuilder.append (@"

$(row.filename != null? row.filename : "Loading Informatioan")

"); - sbuilder.append (@"
$(GLib.format_size (row.transferred).to_ascii ())
"); - sbuilder.append (@"
$(GLib.format_size (row.totalsize).to_ascii ())
"); - sbuilder.append (@"
"); - sbuilder.append ("
"); + if (row.fileordir != null) { + sbuilder.append (@""); + } else { + sbuilder.append (""); + } + sbuilder.append (@"
    "); + if (row.filename != null && row.pathname != null) { + sbuilder.append (@"
  • $(row.filename)

  • "); + } else { + sbuilder.append (@"
  • \"Loading Informatioan\"

  • "); + } + if (row.totalsize > 0) { + sbuilder.append (@"
  • "); + } else { + sbuilder.append (@"
  • "); + } + if (row.labeltransfer != null) { + sbuilder.append (@"
  • $(row.labeltransfer.to_ascii ())
  • "); + } else { + sbuilder.append ("
  • \"Loading file...\"
  • "); + } + sbuilder.append (@"
"); + sbuilder.append (@"
"); + sbuilder.append (@"
"); + sbuilder.append ("\n"); return sbuilder.str; } @@ -281,7 +357,7 @@ namespace Gabut { var filesorter = new Gtk.ListStore (FSorter.N_COLUMNS, typeof (string), typeof (string), typeof (bool), typeof (int64), typeof (int), typeof (FileInfo), typeof (string)); FileEnumerator enumerator = file.enumerate_children ("*", GLib.FileQueryInfoFlags.NOFOLLOW_SYMLINKS); FileInfo info = null; - while (((info = enumerator.next_file (null)) != null)) { + while ((info = enumerator.next_file ()) != null) { if (info.get_is_hidden ()) { continue; } @@ -407,7 +483,7 @@ namespace Gabut { } else { sbuilder.append (@""); } - sbuilder.append (""); + sbuilder.append ("\n"); return sbuilder.str; } diff --git a/src/GabutWindow.vala b/src/GabutWindow.vala index 5cc055a..1816a15 100644 --- a/src/GabutWindow.vala +++ b/src/GabutWindow.vala @@ -26,6 +26,7 @@ namespace Gabut { public signal void restart_server (); public signal void open_show (); public signal bool active_downloader (string ariagid); + public signal void update_agid (string ariagid, string newgid); public signal string get_host (); private Gtk.ListBox list_box; private Gtk.Stack headerstack; @@ -141,18 +142,16 @@ namespace Gabut { restart_server (); }); preferences.restart_process.connect (()=> { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - row.if_not_exist (row.ariagid, row.linkmode, row.status); - } + listrow.foreach ((row)=> { + row.if_not_exist (row.ariagid, row.linkmode, row.status); }); }); preferences.max_active.connect (()=> { next_download (); }); + preferences.global_opt.connect (()=> { + update_options (); + }); preferences.close.connect (()=> { if (bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)) != hide_on_close) { hide_on_close = bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)); @@ -403,58 +402,56 @@ namespace Gabut { public GLib.List get_dl_row (int status) { var rowlist = new GLib.List (); - int total = (int) listrow.length (); - for (int i = 0; i < total; i++) { - list_box.select_row (list_box.get_row_at_index (i)); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.status == status) { - rowlist.append (row); - } + for (int i = 0; i < (int) listrow.length (); i++) { + if (listrow.nth_data (i).status == status) { + rowlist.append (listrow.nth_data (i)); } } return rowlist; } + private void update_options () { + listrow.foreach ((row)=> { + if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { + glob_to_opt (row.ariagid); + } + }); + } + private void next_download () { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.status == StatusMode.WAIT) { - aria_unpause (row.ariagid); - row.idle_progress (); - } + listrow.foreach ((row)=> { + if (row.status == StatusMode.WAIT) { + row.update_progress (); } }); } - public void fast_respond (string ariagid) { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.ariagid == ariagid) { - row.idle_progress (); - } + public string server_action (string ariagid, int status = 2) { + var agid = ariagid; + listrow.foreach ((row)=> { + if (row.ariagid == ariagid) { + agid = row.action_btn (status); } }); + return agid; } - public void remove_all () { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { + public void remove_item (string ariagid) { + listrow.foreach ((row)=> { + if (row.ariagid == ariagid) { row.remove_down (); } }); aria_purge_all (); } + public void remove_all () { + listrow.foreach ((row)=> { + row.remove_down (); + }); + aria_purge_all (); + } + public void load_dowanload () { get_download ().foreach ((row)=> { if (!get_exist (row.url)) { @@ -499,6 +496,9 @@ namespace Gabut { listrow.delete_link (listrow.find (rw)); stop_launcher (); }); + row.update_agid.connect ((ariagid, newgid)=> { + update_agid (ariagid, newgid); + }); } }); } @@ -544,6 +544,9 @@ namespace Gabut { listrow.delete_link (listrow.find (rw)); stop_launcher (); }); + row.update_agid.connect ((ariagid, newgid)=> { + update_agid (ariagid, newgid); + }); if (list_box.get_selected_row () == null) { list_box.select_row (row); list_box.row_activated (row); @@ -558,90 +561,60 @@ namespace Gabut { private bool get_exist (string url) { bool linkexist = false; - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.url == url) { - linkexist = true; - } + listrow.foreach ((row)=> { + if (row.url == url) { + linkexist = true; } }); return linkexist; } private void start_all () { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { - aria_unpause (row.ariagid); - row.idle_progress (); - } + listrow.foreach ((row)=> { + if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { + aria_unpause (row.ariagid); + row.update_progress (); } }); view_status (); } private void stop_all () { - aria_pause_all (); - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { - aria_pause (row.ariagid); - row.update_progress (); - } + listrow.foreach ((row)=> { + if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { + aria_pause (row.ariagid); + row.idle_progress (); } }); + aria_pause_all (); view_status (); } public string set_selected (string ariagid, string selected) { string aria_gid = ""; - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.ariagid == ariagid) { - aria_gid = row.set_selected (selected); - } + listrow.foreach ((row)=> { + if (row.ariagid == ariagid) { + aria_gid = row.set_selected (selected); } }); return aria_gid; } public void append_row (string ariagid) { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.ariagid == ariagid) { - if (row.status == StatusMode.ACTIVE) { - append_dbus.begin (row.rowbus); - } + listrow.foreach ((row)=> { + if (row.ariagid == ariagid) { + if (row.status == StatusMode.ACTIVE) { + append_dbus.begin (row.rowbus); } } }); } public void remove_row (string ariagid) { - listrow.foreach ((lrow)=> { - list_box.select_row (lrow); - var row = (DownloadRow) list_box.get_selected_row (); - if (row != null) { - list_box.unselect_row (row); - if (row.ariagid == ariagid) { - if (row.status == StatusMode.ACTIVE) { - remove_dbus.begin (row.rowbus); - } + listrow.foreach ((row)=> { + if (row.ariagid == ariagid) { + if (row.status == StatusMode.ACTIVE) { + remove_dbus.begin (row.rowbus); } } }); diff --git a/src/Preferences.vala b/src/Preferences.vala index 677d9d0..1c09854 100644 --- a/src/Preferences.vala +++ b/src/Preferences.vala @@ -24,6 +24,7 @@ namespace Gabut { public signal void restart_server (); public signal void restart_process (); public signal void max_active (); + public signal void global_opt (); private Gtk.MenuButton allocate_button; private Gtk.MenuButton piecesel_button; private Gtk.MenuButton urisel_button; @@ -724,6 +725,7 @@ namespace Gabut { notifyopt.attach (headerlabel (_("File Download:"), 450), 0, 9, 1, 1); notifyopt.attach (allowrepl, 0, 10, 1, 1); notifyopt.attach (autorename, 0, 11, 1, 1); + var notyscr = new Gtk.ScrolledWindow () { width_request = 455, vexpand = true, @@ -809,6 +811,7 @@ namespace Gabut { restart_server (); close (); } else { + global_opt (); close (); } }); diff --git a/src/ServerCss.vala b/src/ServerCss.vala index 1b9fde9..5e08e34 100644 --- a/src/ServerCss.vala +++ b/src/ServerCss.vala @@ -268,6 +268,10 @@ namespace Gabut { flex-basis: 10%; text-align: end; } + .item .deleteb { + flex-basis: 10%; + text-align: end; + } .item .button { flex-basis: 10%; text-align: end; @@ -308,20 +312,20 @@ namespace Gabut { .item .icon.po { content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='white' class='bi bi-translate' viewBox='0 0 16 16'%3E%3Cpath d='M4.545 6.714 4.11 8H3l1.862-5h1.284L8 8H6.833l-.435-1.286H4.545zm1.634-.736L5.5 3.956h-.049l-.679 2.022H6.18z'/%3E%3Cpath d='M0 2a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v3h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-3H2a2 2 0 0 1-2-2V2zm2-1a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H2zm7.138 9.995c.193.301.402.583.63.846-.748.575-1.673 1.001-2.768 1.292.178.217.451.635.555.867 1.125-.359 2.08-.844 2.886-1.494.777.665 1.739 1.165 2.93 1.472.133-.254.414-.673.629-.89-1.125-.253-2.057-.694-2.82-1.284.681-.747 1.222-1.651 1.621-2.757H14V8h-3v1.047h.765c-.318.844-.74 1.546-1.272 2.13a6.066 6.066 0 0 1-.415-.492 1.988 1.988 0 0 1-.94.31z'/%3E%3C/svg%3E\"); } - .item .icon.playing { - content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='yellow' class='bi bi-play-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.79 5.093A.5.5 0 0 0 6 5.5v5a.5.5 0 0 0 .79.407l3.5-2.5a.5.5 0 0 0 0-.814l-3.5-2.5z'/%3E%3C/svg%3E\"); + .icon.playing { + content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128' fill='yellow' class='bi bi-play-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.79 5.093A.5.5 0 0 0 6 5.5v5a.5.5 0 0 0 .79.407l3.5-2.5a.5.5 0 0 0 0-.814l-3.5-2.5z'/%3E%3C/svg%3E\"); } - .item .icon.paused { - content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='blue' class='bi bi-pause-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.25 5C5.56 5 5 5.56 5 6.25v3.5a1.25 1.25 0 1 0 2.5 0v-3.5C7.5 5.56 6.94 5 6.25 5zm3.5 0c-.69 0-1.25.56-1.25 1.25v3.5a1.25 1.25 0 1 0 2.5 0v-3.5C11 5.56 10.44 5 9.75 5z'/%3E%3C/svg%3E\"); + .icon.paused { + content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128' fill='blue' class='bi bi-pause-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM6.25 5C5.56 5 5 5.56 5 6.25v3.5a1.25 1.25 0 1 0 2.5 0v-3.5C7.5 5.56 6.94 5 6.25 5zm3.5 0c-.69 0-1.25.56-1.25 1.25v3.5a1.25 1.25 0 1 0 2.5 0v-3.5C11 5.56 10.44 5 9.75 5z'/%3E%3C/svg%3E\"); } - .item .icon.waiting { - content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='white' class='bi bi-stopwatch-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 0a.5.5 0 0 0 0 1H7v1.07A7.001 7.001 0 0 0 8 16a7 7 0 0 0 5.29-11.584.531.531 0 0 0 .013-.012l.354-.354.353.354a.5.5 0 1 0 .707-.707l-1.414-1.415a.5.5 0 1 0-.707.707l.354.354-.354.354a.717.717 0 0 0-.012.012A6.973 6.973 0 0 0 9 2.071V1h.5a.5.5 0 0 0 0-1h-3zm2 5.6V9a.5.5 0 0 1-.5.5H4.5a.5.5 0 0 1 0-1h3V5.6a.5.5 0 1 1 1 0z'/%3E%3C/svg%3E\"); + .icon.waiting { + content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128' fill='white' class='bi bi-stopwatch-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 0a.5.5 0 0 0 0 1H7v1.07A7.001 7.001 0 0 0 8 16a7 7 0 0 0 5.29-11.584.531.531 0 0 0 .013-.012l.354-.354.353.354a.5.5 0 1 0 .707-.707l-1.414-1.415a.5.5 0 1 0-.707.707l.354.354-.354.354a.717.717 0 0 0-.012.012A6.973 6.973 0 0 0 9 2.071V1h.5a.5.5 0 0 0 0-1h-3zm2 5.6V9a.5.5 0 0 1-.5.5H4.5a.5.5 0 0 1 0-1h3V5.6a.5.5 0 1 1 1 0z'/%3E%3C/svg%3E\"); } - .item .icon.complete { - content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='blue' class='bi bi-check-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z'/%3E%3C/svg%3E\"); + .icon.complete { + content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128' fill='blue' class='bi bi-check-circle-fill' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z'/%3E%3C/svg%3E\"); } - .item .icon.error { - content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='red' class='bi bi-x-octagon-fill' viewBox='0 0 16 16'%3E%3Cpath d='M11.46.146A.5.5 0 0 0 11.107 0H4.893a.5.5 0 0 0-.353.146L.146 4.54A.5.5 0 0 0 0 4.893v6.214a.5.5 0 0 0 .146.353l4.394 4.394a.5.5 0 0 0 .353.146h6.214a.5.5 0 0 0 .353-.146l4.394-4.394a.5.5 0 0 0 .146-.353V4.893a.5.5 0 0 0-.146-.353L11.46.146zm-6.106 4.5L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 1 1 .708-.708z'/%3E%3C/svg%3E\"); + .icon.error { + content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='128' fill='red' class='bi bi-x-octagon-fill' viewBox='0 0 16 16'%3E%3Cpath d='M11.46.146A.5.5 0 0 0 11.107 0H4.893a.5.5 0 0 0-.353.146L.146 4.54A.5.5 0 0 0 0 4.893v6.214a.5.5 0 0 0 .146.353l4.394 4.394a.5.5 0 0 0 .353.146h6.214a.5.5 0 0 0 .353-.146l4.394-4.394a.5.5 0 0 0 .146-.353V4.893a.5.5 0 0 0-.146-.353L11.46.146zm-6.106 4.5L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 1 1 .708-.708z'/%3E%3C/svg%3E\"); } .icon.closew { content: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' fill='white' class='bi bi-x-circle' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E\"); @@ -452,6 +456,6 @@ namespace Gabut { -webkit-transform: none; transform: none; } - } - ";} + }"; + } } diff --git a/src/ServerDM.vala b/src/ServerDM.vala index def0784..20b32b4 100644 --- a/src/ServerDM.vala +++ b/src/ServerDM.vala @@ -20,13 +20,42 @@ */ namespace Gabut { - public string get_dm (string pathname, string htmlstr) { + public string get_dm (string pathname, string htmlstr, string javascr) { + string errordm = "

Nothing Error file Download

"; + string activedm = "

Nothing Active file Download

"; + string pauseddm = "

Nothing Paused file Download

"; + string waitdm = "

No Waiting file Download

"; + string completedm = "

Nothing Complete file Download

"; + if (pathname == "Downloading") { + if (htmlstr != "") { + activedm = htmlstr; + } + } else if (pathname == "Paused") { + if (htmlstr != "") { + pauseddm = htmlstr; + } + } else if (pathname == "Complete") { + if (htmlstr != "") { + completedm = htmlstr; + } + } else if (pathname == "Waiting") { + if (htmlstr != "") { + waitdm = htmlstr; + } + } else if (pathname == "Error") { + if (htmlstr != "") { + errordm = htmlstr; + } + } return @" Gabut Download Manager +
@@ -49,43 +78,43 @@ namespace Gabut {
- $(htmlstr) + $(activedm)
- $(htmlstr) + $(pauseddm)
- +
- $(htmlstr) + $(completedm)
- $(htmlstr) + $(waitdm)
- $(htmlstr) + $(errordm)
-
+ $(javascr) - diff --git a/src/ServerHome.vala b/src/ServerHome.vala index b841f0b..5f1e709 100644 --- a/src/ServerHome.vala +++ b/src/ServerHome.vala @@ -27,6 +27,9 @@ namespace Gabut { Welcome to Gabut Akut +
@@ -97,9 +100,6 @@ namespace Gabut { document.getElementById(\"myOverlay\").style.display = \"none\"; } - diff --git a/src/ServerNotFound.vala b/src/ServerNotFound.vala index a88ed28..a745109 100644 --- a/src/ServerNotFound.vala +++ b/src/ServerNotFound.vala @@ -27,6 +27,9 @@ namespace Gabut { Not Found +
@@ -68,9 +71,6 @@ namespace Gabut {
- diff --git a/src/ServerShare.vala b/src/ServerShare.vala index 677e150..426b0ff 100644 --- a/src/ServerShare.vala +++ b/src/ServerShare.vala @@ -31,6 +31,9 @@ namespace Gabut { +
@@ -77,9 +80,6 @@ namespace Gabut {
- diff --git a/src/ServerUpload.vala b/src/ServerUpload.vala index cec6468..dd40392 100644 --- a/src/ServerUpload.vala +++ b/src/ServerUpload.vala @@ -27,6 +27,9 @@ namespace Gabut { Share File To Computer +
@@ -83,9 +86,6 @@ namespace Gabut { document.getElementById(\"myOverlay\").style.display = \"none\"; } - diff --git a/src/Utils.vala b/src/Utils.vala index f0bbff5..221fd1d 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -258,7 +258,7 @@ namespace Gabut { COMPLETE = 2, WAIT = 3, ERROR = 4, - NOTHING + NOTHING = 5 } private enum AriaOptions { @@ -371,7 +371,8 @@ namespace Gabut { HTTP_PROXY_PASSWD = 106, HTTPS_PROXY = 107, HTTPS_PROXY_USER = 108, - HTTPS_PROXY_PASSWD = 109; + HTTPS_PROXY_PASSWD = 109, + OPTIMIZE_CONCURRENT_DOWNLOADS = 110; public string get_name () { switch (this) { @@ -593,6 +594,8 @@ namespace Gabut { return "https-proxy-user"; case HTTPS_PROXY_PASSWD: return "https-proxy-passwd"; + case OPTIMIZE_CONCURRENT_DOWNLOADS: + return "optimize-concurrent-downloads"; default: return "allow-overwrite"; } @@ -1805,6 +1808,57 @@ namespace Gabut { }); } + private void glob_to_opt (string ariagid) { + if (get_dbsetting (DBSettings.MAXTRIES) != aria_get_option (ariagid, AriaOptions.MAX_TRIES)) { + aria_set_option (ariagid, AriaOptions.MAX_TRIES, get_dbsetting (DBSettings.MAXTRIES)); + } + if (get_dbsetting (DBSettings.CONNSERVER) != aria_get_option (ariagid, AriaOptions.MAX_CONNECTION_PER_SERVER)) { + aria_set_option (ariagid, AriaOptions.MAX_CONNECTION_PER_SERVER, get_dbsetting (DBSettings.CONNSERVER)); + } + if (get_dbsetting (DBSettings.TIMEOUT) != aria_get_option (ariagid, AriaOptions.TIMEOUT)) { + aria_set_option (ariagid, AriaOptions.TIMEOUT, get_dbsetting (DBSettings.TIMEOUT)); + } + if (get_dbsetting (DBSettings.RETRY) != aria_get_option (ariagid, AriaOptions.RETRY_WAIT)) { + aria_set_option (ariagid, AriaOptions.RETRY_WAIT, get_dbsetting (DBSettings.RETRY)); + } + if (get_dbsetting (DBSettings.BTMAXPEERS) != aria_get_option (ariagid, AriaOptions.BT_MAX_PEERS)) { + aria_set_option (ariagid, AriaOptions.BT_MAX_PEERS, get_dbsetting (DBSettings.BTMAXPEERS)); + } + if (get_dbsetting (DBSettings.BTTIMEOUTTRACK) != aria_get_option (ariagid, AriaOptions.BT_TRACKER_TIMEOUT)) { + aria_set_option (ariagid, AriaOptions.BT_TRACKER_TIMEOUT, get_dbsetting (DBSettings.BTTIMEOUTTRACK)); + } + if (get_dbsetting (DBSettings.SPLIT) != aria_get_option (ariagid, AriaOptions.SPLIT)) { + aria_set_option (ariagid, AriaOptions.SPLIT, get_dbsetting (DBSettings.SPLIT)); + } + if (get_dbsetting (DBSettings.SEEDTIME) != aria_get_option (ariagid, AriaOptions.SEED_TIME)) { + aria_set_option (ariagid, AriaOptions.SEED_TIME, get_dbsetting (DBSettings.SEEDTIME)); + } + if (get_dbsetting (DBSettings.OVERWRITE) != aria_get_option (ariagid, AriaOptions.ALLOW_OVERWRITE)) { + aria_set_option (ariagid, AriaOptions.ALLOW_OVERWRITE, get_dbsetting (DBSettings.OVERWRITE)); + } + if (get_dbsetting (DBSettings.AUTORENAMING) != aria_get_option (ariagid, AriaOptions.AUTO_FILE_RENAMING)) { + aria_set_option (ariagid, AriaOptions.AUTO_FILE_RENAMING, get_dbsetting (DBSettings.AUTORENAMING)); + } + if (get_dbsetting (DBSettings.BTTRACKER) != aria_get_option (ariagid, AriaOptions.BT_TRACKER)) { + aria_set_option (ariagid, AriaOptions.BT_TRACKER, get_dbsetting (DBSettings.BTTRACKER)); + } + if (get_dbsetting (DBSettings.BTTRACKEREXC) != aria_get_option (ariagid, AriaOptions.BT_EXCLUDE_TRACKER)) { + aria_set_option (ariagid, AriaOptions.BT_EXCLUDE_TRACKER, get_dbsetting (DBSettings.BTTRACKEREXC)); + } + if (get_dbsetting (DBSettings.SPLITSIZE) != aria_get_option (ariagid, AriaOptions.MIN_SPLIT_SIZE)) { + aria_set_option (ariagid, AriaOptions.MIN_SPLIT_SIZE, get_dbsetting (DBSettings.SPLITSIZE)); + } + if (get_dbsetting (DBSettings.LOWESTSPEED) != aria_get_option (ariagid, AriaOptions.LOWEST_SPEED_LIMIT)) { + aria_set_option (ariagid, AriaOptions.LOWEST_SPEED_LIMIT, get_dbsetting (DBSettings.LOWESTSPEED)); + } + if (get_dbsetting (DBSettings.URISELECTOR) != aria_get_option (ariagid, AriaOptions.URI_SELECTOR)){ + aria_set_option (ariagid, AriaOptions.URI_SELECTOR, get_dbsetting (DBSettings.URISELECTOR)); + } + if (get_dbsetting (DBSettings.PIECESELECTOR) != aria_get_option (ariagid, AriaOptions.STREAM_PIECE_SELECTOR)) { + aria_set_option (ariagid, AriaOptions.STREAM_PIECE_SELECTOR, get_dbsetting (DBSettings.PIECESELECTOR)); + } + } + private void set_startup () { do { aria_set_globalops (AriaOptions.MAX_TRIES, get_dbsetting (DBSettings.MAXTRIES)); @@ -1888,7 +1942,7 @@ namespace Gabut { try { FileEnumerator enumerator = file.enumerate_children ("*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS); FileInfo info = null; - while (((info = enumerator.next_file (null)) != null)) { + while ((info = enumerator.next_file ()) != null) { if (info.get_is_hidden ()) { continue; }