From adfa8c6da2480627b9c44533dd2552ffa4c25cac Mon Sep 17 00:00:00 2001 From: Torikul Date: Mon, 29 Jul 2024 00:45:34 +0700 Subject: [PATCH] Style Action --- src/DownloadRow.vala | 12 ++-- src/GabutWindow.vala | 140 ++++++++++++++++++++++++++++++------------ src/PeersRow.vala | 18 +++--- src/Preferences.vala | 8 +-- src/QrCode.vala | 8 +-- src/SuccesDialog.vala | 8 +-- 6 files changed, 122 insertions(+), 72 deletions(-) diff --git a/src/DownloadRow.vala b/src/DownloadRow.vala index d1d9fb8..a8e2355 100644 --- a/src/DownloadRow.vala +++ b/src/DownloadRow.vala @@ -324,7 +324,7 @@ namespace Gabut { if_not_exist (ariagid, linkmode, status); } - public DownloadRow.Url (string url, Gee.HashMap options, int linkmode, int activedm) { + public DownloadRow.Url (string url, Gee.HashMap options, int linkmode, int activedm, bool later) { this.hashoption = options; this.linkmode = linkmode; if (linkmode == LinkMode.TORRENT) { @@ -337,7 +337,11 @@ namespace Gabut { this.url = url; add_db_download (this); set_dboptions (url, hashoption); - idle_progress (); + Idle.add (()=> { + update_progress (); + start_notif (later); + return GLib.Source.REMOVE; + }); } construct { @@ -467,10 +471,6 @@ namespace Gabut { }); } - public void idle_progress () { - Idle.add (()=> { update_progress (); return GLib.Source.REMOVE;}); - } - private void action_dowload () { status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); if (status == StatusMode.ACTIVE) { diff --git a/src/GabutWindow.vala b/src/GabutWindow.vala index dbadce9..f505b72 100644 --- a/src/GabutWindow.vala +++ b/src/GabutWindow.vala @@ -54,6 +54,8 @@ namespace Gabut { private int64 totalfiles = 0; private int64 totalrecv = 0; private bool removing = false; + private bool starting = false; + private bool stoping = false; SortBy _sorttype = null; SortBy sorttype { @@ -132,13 +134,9 @@ namespace Gabut { } } - public GabutWindow ( ) { - Object (hide_on_close: bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)), - title: _("Gabut Download Manager") - ); - } - construct { + hide_on_close = bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)); + title = _("Gabut Download Manager"); dbmenu = bool.parse (get_dbsetting (DBSettings.DBUSMENU)); dbusserver = new CanonicalDbusmenu (); dbusindicator = new DbusIndicator (dbusserver.dbus_object); @@ -228,6 +226,7 @@ namespace Gabut { var scrolled = new Gtk.ScrolledWindow () { height_request = 350, width_request = 650, + overlay_scrolling = true, vexpand = true, child = list_box }; @@ -742,10 +741,6 @@ namespace Gabut { set_progress_visible.begin (0.0, false); set_count_visible.begin (globalactive); update_info (); - if (indmenu) { - dbusindicator.updateiconame = "com.github.gabutakut.gabutdm"; - dbusindicator.new_icon (); - } stoped--; return stoped != 0; }); @@ -844,31 +839,29 @@ namespace Gabut { public void remove_all () { var totalsize = listrow.size; - int count = 0; + int index = 0; Idle.add (()=> { - count++; + index++; if (listrow.size > 0) { removing = true; - labelview.label = _("Removing... (%i of %i)").printf (count, totalsize); + labelview.label = _("Removing… (%i of %i)").printf (index, totalsize); + indicatorstatus (); listrow.get (0).remove_down (); } else { removing = false; + update_info (); + aria_purge_all (); view_status (); } return removing; }); - aria_purge_all (); - view_status (); } public void load_dowanload () { get_download ().foreach ((row)=> { if (!get_exist (row.url)) { - list_box.append (row); - listrow.add (row); - row.show (); - row.notify_property ("status"); on_append (row); + row.notify_property ("status"); } }); } @@ -877,28 +870,29 @@ namespace Gabut { if (get_exist (url)) { return; } - var row = new DownloadRow.Url (url, options, linkmode, activedm ()) { + var row = new DownloadRow.Url (url, options, linkmode, activedm (), later) { timeadded = new GLib.DateTime.now_local ().to_unix () }; - list_box.append (row); - listrow.add (row); - row.show (); on_append (row); if (!later) { row.download (); } else { aria_pause (row.ariagid); } - row.start_notif (later); } private void on_append (DownloadRow row) { + list_box.append (row); + listrow.add (row); + row.show (); row.notify["status"].connect (()=> { switch (row.status) { case StatusMode.PAUSED: case StatusMode.COMPLETE: case StatusMode.ERROR: - next_download (); + if (!starting && !stoping) { + next_download (); + } stop_launcher (); remove_dbus.begin (row.rowbus); break; @@ -976,6 +970,9 @@ namespace Gabut { if (!indmenu) { return; } + if (starting || stoping || removing) { + return; + } if (allactive > 0) { switch (animation) { case 1: @@ -995,8 +992,10 @@ namespace Gabut { animation++; break; } - dbusindicator.new_icon (); + } else { + dbusindicator.updateiconame = "com.github.gabutakut.gabutdm"; } + dbusindicator.new_icon (); if (_menulabel == 0) { dbusindicator.updateLabel = ""; } else { @@ -1009,6 +1008,19 @@ namespace Gabut { dbusindicator.x_ayatana_new_label (dbusindicator.updateLabel, ""); } + private void indicatorstatus () { + dbusindicator.updateLabel = labelview.label; + dbusindicator.x_ayatana_new_label (dbusindicator.updateLabel, ""); + if (starting) { + dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.active"; + } else if (stoping) { + dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.pause"; + } else { + dbusindicator.updateiconame = "com.github.gabutakut.gabutdm.clear"; + } + dbusindicator.new_icon (); + } + private bool get_exist (string url) { bool linkexist = false; listrow.foreach ((row)=> { @@ -1020,29 +1032,77 @@ namespace Gabut { return linkexist; } - private void start_all () { - int index = 0; + public int beforest () { + int count = 0; listrow.foreach ((row)=> { if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { - aria_position (row.ariagid, index++); - aria_unpause (row.ariagid); - row.update_progress (); + count++; } return true; }); - view_status (); + return count; + } + + private void start_all () { + if (stoping) { + return; + } + int index = activedm (); + int onstr = beforest (); + int count = 0; + Idle.add (()=> { + if (listrow.size > 0) { + starting = true; + var row = listrow.get (count); + if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { + aria_position (row.ariagid, index); + aria_unpause (row.ariagid); + row.update_progress (); + index++; + labelview.label = _("Starting… (%i of %i)").printf (index, onstr); + indicatorstatus (); + } + count++; + } + if (listrow.size == count) { + starting = false; + update_info (); + view_status (); + } + return starting; + }); } private void stop_all () { - listrow.foreach ((row)=> { - if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { - aria_pause (row.ariagid); - row.idle_progress (); + if (starting) { + return; + } + int index = 0; + int count = 0; + int acti = activedm (); + Idle.add (()=> { + if (listrow.size > 0) { + stoping = true; + var row = listrow.get (index); + if (row.status != StatusMode.COMPLETE && row.status != StatusMode.ERROR) { + aria_pause (row.ariagid); + row.update_progress (); + count++; + if (acti > 0 && count <= acti) { + labelview.label = _("Stoping… (%i of %i)").printf (count, acti); + indicatorstatus (); + } + } + index++; + } + if (listrow.size == index) { + stoping = false; + update_info (); + aria_pause_all (); + view_status (); } - return true; + return stoping; }); - aria_pause_all (); - view_status (); } public string set_selected (string ariagid, string selected) { @@ -1179,7 +1239,7 @@ namespace Gabut { } public void view_status () { - if (removing) { + if (starting || stoping || removing) { return; } int indexv = 0; diff --git a/src/PeersRow.vala b/src/PeersRow.vala index 8d5fd2f..d72723d 100644 --- a/src/PeersRow.vala +++ b/src/PeersRow.vala @@ -47,7 +47,7 @@ namespace Gabut { } set { _peerschoking = value; - imgpeerchok.gicon = new ThemedIcon (_peerschoking); + imgpeerchok.icon_name = _peerschoking; } } @@ -102,7 +102,7 @@ namespace Gabut { } set { _amchoking = value; - imgamchok.gicon = new ThemedIcon (_amchoking); + imgamchok.icon_name = _amchoking; } } private string _bitfield; @@ -121,7 +121,7 @@ namespace Gabut { }; var host_id = new Gtk.Image () { valign = Gtk.Align.CENTER, - gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.gohome"), + icon_name = "com.github.gabutakut.gabutdm.gohome", tooltip_text = _("Host") }; @@ -134,7 +134,7 @@ namespace Gabut { }; var peer_id = new Gtk.Image () { valign = Gtk.Align.CENTER, - gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.client"), + icon_name = "com.github.gabutakut.gabutdm.client", tooltip_text = _("Client") }; @@ -147,7 +147,7 @@ namespace Gabut { }; var label_download = new Gtk.Image () { valign = Gtk.Align.CENTER, - gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.down"), + icon_name = "com.github.gabutakut.gabutdm.down", tooltip_text = _("Download Speed") }; download_rate = new Gtk.Label (null) { @@ -159,7 +159,7 @@ namespace Gabut { }; var label_upload = new Gtk.Image () { valign = Gtk.Align.CENTER, - gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.up"), + icon_name = "com.github.gabutakut.gabutdm.up", tooltip_text = _("Upload Speed") }; upload_rate = new Gtk.Label (null) { @@ -171,11 +171,13 @@ namespace Gabut { }; imgamchok = new Gtk.Image () { - valign = Gtk.Align.CENTER + valign = Gtk.Align.CENTER, + tooltip_text = _("GDM Choking") }; imgpeerchok = new Gtk.Image () { - valign = Gtk.Align.CENTER + valign = Gtk.Align.CENTER, + tooltip_text = _("Peer Choking") }; var grid = new Gtk.Grid () { diff --git a/src/Preferences.vala b/src/Preferences.vala index 68816e0..5db077f 100644 --- a/src/Preferences.vala +++ b/src/Preferences.vala @@ -90,13 +90,9 @@ namespace Gabut { } } - public Preferences () { - Object (resizable: false, - use_header_bar: 1 - ); - } - construct { + resizable = false; + use_header_bar = 1; var view_mode = new ModeButton () { hexpand = false, homogeneous = true, diff --git a/src/QrCode.vala b/src/QrCode.vala index b237cc7..2dd1a1e 100644 --- a/src/QrCode.vala +++ b/src/QrCode.vala @@ -28,13 +28,9 @@ namespace Gabut { private Gtk.Button host_button; private bool local_server; - public QrCode () { - Object (resizable: false, - use_header_bar: 1 - ); - } - construct { + resizable = false; + use_header_bar = 1; var icon_image = new Gtk.Image () { valign = Gtk.Align.START, halign = Gtk.Align.END, diff --git a/src/SuccesDialog.vala b/src/SuccesDialog.vala index 3d2276c..c0374a3 100644 --- a/src/SuccesDialog.vala +++ b/src/SuccesDialog.vala @@ -27,13 +27,9 @@ namespace Gabut { private MediaEntry directory; public string datastr; - public SuccesDialog ( ) { - Object (resizable: false, - use_header_bar: 1 - ); - } - construct { + resizable = false; + use_header_bar = 1; icon_image = new Gtk.Image () { valign = Gtk.Align.START, halign = Gtk.Align.END,