/* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation. * * 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 Lesser General Public License * along with this program; if not, see . * * * Authors: * Michael Zucchi * Jonathon Jongsma * * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * Copyright (C) 2009 Intel Corporation * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include "e-alert.h" #include "e-alert-sink.h" #define d(x) #define E_ALERT_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_ALERT, EAlertPrivate)) typedef struct _EAlertButton EAlertButton; struct _e_alert { const gchar *id; GtkMessageType message_type; gint default_response; const gchar *primary_text; const gchar *secondary_text; EAlertButton *buttons; }; struct _e_alert_table { const gchar *domain; const gchar *translation_domain; GHashTable *alerts; }; struct _EAlertButton { EAlertButton *next; const gchar *stock_id; const gchar *label; gint response_id; }; static GHashTable *alert_table; /* ********************************************************************** */ static EAlertButton default_ok_button = { NULL, NULL, NULL, GTK_RESPONSE_OK }; static struct _e_alert default_alerts[] = { { "error", GTK_MESSAGE_ERROR, GTK_RESPONSE_OK, "{0}", "{1}", &default_ok_button }, { "warning", GTK_MESSAGE_WARNING, GTK_RESPONSE_OK, "{0}", "{1}", &default_ok_button } }; /* ********************************************************************** */ struct _EAlertPrivate { gchar *tag; GPtrArray *args; gchar *primary_text; gchar *secondary_text; struct _e_alert *definition; GtkMessageType message_type; gint default_response; guint timeout_id; /* It may occur to one that we could use a GtkActionGroup here, * but we need to preserve the button order and GtkActionGroup * uses a hash table, which does not preserve order. */ GQueue actions; GQueue widgets; }; enum { PROP_0, PROP_ARGS, PROP_TAG, PROP_MESSAGE_TYPE, PROP_PRIMARY_TEXT, PROP_SECONDARY_TEXT }; enum { RESPONSE, LAST_SIGNAL }; static gulong signals[LAST_SIGNAL]; G_DEFINE_TYPE ( EAlert, e_alert, G_TYPE_OBJECT) static gint map_response (const gchar *name) { GEnumClass *class; GEnumValue *value; class = g_type_class_ref (GTK_TYPE_RESPONSE_TYPE); value = g_enum_get_value_by_name (class, name); g_type_class_unref (class); return (value != NULL) ? value->value : 0; } static GtkMessageType map_type (const gchar *nick) { GEnumClass *class; GEnumValue *value; class = g_type_class_ref (GTK_TYPE_MESSAGE_TYPE); value = g_enum_get_value_by_nick (class, nick); g_type_class_unref (class); return (value != NULL) ? value->value : GTK_MESSAGE_ERROR; } /* * XML format: * * * Primary error text.? * Secondary error text.? *