Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dark theme switch in settings #67

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libdino/src/entity/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}

}
17 changes: 17 additions & 0 deletions main/data/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">_Dark theme</property>
<property name="subtitle" translatable="yes">If disabled, use system settings</property>
<property name="use-underline">True</property>
<property name="activatable-widget">dark_theme</property>
<child type="suffix">
<object class="GtkSwitch" id="dark_theme">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
Expand Down
48 changes: 41 additions & 7 deletions main/po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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: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:59
msgid "Check spelling"
#: main/data/settings_dialog.ui:148
msgid "If disabled, use system settings"
msgstr ""

#: main/data/im.dino.Dino.appdata.xml.in:7
Expand Down
48 changes: 42 additions & 6 deletions main/po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions main/src/ui/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 4 additions & 0 deletions main/src/ui/settings_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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; } );
Expand Down Expand Up @@ -65,6 +68,7 @@ class SettingsDialog : Adw.PreferencesWindow {
enter_newline_switch.active = visible;
}
});
dark_theme.notify["active"].connect(() => { settings.dark_theme = dark_theme.active; });
}
}

Expand Down
Loading