Rework the Remove Torrent Dialog and change client.remove_torrent() to

only having the option of removing data, not torrent file.  Deleting the 
torrent file was deleting the torrent file in the Copy Torrentfile 
folder and this is not desirable.
This commit is contained in:
Andrew Resch 2008-11-26 09:11:18 +00:00
commit c6422b53df
13 changed files with 826 additions and 969 deletions

View file

@ -432,10 +432,10 @@ class Core(
# Run the plugin hooks for 'post_torrent_add' # Run the plugin hooks for 'post_torrent_add'
self.plugins.run_post_torrent_add(torrent_id) self.plugins.run_post_torrent_add(torrent_id)
def export_remove_torrent(self, torrent_ids, remove_torrent, remove_data): def export_remove_torrent(self, torrent_ids, remove_data):
log.debug("Removing torrent %s from the core.", torrent_ids) log.debug("Removing torrent %s from the core.", torrent_ids)
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
if self.torrents.remove(torrent_id, remove_torrent, remove_data): if self.torrents.remove(torrent_id, 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)

View file

@ -421,30 +421,15 @@ class TorrentManager(component.Component):
return filedump return filedump
def remove(self, torrent_id, remove_torrent=False, remove_data=False): def remove(self, torrent_id, remove_data=False):
"""Remove a torrent from the manager""" """Remove a torrent from the manager"""
try: try:
# Remove from libtorrent session
option = 0
# Remove data if set
if remove_data:
option = 1
self.session.remove_torrent(self.torrents[torrent_id].handle, self.session.remove_torrent(self.torrents[torrent_id].handle,
option) 1 if remove_data else 0)
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 # Remove the .fastresume if it exists
self.torrents[torrent_id].delete_fastresume() self.torrents[torrent_id].delete_fastresume()

View file

@ -12,8 +12,6 @@ class Command(BaseCommand):
aliases = ['del'] aliases = ['del']
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
make_option('--remove_torrent', action='store_true', default=False,
help="remove the torrent's file"),
make_option('--remove_data', action='store_true', default=False, make_option('--remove_data', action='store_true', default=False,
help="remove the torrent's data"), help="remove the torrent's data"),
) )
@ -22,7 +20,7 @@ class Command(BaseCommand):
try: try:
args = mapping.to_ids(args) args = mapping.to_ids(args)
torrents = match_torrents(args) torrents = match_torrents(args)
client.remove_torrent(torrents, options['remove_torrent'], options['remove_data']) client.remove_torrent(torrents, options['remove_data'])
except Exception, msg: except Exception, msg:
print template.ERROR(str(msg)) print template.ERROR(str(msg))

File diff suppressed because it is too large Load diff

View file

@ -1,25 +1,21 @@
<?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 Sun Feb 17 13:32:23 2008 --> <!--Generated with glade3 3.4.5 on Wed Nov 26 00:35:55 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkDialog" id="remove_torrent_dialog"> <widget class="GtkDialog" id="remove_torrent_dialog">
<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 Torrent?</property>
<property name="resizable">False</property> <property name="resizable">False</property>
<property name="modal">True</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="destroy_with_parent">True</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property> <property name="deletable">False</property>
<child internal-child="vbox"> <child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1"> <widget class="GtkVBox" id="dialog-vbox1">
<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="spacing">2</property> <property name="spacing">2</property>
<child>
<widget class="GtkVBox" id="vbox1">
<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="spacing">5</property>
<child> <child>
<widget class="GtkHBox" id="hbox1"> <widget class="GtkHBox" id="hbox1">
<property name="visible">True</property> <property name="visible">True</property>
@ -43,7 +39,6 @@
<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;Are you sure you want to remove the selected torrent?&lt;/b&gt;&lt;/big&gt;</property> <property name="label" translatable="yes">&lt;big&gt;&lt;b&gt;Are you sure you want to remove the selected torrent?&lt;/b&gt;&lt;/big&gt;</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
<property name="wrap">True</property>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -55,104 +50,9 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator1">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</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="GtkHBox" id="hbox_torrentfile">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">5</property>
<child>
<widget class="GtkImage" id="image2">
<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="stock">gtk-dialog-warning</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_torrentfile_warning">
<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="label" translatable="yes">&lt;i&gt;The associated .torrent will be deleted!&lt;/i&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </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>
<widget class="GtkHBox" id="hbox_data">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">5</property>
<child>
<widget class="GtkImage" id="image3">
<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="stock">gtk-dialog-warning</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label_data_warning">
<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="label" translatable="yes">&lt;i&gt;The downloaded data will be deleted!&lt;/i&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">5</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area"> <child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1"> <widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property> <property name="visible">True</property>
@ -163,25 +63,38 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">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">gtk-cancel</property>
<property name="label" translatable="no">gtk-cancel</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="response_id">0</property> <property name="response_id">-6</property>
<signal name="clicked" handler="on_button_cancel_clicked"/> <signal name="clicked" handler="on_button_cancel_clicked"/>
</widget> </widget>
</child> </child>
<child>
<widget class="GtkButton" id="button_data">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">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">Remove Torrent and Data</property>
<property name="response_id">2</property>
<signal name="clicked" handler="on_button_data_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<widget class="GtkButton" id="button_ok"> <widget class="GtkButton" id="button_ok">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">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">Remove Selected Torrent</property> <property name="label" translatable="yes">Remove Torrent</property>
<property name="response_id">0</property> <property name="response_id">1</property>
<signal name="clicked" handler="on_button_ok_clicked"/> <signal name="clicked" handler="on_button_ok_clicked"/>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</widget> </widget>

View file

@ -151,6 +151,7 @@
<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">_Remove Torrent</property> <property name="label" translatable="yes">_Remove Torrent</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_remove_activate"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="menu-item-image9"> <widget class="GtkImage" id="menu-item-image9">
<property name="visible">True</property> <property name="visible">True</property>
@ -201,46 +202,6 @@
</widget> </widget>
</child> </child>
</widget> </widget>
<widget class="GtkMenu" id="remove_torrent_menu">
<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>
<child>
<widget class="GtkMenuItem" id="menuitem_remove_session">
<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="label" translatable="yes">From Session</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_remove_session_activate"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem_remove_torrentfile">
<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="label" translatable="yes">.. And Delete Torrent File</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_remove_torrentfile_activate"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem_remove_data">
<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="label" translatable="yes">.. And Delete Downloaded Files</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_remove_data_activate"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem_remove_both">
<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="label" translatable="yes">.. And Delete All Files</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menuitem_remove_both_activate"/>
</widget>
</child>
</widget>
<widget class="GtkMenu" id="options_torrent_menu"> <widget class="GtkMenu" id="options_torrent_menu">
<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>
@ -331,7 +292,7 @@
<widget class="GtkImageMenuItem" id="menuitem_queue_up"> <widget class="GtkImageMenuItem" id="menuitem_queue_up">
<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="no">gtk-go-up</property> <property name="label">gtk-go-up</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="activate" handler="on_menuitem_queue_up_activate"/> <signal name="activate" handler="on_menuitem_queue_up_activate"/>
@ -341,7 +302,7 @@
<widget class="GtkImageMenuItem" id="menuitem_queue_down"> <widget class="GtkImageMenuItem" id="menuitem_queue_down">
<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="no">gtk-go-down</property> <property name="label">gtk-go-down</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="activate" handler="on_menuitem_queue_down_activate"/> <signal name="activate" handler="on_menuitem_queue_down_activate"/>

View file

@ -49,10 +49,6 @@ class MenuBar(component.Component):
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/torrent_menu.glade")) "glade/torrent_menu.glade"))
# Attach remove torrent menu
self.torrentmenu_glade.get_widget("menuitem_remove").set_submenu(
self.torrentmenu_glade.get_widget("remove_torrent_menu"))
self.torrentmenu_glade.get_widget("menuitem_queue").set_submenu( self.torrentmenu_glade.get_widget("menuitem_queue").set_submenu(
self.torrentmenu_glade.get_widget("queue_torrent_menu")) self.torrentmenu_glade.get_widget("queue_torrent_menu"))
@ -147,15 +143,8 @@ class MenuBar(component.Component):
self.on_menuitem_updatetracker_activate, self.on_menuitem_updatetracker_activate,
"on_menuitem_edittrackers_activate": \ "on_menuitem_edittrackers_activate": \
self.on_menuitem_edittrackers_activate, self.on_menuitem_edittrackers_activate,
"on_menuitem_remove_session_activate": \ "on_menuitem_remove_activate": \
self.on_menuitem_remove_session_activate, self.on_menuitem_remove_activate,
"on_menuitem_remove_torrentfile_activate": \
self.on_menuitem_remove_torrentfile_activate,
"on_menuitem_remove_data_activate": \
self.on_menuitem_remove_data_activate,
"on_menuitem_remove_both_activate": \
self.on_menuitem_remove_both_activate,
"on_menuitem_recheck_activate": self.on_menuitem_recheck_activate, "on_menuitem_recheck_activate": self.on_menuitem_recheck_activate,
"on_menuitem_open_folder_activate": self.on_menuitem_open_folder_activate, "on_menuitem_open_folder_activate": self.on_menuitem_open_folder_activate,
"on_menuitem_move_activate": self.on_menuitem_move_activate, "on_menuitem_move_activate": self.on_menuitem_move_activate,
@ -287,33 +276,10 @@ class MenuBar(component.Component):
component.get("MainWindow").window) component.get("MainWindow").window)
dialog.run() dialog.run()
def on_menuitem_remove_session_activate(self, data=None): def on_menuitem_remove_activate(self, data=None):
log.debug("on_menuitem_remove_session_activate") log.debug("on_menuitem_remove_activate")
from removetorrentdialog import RemoveTorrentDialog from removetorrentdialog import RemoveTorrentDialog
RemoveTorrentDialog( RemoveTorrentDialog(component.get("TorrentView").get_selected_torrents()).run()
component.get("TorrentView").get_selected_torrents()).run()
def on_menuitem_remove_torrentfile_activate(self, data=None):
log.debug("on_menuitem_remove_torrentfile_activate")
from removetorrentdialog import RemoveTorrentDialog
RemoveTorrentDialog(
component.get("TorrentView").get_selected_torrents(),
remove_torrentfile=True).run()
def on_menuitem_remove_data_activate(self, data=None):
log.debug("on_menuitem_remove_data_activate")
from removetorrentdialog import RemoveTorrentDialog
RemoveTorrentDialog(
component.get("TorrentView").get_selected_torrents(),
remove_data=True).run()
def on_menuitem_remove_both_activate(self, data=None):
log.debug("on_menuitem_remove_both_activate")
from removetorrentdialog import RemoveTorrentDialog
RemoveTorrentDialog(
component.get("TorrentView").get_selected_torrents(),
remove_torrentfile=True,
remove_data=True).run()
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")

View file

@ -1,7 +1,7 @@
# #
# removetorrentdialog.py # removetorrentdialog.py
# #
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com>
# #
# Deluge is free software. # Deluge is free software.
# #
@ -22,62 +22,72 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
import gtk, gtk.glade import gtk, gtk.glade
import pkg_resources import pkg_resources
import deluge.common
from deluge.ui.client import aclient as client from deluge.ui.client import aclient as client
import deluge.component as component import deluge.component as component
from deluge.log import LOG as log from deluge.log import LOG as log
import deluge.ui.gtkui.common as common
class RemoveTorrentDialog: class RemoveTorrentDialog(object):
def __init__(self, torrent_ids, remove_torrentfile=False, remove_data=False): """
self.torrent_ids = torrent_ids This class is used to create and show a Remove Torrent Dialog.
self.remove_torrentfile = remove_torrentfile
self.remove_data = remove_data
self.glade = gtk.glade.XML( :param torrent_ids: a list of torrent_ids to remove
:raises TypeError: if :param:`torrent_id` is not a sequence type
:raises ValueError: if :param:`torrent_id` contains no torrent_ids or is None
"""
def __init__(self, torrent_ids):
if type(torrent_ids) != list and type(torrent_ids) != tuple:
raise TypeError("requires a list of torrent_ids")
if not torrent_ids:
raise ValueError("requires a list of torrent_ids")
self.__torrent_ids = torrent_ids
glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/remove_torrent_dialog.glade")) "glade/remove_torrent_dialog.glade"))
self.dialog = self.glade.get_widget("remove_torrent_dialog") self.__dialog = glade.get_widget("remove_torrent_dialog")
self.dialog.set_icon(common.get_logo(32)) self.__dialog.set_transient_for(component.get("MainWindow").window)
self.dialog.set_transient_for(component.get("MainWindow").window) self.__dialog.set_title("")
self.glade.signal_autoconnect({ if len(self.__torrent_ids) > 1:
"on_button_ok_clicked": self.on_button_ok_clicked,
"on_button_cancel_clicked": self.on_button_cancel_clicked
})
if len(self.torrent_ids) > 1:
# We need to pluralize the dialog # We need to pluralize the dialog
self.dialog.set_title("Remove Torrents?") label_title = glade.get_widget("label_title")
self.glade.get_widget("label_title").set_markup( button_ok = glade.get_widget("button_ok")
_("<big><b>Are you sure you want to remove the selected torrents?</b></big>")) button_data = glade.get_widget("button_data")
self.glade.get_widget("button_ok").set_label(_("Remove Selected Torrents"))
if self.remove_torrentfile or self.remove_data: def pluralize_torrents(text):
self.glade.get_widget("hseparator1").show() plural_torrent = _("Torrents")
if self.remove_torrentfile: return text.replace("torrent", plural_torrent.lower()).replace("Torrent", plural_torrent)
self.glade.get_widget("hbox_torrentfile").show()
if self.remove_data:
self.glade.get_widget("hbox_data").show()
def run(self): label_title.set_markup(pluralize_torrents(label_title.get_label()))
if self.torrent_ids == None or self.torrent_ids == []: button_ok.set_label(pluralize_torrents(button_ok.get_label()))
self.dialog.destroy() button_data.set_label(pluralize_torrents(button_data.get_label()))
return
self.dialog.show()
def on_button_ok_clicked(self, widget): def __remove_torrents(self, remove_data):
client.remove_torrent( client.remove_torrent(self.__torrent_ids, remove_data)
self.torrent_ids, self.remove_torrentfile, self.remove_data)
# Unselect all to avoid issues with the selection changed event # Unselect all to avoid issues with the selection changed event
component.get("TorrentView").treeview.get_selection().unselect_all() component.get("TorrentView").treeview.get_selection().unselect_all()
self.dialog.destroy()
def on_button_cancel_clicked(self, widget): def run(self):
self.dialog.destroy() """
Shows the dialog and awaits for user input. The user can select to
remove the torrent(s) from the session with or without their data.
"""
# Response IDs from the buttons
RESPONSE_SESSION = 1
RESPONSE_DATA = 2
response = self.__dialog.run()
if response == RESPONSE_SESSION:
self.__remove_torrents(False)
elif response == RESPONSE_DATA:
self.__remove_torrents(True)
self.__dialog.destroy()

View file

@ -63,11 +63,6 @@ class ToolBar(component.Component):
"toolbutton_queue_down" "toolbutton_queue_down"
] ]
# Set the Remove Torrent toolbuttons drop-down menu
tb_remove = self.window.main_glade.get_widget("toolbutton_remove")
tb_remove.set_menu(
component.get("MenuBar").torrentmenu_glade.get_widget("remove_torrent_menu"))
if self.config["classic_mode"]: if self.config["classic_mode"]:
self.window.main_glade.get_widget("toolbutton_connectionmanager").hide() self.window.main_glade.get_widget("toolbutton_connectionmanager").hide()
@ -142,7 +137,7 @@ class ToolBar(component.Component):
def on_toolbutton_remove_clicked(self, data): def on_toolbutton_remove_clicked(self, data):
log.debug("on_toolbutton_remove_clicked") log.debug("on_toolbutton_remove_clicked")
# Use the menubar's callbacks # Use the menubar's callbacks
component.get("MenuBar").on_menuitem_remove_session_activate(data) component.get("MenuBar").on_menuitem_remove_activate(data)
def on_toolbutton_pause_clicked(self, data): def on_toolbutton_pause_clicked(self, data):
log.debug("on_toolbutton_pause_clicked") log.debug("on_toolbutton_pause_clicked")

View file

@ -404,7 +404,7 @@ class CommandRemove(Command):
return return
try: try:
torrents = self.match_torrents(cmd[1:]) torrents = self.match_torrents(cmd[1:])
client.remove_torrent(torrents, False, False) client.remove_torrent(torrents, False)
except Exception, msg: except Exception, msg:
print "*** Error:", str(msg), "\n" print "*** Error:", str(msg), "\n"
@ -500,4 +500,3 @@ class NullUI:
print print
print "Thanks." print "Thanks."

View file

@ -192,7 +192,7 @@ class torrent_delete:
vars = web.input(data_also = None, torrent_also = None) vars = web.input(data_also = None, torrent_also = None)
data_also = bool(vars.data_also) data_also = bool(vars.data_also)
torrent_also = bool(vars.torrent_also) torrent_also = bool(vars.torrent_also)
proxy.remove_torrent(torrent_ids, torrent_also, data_also) proxy.remove_torrent(torrent_ids, data_also)
do_redirect() do_redirect()
route("/torrent/delete/(.*)",torrent_delete) route("/torrent/delete/(.*)",torrent_delete)
@ -487,7 +487,3 @@ class gettext:
web.header("Content-Type", "text/javascript") web.header("Content-Type", "text/javascript")
print render.gettext() print render.gettext()
route("/gettext.js", gettext) route("/gettext.js", gettext)

View file

@ -396,7 +396,7 @@ Deluge.UI = {
removeTorrent = true; removeTorrent = true;
removeFiles = true; removeFiles = true;
} }
client.remove_torrent(torrentIds, removeTorrent, removeFiles); client.remove_torrent(torrentIds, removeFiles);
break; break;
case 'preferences': case 'preferences':
this.prefsWindow.show(); this.prefsWindow.show();

View file

@ -230,7 +230,7 @@ class TestIntegration(TestWebUiBase):
#delete all, nice use case for refactoring delete.. #delete all, nice use case for refactoring delete..
torrent_ids = proxy.get_session_state() torrent_ids = proxy.get_session_state()
for torrent in torrent_ids: for torrent in torrent_ids:
proxy.remove_torrent([torrent], False, False) proxy.remove_torrent([torrent], False)
torrent_ids = proxy.get_session_state() torrent_ids = proxy.get_session_state()
self.assertEqual(torrent_ids, []) self.assertEqual(torrent_ids, [])
@ -411,4 +411,3 @@ elif False:
else: else:
unittest.main() unittest.main()