From e6b8ff34edb20d72e2e01f1e05f480f0b0117a51 Mon Sep 17 00:00:00 2001 From: Igor Sharonov Date: Mon, 22 Apr 2024 07:46:53 +0300 Subject: [PATCH] Support dark theme switch in settings --- libdino/src/entity/settings.vala | 15 ++++++++++ main/data/settings_dialog.ui | 17 +++++++++++ main/po/en.po | 48 +++++++++++++++++++++++++++----- main/po/ru.po | 48 ++++++++++++++++++++++++++++---- main/src/ui/application.vala | 13 +++++++++ main/src/ui/settings_dialog.vala | 4 +++ 6 files changed, 132 insertions(+), 13 deletions(-) diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala index 8f39713f..9b1efa3a 100644 --- a/libdino/src/entity/settings.vala +++ b/libdino/src/entity/settings.vala @@ -15,6 +15,7 @@ public class Settings : Object { default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN); send_button = col_to_bool_or_default("send_button", false); enter_newline = col_to_bool_or_default("enter_newline", false); + dark_theme = col_to_bool_or_default("dark_theme", false); } private bool col_to_bool_or_default(string key, bool def) { @@ -128,6 +129,20 @@ public class Settings : Object { enter_newline_ = value; } } + + public signal void dark_theme_update(bool is_dark); + private bool dark_theme_; + public bool dark_theme { + get { return dark_theme_; } + set { + db.settings.upsert() + .value(db.settings.key, "dark_theme", true) + .value(db.settings.value, value.to_string()) + .perform(); + dark_theme_ = value; + dark_theme_update(value); + } + } } } diff --git a/main/data/settings_dialog.ui b/main/data/settings_dialog.ui index 04bd548b..5fafe36d 100644 --- a/main/data/settings_dialog.ui +++ b/main/data/settings_dialog.ui @@ -140,6 +140,23 @@ + + + + + _Dark theme + If disabled, use system settings + True + dark_theme + + + center + + + + + + diff --git a/main/po/en.po b/main/po/en.po index 7fb7fc6f..c217e2d9 100644 --- a/main/po/en.po +++ b/main/po/en.po @@ -533,12 +533,10 @@ msgid "Local Settings" msgstr "" #: main/src/ui/contact_details/settings_provider.vala:28 -#: main/data/settings_dialog.ui:23 msgid "Send typing notifications" msgstr "" #: main/src/ui/contact_details/settings_provider.vala:33 -#: main/data/settings_dialog.ui:32 msgid "Send read receipts" msgstr "" @@ -1012,16 +1010,52 @@ msgstr "" msgid "Add Contact" msgstr "" -#: main/data/settings_dialog.ui:41 +#: main/data/settings_dialog.ui:14 +msgid "Default encryption for 1-on-1 chats" +msgstr "" + +#: main/data/settings_dialog.ui:19 +msgid "Ask" +msgstr "" + +#: main/data/settings_dialog.ui:57 +msgid "Send _Typing Notifications" +msgstr "" + +#: main/data/settings_dialog.ui:85 +msgid "_Notifications" +msgstr "" + +#: main/data/settings_dialog.ui:69 +msgid "Send _Read Receipts" +msgstr "" + +#: main/data/settings_dialog.ui:86 msgid "Notify when a new message arrives" msgstr "" -#: main/data/settings_dialog.ui:50 -msgid "Convert smileys to emojis" +#: main/data/settings_dialog.ui:102 +msgid "_Convert Smileys to Emoji" msgstr "" -#: main/data/settings_dialog.ui:59 -msgid "Check spelling" +#: main/data/settings_dialog.ui:118 +msgid "_Display send button" +msgstr "" + +#: main/data/settings_dialog.ui:130 +msgid "_Use Enter key to start a new line" +msgstr "" + +#: main/data/settings_dialog.ui:131 +msgid "If disabled, use Shift+Enter to start a new line" +msgstr "" + +#: main/data/settings_dialog.ui:147 +msgid "_Dark theme" +msgstr "" + +#: main/data/settings_dialog.ui:148 +msgid "If disabled, use system settings" msgstr "" #: main/data/im.dino.Dino.appdata.xml.in:7 diff --git a/main/po/ru.po b/main/po/ru.po index 2b3af4d1..dad1e6f4 100644 --- a/main/po/ru.po +++ b/main/po/ru.po @@ -1028,17 +1028,53 @@ msgstr "Псевдоним" msgid "Add Contact" msgstr "Добавить контакт" -#: main/data/settings_dialog.ui:41 +#: main/data/settings_dialog.ui:14 +msgid "Default encryption for 1-on-1 chats" +msgstr "Шифрование по умолчанию для 1-на-1 чатов" + +#: main/data/settings_dialog.ui:19 +msgid "Ask" +msgstr "Спрашивать" + +#: main/data/settings_dialog.ui:57 +msgid "Send _Typing Notifications" +msgstr "Отправлять уведомления при наборе сообщения" + +#: main/data/settings_dialog.ui:85 +msgid "_Notifications" +msgstr "Уведомления" + +#: main/data/settings_dialog.ui:69 +msgid "Send _Read Receipts" +msgstr "Отправлять уведомления о прочтении" + +#: main/data/settings_dialog.ui:86 msgid "Notify when a new message arrives" msgstr "Уведомлять о новых сообщениях" -#: main/data/settings_dialog.ui:50 -msgid "Convert smileys to emojis" +#: main/data/settings_dialog.ui:102 +msgid "_Convert Smileys to Emoji" msgstr "Превращать смайлы в эмодзи" -#: main/data/settings_dialog.ui:59 -msgid "Check spelling" -msgstr "Проверка орфографии" +#: main/data/settings_dialog.ui:118 +msgid "_Display send button" +msgstr "Показывать кнопку отправки" + +#: main/data/settings_dialog.ui:130 +msgid "_Use Enter key to start a new line" +msgstr "Использовать Enter для вставки новой строки" + +#: main/data/settings_dialog.ui:131 +msgid "If disabled, use Shift+Enter to start a new line" +msgstr "Если опция недоступна, используйте Shift+Enter для вставки новой строки" + +#: main/data/settings_dialog.ui:147 +msgid "_Dark theme" +msgstr "Тёмная тема" + +#: main/data/settings_dialog.ui:148 +msgid "If disabled, use system settings" +msgstr "Если опция недоступна, используйте настройки системы" #: main/data/im.dino.Dino.appdata.xml.in:7 msgid "Modern XMPP Chat Client" diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index a1671364..1a7b4170 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -68,6 +68,19 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application { } } }); + + settings.dark_theme_update.connect((is_dark) => { + var manager = Adw.StyleManager.get_default(); + if (is_dark != manager.dark) { + if (is_dark) { + manager.set_color_scheme(Adw.ColorScheme.PREFER_DARK); + } else { + manager.set_color_scheme(Adw.ColorScheme.PREFER_LIGHT); + } + } + }); + + settings.dark_theme_update(settings.dark_theme); // Change theme at startup. }); activate.connect(() => { diff --git a/main/src/ui/settings_dialog.vala b/main/src/ui/settings_dialog.vala index 5bdcee99..8c20a84b 100644 --- a/main/src/ui/settings_dialog.vala +++ b/main/src/ui/settings_dialog.vala @@ -15,6 +15,7 @@ class SettingsDialog : Adw.PreferencesWindow { [GtkChild] private unowned CheckButton encryption_radio_openpgp; [GtkChild] private unowned Switch send_button_switch; [GtkChild] private unowned Switch enter_newline_switch; + [GtkChild] private unowned Switch dark_theme; Dino.Entities.Settings settings = Dino.Application.get_default().settings; @@ -32,6 +33,8 @@ class SettingsDialog : Adw.PreferencesWindow { send_button_switch.active = settings.send_button; enter_newline_switch.active = settings.enter_newline; enter_newline_switch.sensitive = settings.send_button; + dark_theme.active = settings.dark_theme; + dark_theme.sensitive = !Adw.StyleManager.get_default().system_supports_color_schemes; typing_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } ); marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } ); @@ -65,6 +68,7 @@ class SettingsDialog : Adw.PreferencesWindow { enter_newline_switch.active = visible; } }); + dark_theme.notify["active"].connect(() => { settings.dark_theme = dark_theme.active; }); } }