Updates to the ConnectionManager stuff. This is a work in progress.

Renamed functions.py to client.py.
This commit is contained in:
Andrew Resch 2007-10-20 16:55:38 +00:00
parent bf6a709340
commit c852cfd7c1
18 changed files with 1093 additions and 640 deletions

View File

@ -88,7 +88,7 @@ class Core(
# Setup the xmlrpc server
try:
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
self, ("localhost", 6666), logRequests=False, allow_none=True)
self, ("localhost", 58846), logRequests=False, allow_none=True)
except:
log.info("Daemon already running or port not available..")
sys.exit(0)
@ -200,6 +200,10 @@ class Core(
self.loop.quit()
# Exported Methods
def export_ping(self):
"""A method to see if the core is running"""
return True
def export_shutdown(self):
"""Shutdown the core"""
# Make shutdown an async call
@ -210,6 +214,10 @@ class Core(
sent to it."""
self.signals.register_client(uri)
def export_deregister_client(self, uri):
"""De-registers a client with the signal manager."""
self.signals.deregister_client(uri)
def export_add_torrent_file(self, filename, save_path, filedump):
"""Adds a torrent file to the libtorrent session
This requires the torrents filename and a dump of it's content

View File

@ -39,6 +39,11 @@ class SignalManager:
def __init__(self):
self.clients = []
def deregister_client(self, uri):
"""Deregisters a client"""
log.debug("Deregistering %s as a signal reciever..", uri)
self.clients.remove(self.clients.index(uri))
def register_client(self, uri):
"""Registers a client to emit signals to."""
log.debug("Registering %s as a signal reciever..", uri)

View File

@ -45,12 +45,27 @@ from deluge.log import LOG as log
class CoreProxy:
def __init__(self):
self._uri = None
self._core = None
self._on_new_core_callbacks = []
def connect_on_new_core(self, callback):
"""Connect a callback to be called when a new core is connected to."""
self._on_new_core_callbacks.append(callback)
def set_core_uri(self, uri):
log.info("Setting core uri as %s", uri)
self._uri = uri
# Get a new core
self.get_core()
def get_core(self):
if self._core is None:
if self._core is None and self._uri is not None:
log.debug("Creating ServerProxy..")
self._core = xmlrpclib.ServerProxy("http://localhost:6666")
self._core = xmlrpclib.ServerProxy(self._uri)
# Call any callbacks registered
for callback in self._on_new_core_callbacks:
callback()
return self._core
@ -69,6 +84,14 @@ def get_core_plugin(plugin):
core = dbus.Interface(proxy, "org.deluge_torrent.Deluge." + plugin)
return core
def connect_on_new_core(callback):
"""Connect a callback whenever a new core is connected to."""
return _core.connect_on_new_core(callback)
def set_core_uri(uri):
"""Sets the core uri"""
return _core.set_core_uri(uri)
def shutdown():
"""Shutdown the core daemon"""
get_core().shutdown()
@ -156,6 +179,15 @@ def get_available_plugins():
def get_enabled_plugins():
return get_core().get_enabled_plugins()
def get_download_rate():
return get_core().get_download_rate()
def get_upload_rate():
return get_core().get_upload_rate()
def get_num_connections():
return get_core().get_num_connections()
def open_url_in_browser(url):
"""Opens link in the desktop's default browser"""
def start_browser():

View File

@ -37,13 +37,13 @@ import gtk
import pkg_resources
import deluge.common
import deluge.ui.functions as functions
import deluge.ui.client as client
class AboutDialog:
def __init__(self):
# Get the glade file for the about dialog
def url_hook(dialog, url):
functions.open_url_in_browser(url)
client.open_url_in_browser(url)
gtk.about_dialog_set_url_hook(url_hook)
self.about = gtk.glade.XML(pkg_resources.resource_filename(\
"deluge.ui.gtkui", "glade/aboutdialog.glade")).get_widget(\

View File

@ -31,6 +31,169 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
class ConnectionManager:
def __init__(self):
import gtk, gtk.glade
import pkg_resources
import gobject
import socket
import deluge.xmlrpclib as xmlrpclib
import deluge.common
import deluge.ui.client as client
from deluge.configmanager import ConfigManager
from deluge.log import LOG as log
DEFAULT_CONFIG = {
"hosts": ["localhost:58846"]
}
class ConnectionManager:
def __init__(self, window):
# Get the glade file for the connection manager
self.glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/connection_manager.glade"))
self.window = window
self.config = ConfigManager("hostlist.conf", DEFAULT_CONFIG)
self.connection_manager = self.glade.get_widget("connection_manager")
self.hostlist = self.glade.get_widget("hostlist")
self.connection_manager.set_icon(deluge.common.get_logo(16))
self.glade.get_widget("image1").set_from_pixbuf(
deluge.common.get_logo(32))
self.liststore = gtk.ListStore(gtk.gdk.Pixbuf, str)
# Fill in hosts from config file
for host in self.config["hosts"]:
row = self.liststore.append()
self.liststore.set_value(row, 1, host)
# Setup host list treeview
self.hostlist.set_model(self.liststore)
render = gtk.CellRendererPixbuf()
column = gtk.TreeViewColumn("Status", render, pixbuf=0)
self.hostlist.append_column(column)
render = gtk.CellRendererText()
column = gtk.TreeViewColumn("Host", render, text=1)
self.hostlist.append_column(column)
self.glade.signal_autoconnect({
"on_button_addhost_clicked": self.on_button_addhost_clicked,
"on_button_removehost_clicked": self.on_button_removehost_clicked,
"on_button_startdaemon_clicked": \
self.on_button_startdaemon_clicked,
"on_button_cancel_clicked": self.on_button_cancel_clicked,
"on_button_connect_clicked": self.on_button_connect_clicked,
})
self.connection_manager.connect("delete-event", self.on_delete_event)
def show(self):
self.update_timer = gobject.timeout_add(5000, self.update)
self.update()
self.connection_manager.show_all()
def hide(self):
self.connection_manager.hide()
gobject.source_remove(self.update_timer)
def update(self):
"""Updates the host status"""
def update_row(model=None, path=None, row=None, columns=None):
uri = model.get_value(row, 1)
uri = "http://" + uri
online = True
host = None
try:
host = xmlrpclib.ServerProxy(uri)
host.ping()
except socket.error:
print "socket.error!"
online = False
print "online: ", online
del host
if online:
image = gtk.STOCK_YES
else:
image = gtk.STOCK_NO
pixbuf = self.connection_manager.render_icon(
image, gtk.ICON_SIZE_MENU)
model.set_value(row, 0, pixbuf)
self.liststore.foreach(update_row)
return True
def save(self):
"""Save the current host list to file"""
def append_row(model=None, path=None, row=None, columns=None):
hostlist.append(model.get_value(row, 1))
hostlist = []
self.liststore.foreach(append_row, hostlist)
self.config["hosts"] = hostlist
self.config.save()
## Callbacks
def on_delete_event(self, widget, event):
self.hide()
return True
def on_button_addhost_clicked(self, widget):
log.debug("on_button_addhost_clicked")
dialog = self.glade.get_widget("addhost_dialog")
dialog.set_icon(deluge.common.get_logo(16))
hostname_entry = self.glade.get_widget("entry_hostname")
port_spinbutton = self.glade.get_widget("spinbutton_port")
response = dialog.run()
if response == 1:
# We add the host
hostname = hostname_entry.get_text()
if hostname.startswith("http://"):
hostname = hostname[7:]
# Check to make sure the hostname is at least 1 character long
if len(hostname) < 1:
dialog.hide()
return
# Get the port and concatenate the hostname string
port = port_spinbutton.get_value_as_int()
hostname = hostname + ":" + str(port)
row = self.liststore.append()
self.liststore.set_value(row, 1, hostname)
# Save the host list to file
self.save()
dialog.hide()
def on_button_removehost_clicked(self, widget):
log.debug("on_button_removehost_clicked")
# Get the selected rows
paths = self.hostlist.get_selection().get_selected_rows()[1]
for path in paths:
self.liststore.remove(self.liststore.get_iter(path))
# Save the host list
self.save()
def on_button_startdaemon_clicked(self, widget):
log.debug("on_button_startdaemon_clicked")
def on_button_cancel_clicked(self, widget):
log.debug("on_button_cancel_clicked")
self.hide()
def on_button_connect_clicked(self, widget):
log.debug("on_button_connect_clicked")
paths = self.hostlist.get_selection().get_selected_rows()[1]
row = self.liststore.get_iter(paths[0])
uri = self.liststore.get_value(row, 1)
uri = "http://" + uri
client.set_core_uri(uri)
self.window.start()
self.hide()

View File

@ -1,14 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.0 on Mon Oct 15 00:29:12 2007 by andrew@delicious-->
<!--Generated with glade3 3.2.2 on Tue Oct 16 23:05:06 2007 by andrew@fragment-->
<glade-interface>
<widget class="GtkWindow" id="window1">
<widget class="GtkDialog" id="connection_manager">
<property name="has_focus">True</property>
<property name="is_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="title" translatable="yes">Deluge Connection Manager</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="border_width">5</property>
<property name="title" translatable="yes">Connection Manager</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="default_width">350</property>
<property name="default_height">300</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-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>
<property name="spacing">2</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
@ -29,7 +38,7 @@
<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;Deluge Connection Manager&lt;/b&gt;&lt;/big&gt;</property>
<property name="label" translatable="yes">&lt;big&gt;&lt;b&gt;Connection Manager&lt;/b&gt;&lt;/big&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
@ -41,12 +50,14 @@
<packing>
<property name="expand">False</property>
<property name="padding">5</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<widget class="GtkVBox" id="vbox3">
<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="GtkViewport" id="viewport1">
<property name="visible">True</property>
@ -60,7 +71,7 @@
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<child>
<widget class="GtkTreeView" id="treeview1">
<widget class="GtkTreeView" id="hostlist">
<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>
@ -72,87 +83,165 @@
</widget>
</child>
<child>
<widget class="GtkVButtonBox" id="vbuttonbox1">
<widget class="GtkHBox" id="hbox3">
<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_SPREAD</property>
<child>
<widget class="GtkButton" id="button3">
<widget class="GtkHButtonBox" id="hbuttonbox2">
<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_addhost">
<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="xalign">0</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_addhost_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_removehost">
<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_removehost_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_startdaemon">
<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="response_id">0</property>
<signal name="clicked" handler="on_button_startdaemon_clicked"/>
<child>
<widget class="GtkHBox" id="hbox4">
<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="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="xalign">0</property>
<property name="stock">gtk-add</property>
<property name="stock">gtk-execute</property>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label5">
<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">_Start local daemon</property>
<property name="use_underline">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">10</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button4">
<widget class="GtkExpander" id="expander1">
<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="xalign">0</property>
<child>
<widget class="GtkImage" id="image3">
<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>
<property name="xalign">0</property>
<property name="stock">gtk-remove</property>
<child>
<widget class="GtkCheckButton" id="checkbutton1">
<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">checkbutton</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</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="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area2">
<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_EDGE</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button1">
<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="button2">
<widget class="GtkButton" id="button_connect">
<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-connect</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_connect_clicked"/>
</widget>
<packing>
<property name="position">1</property>
@ -161,9 +250,125 @@
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
<widget class="GtkDialog" id="addhost_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="title" translatable="yes">Add Host</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox3">
<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="GtkHBox" id="hbox2">
<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="GtkLabel" id="label3">
<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">Hostname:</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entry_hostname">
<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>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<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">Port:</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spinbutton_port">
<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="max_length">5</property>
<property name="width_chars">5</property>
<property name="xalign">1</property>
<property name="adjustment">58846 1 65535 1 10 10</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area3">
<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_addhost_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>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_addhost_add">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_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-add</property>
<property name="use_stock">True</property>
<property name="response_id">1</property>
</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>

File diff suppressed because it is too large Load Diff

View File

@ -93,13 +93,13 @@ class GtkUI:
self.mainwindow = MainWindow()
# Start the signal receiver
self.signal_receiver = Signals(self)
#self.signal_receiver = Signals(self)
# Initalize the plugins
self.plugins = PluginManager(self)
# Start the mainwindow and show it
self.mainwindow.start()
#self.mainwindow.start()
# Start the gtk main loop
gtk.gdk.threads_init()

View File

@ -37,6 +37,7 @@ import gtk, gtk.glade
import gobject
import pkg_resources
import deluge.ui.client as client
from deluge.configmanager import ConfigManager
from menubar import MenuBar
from toolbar import ToolBar
@ -45,6 +46,7 @@ from torrentdetails import TorrentDetails
from preferences import Preferences
from systemtray import SystemTray
from statusbar import StatusBar
from connectionmanager import ConnectionManager
import deluge.common
from deluge.log import LOG as log
@ -81,15 +83,19 @@ class MainWindow:
self.preferences = Preferences(self)
self.systemtray = SystemTray(self)
self.statusbar = StatusBar(self)
def start(self):
"""Start the update thread and show the window"""
self.update_timer = gobject.timeout_add(1000, self.update)
self.connectionmanager = ConnectionManager(self)
client.connect_on_new_core(self.start)
if not(self.config["start_in_tray"] and \
self.config["enable_system_tray"]) and not \
self.window.get_property("visible"):
log.debug("Showing window")
self.show()
self.connectionmanager.show()
def start(self):
"""Start the update thread and show the window"""
self.torrentview.start()
self.update_timer = gobject.timeout_add(1000, self.update)
def update(self):
# Don't update the UI if the the window is minimized.
@ -121,7 +127,10 @@ class MainWindow:
def quit(self):
# Stop the update timer from running
try:
gobject.source_remove(self.update_timer)
except:
pass
del self.systemtray
del self.menubar
del self.toolbar

View File

@ -36,7 +36,7 @@ pygtk.require('2.0')
import gtk, gtk.glade
import pkg_resources
import deluge.ui.functions as functions
import deluge.ui.client as client
from deluge.log import LOG as log
@ -70,6 +70,8 @@ class MenuBar:
## Edit Menu
"on_menuitem_preferences_activate": \
self.on_menuitem_preferences_activate,
"on_menuitem_connectionmanager_activate": \
self.on_menuitem_connectionmanager_activate,
## View Menu
"on_menuitem_toolbar_toggled": self.on_menuitem_toolbar_toggled,
@ -97,14 +99,14 @@ class MenuBar:
def on_menuitem_addtorrent_activate(self, data=None):
log.debug("on_menuitem_addtorrent_activate")
from addtorrentdialog import AddTorrentDialog
functions.add_torrent_file(AddTorrentDialog().run())
client.add_torrent_file(AddTorrentDialog().run())
def on_menuitem_addurl_activate(self, data=None):
log.debug("on_menuitem_addurl_activate")
from addtorrenturl import AddTorrentUrl
result = AddTorrentUrl().run()
if result is not None:
functions.add_torrent_url(result)
client.add_torrent_url(result)
def on_menuitem_clear_activate(self, data=None):
log.debug("on_menuitem_clear_activate")
@ -113,7 +115,7 @@ class MenuBar:
log.debug("on_menuitem_quitdaemon_activate")
# Tell the core to shutdown
self.window.quit()
functions.shutdown()
client.shutdown()
def on_menuitem_quit_activate(self, data=None):
log.debug("on_menuitem_quit_activate")
@ -124,20 +126,24 @@ class MenuBar:
log.debug("on_menuitem_preferences_activate")
self.window.preferences.show()
def on_menuitem_connectionmanager_activate(self, data=None):
log.debug("on_menuitem_connectionmanager_activate")
self.window.connectionmanager.show()
## Torrent Menu ##
def on_menuitem_pause_activate(self, data=None):
log.debug("on_menuitem_pause_activate")
functions.pause_torrent(
client.pause_torrent(
self.window.torrentview.get_selected_torrents())
def on_menuitem_resume_activate(self, data=None):
log.debug("on_menuitem_resume_activate")
functions.resume_torrent(
client.resume_torrent(
self.window.torrentview.get_selected_torrents())
def on_menuitem_updatetracker_activate(self, data=None):
log.debug("on_menuitem_updatetracker_activate")
functions.force_reannounce(
client.force_reannounce(
self.window.torrentview.get_selected_torrents())
def on_menuitem_edittrackers_activate(self, data=None):
@ -145,7 +151,7 @@ class MenuBar:
def on_menuitem_remove_activate(self, data=None):
log.debug("on_menuitem_remove_activate")
functions.remove_torrent(
client.remove_torrent(
self.window.torrentview.get_selected_torrents())
## View Menu ##

View File

@ -32,7 +32,7 @@
# statement from all source files in the program, then also delete it here.
import deluge.pluginmanagerbase
import deluge.ui.functions as functions
import deluge.ui.client as client
from deluge.configmanager import ConfigManager
from deluge.log import LOG as log
@ -42,8 +42,13 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
self.config = ConfigManager("gtkui.conf")
self._gtkui = gtkui
# Register a callback with the client
client.connect_on_new_core(self.start)
def start(self):
"""Start the plugin manager"""
# Update the enabled_plugins from the core
enabled_plugins = functions.get_enabled_plugins()
enabled_plugins = client.get_enabled_plugins()
enabled_plugins += self.config["enabled_plugins"]
enabled_plugins = list(set(enabled_plugins))
self.config["enabled_plugins"] = enabled_plugins

View File

@ -37,7 +37,7 @@ import gtk, gtk.glade
import pkg_resources
from deluge.log import LOG as log
import deluge.ui.functions as functions
import deluge.ui.client as client
import deluge.common
from deluge.configmanager import ConfigManager
@ -51,7 +51,6 @@ class Preferences:
self.pref_dialog.set_icon(deluge.common.get_logo(32))
self.treeview = self.glade.get_widget("treeview")
self.notebook = self.glade.get_widget("notebook")
self.core = functions.get_core()
self.gtkui_config = ConfigManager("gtkui.conf")
# Setup the liststore for the categories (tab pages)
self.liststore = gtk.ListStore(int, str)
@ -104,7 +103,7 @@ class Preferences:
self.liststore.append([index, name])
def show(self):
self.core_config = functions.get_config()
self.core_config = client.get_config()
# Update the preferences dialog to reflect current config settings
## Downloads tab ##
@ -134,7 +133,7 @@ class Preferences:
self.glade.get_widget("spin_port_max").set_value(
self.core_config["listen_ports"][1])
self.glade.get_widget("active_port_label").set_text(
str(functions.get_listen_port()))
str(client.get_listen_port()))
self.glade.get_widget("chk_random_port").set_active(
self.core_config["random_port"])
self.glade.get_widget("chk_dht").set_active(
@ -193,8 +192,8 @@ class Preferences:
self.gtkui_config["send_info"])
## Plugins tab ##
all_plugins = functions.get_available_plugins()
enabled_plugins = functions.get_enabled_plugins()
all_plugins = client.get_available_plugins()
enabled_plugins = client.get_enabled_plugins()
# Clear the existing list so we don't duplicate entries.
self.plugin_liststore.clear()
# Iterate through the lists and add them to the liststore
@ -310,7 +309,7 @@ class Preferences:
config_to_set[key] = new_core_config[key]
# Set each changed config value in the core
functions.set_config(config_to_set)
client.set_config(config_to_set)
# Update the configuration
self.core_config.update(config_to_set)
@ -387,8 +386,8 @@ class Preferences:
def on_test_port_clicked(self, data):
log.debug("on_test_port_clicked")
url = "http://deluge-torrent.org/test-port.php?port=%s" % \
functions.get_listen_port()
functions.open_url_in_browser(url)
client.get_listen_port()
client.open_url_in_browser(url)
def on_plugin_toggled(self, renderer, path):
log.debug("on_plugin_toggled")

View File

@ -37,7 +37,7 @@ from deluge.log import LOG as log
class Signals:
def __init__(self, ui):
self.ui = ui
self.receiver = SignalReceiver(6667, "http://localhost:6666")
self.receiver = SignalReceiver(6667, "http://localhost:56684")
self.receiver.start()
self.receiver.connect_to_signal("torrent_added",
self.torrent_added_signal)

View File

@ -34,13 +34,12 @@
import gtk
import deluge.common
import deluge.ui.functions as functions
import deluge.ui.client as client
class StatusBar:
def __init__(self, window):
self.window = window
self.statusbar = self.window.main_glade.get_widget("statusbar")
self.core = functions.get_core()
# Add a HBox to the statusbar after removing the initial label widget
self.hbox = gtk.HBox()
@ -69,36 +68,36 @@ class StatusBar:
expand=False, fill=False)
# Update once before showing
self.update()
# self.update()
self.statusbar.show_all()
def update(self):
# Set the max connections label
max_connections = functions.get_config_value("max_connections_global")
max_connections = client.get_config_value("max_connections_global")
if max_connections < 0:
max_connections = _("Unlimited")
self.label_connections.set_text("%s (%s)" % (
self.core.get_num_connections(), max_connections))
client.get_num_connections(), max_connections))
# Set the download speed label
max_download_speed = functions.get_config_value("max_download_speed")
max_download_speed = client.get_config_value("max_download_speed")
if max_download_speed < 0:
max_download_speed = _("Unlimited")
else:
max_download_speed = "%s %s" % (max_download_speed, _("KiB/s"))
self.label_download_speed.set_text("%s/s (%s)" % (
deluge.common.fsize(self.core.get_download_rate()),
deluge.common.fsize(client.get_download_rate()),
max_download_speed))
# Set the upload speed label
max_upload_speed = functions.get_config_value("max_upload_speed")
max_upload_speed = client.get_config_value("max_upload_speed")
if max_upload_speed < 0:
max_upload_speed = _("Unlimited")
else:
max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s"))
self.label_upload_speed.set_text("%s/s (%s)" % (
deluge.common.fsize(self.core.get_upload_rate()),
deluge.common.fsize(client.get_upload_rate()),
max_upload_speed))

View File

@ -34,7 +34,7 @@
import gtk
import pkg_resources
import deluge.ui.functions as functions
import deluge.ui.client as client
import deluge.common
from deluge.configmanager import ConfigManager
from deluge.log import LOG as log
@ -49,7 +49,6 @@ class SystemTray:
def enable(self):
"""Enables the system tray icon."""
log.debug("Enabling the system tray icon..")
self.core = functions.get_core()
self.tray = gtk.status_icon_new_from_icon_name('deluge')
self.tray.connect("activate", self.on_tray_clicked)
self.tray.connect("popup-menu", self.on_tray_popup)
@ -79,6 +78,7 @@ class SystemTray:
self.tray_glade.get_widget("upload-limit-image").set_from_file(
deluge.common.get_pixmap("seeding16.png"))
def start(self):
# Build the bandwidth speed limit menus
self.build_tray_bwsetsubmenu()
@ -86,13 +86,13 @@ class SystemTray:
# Create the Download speed list sub-menu
submenu_bwdownset = self.build_menu_radio_list(
self.config["tray_download_speed_list"], self.tray_setbwdown,
functions.get_config_value("max_download_speed"),
client.get_config_value("max_download_speed"),
_("KiB/s"), show_notset=True, show_other=True)
# Create the Upload speed list sub-menu
submenu_bwupset = self.build_menu_radio_list(
self.config["tray_upload_speed_list"], self.tray_setbwup,
functions.get_config_value("max_upload_speed"),
client.get_config_value("max_upload_speed"),
_("KiB/s"), show_notset=True, show_other=True)
# Add the sub-menus to the tray menu
@ -160,7 +160,7 @@ class SystemTray:
def on_menuitem_add_torrent_activate(self, menuitem):
log.debug("on_menuitem_add_torrent_activate")
from addtorrentdialog import AddTorrentDialog
functions.add_torrent_file(AddTorrentDialog().run())
client.add_torrent_file(AddTorrentDialog().run())
def on_menuitem_pause_all_activate(self, menuitem):
log.debug("on_menuitem_pause_all_activate")
@ -184,13 +184,13 @@ class SystemTray:
log.debug("on_menuitem_quitdaemon_activate")
if self.window.visible():
self.window.quit()
functions.shutdown()
client.shutdown()
else:
if self.config["lock_tray"] == True:
self.unlock_tray("quitdaemon")
else:
self.window.quit()
functions.shutdown()
client.shutdown()
def build_menu_radio_list(self, value_list, callback, pref_value=None,
suffix=None, show_notset=False, notset_label=None, notset_lessthan=0,
@ -281,7 +281,7 @@ class SystemTray:
spin_title.set_text(_("%s Speed (KiB/s):" % string))
spin_speed = dialog_glade.get_widget("spin_speed")
spin_speed.set_value(
functions.get_config_value(core_key))
client.get_config_value(core_key))
spin_speed.select_region(0, -1)
response = speed_dialog.run()
if response == 1: # OK Response
@ -294,7 +294,7 @@ class SystemTray:
# Set the config in the core
value = float(value)
config_to_set = {core_key: value}
functions.set_config(config_to_set)
client.set_config(config_to_set)
# Update the tray speed limit list
if value not in self.config[ui_key] and value >= 0:
@ -338,7 +338,7 @@ window, please enter your password"))
log.debug("Showing main window via tray")
self.window.show()
elif comingnext == "quitdaemon":
functions.shutdown()
client.shutdown()
self.window.hide()
self.window.quit()
elif comingnext == "quitui":

View File

@ -38,7 +38,7 @@ pygtk.require('2.0')
import gtk, gtk.glade
import gettext
import deluge.ui.functions as functions
import deluge.ui.client as client
import deluge.common
from deluge.log import LOG as log
@ -93,7 +93,7 @@ class TorrentDetails:
"upload_payload_rate", "num_peers", "num_seeds", "total_peers",
"total_seeds", "eta", "ratio", "tracker", "next_announce",
"tracker_status", "save_path"]
status = functions.get_torrent_status(selected, status_keys)
status = client.get_torrent_status(selected, status_keys)
# Check to see if we got valid data from the core
if status is None:

View File

@ -40,7 +40,7 @@ import gettext
import gobject
import deluge.common
import deluge.ui.functions as functions
import deluge.ui.client as client
from deluge.log import LOG as log
import deluge.ui.gtkui.listview as listview
@ -163,9 +163,11 @@ class TorrentView(listview.ListView):
self.treeview.get_selection().connect("changed",
self.on_selection_changed)
def start(self):
"""Start the torrentview"""
# We need to get the core session state to know which torrents are in
# the session so we can add them to our list.
session_state = functions.get_session_state()
session_state = client.get_session_state()
for torrent_id in session_state:
self.add_row(torrent_id)
@ -212,7 +214,7 @@ class TorrentView(listview.ListView):
# Remove duplicates from status_key list
status_keys = list(set(status_keys))
status = functions.get_torrent_status(torrent_id,
status = client.get_torrent_status(torrent_id,
status_keys)
# Set values for each column in the row

View File

@ -48,6 +48,8 @@ class SignalReceiver(
log.debug("SignalReceiver init..")
threading.Thread.__init__(self)
self.port = port
# Daemonize the thread so it exits when the main program does
self.setDaemon(True)
@ -69,6 +71,10 @@ class SignalReceiver(
core = xmlrpclib.ServerProxy(core_uri)
core.register_client("http://localhost:" + str(port))
def __del__(self):
core.deregister_client("http://localhost:" + str(self.port))
def run(self):
"""This gets called when we start the thread"""
t = threading.Thread(target=self.serve_forever)