[ubuntu-x] [PATCH 3/15] gnome-desktop: Revert support

Bryce Harrington bryce at canonical.com
Thu Apr 10 20:52:42 BST 2008


gnome-desktop:  104_gd-randr-revert-support.patch (LP: #197673)

Adds support for a "revert dialog".  Without a revert capability, if you
happens to select a configuration in the GUI that fails on your machine,
that config will be written to .gnome2/monitors.xml permanently, and
will always be used on boot up, with no way to fix it short of a
reinstall or hand-removing ~/.gnome2/monitors.xml; this was found to be
highly unpopular among our users.

Perhaps there is a smarter way to implement this capability.  This adds
a configuration_save_onetime() for writing a "one time" monitors xml
file, that is removed after first application.  The caller can use this
to "test" a new config, and then write it permanently using the existing
configuration_save() API call.

There might be some corner cases such as if the user had a missing or
corrupt monitors.xml and attempts to revert, but I've not tested this
exhaustively yet.  If this is taken upstream, we'll pass along
additional fixes as we run across them.

diff -Nur -x '*.orig' -x '*~' gnome-desktop-2.22.0/libgnome-desktop/libgnomeui/monitor-db.h gnome-desktop-2.22.0.new/libgnome-desktop/libgnomeui/monitor-db.h
--- gnome-desktop-2.22.0/libgnome-desktop/libgnomeui/monitor-db.h	2008-04-07 13:33:15.000000000 +0200
+++ gnome-desktop-2.22.0.new/libgnome-desktop/libgnomeui/monitor-db.h	2008-04-07 13:33:53.000000000 +0200
@@ -48,6 +48,8 @@
 					    Configuration  *config2);
 gboolean        configuration_save         (Configuration  *configuration,
 					    GError        **err);
+gboolean        configuration_save_onetime (Configuration  *configuration,
+					    GError        **err);
 void		configuration_sanitize     (Configuration  *configuration);
 gboolean	configuration_apply_stored (RWScreen       *screen);
 gboolean	configuration_applicable   (Configuration  *configuration,
diff -Nur -x '*.orig' -x '*~' gnome-desktop-2.22.0/libgnome-desktop/monitor-db.c gnome-desktop-2.22.0.new/libgnome-desktop/monitor-db.c
--- gnome-desktop-2.22.0/libgnome-desktop/monitor-db.c	2008-04-07 13:33:16.000000000 +0200
+++ gnome-desktop-2.22.0.new/libgnome-desktop/monitor-db.c	2008-04-07 13:33:17.000000000 +0200
@@ -1,3 +1,4 @@
+#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
@@ -727,6 +728,14 @@
 	    g_get_home_dir(), ".gnome2", "monitors.xml", NULL));
 }
 
+static const gchar *
+get_onetime_filename (void)
+{
+    return idle_free (
+	g_build_filename (
+	    g_get_home_dir(), ".gnome2", "monitors-onetime.xml", NULL));
+}
+
 static const char *
 get_rotation_name (RWRotation r)
 {
@@ -847,14 +856,14 @@
     }
 }
 
-gboolean
-configuration_save (Configuration *configuration, GError **err)
+static gboolean
+configuration_save_to_file (Configuration *configuration, GError **err, const gchar* filename)
 {
     Configuration **configurations;
     GString *output = g_string_new("");
     int i;
 
-    configurations = configurations_read (get_filename(), NULL);
+    configurations = configurations_read (filename, NULL);
     
     if (configurations)
     {
@@ -869,7 +878,25 @@
 
     emit_configuration (configuration, output);
 
-    return g_file_set_contents (get_filename(), output->str, -1, err);
+    if (g_file_set_contents (filename, output->str, -1, err)) {
+        return TRUE;
+    } else {
+        g_print("Failed to save to %s\n", filename);
+        g_print("Content was\n%s\n", output->str);
+        return FALSE;
+    }
+}
+
+gboolean
+configuration_save (Configuration *configuration, GError **err)
+{
+    return configuration_save_to_file (configuration, err, get_filename());
+}
+
+gboolean
+configuration_save_onetime (Configuration *configuration, GError **err)
+{
+    return configuration_save_to_file (configuration, err, get_onetime_filename());
 }
 
 static gboolean
@@ -905,20 +932,32 @@
 gboolean
 configuration_apply_stored (RWScreen *screen)
 {
-    char *file = g_build_filename (
-	g_get_home_dir(), ".gnome2", "monitors.xml", NULL);
-    Configuration **configs = configurations_read (file, NULL);
+    Configuration **configs;
     Configuration *current;
     Configuration *found;
-    gboolean result;
+    gboolean result = FALSE;
 
     if (!screen) {
         g_print("No valid screens to apply stored configuration\n");
         return FALSE;
     }
 
+    g_print ("Reading config file %s\n", get_onetime_filename());
+    configs = configurations_read (get_onetime_filename(), NULL);
+    if ( ! configs ) {
+        /* No monitors-onetime.xml file, so try monitors.xml */
+        configs = configurations_read (get_filename(), NULL);
+    } else {
+        /* monitors-onetime.xml was loaded; now remove it before trying anything so
+         * if there are problems, we won't re-load it again */
+        if (unlink(get_onetime_filename()) != 0) {
+            g_print("Cannot unlink %s - cowardly refusing to apply it\n", get_onetime_filename());
+            return FALSE;
+        }
+    }
+
     rw_screen_refresh (screen);
-    
+
     current = configuration_new_current (screen);
     if (configs)
     {
@@ -931,11 +970,10 @@
 	{
 	    result = FALSE;
 	}
-	
+
 	configurations_free (configs);
     }
-	
-    g_free (file);
+
     configuration_free (current);
 
     return result;



More information about the Ubuntu-x mailing list