From a12c51285085e4a4500cc0efc5a9c613e4256bc7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 6 Mar 2024 00:20:45 +0100 Subject: Adding upstream version 2.1.2~dev0+20240219. Signed-off-by: Daniel Baumann --- deluge/ui/gtk3/glade/preferences_dialog.ui | 48 +++++++++++++++++-- deluge/ui/gtk3/gtkui.py | 1 + deluge/ui/gtk3/mainwindow.py | 6 +++ deluge/ui/gtk3/preferences.py | 20 +++++++- .../web/js/deluge-all/preferences/InterfacePage.js | 54 ++++++++++++++++++++++ deluge/ui/web/json_api.py | 20 ++++++++ deluge/ui/web/server.py | 40 ++++++++++++---- 7 files changed, 176 insertions(+), 13 deletions(-) diff --git a/deluge/ui/gtk3/glade/preferences_dialog.ui b/deluge/ui/gtk3/glade/preferences_dialog.ui index aa1531d..720dc6b 100644 --- a/deluge/ui/gtk3/glade/preferences_dialog.ui +++ b/deluge/ui/gtk3/glade/preferences_dialog.ui @@ -736,7 +736,7 @@ and daemon (does not apply in Standalone mode). False False 5 - 1 + 2 @@ -967,6 +967,48 @@ and daemon (does not apply in Standalone mode). 2 + + + True + False + 0 + none + + + True + False + 3 + 10 + + + Prefer Dark + True + True + False + If available, use dark variant of GTK theme. + True + + + + + + + True + False + Theme + + + + + + + + False + False + 5 + 3 + + True @@ -1024,7 +1066,7 @@ and daemon (does not apply in Standalone mode). False False 5 - 3 + 4 @@ -1101,7 +1143,7 @@ and daemon (does not apply in Standalone mode). False True - 4 + 5 diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index 434d1b8..73a7c97 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -84,6 +84,7 @@ except ImportError: DEFAULT_PREFS = { 'standalone': True, + 'prefer_dark_theme': False, 'interactive_add': True, 'focus_add_dialog': True, 'enable_system_tray': True, diff --git a/deluge/ui/gtk3/mainwindow.py b/deluge/ui/gtk3/mainwindow.py index e1e3bb3..6c871d2 100644 --- a/deluge/ui/gtk3/mainwindow.py +++ b/deluge/ui/gtk3/mainwindow.py @@ -72,6 +72,12 @@ class MainWindow(component.Component): self.config = ConfigManager('gtk3ui.conf') self.main_builder = Gtk.Builder() + # Set theme + Gtk.Settings.get_default().set_property( + 'gtk-application-prefer-dark-theme', + self.config['prefer_dark_theme'], + ) + # Patch this GtkBuilder to avoid connecting signals from elsewhere # # Think about splitting up mainwindow gtkbuilder file into the necessary parts diff --git a/deluge/ui/gtk3/preferences.py b/deluge/ui/gtk3/preferences.py index a024a59..cd67a5b 100644 --- a/deluge/ui/gtk3/preferences.py +++ b/deluge/ui/gtk3/preferences.py @@ -13,7 +13,7 @@ from hashlib import sha1 as sha from urllib.parse import urlparse from gi import require_version -from gi.repository import Gtk +from gi.repository import GObject, Gtk from gi.repository.Gdk import Color import deluge.common @@ -171,6 +171,14 @@ class Preferences(component.Component): # Radio buttons to choose between systray and appindicator self.builder.get_object('alignment_tray_type').set_visible(appindicator) + # Initialize a binding for dark theme + Gtk.Settings.get_default().bind_property( + 'gtk-application-prefer-dark-theme', + self.builder.get_object('chk_prefer_dark_theme'), + 'active', + GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE, + ) + from .gtkui import DEFAULT_PREFS self.COLOR_DEFAULTS = {} @@ -557,6 +565,9 @@ class Preferences(component.Component): self.builder.get_object('radio_thinclient').set_active( not self.gtkui_config['standalone'] ) + self.builder.get_object('chk_prefer_dark_theme').set_active( + self.gtkui_config['prefer_dark_theme'] + ) self.builder.get_object('chk_show_rate_in_title').set_active( self.gtkui_config['show_rate_in_title'] ) @@ -741,6 +752,9 @@ class Preferences(component.Component): ).get_active() # Interface tab # + new_gtkui_config['prefer_dark_theme'] = self.builder.get_object( + 'chk_prefer_dark_theme' + ).get_active() new_gtkui_config['enable_system_tray'] = self.builder.get_object( 'chk_use_tray' ).get_active() @@ -1074,6 +1088,10 @@ class Preferences(component.Component): def on_button_cancel_clicked(self, data): log.debug('on_button_cancel_clicked') + Gtk.Settings.get_default().set_property( + 'gtk-application-prefer-dark-theme', + self.gtkui_config['prefer_dark_theme'], + ) self.hide() return True 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 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() -- cgit v1.2.3