[mutter: 31/209] Use zenity for the session management dialogue that warns about clueless clients, not metacity-dia



commit 0b3f45bb1bf8b73e4b409dba5d39479a3ae5443e
Author: Thomas James Alexander Thurman <tthurman src gnome org>
Date:   Fri Feb 20 19:48:04 2009 +0000

    	Use zenity for the session management dialogue that warns about
    	clueless clients, not metacity-dialog.  This is the last change
    	away from metacity-dialog and therefore closes #521914.
    	* src/Makefile.am:
    	* src/core/session.c:
    	* src/core/util.c:
    	* src/include/util.h:
    	* src/ui/metacity-dialog.c (deleted):
    
    
    svn path=/trunk/; revision=4163

 ChangeLog                |   12 ++
 src/Makefile.am          |    5 -
 src/core/session.c       |  142 ++++------------
 src/core/util.c          |   55 +++---
 src/include/util.h       |    4 +-
 src/ui/metacity-dialog.c |  438 ----------------------------------------------
 6 files changed, 76 insertions(+), 580 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f57bc0e..0244a1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-02-11  Thomas Thurman  <tthurman gnome org>
+
+	Use zenity for the session management dialogue that warns about
+	clueless clients, not metacity-dialog.  This is the last change
+	away from metacity-dialog and therefore closes #521914.
+
+	* src/Makefile.am:
+	* src/core/session.c:
+	* src/core/util.c:
+	* src/include/util.h:
+	* src/ui/metacity-dialog.c (deleted):
+
 2009-02-12  Matthias Clasen  <mclasen redhat com>
 
 	* src/core/bell.c (meta_bell_set_audible): Now that we are
diff --git a/src/Makefile.am b/src/Makefile.am
index 4c9e39c..bd3420f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -134,9 +134,6 @@ libmetacityinclude_HEADERS =			\
 metacity_theme_viewer_SOURCES=  \
 	ui/theme-viewer.c
 
-metacity_dialog_SOURCES= 	\
-	ui/metacity-dialog.c
-
 schema_bindings_SOURCES =       \
         core/schema-bindings.c			\
 	metacity.schemas.in.in
@@ -147,12 +144,10 @@ metacity.schemas.in: schema_bindings ${srcdir}/metacity.schemas.in.in
 	${builddir}/schema_bindings ${srcdir}/metacity.schemas.in.in ${builddir}/metacity.schemas.in
 
 bin_PROGRAMS=metacity metacity-theme-viewer
-libexec_PROGRAMS=metacity-dialog
 
 EFENCE=
 metacity_LDADD= METACITY_LIBS@ $(EFENCE)
 metacity_theme_viewer_LDADD= @METACITY_LIBS@ libmetacity-private.la
-metacity_dialog_LDADD= METACITY_LIBS@
 
 testboxes_SOURCES=include/util.h core/util.c include/boxes.h core/boxes.c core/testboxes.c
 testgradient_SOURCES=ui/gradient.h ui/gradient.c ui/testgradient.c
diff --git a/src/core/session.c b/src/core/session.c
index 0707491..7e3b389 100644
--- a/src/core/session.c
+++ b/src/core/session.c
@@ -1731,13 +1731,6 @@ windows_cmp_by_title (MetaWindow *a,
   return g_utf8_collate (a->title, b->title);
 }
 
-typedef struct
-{
-  int child_pid;
-  int child_pipe;
-  gboolean shutdown;
-} LameClientsDialogData;
-
 static void
 finish_interact (gboolean shutdown)
 {
@@ -1749,63 +1742,26 @@ finish_interact (gboolean shutdown)
     }
 }
 
-static gboolean  
-io_from_warning_dialog (GIOChannel   *channel,
-                        GIOCondition  condition,
-                        gpointer      data)
+static void
+sigchld_handler (MetaNexus *nexus, guint arg1, gpointer arg2, gpointer user_data)
 {
-  LameClientsDialogData *d;
+  gboolean shutdown = GPOINTER_TO_INT (user_data);
 
-  d = data;
-  
-  meta_topic (META_DEBUG_PING,
-              "IO handler from lame clients dialog, condition = %x\n",
-              condition);
-  
-  if (condition & (G_IO_HUP | G_IO_NVAL | G_IO_ERR))
+  if (arg1 == 0) /* pressed "OK" */
     {
-      finish_interact (d->shutdown);
-
-      /* Remove the callback, freeing data */
-      return FALSE; 
-    }
-  else if (condition & G_IO_IN)
-    {
-      /* Check for EOF */
-      
-      char buf[16];
-      int ret;
- 
-      ret = read (d->child_pipe, buf, sizeof (buf));
-      if (ret == 0)
- 	{
- 	  finish_interact (d->shutdown);
- 	  return FALSE;
- 	}
+      finish_interact (shutdown);
     }
-
-  /* Keep callback installed */
-  return TRUE;
 }
 
 static void
 warn_about_lame_clients_and_finish_interact (gboolean shutdown)
 {
-  GSList *lame;
+  GSList *lame = NULL;
   GSList *windows;
-  char **argv;
-  int i;
+  GSList *lame_details = NULL;
   GSList *tmp;
-  int len;
-  int child_pid;
-  int child_pipe;
-  GError *err;
-  GIOChannel *channel;
-  LameClientsDialogData *d;
-  guint32 timestamp;
-  char timestampbuf[32];
-  
-  lame = NULL;
+  GSList *columns = NULL;
+  
   windows = meta_display_list_windows (meta_get_display ());
   tmp = windows;
   while (tmp != NULL)
@@ -1832,77 +1788,43 @@ warn_about_lame_clients_and_finish_interact (gboolean shutdown)
       finish_interact (shutdown);
       return;
     }
-  
-  lame = g_slist_sort (lame, (GCompareFunc) windows_cmp_by_title);
 
-  timestamp = meta_display_get_current_time_roundtrip (meta_get_display ());
-  sprintf (timestampbuf, "%u", timestamp);
+  columns = g_slist_prepend (columns, "Window");
+  columns = g_slist_prepend (columns, "Class");
 
-  len = g_slist_length (lame);
-  len *= 2; /* titles and also classes */
-  len += 2; /* --timestamp flag and actual timestamp */
-  len += 1; /* NULL term */
-  len += 2; /* metacity-dialog command and option */
-  
-  argv = g_new0 (char*, len);
-  
-  i = 0;
+  lame = g_slist_sort (lame, (GCompareFunc) windows_cmp_by_title);
 
-  argv[i] = METACITY_LIBEXECDIR"/metacity-dialog";
-  ++i;
-  argv[i] = "--timestamp";
-  ++i;
-  argv[i] = timestampbuf;
-  ++i;
-  argv[i] = "--warn-about-no-sm-support";
-  ++i;
-  
   tmp = lame;
   while (tmp != NULL)
     {
       MetaWindow *w = tmp->data;
 
-      argv[i] = w->title;
-      ++i;
-      argv[i] = w->res_class ? w->res_class : "";
-      ++i;
+      lame_details = g_slist_prepend (lame_details,
+                                      w->res_class ? w->res_class : "");
+      lame_details = g_slist_prepend (lame_details,
+                                      w->title);
 
       tmp = tmp->next;
     }
+  g_slist_free (lame);
 
-  child_pipe = -1;
-  child_pid = -1;
-  err = NULL;
-  if (!g_spawn_async_with_pipes ("/",
-                                 argv,
-                                 NULL,
-                                 0,
-                                 NULL, NULL,
-                                 &child_pid,
-                                 NULL,
-                                 &child_pipe,
-                                 NULL,
-                                 &err))
-    {
-      meta_warning (_("Error launching metacity-dialog to warn about apps that don't support session management: %s\n"),
-                    err->message);
-      g_error_free (err);
-    }
+  meta_show_dialog("--list",
+                   _("These windows do not support &quot;save current setup&quot; "
+                     "and will have to be restarted manually next time "
+                     "you log in."),
+                   "240",
+                   meta_screen_get_screen_number (meta_get_display()->active_screen),
+                   NULL, NULL,
+                   None,
+                   columns,
+                   lame_details);
 
-  g_free (argv);
-  g_slist_free (lame);
+  g_slist_free (lame_details);
+
+  g_signal_connect (sigchld_nexus, "sigchld",
+                    G_CALLBACK (sigchld_handler),
+                    GINT_TO_POINTER (shutdown));
 
-  d = g_new0 (LameClientsDialogData, 1);
-  d->child_pipe = child_pipe;
-  d->child_pid = child_pid;
-  d->shutdown = shutdown;
-  
-  channel = g_io_channel_unix_new (d->child_pipe);
-  g_io_add_watch_full (channel, G_PRIORITY_DEFAULT,
-                       G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
-                       io_from_warning_dialog,
-                       d, g_free);
-  g_io_channel_unref (channel);
 }
 
 #endif /* HAVE_SM */
diff --git a/src/core/util.c b/src/core/util.c
index af4b8dd..299cd79 100644
--- a/src/core/util.c
+++ b/src/core/util.c
@@ -548,29 +548,18 @@ meta_show_dialog (const char *type,
                   const char *ok_text,
                   const char *cancel_text,
                   const int transient_for,
-                  const char **columns,
-                  const char **entries)
+                  GSList *columns,
+                  GSList *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;
-  char **envl;
+  GSList *tmp;
   int i=0;
   GPid child_pid;
-
-  argvl = g_malloc(sizeof (char*) * 15);
+  const char **argvl = g_malloc(sizeof (char*) *
+                                (15 +
+                                 g_slist_length (columns)*2 +
+                                 g_slist_length (entries)));
 
   argvl[i++] = "zenity";
   argvl[i++] = type;
@@ -594,22 +583,35 @@ zenity --display X --screen S --title Metacity --list --timeout 240 --text "Thes
       argvl[i++] = ok_text;
      }
 
-   if (cancel_text)
+  if (cancel_text)
     {
       argvl[i++] = "--cancel-label";
       argvl[i++] = cancel_text;
-     }
+    }
+  
+  tmp = columns;
+  while (tmp)
+    {
+      argvl[i++] = "--column";
+      argvl[i++] = tmp->data;
+      tmp = tmp->next;
+    }
 
+  tmp = entries;
+  while (tmp)
+    {
+      argvl[i++] = tmp->data;
+      tmp = tmp->next;
+    }
+    
   argvl[i] = NULL;
 
   if (transient_for)
     {
-        gchar *env = g_strdup_printf("%d", transient_for);
-        setenv ("WINDOWID", env, 1);
-        g_free (env);
+      gchar *env = g_strdup_printf("%d", transient_for);
+      setenv ("WINDOWID", env, 1);
+      g_free (env);
     }
-  else
-    envl = NULL;
 
   g_spawn_async (
                  "/",
@@ -621,6 +623,9 @@ zenity --display X --screen S --title Metacity --list --timeout 240 --text "Thes
                  &error
                  );
 
+  if (transient_for)
+    unsetenv ("WINDOWID");
+
   g_free (argvl);
   g_free (screen_number_text);
 
diff --git a/src/include/util.h b/src/include/util.h
index dc58cc7..f2a20b1 100644
--- a/src/include/util.h
+++ b/src/include/util.h
@@ -105,8 +105,8 @@ GPid meta_show_dialog (const char *type,
                        const char *ok_text,
                        const char *cancel_text,
                        const int transient_for,
-                       const char **columns,
-                       const char **entries);
+                       GSList *columns,
+                       GSList *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]