aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-10-06 22:55:27 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-10-13 01:59:00 +0800
commit4118d671d44b71592f0e91abb63f2468baaa9318 (patch)
treee70f787f68034a16df1c59f75c8869618b02146b /e-util
parenta06e4484b8df804124b5bcf88d94dec5acfba270 (diff)
downloadgsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.tar
gsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.tar.gz
gsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.tar.bz2
gsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.tar.lz
gsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.tar.xz
gsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.tar.zst
gsoc2013-evolution-4118d671d44b71592f0e91abb63f2468baaa9318.zip
Composer: Show cancellable operations and errors inline.
'Send' and 'Save Draft' are now asynchronous and run outside of Evolution's MailMsg infrastructure. Add an EActivityBar to the composer window so these asynchronous operations can be tracked and cancelled even in the absense of a main window. Also add an EAlertBar to the composer window so error messages can be shown directly in the window. Instead of calling e_alert_dialog_run_for_args(), call e_alert_submit() and pass the EMsgComposer as the widget argument. The EMsgComposer will decide whether to show an EAlertDialog or use the EAlertBar, depending on the GtkMessageType of the alert.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-alert-activity.c2
-rw-r--r--e-util/e-alert-dialog.c297
-rw-r--r--e-util/e-alert-dialog.h79
-rw-r--r--e-util/e-alert.c144
-rw-r--r--e-util/e-alert.h16
-rw-r--r--e-util/e-marshal.list1
6 files changed, 287 insertions, 252 deletions
diff --git a/e-util/e-alert-activity.c b/e-util/e-alert-activity.c
index 3a97a4eab4..7d7e5a7999 100644
--- a/e-util/e-alert-activity.c
+++ b/e-util/e-alert-activity.c
@@ -124,8 +124,6 @@ alert_activity_constructed (GObject *object)
secondary_text = e_alert_get_secondary_text (alert);
e_activity_set_secondary_text (activity, secondary_text);
- g_object_unref (alert);
-
/* This is a constructor property, so can't do it in init().
* XXX What we really want to do is override the property's
* default value, but GObject does not support that. */
diff --git a/e-util/e-alert-dialog.c b/e-util/e-alert-dialog.c
index 0057ed91aa..4d6fcd8e6e 100644
--- a/e-util/e-alert-dialog.c
+++ b/e-util/e-alert-dialog.c
@@ -24,95 +24,90 @@
#include "e-alert-dialog.h"
#include "e-util.h"
-G_DEFINE_TYPE (
- EAlertDialog,
- e_alert_dialog,
- GTK_TYPE_DIALOG)
-
-#define ALERT_DIALOG_PRIVATE(o) \
+#define E_ALERT_DIALOG_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), E_TYPE_ALERT_DIALOG, EAlertDialogPrivate))
-struct _EAlertDialogPrivate
-{
+struct _EAlertDialogPrivate {
GtkWindow *parent;
EAlert *alert;
};
-enum
-{
+enum {
PROP_0,
- PROP_PARENT,
PROP_ALERT
};
+G_DEFINE_TYPE (
+ EAlertDialog,
+ e_alert_dialog,
+ GTK_TYPE_DIALOG)
+
static void
-e_alert_dialog_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
+alert_dialog_set_alert (EAlertDialog *dialog,
+ EAlert *alert)
{
- EAlertDialog *dialog = (EAlertDialog*) object;
+ g_return_if_fail (E_IS_ALERT (alert));
+ g_return_if_fail (dialog->priv->alert == NULL);
- switch (property_id)
- {
- case PROP_PARENT:
- dialog->priv->parent = g_value_dup_object (value);
- break;
+ dialog->priv->alert = g_object_ref (alert);
+}
+
+static void
+alert_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
case PROP_ALERT:
- dialog->priv->alert = g_value_dup_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ alert_dialog_set_alert (
+ E_ALERT_DIALOG (object),
+ g_value_get_object (value));
+ return;
}
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
-e_alert_dialog_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+alert_dialog_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EAlertDialog *dialog = (EAlertDialog*) object;
-
- switch (property_id)
- {
- case PROP_PARENT:
- g_value_set_object (value, dialog->priv->parent);
- break;
+ switch (property_id) {
case PROP_ALERT:
- g_value_set_object (value, dialog->priv->alert);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ g_value_set_object (
+ value, e_alert_dialog_get_alert (
+ E_ALERT_DIALOG (object)));
+ return;
}
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
-e_alert_dialog_dispose (GObject *object)
+alert_dialog_dispose (GObject *object)
{
- EAlertDialog *dialog = (EAlertDialog*) object;
+ EAlertDialogPrivate *priv;
- if (dialog->priv->parent) {
- g_object_unref (dialog->priv->parent);
- dialog->priv->parent = NULL;
- }
+ priv = E_ALERT_DIALOG_GET_PRIVATE (object);
- if (dialog->priv->alert) {
- g_object_unref (dialog->priv->alert);
- dialog->priv->alert = NULL;
+ if (priv->alert) {
+ g_object_unref (priv->alert);
+ priv->alert = NULL;
}
+ /* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_alert_dialog_parent_class)->dispose (object);
}
static void
-e_alert_dialog_init (EAlertDialog *self)
-{
- self->priv = ALERT_DIALOG_PRIVATE (self);
-}
-
-static void
-e_alert_dialog_constructed (GObject *obj)
+alert_dialog_constructed (GObject *object)
{
- EAlertDialog *self = (EAlertDialog*) obj;
+ EAlertDialog *self = (EAlertDialog*) object;
EAlert *alert;
- struct _e_alert_button *b;
+ EAlertButton *b;
GtkWidget *action_area;
GtkWidget *content_area;
GtkWidget *container;
@@ -123,58 +118,49 @@ e_alert_dialog_constructed (GObject *obj)
g_return_if_fail (self != NULL);
- self->priv = ALERT_DIALOG_PRIVATE (self);
- alert = self->priv->alert;
+ alert = e_alert_dialog_get_alert (E_ALERT_DIALOG (self));
gtk_window_set_title (GTK_WINDOW (self), " ");
- action_area = gtk_dialog_get_action_area ((GtkDialog*) self);
- content_area = gtk_dialog_get_content_area ((GtkDialog*) self);
+ action_area = gtk_dialog_get_action_area (GTK_DIALOG (self));
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (self));
#if !GTK_CHECK_VERSION(2,90,7)
g_object_set (self, "has-separator", FALSE, NULL);
#endif
- gtk_widget_ensure_style ((GtkWidget *)self);
+ gtk_widget_ensure_style (GTK_WIDGET (self));
gtk_container_set_border_width (GTK_CONTAINER (action_area), 12);
gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
- if (self->priv->parent)
- gtk_window_set_transient_for ((GtkWindow *)self, self->priv->parent);
- else
- g_warning (
- "Something called %s() with a NULL parent window. "
- "This is no longer legal, please fix it.", G_STRFUNC);
-
- gtk_window_set_destroy_with_parent ((GtkWindow *)self, TRUE);
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (self), TRUE);
b = e_alert_peek_buttons (alert);
if (b == NULL) {
- gtk_dialog_add_button ((GtkDialog*) self, GTK_STOCK_OK, GTK_RESPONSE_OK);
+ gtk_dialog_add_button (
+ GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
} else {
for (; b; b=b->next) {
if (b->stock) {
- if (b->label) {
-#if 0
- /* FIXME: So although this looks like it will work, it wont.
- Need to do it the hard way ... it also breaks the
- default_response stuff */
- w = gtk_button_new_from_stock (b->stock);
- gtk_button_set_label ((GtkButton *)w, b->label);
- gtk_widget_show (w);
- gtk_dialog_add_action_widget (self, w, b->response);
-#endif
- gtk_dialog_add_button ((GtkDialog*) self, b->label, b->response);
- } else
- gtk_dialog_add_button ((GtkDialog*) self, b->stock, b->response);
+ if (b->label != NULL)
+ gtk_dialog_add_button (
+ GTK_DIALOG (self),
+ b->label, b->response);
+ else
+ gtk_dialog_add_button (
+ GTK_DIALOG (self),
+ b->stock, b->response);
} else
- gtk_dialog_add_button ((GtkDialog*) self, b->label, b->response);
+ gtk_dialog_add_button (
+ GTK_DIALOG (self),
+ b->label, b->response);
}
}
if (e_alert_get_default_response (alert))
- gtk_dialog_set_default_response ((GtkDialog*) self,
- e_alert_get_default_response (alert));
+ gtk_dialog_set_default_response (
+ GTK_DIALOG (self),
+ e_alert_get_default_response (alert));
widget = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
@@ -224,90 +210,118 @@ e_alert_dialog_constructed (GObject *obj)
}
static void
-e_alert_dialog_class_init (EAlertDialogClass *klass)
+alert_dialog_response (GtkDialog *dialog,
+ gint response_id)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (klass, sizeof (EAlertDialogPrivate));
-
- object_class->dispose = e_alert_dialog_dispose;
- object_class->get_property = e_alert_dialog_get_property;
- object_class->set_property = e_alert_dialog_set_property;
- object_class->constructed = e_alert_dialog_constructed;
-
- g_object_class_install_property (object_class,
- PROP_PARENT,
- g_param_spec_object ("parent",
- "parent window",
- "A parent window to be transient for",
- GTK_TYPE_WINDOW,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
- g_object_class_install_property (object_class,
- PROP_ALERT,
- g_param_spec_object ("alert",
- "alert",
- "EAlert to be displayed",
- E_TYPE_ALERT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
+ EAlert *alert;
+
+ alert = e_alert_dialog_get_alert (E_ALERT_DIALOG (dialog));
+ e_alert_response (alert, response_id);
}
-GtkWidget*
+static void
+e_alert_dialog_class_init (EAlertDialogClass *class)
+{
+ GObjectClass *object_class;
+ GtkDialogClass *dialog_class;
+
+ g_type_class_add_private (class, sizeof (EAlertDialogPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = alert_dialog_set_property;
+ object_class->get_property = alert_dialog_get_property;
+ object_class->dispose = alert_dialog_dispose;
+ object_class->constructed = alert_dialog_constructed;
+
+ dialog_class = GTK_DIALOG_CLASS (class);
+ dialog_class->response = alert_dialog_response;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_ALERT,
+ g_param_spec_object (
+ "alert",
+ "Alert",
+ "Alert to be displayed",
+ E_TYPE_ALERT,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+e_alert_dialog_init (EAlertDialog *self)
+{
+ self->priv = E_ALERT_DIALOG_GET_PRIVATE (self);
+}
+
+GtkWidget *
e_alert_dialog_new (GtkWindow *parent,
EAlert *alert)
{
+ g_return_val_if_fail (E_IS_ALERT (alert), NULL);
+
return g_object_new (
E_TYPE_ALERT_DIALOG,
- "parent", parent, "alert", alert, NULL);
+ "alert", alert, "transient-for", parent, NULL);
}
-GtkWidget*
-e_alert_dialog_new_for_args (GtkWindow *parent, const gchar *tag, ...)
+GtkWidget *
+e_alert_dialog_new_for_args (GtkWindow *parent,
+ const gchar *tag,
+ ...)
{
- GtkWidget *d;
- EAlert *e;
+ GtkWidget *dialog;
+ EAlert *alert;
va_list ap;
+ g_return_val_if_fail (tag != NULL, NULL);
+
va_start (ap, tag);
- e = e_alert_new_valist (tag, ap);
+ alert = e_alert_new_valist (tag, ap);
va_end (ap);
- d = e_alert_dialog_new (parent, e);
- g_object_unref (e);
+ dialog = e_alert_dialog_new (parent, alert);
+
+ g_object_unref (alert);
- return d;
+ return dialog;
}
gint
-e_alert_run_dialog (GtkWindow *parent, EAlert *alert)
+e_alert_run_dialog (GtkWindow *parent,
+ EAlert *alert)
{
GtkWidget *dialog;
- gint res;
+ gint response;
- dialog = e_alert_dialog_new (parent, alert);
+ g_return_val_if_fail (E_IS_ALERT (alert), 0);
- res = gtk_dialog_run ((GtkDialog *)dialog);
+ dialog = e_alert_dialog_new (parent, alert);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
- return res;
+ return response;
}
gint
-e_alert_run_dialog_for_args (GtkWindow *parent, const gchar *tag, ...)
+e_alert_run_dialog_for_args (GtkWindow *parent,
+ const gchar *tag,
+ ...)
{
- EAlert *e;
- va_list ap;
+ EAlert *alert;
gint response;
+ va_list ap;
+
+ g_return_val_if_fail (tag != NULL, 0);
va_start (ap, tag);
- e = e_alert_new_valist (tag, ap);
+ alert = e_alert_new_valist (tag, ap);
va_end (ap);
- response = e_alert_run_dialog (parent, e);
- g_object_unref (e);
+ response = e_alert_run_dialog (parent, alert);
+
+ g_object_unref (alert);
return response;
}
@@ -329,7 +343,7 @@ e_alert_dialog_count_buttons (EAlertDialog *dialog)
g_return_val_if_fail (E_IS_ALERT_DIALOG (dialog), 0);
- container = gtk_dialog_get_action_area ((GtkDialog*) dialog);
+ container = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
children = gtk_container_get_children (GTK_CONTAINER (container));
/* Iterate over the children looking for buttons. */
@@ -346,19 +360,14 @@ e_alert_dialog_count_buttons (EAlertDialog *dialog)
* e_alert_dialog_get_alert:
* @dialog: a #EAlertDialog
*
- * Convenience API for getting the #EAlert associated with @dialog
+ * Returns the #EAlert associated with @dialog.
*
- * Return value: the #EAlert associated with @dialog. The alert should be
- * unreffed when no longer needed.
- */
+ * Returns: the #EAlert associated with @dialog
+ **/
EAlert *
e_alert_dialog_get_alert (EAlertDialog *dialog)
{
- EAlert *alert = NULL;
-
- g_return_val_if_fail (dialog != NULL, NULL);
+ g_return_val_if_fail (E_IS_ALERT_DIALOG (dialog), NULL);
- g_object_get (dialog, "alert", &alert,
- NULL);
- return alert;
+ return dialog->priv->alert;
}
diff --git a/e-util/e-alert-dialog.h b/e-util/e-alert-dialog.h
index 54235a757b..96253a582e 100644
--- a/e-util/e-alert-dialog.h
+++ b/e-util/e-alert-dialog.h
@@ -21,63 +21,60 @@
* Copyright (C) 2009 Intel Corporation
*/
-#ifndef _E_ALERT_DIALOG_H
-#define _E_ALERT_DIALOG_H
+#ifndef E_ALERT_DIALOG_H
+#define E_ALERT_DIALOG_H
#include <gtk/gtk.h>
#include <e-util/e-alert.h>
-G_BEGIN_DECLS
-
-#define E_TYPE_ALERT_DIALOG e_alert_dialog_get_type()
-
+/* Standard GObject macros */
+#define E_TYPE_ALERT_DIALOG \
+ (e_alert_dialog_get_type ())
#define E_ALERT_DIALOG(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- E_TYPE_ALERT_DIALOG, EAlertDialog))
-
-#define E_ALERT_DIALOG_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), \
- E_TYPE_ALERT_DIALOG, EAlertDialogClass))
-
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_ALERT_DIALOG, EAlertDialog))
+#define E_ALERT_DIALOG_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_ALERT_DIALOG, EAlertDialogClass))
#define E_IS_ALERT_DIALOG(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- E_TYPE_ALERT_DIALOG))
-
-#define E_IS_ALERT_DIALOG_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
- E_TYPE_ALERT_DIALOG))
-
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_ALERT_DIALOG))
+#define E_IS_ALERT_DIALOG_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_ALERT_DIALOG))
#define E_ALERT_DIALOG_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
- E_TYPE_ALERT_DIALOG, EAlertDialogClass))
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_ALERT_DIALOG, EAlertDialogClass))
+
+G_BEGIN_DECLS
typedef struct _EAlertDialog EAlertDialog;
typedef struct _EAlertDialogClass EAlertDialogClass;
typedef struct _EAlertDialogPrivate EAlertDialogPrivate;
-struct _EAlertDialog
-{
- GtkDialog parent;
- EAlertDialogPrivate *priv;
+struct _EAlertDialog {
+ GtkDialog parent;
+ EAlertDialogPrivate *priv;
};
-struct _EAlertDialogClass
-{
- GtkDialogClass parent_class;
+struct _EAlertDialogClass {
+ GtkDialogClass parent_class;
};
-GType e_alert_dialog_get_type (void);
-
-GtkWidget* e_alert_dialog_new (GtkWindow* parent, EAlert *alert);
-GtkWidget* e_alert_dialog_new_for_args (GtkWindow* parent, const gchar *tag, ...) G_GNUC_NULL_TERMINATED;
-
-/* Convenience functions for displaying the alert in a GtkDialog */
-gint e_alert_run_dialog (GtkWindow *parent, EAlert *alert);
-gint e_alert_run_dialog_for_args (GtkWindow *parent, const gchar *tag, ...) G_GNUC_NULL_TERMINATED;
-
-guint e_alert_dialog_count_buttons (EAlertDialog *dialog);
-EAlert *e_alert_dialog_get_alert (EAlertDialog *dialog);
+GType e_alert_dialog_get_type (void);
+GtkWidget * e_alert_dialog_new (GtkWindow *parent,
+ EAlert *alert);
+GtkWidget * e_alert_dialog_new_for_args (GtkWindow *parent,
+ const gchar *tag,
+ ...) G_GNUC_NULL_TERMINATED;
+gint e_alert_run_dialog (GtkWindow *parent,
+ EAlert *alert);
+gint e_alert_run_dialog_for_args (GtkWindow *parent,
+ const gchar *tag,
+ ...) G_GNUC_NULL_TERMINATED;
+guint e_alert_dialog_count_buttons (EAlertDialog *dialog);
+EAlert * e_alert_dialog_get_alert (EAlertDialog *dialog);
G_END_DECLS
-#endif /* _E_ALERT_DIALOG_H */
+#endif /* E_ALERT_DIALOG_H */
diff --git a/e-util/e-alert.c b/e-util/e-alert.c
index ced83ddc0e..1846e6d1fa 100644
--- a/e-util/e-alert.c
+++ b/e-util/e-alert.c
@@ -52,7 +52,7 @@ struct _e_alert {
gint default_response;
const gchar *primary_text;
const gchar *secondary_text;
- struct _e_alert_button *buttons;
+ EAlertButton *buttons;
};
struct _e_alert_table {
@@ -65,7 +65,7 @@ static GHashTable *alert_table;
/* ********************************************************************** */
-static struct _e_alert_button default_ok_button = {
+static EAlertButton default_ok_button = {
NULL, "gtk-ok", NULL, GTK_RESPONSE_OK
};
@@ -78,31 +78,48 @@ static struct _e_alert default_alerts[] = {
/* ********************************************************************** */
-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 },
+struct _EAlertPrivate {
+ gchar *tag;
+ GPtrArray *args;
+ gchar *primary_text;
+ gchar *secondary_text;
+ struct _e_alert *definition;
+ GtkMessageType message_type;
+ gint default_response;
};
+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)
{
- gint i;
+ GEnumClass *class;
+ GEnumValue *value;
- for (i = 0; i < G_N_ELEMENTS (response_map); i++)
- if (!strcmp (name, response_map[i].name))
- return response_map[i].id;
+ class = g_type_class_ref (GTK_TYPE_RESPONSE_TYPE);
+ value = g_enum_get_value_by_name (class, name);
+ g_type_class_unref (class);
- return 0;
+ return (value != NULL) ? value->value : 0;
}
static GtkMessageType
@@ -111,36 +128,13 @@ map_type (const gchar *nick)
GEnumClass *class;
GEnumValue *value;
- class = g_type_class_peek (GTK_TYPE_MESSAGE_TYPE);
+ 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;
}
-G_DEFINE_TYPE (
- EAlert,
- e_alert,
- G_TYPE_OBJECT)
-
-enum {
- PROP_0,
- PROP_ARGS,
- PROP_TAG,
- PROP_MESSAGE_TYPE,
- PROP_PRIMARY_TEXT,
- PROP_SECONDARY_TEXT
-};
-
-struct _EAlertPrivate {
- gchar *tag;
- GPtrArray *args;
- gchar *primary_text;
- gchar *secondary_text;
- struct _e_alert *definition;
- GtkMessageType message_type;
- gint default_response;
-};
-
/*
XML format:
@@ -152,9 +146,6 @@ struct _EAlertPrivate {
response="response_id"? /> *
</error>
- The tool e-error-tool is used to extract the translatable strings for
- translation.
-
*/
static void
e_alert_load (const gchar *path)
@@ -162,7 +153,7 @@ e_alert_load (const gchar *path)
xmlDocPtr doc = NULL;
xmlNodePtr root, error, scan;
struct _e_alert *e;
- struct _e_alert_button *lastbutton;
+ EAlertButton *lastbutton;
struct _e_alert_table *table;
gchar *tmp;
@@ -217,7 +208,7 @@ e_alert_load (const gchar *path)
e->id = g_strdup (tmp);
xmlFree (tmp);
- lastbutton = (struct _e_alert_button *)&e->buttons;
+ lastbutton = (EAlertButton *)&e->buttons;
tmp = (gchar *)xmlGetProp(error, (const guchar *)"type");
e->message_type = map_type (tmp);
@@ -242,7 +233,7 @@ e_alert_load (const gchar *path)
xmlFree (tmp);
}
} else if (!strcmp((gchar *)scan->name, "button")) {
- struct _e_alert_button *b;
+ EAlertButton *b;
gchar *label = NULL;
gchar *stock = NULL;
@@ -557,6 +548,16 @@ e_alert_class_init (EAlertClass *class)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ signals[RESPONSE] = g_signal_new (
+ "response",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EAlertClass, response),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE, 1,
+ G_TYPE_INT);
+
e_alert_load_tables ();
}
@@ -730,16 +731,8 @@ e_alert_set_secondary_text (EAlert *alert,
g_object_notify (G_OBJECT (alert), "secondary-text");
}
-struct _e_alert_button *
-e_alert_peek_buttons (EAlert *alert)
-{
- g_return_val_if_fail (alert && alert->priv && alert->priv->definition, NULL);
- return alert->priv->definition->buttons;
-}
-
-GtkWidget *
-e_alert_create_image (EAlert *alert,
- GtkIconSize size)
+const gchar *
+e_alert_get_stock_id (EAlert *alert)
{
const gchar *stock_id;
@@ -764,10 +757,39 @@ e_alert_create_image (EAlert *alert,
break;
}
+ return stock_id;
+}
+
+EAlertButton *
+e_alert_peek_buttons (EAlert *alert)
+{
+ g_return_val_if_fail (alert && alert->priv && alert->priv->definition, NULL);
+ return alert->priv->definition->buttons;
+}
+
+GtkWidget *
+e_alert_create_image (EAlert *alert,
+ GtkIconSize size)
+{
+ const gchar *stock_id;
+
+ g_return_val_if_fail (E_IS_ALERT (alert), NULL);
+
+ stock_id = e_alert_get_stock_id (alert);
+
return gtk_image_new_from_stock (stock_id, size);
}
void
+e_alert_response (EAlert *alert,
+ gint response_id)
+{
+ g_return_if_fail (E_IS_ALERT (alert));
+
+ g_signal_emit (alert, signals[RESPONSE], 0, response_id);
+}
+
+void
e_alert_submit (GtkWidget *widget,
const gchar *tag,
...)
diff --git a/e-util/e-alert.h b/e-util/e-alert.h
index fe705c5036..e0ad92c7d2 100644
--- a/e-util/e-alert.h
+++ b/e-util/e-alert.h
@@ -61,8 +61,10 @@ typedef struct _EAlert EAlert;
typedef struct _EAlertClass EAlertClass;
typedef struct _EAlertPrivate EAlertPrivate;
-struct _e_alert_button {
- struct _e_alert_button *next;
+typedef struct _EAlertButton EAlertButton;
+
+struct _EAlertButton {
+ EAlertButton *next;
const gchar *stock;
const gchar *label;
gint response;
@@ -75,6 +77,10 @@ struct _EAlert {
struct _EAlertClass {
GObjectClass parent_class;
+
+ /* Signals */
+ void (*response) (EAlert *alert,
+ gint response_id);
};
GType e_alert_get_type (void);
@@ -96,10 +102,12 @@ void e_alert_set_primary_text (EAlert *alert,
const gchar * e_alert_get_secondary_text (EAlert *alert);
void e_alert_set_secondary_text (EAlert *alert,
const gchar *secondary_text);
-struct _e_alert_button *
- e_alert_peek_buttons (EAlert *alert);
+const gchar * e_alert_get_stock_id (EAlert *alert);
+EAlertButton * e_alert_peek_buttons (EAlert *alert);
GtkWidget * e_alert_create_image (EAlert *alert,
GtkIconSize size);
+void e_alert_response (EAlert *alert,
+ gint response_id);
void e_alert_submit (GtkWidget *widget,
const gchar *tag,
diff --git a/e-util/e-marshal.list b/e-util/e-marshal.list
index 9cc975f3b4..d4e6f43f15 100644
--- a/e-util/e-marshal.list
+++ b/e-util/e-marshal.list
@@ -20,6 +20,7 @@ INT:INT,INT,BOXED
INT:INT,POINTER,INT,BOXED
INT:OBJECT,BOXED
INT:POINTER
+NONE:ENUM,OBJECT,OBJECT
NONE:INT,INT
NONE:INT,INT,BOXED
NONE:INT,INT,OBJECT