From bf536134338334622337e7e3ca3573e70921ad6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 23 Sep 2018 14:57:10 +0200 Subject: [PATCH] Add dark theme switch in preferences --- gajim/data/gui/preferences_window.ui | 28 ++++++++++++++++++++++------ gajim/gtk/preferences.py | 8 ++++++++ gajim/gtk/util.py | 10 ++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/gajim/data/gui/preferences_window.ui b/gajim/data/gui/preferences_window.ui index 0ba4e66fa..fe4bb8ba9 100644 --- a/gajim/data/gui/preferences_window.ui +++ b/gajim/data/gui/preferences_window.ui @@ -1508,9 +1508,6 @@ $T will be replaced by auto-not-available timeout 18 vertical 12 - - - True @@ -1616,6 +1613,28 @@ $T will be replaced by auto-not-available timeout 0 + + + Enable dark theme + True + True + False + start + True + True + + + + 1 + 3 + + + + + + + + @@ -1640,9 +1659,6 @@ $T will be replaced by auto-not-available timeout 1 - - - 4 diff --git a/gajim/gtk/preferences.py b/gajim/gtk/preferences.py index b1988a96f..d59f1f1d7 100644 --- a/gajim/gtk/preferences.py +++ b/gajim/gtk/preferences.py @@ -24,6 +24,8 @@ from gajim.common import helpers from gajim.common import configpaths from gajim.common import config as c_config from gajim.common import idle +from gajim.gtk.util import get_dark_theme +from gajim.gtk.util import set_dark_theme from gajim.gtk.util import get_builder from gajim.gtk import AspellDictError from gajim.gtk.themes import Themes @@ -207,6 +209,9 @@ class Preferences(Gtk.ApplicationWindow): st = app.config.get('use_transports_iconsets') self.xml.get_object('transports_iconsets_checkbutton').set_active(st) + # Dark theme + self.xml.get_object('enable_dark_theme').set_active(get_dark_theme()) + ### Personal Events tab ### # outgoing send chat state notifications st = app.config.get('outgoing_chat_state_notifications') @@ -655,6 +660,9 @@ class Preferences(Gtk.ApplicationWindow): self.on_checkbutton_toggled(widget, 'use_transports_iconsets') gtkgui_helpers.reload_jabber_state_images() + def on_enable_dark_theme_toggled(self, widget): + set_dark_theme(widget.get_active()) + def on_outgoing_chat_states_combobox_changed(self, widget): active = widget.get_active() old_value = app.config.get('outgoing_chat_state_notifications') diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index 471627ae1..c76df168f 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -230,3 +230,13 @@ def convert_rgb_to_hex(rgb_string): green = int(rgb.green * 255) blue = int(rgb.blue * 255) return '#%02x%02x%02x' % (red, green, blue) + + +def set_dark_theme(enable: bool) -> None: + settings = Gtk.Settings.get_default() + settings.set_property('gtk-application-prefer-dark-theme', enable) + + +def get_dark_theme() -> bool: + settings = Gtk.Settings.get_default() + return settings.get_property('gtk-application-prefer-dark-theme')