2014-09-26 13:01:19 +00:00
|
|
|
/* ag-preferences.c - Preferences dialog for Astrognome
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Polonkai Gergely
|
|
|
|
*
|
|
|
|
* Astrognome is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 3 of the License,
|
|
|
|
* or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Astrognome is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this software; if not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2013-09-21 19:54:35 +00:00
|
|
|
#include <gtk/gtk.h>
|
2014-07-18 19:06:50 +00:00
|
|
|
#include <swe-glib.h>
|
2014-09-14 12:30:27 +00:00
|
|
|
#include <stdlib.h>
|
2013-09-21 19:54:35 +00:00
|
|
|
|
|
|
|
#include "ag-settings.h"
|
2014-06-30 20:51:15 +00:00
|
|
|
#include "ag-preferences.h"
|
2014-09-14 12:30:27 +00:00
|
|
|
#include "ag-display-theme.h"
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
static GtkWidget *prefs_dialog = NULL;
|
|
|
|
|
|
|
|
typedef struct _AgPreferencesPrivate {
|
|
|
|
GtkCheckButton *maximized;
|
2014-07-04 11:13:38 +00:00
|
|
|
GtkCheckButton *planet_chars;
|
|
|
|
GtkCheckButton *aspect_chars;
|
2014-07-18 19:06:50 +00:00
|
|
|
GtkWidget *house_system;
|
|
|
|
GtkListStore *house_system_model;
|
2014-09-14 12:30:27 +00:00
|
|
|
GtkWidget *display_theme;
|
|
|
|
GtkListStore *display_theme_model;
|
2014-07-04 11:13:38 +00:00
|
|
|
|
2013-09-21 19:54:35 +00:00
|
|
|
AgSettings *settings;
|
2014-06-30 20:51:15 +00:00
|
|
|
} AgPreferencesPrivate;
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE(AgPreferences, ag_preferences, GTK_TYPE_DIALOG);
|
2013-09-21 19:54:35 +00:00
|
|
|
|
|
|
|
static void
|
2014-06-30 20:51:15 +00:00
|
|
|
ag_preferences_finalize(GObject *gobject)
|
2013-09-21 19:54:35 +00:00
|
|
|
{
|
2014-06-30 20:51:15 +00:00
|
|
|
AgPreferencesPrivate *priv;
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
priv = ag_preferences_get_instance_private(AG_PREFERENCES(gobject));
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
g_clear_object(&priv->settings);
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
G_OBJECT_CLASS(ag_preferences_parent_class)->finalize(gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ag_preferences_response(GtkDialog *dlg, gint response_id)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(dlg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ag_preferences_class_init(AgPreferencesClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
|
|
|
|
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS(klass);
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
object_class->finalize = ag_preferences_finalize;
|
|
|
|
dialog_class->response = ag_preferences_response;
|
|
|
|
|
2014-07-11 08:33:04 +00:00
|
|
|
gtk_widget_class_set_template_from_resource(
|
|
|
|
widget_class,
|
|
|
|
"/eu/polonkai/gergely/Astrognome/ui/ag-preferences.ui"
|
|
|
|
);
|
|
|
|
gtk_widget_class_bind_template_child_private(
|
|
|
|
widget_class,
|
|
|
|
AgPreferences,
|
|
|
|
maximized
|
|
|
|
);
|
|
|
|
gtk_widget_class_bind_template_child_private(
|
|
|
|
widget_class,
|
|
|
|
AgPreferences,
|
|
|
|
planet_chars
|
|
|
|
);
|
|
|
|
gtk_widget_class_bind_template_child_private(
|
|
|
|
widget_class,
|
|
|
|
AgPreferences,
|
|
|
|
aspect_chars
|
|
|
|
);
|
2014-07-18 19:06:50 +00:00
|
|
|
gtk_widget_class_bind_template_child_private(
|
|
|
|
widget_class,
|
|
|
|
AgPreferences,
|
|
|
|
house_system
|
|
|
|
);
|
|
|
|
gtk_widget_class_bind_template_child_private(
|
|
|
|
widget_class,
|
|
|
|
AgPreferences,
|
|
|
|
house_system_model
|
|
|
|
);
|
2014-09-14 12:30:27 +00:00
|
|
|
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
|
|
|
|
);
|
2014-07-18 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ag_preferences_add_house_system(GsweHouseSystemInfo *house_system_info,
|
|
|
|
AgPreferencesPrivate *priv)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GEnumClass *house_system_type = g_type_class_ref(GSWE_TYPE_HOUSE_SYSTEM);
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
|
|
|
|
enum_value = g_enum_get_value(
|
|
|
|
house_system_type,
|
|
|
|
gswe_house_system_info_get_house_system(house_system_info)
|
|
|
|
);
|
|
|
|
gtk_list_store_append(priv->house_system_model, &iter);
|
|
|
|
gtk_list_store_set(
|
|
|
|
priv->house_system_model, &iter,
|
|
|
|
0, enum_value->value_nick,
|
|
|
|
1, gswe_house_system_info_get_name(house_system_info),
|
|
|
|
-1
|
|
|
|
);
|
2014-06-30 20:51:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-14 12:30:27 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
static void
|
|
|
|
ag_preferences_init(AgPreferences *prefs)
|
|
|
|
{
|
2014-07-04 11:13:38 +00:00
|
|
|
GSettings *settings_window,
|
|
|
|
*settings_main;
|
2014-07-18 19:06:50 +00:00
|
|
|
GtkCellRenderer *cell_renderer;
|
2014-09-14 12:30:27 +00:00
|
|
|
GList *house_system_list = gswe_all_house_systems(),
|
|
|
|
*display_theme_list = ag_display_theme_get_list();
|
|
|
|
AgPreferencesPrivate *priv = ag_preferences_get_instance_private(prefs);
|
2014-06-30 20:51:15 +00:00
|
|
|
|
|
|
|
gtk_widget_init_template(GTK_WIDGET(prefs));
|
|
|
|
priv->settings = ag_settings_get();
|
2014-07-18 19:06:50 +00:00
|
|
|
g_list_foreach(
|
|
|
|
house_system_list,
|
|
|
|
(GFunc)ag_preferences_add_house_system,
|
|
|
|
priv
|
|
|
|
);
|
|
|
|
cell_renderer = gtk_cell_renderer_text_new();
|
|
|
|
gtk_cell_layout_pack_start(
|
|
|
|
GTK_CELL_LAYOUT(priv->house_system),
|
|
|
|
cell_renderer,
|
|
|
|
TRUE
|
|
|
|
);
|
|
|
|
gtk_cell_layout_set_attributes(
|
|
|
|
GTK_CELL_LAYOUT(priv->house_system),
|
|
|
|
cell_renderer,
|
|
|
|
"text", 1,
|
|
|
|
NULL
|
|
|
|
);
|
2014-06-30 20:51:15 +00:00
|
|
|
|
2014-09-14 12:30:27 +00:00
|
|
|
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
|
|
|
|
);
|
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
settings_window = ag_settings_peek_window_settings(priv->settings);
|
2014-07-11 08:33:04 +00:00
|
|
|
g_settings_bind(
|
|
|
|
settings_window,
|
|
|
|
"maximized",
|
|
|
|
priv->maximized,
|
|
|
|
"active",
|
|
|
|
G_SETTINGS_BIND_DEFAULT
|
|
|
|
);
|
2014-07-04 11:13:38 +00:00
|
|
|
|
|
|
|
settings_main = ag_settings_peek_main_settings(priv->settings);
|
2014-07-11 08:33:04 +00:00
|
|
|
g_settings_bind(
|
|
|
|
settings_main,
|
|
|
|
"planets-char",
|
|
|
|
priv->planet_chars,
|
|
|
|
"active",
|
|
|
|
G_SETTINGS_BIND_DEFAULT
|
|
|
|
);
|
|
|
|
g_settings_bind(
|
|
|
|
settings_main,
|
|
|
|
"aspects-char",
|
|
|
|
priv->aspect_chars,
|
|
|
|
"active",
|
|
|
|
G_SETTINGS_BIND_DEFAULT
|
|
|
|
);
|
2014-07-18 19:06:50 +00:00
|
|
|
g_settings_bind(
|
|
|
|
settings_main,
|
|
|
|
"default-house-system",
|
|
|
|
priv->house_system,
|
|
|
|
"active-id",
|
|
|
|
G_SETTINGS_BIND_DEFAULT
|
|
|
|
);
|
2014-09-14 12:30:27 +00:00
|
|
|
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
|
|
|
|
);
|
2013-09-21 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-30 20:51:15 +00:00
|
|
|
ag_preferences_show_dialog(GtkWindow *parent)
|
2013-09-21 19:54:35 +00:00
|
|
|
{
|
2014-06-30 20:51:15 +00:00
|
|
|
g_return_if_fail(GTK_IS_WINDOW(parent));
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
if (prefs_dialog == NULL) {
|
|
|
|
prefs_dialog = GTK_WIDGET(g_object_new(AG_TYPE_PREFERENCES, NULL));
|
2014-07-11 08:33:04 +00:00
|
|
|
g_signal_connect(
|
|
|
|
prefs_dialog,
|
|
|
|
"destroy",
|
|
|
|
G_CALLBACK(gtk_widget_destroyed),
|
|
|
|
&prefs_dialog
|
|
|
|
);
|
2014-06-30 20:51:15 +00:00
|
|
|
}
|
2013-09-21 19:54:35 +00:00
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
if (parent != gtk_window_get_transient_for(GTK_WINDOW(prefs_dialog))) {
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(prefs_dialog), parent);
|
2013-09-21 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 20:51:15 +00:00
|
|
|
gtk_window_present(GTK_WINDOW(prefs_dialog));
|
|
|
|
}
|