Back to index

lightdm  1.3.2
configuration.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 Robert Ancell.
00003  * Author: Robert Ancell <robert.ancell@canonical.com>
00004  * 
00005  * This program is free software: you can redistribute it and/or modify it under
00006  * the terms of the GNU General Public License as published by the Free Software
00007  * Foundation, either version 3 of the License, or (at your option) any later
00008  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
00009  * license.
00010  */
00011 
00012 #include "configuration.h"
00013 
00014 struct ConfigurationPrivate
00015 {
00016     GKeyFile *key_file;
00017 };
00018 
00019 G_DEFINE_TYPE (Configuration, config, G_TYPE_OBJECT);
00020 
00021 static Configuration *configuration_instance = NULL;
00022 
00023 Configuration *
00024 config_get_instance (void)
00025 {
00026     if (!configuration_instance)
00027         configuration_instance = g_object_new (CONFIGURATION_TYPE, NULL);
00028     return configuration_instance;
00029 }
00030 
00031 gboolean
00032 config_load_from_file (Configuration *config, const gchar *path, GError **error)
00033 {
00034     return g_key_file_load_from_file (config->priv->key_file, path, G_KEY_FILE_NONE, error);
00035 }
00036 
00037 gchar **
00038 config_get_groups (Configuration *config)
00039 {
00040     return g_key_file_get_groups (config->priv->key_file, NULL);
00041 }
00042 
00043 gchar **
00044 config_get_keys (Configuration *config, const gchar *group_name)
00045 {
00046     return g_key_file_get_keys (config->priv->key_file, group_name, NULL, NULL);
00047 }
00048 
00049 gboolean
00050 config_has_key (Configuration *config, const gchar *section, const gchar *key)
00051 {
00052     return g_key_file_has_key (config->priv->key_file, section, key, NULL);
00053 }
00054 
00055 void
00056 config_set_string (Configuration *config, const gchar *section, const gchar *key, const gchar *value)
00057 {
00058     g_key_file_set_string (config->priv->key_file, section, key, value);
00059 }
00060 
00061 gchar *
00062 config_get_string (Configuration *config, const gchar *section, const gchar *key)
00063 {
00064     return g_key_file_get_string (config->priv->key_file, section, key, NULL);
00065 }
00066 
00067 void
00068 config_set_integer (Configuration *config, const gchar *section, const gchar *key, gint value)
00069 {
00070     g_key_file_set_integer (config->priv->key_file, section, key, value);
00071 }
00072 
00073 gint
00074 config_get_integer (Configuration *config, const gchar *section, const gchar *key)
00075 {
00076     return g_key_file_get_integer (config->priv->key_file, section, key, NULL);
00077 }
00078 
00079 void
00080 config_set_boolean (Configuration *config, const gchar *section, const gchar *key, gboolean value)
00081 {
00082     g_key_file_set_boolean (config->priv->key_file, section, key, value);
00083 }
00084 
00085 gboolean
00086 config_get_boolean (Configuration *config, const gchar *section, const gchar *key)
00087 {
00088     return g_key_file_get_boolean (config->priv->key_file, section, key, NULL);
00089 }
00090 
00091 static void
00092 config_init (Configuration *config)
00093 {
00094     config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, CONFIGURATION_TYPE, ConfigurationPrivate);
00095     config->priv->key_file = g_key_file_new ();  
00096 }
00097 
00098 static void
00099 config_finalize (GObject *object)
00100 {
00101     Configuration *self;
00102 
00103     self = CONFIGURATION (object);
00104 
00105     g_key_file_free (self->priv->key_file);
00106 
00107     G_OBJECT_CLASS (config_parent_class)->finalize (object);  
00108 }
00109 
00110 static void
00111 config_class_init (ConfigurationClass *klass)
00112 {
00113     GObjectClass *object_class = G_OBJECT_CLASS (klass);
00114 
00115     object_class->finalize = config_finalize;  
00116 
00117     g_type_class_add_private (klass, sizeof (ConfigurationPrivate));
00118 }