[gnome-session/wip/cleanups: 6/15] Make the fail whale a separate program



commit 4473245dd4e312bbd0798ead86f65c34036b18f0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 11 12:30:14 2012 -0500

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

 gnome-session/Makefile.am             |   27 ++++++++++----
 gnome-session/gsm-fail-whale-dialog.c |   59 +++++++++++++++++++--------------
 gnome-session/gsm-fail-whale-dialog.h |    6 ---
 gnome-session/gsm-fail-whale.c        |   47 ++++++++++++++++++++++++++
 gnome-session/gsm-fail-whale.h        |   35 +++++++++++++++++++
 gnome-session/gsm-manager.c           |    1 +
 gnome-session/main.c                  |    2 +-
 7 files changed, 137 insertions(+), 40 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index 954ab0e..beaf51a 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,19 +23,12 @@ 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-system.h				\
 	gsm-system.c				\
 	gsm-consolekit.c			\
 	gsm-consolekit.h			\
 	gsm-systemd.h				\
 	gsm-systemd.c				\
-	gsm-logout-dialog.h			\
-	gsm-logout-dialog.c			\
-	gsm-icon-names.h			\
-	gsm-inhibit-dialog.h			\
-	gsm-inhibit-dialog.c			\
 	gs-idle-monitor.h			\
 	gs-idle-monitor.c			\
 	gsm-presence.h				\
@@ -59,6 +53,8 @@ gnome_session_SOURCES =				\
 	gsm-session-save.h			\
 	gsm-shell-extensions.c			\
 	gsm-shell-extensions.h			\
+	gsm-fail-whale.c			\
+	gsm-fail-whale.h			\
 	gsm-shell.c				\
 	gsm-shell.h				\
 	gsm-xsmp-server.c			\
@@ -74,7 +70,6 @@ gnome_session_CPPFLAGS =			\
 	-I$(top_srcdir)/egg			\
 	-DLOCALE_DIR=\""$(datadir)/locale"\"	\
 	-DDATA_DIR=\""$(datadir)/gnome-session"\" \
-	-DLIBEXECDIR=\"$(libexecdir)\"		\
 	-DGTKBUILDER_DIR=\""$(pkgdatadir)"\"	\
 	-DGCONF_SANITY_CHECK=\""$(GCONF_SANITY_CHECK)"\" \
 	-DGCONFTOOL_CMD=\"$(GCONFTOOL)\"
@@ -92,6 +87,10 @@ gnome_session_LDADD =				\
 	$(SYSTEMD_LIBS)				\
 	$(EXECINFO_LIBS)
 
+libgsmutil_la_CPPFLAGS =			\
+	$(AM_CPPFLAGS)				\
+	-DLIBEXECDIR=\"$(libexecdir)\"
+
 libgsmutil_la_SOURCES =				\
 	gsm-util.c				\
 	gsm-util.h
@@ -99,6 +98,18 @@ libgsmutil_la_SOURCES =				\
 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 e9d2e04..5e2114f 100644
--- a/gnome-session/gsm-fail-whale-dialog.c
+++ b/gnome-session/gsm-fail-whale-dialog.c
@@ -23,6 +23,7 @@
 
 #include <config.h>
 
+#include <stdlib.h>
 #include <glib/gi18n.h>
 
 #include <gtk/gtkx.h>
@@ -30,7 +31,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))
@@ -246,7 +246,7 @@ on_logout_clicked (GtkWidget          *button,
                    GsmFailWhaleDialog *fail_dialog)
 {
         if (!fail_dialog->priv->debug_mode) {
-                g_spawn_command_line_async ("gnome-session-quit --force");
+                g_spawn_command_line_async ("gnome-session-quit --force", NULL);
         }
         gtk_main_quit ();
 }
@@ -280,14 +280,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 +343,43 @@ 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_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..a76932d
--- /dev/null
+++ b/gnome-session/gsm-fail-whale.c
@@ -0,0 +1,47 @@
+/* -*- 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);
+}
diff --git a/gnome-session/gsm-fail-whale.h b/gnome-session/gsm-fail-whale.h
new file mode 100644
index 0000000..af49b60
--- /dev/null
+++ b/gnome-session/gsm-fail-whale.h
@@ -0,0 +1,35 @@
+/* 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 3effdbf..8f2afe8 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -63,6 +63,7 @@
 #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 061ac0e..116b3b2 100644
--- a/gnome-session/main.c
+++ b/gnome-session/main.c
@@ -47,7 +47,7 @@
 #include "gsm-store.h"
 #include "gsm-system.h"
 #include "gsm-xsmp-server.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]