[gnome-session] Make the fail whale a separate program



commit f2ae6ebe04f7fe89acbb76ff61acbb4ef0c5c5e2
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Nov 23 01:59:07 2012 -0500

    Make the fail whale a separate program
    
    This makes it easier to test, and makes gnome-session itself
    a bit smaller.

 gnome-session/Makefile.am             |   23 +++++++++++--
 gnome-session/gsm-fail-whale-dialog.c |   57 +++++++++++++++++++-------------
 gnome-session/gsm-fail-whale-dialog.h |    6 ---
 gnome-session/gsm-fail-whale.c        |   49 ++++++++++++++++++++++++++++
 gnome-session/gsm-fail-whale.h        |   36 +++++++++++++++++++++
 gnome-session/gsm-manager.c           |    2 +-
 gnome-session/main.c                  |    2 +-
 7 files changed, 140 insertions(+), 35 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index ac46df0..7b66276 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -1,4 +1,5 @@
 bin_PROGRAMS = gnome-session
+libexec_PROGRAMS = gnome-session-failed
 noinst_LTLIBRARIES = libgsmutil.la
 noinst_PROGRAMS = 		\
 	test-client-dbus	\
@@ -22,8 +23,8 @@ gnome_session_SOURCES =				\
 	gsm-xsmp-client.c			\
 	gsm-dbus-client.h			\
 	gsm-dbus-client.c			\
-	gsm-fail-whale-dialog.h			\
-	gsm-fail-whale-dialog.c			\
+	gsm-fail-whale.h			\
+	gsm-fail-whale.c			\
 	gsm-system.h				\
 	gsm-system.c				\
 	gsm-consolekit.c			\
@@ -32,7 +33,6 @@ gnome_session_SOURCES =				\
 	gsm-systemd.c				\
 	gsm-logout-dialog.h			\
 	gsm-logout-dialog.c			\
-	gsm-icon-names.h			\
 	gsm-inhibit-dialog.h			\
 	gsm-inhibit-dialog.c			\
 	gsm-presence.h				\
@@ -72,7 +72,7 @@ gnome_session_CPPFLAGS =			\
 	-I$(top_srcdir)/egg			\
 	-DLOCALE_DIR=\""$(datadir)/locale"\"	\
 	-DDATA_DIR=\""$(datadir)/gnome-session"\" \
-	-DLIBEXECDIR=\"$(libexecdir)\"		\
+        -DLIBEXECDIR=\"$(libexecdir)\"		\
 	-DGTKBUILDER_DIR=\""$(pkgdatadir)"\"	\
 	-DGCONF_SANITY_CHECK=\""$(GCONF_SANITY_CHECK)"\" \
 	-DGCONFTOOL_CMD=\"$(GCONFTOOL)\"
@@ -94,9 +94,24 @@ libgsmutil_la_SOURCES =				\
 	gsm-util.c				\
 	gsm-util.h
 
+libgsmutil_la_CPPFLAGS =                       \
+       $(AM_CPPFLAGS)
+
 libgsmutil_la_LIBADD = 				\
 	$(GNOME_SESSION_LIBS)
 
+gnome_session_failed_SOURCES =         \
+       gsm-fail-whale-dialog.c \
+       gsm-fail-whale-dialog.h \
+       gsm-icon-names.h
+
+gnome_session_failed_CPPFLAGS = \
+       $(GTK3_CFLAGS)          \
+       -DLOCALE_DIR=\""$(datadir)/locale"\"
+
+gnome_session_failed_LDADD =   \
+       $(GTK3_LIBS)
+
 test_inhibit_SOURCES = test-inhibit.c
 test_inhibit_LDADD = $(GNOME_SESSION_LIBS)
 
diff --git a/gnome-session/gsm-fail-whale-dialog.c b/gnome-session/gsm-fail-whale-dialog.c
index 33f6b11..8a2033c 100644
--- a/gnome-session/gsm-fail-whale-dialog.c
+++ b/gnome-session/gsm-fail-whale-dialog.c
@@ -23,6 +23,8 @@
 
 #include <config.h>
 
+#include <stdlib.h>
+
 #include <glib/gi18n.h>
 
 #include <gtk/gtkx.h>
@@ -30,7 +32,6 @@
 #include "gsm-fail-whale-dialog.h"
 
 #include "gsm-icon-names.h"
-#include "gsm-shell-extensions.h"
 
 #define GSM_FAIL_WHALE_DIALOG_GET_PRIVATE(o)                                \
         (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_FAIL_WHALE_DIALOG, GsmFailWhaleDialogPrivate))
@@ -280,14 +281,12 @@ setup_window (GsmFailWhaleDialog *fail_dialog)
         gtk_window_set_title (GTK_WINDOW (fail_dialog), "");
         gtk_window_set_icon_name (GTK_WINDOW (fail_dialog), GSM_ICON_COMPUTER_FAIL);
 
-        if (!fail_dialog->priv->debug_mode) {
-                gtk_window_set_skip_taskbar_hint (GTK_WINDOW (fail_dialog), TRUE);
-                gtk_window_set_keep_above (GTK_WINDOW (fail_dialog), TRUE);
-                gtk_window_stick (GTK_WINDOW (fail_dialog));
-                gtk_window_set_position (GTK_WINDOW (fail_dialog), GTK_WIN_POS_CENTER_ALWAYS);
-                /* only works if there is a window manager which is unlikely */
-                gtk_window_fullscreen (GTK_WINDOW (fail_dialog));
-        }
+        gtk_window_set_skip_taskbar_hint (GTK_WINDOW (fail_dialog), TRUE);
+        gtk_window_set_keep_above (GTK_WINDOW (fail_dialog), TRUE);
+        gtk_window_stick (GTK_WINDOW (fail_dialog));
+        gtk_window_set_position (GTK_WINDOW (fail_dialog), GTK_WIN_POS_CENTER_ALWAYS);
+        /* only works if there is a window manager which is unlikely */
+        gtk_window_fullscreen (GTK_WINDOW (fail_dialog));
 
         alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
         gtk_widget_show (alignment);
@@ -345,32 +344,44 @@ gsm_fail_whale_dialog_init (GsmFailWhaleDialog *fail_dialog)
         fail_dialog->priv = GSM_FAIL_WHALE_DIALOG_GET_PRIVATE (fail_dialog);
 }
 
-void
-gsm_fail_whale_dialog_we_failed (gboolean            debug_mode,
-                                 gboolean            allow_logout,
-                                 GsmShellExtensions *extensions)
+static gboolean debug_mode = FALSE;
+static gboolean allow_logout = FALSE;
+static gboolean extensions = FALSE;
 
+int main (int argc, char *argv[])
 {
-        static GsmFailWhaleDialog *current_dialog = NULL;
+        GOptionEntry entries[] = {
+                 { "debug", 0, 0, G_OPTION_ARG_NONE, &debug_mode, N_("Enable debugging code"), NULL },
+                 { "allow-logout", 0, 0, G_OPTION_ARG_NONE, &allow_logout, N_("Allow logout"), NULL },
+                 { "extensions", 0, 0, G_OPTION_ARG_NONE, &extensions, N_("Show extension warning"), NULL },
+                { NULL, 0, 0, 0, NULL, NULL, NULL }
+        };
+
         GsmFailWhaleDialog        *fail_dialog;
+        GError *error = NULL;
 
-        if (current_dialog != NULL) {
-                return;
-        }
+        gtk_init_with_args (&argc, &argv, " - fail whale",
+                            entries, GETTEXT_PACKAGE,
+                            &error);
+         if (error != NULL) {
+                 g_warning ("%s", error->message);
+                 exit (1);
+         }
 
         fail_dialog = g_object_new (GSM_TYPE_FAIL_WHALE_DIALOG, NULL);
         fail_dialog->priv->debug_mode = debug_mode;
         fail_dialog->priv->allow_logout = allow_logout;
-        fail_dialog->priv->extensions = extensions != NULL && gsm_shell_extensions_n_extensions (extensions) > 0;
+        fail_dialog->priv->extensions = extensions;
 
         setup_window (fail_dialog);
 
-        current_dialog = fail_dialog;
-        g_signal_connect (current_dialog,
-                          "destroy",
-                          G_CALLBACK (gtk_widget_destroyed),
-                          &current_dialog);
+        g_signal_connect (fail_dialog, "destroy",
+                          G_CALLBACK (gtk_main_quit), NULL);
 
         gtk_widget_show (GTK_WIDGET (fail_dialog));
+
+        gtk_main ();
+
+        return 0;
 }
 
diff --git a/gnome-session/gsm-fail-whale-dialog.h b/gnome-session/gsm-fail-whale-dialog.h
index 0e08672..ec13993 100644
--- a/gnome-session/gsm-fail-whale-dialog.h
+++ b/gnome-session/gsm-fail-whale-dialog.h
@@ -26,8 +26,6 @@
 
 #include <gtk/gtk.h>
 
-#include "gsm-shell-extensions.h"
-
 G_BEGIN_DECLS
 
 #define GSM_TYPE_FAIL_WHALE_DIALOG         (gsm_fail_whale_dialog_get_type ())
@@ -55,10 +53,6 @@ struct _GsmFailWhaleDialogClass
 
 GType        gsm_fail_whale_dialog_get_type   (void) G_GNUC_CONST;
 
-void         gsm_fail_whale_dialog_we_failed  (gboolean            debug_mode,
-                                               gboolean            allow_logout,
-                                               GsmShellExtensions *extensions);
-
 G_END_DECLS
 
 #endif /* __GSM_FAIL_WHALE_DIALOG_H__ */
diff --git a/gnome-session/gsm-fail-whale.c b/gnome-session/gsm-fail-whale.c
new file mode 100644
index 0000000..bb0a60f
--- /dev/null
+++ b/gnome-session/gsm-fail-whale.c
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ * gsm-fail-whale.c
+ * Copyright (C) 2012 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+
+#include "gsm-fail-whale.h"
+
+void
+gsm_fail_whale_dialog_we_failed  (gboolean            debug_mode,
+                                  gboolean            allow_logout,
+                                  GsmShellExtensions *extensions)
+{
+        gint i;
+        gchar *argv[5];
+
+        i = 0;
+        argv[i++] = LIBEXECDIR "/gnome-session-failed";
+        if (debug_mode)
+                argv[i++] = "--debug";
+        if (allow_logout)
+                argv[i++] = "--allow-logout";
+        if (extensions != NULL && gsm_shell_extensions_n_extensions (extensions) > 0)
+                argv[i++] = "--extensions";
+        argv[i++] = NULL;
+
+        g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
+
+        return 0;
+}
diff --git a/gnome-session/gsm-fail-whale.h b/gnome-session/gsm-fail-whale.h
new file mode 100644
index 0000000..0736ec4
--- /dev/null
+++ b/gnome-session/gsm-fail-whale.h
@@ -0,0 +1,36 @@
+/* gsm-fail-whale.h
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef __GSM_FAIL_WHALE_H___
+#define __GSM_FAIL_WHALE_H__
+
+#include <glib.h>
+
+#include "gsm-shell-extensions.h"
+
+G_BEGIN_DECLS
+
+void        gsm_fail_whale_dialog_we_failed  (gboolean            debug_mode,
+                                              gboolean            allow_logout,
+                                              GsmShellExtensions *extensions);
+
+G_END_DECLS
+
+#endif /* __GSM_FAIL_WHALE_H__ */
+
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 33d5979..5c1220e 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -58,12 +58,12 @@
 #include "gsm-util.h"
 #include "gdm.h"
 #include "gsm-logout-dialog.h"
-#include "gsm-fail-whale-dialog.h"
 #include "gsm-icon-names.h"
 #include "gsm-inhibit-dialog.h"
 #include "gsm-system.h"
 #include "gsm-session-save.h"
 #include "gsm-shell-extensions.h"
+#include "gsm-fail-whale.h"
 
 #define GSM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_MANAGER, GsmManagerPrivate))
 
diff --git a/gnome-session/main.c b/gnome-session/main.c
index 44d6ee5..e074526 100644
--- a/gnome-session/main.c
+++ b/gnome-session/main.c
@@ -46,7 +46,7 @@
 #include "gsm-session-fill.h"
 #include "gsm-store.h"
 #include "gsm-system.h"
-#include "gsm-fail-whale-dialog.h"
+#include "gsm-fail-whale.h"
 
 #define GSM_DBUS_NAME "org.gnome.SessionManager"
 



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