diff --git a/src/Downloader.vala b/src/Downloader.vala index c444288..9cec783 100644 --- a/src/Downloader.vala +++ b/src/Downloader.vala @@ -40,6 +40,7 @@ namespace Gabut { private Gtk.ListBox listboxtorrent; private Gee.ArrayList listtorrent; private Gtk.ListBox lisboxserver; + private Gee.ArrayList listserver; private Gtk.ListBox listboxpeers; private Gee.ArrayList listpeers; private Gtk.TextView infotorrent; @@ -497,6 +498,7 @@ namespace Gabut { centerbox.set_end_widget (box_action); lisboxserver = new Gtk.ListBox (); + listserver = new Gee.ArrayList (); var servscrolled = new Gtk.ScrolledWindow () { hexpand = true, @@ -645,19 +647,69 @@ namespace Gabut { } if (switch_rev) { if (connpeers.get_visible_child_name () == "serverconn") { - lisboxserver.remove_all (); - aria_servers_store (ariagid).foreach ((serverrow)=> { - lisboxserver.append (serverrow); - serverrow.show (); + var arrayserv = aria_servers_store (ariagid); + arrayserv.foreach ((serverrow) => { + bool servext = false; + listserver.foreach ((serverrow2) => { + if (serverrow.key == serverrow2.index) { + servext = true; + serverrow2.currenturi = serverrow.value.currenturi; + serverrow2.downloadspeed = serverrow.value.downloadspeed; + serverrow2.uriserver = serverrow.value.uriserver; + } + return true; + }); + if (!servext) { + if (!server_exist (serverrow.key)) { + lisboxserver.append (serverrow.value); + listserver.add (serverrow.value); + serverrow.value.show (); + } + } + return true; + }); + listserver.foreach ((servrow2) => { + if (!arrayserv.has_key (servrow2.index)) { + listserver.remove (servrow2); + lisboxserver.remove (servrow2); + } return true; }); + arrayserv.clear (); } else { - show_peers (); - } - } else { - if (listpeers.size > 1) { - listboxpeers.remove_all (); - listpeers.clear (); + var arraypeers = aria_get_peers (ariagid); + arraypeers.foreach ((peersrow) => { + bool peerext = false; + listpeers.foreach ((peersrow2) => { + if (peersrow2.host == peersrow.key) { + peerext = true; + peersrow2.peerid = peersrow.value.peerid; + peersrow2.downloadspeed = peersrow.value.downloadspeed; + peersrow2.uploadspeed = peersrow.value.uploadspeed; + peersrow2.peerschoking = peersrow.value.peerschoking; + peersrow2.seeder = peersrow.value.seeder; + peersrow2.amchoking = peersrow.value.amchoking; + peersrow2.bitfield = peersrow.value.bitfield; + } + return true; + }); + if (!peerext) { + if (!peer_exist (peersrow.key)) { + listboxpeers.append (peersrow.value); + listpeers.add (peersrow.value); + peersrow.value.show (); + } + } + return true; + }); + listpeers.foreach ((peersrow2) => { + if (!arraypeers.has_key (peersrow2.host)) { + listpeers.remove (peersrow2); + listboxpeers.remove (peersrow2); + } + return true; + }); + arraypeers.clear (); } } status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); @@ -667,39 +719,15 @@ namespace Gabut { return stoptimer; } - private void show_peers () { - var arraypeers = aria_get_peers (ariagid); - arraypeers.foreach ((peersrow) => { - bool exist = false; - listpeers.foreach ((peersrow2) => { - if (peersrow2.host == peersrow.key) { - exist = true; - peersrow2.peerid = peersrow.value.peerid; - peersrow2.downloadspeed = peersrow.value.downloadspeed; - peersrow2.uploadspeed = peersrow.value.uploadspeed; - peersrow2.peerschoking = peersrow.value.peerschoking; - peersrow2.seeder = peersrow.value.seeder; - peersrow2.amchoking = peersrow.value.amchoking; - peersrow2.bitfield = peersrow.value.bitfield; - } - return true; - }); - if (!exist) { - if (!peer_exist (peersrow.key)) { - listboxpeers.append (peersrow.value); - listpeers.add (peersrow.value); - peersrow.value.show (); - } - } - return true; - }); - listpeers.foreach ((peersrow2) => { - if (!arraypeers.has_key (peersrow2.host)) { - listpeers.remove (peersrow2); + private bool server_exist (int index) { + bool exist = false; + listserver.foreach ((servrow2) => { + if (servrow2.index == index) { + exist = true; } return true; }); - arraypeers.clear (); + return exist; } private bool peer_exist (string host) { diff --git a/src/GabutWindow.vala b/src/GabutWindow.vala index 85bf662..3047893 100644 --- a/src/GabutWindow.vala +++ b/src/GabutWindow.vala @@ -58,14 +58,14 @@ namespace Gabut { } } - DeAscending _deascend = null; - DeAscending deascend { + DeAscend _deascend; + DeAscend deascend { get { return _deascend; } set { _deascend = value; - set_dbsetting (DBSettings.ASCEDESCEN, _deascend.get_index ().to_string ()); + set_dbsetting (DBSettings.ASCEDESCEN, _deascend.to_string ()); } } @@ -490,40 +490,31 @@ namespace Gabut { } public Gtk.Popover get_menu () { - var sort_flow = new Gtk.FlowBox () { - orientation = Gtk.Orientation.HORIZONTAL, - width_request = 70, - margin_top = 4, - margin_bottom = 4 - }; - var deas_flow = new Gtk.FlowBox () { - orientation = Gtk.Orientation.HORIZONTAL, - width_request = 70 - }; + var sort_flow = new Gtk.FlowBox (); showtime = new Gtk.CheckButton.with_label (_("Time")) { - margin_start = 9, - margin_top = 4, - margin_bottom = 4, - margin_end = 4, - width_request = 130, + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER, + width_request = 140, active = bool.parse (get_dbsetting (DBSettings.SHOWTIME)) }; ((Gtk.Label) showtime.get_last_child ()).attributes = set_attribute (Pango.Weight.BOLD); ((Gtk.Label) showtime.get_last_child ()).halign = Gtk.Align.CENTER; ((Gtk.Label) showtime.get_last_child ()).wrap_mode = Pango.WrapMode.WORD_CHAR; var timeimg = new Gtk.Image () { + halign = Gtk.Align.CENTER, valign = Gtk.Align.CENTER, gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.waiting") }; - var centime = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + var centime = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER + }; centime.append (showtime); centime.append (timeimg); showdate = new Gtk.CheckButton.with_label (_("Date")) { - margin_start = 9, - margin_top = 4, - margin_bottom = 4, - margin_end = 4, - width_request = 130, + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER, + width_request = 140, active = bool.parse (get_dbsetting (DBSettings.SHOWDATE)) }; ((Gtk.Label) showdate.get_last_child ()).attributes = set_attribute (Pango.Weight.BOLD); @@ -531,38 +522,60 @@ namespace Gabut { ((Gtk.Label) showdate.get_last_child ()).wrap_mode = Pango.WrapMode.WORD_CHAR; var dateimg = new Gtk.Image () { valign = Gtk.Align.CENTER, + halign = Gtk.Align.CENTER, gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.date") }; - var cendate = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + var cendate = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER + }; cendate.append (showdate); cendate.append (dateimg); - var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { + var dsasc = new ModeTogle () { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER + }; + dsasc.add_item (new ModeTogle.with_icon_label (_("Ascending"), "com.github.gabutakut.gabutdm.down")); + dsasc.add_item (new ModeTogle.with_icon_label (_("Descending"), "com.github.gabutakut.gabutdm.up")); + var box = new Gtk.Grid () { margin_top = 4, - margin_bottom = 4 + margin_bottom = 4, + row_spacing = 4, + width_request = 150 }; - box.append (sort_flow); - box.append (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); - box.append (deas_flow); - box.append (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); - box.append (centime); - box.append (cendate); + box.attach (sort_flow, 0, 0); + box.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 1); + box.attach (dsasc, 0, 2); + box.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 3); + box.attach (centime, 0, 4); + box.attach (cendate, 0, 5); var sort_popover = new Gtk.Popover () { position = Gtk.PositionType.TOP, - width_request = 70, child = box }; + dsasc.notify["id"].connect (()=> { + sort_popover.hide (); + deascend = (DeAscend) dsasc.id; + list_box.set_sort_func ((Gtk.ListBoxSortFunc) sort_dm); + listrow.sort (sort_dm); + }); + dsasc.id = int.parse (get_dbsetting (DBSettings.ASCEDESCEN)); + deascend = (DeAscend) dsasc.id; + showdate.toggled.connect (()=> { sort_popover.hide (); ((Gtk.Label) showdate.get_last_child ()).attributes = showdate.active? color_attribute (0, 60000, 0) : set_attribute (Pango.Weight.BOLD); set_dbsetting (DBSettings.SHOWDATE, showdate.active.to_string ()); set_listheader (); }); + ((Gtk.Label) showdate.get_last_child ()).attributes = showdate.active? color_attribute (0, 60000, 0) : set_attribute (Pango.Weight.BOLD); showtime.toggled.connect (()=> { sort_popover.hide (); ((Gtk.Label) showtime.get_last_child ()).attributes = showtime.active? color_attribute (0, 60000, 0) : set_attribute (Pango.Weight.BOLD); set_dbsetting (DBSettings.SHOWTIME, showtime.active.to_string ()); set_listheader (); }); + ((Gtk.Label) showtime.get_last_child ()).attributes = showtime.active? color_attribute (0, 60000, 0) : set_attribute (Pango.Weight.BOLD); set_listheader (); foreach (var shorty in SortbyWindow.get_all ()) { sort_flow.append (new SortBy (shorty)); @@ -578,27 +591,9 @@ namespace Gabut { }); sorttype = sort_flow.get_child_at_index (int.parse (get_dbsetting (DBSettings.SORTBY))) as SortBy; ((Gtk.Label)sorttype.get_last_child ()).attributes = color_attribute (0, 60000, 0); - foreach (var deas in DeAscend.get_all ()) { - deas_flow.append (new DeAscending (deas)); - } - deas_flow.show (); - deas_flow.child_activated.connect ((deas)=> { - sort_popover.hide (); - ((DeAscending) deascend).activebtn = false; - ((Gtk.Label)deascend.get_first_child ().get_last_child ().get_prev_sibling ()).attributes = set_attribute (Pango.Weight.BOLD); - deascend = deas as DeAscending; - ((Gtk.Label)deascend.get_first_child ().get_last_child ().get_prev_sibling ()).attributes = color_attribute (0, 60000, 0); - deascend.activebtn = true; - list_box.set_sort_func ((Gtk.ListBoxSortFunc) sort_dm); - listrow.sort (sort_dm); - }); - deascend = deas_flow.get_child_at_index (int.parse (get_dbsetting (DBSettings.ASCEDESCEN))) as DeAscending; - ((Gtk.Label)deascend.get_first_child ().get_last_child ().get_prev_sibling ()).attributes = color_attribute (0, 60000, 0); - deascend.activebtn = true; sort_popover.show.connect (() => { sort_flow.select_child (sorttype); sorttype.grab_focus (); - deas_flow.unselect_child (deascend); }); return sort_popover; } @@ -821,6 +816,7 @@ namespace Gabut { } }); listrow.sort (sort_dm); + update_info (); } public void add_url_box (string url, Gee.HashMap options, bool later, int linkmode) { @@ -886,6 +882,7 @@ namespace Gabut { aria_pause (row.ariagid); } listrow.sort (sort_dm); + update_info (); } public int activedm () { @@ -902,23 +899,26 @@ namespace Gabut { private void update_info () { var infol = aria_label_info (); var activedmapp = int64.parse (infol.fetch (2)); - labelall.label = "Active: %i Download: %s Upload: %s".printf ((int)activedmapp, GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (1)) : 0), GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (6)) : 0)); - if (menulabel == 2 && indmenu) { + labelall.label = _("List: %i Active: %i Download: %s Upload: %s").printf (listrow.size, (int)activedmapp, GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (1)) : 0), GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (6)) : 0)); + if (!indmenu) { + return; + } + if (activedmapp > 0) { + if (animation % 2 == 0) { + dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.seed"; + dbusindicator.new_icon (); + } else { + dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.seedloop"; + dbusindicator.new_icon (); + } + if (animation > 9) { + animation = 0; + } + animation++; + } + if (menulabel == 2) { dbusindicator.updateLabel = " %s".printf (GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (6)) + int64.parse (infol.fetch (1)) : 0)); dbusindicator.x_ayatana_new_label (dbusindicator.updateLabel, ""); - if (activedmapp > 0) { - if (animation % 2 == 0) { - dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.seed"; - dbusindicator.new_icon (); - } else { - dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.seedloop"; - dbusindicator.new_icon (); - } - if (animation > 9) { - animation = 0; - } - animation++; - } } } diff --git a/src/ModeButton.vala b/src/ModeButton.vala index 0e7ba04..8a4e53f 100644 --- a/src/ModeButton.vala +++ b/src/ModeButton.vala @@ -41,6 +41,7 @@ namespace Gabut { public int append_text (string text) { var label = new Gtk.Label (text) { + valign = Gtk.Align.CENTER, attributes = set_attribute (Pango.Weight.ULTRABOLD) }; return appends (label); @@ -48,14 +49,15 @@ namespace Gabut { public int append_icon_text (string icon_name, string name_label) { var label = new Gtk.Label (name_label) { + valign = Gtk.Align.CENTER, attributes = set_attribute (Pango.Weight.ULTRABOLD) }; var gridn = new Gtk.Grid () { column_spacing = 4, - margin_top = 7 + valign = Gtk.Align.CENTER }; - gridn.attach (new Gtk.Image.from_icon_name (icon_name), 0, 1); - gridn.attach (label, 1, 1); + gridn.attach (new Gtk.Image.from_icon_name (icon_name), 0, 0); + gridn.attach (label, 1, 0); return appends (gridn); } diff --git a/src/ModeTogle.vala b/src/ModeTogle.vala index d9649a8..aa8452d 100755 --- a/src/ModeTogle.vala +++ b/src/ModeTogle.vala @@ -41,6 +41,28 @@ namespace Gabut { checkbtn.set_label (value); } + public ModeTogle.with_icon_label (string value, string nameico) { + var title = new Gtk.Label (value) { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER, + wrap_mode = Pango.WrapMode.WORD_CHAR, + attributes = set_attribute (Pango.Weight.BOLD), + width_request = 110 + }; + var dateimg = new Gtk.Image () { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon (nameico) + }; + var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER + }; + box.append (title); + box.append (dateimg); + checkbtn.child = box; + } + construct { orientation = Gtk.Orientation.VERTICAL; checkbtn = new Gtk.CheckButton () { @@ -76,6 +98,10 @@ namespace Gabut { } child.checkbtn.toggled.connect (()=> { if (child.checkbtn.active) { + if (child.checkbtn.get_last_child ().name == "GtkBox") { + ((Gtk.Label)menuchildren.nth_data (id).checkbtn.get_last_child ().get_first_child ()).attributes = set_attribute (Pango.Weight.BOLD); + ((Gtk.Label)child.checkbtn.get_last_child ().get_first_child ()).attributes = color_attribute (0, 60000, 0); + } id = child.id; } }); diff --git a/src/QrCode.vala b/src/QrCode.vala index 73761f5..739c385 100644 --- a/src/QrCode.vala +++ b/src/QrCode.vala @@ -157,7 +157,13 @@ namespace Gabut { string host = get_host (reboot); create_qrcode (host); linkbutton.uri = host; - linkbutton.label = host.contains ("0.0.0.0")? _("No Network Connected"): host.up (); + if (host.contains ("0.0.0.0")) { + linkbutton.label = _("No Network Connected"); + } else if (host.contains ("127.0.0.1")) { + linkbutton.label = _("Localhost"); + } else { + linkbutton.label = host.up (); + } } private void create_qrcode (string strinput) { diff --git a/src/ServerRow.vala b/src/ServerRow.vala index 5681ed5..d86e30c 100644 --- a/src/ServerRow.vala +++ b/src/ServerRow.vala @@ -24,6 +24,16 @@ namespace Gabut { private Gtk.Label download_rate; private Gtk.Label currenturi_label; + private int _index; + public int index { + get { + return _index; + } + set { + _index = value; + } + } + private string _currenturi; public string currenturi { get { diff --git a/src/Utils.vala b/src/Utils.vala index 4bd2511..e283cc0 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -1381,29 +1381,7 @@ namespace Gabut { public enum DeAscend { ASCENDING = 0, - DESCENDING = 1; - - public string to_string () { - switch (this) { - case DESCENDING: - return "Descending"; - default: - return "Ascending"; - } - } - - public string to_icon () { - switch (this) { - case DESCENDING: - return "com.github.gabutakut.gabutdm.up"; - default: - return "com.github.gabutakut.gabutdm.down"; - } - } - - public static DeAscend [] get_all () { - return { ASCENDING, DESCENDING}; - } + DESCENDING = 1 } public enum MenuItem { @@ -1823,8 +1801,8 @@ namespace Gabut { return torrentstore; } - private Gee.ArrayList aria_servers_store (string gid) { - var serverstore = new Gee.ArrayList (); + private Gee.HashMap aria_servers_store (string gid) { + var serverstore = new Gee.HashMap (); string result = get_soupmess (@"{\"jsonrpc\":\"2.0\", \"id\":\"qwer\", \"method\":\"aria2.getServers\", \"params\":[\"$(gid)\"]}"); if (!result.down ().contains ("result") || result == null) { return serverstore; @@ -1833,14 +1811,17 @@ namespace Gabut { MatchInfo match_info; Regex regex = new Regex ("{\"currentUri\":\"(.*?)\".*?\"downloadSpeed\":\"(.*?)\".*?\"uri\":\"(.*?)\""); if (regex.match_full (result, -1, 0, 0, out match_info)) { + int index = 0; while (match_info.matches ()) { var curi = match_info.fetch (1); var serverrow = new ServerRow () { + index = index, uriserver = match_info.fetch (3), downloadspeed = GLib.format_size (int64.parse (match_info.fetch (2))), currenturi = curi != null? Markup.escape_text (curi.replace ("\\/", "/")) : curi }; - serverstore.add (serverrow); + serverstore.set (index, serverrow); + index++; match_info.next (); } } @@ -2459,16 +2440,16 @@ namespace Gabut { return hlabel; } - private int sort_a (DeAscending deascending) { - if (deascending.deascend == DeAscend.ASCENDING) { + private int sort_a (DeAscend deascending) { + if (deascending == DeAscend.ASCENDING) { return 1; } else { return -1; } } - private int sort_b (DeAscending deascending) { - if (deascending.deascend == DeAscend.DESCENDING) { + private int sort_b (DeAscend deascending) { + if (deascending == DeAscend.DESCENDING) { return 1; } else { return -1; @@ -3849,20 +3830,18 @@ namespace Gabut { var themename = get_dbsetting (DBSettings.THEMECUSTOM); switch (int.parse (get_dbsetting (DBSettings.STYLE))) { case 1: + adwt_settings.color_scheme = Adw.ColorScheme.FORCE_LIGHT; if (!tdefault) { - adwt_settings.color_scheme = Adw.ColorScheme.FORCE_LIGHT; gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_application_prefer_dark_theme = false; gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } break; case 2: + adwt_settings.color_scheme = Adw.ColorScheme.FORCE_DARK; if (!tdefault) { - adwt_settings.color_scheme = Adw.ColorScheme.FORCE_DARK; gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_application_prefer_dark_theme = true; gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } break; @@ -3870,20 +3849,18 @@ namespace Gabut { PortalSettings portalsettings = yield GLib.Bus.get_proxy (GLib.BusType.SESSION, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop"); if (portalsettings != null) { themecall = gdm_theme.callback; + adwt_settings.color_scheme = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? Adw.ColorScheme.FORCE_DARK : Adw.ColorScheme.FORCE_LIGHT; if (!tdefault) { - adwt_settings.color_scheme = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? Adw.ColorScheme.FORCE_DARK : Adw.ColorScheme.FORCE_LIGHT; gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_application_prefer_dark_theme = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? true : false; gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } portalsettings.setting_changed.connect ((scheme, key, value) => { if (scheme == "org.freedesktop.appearance" && key == "color-scheme") { + adwt_settings.color_scheme = value.get_uint32 () == 1? Adw.ColorScheme.FORCE_DARK : Adw.ColorScheme.FORCE_LIGHT; if (!tdefault) { - adwt_settings.color_scheme = value.get_uint32 () == 1? Adw.ColorScheme.FORCE_DARK : Adw.ColorScheme.FORCE_LIGHT; gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_application_prefer_dark_theme = value.get_uint32 () == 1? true : false; gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } } diff --git a/src/meson.build b/src/meson.build index a2fd232..1f282b5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,7 +33,6 @@ sources = files ( 'ServerNotFound.vala', 'ServerComplete.vala', 'SortBy.vala', - 'DeAscending.vala', 'GdmOutstream.vala', 'DbusIndicator.vala', 'PeersRow.vala',