From 7c36587f235f760f276caea536a5a55cf2757d26 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 24 Jul 2007 07:19:38 +0000 Subject: [PATCH] Can now change queue order in the UI. --- deluge/core/core.py | 44 +++++++----------------- deluge/core/torrent.py | 3 ++ deluge/ui/gtkui/addtorrentdialog.py | 1 - deluge/ui/gtkui/functions.py | 28 +++++++++++++++ deluge/ui/gtkui/glade/torrent_menu.glade | 4 +-- deluge/ui/gtkui/menubar.py | 19 ++++++++-- deluge/ui/gtkui/signals.py | 7 ++++ deluge/ui/gtkui/toolbar.py | 25 ++++++++++++-- deluge/ui/gtkui/torrentview.py | 10 +++--- 9 files changed, 99 insertions(+), 42 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index f16cc91e1..07c46827d 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -188,29 +188,29 @@ class Core(dbus.service.Object): in_signature="s", out_signature="") def queue_top(self, torrent_id): # If the queue method returns True, then we should emit a signal - if self.queue.top(torrent_id): - self.torrent_queue_top() + if self.torrents.queue.top(torrent_id): + self.torrent_queue_changed() @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="s", out_signature="") def queue_up(self, torrent_id): # If the queue method returns True, then we should emit a signal - if self.queue.up(torrent_id): - self.torrent_queue_up() - + if self.torrents.queue.up(torrent_id): + self.torrent_queue_changed() + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="s", out_signature="") def queue_down(self, torrent_id): # If the queue method returns True, then we should emit a signal - if self.queue.down(torrent_id): - self.torrent_queue_down() + if self.torrents.queue.down(torrent_id): + self.torrent_queue_changed() @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="s", out_signature="") def queue_bottom(self, torrent_id): # If the queue method returns True, then we should emit a signal - if self.queue.bottom(torrent_id): - self.torrent_queue_bottom() + if self.torrents.queue.bottom(torrent_id): + self.torrent_queue_changed() # Signals @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", @@ -232,25 +232,7 @@ class Core(dbus.service.Object): log.debug("torrent_remove signal emitted") @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", - signature="s") - def torrent_queue_top(self, torrent_id): - """Emitted when a torrent is queued to the top""" - log.debug("torrent_queue_top signal emitted") - - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", - signature="s") - def torrent_queue_up(self, torrent_id): - """Emitted when a torrent is queued up""" - log.debug("torrent_queue_up signal emitted") - - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", - signature="s") - def torrent_queue_down(self, torrent_id): - """Emitted when a torrent is queued down""" - log.debug("torrent_queue_down signal emitted") - - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge", - signature="s") - def torrent_queue_bottom(self, torrent_id): - """Emitted when a torrent is queued to the bottom""" - log.debug("torrent_queue_bottom signal emitted") + signature="") + def torrent_queue_changed(self): + """Emitted when a torrent queue position is changed""" + log.debug("torrent_queue_changed signal emitted") diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 54d695e88..7b7824667 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -55,6 +55,9 @@ class Torrent: left = self.handle.status().total_wanted \ - self.handle.status().total_done + if left == 0 or self.handle.status().download_payload_rate == 0: + return 0 + try: eta = left / self.handle.status().download_payload_rate except ZeroDivisionError: diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 7cde8358e..98c294e08 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -70,7 +70,6 @@ class AddTorrentDialog: self.chooser.set_current_folder( self.config.get("default_load_path")) - def run(self): """Returns a list of selected files or None if no files were selected. """ diff --git a/deluge/ui/gtkui/functions.py b/deluge/ui/gtkui/functions.py index 5e6fb7226..7de2d515c 100644 --- a/deluge/ui/gtkui/functions.py +++ b/deluge/ui/gtkui/functions.py @@ -93,6 +93,34 @@ def remove_torrent(torrent_ids): for torrent_id in torrent_ids: core.remove_torrent(torrent_id) +def queue_top(torrent_ids): + """Attempts to queue all torrent_ids to the top""" + log.debug("Attempting to queue to top these torrents: %s", torrent_ids) + core = get_core() + for torrent_id in torrent_ids: + core.queue_top(torrent_id) + +def queue_up(torrent_ids): + """Attempts to queue all torrent_ids up""" + log.debug("Attempting to queue up these torrents: %s", torrent_ids) + core = get_core() + for torrent_id in torrent_ids: + core.queue_up(torrent_id) + +def queue_down(torrent_ids): + """Attempts to queue all torrent_ids down""" + log.debug("Attempting to queue down these torrents: %s", torrent_ids) + core = get_core() + for torrent_id in torrent_ids: + core.queue_down(torrent_id) + +def queue_bottom(torrent_ids): + """Attempts to queue all torrent_ids to the bottom""" + log.debug("Attempting to queue to bottom these torrents: %s", torrent_ids) + core = get_core() + for torrent_id in torrent_ids: + core.queue_bottom(torrent_id) + def get_torrent_status_dict(core, torrent_id): """Builds and returns a status dictionary using the status template""" status = core.get_torrent_status(torrent_id) diff --git a/deluge/ui/gtkui/glade/torrent_menu.glade b/deluge/ui/gtkui/glade/torrent_menu.glade index dc1c89d74..a14b823af 100644 --- a/deluge/ui/gtkui/glade/torrent_menu.glade +++ b/deluge/ui/gtkui/glade/torrent_menu.glade @@ -106,7 +106,7 @@ True _Up True - + True @@ -122,7 +122,7 @@ True _Down True - + True diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index 5e758a788..61bb4a8fa 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -102,10 +102,13 @@ class MenuBar: def on_menuitem_addtorrent_activate(self, data=None): log.debug("on_menuitem_addtorrent_activate") functions.add_torrent_file() + def on_menuitem_addurl_activate(self, data=None): log.debug("on_menuitem_addurl_activate") + def on_menuitem_clear_activate(self, data=None): log.debug("on_menuitem_clear_activate") + def on_menuitem_quit_activate(self, data=None): log.debug("on_menuitem_quit_activate") self.window.quit() @@ -113,36 +116,48 @@ class MenuBar: ## Edit Menu ## def on_menuitem_preferences_activate(self, data=None): log.debug("on_menuitem_preferences_activate") + def on_menuitem_plugins_activate(self, data=None): log.debug("on_menuitem_plugins_activate") ## Torrent Menu ## def on_menuitem_pause_activate(self, data=None): log.debug("on_menuitem_pause_activate") + def on_menuitem_updatetracker_activate(self, data=None): log.debug("on_menuitem_updatetracker_activate") + def on_menuitem_edittrackers_activate(self, data=None): log.debug("on_menuitem_edittrackers_activate") + def on_menuitem_remove_activate(self, data=None): log.debug("on_menuitem_remove_activate") functions.remove_torrent( self.window.torrentview.get_selected_torrents()) + def on_menuitem_queuetop_activate(self, data=None): log.debug("on_menuitem_queuetop_activate") + functions.queue_top(self.window.torrentview.get_selected_torrents()) + def on_menuitem_queueup_activate(self, data=None): log.debug("on_menuitem_queueup_activate") + functions.queue_up(self.window.torrentview.get_selected_torrents()) + def on_menuitem_queuedown_activate(self, data=None): log.debug("on_menuitem_queuedown_activate") + functions.queue_down(self.window.torrentview.get_selected_torrents()) + def on_menuitem_queuebottom_activate(self, data=None): log.debug("on_menuitem_queuebottom_activate") - + functions.queue_bottom(self.window.torrentview.get_selected_torrents()) + ## View Menu ## def on_menuitem_toolbar_toggled(self, data=None): log.debug("on_menuitem_toolbar_toggled") + def on_menuitem_infopane_toggled(self, data=None): log.debug("on_menuitem_infopane_toggled") ## Help Menu ## def on_menuitem_about_activate(self, data=None): log.debug("on_menuitem_about_activate") - diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index c1d4431d8..10c87a105 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -63,6 +63,8 @@ class Signals: self.core.connect_to_signal("torrent_added", self.torrent_added_signal) self.core.connect_to_signal("torrent_removed", self.torrent_removed_signal) + self.core.connect_to_signal("torrent_queue_changed", + self.torrent_queue_changed_signal) def torrent_added_signal(self, torrent_id): log.debug("torrent_added signal received..") @@ -75,3 +77,8 @@ class Signals: log.debug("torrent id: %s", torrent_id) # Remove the torrent from the treeview self.ui.main_window.torrentview.remove_row(torrent_id) + + def torrent_queue_changed_signal(self): + log.debug("torrent_queue_changed signal received..") + # Force an update of the torrent view + self.ui.main_window.torrentview.update() diff --git a/deluge/ui/gtkui/toolbar.py b/deluge/ui/gtkui/toolbar.py index 305f2faa4..a565c38df 100644 --- a/deluge/ui/gtkui/toolbar.py +++ b/deluge/ui/gtkui/toolbar.py @@ -66,19 +66,40 @@ class ToolBar: ### Callbacks ### def on_toolbutton_add_clicked(self, data): log.debug("on_toolbutton_add_clicked") - functions.add_torrent_file() + # Use the menubar's callback + self.window.menubar.on_menuitem_addtorrent_activate(data) + def on_toolbutton_remove_clicked(self, data): log.debug("on_toolbutton_remove_clicked") + # Use the menubar's callbacks + self.window.menubar.on_menuitem_remove_activate(data) + def on_toolbutton_clear_clicked(self, data): log.debug("on_toolbutton_clear_clicked") + # Use the menubar's callbacks + self.window.menubar.on_menuitem_clear_activate(data) + def on_toolbutton_pause_clicked(self, data): log.debug("on_toolbutton_pause_clicked") + # Use the menubar's callbacks + self.window.menubar.on_menuitem_pause_activate(data) + def on_toolbutton_queueup_clicked(self, data): log.debug("on_toolbutton_queueup_clicked") + # Use the menubar's callbacks + self.window.menubar.on_menuitem_queueup_activate(data) + def on_toolbutton_queuedown_clicked(self, data): log.debug("on_toolbutton_queuedown_clicked") + # Use the menubar's callbacks + self.window.menubar.on_menuitem_queuedown_activate(data) + def on_toolbutton_preferences_clicked(self, data): log.debug("on_toolbutton_preferences_clicked") + # Use the menubar's callbacks + self.window.menubar.on_menuitem_preferences_activate(data) + def on_toolbutton_plugins_clicked(self, data): log.debug("on_toolbutton_plugins_clicked") - + # Use the menubar's callbacks + self.window.menubar.on_menuitem_preferences_activate(data) diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index c09177da9..7c8d8b002 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -153,9 +153,9 @@ class TorrentView: def update(self): """Update the view, this is likely called by a timer""" - # Iterate through the torrent_model and update rows - row = self.torrent_model.get_iter_first() - while row is not None: + + # This function is used for the foreach method of the treemodel + def update_row(model, path, row, user_data): torrent_id = self.torrent_model.get_value(row, 0) status = functions.get_torrent_status_dict(self.core, torrent_id) # Set values for each column in the row @@ -179,7 +179,9 @@ class TorrentView: status["upload_payload_rate"]) self.torrent_model.set_value(row, TORRENT_VIEW_COL_ETA, status["eta"]) - row = self.torrent_model.iter_next(row) + + # Iterates through every row and updates them accordingly + self.torrent_model.foreach(update_row, None) def add_row(self, torrent_id): """Adds a new torrent row to the treeview"""