gnome-settings-daemon r623 - in trunk: . plugins/xrandr



Author: federico
Date: Thu Dec  4 00:32:00 2008
New Revision: 623
URL: http://svn.gnome.org/viewvc/gnome-settings-daemon?rev=623&view=rev

Log:
Use the GError-ified API from gnome-rr-*
2008-12-02  Federico Mena Quintero  <federico novell com>

	* plugins/xrandr/gsd-xrandr-manager.c (error_message): Renamed
	from error_dialog(); use libnotify instead of ugly dialogs for
	error messages.
	(gsd_xrandr_manager_start):  Proxy the error from
	gnome_rr_screen_new() to our caller.
	(gsd_xrandr_manager_start): Display an error if we cannot apply
	the initially-loaded configuration.
	(generate_fn_f7_configs, get_allowed_rotations_for_output): Pass
	GError arguments to the gnome_rr_*() functions.
	(handle_fn_f7): Display an error if we cannot refresh the screen
	configuration or apply the new one.
	(output_rotation_item_activate_cb): Display an error if the
	rotation cannot be applied.

Signed-off-by: Federico Mena Quintero <federico novell com>

Modified:
   trunk/ChangeLog
   trunk/plugins/xrandr/Makefile.am
   trunk/plugins/xrandr/gsd-xrandr-manager.c

Modified: trunk/plugins/xrandr/Makefile.am
==============================================================================
--- trunk/plugins/xrandr/Makefile.am	(original)
+++ trunk/plugins/xrandr/Makefile.am	Thu Dec  4 00:32:00 2008
@@ -36,23 +36,25 @@
 	gsd-xrandr-manager.h	\
 	gsd-xrandr-manager.c
 
-libxrandr_la_CPPFLAGS = \
-	-I$(top_srcdir)/gnome-settings-daemon		\
-	-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \
+libxrandr_la_CPPFLAGS =						\
+	-I$(top_srcdir)/gnome-settings-daemon			\
+	-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\"	\
 	$(AM_CPPFLAGS)
 
-libxrandr_la_CFLAGS = \
+libxrandr_la_CFLAGS =			\
 	$(SETTINGS_PLUGIN_CFLAGS)	\
+	$(LIBNOTIFY_CFLAGS)		\
 	$(AM_CFLAGS)
 
-libxrandr_la_LDFLAGS = 		\
+libxrandr_la_LDFLAGS = 			\
 	$(GSD_PLUGIN_LDFLAGS)
 
-libxrandr_la_LIBADD  = 		\
-	$(SETTINGS_PLUGIN_LIBS)	\
+libxrandr_la_LIBADD  =			\
+	$(SETTINGS_PLUGIN_LIBS)		\
+	$(LIBNOTIFY_LIBS)		\
 	$(RANDR_LIBS)
 
-plugin_in_files = 		\
+plugin_in_files =			\
 	xrandr.gnome-settings-plugin.in
 
 plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin)

Modified: trunk/plugins/xrandr/gsd-xrandr-manager.c
==============================================================================
--- trunk/plugins/xrandr/gsd-xrandr-manager.c	(original)
+++ trunk/plugins/xrandr/gsd-xrandr-manager.c	Thu Dec  4 00:32:00 2008
@@ -37,6 +37,7 @@
 #include <gdk/gdkx.h>
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
+#include <libnotify/notify.h>
 
 #define GNOME_DESKTOP_USE_UNSTABLE_API
 
@@ -122,6 +123,7 @@
             ev->type == ClientMessage &&
             ev->xclient.message_type == gnome_randr_xatom ()) {
 
+                /* FMQ: this should happen with DBus */
                 gnome_rr_config_apply_stored (screen);
 
                 return GDK_FILTER_REMOVE;
@@ -478,7 +480,7 @@
         g_ptr_array_add (array, make_clone_setup (screen));
         g_ptr_array_add (array, make_laptop_setup (screen));
         g_ptr_array_add (array, make_other_setup (screen));
-        g_ptr_array_add (array, gnome_rr_config_new_stored (screen));
+        g_ptr_array_add (array, gnome_rr_config_new_stored (screen, NULL)); /* NULL-GError - if this can't read the stored config, no big deal */
         g_ptr_array_add (array, NULL);
 
         array = sanitize (array);
@@ -488,11 +490,27 @@
 }
 
 static void
+error_message (GsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text)
+{
+        GsdXrandrManagerPrivate *priv = mgr->priv;
+        NotifyNotification *notification;
+
+        g_assert (error_to_display == NULL || secondary_text == NULL);
+
+        notification = notify_notification_new_with_status_icon (primary_text,
+                                                                 error_to_display ? error_to_display->message : secondary_text,
+                                                                 GSD_XRANDR_ICON_NAME,
+                                                                 priv->status_icon);
+        notify_notification_show (notification, NULL); /* NULL-GError */
+}
+
+static void
 handle_fn_f7 (GsdXrandrManager *mgr)
 {
         GsdXrandrManagerPrivate *priv = mgr->priv;
         GnomeRRScreen *screen = priv->rw_screen;
         GnomeRRConfig *current;
+        GError *error;
         
         /* Theory of fn-F7 operation
          *
@@ -507,7 +525,16 @@
          *
          */
         g_print ("Handling fn-f7\n");
-        gnome_rr_screen_refresh (screen);
+
+        error = NULL;
+        if (!gnome_rr_screen_refresh (screen, &error)) {
+                char *str;
+
+                str = g_strdup_printf (_("Could not refresh the screen information: %s"), error->message);
+                g_error_free (error);
+
+                error_message (mgr, str, NULL, _("Trying to switch the monitor configuration anyway."));
+        }
 
         if (!priv->fn_f7_configs)
                 generate_fn_f7_configs (mgr);
@@ -536,9 +563,12 @@
                 print_configuration (priv->fn_f7_configs[mgr->priv->current_fn_f7_config], "new config");
 
                 g_print ("applying\n");
-                
-                gnome_rr_config_apply (priv->fn_f7_configs[mgr->priv->current_fn_f7_config],
-                                       screen);
+
+                error = NULL;
+                if (!gnome_rr_config_apply (priv->fn_f7_configs[mgr->priv->current_fn_f7_config], screen, &error)) {
+                        error_message (mgr, _("Could not switch the monitor configuration"), error, NULL);
+                        g_error_free (error);
+                }
         }
         else {
                 g_print ("no configurations generated\n");
@@ -807,7 +837,7 @@
 
                 output->rotation = rotation_to_test;
 
-                if (gnome_rr_config_applicable (priv->configuration, priv->rw_screen)) {
+                if (gnome_rr_config_applicable (priv->configuration, priv->rw_screen, NULL)) { /* NULL-GError */
                         (*out_num_rotations)++;
                         (*out_rotations) |= rotation_to_test;
                 }
@@ -840,19 +870,6 @@
 }
 
 static void
-error_dialog (const char *title, const char *msg)
-{
-        GtkWidget *dialog;
-
-        dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-                                         "%s", title);
-        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg);
-
-        gtk_dialog_run (GTK_DIALOG (dialog));
-        gtk_widget_destroy (dialog);
-}
-
-static void
 output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data)
 {
         GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data);
@@ -871,19 +888,20 @@
         output->rotation = rotation;
 
         error = NULL;
-        if (gnome_rr_config_save (priv->configuration, &error)) {
-                if (!gnome_rr_config_apply_stored (priv->rw_screen)) {
-                        error_dialog (_("The selected rotation could not be applied"),
-                                      _("An error occurred while configuring the screen"));
-                        /* FIXME: that message is really useless.  Make
-                         * gnome_rr_config_apply_stored() give us a meaningful
-                         * error message!
-                         */
-                }
-        } else {
-                error_dialog (_("The selected rotation could not be applied"),
-                              error->message);
-                g_error_free (error);
+        if (!gnome_rr_config_save (priv->configuration, &error)) {
+                error_message (manager, _("Could not save monitor configuration"), error, NULL);
+                if (error)
+                        g_error_free (error);
+
+                return;
+        }
+
+        if (!gnome_rr_config_apply_stored (priv->rw_screen, &error)) {
+                error_message (manager, _("The selected rotation could not be applied"), error, NULL);
+                if (error)
+                        g_error_free (error);
+
+                return;
         }
 }
 
@@ -1107,16 +1125,16 @@
 gsd_xrandr_manager_start (GsdXrandrManager *manager,
                           GError          **error)
 {
+        GError *my_error;
+
         g_debug ("Starting xrandr manager");
         gnome_settings_profile_start (NULL);
 
         manager->priv->rw_screen = gnome_rr_screen_new (
-                gdk_screen_get_default (), on_randr_event, manager);
+                gdk_screen_get_default (), on_randr_event, manager, error);
 
-        if (manager->priv->rw_screen == NULL) {
-                g_set_error (error, 0, 0, "Failed to initialize XRandR extension");
+        if (manager->priv->rw_screen == NULL)
                 return FALSE;
-        }
 
         manager->priv->running = TRUE;
         manager->priv->client = gconf_client_get_default ();
@@ -1145,7 +1163,14 @@
                 gdk_error_trap_pop ();
         }
 
-        gnome_rr_config_apply_stored (manager->priv->rw_screen);
+        my_error = NULL;
+        if (!gnome_rr_config_apply_stored (manager->priv->rw_screen, &my_error)) {
+                /* my_error can be null if there were no stored configurations */
+                if (my_error) {
+                        error_message (manager, _("Could not apply the stored configuration for monitors"), my_error, NULL);
+                        g_error_free (my_error);
+                }
+        }
 
         gdk_window_add_filter (gdk_get_default_root_window(),
                                (GdkFilterFunc)event_filter,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]