File gnome-desktop-bnc467558-bgo545115-randr-confirmation.diff of Package gnome-desktop

diff --git a/ChangeLog b/ChangeLog
index 1cc0317..8926e11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-02-03  Federico Mena Quintero  <federico@novell.com>
+
+	* configure.in (LT_VERSION): Increment the revision/age now that
+	gnome_rr_config_apply_stored() is the same as before; plus we have
+	the addition of gnome_rr_config_get_*_filename().
+
 2008-10-22  Vincent Untz  <vuntz@gnome.org>
 
 	* configure.in:
diff --git a/configure.in b/configure.in
index 57387f0..5a20213 100644
--- a/configure.in
+++ b/configure.in
@@ -19,7 +19,7 @@ AC_SUBST(ACLOCAL_AMFLAGS, "\${ACLOCAL_FLAGS}")
 #   change to C+1:0:0
 # - If the interface is the same as the previous version, change to C:R+1:A
 
-LT_VERSION=9:4:2
+LT_VERSION=10:0:3
 AC_SUBST(LT_VERSION)
 
 AM_MAINTAINER_MODE
diff --git a/libgnome-desktop/ChangeLog b/libgnome-desktop/ChangeLog
index 3166b49..387e944 100644
--- a/libgnome-desktop/ChangeLog
+++ b/libgnome-desktop/ChangeLog
@@ -1,3 +1,16 @@
+2009-02-03  Federico Mena Quintero  <federico@novell.com>
+
+	Don't break the API/ABI for gnome_rr_config_apply_stored(); just
+	deprecate it.
+
+	* gnome-rr-config.c (gnome_rr_config_apply_stored): Remove the
+	"filename" argument to avoid breaking the API/ABI.
+	(gnome_rr_config_apply_from_filename): New public function that
+	takes a filename.
+
+	* libgnomeui/gnome-rr-config.h (gnome_rr_config_apply_from_filename):
+	New prototype.
+
 2008-12-12  Vincent Untz  <vuntz@gnome.org>
 
 	* gnome-rr-config.c: (crtc_assignment_new):
diff --git a/libgnome-desktop/gnome-rr-config.c b/libgnome-desktop/gnome-rr-config.c
index 7880c7e..8b393b9 100644
--- a/libgnome-desktop/gnome-rr-config.c
+++ b/libgnome-desktop/gnome-rr-config.c
@@ -33,7 +33,8 @@
 #include "libgnomeui/gnome-rr-config.h"
 #include "edid.h"
 
-#define CONFIG_BASENAME "monitors.xml"
+#define CONFIG_INTENDED_BASENAME "monitors.xml"
+#define CONFIG_BACKUP_BASENAME "monitors.xml.backup"
 
 /* In version 0 of the config file format, we had several <configuration>
  * toplevel elements and no explicit version number.  So, the filed looked
@@ -77,9 +78,6 @@ static void             crtc_assignment_free  (CrtcAssignment   *assign);
 static void             output_free           (GnomeOutputInfo  *output);
 static GnomeOutputInfo *output_copy           (GnomeOutputInfo  *output);
 
-static gchar *get_old_config_filename (void);
-static gchar *get_config_filename (void);
-
 typedef struct Parser Parser;
 
 /* Parser for monitor configurations */
@@ -423,42 +421,6 @@ out:
     return result;
 }
 
-static GnomeRRConfig **
-configurations_read (GError **error)
-{
-    char *filename;
-    GnomeRRConfig **configs;
-    GError *err;
-
-    /* Try the new configuration file... */
-
-    filename = get_config_filename ();
-
-    err = NULL;
-    
-    configs = configurations_read_from_file (filename, &err);
-
-    g_free (filename);
-
-    if (err)
-    {
-	if (g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
-	{
-	    g_error_free (err);
-	    
-	    /* Okay, so try the old configuration file */
-	    filename = get_old_config_filename ();
-	    configs = configurations_read_from_file (filename, error);
-	    g_free (filename);
-	}
-	else
-	{
-	    g_propagate_error (error, err);
-	}
-    }
-    return configs;
-}
-
 GnomeRRConfig *
 gnome_rr_config_new_current (GnomeRRScreen *screen)
 {
@@ -915,16 +877,24 @@ gnome_rr_config_applicable (GnomeRRConfig  *configuration,
 
 /* Database management */
 
-static gchar *
-get_old_config_filename (void)
+static void
+ensure_config_directory (void)
+{
+    g_mkdir_with_parents (g_get_user_config_dir (), 0700);
+}
+
+char *
+gnome_rr_config_get_backup_filename (void)
 {
-    return g_build_filename (g_get_home_dir(), ".gnome2", CONFIG_BASENAME, NULL);
+    ensure_config_directory ();
+    return g_build_filename (g_get_user_config_dir (), CONFIG_BACKUP_BASENAME, NULL);
 }
 
-static gchar *
-get_config_filename (void)
+char *
+gnome_rr_config_get_intended_filename (void)
 {
-    return g_build_filename (g_get_user_config_dir (), CONFIG_BASENAME, NULL);
+    ensure_config_directory ();
+    return g_build_filename (g_get_user_config_dir (), CONFIG_INTENDED_BASENAME, NULL);
 }
 
 static const char *
@@ -1054,7 +1024,8 @@ gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
     GnomeRRConfig **configurations;
     GString *output;
     int i;
-    gchar *filename;
+    gchar *intended_filename;
+    gchar *backup_filename;
     gboolean result;
 
     g_return_val_if_fail (configuration != NULL, FALSE);
@@ -1062,7 +1033,10 @@ gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
 
     output = g_string_new ("");
 
-    configurations = configurations_read (NULL); /* NULL-GError */
+    backup_filename = gnome_rr_config_get_backup_filename ();
+    intended_filename = gnome_rr_config_get_intended_filename ();
+
+    configurations = configurations_read_from_file (intended_filename, NULL); /* NULL-GError */
     
     g_string_append_printf (output, "<monitors version=\"1\">\n");
 
@@ -1081,20 +1055,16 @@ gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
 
     g_string_append_printf (output, "</monitors>\n");
 
-    filename = get_config_filename ();
-    result = g_file_set_contents (filename, output->str, -1, error);
-    g_free (filename);
+    /* backup the file first */
+    rename (intended_filename, backup_filename); /* no error checking because the intended file may not even exist */
 
-    if (result)
-    {
-	/* Only remove the old config file if we were successful in saving the new one */
+    result = g_file_set_contents (intended_filename, output->str, -1, error);
 
-	filename = get_old_config_filename ();
-	if (g_file_test (filename, G_FILE_TEST_EXISTS))
-	    g_unlink (filename);
+    if (!result)
+	rename (backup_filename, intended_filename); /* no error checking because the backup may not even exist */
 
-	g_free (filename);
-    }
+    g_free (backup_filename);
+    g_free (intended_filename);
 
     return result;
 }
@@ -1117,8 +1087,8 @@ gnome_rr_config_copy (GnomeRRConfig *config)
     return copy;
 }
 
-GnomeRRConfig *
-gnome_rr_config_new_stored (GnomeRRScreen *screen, GError **error)
+static GnomeRRConfig *
+config_new_stored (GnomeRRScreen *screen, const char *filename, GError **error)
 {
     GnomeRRConfig *current;
     GnomeRRConfig **configs;
@@ -1129,7 +1099,7 @@ gnome_rr_config_new_stored (GnomeRRScreen *screen, GError **error)
     
     current = gnome_rr_config_new_current (screen);
     
-    configs = configurations_read (error);
+    configs = configurations_read_from_file (filename, error);
 
     result = NULL;
     if (configs)
@@ -1157,6 +1127,21 @@ gnome_rr_config_new_stored (GnomeRRScreen *screen, GError **error)
     return result;
 }
 
+GnomeRRConfig *
+gnome_rr_config_new_stored (GnomeRRScreen *screen, GError **error)
+{
+    char *intended_filename;
+    GnomeRRConfig *config;
+
+    intended_filename = gnome_rr_config_get_intended_filename ();
+
+    config = config_new_stored (screen, intended_filename, error);
+
+    g_free (intended_filename);
+
+    return config;
+}
+
 gboolean
 gnome_rr_config_apply (GnomeRRConfig *config,
 		       GnomeRRScreen *screen,
@@ -1185,13 +1170,70 @@ gnome_rr_config_apply (GnomeRRConfig *config,
     return result;
 }
 
+/**
+ * gnome_rr_config_apply_stored:
+ * @screen: A #GnomeRRScreen
+ * @error: Location to store error, or %NULL
+ *
+ * See the documentation for gnome_rr_config_apply_from_filename().  This
+ * function simply calls that other function with a filename of
+ * gnome_rr_config_get_intended_filename().
+
+ * @Deprecated: 2.26: Use gnome_rr_config_apply_from_filename() instead and pass it
+ * the filename from gnome_rr_config_get_intended_filename().
+ */
 gboolean
 gnome_rr_config_apply_stored (GnomeRRScreen *screen, GError **error)
 {
+    char *filename;
+    gboolean result;
+
+    filename = gnome_rr_config_get_intended_filename ();
+    result = gnome_rr_config_apply_from_filename (screen, filename, error);
+    g_free (filename);
+
+    return result;
+}
+
+/* gnome_rr_config_apply_from_filename:
+ * @screen: A #GnomeRRScreen
+ * @filename: Path of the file to look in for stored RANDR configurations.
+ * @error: Location to store error, or %NULL
+ *
+ * First, this function refreshes the @screen to match the current RANDR
+ * configuration from the X server.  Then, it tries to load the file in
+ * @filename and looks for suitable matching RANDR configurations in the file;
+ * if one is found, that configuration will be applied to the current set of
+ * RANDR outputs.
+ *
+ * Typically, @filename is the result of gnome_rr_config_get_intended_filename() or
+ * gnome_rr_config_get_backup_filename().
+ *
+ * Returns: TRUE if the RANDR configuration was loaded and applied from
+ * $(XDG_CONFIG_HOME)/monitors.xml, or FALSE otherwise:
+ *
+ * If the current RANDR configuration could not be refreshed, the @error will
+ * have a domain of #GNOME_RR_ERROR and a corresponding error code.
+ *
+ * If the file in question is loaded successfully but the configuration cannot
+ * be applied, the @error will have a domain of #GNOME_RR_ERROR.  Note that an
+ * error code of #GNOME_RR_ERROR_NO_MATCHING_CONFIG is not a real error; it
+ * simply means that there were no stored configurations that match the current
+ * set of RANDR outputs.
+ *
+ * If the file in question cannot be loaded, the @error will have a domain of
+ * #G_FILE_ERROR.  Note that an error code of G_FILE_ERROR_NOENT is not really
+ * an error, either; it means that there was no stored configuration file and so
+ * nothing is changed.
+ */
+gboolean
+gnome_rr_config_apply_from_filename (GnomeRRScreen *screen, const char *filename, GError **error)
+{
     GnomeRRConfig *stored;
     GError *my_error;
 
     g_return_val_if_fail (screen != NULL, FALSE);
+    g_return_val_if_fail (filename != NULL, FALSE);
     g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     my_error = NULL;
@@ -1204,7 +1246,7 @@ gnome_rr_config_apply_stored (GnomeRRScreen *screen, GError **error)
 	    /* This means the screen didn't change, so just proceed */
     }
 
-    stored = gnome_rr_config_new_stored (screen, error);
+    stored = config_new_stored (screen, filename, error);
 
     if (stored)
     {
diff --git a/libgnome-desktop/libgnomeui/gnome-rr-config.h b/libgnome-desktop/libgnomeui/gnome-rr-config.h
index a59db55..aeed881 100644
--- a/libgnome-desktop/libgnomeui/gnome-rr-config.h
+++ b/libgnome-desktop/libgnomeui/gnome-rr-config.h
@@ -88,10 +88,18 @@ gboolean	gnome_rr_config_apply        (GnomeRRConfig  *configuration,
 					      GError        **error);
 gboolean        gnome_rr_config_apply_stored (GnomeRRScreen  *screen,
 					      GError        **error);
+
+gboolean        gnome_rr_config_apply_from_filename (GnomeRRScreen  *screen,
+						     const char     *filename,
+						     GError        **error);
+
 gboolean        gnome_rr_config_applicable   (GnomeRRConfig  *configuration,
 					      GnomeRRScreen  *screen,
 					      GError        **error);
 
+char *gnome_rr_config_get_backup_filename (void);
+char *gnome_rr_config_get_intended_filename (void);
+
 /* A utility function that isn't really in the spirit of this file, but I don't
  * don't know a better place for it.
  */
openSUSE Build Service is sponsored by