Add remove torrent dialog.

This commit is contained in:
Andrew Resch 2007-11-24 01:38:17 +00:00
parent ffa2066046
commit ac08425ee3
6 changed files with 82 additions and 24 deletions

1
TODO
View File

@ -13,7 +13,6 @@
* Hide open folder if not localhost * Hide open folder if not localhost
* Add classic/normal mode to preferences * Add classic/normal mode to preferences
* Implement 'Classic' mode * Implement 'Classic' mode
* Add remove torrent dialog and ability to remove data
* Tray tooltip * Tray tooltip
* Add torrentfiles location config option * Add torrentfiles location config option
* Add autoload folder * Add autoload folder

View File

@ -275,9 +275,9 @@ class Core(
# Add the torrent to session # Add the torrent to session
return self.export_add_torrent_file(filename, save_path, filedump) return self.export_add_torrent_file(filename, save_path, filedump)
def export_remove_torrent(self, torrent_id): def export_remove_torrent(self, torrent_id, remove_torrent, remove_data):
log.debug("Removing torrent %s from the core.", torrent_id) log.debug("Removing torrent %s from the core.", torrent_id)
if self.torrents.remove(torrent_id): if self.torrents.remove(torrent_id, remove_torrent, remove_data):
# Run the plugin hooks for 'post_torrent_remove' # Run the plugin hooks for 'post_torrent_remove'
self.plugins.run_post_torrent_remove(torrent_id) self.plugins.run_post_torrent_remove(torrent_id)
# Emit the torrent_removed signal # Emit the torrent_removed signal

View File

@ -250,19 +250,39 @@ class TorrentManager:
return filedump return filedump
def remove(self, torrent_id): def remove(self, torrent_id, remove_torrent, remove_data):
"""Remove a torrent from the manager""" """Remove a torrent from the manager"""
try: try:
# Remove from libtorrent session # Remove from libtorrent session
self.session.remove_torrent(self.torrents[torrent_id].handle, 0) option = 0
# Remove data if set
if remove_data:
option = 1
self.session.remove_torrent(self.torrents[torrent_id].handle,
option)
except (RuntimeError, KeyError), e: except (RuntimeError, KeyError), e:
log.warning("Error removing torrent: %s", e) log.warning("Error removing torrent: %s", e)
return False return False
# Remove the .torrent file if requested
if remove_torrent:
try:
torrent_file = os.path.join(
self.config["torrentfiles_location"],
self.torrents[torrent_id].filename)
os.remove(torrent_file)
except Exception, e:
log.warning("Unable to remove .torrent file: %s", e)
# Remove the .fastresume if it exists
self.delete_fastresume(torrent_id)
# Remove the torrent from deluge's session
try: try:
del self.torrents[torrent_id] del self.torrents[torrent_id]
except KeyError, ValueError: except KeyError, ValueError:
return False return False
# Save the session state # Save the session state
self.save_state() self.save_state()
return True return True

View File

@ -188,12 +188,12 @@ def add_torrent_url(torrent_url):
else: else:
log.warning("Invalid URL %s", torrent_url) log.warning("Invalid URL %s", torrent_url)
def remove_torrent(torrent_ids): def remove_torrent(torrent_ids, remove_torrent=False, remove_data=False):
"""Removes torrent_ids from the core.. Expects a list of torrent_ids""" """Removes torrent_ids from the core.. Expects a list of torrent_ids"""
log.debug("Attempting to removing torrents: %s", torrent_ids) log.debug("Attempting to removing torrents: %s", torrent_ids)
try: try:
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
get_core().remove_torrent(torrent_id) get_core().remove_torrent(torrent_id, remove_torrent, remove_data)
except (AttributeError, socket.error): except (AttributeError, socket.error):
set_core_uri(None) set_core_uri(None)

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Fri Nov 23 00:27:14 2007 --> <!--Generated with glade3 3.4.0 on Fri Nov 23 17:37:14 2007 -->
<glade-interface> <glade-interface>
<widget class="GtkDialog" id="remove_torrent_dialog"> <widget class="GtkDialog" id="remove_torrent_dialog">
<property name="width_request">350</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="title" translatable="yes">Remove Torrents</property> <property name="title" translatable="yes">Remove Torrent</property>
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property> <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
@ -30,7 +31,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="stock">gtk-dialog-warning</property> <property name="stock">gtk-dialog-warning</property>
<property name="icon_size">6</property> <property name="icon_size">5</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -41,7 +42,7 @@
<widget class="GtkLabel" id="label1"> <widget class="GtkLabel" id="label1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">&lt;big&gt;&lt;b&gt;Remove Torrents?&lt;/b&gt;&lt;/big&gt;</property> <property name="label" translatable="yes">&lt;big&gt;&lt;b&gt;Remove Torrent(s)?&lt;/b&gt;&lt;/big&gt;</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
</widget> </widget>
<packing> <packing>
@ -57,20 +58,55 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkCheckButton" id="chk_torrents"> <widget class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Delete .torrent files</property> </widget>
<property name="response_id">0</property> <packing>
<property name="draw_indicator">True</property> <property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="xpad">10</property>
<property name="label" translatable="yes">&lt;b&gt;Options&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="left_padding">15</property>
<child>
<widget class="GtkCheckButton" id="chk_torrents">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Delete .torrent file(s)</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="left_padding">15</property>
<child> <child>
<widget class="GtkCheckButton" id="chk_data"> <widget class="GtkCheckButton" id="chk_data">
<property name="visible">True</property> <property name="visible">True</property>
@ -80,10 +116,10 @@
<property name="response_id">0</property> <property name="response_id">0</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
</widget> </widget>
</child>
</widget>
<packing> <packing>
<property name="expand">False</property> <property name="position">4</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing> </packing>
</child> </child>
</widget> </widget>

View File

@ -191,8 +191,11 @@ class MenuBar(component.Component):
def on_menuitem_remove_activate(self, data=None): def on_menuitem_remove_activate(self, data=None):
log.debug("on_menuitem_remove_activate") log.debug("on_menuitem_remove_activate")
client.remove_torrent( from removetorrentdialog import RemoveTorrentDialog
component.get("TorrentView").get_selected_torrents()) RemoveTorrentDialog(
component.get("TorrentView").get_selected_torrents()).run()
#client.remove_torrent(
# component.get("TorrentView").get_selected_torrents())
def on_menuitem_recheck_activate(self, data=None): def on_menuitem_recheck_activate(self, data=None):
log.debug("on_menuitem_recheck_activate") log.debug("on_menuitem_recheck_activate")