From b46562d93295aa0e7828d2623b35223e132de328 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Fri, 30 Apr 2010 14:04:15 +0100 Subject: [PATCH] disable the webui plugin settings and display an error message when deluge-web is missing --- deluge/plugins/webui/webui/core.py | 23 ++++++++++++++++++----- deluge/plugins/webui/webui/gtkui.py | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/deluge/plugins/webui/webui/core.py b/deluge/plugins/webui/webui/core.py index 8311962a7..9ad4abd4e 100644 --- a/deluge/plugins/webui/webui/core.py +++ b/deluge/plugins/webui/webui/core.py @@ -43,8 +43,6 @@ from deluge.log import LOG as log from deluge.plugins.pluginbase import CorePluginBase from deluge.core.rpcserver import export -from deluge.ui.web import server - DEFAULT_PREFS = { "enabled": False, "ssl": False, @@ -75,14 +73,29 @@ class Core(CorePluginBase): def on_stop(self, *args): self.start() + + @export + def got_deluge_web(self): + try: + from deluge.ui.web import server + return True + except ImportError: + return False @export def start(self): if not self.server: + try: + from deluge.ui.web import server + except ImportError: + return False + self.server = server.DelugeWeb() + self.server.port = self.config["port"] self.server.https = self.config["ssl"] self.server.start(False) + return True @export def stop(self): @@ -107,11 +120,11 @@ class Core(CorePluginBase): self.config.save() if action == 'start': - self.start() + return self.start() elif action == 'stop': - self.stop() + return self.stop() elif action == 'restart': - self.restart() + return self.restart() @export def get_config(self): diff --git a/deluge/plugins/webui/webui/gtkui.py b/deluge/plugins/webui/webui/gtkui.py index 1be861c07..fc45eee42 100644 --- a/deluge/plugins/webui/webui/gtkui.py +++ b/deluge/plugins/webui/webui/gtkui.py @@ -54,6 +54,7 @@ class GtkUI(GtkPluginBase): component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) client.webui.get_config().addCallback(self.cb_get_config) + client.webui.got_deluge_web().addCallback(self.cb_chk_deluge_web) def disable(self): component.get("Preferences").remove_page("WebUi") @@ -61,6 +62,8 @@ class GtkUI(GtkPluginBase): component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs) def on_apply_prefs(self): + if not self.have_web: + return log.debug("applying prefs for WebUi") config = { "enabled": self.glade.get_widget("enabled_checkbutton").get_active(), @@ -77,3 +80,26 @@ class GtkUI(GtkPluginBase): self.glade.get_widget("enabled_checkbutton").set_active(config["enabled"]) self.glade.get_widget("ssl_checkbutton").set_active(config["ssl"]) self.glade.get_widget("port_spinbutton").set_value(config["port"]) + + def cb_chk_deluge_web(self, have_web): + self.have_web = have_web + if have_web: + return + self.glade.get_widget("settings_vbox").set_sensitive(False) + + vbox = self.glade.get_widget("prefs_box") + + hbox = gtk.HBox() + icon = gtk.image_new_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_SMALL_TOOLBAR) + icon.set_padding(5, 5) + hbox.pack_start(icon, False, False) + + label = gtk.Label(_("The Deluge web interface is not installed, " + "please install the\ninterface and try again")) + label.set_alignment(0, 0.5) + label.set_padding(5, 5) + hbox.pack_start(label) + + vbox.pack_start(hbox, False, False, 10) + vbox.reorder_child(hbox, 0) + vbox.show_all()