Fix classic mode

This commit is contained in:
Andrew Resch 2009-02-26 05:24:36 +00:00
parent cb78682415
commit d9f2daa778
7 changed files with 54 additions and 11 deletions

View File

@ -57,10 +57,6 @@ class AlertManager(component.Component):
def update(self):
self.handle_alerts()
def shutdown(self):
del self.session
del self.handlers
def register_handler(self, alert_type, handler):
"""Registers a function that will be called when 'alert_type' is pop'd
in handle_alerts. The handler function should look like:

View File

@ -28,6 +28,7 @@ import gettext
import locale
import pkg_resources
from twisted.internet import reactor
import twisted.internet.error
import deluge.component as component
import deluge.configmanager
@ -108,7 +109,10 @@ class Daemon(object):
@export()
def shutdown(self, *args, **kwargs):
component.shutdown()
reactor.stop()
try:
reactor.stop()
except twisted.internet.error.ReactorNotRunning:
log.debug("Tried to stop the reactor but it is not running..")
@export()
def info(self):

View File

@ -41,7 +41,8 @@ class EventManager(component.Component):
# Call any handlers for the event
if event.name in self.handlers:
for handler in self.handlers[event.name]:
handler(event.args)
#log.debug("Running handler %s for event %s with args: %s", event.name, handler, event.args)
handler(*event.args)
def register_event_handler(self, event, handler):
"""

View File

@ -387,7 +387,7 @@ class DaemonSSLProxy(DaemonProxy):
self.disconnect_callback = cb
class DaemonClassicProxy(DaemonProxy):
def __init__(self):
def __init__(self, event_handlers={}):
import deluge.core.daemon
self.__daemon = deluge.core.daemon.Daemon(classic=True)
log.debug("daemon created!")
@ -395,12 +395,16 @@ class DaemonClassicProxy(DaemonProxy):
self.host = "localhost"
self.port = 58846
self.user = "localclient"
# Register the event handlers
for event in event_handlers:
for handler in event_handlers[event]:
self.__daemon.core.eventmanager.register_event_handler(event, handler)
def disconnect(self):
self.__daemon = None
def call(self, method, *args, **kwargs):
log.debug("call: %s %s %s", method, args, kwargs)
#log.debug("call: %s %s %s", method, args, kwargs)
d = defer.Deferred()
try:
@ -418,6 +422,27 @@ class DaemonClassicProxy(DaemonProxy):
d.callback(result)
return d
def register_event_handler(self, event, handler):
"""
Registers a handler function to be called when `:param:event` is received
from the daemon.
:param event: str, the name of the event to handle
:param handler: function, the function to be called when `:param:event`
is emitted from the daemon
"""
self.__daemon.core.eventmanager.register_event_handler(event, handler)
def deregister_event_handler(self, event, handler):
"""
Deregisters a event handler.
:param event: str, the name of the event
:param handler: function, the function registered
"""
self.__daemon.core.eventmanager.deregister_event_handler(event, handler)
class DottedObject(object):
"""
@ -451,6 +476,7 @@ class Client(object):
def __init__(self):
self._daemon_proxy = None
self.disconnect_callback = None
self.__started_in_classic = False
def connect(self, host="127.0.0.1", port=58846, username="", password=""):
"""
@ -486,7 +512,8 @@ class Client(object):
"""
Starts a daemon in the same process as the client.
"""
self._daemon_proxy = DaemonClassicProxy()
self._daemon_proxy = DaemonClassicProxy(self.__event_handlers)
self.__started_in_classic = True
def start_daemon(self, port, config):
"""
@ -521,6 +548,15 @@ class Client(object):
return True
return False
def is_classicmode(self):
"""
Checks to see if the client has been started in classic mode.
:returns: bool, True if in classic mode
"""
return self.__started_in_classic
def connected(self):
"""
Check to see if connected to a daemon.

View File

@ -244,6 +244,7 @@ class GtkUI:
if self.config["classic_mode"]:
client.start_classic_mode()
component.start()
return
def __on_disconnect(self):

View File

@ -254,7 +254,7 @@ class MenuBar(component.Component):
def on_menuitem_quit_activate(self, data=None):
log.debug("on_menuitem_quit_activate")
if self.config["classic_mode"]:
if self.config["classic_mode"] and client.is_classicmode():
client.daemon.shutdown()
self.window.quit()

View File

@ -207,7 +207,7 @@ class TorrentView(listview.ListView, component.Component):
client.core.get_session_state().addCallback(self._on_session_state)
def _on_session_state(self, state):
log.debug("on_session_state")
log.debug("on_session_state: %s", state)
self.treeview.freeze_child_notify()
model = self.treeview.get_model()
for torrent_id in state:
@ -323,6 +323,11 @@ class TorrentView(listview.ListView, component.Component):
def add_row(self, torrent_id, update=True):
"""Adds a new torrent row to the treeview"""
# Make sure this torrent isn't already in the list
for row in self.liststore:
if row[self.columns["torrent_id"].column_indices[0]] == torrent_id:
# Row already in the list
return
# Insert a new row to the liststore
row = self.liststore.append()
# Store the torrent id