mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-28 08:10:19 +00:00
Add None option for GTK3 theme reset
This commit is contained in:
@@ -337,6 +337,44 @@ test_unset_theme_keeps_system_default_without_apply (void)
|
|||||||
gtk_widget_destroy (page);
|
gtk_widget_destroy (page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_select_none_resets_theme_and_applies (void)
|
||||||
|
{
|
||||||
|
GtkWidget *page;
|
||||||
|
theme_preferences_ui *ui;
|
||||||
|
struct zoitechatprefs setup_prefs;
|
||||||
|
|
||||||
|
if (!gtk_available)
|
||||||
|
{
|
||||||
|
g_test_message ("GTK display not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (&setup_prefs, 0, sizeof (setup_prefs));
|
||||||
|
memset (&prefs, 0, sizeof (prefs));
|
||||||
|
g_strlcpy (prefs.hex_gui_gtk3_theme, "fallback-theme", sizeof (prefs.hex_gui_gtk3_theme));
|
||||||
|
prefs.hex_gui_gtk3_variant = THEME_GTK3_VARIANT_PREFER_LIGHT;
|
||||||
|
removed_selected = FALSE;
|
||||||
|
apply_current_calls = 0;
|
||||||
|
applied_theme_id[0] = '\0';
|
||||||
|
|
||||||
|
page = theme_preferences_create_page (NULL, &setup_prefs, NULL);
|
||||||
|
ui = g_object_get_data (G_OBJECT (page), "theme-preferences-ui");
|
||||||
|
g_assert_nonnull (ui);
|
||||||
|
|
||||||
|
gtk_combo_box_set_active (GTK_COMBO_BOX (ui->gtk3_combo), 0);
|
||||||
|
|
||||||
|
g_assert_cmpstr (prefs.hex_gui_gtk3_theme, ==, "");
|
||||||
|
g_assert_cmpstr (setup_prefs.hex_gui_gtk3_theme, ==, "");
|
||||||
|
g_assert_cmpint (prefs.hex_gui_gtk3_variant, ==, THEME_GTK3_VARIANT_FOLLOW_SYSTEM);
|
||||||
|
g_assert_cmpint (setup_prefs.hex_gui_gtk3_variant, ==, THEME_GTK3_VARIANT_FOLLOW_SYSTEM);
|
||||||
|
g_assert_cmpint (apply_current_calls, ==, 1);
|
||||||
|
g_assert_cmpstr (applied_theme_id, ==, "");
|
||||||
|
g_assert_cmpint (applied_variant, ==, THEME_GTK3_VARIANT_FOLLOW_SYSTEM);
|
||||||
|
|
||||||
|
gtk_widget_destroy (page);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -346,5 +384,7 @@ main (int argc, char **argv)
|
|||||||
test_removed_selected_theme_commits_fallback_and_applies);
|
test_removed_selected_theme_commits_fallback_and_applies);
|
||||||
g_test_add_func ("/theme/preferences/gtk3_unset_keeps_system_default",
|
g_test_add_func ("/theme/preferences/gtk3_unset_keeps_system_default",
|
||||||
test_unset_theme_keeps_system_default_without_apply);
|
test_unset_theme_keeps_system_default_without_apply);
|
||||||
|
g_test_add_func ("/theme/preferences/gtk3_select_none_resets_theme",
|
||||||
|
test_select_none_resets_theme_and_applies);
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1380,6 +1380,9 @@ theme_preferences_gtk3_changed_cb (GtkComboBox *combo, gpointer user_data)
|
|||||||
if (!id)
|
if (!id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (id[0] == '\0')
|
||||||
|
variant = THEME_GTK3_VARIANT_FOLLOW_SYSTEM;
|
||||||
|
else
|
||||||
variant = theme_gtk3_variant_for_theme (id);
|
variant = theme_gtk3_variant_for_theme (id);
|
||||||
selection_changed = g_strcmp0 (prefs.hex_gui_gtk3_theme, id) != 0
|
selection_changed = g_strcmp0 (prefs.hex_gui_gtk3_theme, id) != 0
|
||||||
|| prefs.hex_gui_gtk3_variant != variant;
|
|| prefs.hex_gui_gtk3_variant != variant;
|
||||||
@@ -1402,40 +1405,6 @@ theme_preferences_gtk3_changed_cb (GtkComboBox *combo, gpointer user_data)
|
|||||||
g_free (id);
|
g_free (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
theme_preferences_gtk3_find_system_theme_index (GPtrArray *themes)
|
|
||||||
{
|
|
||||||
GtkSettings *settings;
|
|
||||||
char *system_theme = NULL;
|
|
||||||
guint i;
|
|
||||||
int found = -1;
|
|
||||||
|
|
||||||
settings = gtk_settings_get_default ();
|
|
||||||
if (!settings || !themes)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
g_object_get (G_OBJECT (settings), "gtk-theme-name", &system_theme, NULL);
|
|
||||||
if (!system_theme || system_theme[0] == '\0')
|
|
||||||
{
|
|
||||||
g_free (system_theme);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < themes->len; i++)
|
|
||||||
{
|
|
||||||
ZoitechatGtk3Theme *theme = g_ptr_array_index (themes, i);
|
|
||||||
|
|
||||||
if (theme && g_strcmp0 (theme->id, system_theme) == 0)
|
|
||||||
{
|
|
||||||
found = (int) i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (system_theme);
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
theme_preferences_populate_gtk3 (theme_preferences_ui *ui)
|
theme_preferences_populate_gtk3 (theme_preferences_ui *ui)
|
||||||
{
|
{
|
||||||
@@ -1454,6 +1423,12 @@ theme_preferences_populate_gtk3 (theme_preferences_ui *ui)
|
|||||||
store = GTK_TREE_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (ui->gtk3_combo)));
|
store = GTK_TREE_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (ui->gtk3_combo)));
|
||||||
ui->gtk3_populating = TRUE;
|
ui->gtk3_populating = TRUE;
|
||||||
gtk_tree_store_clear (store);
|
gtk_tree_store_clear (store);
|
||||||
|
gtk_tree_store_append (store, &iter, NULL);
|
||||||
|
gtk_tree_store_set (store, &iter,
|
||||||
|
GTK3_THEME_COL_ID, "",
|
||||||
|
GTK3_THEME_COL_LABEL, _("None"),
|
||||||
|
GTK3_THEME_COL_SOURCE, ZOITECHAT_GTK3_THEME_SOURCE_SYSTEM,
|
||||||
|
-1);
|
||||||
themes = zoitechat_gtk3_theme_service_discover ();
|
themes = zoitechat_gtk3_theme_service_discover ();
|
||||||
for (i = 0; i < themes->len; i++)
|
for (i = 0; i < themes->len; i++)
|
||||||
{
|
{
|
||||||
@@ -1468,28 +1443,29 @@ theme_preferences_populate_gtk3 (theme_preferences_ui *ui)
|
|||||||
GTK3_THEME_COL_SOURCE, theme->source,
|
GTK3_THEME_COL_SOURCE, theme->source,
|
||||||
-1);
|
-1);
|
||||||
if (g_strcmp0 (prefs.hex_gui_gtk3_theme, theme->id) == 0)
|
if (g_strcmp0 (prefs.hex_gui_gtk3_theme, theme->id) == 0)
|
||||||
active = i;
|
active = (int)i + 1;
|
||||||
g_free (label);
|
g_free (label);
|
||||||
}
|
}
|
||||||
if (active < 0 && using_system_default)
|
if (active < 0 && using_system_default)
|
||||||
active = theme_preferences_gtk3_find_system_theme_index (themes);
|
active = 0;
|
||||||
if (active >= 0)
|
if (active >= 0)
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (ui->gtk3_combo), active);
|
gtk_combo_box_set_active (GTK_COMBO_BOX (ui->gtk3_combo), active);
|
||||||
else if (themes->len > 0)
|
else
|
||||||
{
|
{
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (ui->gtk3_combo), 0);
|
gtk_combo_box_set_active (GTK_COMBO_BOX (ui->gtk3_combo), 0);
|
||||||
if (!using_system_default)
|
if (!using_system_default)
|
||||||
removed_selected_theme = TRUE;
|
removed_selected_theme = TRUE;
|
||||||
}
|
}
|
||||||
else if (prefs.hex_gui_gtk3_theme[0] != '\0')
|
gtk_widget_set_sensitive (ui->gtk3_combo, TRUE);
|
||||||
removed_selected_theme = TRUE;
|
|
||||||
gtk_widget_set_sensitive (ui->gtk3_combo, themes->len > 0);
|
|
||||||
theme_preferences_gtk3_sync_remove_state (ui);
|
theme_preferences_gtk3_sync_remove_state (ui);
|
||||||
ui->gtk3_populating = FALSE;
|
ui->gtk3_populating = FALSE;
|
||||||
|
|
||||||
final_id = theme_preferences_gtk3_active_id (ui);
|
final_id = theme_preferences_gtk3_active_id (ui);
|
||||||
if (final_id)
|
if (final_id)
|
||||||
{
|
{
|
||||||
|
if (final_id[0] == '\0')
|
||||||
|
final_variant = THEME_GTK3_VARIANT_FOLLOW_SYSTEM;
|
||||||
|
else
|
||||||
final_variant = theme_gtk3_variant_for_theme (final_id);
|
final_variant = theme_gtk3_variant_for_theme (final_id);
|
||||||
if (!using_system_default || removed_selected_theme)
|
if (!using_system_default || removed_selected_theme)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user