summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--deluge/ui/gtk3/glade/preferences_dialog.ui48
-rw-r--r--deluge/ui/gtk3/gtkui.py1
-rw-r--r--deluge/ui/gtk3/mainwindow.py6
-rw-r--r--deluge/ui/gtk3/preferences.py20
-rw-r--r--deluge/ui/web/js/deluge-all/preferences/InterfacePage.js54
-rw-r--r--deluge/ui/web/json_api.py20
-rw-r--r--deluge/ui/web/server.py40
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).</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">5</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -968,6 +968,48 @@ and daemon (does not apply in Standalone mode).</property>
</packing>
</child>
<child>
+ <object class="GtkFrame" id="frame_theme">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label-xalign">0</property>
+ <property name="shadow-type">none</property>
+ <child>
+ <object class="GtkAlignment" id="alignment_theme">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="top-padding">3</property>
+ <property name="left-padding">10</property>
+ <child>
+ <object class="GtkCheckButton" id="chk_prefer_dark_theme">
+ <property name="label" translatable="yes">Prefer Dark</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="tooltip_text" translatable="yes">If available, use dark variant of GTK theme.</property>
+ <property name="draw-indicator">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label_theme">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label" translatable="yes">Theme</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">5</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkFrame" id="frame19">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -1024,7 +1066,7 @@ and daemon (does not apply in Standalone mode).</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">5</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
<child>
@@ -1101,7 +1143,7 @@ and daemon (does not apply in Standalone mode).</property>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">4</property>
+ <property name="position">5</property>
</packing>
</child>
</object>
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 <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()