mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-03 07:03:39 +00:00
GTK UI connection manager fixes.
Auto-connecting to daemon now works. Fixes #1815. Auto-starting a `localhost` daemon now also works, the reconnecting attempts were not being "triggered". When not connected to a daemon, "Quit & Shutdown Daemon" is not present. So #1818 is also fixed. Some more work regarding #1819 was done. Client now disconnects before shutting down the GTK UI.
This commit is contained in:
parent
1be59bb116
commit
63d0d0c69b
@ -607,13 +607,15 @@ class Client(object):
|
||||
self._daemon_proxy = DaemonSSLProxy(dict(self.__event_handlers))
|
||||
self._daemon_proxy.set_disconnect_callback(self.__on_disconnect)
|
||||
d = self._daemon_proxy.connect(host, port)
|
||||
auth_deferred = defer.Deferred()
|
||||
|
||||
def on_connect_fail(reason):
|
||||
self.disconnect()
|
||||
auth_deferred.errback(reason)
|
||||
return reason
|
||||
d.addErrback(on_connect_fail)
|
||||
|
||||
if not skip_authentication:
|
||||
auth_deferred = defer.Deferred()
|
||||
|
||||
def on_authenticate(result, daemon_info):
|
||||
log.debug("Authentication sucessfull: %s", result)
|
||||
|
@ -95,11 +95,12 @@ class ConnectionManager(component.Component):
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, "ConnectionManager")
|
||||
self.gtkui_config = ConfigManager("gtkui.conf")
|
||||
self.config = self.__load_config()
|
||||
self.running = False
|
||||
|
||||
# Component overrides
|
||||
def start(self):
|
||||
self.config = self.__load_config()
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
# Close this dialog when we are shutting down
|
||||
@ -184,23 +185,22 @@ class ConnectionManager(component.Component):
|
||||
column = gtk.TreeViewColumn(_("Version"), render, text=HOSTLIST_COL_VERSION)
|
||||
self.hostlist.append_column(column)
|
||||
|
||||
# Connect the signals to the handlers
|
||||
self.glade.signal_autoconnect(self)
|
||||
|
||||
# Load any saved host entries
|
||||
self.__load_hostlist()
|
||||
self.__load_options()
|
||||
|
||||
# Select the first host if possible
|
||||
if len(self.liststore) > 0:
|
||||
self.hostlist.get_selection().select_path("0")
|
||||
|
||||
# Connect the signals to the handlers
|
||||
self.glade.signal_autoconnect(self)
|
||||
self.hostlist.get_selection().connect(
|
||||
"changed", self.on_hostlist_selection_changed
|
||||
)
|
||||
|
||||
self.__update_list()
|
||||
|
||||
self.running = True
|
||||
# Trigger the on_selection_changed code and select the first host
|
||||
# if possible
|
||||
self.hostlist.get_selection().unselect_all()
|
||||
if len(self.liststore) > 0:
|
||||
self.hostlist.get_selection().select_path("0")
|
||||
|
||||
# Run the dialog
|
||||
response = self.connection_manager.run()
|
||||
self.running = False
|
||||
|
||||
@ -361,9 +361,13 @@ class ConnectionManager(component.Component):
|
||||
"""
|
||||
Set the widgets to show the correct options from the config.
|
||||
"""
|
||||
self.glade.get_widget("chk_autoconnect").set_active(self.gtkui_config["autoconnect"])
|
||||
self.glade.get_widget("chk_autostart").set_active(self.gtkui_config["autostart_localhost"])
|
||||
self.glade.get_widget("chk_donotshow").set_active(not self.gtkui_config["show_connection_manager_on_start"])
|
||||
self.autoconnect_host_id = self.gtkui_config['autoconnect_host_id']
|
||||
self.glade.get_widget("chk_autostart").set_active(
|
||||
self.gtkui_config["autostart_localhost"]
|
||||
)
|
||||
self.glade.get_widget("chk_donotshow").set_active(
|
||||
not self.gtkui_config["show_connection_manager_on_start"]
|
||||
)
|
||||
|
||||
def __save_options(self):
|
||||
"""
|
||||
@ -385,18 +389,26 @@ class ConnectionManager(component.Component):
|
||||
self.glade.get_widget("image_startdaemon").set_from_stock(
|
||||
gtk.STOCK_EXECUTE, gtk.ICON_SIZE_MENU)
|
||||
self.glade.get_widget("label_startdaemon").set_text("_Start Daemon")
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(False)
|
||||
|
||||
model, row = self.hostlist.get_selection().get_selected()
|
||||
if not row:
|
||||
self.glade.get_widget("button_edithost").set_sensitive(False)
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(False)
|
||||
return
|
||||
|
||||
self.glade.get_widget("button_edithost").set_sensitive(True)
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(True)
|
||||
|
||||
# Get some values about the selected host
|
||||
status = model[row][HOSTLIST_COL_STATUS]
|
||||
hostid = model[row][HOSTLIST_COL_ID]
|
||||
host = model[row][HOSTLIST_COL_HOST]
|
||||
|
||||
self.glade.get_widget("chk_autoconnect").set_active(
|
||||
hostid == self.gtkui_config["autoconnect_host_id"]
|
||||
)
|
||||
|
||||
log.debug("Status: %s", status)
|
||||
# Check to see if we have a localhost entry selected
|
||||
localhost = False
|
||||
@ -700,6 +712,44 @@ class ConnectionManager(component.Component):
|
||||
def on_askpassword_dialog_entry_activate(self, entry):
|
||||
self.askpassword_dialog.response(gtk.RESPONSE_OK)
|
||||
|
||||
def on_hostlist_cursor_changed(self, widget):
|
||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||
if len(paths) < 1:
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(False)
|
||||
return
|
||||
else:
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(True)
|
||||
|
||||
hostid = self.liststore[paths[0]][HOSTLIST_COL_ID]
|
||||
self.glade.get_widget("chk_autoconnect").set_active(
|
||||
hostid == self.gtkui_config["autoconnect_host_id"]
|
||||
)
|
||||
|
||||
def on_chk_autoconnect_toggled(self, widget):
|
||||
paths = self.hostlist.get_selection().get_selected_rows()[1]
|
||||
if len(paths) < 1:
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(False)
|
||||
self.glade.get_widget("chk_autostart").set_sensitive(False)
|
||||
return
|
||||
else:
|
||||
self.glade.get_widget("chk_autoconnect").set_sensitive(True)
|
||||
|
||||
self.glade.get_widget("chk_autostart").set_sensitive(widget.get_active())
|
||||
|
||||
hostid = self.liststore[paths[0]][HOSTLIST_COL_ID]
|
||||
|
||||
if widget.get_active():
|
||||
if self.autoconnect_host_id != hostid:
|
||||
self.gtkui_config["autoconnect_host_id"] = hostid
|
||||
self.autoconnect_host_id = hostid
|
||||
self.gtkui_config.save()
|
||||
return
|
||||
|
||||
if self.autoconnect_host_id == hostid:
|
||||
self.gtkui_config["autoconnect_host_id"] = None
|
||||
self.autoconnect_host_id = None
|
||||
self.gtkui_config.save()
|
||||
|
||||
def __migrate_config_1_to_2(self, config):
|
||||
localclient_username, localclient_password = get_localhost_auth()
|
||||
if not localclient_username:
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<glade-interface>
|
||||
<!-- interface-requires gtk+ 2.6 -->
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
@ -10,7 +10,6 @@
|
||||
<property name="window_position">center</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="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>
|
||||
@ -230,7 +229,6 @@
|
||||
<property name="default_height">300</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="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>
|
||||
@ -294,6 +292,7 @@
|
||||
<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>
|
||||
<signal name="cursor_changed" handler="on_hostlist_cursor_changed"/>
|
||||
<signal name="row_activated" handler="on_hostlist_row_activated"/>
|
||||
</widget>
|
||||
</child>
|
||||
@ -470,16 +469,23 @@
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment2">
|
||||
<property name="visible">True</property>
|
||||
<property name="left_padding">15</property>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_autostart">
|
||||
<property name="label" translatable="yes">Automatically start localhost if needed</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_chk_autostart_toggled"/>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
@ -585,7 +591,6 @@
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="skip_taskbar_hint">True</property>
|
||||
<property name="has_separator">False</property>
|
||||
<child internal-child="vbox">
|
||||
<widget class="GtkVBox" id="dialog-vbox5">
|
||||
<property name="visible">True</property>
|
||||
@ -608,7 +613,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="visibility">False</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<signal name="activate" handler="on_askpassword_dialog_entry_activate"/>
|
||||
</widget>
|
||||
<packing>
|
||||
|
@ -333,28 +333,66 @@ Please see the details below for more information."), details=traceback.format_e
|
||||
# Check to see if we need to start the localhost daemon
|
||||
if self.config["autostart_localhost"] and host[1] in ("localhost", "127.0.0.1"):
|
||||
log.debug("Autostarting localhost:%s", host[2])
|
||||
try_connect = client.start_daemon(host[2], deluge.configmanager.get_config_dir())
|
||||
try_connect = client.start_daemon(
|
||||
host[2], deluge.configmanager.get_config_dir()
|
||||
)
|
||||
log.debug("Localhost started: %s", try_connect)
|
||||
if not try_connect:
|
||||
dialogs.ErrorDialog(
|
||||
_("Error Starting Daemon"),
|
||||
_("There was an error starting the daemon process. Try running it from a console to see if there is an error.")).run()
|
||||
_("There was an error starting the daemon "
|
||||
"process. Try running it from a console "
|
||||
"to see if there is an error.")
|
||||
).run()
|
||||
|
||||
# def refresh_connection_manager_list():
|
||||
# try:
|
||||
# self.connectionmanager.glade.get_widget(
|
||||
# "button_refresh"
|
||||
# ).emit("clicked")
|
||||
# except:
|
||||
# pass
|
||||
#
|
||||
# reactor.callLatter(1, refresh_connection_manager_list)
|
||||
|
||||
def update_connection_manager():
|
||||
if not self.connectionmanager.running:
|
||||
return
|
||||
self.connectionmanager.glade.get_widget(
|
||||
"button_refresh"
|
||||
).emit("clicked")
|
||||
|
||||
def close_connection_manager():
|
||||
if not self.connectionmanager.running:
|
||||
return
|
||||
self.connectionmanager.glade.get_widget(
|
||||
"button_close"
|
||||
).emit("clicked")
|
||||
|
||||
|
||||
def on_connect(connector):
|
||||
print 'ON GTK UI CONNECT!!!!\n\n'
|
||||
component.start()
|
||||
reactor.callLater(0.5, update_connection_manager)
|
||||
reactor.callLater(1, close_connection_manager)
|
||||
|
||||
def on_connect_fail(result, try_counter):
|
||||
log.error("Connection to host failed..")
|
||||
# We failed connecting to the daemon, but lets try again
|
||||
if try_counter:
|
||||
log.info("Retrying connection.. Retries left: %s", try_counter)
|
||||
log.info("Retrying connection.. Retries left: "
|
||||
"%s", try_counter)
|
||||
try_counter -= 1
|
||||
import time
|
||||
time.sleep(0.5)
|
||||
do_connect(try_counter)
|
||||
reactor.callLater(0.5, update_connection_manager)
|
||||
return result
|
||||
|
||||
def do_connect(try_counter):
|
||||
client.connect(*host[1:]).addCallback(on_connect).addErrback(on_connect_fail, try_counter)
|
||||
d = client.connect(*host[1:])
|
||||
d.addCallback(on_connect)
|
||||
d.addErrback(on_connect_fail, try_counter)
|
||||
|
||||
if try_connect:
|
||||
do_connect(6)
|
||||
|
@ -161,8 +161,20 @@ class MainWindow(component.Component):
|
||||
:type shutdown: boolean
|
||||
"""
|
||||
if shutdown:
|
||||
client.daemon.shutdown()
|
||||
def on_daemon_shutdown(result):
|
||||
reactor.stop()
|
||||
client.daemon.shutdown().addCallback(on_daemon_shutdown)
|
||||
return
|
||||
if client.is_classicmode():
|
||||
reactor.stop()
|
||||
return
|
||||
if not client.connected():
|
||||
reactor.stop()
|
||||
return
|
||||
def on_client_disconnected(result):
|
||||
reactor.stop()
|
||||
client.disconnect().addCallback(on_client_disconnected)
|
||||
|
||||
|
||||
def load_window_state(self):
|
||||
x = self.config["window_x_pos"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user