diff --git a/deluge/plugins/queue/queue/gtkui.py b/deluge/plugins/queue/queue/gtkui.py index 0fb08b0ee..31cba2b50 100644 --- a/deluge/plugins/queue/queue/gtkui.py +++ b/deluge/plugins/queue/queue/gtkui.py @@ -58,6 +58,11 @@ class GtkUI: proxy = bus.get_object("org.deluge_torrent.Deluge", "/org/deluge_torrent/Plugin/Queue") self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge.Queue") + + # Connect to the 'torrent_queue_changed' signal + self.core.connect_to_signal("torrent_queue_changed", + self.torrent_queue_changed_signal) + # Get the torrentview component from the plugin manager self.torrentview = self.plugin.get_torrentview() # Add the '#' column at the first position @@ -65,7 +70,41 @@ class GtkUI: col_type=int, position=0, get_function=self.column_get_function) + # Add a toolbar buttons + self.plugin.get_toolbar().add_separator() + self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-up", + label="Queue Up", + tooltip="Queue selected torrents up", + callback=self.on_queueup_toolbutton_clicked) + + self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-down", + label="Queue Down", + tooltip="Queue selected torrents down", + callback=self.on_queuedown_toolbutton_clicked) + + def on_queuedown_toolbutton_clicked(self, widget): + log.debug("Queue down toolbutton clicked.") + # Get the selected torrents + torrent_ids = self.plugin.get_selected_torrents() + for torrent_id in torrent_ids: + self.core.queue_down(torrent_id) + return + + def on_queueup_toolbutton_clicked(self, widget): + log.debug("Queue Up toolbutton clicked.") + # Get the selected torrents + torrent_ids = self.plugin.get_selected_torrents() + for torrent_id in torrent_ids: + self.core.queue_up(torrent_id) + return + def torrent_queue_changed_signal(self): + """This function is called whenever we receive a 'torrent_queue_changed' + signal from the core plugin. + """ + log.debug("torrent_queue_changed signal received..") + return + def column_get_function(self, torrent_id): """Returns the queue position for torrent_id""" # Return the value + 1 because we want the queue list to start at 1 diff --git a/deluge/ui/functions.py b/deluge/ui/functions.py index 089585ea5..b755fea60 100644 --- a/deluge/ui/functions.py +++ b/deluge/ui/functions.py @@ -112,34 +112,6 @@ def resume_torrent(torrent_ids): for torrent_id in torrent_ids: core.resume_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_plugin("Queue") - 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_info(core, torrent_id): """Builds the info dictionary and returns it""" info = core.get_torrent_info(torrent_id) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 1c9738f0c..b8af8878a 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -124,6 +124,7 @@ class ListView: def set_treeview(self, treeview_widget): self.treeview = treeview_widget + self.treeview.set_model(self.liststore) return def get_column_index(self, name): diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 527d0cd12..7c19954e3 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.py @@ -70,3 +70,11 @@ class PluginManager: def get_torrentview(self): """Returns a reference to the torrentview component""" return self._gtkui.mainwindow.torrentview + + def get_toolbar(self): + """Returns a reference to the toolbar component""" + return self._gtkui.mainwindow.toolbar + + def get_selected_torrents(self): + """Returns a list of the selected torrent_ids""" + return self._gtkui.mainwindow.torrentview.get_selected_torrents() diff --git a/deluge/ui/gtkui/toolbar.py b/deluge/ui/gtkui/toolbar.py index 872046119..65ae7683e 100644 --- a/deluge/ui/gtkui/toolbar.py +++ b/deluge/ui/gtkui/toolbar.py @@ -44,7 +44,7 @@ class ToolBar: def __init__(self, window): log.debug("ToolBar Init..") self.window = window - + self.toolbar = self.window.main_glade.get_widget("toolbar") ### Connect Signals ### self.window.main_glade.signal_autoconnect({ "on_toolbutton_add_clicked": self.on_toolbutton_add_clicked, @@ -52,15 +52,43 @@ class ToolBar: "on_toolbutton_clear_clicked": self.on_toolbutton_clear_clicked, "on_toolbutton_pause_clicked": self.on_toolbutton_pause_clicked, "on_toolbutton_resume_clicked": self.on_toolbutton_resume_clicked, - "on_toolbutton_queueup_clicked": \ - self.on_toolbutton_queueup_clicked, - "on_toolbutton_queuedown_clicked": \ - self.on_toolbutton_queuedown_clicked, "on_toolbutton_preferences_clicked": \ self.on_toolbutton_preferences_clicked, "on_toolbutton_plugins_clicked": \ self.on_toolbutton_plugins_clicked, }) + + def add_toolbutton(self, callback, label=None, image=None, stock=None, + tooltip=None): + """Adds a toolbutton to the toolbar""" + # Create the button + toolbutton = gtk.ToolButton(stock) + if label is not None: + toolbutton.set_label(label) + if image is not None: + toolbutton.set_icon_widget(image) + # Set the tooltip + if tooltip is not None: + tip = gtk.Tooltips() + tip.set_tip(toolbutton, tooltip) + + # Connect the 'clicked' event callback + toolbutton.connect("clicked", callback) + + # Append the button to the toolbar + self.toolbar.insert(toolbutton, -1) + + return + + def add_separator(self, position=None): + """Adds a separator toolitem""" + sep = gtk.SeparatorToolItem() + if position is not None: + self.toolbar.insert(sep, position) + else: + # Append the separator + self.toolbar.insert(sep, -1) + return ### Callbacks ### def on_toolbutton_add_clicked(self, data): @@ -88,16 +116,6 @@ class ToolBar: # Use the menubar's calbacks self.window.menubar.on_menuitem_resume_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 diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index f2863bcdf..0c5cc189b 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -47,14 +47,14 @@ log = logging.getLogger("deluge") class TorrentView(listview.ListView): def __init__(self, window): - # Call the ListView constructor - listview.ListView.__init__(self) - log.debug("TorrentView Init..") self.window = window + # Call the ListView constructor + listview.ListView.__init__(self, + self.window.main_glade.get_widget("torrent_view")) + log.debug("TorrentView Init..") self.core = functions.get_core() - # Set the treeview used in listview with the one from our glade file - self.set_treeview(self.window.main_glade.get_widget("torrent_view")) - + + # Add the columns to the listview self.add_text_column("torrent_id", hidden=True) self.add_texticon_column("Name") self.add_func_column("Size",