[gnome-session] Add "fail whale" dialog, will be shown on component failure



commit a2fedc4dc0e655a13f43d205c4982fa142bf67d6
Author: Colin Walters <walters verbum org>
Date:   Thu Mar 10 09:54:54 2011 -0500

    Add "fail whale" dialog, will be shown on component failure
    
    Named the "fail whale" after Twitter, this dialog tells the user we
    hit a serious problem and offers to log out.  Will be used
    by following patches.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642497

 gnome-session/Makefile.am             |    2 +
 gnome-session/gsm-fail-whale-dialog.c |  267 +++++++++++++++++++++++++++++++++
 gnome-session/gsm-fail-whale-dialog.h |   66 ++++++++
 gnome-session/gsm-logout-dialog.c     |    2 +
 4 files changed, 337 insertions(+), 0 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index 23855da..1336e29 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -22,6 +22,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-marshal.h				\
 	gsm-marshal.c				\
 	gsm-consolekit.c			\
diff --git a/gnome-session/gsm-fail-whale-dialog.c b/gnome-session/gsm-fail-whale-dialog.c
new file mode 100644
index 0000000..5ad04e1
--- /dev/null
+++ b/gnome-session/gsm-fail-whale-dialog.c
@@ -0,0 +1,267 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 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
+ * 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.
+ *
+ * Authors:
+ *	Colin Walters <walters verbum org>
+ */
+
+#include <config.h>
+
+#include "gsm-fail-whale-dialog.h"
+#include "gsm-manager.h"
+
+#include <glib/gi18n.h>
+
+#define GSM_FAIL_WHALE_DIALOG_GET_PRIVATE(o)                                \
+        (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_FAIL_WHALE_DIALOG, GsmFailWhaleDialogPrivate))
+
+/* Shared with gsm-logout-dialog.c */
+#define AUTOMATIC_ACTION_TIMEOUT 60
+
+enum
+{
+        GSM_FAIL_WHALE_DIALOG_RESPONSE_LOG_OUT,
+        GSM_FAIL_WHALE_DIALOG_RESPONSE_TRY_RECOVERY
+};
+
+struct _GsmFailWhaleDialogPrivate
+{
+        GsmFailWhaleDialogFailType type;
+
+        int                  timeout;
+        unsigned int         timeout_id;
+
+        unsigned int         default_response;
+};
+
+static GsmFailWhaleDialog *current_dialog = NULL;
+
+static void gsm_fail_whale_dialog_destroy  (GsmFailWhaleDialog *fail_dialog,
+                                            gpointer         data);
+
+enum {
+        PROP_0,
+        PROP_FAIL_TYPE
+};
+
+G_DEFINE_TYPE (GsmFailWhaleDialog, gsm_fail_whale_dialog, GTK_TYPE_MESSAGE_DIALOG);
+
+static void
+gsm_fail_whale_dialog_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+        GsmFailWhaleDialog *dialog = GSM_FAIL_WHALE_DIALOG (object);
+        (void) dialog;
+
+        switch (prop_id) {
+        case PROP_FAIL_TYPE:
+                dialog->priv->type = g_value_get_enum (value);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+gsm_fail_whale_dialog_get_property (GObject     *object,
+                                    guint        prop_id,
+                                    GValue      *value,
+                                    GParamSpec  *pspec)
+{
+        GsmFailWhaleDialog *dialog = GSM_FAIL_WHALE_DIALOG (object);
+        (void) dialog;
+
+        switch (prop_id) {
+        case PROP_FAIL_TYPE:
+                g_value_set_enum (value, dialog->priv->type);
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+gsm_fail_whale_dialog_class_init (GsmFailWhaleDialogClass *klass)
+{
+        GObjectClass *gobject_class;
+
+        gobject_class = G_OBJECT_CLASS (klass);
+        gobject_class->set_property = gsm_fail_whale_dialog_set_property;
+        gobject_class->get_property = gsm_fail_whale_dialog_get_property;
+
+        g_type_class_add_private (klass, sizeof (GsmFailWhaleDialogPrivate));
+}
+
+static void
+gsm_fail_whale_dialog_init (GsmFailWhaleDialog *fail_dialog)
+{
+        fail_dialog->priv = GSM_FAIL_WHALE_DIALOG_GET_PRIVATE (fail_dialog);
+
+        fail_dialog->priv->timeout_id = 0;
+        fail_dialog->priv->timeout = 0;
+        fail_dialog->priv->default_response = GTK_RESPONSE_CANCEL;
+
+        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));
+
+        g_signal_connect (fail_dialog,
+                          "destroy",
+                          G_CALLBACK (gsm_fail_whale_dialog_destroy),
+                          NULL);
+}
+
+static void
+gsm_fail_whale_dialog_destroy (GsmFailWhaleDialog *fail_dialog,
+                               gpointer         data)
+{
+        if (fail_dialog->priv->timeout_id != 0) {
+                g_source_remove (fail_dialog->priv->timeout_id);
+                fail_dialog->priv->timeout_id = 0;
+        }
+
+        g_assert (current_dialog != NULL);
+        current_dialog = NULL;
+}
+
+static gboolean
+gsm_fail_whale_dialog_timeout (gpointer data)
+{
+        GsmFailWhaleDialog *fail_dialog;
+        char            *seconds_warning;
+        int              seconds_to_show;
+
+        fail_dialog = GSM_FAIL_WHALE_DIALOG (data);
+
+        if (fail_dialog->priv->timeout == 0) {
+                gtk_dialog_response (GTK_DIALOG (fail_dialog), GSM_FAIL_WHALE_DIALOG_RESPONSE_LOG_OUT);
+                return FALSE;
+        }
+
+        if (fail_dialog->priv->timeout <= 30) {
+                seconds_to_show = fail_dialog->priv->timeout;
+        } else {
+                seconds_to_show = (fail_dialog->priv->timeout/10) * 10;
+
+                if (fail_dialog->priv->timeout % 10)
+                        seconds_to_show += 10;
+        }
+
+        /* This string is shared with gsm-logout-dialog.c */
+        seconds_warning = ngettext ("You will be automatically logged "
+                                    "out in %d second.",
+                                    "You will be automatically logged "
+                                    "out in %d seconds.",
+                                    seconds_to_show);
+        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (fail_dialog),
+                                                  seconds_warning,
+                                                  seconds_to_show,
+                                                  NULL);
+        fail_dialog->priv->timeout--;
+
+        return TRUE;
+}
+
+static void
+gsm_fail_whale_dialog_on_response (GsmFailWhaleDialog *fail_dialog,
+                                   int                 response_id,
+                                   gpointer            user_data)
+{
+        switch (response_id) {
+        case GSM_FAIL_WHALE_DIALOG_RESPONSE_LOG_OUT:
+                gsm_manager_logout (gsm_manager_get (),
+                                    GSM_MANAGER_LOGOUT_MODE_FORCE,
+                                    NULL);
+                break;
+        }
+}
+
+void
+gsm_fail_whale_dialog_we_failed (GsmFailWhaleDialogFailType fail_type,
+                                 const char *               additional_text)
+{
+        GsmFailWhaleDialog *fail_dialog;
+        char *primary_text;
+
+        g_printerr ("gnome-session: %s failure: %s\n",
+                    fail_type == GSM_FAIL_WHALE_DIALOG_FAIL_TYPE_FATAL ? "fatal" : "recoverable",
+                    additional_text ? additional_text : "");
+
+        if (current_dialog != NULL) {
+                /* Only allow replacing non-fatal dialogs */
+                if (fail_type == GSM_FAIL_WHALE_DIALOG_FAIL_TYPE_FATAL)
+                        gtk_widget_destroy (GTK_WIDGET (current_dialog));
+                else
+                        return;
+        }
+
+        fail_dialog = g_object_new (GSM_TYPE_FAIL_WHALE_DIALOG,
+                                    "fail-type", fail_type,
+                                    NULL);
+        
+        current_dialog = fail_dialog;
+
+        gtk_window_set_title (GTK_WINDOW (fail_dialog), "");
+
+        gtk_dialog_add_button (GTK_DIALOG (fail_dialog),
+                               _("_Log Out"),
+                               GSM_FAIL_WHALE_DIALOG_RESPONSE_LOG_OUT);
+
+        gtk_window_set_icon_name (GTK_WINDOW (fail_dialog), "gtk-error");
+        gtk_window_set_position (GTK_WINDOW (fail_dialog), GTK_WIN_POS_CENTER_ALWAYS);
+        
+        switch (fail_type) {
+        case GSM_FAIL_WHALE_DIALOG_FAIL_TYPE_RECOVERABLE:
+                gtk_dialog_add_button (GTK_DIALOG (fail_dialog),
+                                       _("Try _Recovery"),
+                                       GSM_FAIL_WHALE_DIALOG_RESPONSE_TRY_RECOVERY);
+                primary_text = g_strdup_printf (_("A non-fatal system error has occurred: %s"), additional_text);
+                break;
+        case GSM_FAIL_WHALE_DIALOG_FAIL_TYPE_FATAL:
+                primary_text = g_strdup_printf (_("A fatal system error has occurred: %s"), additional_text);
+                break;
+        default:
+                g_assert_not_reached ();
+                return;
+        }
+        gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (fail_dialog),
+                                       primary_text);
+        gtk_dialog_set_default_response (GTK_DIALOG (fail_dialog),
+                                         GSM_FAIL_WHALE_DIALOG_RESPONSE_LOG_OUT);
+
+        fail_dialog->priv->timeout = AUTOMATIC_ACTION_TIMEOUT;
+
+        gsm_fail_whale_dialog_timeout (fail_dialog);
+
+        if (fail_dialog->priv->timeout_id != 0) {
+                g_source_remove (fail_dialog->priv->timeout_id);
+        }
+        fail_dialog->priv->timeout_id = g_timeout_add (1000,
+                                                       gsm_fail_whale_dialog_timeout,
+                                                       fail_dialog);
+        g_signal_connect (fail_dialog, "response",
+                          G_CALLBACK (gsm_fail_whale_dialog_on_response),
+                          fail_dialog);
+        gtk_widget_show (GTK_WIDGET (fail_dialog));
+}
+
diff --git a/gnome-session/gsm-fail-whale-dialog.h b/gnome-session/gsm-fail-whale-dialog.h
new file mode 100644
index 0000000..98f7288
--- /dev/null
+++ b/gnome-session/gsm-fail-whale-dialog.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 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
+ * 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.
+ *
+ * Authors:
+ *	Colin Walters <walters verbum org>
+ */
+
+#ifndef __GSM_FAIL_WHALE_DIALOG_H__
+#define __GSM_FAIL_WHALE_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GSM_TYPE_FAIL_WHALE_DIALOG         (gsm_fail_whale_dialog_get_type ())
+#define GSM_FAIL_WHALE_DIALOG(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GSM_TYPE_FAIL_WHALE_DIALOG, GsmFailWhaleDialog))
+#define GSM_FAIL_WHALE_DIALOG_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GSM_TYPE_FAIL_WHALE_DIALOG, GsmFailWhaleDialogClass))
+#define GSM_IS_FAIL_WHALE_DIALOG(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSM_TYPE_FAIL_WHALE_DIALOG))
+#define GSM_IS_FAIL_WHALE_DIALOG_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GSM_TYPE_FAIL_WHALE_DIALOG))
+#define GSM_FAIL_WHALE_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSM_TYPE_FAIL_WHALE_DIALOG, GsmFailWhaleDialogClass))
+
+typedef struct _GsmFailWhaleDialog         GsmFailWhaleDialog;
+typedef struct _GsmFailWhaleDialogClass    GsmFailWhaleDialogClass;
+typedef struct _GsmFailWhaleDialogPrivate  GsmFailWhaleDialogPrivate;
+
+typedef enum {
+        GSM_FAIL_WHALE_DIALOG_FAIL_TYPE_RECOVERABLE,
+        GSM_FAIL_WHALE_DIALOG_FAIL_TYPE_FATAL
+} GsmFailWhaleDialogFailType;
+
+struct _GsmFailWhaleDialog
+{
+        GtkMessageDialog        parent;
+
+        GsmFailWhaleDialogPrivate *priv;
+};
+
+struct _GsmFailWhaleDialogClass
+{
+        GtkMessageDialogClass  parent_class;
+};
+
+GType        gsm_fail_whale_dialog_get_type   (void) G_GNUC_CONST;
+
+void         gsm_fail_whale_dialog_we_failed  (GsmFailWhaleDialogFailType fail_type,
+                                               const char *additional_text);
+
+G_END_DECLS
+
+#endif /* __GSM_FAIL_WHALE_DIALOG_H__ */
diff --git a/gnome-session/gsm-logout-dialog.c b/gnome-session/gsm-logout-dialog.c
index ca68714..7ecfdae 100644
--- a/gnome-session/gsm-logout-dialog.c
+++ b/gnome-session/gsm-logout-dialog.c
@@ -36,6 +36,7 @@
 #define GSM_LOGOUT_DIALOG_GET_PRIVATE(o)                                \
         (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_LOGOUT_DIALOG, GsmLogoutDialogPrivate))
 
+/* Shared with gsm-fail-whale-dialog.c */
 #define AUTOMATIC_ACTION_TIMEOUT 60
 
 #define GSM_ICON_LOGOUT   "system-log-out"
@@ -263,6 +264,7 @@ gsm_logout_dialog_timeout (gpointer data)
 
         switch (logout_dialog->priv->type) {
         case GSM_DIALOG_LOGOUT_TYPE_LOGOUT:
+                /* This string is shared with gsm-fail-whale-dialog.c */
                 seconds_warning = ngettext ("You will be automatically logged "
                                             "out in %d second.",
                                             "You will be automatically logged "



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