Skip to content

Commit

Permalink
Merge pull request #298 from torikulhabib/master
Browse files Browse the repository at this point in the history
new
  • Loading branch information
torikulhabib authored Aug 3, 2024
2 parents 5473db8 + 1140d1a commit ec1f4d9
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 84 deletions.
Binary file modified Screenshot0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace Gabut {
open_now ();
}
lastclipboard = get_dbsetting (Gabut.DBSettings.LASTCLIPBOARD);
clipboard = Gdk.Display.get_default ().get_clipboard ();
clipboard = gabutwindow.get_clipboard ();
Timeout.add_seconds (1, on_clipboard);
} else {
open_now ();
Expand Down
2 changes: 1 addition & 1 deletion src/DownloadRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Gabut {
public Gtk.Image badge_img;
public DbusmenuItem rowbus;
private bool stoptimer;
private uint timeout_id = 0;
public Gee.HashMap<string, string> hashoption = new Gee.HashMap<string, string> ();

private int _linkmode;
Expand Down Expand Up @@ -570,7 +571,6 @@ namespace Gabut {
GLib.Application.get_default ().lookup_action ("downloader").activate (new Variant.string (ariagid));
}

private uint timeout_id = 0;
private void add_timeout () {
if (timeout_id == 0) {
stoptimer = GLib.Source.CONTINUE;
Expand Down
127 changes: 72 additions & 55 deletions src/Downloader.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ namespace Gabut {
private Gtk.Stack connpeers;
private ModeButton view_mode;
private bool stoptimer;
private int loadfile = 0;
private int totalfile = 0;
private uint timeout_id = 0;

private bool _switch_rev;
public bool switch_rev {
Expand Down Expand Up @@ -187,13 +190,9 @@ namespace Gabut {
}
}

public Downloader () {
Object (resizable: false,
use_header_bar: 1
);
}

construct {
resizable = false;
use_header_bar = 1;
view_mode = new ModeButton () {
hexpand = true,
homogeneous = true,
Expand All @@ -209,14 +208,16 @@ namespace Gabut {
switch (view_mode.selected) {
case 1:
torrentmode.label = _("Mode: %s").printf (aria_tell_bittorent (ariagid, TellBittorrent.MODE));
var timesn = new GLib.DateTime.from_unix_local (int64.parse (aria_tell_bittorent (ariagid, TellBittorrent.CREATIONDATE)));
timecreation.label = _("Time Creation: %s").printf (timesn.format ("%a, %I:%M %p %x"));
var datetime = aria_tell_bittorent (ariagid, TellBittorrent.CREATIONDATE);
timecreation.label = _("Time Creation: %s").printf (datetime.strip () != ""? new GLib.DateTime.from_unix_local (int64.parse (datetime)).format ("%a, %I:%M %p %x") : "");
infotorrent.buffer.text = aria_tell_bittorent (ariagid, TellBittorrent.ANNOUNCELIST).strip ();
var commenttorrent = aria_tell_bittorent (ariagid, TellBittorrent.COMMENT);
commenttext.buffer.text = commenttorrent.contains ("\\/")? GLib.Uri.unescape_string (commenttorrent.replace ("\\/", "/")) : commenttorrent;
break;
case 2:
show_files ();
if (status != StatusMode.ACTIVE) {
show_files ();
}
break;
case 3:
down_limit.value = double.parse (aria_get_option (ariagid, AriaOptions.MAX_DOWNLOAD_LIMIT)) / 1024;
Expand Down Expand Up @@ -383,6 +384,7 @@ namespace Gabut {
};
listboxtorrent = new Gtk.ListBox ();
listtorrent = new Gee.ArrayList<TorrentRow> ();
listboxtorrent.set_sort_func ((Gtk.ListBoxSortFunc) sort_index);

var torrscrolled = new Gtk.ScrolledWindow () {
hexpand = true,
Expand Down Expand Up @@ -558,6 +560,19 @@ namespace Gabut {
});
}

[CCode (instance_pos = -1)]
private int sort_index (TorrentRow row1, TorrentRow row2) {
var total1 = row1.index;
var total2 = row2.index;
if (total1 > total2) {
return 1;
}
if (total1 < total2) {
return -1;
}
return 0;
}

public override void show () {
update_progress ();
base.show ();
Expand All @@ -567,7 +582,6 @@ namespace Gabut {
status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS));
}

private uint timeout_id = 0;
private void add_timeout () {
if (timeout_id == 0) {
stoptimer = GLib.Source.CONTINUE;
Expand Down Expand Up @@ -638,6 +652,7 @@ namespace Gabut {
}
} else if (view_mode.selected == 2) {
show_files ();
loadfile++;
}
if (switch_rev) {
if (connpeers.get_visible_child_name () == "serverconn") {
Expand Down Expand Up @@ -736,60 +751,62 @@ namespace Gabut {
}

private void show_files () {
aria_files_store (ariagid).foreach ((torrentstore) => {
if (torrentstore.filepath == "" || torrentstore.filepath == null) {
return true;
}
if (torrentstore.filepath.contains ("[METADATA]")) {
return true;
}
if (torrentstore.filebasename == null || torrentstore.filesize == null || torrentstore.completesize == null) {
return true;
}
if (!files_exist (torrentstore)) {
listtorrent.add (torrentstore);
listboxtorrent.append (torrentstore);
torrentstore.show ();
torrentstore.selecting.connect ((index, selected)=> {
var builder = new StringBuilder ();
uint hashb = builder.str.hash ();
listtorrent.foreach ((torrentrow)=> {
var selectfile = torrentrow.selected;
if (torrentrow.index == index) {
selectfile = selected;
}
if (selectfile) {
if (hashb == builder.str.hash ()) {
builder.append (torrentrow.index.to_string ());
} else {
builder.append (",");
builder.append (torrentrow.index.to_string ());
if (loadfile >= totalfile) {
var fileshow = aria_files_store (ariagid);
totalfile = fileshow.size > 100? 6 : 2;
fileshow.foreach ((torrentstore) => {
if (torrentstore.value.filepath == "" || torrentstore.value.filepath == null) {
return true;
}
if (torrentstore.value.filepath.contains ("[METADATA]")) {
return true;
}
if (torrentstore.value.filebasename == null || torrentstore.value.sizetransfered == null || torrentstore.value.completesize == null) {
return true;
}
if (!files_exist (torrentstore.key, torrentstore.value)) {
listtorrent.add (torrentstore.value);
listboxtorrent.append (torrentstore.value);
torrentstore.value.show ();
torrentstore.value.selecting.connect ((index, selected)=> {
var builder = new StringBuilder ();
uint hashb = builder.str.hash ();
listtorrent.foreach ((torrentrow)=> {
var selectfile = torrentrow.selected;
if (torrentrow.index == index) {
selectfile = selected;
}
if (selectfile) {
if (hashb == builder.str.hash ()) {
builder.append (torrentrow.index.to_string ());
} else {
builder.append (",");
builder.append (torrentrow.index.to_string ());
}
}
return true;
});
if (hashb == builder.str.hash ()) {
return;
}
return true;
string aria_gid = sendselected (ariagid, builder.str);
this.ariagid = aria_gid;
update_progress ();
});
if (hashb == builder.str.hash ()) {
return;
}
string aria_gid = sendselected (ariagid, builder.str);
this.ariagid = aria_gid;
update_progress ();
});
}
return true;
});
}
return true;
});
loadfile = 0;
}
}

private bool files_exist (TorrentRow torrentrw) {
private bool files_exist (string path, TorrentRow torrentrw) {
bool exist = false;
listtorrent.foreach ((torrentrow)=> {
if (torrentrow.filepath == torrentrw.filepath) {
if (torrentrow.filepath == path) {
exist = true;
torrentrow.index = torrentrw.index;
torrentrow.selected = torrentrw.selected;
torrentrow.filebasename = torrentrw.filebasename;
torrentrow.filesize = torrentrw.filesize;
torrentrow.completesize = torrentrw.completesize;
torrentrow.sizetransfered = torrentrw.sizetransfered;
torrentrow.fraction = torrentrw.fraction;
torrentrow.status = torrentrw.status;
torrentrow.persen = torrentrw.persen;
Expand Down
7 changes: 5 additions & 2 deletions src/GabutWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ namespace Gabut {
}

public void remove_all () {
if (starting || stoping || removing) {
return;
}
var totalsize = listrow.size;
int index = 0;
Idle.add (()=> {
Expand Down Expand Up @@ -1044,7 +1047,7 @@ namespace Gabut {
}

private void start_all () {
if (stoping) {
if (starting || stoping || removing) {
return;
}
int index = activedm ();
Expand Down Expand Up @@ -1074,7 +1077,7 @@ namespace Gabut {
}

private void stop_all () {
if (starting) {
if (starting || stoping || removing) {
return;
}
int index = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/GdmMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Gabut {

public GdmMenu (DownloadMenu downloadmenu) {
this.downloadmenu = downloadmenu;
halign = Gtk.Align.CENTER;
var title = new Gtk.Label (downloadmenu.to_string ()) {
xalign = 0,
margin_top = 6,
Expand All @@ -38,6 +37,7 @@ namespace Gabut {
};
var imgstatus = new Gtk.Image () {
valign = Gtk.Align.CENTER,
halign = Gtk.Align.START,
gicon = new ThemedIcon (downloadmenu.to_icon ())
};
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/OpenMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Gabut {

public OpenMenu (OpenMenus openmn) {
this.openmn = openmn;
halign = Gtk.Align.CENTER;
var title = new Gtk.Label (openmn.to_string ()) {
xalign = 0,
margin_top = 6,
Expand All @@ -38,6 +37,7 @@ namespace Gabut {
};
var imgstatus = new Gtk.Image () {
valign = Gtk.Align.CENTER,
halign = Gtk.Align.START,
gicon = new ThemedIcon (openmn.to_icon ())
};
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/ProgressPaint.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Gabut {
cr.set_source_rgba (0.0, 1.0, 0.0 , 1.0);
cr.arc (0, 0, width / 2.0 + 1, -GLib.Math.PI / 2, arc_end);
cr.stroke ();
cr.set_source_rgba (1.0, 0.0, 0.0, 1.0);
cr.set_source_rgba (1.0, 0.5, 0.0, 1.0);
cr.arc (0, 0, width / 2.0 + 1, arc_end, 3.0 * GLib.Math.PI / 2.0);
cr.stroke ();
}
Expand Down
Loading

0 comments on commit ec1f4d9

Please sign in to comment.