Fix classic mode
This commit is contained in:
parent
cb78682415
commit
d9f2daa778
|
@ -57,10 +57,6 @@ class AlertManager(component.Component):
|
||||||
def update(self):
|
def update(self):
|
||||||
self.handle_alerts()
|
self.handle_alerts()
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
del self.session
|
|
||||||
del self.handlers
|
|
||||||
|
|
||||||
def register_handler(self, alert_type, handler):
|
def register_handler(self, alert_type, handler):
|
||||||
"""Registers a function that will be called when 'alert_type' is pop'd
|
"""Registers a function that will be called when 'alert_type' is pop'd
|
||||||
in handle_alerts. The handler function should look like:
|
in handle_alerts. The handler function should look like:
|
||||||
|
|
|
@ -28,6 +28,7 @@ import gettext
|
||||||
import locale
|
import locale
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
import twisted.internet.error
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
|
@ -108,7 +109,10 @@ class Daemon(object):
|
||||||
@export()
|
@export()
|
||||||
def shutdown(self, *args, **kwargs):
|
def shutdown(self, *args, **kwargs):
|
||||||
component.shutdown()
|
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()
|
@export()
|
||||||
def info(self):
|
def info(self):
|
||||||
|
|
|
@ -41,7 +41,8 @@ class EventManager(component.Component):
|
||||||
# Call any handlers for the event
|
# Call any handlers for the event
|
||||||
if event.name in self.handlers:
|
if event.name in self.handlers:
|
||||||
for handler in self.handlers[event.name]:
|
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):
|
def register_event_handler(self, event, handler):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -387,7 +387,7 @@ class DaemonSSLProxy(DaemonProxy):
|
||||||
self.disconnect_callback = cb
|
self.disconnect_callback = cb
|
||||||
|
|
||||||
class DaemonClassicProxy(DaemonProxy):
|
class DaemonClassicProxy(DaemonProxy):
|
||||||
def __init__(self):
|
def __init__(self, event_handlers={}):
|
||||||
import deluge.core.daemon
|
import deluge.core.daemon
|
||||||
self.__daemon = deluge.core.daemon.Daemon(classic=True)
|
self.__daemon = deluge.core.daemon.Daemon(classic=True)
|
||||||
log.debug("daemon created!")
|
log.debug("daemon created!")
|
||||||
|
@ -395,12 +395,16 @@ class DaemonClassicProxy(DaemonProxy):
|
||||||
self.host = "localhost"
|
self.host = "localhost"
|
||||||
self.port = 58846
|
self.port = 58846
|
||||||
self.user = "localclient"
|
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):
|
def disconnect(self):
|
||||||
self.__daemon = None
|
self.__daemon = None
|
||||||
|
|
||||||
def call(self, method, *args, **kwargs):
|
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()
|
d = defer.Deferred()
|
||||||
try:
|
try:
|
||||||
|
@ -418,6 +422,27 @@ class DaemonClassicProxy(DaemonProxy):
|
||||||
d.callback(result)
|
d.callback(result)
|
||||||
return d
|
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):
|
class DottedObject(object):
|
||||||
"""
|
"""
|
||||||
|
@ -451,6 +476,7 @@ class Client(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._daemon_proxy = None
|
self._daemon_proxy = None
|
||||||
self.disconnect_callback = None
|
self.disconnect_callback = None
|
||||||
|
self.__started_in_classic = False
|
||||||
|
|
||||||
def connect(self, host="127.0.0.1", port=58846, username="", password=""):
|
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.
|
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):
|
def start_daemon(self, port, config):
|
||||||
"""
|
"""
|
||||||
|
@ -521,6 +548,15 @@ class Client(object):
|
||||||
return True
|
return True
|
||||||
return False
|
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):
|
def connected(self):
|
||||||
"""
|
"""
|
||||||
Check to see if connected to a daemon.
|
Check to see if connected to a daemon.
|
||||||
|
|
|
@ -244,6 +244,7 @@ class GtkUI:
|
||||||
|
|
||||||
if self.config["classic_mode"]:
|
if self.config["classic_mode"]:
|
||||||
client.start_classic_mode()
|
client.start_classic_mode()
|
||||||
|
component.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
def __on_disconnect(self):
|
def __on_disconnect(self):
|
||||||
|
|
|
@ -254,7 +254,7 @@ class MenuBar(component.Component):
|
||||||
|
|
||||||
def on_menuitem_quit_activate(self, data=None):
|
def on_menuitem_quit_activate(self, data=None):
|
||||||
log.debug("on_menuitem_quit_activate")
|
log.debug("on_menuitem_quit_activate")
|
||||||
if self.config["classic_mode"]:
|
if self.config["classic_mode"] and client.is_classicmode():
|
||||||
client.daemon.shutdown()
|
client.daemon.shutdown()
|
||||||
self.window.quit()
|
self.window.quit()
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
client.core.get_session_state().addCallback(self._on_session_state)
|
client.core.get_session_state().addCallback(self._on_session_state)
|
||||||
|
|
||||||
def _on_session_state(self, state):
|
def _on_session_state(self, state):
|
||||||
log.debug("on_session_state")
|
log.debug("on_session_state: %s", state)
|
||||||
self.treeview.freeze_child_notify()
|
self.treeview.freeze_child_notify()
|
||||||
model = self.treeview.get_model()
|
model = self.treeview.get_model()
|
||||||
for torrent_id in state:
|
for torrent_id in state:
|
||||||
|
@ -323,6 +323,11 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
|
|
||||||
def add_row(self, torrent_id, update=True):
|
def add_row(self, torrent_id, update=True):
|
||||||
"""Adds a new torrent row to the treeview"""
|
"""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
|
# Insert a new row to the liststore
|
||||||
row = self.liststore.append()
|
row = self.liststore.append()
|
||||||
# Store the torrent id
|
# Store the torrent id
|
||||||
|
|
Loading…
Reference in New Issue