Queued torrents update.

This commit is contained in:
Andrew Resch 2007-11-14 15:51:22 +00:00
parent 80ef895a51
commit eac95882d4
3 changed files with 320 additions and 16 deletions

View File

@ -34,8 +34,9 @@
import sys import sys
import os import os
import gtk
import gobject
# Import DBUS # Import DBUS
#from dbus import Interface, SessionBus, version
import dbus, dbus.service import dbus, dbus.service
if dbus.version >= (0,41,0) and dbus.version < (0,80,0): if dbus.version >= (0,41,0) and dbus.version < (0,80,0):
@ -51,8 +52,9 @@ from deluge.log import LOG as log
class DbusInterface(dbus.service.Object, component.Component): class DbusInterface(dbus.service.Object, component.Component):
def __init__(self, args, path="/org/deluge_torrent/Deluge"): def __init__(self, args, path="/org/deluge_torrent/Deluge"):
component.Component.__init__(self, "DbusInterface") component.Component.__init__(self, "DbusInterface", ["StatusBar"])
self.queue = []
self.widgets = None
# Check to see if the daemon is already running and if not, start it # Check to see if the daemon is already running and if not, start it
bus = dbus.SessionBus() bus = dbus.SessionBus()
obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
@ -79,12 +81,66 @@ class DbusInterface(dbus.service.Object, component.Component):
log.debug("Exiting..") log.debug("Exiting..")
sys.exit(0) sys.exit(0)
# Process the args if any
self.process_args(args)
# Register Deluge with Dbus # Register Deluge with Dbus
log.info("Registering with DBUS..") log.info("Registering with DBUS..")
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", bus_name = dbus.service.BusName("org.deluge_torrent.Deluge",
bus=dbus.SessionBus()) bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, path) dbus.service.Object.__init__(self, bus_name, path)
def start(self):
"""Called when we connect to a host"""
log.debug("DbusInterface start..")
if len(self.queue) == 0:
return
# Make sure status bar info is showing
self.widgets = None
self.update_status_bar()
def add_to_queue(self, torrents):
"""Adds the list of torrents to the queue"""
# Add to the queue while removing duplicates
self.queue = list(set(self.queue + torrents))
# Update the status bar
self.update_status_bar()
def update_status_bar(self):
"""Attempts to update status bar"""
# If there are no queued torrents.. remove statusbar widgets and return
if len(self.queue) == 0:
if self.widgets != None:
for widget in self.widgets:
component.get("StatusBar").remove(widget)
return False
try:
statusbar = component.get("StatusBar")
except Exception, e:
# The statusbar hasn't been loaded yet, so we'll add a timer to
# update it later.
gobject.timeout_add(100, self.update_status_bar)
return False
# Set the label text for statusbar
if len(self.queue) > 1:
label = str(len(self.queue)) + _(" Torrents Queued")
else:
label = str(len(self.queue)) + _(" Torrent Queued")
# Add the statusbar items if needed, or just modify the label if they
# have already been added.
if self.widgets == None:
self.widgets = component.get("StatusBar").add_item(
stock=gtk.STOCK_SORT_DESCENDING,
text=label)
else:
self.widgets[1].set_text(label)
# We return False so the timer stops
return False
@dbus.service.method("org.deluge_torrent.Deluge", in_signature="as") @dbus.service.method("org.deluge_torrent.Deluge", in_signature="as")
def process_args(self, args): def process_args(self, args):
"""Process arguments sent to already running Deluge""" """Process arguments sent to already running Deluge"""
@ -94,9 +150,13 @@ class DbusInterface(dbus.service.Object, component.Component):
for arg in dbus_args: for arg in dbus_args:
args.append(str(arg)) args.append(str(arg))
log.debug("Processing args from other process: %s", args) log.debug("Processing args from other process: %s", args)
if not client.connected():
# We're not connected so add these to the queue
log.debug("Not connected to host.. Adding to queue.")
self.add_to_queue(args)
return
for arg in args: for arg in args:
# Check to see if we're connected to a host first
if client.connected():
if deluge.common.is_url(arg): if deluge.common.is_url(arg):
log.debug("Attempting to add %s from external source..", log.debug("Attempting to add %s from external source..",
arg) arg)

View File

@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Wed Nov 14 03:28:00 2007 -->
<glade-interface>
<widget class="GtkDialog" id="queued_torrents_dialog">
<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="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="destroy_with_parent">True</property>
<property name="icon">.</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-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">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>
<widget class="GtkHBox" id="hbox1">
<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>
<widget class="GtkImage" id="image1">
<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-add</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<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">&lt;big&gt;&lt;b&gt;Add Queued Torrents&lt;/b&gt;&lt;/big&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<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="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkTreeView" id="treeview1">
<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="headers_clickable">True</property>
</widget>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<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="layout_style">GTK_BUTTONBOX_START</property>
<child>
<widget class="GtkButton" id="button_remove">
<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" translatable="yes">gtk-remove</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_remove_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_clear">
<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" translatable="yes">gtk-clear</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_clear_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkExpander" id="expander1">
<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>
<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">11</property>
<child>
<widget class="GtkVBox" id="vbox2">
<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="GtkCheckButton" id="chk_autoadd">
<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">Automatically add torrents on connect</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</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="label" translatable="yes">Options</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<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="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button_cancel">
<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" translatable="yes">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_cancel_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_add">
<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" translatable="yes">gtk-add</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_add_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -86,10 +86,44 @@ class StatusBar(component.Component):
image = gtk.Image() image = gtk.Image()
image.set_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU) image.set_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU)
self.hbox.pack_start(image, expand=False, fill=False) self.hbox.pack_start(image, expand=False, fill=False)
label = gtk.Label("Not connected to daemon..") label = gtk.Label(_("Not Connected"))
self.hbox.pack_start(label, expand=False, fill=False) self.hbox.pack_start(label, expand=False, fill=False)
self.statusbar.show_all() self.statusbar.show_all()
def add_item(self, image=None, stock=None, text=None):
"""Adds an item to the status bar"""
# The return tuple.. we return whatever widgets we add
ret = []
# Add image from file or stock
if image != None or stock != None:
_image = gtk.Image()
if image != None:
_image.set_from_file(image)
if stock != None:
_image.set_from_stock(stock, gtk.ICON_SIZE_MENU)
self.hbox.pack_start(_image, expand=False, fill=False)
ret.append(_image)
# Add text
if text != None:
label = gtk.Label(text)
self.hbox.pack_start(label, expand=False, fill=False)
ret.append(label)
# Show the widgets
for widget in ret:
widget.show()
# Return the widgets
return tuple(ret)
def remove_item(self, widget):
"""Removes an item from the statusbar"""
try:
self.hbox.remove(widget)
except Exception, e:
log.debug("Unable to remove widget: %s", e)
def clear_statusbar(self): def clear_statusbar(self):
def remove(child): def remove(child):
self.hbox.remove(child) self.hbox.remove(child)