astrognome/src/ag-settings.c

95 lines
2.3 KiB
C
Raw Normal View History

#include "ag-settings.h"
#define SETTINGS_SCHEMA_ID_MAIN "eu.polonkai.gergely.Astrognome"
#define SETTINGS_SCHEMA_ID_WINDOW "eu.polonkai.gergely.Astrognome.state.window"
#define SETTINGS_SCHEMA_ID_CHART "eu.polonkai.gergely.Astrognome.state.chart"
static AgSettings *singleton = NULL;
struct _AgSettingsPrivate {
GSettings *settings_main;
GSettings *settings_window;
GSettings *settings_chart;
};
2014-06-29 14:53:52 +00:00
G_DEFINE_TYPE_WITH_PRIVATE(AgSettings, ag_settings, G_TYPE_OBJECT);
static void
ag_settings_init(AgSettings *settings)
{
2014-07-03 16:15:48 +00:00
AgSettingsPrivate *priv = ag_settings_get_instance_private(settings);
priv->settings_main = g_settings_new(SETTINGS_SCHEMA_ID_MAIN);
2014-07-03 16:15:48 +00:00
priv->settings_window = g_settings_new(SETTINGS_SCHEMA_ID_WINDOW);
priv->settings_chart = g_settings_new(SETTINGS_SCHEMA_ID_CHART);
}
static void
ag_settings_dispose(GObject *object)
{
AgSettingsPrivate *priv = ag_settings_get_instance_private(
AG_SETTINGS(object)
);
2014-07-03 16:15:48 +00:00
g_clear_object(&priv->settings_window);
g_clear_object(&priv->settings_chart);
g_clear_object(&priv->settings_main);
G_OBJECT_CLASS(ag_settings_parent_class)->dispose(object);
}
static void
ag_settings_finalize(GObject *object)
{
singleton = NULL;
2014-07-03 16:15:48 +00:00
G_OBJECT_CLASS(ag_settings_parent_class)->finalize(object);
}
static void
ag_settings_class_init(AgSettingsClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
2013-09-21 16:43:48 +00:00
gobject_class->dispose = ag_settings_dispose;
gobject_class->finalize = ag_settings_finalize;
}
AgSettings *
ag_settings_get(void)
{
if (!singleton) {
singleton = AG_SETTINGS(g_object_new(AG_TYPE_SETTINGS, NULL));
} else {
g_object_ref(singleton);
}
g_assert(singleton);
return singleton;
}
GSettings *
ag_settings_peek_main_settings(AgSettings *settings)
{
AgSettingsPrivate *priv = ag_settings_get_instance_private(settings);
return priv->settings_main;
}
GSettings *
ag_settings_peek_window_settings(AgSettings *settings)
{
2014-07-03 16:15:48 +00:00
AgSettingsPrivate *priv = ag_settings_get_instance_private(settings);
return priv->settings_window;
}
GSettings *
ag_settings_peek_chart_settings(AgSettings *settings)
{
2014-07-03 16:15:48 +00:00
AgSettingsPrivate *priv = ag_settings_get_instance_private(settings);
2014-07-03 16:15:48 +00:00
return priv->settings_chart;
}