Skip to content

Commit

Permalink
Merge pull request #295 from torikulhabib/master
Browse files Browse the repository at this point in the history
Style Action
  • Loading branch information
torikulhabib authored Jul 28, 2024
2 parents a7b8887 + adfa8c6 commit e032c60
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 72 deletions.
12 changes: 6 additions & 6 deletions src/DownloadRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace Gabut {
if_not_exist (ariagid, linkmode, status);
}

public DownloadRow.Url (string url, Gee.HashMap<string, string> options, int linkmode, int activedm) {
public DownloadRow.Url (string url, Gee.HashMap<string, string> options, int linkmode, int activedm, bool later) {
this.hashoption = options;
this.linkmode = linkmode;
if (linkmode == LinkMode.TORRENT) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
140 changes: 100 additions & 40 deletions src/GabutWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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");
}
});
}
Expand All @@ -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;
Expand Down Expand Up @@ -976,6 +970,9 @@ namespace Gabut {
if (!indmenu) {
return;
}
if (starting || stoping || removing) {
return;
}
if (allactive > 0) {
switch (animation) {
case 1:
Expand All @@ -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 {
Expand All @@ -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)=> {
Expand All @@ -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) {
Expand Down Expand Up @@ -1179,7 +1239,7 @@ namespace Gabut {
}

public void view_status () {
if (removing) {
if (starting || stoping || removing) {
return;
}
int indexv = 0;
Expand Down
18 changes: 10 additions & 8 deletions src/PeersRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Gabut {
}
set {
_peerschoking = value;
imgpeerchok.gicon = new ThemedIcon (_peerschoking);
imgpeerchok.icon_name = _peerschoking;
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ namespace Gabut {
}
set {
_amchoking = value;
imgamchok.gicon = new ThemedIcon (_amchoking);
imgamchok.icon_name = _amchoking;
}
}
private string _bitfield;
Expand All @@ -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")
};

Expand All @@ -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")
};

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 () {
Expand Down
8 changes: 2 additions & 6 deletions src/Preferences.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/QrCode.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit e032c60

Please sign in to comment.