metacity r4013 - in trunk: . src/core src/include



Author: tthurman
Date: Sat Nov  8 18:51:56 2008
New Revision: 4013
URL: http://svn.gnome.org/viewvc/metacity?rev=4013&view=rev

Log:
	* configure.in: added dependency on Zenity
	* src/core/keybindings.c: remove error_on_generic_command() and
	  error_on_terminal_command(); rewrite error_on_command
	  in terms of meta_show_dialog()
	* src/core/util.c: add meta_show_dialog() to call Zenity
	* src/include/util.h: ditto



Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/src/core/keybindings.c
   trunk/src/core/util.c
   trunk/src/include/util.h

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Sat Nov  8 18:51:56 2008
@@ -471,6 +471,10 @@
   GCONF_SCHEMAS_INSTALL_FALSE=
 fi
 
+AC_PATH_PROG(ZENITY, zenity, no)
+if test x"$ZENITY" = xno; then
+  AC_MSG_ERROR([zenity not found in your path - needed for dialogs])
+fi
 
 AC_ARG_ENABLE(debug,
 	[  --enable-debug		enable debugging],,

Modified: trunk/src/core/keybindings.c
==============================================================================
--- trunk/src/core/keybindings.c	(original)
+++ trunk/src/core/keybindings.c	Sat Nov  8 18:51:56 2008
@@ -36,6 +36,7 @@
 #include "place.h"
 #include "prefs.h"
 #include "effects.h"
+#include "util.h"
 
 #include <X11/keysym.h>
 #include <string.h>
@@ -2343,81 +2344,52 @@
 }
 
 static void
-error_on_generic_command (const char *key,
-                          const char *command,
-                          const char *message,
-                          int         screen_number,
-                          guint32     timestamp)
-{
-  GError *err;
-  char *argv[10];
-  char numbuf[32];
-  char timestampbuf[32];
-  
-  sprintf (numbuf, "%d", screen_number);
-  sprintf (timestampbuf, "%u", timestamp);
-  
-  argv[0] = METACITY_LIBEXECDIR"/metacity-dialog";
-  argv[1] = "--screen";
-  argv[2] = numbuf;
-  argv[3] = "--timestamp";
-  argv[4] = timestampbuf;
-  argv[5] = "--command-failed-error";
-  argv[6] = (char *)key;
-  argv[7] = (char*) (command ? command : "");
-  argv[8] = (char*) message;
-  argv[9] = NULL;
-  
-  err = NULL;
-  if (!g_spawn_async_with_pipes ("/",
-                                 argv,
-                                 NULL,
-                                 0,
-                                 NULL, NULL,
-                                 NULL,
-                                 NULL,
-                                 NULL,
-                                 NULL,
-                                 &err))
-    {
-      meta_warning (_("Error launching metacity-dialog to print an error about a command: %s\n"),
-                    err->message);
-      g_error_free (err);
-    }
-}
-
-static void
 error_on_command (int         command_index,
                   const char *command,
                   const char *message,
                   int         screen_number,
                   guint32     timestamp)
 {
-  char *key;
-  
-  meta_warning ("Error on command %d \"%s\": %s\n",
-                command_index, command, message);  
-
-  key = meta_prefs_get_gconf_key_for_command (command_index);
+  if (command_index < 0)
+    meta_warning ("Error on terminal command \"%s\": %s\n", command, message);  
+  else
+    meta_warning ("Error on command %d \"%s\": %s\n",
+                  command_index, command, message);  
 
-  error_on_generic_command (key, command, message, screen_number, timestamp);
-  
-  g_free (key);
-}
+  /*
+    metacity-dialog said:
+        
+    FIXME offer to change the value of the command's gconf key
+  */
+
+  if (command && strcmp(command, "")!=0)
+    {
+      char *text = g_strdup_printf (
+                                    /* Displayed when a keybinding which is
+                                     * supposed to launch a program fails.
+                                     */
+                                    _("There was an error running "
+                                      "<tt>%s</tt>:\n\n%s"),
+                                    command,
+                                    message);
+
+      meta_show_dialog ("--error",
+                        text,
+                        NULL,
+                        screen_number,
+                        NULL, NULL);
 
-static void
-error_on_terminal_command (const char *command,
-                           const char *message,
-                           int         screen_number,
-                           guint32     timestamp)
-{
-  const char *key;
-  
-  meta_warning ("Error on terminal command \"%s\": %s\n", command, message);  
+      g_free (text);
 
-  key = meta_prefs_get_gconf_key_for_terminal_command ();
-
-  error_on_generic_command (key, command, message, screen_number, timestamp);
+    }
+  else
+    {
+      meta_show_dialog ("--error",
+                        message,
+                        NULL,
+                        screen_number,
+                        NULL, NULL);
+    }
 }
 
 static void
@@ -3497,7 +3469,7 @@
 		  "keybinding press\n");
       
       s = g_strdup_printf (_("No terminal command has been defined.\n"));
-      error_on_terminal_command (NULL, s, screen->number, event->xkey.time);
+      error_on_command (-1, NULL, s, screen->number, event->xkey.time);
       g_free (s);
       
       return;
@@ -3506,8 +3478,8 @@
   err = NULL;
   if (!meta_spawn_command_line_async_on_screen (command, screen, &err))
     {
-      error_on_terminal_command (command, err->message, screen->number,
-		      		 event->xkey.time);
+      error_on_command (-1, command, err->message, screen->number,
+                        event->xkey.time);
       
       g_error_free (err);
     }

Modified: trunk/src/core/util.c
==============================================================================
--- trunk/src/core/util.c	(original)
+++ trunk/src/core/util.c	Sat Nov  8 18:51:56 2008
@@ -537,3 +537,75 @@
       break;
     }
 }
+
+void
+meta_show_dialog (const char *type,
+                  const char *message,
+                  const char *timeout,
+                  const gint screen_number,
+                  const char **columns,
+                  const char **entries)
+{
+  GError *error = NULL;
+  char *screen_number_text = g_strdup_printf("%d", screen_number);
+
+  /*
+  We want:
+  
+zenity --display X --screen S --title Metacity --error --text "There was an error running <tt>terminal</tt>:\n\nYour computer is on fire."
+  ** with no pipes
+  
+zenity --display X --screen S --title Metacity --question --text "<big><b><tt>%s</tt> is not responding.</b></big>\n\n<i>You may choose to wait a short while for it to continue or force the application to quit entirely.</i>"
+
+zenity --display X --screen S --title Metacity --list --timeout 240 --text "These windows do not support \"save current setup\" and will have to be restarted manually next time you log in." --column "Window" --column "Class" "Firefox" "foo" "Duke Nukem Forever" "bar"
+  */
+
+  const char **argvl;
+  int i=0;
+  GPid child_pid;
+
+  argvl = g_malloc(sizeof (char*) *
+                   (9 + (timeout?2:0))
+                   );
+
+  argvl[i++] = "zenity";
+  argvl[i++] = type;
+  argvl[i++] = "--screen";
+  argvl[i++] = screen_number_text;
+  argvl[i++] = "--title";
+  /* Translators: This is the title used on dialog boxes */
+  argvl[i++] = _("Metacity");
+  argvl[i++] = "--text";
+  argvl[i++] = message;
+  
+  if (timeout)
+    {
+      argvl[i++] = "--timeout";
+      argvl[i++] = timeout;
+    }
+
+  argvl[i] = NULL;
+
+  g_spawn_async_with_pipes (
+                            "/",
+                            (char**) argvl, /* ugh */
+                            NULL,
+                            G_SPAWN_SEARCH_PATH,
+                            NULL, NULL,
+                            &child_pid,
+                            NULL, NULL, NULL,
+                            &error
+                            );
+
+  g_free (argvl);
+  g_free (screen_number_text);
+
+  if (error)
+    {
+      meta_warning ("%s\n", error->message);
+      g_error_free (error);
+    }
+}
+
+/* eof util.c */
+

Modified: trunk/src/include/util.h
==============================================================================
--- trunk/src/include/util.h	(original)
+++ trunk/src/include/util.h	Sat Nov  8 18:51:56 2008
@@ -97,6 +97,13 @@
 
 void  meta_free_gslist_and_elements (GSList *list_to_deep_free);
 
+void meta_show_dialog (const char *type,
+                       const char *title,
+                       const char *message,
+                       gint timeout,
+                       const char **columns,
+                       const char **entries);
+
 /* To disable verbose mode, we make these functions into no-ops */
 #ifdef WITH_VERBOSE_MODE
 



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