Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to remove torrent and delete files #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public class Torrential.MainWindow : Gtk.Window {

private void build_main_interface () {
list_box = new Widgets.TorrentListBox (torrent_manager.get_torrents ());
list_box.torrent_removed.connect ((torrent) => torrent_manager.remove_torrent (torrent));
list_box.torrent_removed.connect ((torrent, delete_files) => torrent_manager.remove_torrent (torrent, delete_files));
list_box.open_torrent.connect ((id) => torrent_manager.open_torrent (id));
list_box.open_torrent_location.connect ((id) => torrent_manager.open_torrent_location (id));
list_box.link_copied.connect (on_link_copied);
Expand Down
4 changes: 2 additions & 2 deletions src/Torrent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public class Torrential.Torrent {
torrent.start ();
}

public void remove () {
torrent.remove (false, null);
public void remove (bool delete_files) {
torrent.remove (delete_files, null);
}

public Torrent (Transmission.Torrent torrent) {
Expand Down
4 changes: 2 additions & 2 deletions src/TorrentManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ public class Torrential.TorrentManager : Object {
}
}

public void remove_torrent (Torrent to_remove) {
public void remove_torrent (Torrent to_remove, bool delete_files) {
foreach (unowned Transmission.Torrent torrent in added_torrents) {
if (torrent.id == to_remove.id) {
added_torrents.remove (torrent);
break;
}
}
to_remove.remove ();
to_remove.remove (delete_files);
}

private void on_completeness_changed (Transmission.Torrent torrent, Transmission.Completeness completeness, bool wasRunning) {
Expand Down
14 changes: 11 additions & 3 deletions src/Widgets/TorrentListBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class Torrential.Widgets.TorrentListBox : Gtk.ListBox {

public signal void torrent_removed (Torrent torrent);
public signal void torrent_removed (Torrent torrent, bool delete_files);
public signal void open_torrent (int id);
public signal void open_torrent_location (int id);
public signal void link_copied ();
Expand Down Expand Up @@ -61,7 +61,7 @@ public class Torrential.Widgets.TorrentListBox : Gtk.ListBox {

private void add_row (Torrent torrent) {
var row = new TorrentListRow (torrent);
row.torrent_removed.connect ((torrent_to_remove) => torrent_removed (torrent_to_remove));
row.torrent_removed.connect ((torrent_to_remove, delete_files) => torrent_removed (torrent_to_remove, delete_files));
add (row);
}

Expand Down Expand Up @@ -108,7 +108,14 @@ public class Torrential.Widgets.TorrentListBox : Gtk.ListBox {
var remove_item = new Gtk.MenuItem.with_label (_("Remove"));
remove_item.activate.connect (() => {
foreach (var selected_row in items) {
(selected_row as TorrentListRow).remove_torrent ();
(selected_row as TorrentListRow).remove_torrent (false);
}
});

var remove_with_files_item = new Gtk.MenuItem.with_label (_("Remove and delete files"));
remove_with_files_item.activate.connect (() => {
foreach (var selected_row in items) {
(selected_row as TorrentListRow).remove_torrent (true);
}
});

Expand Down Expand Up @@ -152,6 +159,7 @@ public class Torrential.Widgets.TorrentListBox : Gtk.ListBox {
});

menu.add (remove_item);
menu.add (remove_with_files_item);
if (all_paused) {
menu.add (unpause_item);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/Widgets/TorrentListRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Torrential.Widgets.TorrentListRow : Gtk.ListBoxRow {
private const string PAUSE_ICON_NAME = "media-playback-pause-symbolic";
private const string RESUME_ICON_NAME = "media-playback-start-symbolic";

public signal void torrent_removed (Torrent torrent);
public signal void torrent_removed (Torrent torrent, bool delete_files);

public bool multi_file_torrent {
get {
Expand Down Expand Up @@ -204,8 +204,8 @@ public class Torrential.Widgets.TorrentListRow : Gtk.ListBoxRow {
}
}

public void remove_torrent () {
torrent_removed (torrent);
public void remove_torrent (bool delete_files) {
torrent_removed (torrent, delete_files);
destroy ();
}

Expand Down