From c2ee0afbc85ce3ddf38ec07497c0cdae4f42a7fc Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Mon, 30 Nov 2009 11:34:43 -0600 Subject: Rename EError to EAlert to match general use better The EError mechanism is used both for error dialogs as well as basic alerts or user prompts, so we should give it a more general name which matches this use. This patch also cleans up a few includes of e-alert.h (formerly e-error.h) that were not actually being used. https://bugzilla.gnome.org/show_bug.cgi?id=602963 --- e-util/e-alert.c | 698 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 698 insertions(+) create mode 100644 e-util/e-alert.c (limited to 'e-util/e-alert.c') diff --git a/e-util/e-alert.c b/e-util/e-alert.c new file mode 100644 index 0000000000..cc7488744e --- /dev/null +++ b/e-util/e-alert.c @@ -0,0 +1,698 @@ +/* + * 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; either + * version 2 of the License, or (at your option) version 3. + * + * 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 Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Michael Zucchi + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include + +#include +#include + +#include +#include + +#include +#include + +#include + +#include "e-util.h" +#include "e-util-private.h" +#include "e-alert.h" + +#define d(x) + +struct _EAlert +{ + gchar *tag; + GPtrArray *args; +}; + +void +e_alert_free (EAlert *alert) +{ + if (alert == NULL) + return; + g_free (alert->tag); + /* arg strings will be freed automatically since we set a free func when + * creating the ptr array */ + g_ptr_array_free (alert->args, TRUE); +} + +struct _e_alert_button { + struct _e_alert_button *next; + const gchar *stock; + const gchar *label; + gint response; +}; + +struct _e_alert { + guint32 flags; + const gchar *id; + gint type; + gint default_response; + const gchar *title; + const gchar *primary; + const gchar *secondary; + const gchar *help_uri; + gboolean scroll; + struct _e_alert_button *buttons; +}; + +struct _e_alert_table { + const gchar *domain; + const gchar *translation_domain; + GHashTable *alerts; +}; + +static GHashTable *alert_table; + +/* ********************************************************************** */ + +static struct _e_alert_button default_ok_button = { + NULL, "gtk-ok", NULL, GTK_RESPONSE_OK +}; + +static struct _e_alert default_alerts[] = { + { GTK_DIALOG_MODAL, "error", 3, GTK_RESPONSE_OK, N_("Evolution Error"), "{0}", "{1}", NULL, FALSE, &default_ok_button }, + { GTK_DIALOG_MODAL, "error-primary", 3, GTK_RESPONSE_OK, N_("Evolution Error"), "{0}", NULL, NULL, FALSE, &default_ok_button }, + { GTK_DIALOG_MODAL, "warning", 1, GTK_RESPONSE_OK, N_("Evolution Warning"), "{0}", "{1}", NULL, FALSE, &default_ok_button }, + { GTK_DIALOG_MODAL, "warning-primary", 1, GTK_RESPONSE_OK, N_("Evolution Warning"), "{0}", NULL, NULL, FALSE, &default_ok_button }, +}; + +/* ********************************************************************** */ + +static struct { + const gchar *name; + gint id; +} response_map[] = { + { "GTK_RESPONSE_REJECT", GTK_RESPONSE_REJECT }, + { "GTK_RESPONSE_ACCEPT", GTK_RESPONSE_ACCEPT }, + { "GTK_RESPONSE_OK", GTK_RESPONSE_OK }, + { "GTK_RESPONSE_CANCEL", GTK_RESPONSE_CANCEL }, + { "GTK_RESPONSE_CLOSE", GTK_RESPONSE_CLOSE }, + { "GTK_RESPONSE_YES", GTK_RESPONSE_YES }, + { "GTK_RESPONSE_NO", GTK_RESPONSE_NO }, + { "GTK_RESPONSE_APPLY", GTK_RESPONSE_APPLY }, + { "GTK_RESPONSE_HELP", GTK_RESPONSE_HELP }, +}; + +static gint +map_response(const gchar *name) +{ + gint i; + + for (i = 0; i < G_N_ELEMENTS (response_map); i++) + if (!strcmp(name, response_map[i].name)) + return response_map[i].id; + + return 0; +} + +static struct { + const gchar *name; + const gchar *icon; +} type_map[] = { + { "info", GTK_STOCK_DIALOG_INFO }, + { "warning", GTK_STOCK_DIALOG_WARNING }, + { "question", GTK_STOCK_DIALOG_QUESTION }, + { "error", GTK_STOCK_DIALOG_ERROR }, +}; + +static gint +map_type(const gchar *name) +{ + gint i; + + if (name) { + for (i = 0; i < G_N_ELEMENTS (type_map); i++) + if (!strcmp(name, type_map[i].name)) + return i; + } + + return 3; +} + +/* + XML format: + + + Window Title? + Primary error text.? + Secondary error text.? + ? +