Updates to ConnectionManager. Can now autostart localhost, autoconnect

and not show dialog if desired.
This commit is contained in:
Andrew Resch 2007-10-26 02:32:40 +00:00
parent 2a315def04
commit c030789e09
6 changed files with 684 additions and 564 deletions

2
TODO
View file

@ -11,3 +11,5 @@
* Restart daemon function
* Docstrings!
* Update libtorrent and bindings for sparse_mode allocation and remove_torrent options
* Implement caching in client.py
* Create a new add torrent dialog

View file

@ -131,7 +131,8 @@ def shutdown():
"""Shutdown the core daemon"""
try:
get_core().shutdown()
except (AttributeError, socket.error):
except:
# Ignore everything
set_core_uri(None)
def add_torrent_file(torrent_files):

View file

@ -67,6 +67,7 @@ class ConnectionManager(component.Component):
self.window = component.get("MainWindow")
self.config = ConfigManager("hostlist.conf", DEFAULT_CONFIG)
self.gtkui_config = ConfigManager("gtkui.conf")
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(32))
@ -98,6 +99,9 @@ class ConnectionManager(component.Component):
self.on_button_startdaemon_clicked,
"on_button_close_clicked": self.on_button_close_clicked,
"on_button_connect_clicked": self.on_button_connect_clicked,
"on_chk_autoconnect_toggled": self.on_chk_autoconnect_toggled,
"on_chk_autostart_toggled": self.on_chk_autostart_toggled,
"on_chk_donotshow_toggled": self.on_chk_donotshow_toggled
})
self.connection_manager.connect("delete-event", self.on_delete_event)
@ -106,14 +110,58 @@ class ConnectionManager(component.Component):
self.hostlist.get_selection().connect("changed",
self.on_selection_changed)
# Auto connect to a host if applicable
if self.gtkui_config["autoconnect"] and \
self.gtkui_config["autoconnect_host_uri"] != None:
uri = self.gtkui_config["autoconnect_host_uri"]
# Make sure the uri is proper
if uri[:7] != "http://":
uri = "http://" + uri
if self.test_online_status(uri):
# Host is online, so lets connect
client.set_core_uri(uri)
self.hide()
elif self.gtkui_config["autostart_localhost"]:
# Check to see if we are trying to connect to a localhost
if uri[7:].split(":")[0] == "localhost" or \
uri[7:].split(":")[0] == "127.0.0.1":
# This is a localhost, so lets try to start it
port = uri[7:].split(":")[1]
os.popen("deluged -p %s" % port)
# We need to wait for the host to start before connecting
while not self.test_online_status(uri):
sleep(10)
client.set_core_uri(uri)
self.hide()
def start(self):
if self.gtkui_config["autoconnect"]:
# We need to update the autoconnect_host_uri on connection to host
# start() gets called whenever we get a new connection to a host
self.gtkui_config["autoconnect_host_uri"] = client.get_core_uri()
def show(self):
# Set the checkbuttons according to 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"])
# Setup timer to update host status
self._update_timer = gobject.timeout_add(1000, self._update)
self._update()
self.connection_manager.show_all()
def hide(self):
self.connection_manager.hide()
gobject.source_remove(self._update_timer)
try:
gobject.source_remove(self._update_timer)
except AttributeError:
# We are probably trying to hide the window without having it showed
# first. OK to ignore.
pass
def _update(self):
"""Updates the host status"""
@ -310,9 +358,27 @@ class ConnectionManager(component.Component):
# Status is OK, so lets change to this host
client.set_core_uri(uri)
self.window.start()
self.hide()
def on_chk_autoconnect_toggled(self, widget):
log.debug("on_chk_autoconnect_toggled")
value = widget.get_active()
self.gtkui_config["autoconnect"] = value
# If we are currently connected to a host, set that as the autoconnect
# host.
if client.get_core_uri() != None:
self.gtkui_config["autoconnect_host_uri"] = client.get_core_uri()
def on_chk_autostart_toggled(self, widget):
log.debug("on_chk_autostart_toggled")
value = widget.get_active()
self.gtkui_config["autostart_localhost"] = value
def on_chk_donotshow_toggled(self, widget):
log.debug("on_chk_donotshow_toggled")
value = widget.get_active()
self.gtkui_config["show_connection_manager_on_start"] = not value
def on_selection_changed(self, treeselection):
log.debug("on_selection_changed")
self.update_buttons()

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.0 on Sat Oct 20 14:16:39 2007 by andrew@delicious-->
<!--Generated with glade3 3.2.2 on Thu Oct 25 01:07:45 2007 by andrew@fragment-->
<glade-interface>
<widget class="GtkDialog" id="connection_manager">
<property name="has_focus">True</property>
@ -99,6 +99,7 @@
<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_addhost_clicked"/>
</widget>
</child>
@ -110,6 +111,7 @@
<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>
@ -128,6 +130,7 @@
<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">
@ -181,16 +184,56 @@
<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="GtkVBox" id="vbox2">
<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="top_padding">5</property>
<property name="bottom_padding">5</property>
<property name="left_padding">5</property>
<property name="right_padding">5</property>
<child>
<widget class="GtkCheckButton" id="checkbutton1">
<widget class="GtkVBox" id="vbox2">
<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="draw_indicator">True</property>
<child>
<widget class="GtkCheckButton" id="chk_autoconnect">
<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 connect to selected host on start-up</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_chk_autoconnect_toggled"/>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="chk_autostart">
<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 start localhost if needed</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_chk_autostart_toggled"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_donotshow">
<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">Do not show this dialog on start-up</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_chk_donotshow_toggled"/>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
</widget>
</child>
</widget>
@ -224,6 +267,7 @@
<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-close</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_close_clicked"/>
</widget>
</child>
@ -235,6 +279,7 @@
<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>
@ -338,6 +383,7 @@
<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>

File diff suppressed because it is too large Load diff

View file

@ -77,7 +77,11 @@ DEFAULT_PREFS = {
"window_pane_position": -1,
"tray_download_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0],
"tray_upload_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0],
"enabled_plugins": []
"enabled_plugins": [],
"show_connection_manager_on_start": True,
"autoconnect": False,
"autoconnect_host_uri": None,
"autostart_localhost": False
}
class GtkUI:
@ -112,7 +116,6 @@ class GtkUI:
self.preferences = Preferences()
self.systemtray = SystemTray()
self.statusbar = StatusBar()
self.connectionmanager = ConnectionManager()
# Start the signal receiver
self.signal_receiver = Signals()
@ -121,7 +124,9 @@ class GtkUI:
self.plugins = PluginManager(self)
# Show the connection manager
self.connectionmanager.show()
self.connectionmanager = ConnectionManager()
if config["show_connection_manager_on_start"]:
self.connectionmanager.show()
# Start the gtk main loop
gtk.gdk.threads_init()