summaryrefslogtreecommitdiffstats
path: root/deluge/ui/web/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/web/server.py')
-rw-r--r--deluge/ui/web/server.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py
index 77c1ddf..5fbdd4e 100644
--- a/deluge/ui/web/server.py
+++ b/deluge/ui/web/server.py
@@ -12,6 +12,7 @@ import logging
import mimetypes
import os
import tempfile
+from pathlib import Path
from twisted.application import internet, service
from twisted.internet import defer, reactor
@@ -539,15 +540,28 @@ class TopLevel(resource.Resource):
self.putChild(b'themes', Themes(rpath('themes')))
self.putChild(b'tracker', Tracker())
- theme = component.get('DelugeWeb').config['theme']
- if not os.path.isfile(rpath('themes', 'css', 'xtheme-%s.css' % theme)):
- theme = CONFIG_DEFAULTS.get('theme')
- self.__stylesheets.insert(1, 'themes/css/xtheme-%s.css' % theme)
-
@property
def stylesheets(self):
return self.__stylesheets
+ def get_themes(self):
+ themes_dir = Path(rpath('themes', 'css'))
+ themes = [
+ theme.stem.split('xtheme-')[1] for theme in themes_dir.glob('xtheme-*.css')
+ ]
+ themes = [(theme, _(theme.capitalize())) for theme in themes]
+ return themes
+
+ def set_theme(self, theme: str):
+ if not os.path.isfile(rpath('themes', 'css', f'xtheme-{theme}.css')):
+ theme = CONFIG_DEFAULTS.get('theme')
+ self.__theme = f'themes/css/xtheme-{theme}.css'
+
+ # Only one xtheme CSS, ordered last to override other styles.
+ if 'xtheme-' in self.stylesheets[-1]:
+ self.__stylesheets.pop()
+ self.__stylesheets.append(self.__theme)
+
def add_script(self, script):
"""
Adds a script to the server so it is included in the <head> element
@@ -683,6 +697,8 @@ class DelugeWeb(component.Component):
elif options.no_ssl:
self.https = False
+ self.top_level.set_theme(self.config['theme'])
+
setup_translation()
# Remove twisted version number from 'server' http-header for security reasons
@@ -741,8 +757,8 @@ class DelugeWeb(component.Component):
def start_normal(self):
self.socket = reactor.listenTCP(self.port, self.site, interface=self.interface)
ip = self.socket.getHost().host
- ip = '[%s]' % ip if is_ipv6(ip) else ip
- log.info('Serving at http://%s:%s%s', ip, self.port, self.base)
+ ip = f'[{ip}]' if is_ipv6(ip) else ip
+ log.info(f'Serving at http://{ip}:{self.port}{self.base}')
def start_ssl(self):
check_ssl_keys()
@@ -758,8 +774,8 @@ class DelugeWeb(component.Component):
interface=self.interface,
)
ip = self.socket.getHost().host
- ip = '[%s]' % ip if is_ipv6(ip) else ip
- log.info('Serving at https://%s:%s%s', ip, self.port, self.base)
+ ip = f'[{ip}]' if is_ipv6(ip) else ip
+ log.info(f'Serving at https://{ip}:{self.port}{self.base}')
def stop(self):
log.info('Shutting down webserver')
@@ -789,6 +805,12 @@ class DelugeWeb(component.Component):
config['language'] = CONFIG_DEFAULTS['language']
return config
+ def get_themes(self):
+ return self.top_level.get_themes()
+
+ def set_theme(self, theme: str):
+ self.top_level.set_theme(theme)
+
if __name__ == '__builtin__':
deluge_web = DelugeWeb()