diff options
Diffstat (limited to 'deluge/ui/web')
-rw-r--r-- | deluge/ui/web/js/deluge-all/preferences/InterfacePage.js | 54 | ||||
-rw-r--r-- | deluge/ui/web/json_api.py | 20 | ||||
-rw-r--r-- | deluge/ui/web/server.py | 40 |
3 files changed, 105 insertions, 9 deletions
diff --git a/deluge/ui/web/js/deluge-all/preferences/InterfacePage.js b/deluge/ui/web/js/deluge-all/preferences/InterfacePage.js index 1b710f2..a5a7909 100644 --- a/deluge/ui/web/js/deluge-all/preferences/InterfacePage.js +++ b/deluge/ui/web/js/deluge-all/preferences/InterfacePage.js @@ -88,6 +88,33 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { }) ); + var themePanel = this.add({ + xtype: 'fieldset', + border: false, + title: _('Theme'), + style: 'margin-bottom: 0px; padding-bottom: 5px; padding-top: 5px', + autoHeight: true, + labelWidth: 1, + defaultType: 'checkbox', + }); + this.theme = om.bind( + 'theme', + themePanel.add({ + xtype: 'combo', + name: 'theme', + labelSeparator: '', + mode: 'local', + width: 200, + store: new Ext.data.ArrayStore({ + fields: ['id', 'text'], + }), + editable: false, + triggerAction: 'all', + valueField: 'id', + displayField: 'text', + }) + ); + fieldset = this.add({ xtype: 'fieldset', border: false, @@ -217,6 +244,24 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { icon: Ext.MessageBox.QUESTION, }); } + if ('theme' in changed) { + deluge.client.web.set_theme(changed['theme']); + Ext.Msg.show({ + title: _('WebUI Theme Changed'), + msg: _( + 'Do you want to refresh the page now to use the new theme?' + ), + buttons: { + yes: _('Refresh'), + no: _('Close'), + }, + multiline: false, + fn: function (btnText) { + if (btnText === 'yes') location.reload(); + }, + icon: Ext.MessageBox.QUESTION, + }); + } } if (this.oldPassword.getValue() || this.newPassword.getValue()) { this.onPasswordChange(); @@ -237,6 +282,11 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { this.language.setValue(this.optionsManager.get('language')); }, + onGotThemes: function (info, obj, response, request) { + this.theme.store.loadData(info); + this.theme.setValue(this.optionsManager.get('theme')); + }, + onPasswordChange: function () { var newPassword = this.newPassword.getValue(); if (newPassword != this.confirmPassword.getValue()) { @@ -295,6 +345,10 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { success: this.onGotLanguages, scope: this, }); + deluge.client.webutils.get_themes({ + success: this.onGotThemes, + scope: this, + }); }, onSSLCheck: function (e, checked) { diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index ea8105d..5f4b3dc 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -982,6 +982,16 @@ class WebApi(JSONComponent): """ return self.event_queue.get_events(__request__.session_id) + @export + def set_theme(self, theme): + """ + Sets a new Theme to the WebUI + + Args: + theme (str): the theme to apply + """ + component.get('DelugeWeb').set_theme(theme) + class WebUtils(JSONComponent): """ @@ -1000,3 +1010,13 @@ class WebUtils(JSONComponent): list: of tuples ``[(lang-id, language-name), ...]`` """ return get_languages() + + @export + def get_themes(self): + """ + Get the available themes + + Returns: + list: of themes ``[theme1, theme2, ...]`` + """ + return component.get('DelugeWeb').get_themes() 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() |