disable the webui plugin settings and display an error message when deluge-web is missing
This commit is contained in:
parent
5c8eccdd82
commit
b46562d932
|
@ -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,
|
||||
|
@ -76,13 +74,28 @@ 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):
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue