2013-09-21 19:54:35 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "ag-settings.h"
|
2014-06-30 20:51:15 +00:00
|
|
|
#include "ag-preferences.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;
|
|
|
|
|
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-06-30 20:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ag_preferences_init(AgPreferences *prefs)
|
|
|
|
{
|
|
|
|
AgPreferencesPrivate *priv;
|
2014-07-04 11:13:38 +00:00
|
|
|
GSettings *settings_window,
|
|
|
|
*settings_main;
|
2014-06-30 20:51:15 +00:00
|
|
|
|
|
|
|
priv = ag_preferences_get_instance_private(prefs);
|
|
|
|
gtk_widget_init_template(GTK_WIDGET(prefs));
|
|
|
|
|
|
|
|
priv->settings = ag_settings_get();
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
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));
|
|
|
|
}
|