Index: glib/gkeyfile.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gkeyfile.c,v
retrieving revision 1.27
diff -u -r1.27 gkeyfile.c
--- glib/gkeyfile.c	17 Mar 2005 19:28:15 -0000	1.27
+++ glib/gkeyfile.c	15 Apr 2005 08:12:00 -0000
@@ -130,11 +130,11 @@
                                                                     GKeyFileGroup *group,
                                                                     GList         *pair_node);
 
-static void                  g_key_file_add_key                (GKeyFile               *key_file,
+static void                  g_key_file_real_add_key           (GKeyFile               *key_file,
 								GKeyFileGroup          *group,
 								const gchar            *key,
 								const gchar            *value);
-static void                  g_key_file_add_group              (GKeyFile               *key_file,
+static void                  g_key_file_real_add_group         (GKeyFile               *key_file,
 								const gchar            *group_name);
 static void                  g_key_file_key_value_pair_free    (GKeyFileKeyValuePair   *pair);
 static gboolean              g_key_file_line_is_comment        (const gchar            *line);
@@ -740,7 +740,7 @@
   group_name = g_strndup (group_name_start, 
                           group_name_end - group_name_start);
   
-  g_key_file_add_group (key_file, group_name);
+  g_key_file_real_add_group (key_file, group_name);
   g_free (group_name);
 }
 
@@ -813,7 +813,7 @@
   locale = key_get_locale (key);
 
   if (locale == NULL || g_key_file_locale_is_interesting (key_file, locale))
-    g_key_file_add_key (key_file, key_file->current_group, key, value);
+    g_key_file_real_add_key (key_file, key_file->current_group, key, value);
 
   g_free (locale);
   g_free (key);
@@ -1203,17 +1203,17 @@
 
   if (!group)
     {
-      g_key_file_add_group (key_file, group_name);
+      g_key_file_real_add_group (key_file, group_name);
       group = (GKeyFileGroup *) key_file->groups->data;
 
-      g_key_file_add_key (key_file, group, key, value);
+      g_key_file_real_add_key (key_file, group, key, value);
     }
   else
     {
       pair = g_key_file_lookup_key_value_pair (key_file, group, key);
 
       if (!pair)
-        g_key_file_add_key (key_file, group, key, value);
+        g_key_file_real_add_key (key_file, group, key, value);
       else
         {
           g_free (pair->value);
@@ -2603,8 +2603,8 @@
 }
 
 static void
-g_key_file_add_group (GKeyFile    *key_file,
-		      const gchar *group_name)
+g_key_file_real_add_group (GKeyFile    *key_file,
+		           const gchar *group_name)
 {
   GKeyFileGroup *group;
 
@@ -2623,6 +2623,34 @@
     key_file->start_group = group;
 }
 
+/**
+ * g_key_file_add_group:
+ * @key_file: a #GKeyFile
+ * @group_name: the new group
+ * @err: return location for a #GError or %NULL
+ *
+ * Adds a new group, @group_name, to a #GKeyFile.
+ **/
+void
+g_key_file_add_group (GKeyFile     *key_file,
+		      const gchar  *group_name,
+		      GError      **error)
+{
+  g_return_if_fail (key_file != NULL);
+  g_return_if_fail (group_name != NULL);
+
+  if (g_file_has_group (key_file, group_name))
+    {
+      g_set_error (error, G_KEY_FILE_ERROR,
+		   G_KEY_FILE_ERROR_DUPLICATE_GROUP,
+		   _("Key file already have group '%s'"),
+		   group_name);
+      return;
+    }
+
+  g_key_file_real_add_group (key_file, group_name);
+}
+
 static void
 g_key_file_key_value_pair_free (GKeyFileKeyValuePair *pair)
 {
@@ -2774,10 +2802,10 @@
 }
 
 static void
-g_key_file_add_key (GKeyFile      *key_file,
-		    GKeyFileGroup *group,
-		    const gchar   *key,
-		    const gchar   *value)
+g_key_file_real_add_key (GKeyFile      *key_file,
+		         GKeyFileGroup *group,
+		         const gchar   *key,
+		         const gchar   *value)
 {
   GKeyFileKeyValuePair *pair;
 
@@ -2792,6 +2820,47 @@
 }
 
 /**
+ * g_key_file_add_key:
+ * @key_file: a #GKeyFile
+ * @group_name: a group name where to add the key
+ * @key_name: the name of the new key
+ * @err: return location for a #GError or %NULL
+ *
+ * Adds a new key, @key_name, to @group_name.  The key is unset: you must set
+ * a value using the g_key_file_set_* functions.
+ **/
+void
+g_key_value_add_key (GKeyFile     *key_file,
+	             const gchar  *group_name,
+		     const gchar  *key_name,
+		     GError      **err)
+{
+  g_return_if_fail (key_file != NULL);
+  g_return_if_fail (group_name != NULL);
+  g_return_if_fail (key_name != NULL);
+
+  if (! g_key_file_has_group (key_file, group_name))
+    {
+      g_set_error (error, G_KEY_FILE_ERROR,
+		   G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
+		   _("Key file does not have group '%s'"),
+		   group_name);
+      return;
+    }
+  
+  if (g_key_file_has_key (key_file, group_name, key_name))
+    {
+      g_set_error (error, G_KEY_FILE_ERROR,
+		   G_KEY_FILE_ERROR_DUPLICATE_KEY,
+		   _("Key file already have key '%s'"),
+		   key_name);
+      return;
+    }
+
+  g_key_file_real_add_key (key_file, group_name, key_name, NULL);
+}
+
+/**
  * g_key_file_remove_key:
  * @key_file: a #GKeyFile
  * @group_name: a group name
Index: glib/gkeyfile.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gkeyfile.h,v
retrieving revision 1.4
diff -u -r1.4 gkeyfile.h
--- glib/gkeyfile.h	28 Nov 2004 19:12:04 -0000	1.4
+++ glib/gkeyfile.h	15 Apr 2005 08:12:00 -0000
@@ -34,6 +34,8 @@
   G_KEY_FILE_ERROR_NOT_FOUND,
   G_KEY_FILE_ERROR_KEY_NOT_FOUND,
   G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
+  G_KEY_FILE_ERROR_DUPLICATE_KEY,
+  G_KEY_FILE_ERROR_DUPLICATE_GROUP,
   G_KEY_FILE_ERROR_INVALID_VALUE
 } GKeyFileError;
 
@@ -182,6 +184,13 @@
                                              const gchar          *group_name,
                                              const gchar          *key,
 					     GError              **error);
+void      g_key_file_add_key                (GKeyFile             *key_file,
+                                             const gchar          *group_name,
+					     const gchar          *key,
+					     GError              **error);
+void      g_key_file_add_group              (GKeyFile             *key_file,
+		                             const gchar          *group_name,
+					     GError              **error);
 void      g_key_file_remove_key             (GKeyFile             *key_file,
 					     const gchar          *group_name,
 					     const gchar          *key,
