diff --git a/ChangeLog b/ChangeLog index 2a1b7f159..6a6021ba4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-08 Thomas Thurman + + * 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 + 2008-11-03 Olav Vitters * src/ui/theme-parser.c: Fix build by readding accidentally removed diff --git a/configure.in b/configure.in index 61a3010e1..07bfda128 100644 --- a/configure.in +++ b/configure.in @@ -471,6 +471,10 @@ else 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],, diff --git a/src/core/keybindings.c b/src/core/keybindings.c index b05fe275d..6b733d7c9 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -36,6 +36,7 @@ #include "place.h" #include "prefs.h" #include "effects.h" +#include "util.h" #include #include @@ -2342,50 +2343,6 @@ handle_switch_to_workspace (MetaDisplay *display, } } -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, @@ -2393,31 +2350,46 @@ error_on_command (int command_index, int screen_number, guint32 timestamp) { - char *key; - - meta_warning ("Error on command %d \"%s\": %s\n", - command_index, command, message); + 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); - key = meta_prefs_get_gconf_key_for_command (command_index); + /* + metacity-dialog said: + + FIXME offer to change the value of the command's gconf key + */ - error_on_generic_command (key, command, message, screen_number, timestamp); - - g_free (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 " + "%s:\n\n%s"), + command, + message); -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); + meta_show_dialog ("--error", + text, + NULL, + screen_number, + NULL, NULL); - key = meta_prefs_get_gconf_key_for_terminal_command (); + g_free (text); - 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 @@ handle_run_terminal (MetaDisplay *display, "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 @@ handle_run_terminal (MetaDisplay *display, 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); } diff --git a/src/core/util.c b/src/core/util.c index e0da863b9..ca7df62aa 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -537,3 +537,75 @@ meta_gravity_to_string (int gravity) 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 terminal:\n\nYour computer is on fire." + ** with no pipes + +zenity --display X --screen S --title Metacity --question --text "%s is not responding.\n\nYou may choose to wait a short while for it to continue or force the application to quit entirely." + +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 */ + diff --git a/src/include/util.h b/src/include/util.h index 161ae9382..5041f5ecc 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -97,6 +97,13 @@ char* meta_g_utf8_strndup (const gchar *src, gsize n); 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