Add default display theme selection to the Preferences

This commit is contained in:
Gergely Polonkai 2014-09-14 14:30:27 +02:00
parent c7f000ccc6
commit 2328f12305
2 changed files with 130 additions and 2 deletions

View File

@ -1,8 +1,10 @@
#include <gtk/gtk.h>
#include <swe-glib.h>
#include <stdlib.h>
#include "ag-settings.h"
#include "ag-preferences.h"
#include "ag-display-theme.h"
static GtkWidget *prefs_dialog = NULL;
@ -12,6 +14,8 @@ typedef struct _AgPreferencesPrivate {
GtkCheckButton *aspect_chars;
GtkWidget *house_system;
GtkListStore *house_system_model;
GtkWidget *display_theme;
GtkListStore *display_theme_model;
AgSettings *settings;
} AgPreferencesPrivate;
@ -75,6 +79,16 @@ ag_preferences_class_init(AgPreferencesClass *klass)
AgPreferences,
house_system_model
);
gtk_widget_class_bind_template_child_private(
widget_class,
AgPreferences,
display_theme
);
gtk_widget_class_bind_template_child_private(
widget_class,
AgPreferences,
display_theme_model
);
}
static void
@ -98,14 +112,68 @@ ag_preferences_add_house_system(GsweHouseSystemInfo *house_system_info,
);
}
static void
ag_preferences_add_display_theme(AgDisplayTheme *display_theme,
AgPreferencesPrivate *priv)
{
GtkTreeIter iter;
gchar *id_string = g_strdup_printf("%d", display_theme->id);
g_debug("Adding theme with ID %d ('%s')", display_theme->id, id_string);
gtk_list_store_append(priv->display_theme_model, &iter);
gtk_list_store_set(
priv->display_theme_model, &iter,
0, id_string,
1, display_theme->name,
-1
);
g_free(id_string);
}
static gboolean
ag_preferences_display_theme_get(GValue *value,
GVariant *variant,
gpointer user_data)
{
gint32 id = g_variant_get_int32(variant);
gchar *id_string = g_strdup_printf("%d", id);
g_debug("Converted %d to '%s'", id, id_string);
g_value_take_string(value, id_string);
return TRUE;
}
static GVariant *
ag_preferences_display_theme_set(const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
const gchar *id_string;
gint32 id;
GVariant *variant;
id_string = g_value_get_string(value);
id = atoi(id_string);
g_debug("Converted '%s' to %d", id_string, id);
variant = g_variant_new_int32(id);
return variant;
}
static void
ag_preferences_init(AgPreferences *prefs)
{
GSettings *settings_window,
*settings_main;
GList *house_system_list = gswe_all_house_systems();
AgPreferencesPrivate *priv = ag_preferences_get_instance_private(prefs);
GtkCellRenderer *cell_renderer;
GList *house_system_list = gswe_all_house_systems(),
*display_theme_list = ag_display_theme_get_list();
AgPreferencesPrivate *priv = ag_preferences_get_instance_private(prefs);
gtk_widget_init_template(GTK_WIDGET(prefs));
priv->settings = ag_settings_get();
@ -127,6 +195,24 @@ ag_preferences_init(AgPreferences *prefs)
NULL
);
g_list_foreach(
display_theme_list,
(GFunc)ag_preferences_add_display_theme,
priv
);
cell_renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(
GTK_CELL_LAYOUT(priv->display_theme),
cell_renderer,
TRUE
);
gtk_cell_layout_set_attributes(
GTK_CELL_LAYOUT(priv->display_theme),
cell_renderer,
"text", 1,
NULL
);
settings_window = ag_settings_peek_window_settings(priv->settings);
g_settings_bind(
settings_window,
@ -158,6 +244,17 @@ ag_preferences_init(AgPreferences *prefs)
"active-id",
G_SETTINGS_BIND_DEFAULT
);
g_settings_bind_with_mapping(
settings_main,
"default-display-theme",
priv->display_theme,
"active-id",
G_SETTINGS_BIND_DEFAULT,
ag_preferences_display_theme_get,
ag_preferences_display_theme_set,
NULL,
NULL
);
}
void

View File

@ -10,6 +10,14 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="display_theme_model">
<columns>
<!-- column-name display-theme-id -->
<column type="gchararray"/>
<!-- column-name display-theme-name -->
<column type="gchararray"/>
</columns>
</object>
<template class="AgPreferences" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="type_hint">normal</property>
@ -108,6 +116,29 @@
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Default display theme</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="display_theme">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">display_theme_model</property>
<property name="id_column">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>