aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-alert-dialog.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-10-16 02:51:13 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-10-19 00:32:36 +0800
commit51ebf20237270a785af0aa0e614db42275a05c62 (patch)
tree328b2fe9b7aa111f0cb21f23b11bc2eaf6da3ac8 /e-util/e-alert-dialog.c
parent2197e6401ec8c5e1b77fa51e085ac068daa39e6a (diff)
downloadgsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.tar
gsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.tar.gz
gsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.tar.bz2
gsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.tar.lz
gsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.tar.xz
gsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.tar.zst
gsoc2013-evolution-51ebf20237270a785af0aa0e614db42275a05c62.zip
EAlert: Allow arbitrary actions to be added.
You can now amend the predefined actions in an EAlert by calling e_alert_add_action(). Useful for adding actions from an existing GtkUIManager. Call e_alert_peek_actions() to obtain a combined list of predefined and custom actions. These will typically serve as "related" actions for GtkButtons (cf. gtk_activatable_set_related_action()). Also, both EShellWindow and EShellView now implement EAlertSink. Use EShellWindow for application-wide alerts, EShellView for view-specific alerts.
Diffstat (limited to 'e-util/e-alert-dialog.c')
-rw-r--r--e-util/e-alert-dialog.c100
1 files changed, 49 insertions, 51 deletions
diff --git a/e-util/e-alert-dialog.c b/e-util/e-alert-dialog.c
index 4d6fcd8e6e..888c9121f9 100644
--- a/e-util/e-alert-dialog.c
+++ b/e-util/e-alert-dialog.c
@@ -22,10 +22,13 @@
*/
#include "e-alert-dialog.h"
+
#include "e-util.h"
+#include "e-alert-action.h"
-#define E_ALERT_DIALOG_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), E_TYPE_ALERT_DIALOG, EAlertDialogPrivate))
+#define E_ALERT_DIALOG_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_ALERT_DIALOG, EAlertDialogPrivate))
struct _EAlertDialogPrivate {
GtkWindow *parent;
@@ -94,6 +97,9 @@ alert_dialog_dispose (GObject *object)
priv = E_ALERT_DIALOG_GET_PRIVATE (object);
if (priv->alert) {
+ g_signal_handlers_disconnect_matched (
+ priv->alert, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, object);
g_object_unref (priv->alert);
priv->alert = NULL;
}
@@ -105,61 +111,67 @@ alert_dialog_dispose (GObject *object)
static void
alert_dialog_constructed (GObject *object)
{
- EAlertDialog *self = (EAlertDialog*) object;
EAlert *alert;
- EAlertButton *b;
+ EAlertDialog *dialog;
GtkWidget *action_area;
GtkWidget *content_area;
GtkWidget *container;
GtkWidget *widget;
PangoAttribute *attr;
PangoAttrList *list;
+ GList *actions;
const gchar *primary, *secondary;
- g_return_if_fail (self != NULL);
-
- alert = e_alert_dialog_get_alert (E_ALERT_DIALOG (self));
+ dialog = E_ALERT_DIALOG (object);
+ alert = e_alert_dialog_get_alert (dialog);
- gtk_window_set_title (GTK_WINDOW (self), " ");
+ gtk_window_set_title (GTK_WINDOW (dialog), " ");
- action_area = gtk_dialog_get_action_area (GTK_DIALOG (self));
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (self));
+ action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
#if !GTK_CHECK_VERSION(2,90,7)
- g_object_set (self, "has-separator", FALSE, NULL);
+ g_object_set (dialog, "has-separator", FALSE, NULL);
#endif
- gtk_widget_ensure_style (GTK_WIDGET (self));
+ gtk_widget_ensure_style (GTK_WIDGET (dialog));
gtk_container_set_border_width (GTK_CONTAINER (action_area), 12);
gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
- gtk_window_set_destroy_with_parent (GTK_WINDOW (self), TRUE);
-
- b = e_alert_peek_buttons (alert);
- if (b == NULL) {
- 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 != 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 (
- GTK_DIALOG (self),
- b->label, b->response);
- }
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+
+ /* Forward EAlert::response signals to GtkDialog::response. */
+ g_signal_connect_swapped (
+ alert, "response",
+ G_CALLBACK (gtk_dialog_response), dialog);
+
+ /* Add buttons from actions. */
+ actions = e_alert_peek_actions (alert);
+ while (actions != NULL) {
+ GtkWidget *button;
+
+ /* These actions are already wired to trigger an
+ * EAlert::response signal when activated, which
+ * will in turn call to gtk_dialog_response(),
+ * so we can add buttons directly to the action
+ * area without knowing their response IDs. */
+
+ button = gtk_button_new ();
+
+ gtk_activatable_set_related_action (
+ GTK_ACTIVATABLE (button),
+ GTK_ACTION (actions->data));
+
+ gtk_box_pack_end (
+ GTK_BOX (action_area),
+ button, FALSE, TRUE, 0);
+
+ actions = g_list_next (actions);
}
if (e_alert_get_default_response (alert))
gtk_dialog_set_default_response (
- GTK_DIALOG (self),
+ GTK_DIALOG (dialog),
e_alert_get_default_response (alert));
widget = gtk_hbox_new (FALSE, 12);
@@ -210,20 +222,9 @@ alert_dialog_constructed (GObject *object)
}
static void
-alert_dialog_response (GtkDialog *dialog,
- gint response_id)
-{
- EAlert *alert;
-
- alert = e_alert_dialog_get_alert (E_ALERT_DIALOG (dialog));
- e_alert_response (alert, response_id);
-}
-
-static void
e_alert_dialog_class_init (EAlertDialogClass *class)
{
GObjectClass *object_class;
- GtkDialogClass *dialog_class;
g_type_class_add_private (class, sizeof (EAlertDialogPrivate));
@@ -233,9 +234,6 @@ e_alert_dialog_class_init (EAlertDialogClass *class)
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,
@@ -250,9 +248,9 @@ e_alert_dialog_class_init (EAlertDialogClass *class)
}
static void
-e_alert_dialog_init (EAlertDialog *self)
+e_alert_dialog_init (EAlertDialog *dialog)
{
- self->priv = E_ALERT_DIALOG_GET_PRIVATE (self);
+ dialog->priv = E_ALERT_DIALOG_GET_PRIVATE (dialog);
}
GtkWidget *