[#1859] [GTKUI] Improve layout of Remove torrent dialog

* Using Shift+Del will now pre-select removing files.
 * Will now show the name of the individual torrent being removed or the
   total count if multiple torrents selected.
This commit is contained in:
Calum Lind 2012-03-05 04:41:58 +00:00
parent 2449f5b99e
commit 739d8f329a
3 changed files with 123 additions and 150 deletions

View File

@ -5,6 +5,7 @@
<object class="GtkDialog" id="remove_torrent_dialog"> <object class="GtkDialog" id="remove_torrent_dialog">
<property name="can_focus">False</property> <property name="can_focus">False</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="modal">True</property>
<property name="window_position">center-on-parent</property> <property name="window_position">center-on-parent</property>
@ -19,7 +20,6 @@
<object class="GtkHBox" id="hbox1"> <object class="GtkHBox" id="hbox1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="spacing">10</property>
<child> <child>
<object class="GtkImage" id="image1"> <object class="GtkImage" id="image1">
<property name="visible">True</property> <property name="visible">True</property>
@ -34,42 +34,16 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property>
<child> <child>
<object class="GtkLabel" id="label_title"> <object class="GtkLabel" id="label_title">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Remove the selected torrent?</property> <property name="label" translatable="yes">Remove the selected torrent(s)?</property>
<attributes> <attributes>
<attribute name="weight" value="bold"/> <attribute name="weight" value="bold"/>
<attribute name="scale" value="1.2"/> <attribute name="scale" value="1.3"/>
</attributes> </attributes>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">If you remove the data, it will be lost permanently.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
@ -79,26 +53,55 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label_torrents">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0.05000000074505806</property>
<property name="ypad">5</property>
<property name="ellipsize">end</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="padding">5</property> <property name="position">2</property>
<property name="position">1</property> </packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator2">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing> </packing>
</child> </child>
<child internal-child="action_area"> <child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1"> <object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="layout_style">center</property> <property name="layout_style">end</property>
<child> <child>
<object class="GtkButton" id="button_cancel"> <object class="GtkButton" id="cancel_button">
<property name="label">gtk-cancel</property> <property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<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="use_action_appearance">False</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="clicked" handler="on_button_cancel_clicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -107,47 +110,13 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="button_data"> <object class="GtkButton" id="ok_button">
<property name="label">gtk-ok</property>
<property name="use_action_appearance">False</property>
<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="use_action_appearance">False</property> <property name="use_stock">True</property>
<signal name="clicked" handler="on_button_data_clicked" swapped="no"/>
<child>
<object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="stock">gtk-delete</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="button_data_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Remove With _Data</property>
<property name="use_markup">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -155,69 +124,69 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkButton" id="button_ok">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_button_ok_clicked" swapped="no"/>
<child>
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="stock">gtk-remove</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="button_ok_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Remove _Torrent</property>
<property name="use_markup">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="delete_files">
<property name="label" translatable="yes">Include downloaded files</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="focus_on_click">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_delete_files_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="warning_label">
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="xpad">4</property>
<property name="ypad">2</property>
<property name="label" translatable="yes">(This is permanent!)</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="0.90000000000000002"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">1</property>
<property name="position">5</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child> </child>
<action-widgets> <action-widgets>
<action-widget response="-6">button_cancel</action-widget> <action-widget response="0">cancel_button</action-widget>
<action-widget response="2">button_data</action-widget> <action-widget response="1">ok_button</action-widget>
<action-widget response="1">button_ok</action-widget>
</action-widgets> </action-widgets>
</object> </object>
</interface> </interface>

View File

@ -54,7 +54,7 @@ class RemoveTorrentDialog(object):
:raises ValueError: if `torrent_id` contains no torrent_ids or is None :raises ValueError: if `torrent_id` contains no torrent_ids or is None
""" """
def __init__(self, torrent_ids): def __init__(self, torrent_ids, delete_files=False):
if type(torrent_ids) != list and type(torrent_ids) != tuple: if type(torrent_ids) != list and type(torrent_ids) != tuple:
raise TypeError("requires a list of torrent_ids") raise TypeError("requires a list of torrent_ids")
@ -63,28 +63,29 @@ class RemoveTorrentDialog(object):
self.__torrent_ids = torrent_ids self.__torrent_ids = torrent_ids
builder = gtk.Builder() self.builder = gtk.Builder()
builder.add_from_file(deluge.common.resource_filename( self.builder.add_from_file(deluge.common.resource_filename(
"deluge.ui.gtkui", os.path.join("glade", "remove_torrent_dialog.ui")) "deluge.ui.gtkui", os.path.join("glade", "remove_torrent_dialog.ui"))
) )
self.__dialog = builder.get_object("remove_torrent_dialog") self.__dialog = self.builder.get_object("remove_torrent_dialog")
self.__dialog.set_transient_for(component.get("MainWindow").window) self.__dialog.set_transient_for(component.get("MainWindow").window)
self.__dialog.set_title("")
if len(self.__torrent_ids) > 1: self.builder.connect_signals({
# We need to pluralize the dialog "on_delete_files_toggled": self.on_delete_files_toggled
label_title = builder.get_object("label_title") })
button_ok = builder.get_object("button_ok_label") self.builder.get_object('delete_files').set_active(delete_files)
button_data = builder.get_object("button_data_label") label_title = self.builder.get_object("label_title")
label_torrents = self.builder.get_object("label_torrents")
num_torrents = len(self.__torrent_ids)
if num_torrents == 1:
label_torrents.set_markup(component.get("TorrentView").get_torrent_status(self.__torrent_ids[0])["name"])
else:
label_title.set_markup(_("Remove the selected torrents?"))
label_torrents.set_markup(_("Total of %s torrents selected") % num_torrents)
def pluralize_torrents(text): def on_delete_files_toggled(self, widget):
plural_torrent = _("Torrents") self.builder.get_object('warning_label').set_visible(widget.get_active())
return text.replace("torrent", plural_torrent.lower()).replace("Torrent", plural_torrent)
label_title.set_markup(pluralize_torrents(label_title.get_label()))
button_ok.set_label(pluralize_torrents(button_ok.get_label()))
button_data.set_label(pluralize_torrents(button_data.get_label()))
def __remove_torrents(self, remove_data): def __remove_torrents(self, remove_data):
# Unselect all to avoid issues with the selection changed event # Unselect all to avoid issues with the selection changed event

View File

@ -713,6 +713,9 @@ class TorrentView(listview.ListView, component.Component):
log.debug("keypress_Delete") log.debug("keypress_Delete")
torrents = self.get_selected_torrents() torrents = self.get_selected_torrents()
if torrents: if torrents:
if event.state & gtk.gdk.SHIFT_MASK:
RemoveTorrentDialog(torrents, delete_files=True).run()
else:
RemoveTorrentDialog(torrents).run() RemoveTorrentDialog(torrents).run()
def keypress_Menu(self, event): def keypress_Menu(self, event):