Support dark theme switch in settings
This commit is contained in:
parent
863cbfb53a
commit
e6b8ff34ed
|
@ -15,6 +15,7 @@ public class Settings : Object {
|
||||||
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
|
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
|
||||||
send_button = col_to_bool_or_default("send_button", false);
|
send_button = col_to_bool_or_default("send_button", false);
|
||||||
enter_newline = col_to_bool_or_default("enter_newline", 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) {
|
private bool col_to_bool_or_default(string key, bool def) {
|
||||||
|
@ -128,6 +129,20 @@ public class Settings : Object {
|
||||||
enter_newline_ = value;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,6 +140,23 @@
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</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>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -533,12 +533,10 @@ msgid "Local Settings"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: main/src/ui/contact_details/settings_provider.vala:28
|
#: main/src/ui/contact_details/settings_provider.vala:28
|
||||||
#: main/data/settings_dialog.ui:23
|
|
||||||
msgid "Send typing notifications"
|
msgid "Send typing notifications"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: main/src/ui/contact_details/settings_provider.vala:33
|
#: main/src/ui/contact_details/settings_provider.vala:33
|
||||||
#: main/data/settings_dialog.ui:32
|
|
||||||
msgid "Send read receipts"
|
msgid "Send read receipts"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -1012,16 +1010,52 @@ msgstr ""
|
||||||
msgid "Add Contact"
|
msgid "Add Contact"
|
||||||
msgstr ""
|
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"
|
msgid "Notify when a new message arrives"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: main/data/settings_dialog.ui:50
|
#: main/data/settings_dialog.ui:102
|
||||||
msgid "Convert smileys to emojis"
|
msgid "_Convert Smileys to Emoji"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: main/data/settings_dialog.ui:59
|
#: main/data/settings_dialog.ui:118
|
||||||
msgid "Check spelling"
|
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 ""
|
msgstr ""
|
||||||
|
|
||||||
#: main/data/im.dino.Dino.appdata.xml.in:7
|
#: main/data/im.dino.Dino.appdata.xml.in:7
|
||||||
|
|
|
@ -1028,17 +1028,53 @@ msgstr "Псевдоним"
|
||||||
msgid "Add Contact"
|
msgid "Add Contact"
|
||||||
msgstr "Добавить контакт"
|
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"
|
msgid "Notify when a new message arrives"
|
||||||
msgstr "Уведомлять о новых сообщениях"
|
msgstr "Уведомлять о новых сообщениях"
|
||||||
|
|
||||||
#: main/data/settings_dialog.ui:50
|
#: main/data/settings_dialog.ui:102
|
||||||
msgid "Convert smileys to emojis"
|
msgid "_Convert Smileys to Emoji"
|
||||||
msgstr "Превращать смайлы в эмодзи"
|
msgstr "Превращать смайлы в эмодзи"
|
||||||
|
|
||||||
#: main/data/settings_dialog.ui:59
|
#: main/data/settings_dialog.ui:118
|
||||||
msgid "Check spelling"
|
msgid "_Display send button"
|
||||||
msgstr "Проверка орфографии"
|
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
|
#: main/data/im.dino.Dino.appdata.xml.in:7
|
||||||
msgid "Modern XMPP Chat Client"
|
msgid "Modern XMPP Chat Client"
|
||||||
|
|
|
@ -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(() => {
|
activate.connect(() => {
|
||||||
|
|
|
@ -15,6 +15,7 @@ class SettingsDialog : Adw.PreferencesWindow {
|
||||||
[GtkChild] private unowned CheckButton encryption_radio_openpgp;
|
[GtkChild] private unowned CheckButton encryption_radio_openpgp;
|
||||||
[GtkChild] private unowned Switch send_button_switch;
|
[GtkChild] private unowned Switch send_button_switch;
|
||||||
[GtkChild] private unowned Switch enter_newline_switch;
|
[GtkChild] private unowned Switch enter_newline_switch;
|
||||||
|
[GtkChild] private unowned Switch dark_theme;
|
||||||
|
|
||||||
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
|
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
|
||||||
|
|
||||||
|
@ -32,6 +33,8 @@ class SettingsDialog : Adw.PreferencesWindow {
|
||||||
send_button_switch.active = settings.send_button;
|
send_button_switch.active = settings.send_button;
|
||||||
enter_newline_switch.active = settings.enter_newline;
|
enter_newline_switch.active = settings.enter_newline;
|
||||||
enter_newline_switch.sensitive = settings.send_button;
|
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; } );
|
typing_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } );
|
||||||
marker_switch.notify["active"].connect(() => { settings.send_marker = marker_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;
|
enter_newline_switch.active = visible;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dark_theme.notify["active"].connect(() => { settings.dark_theme = dark_theme.active; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue