From 2ecce97b88d418a77eb399ff4ca70a329e6aed3b Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 10 Aug 2013 16:41:38 -0400 Subject: Add e_alert_bar_close_alert(). Closes the active EAlert and returns TRUE, or else returns FALSE if there is no active EAlert. --- .../evolution-util/evolution-util-sections.txt | 1 + e-util/e-alert-bar.c | 40 ++++++++++++++++++++++ e-util/e-alert-bar.h | 1 + 3 files changed, 42 insertions(+) diff --git a/doc/reference/evolution-util/evolution-util-sections.txt b/doc/reference/evolution-util/evolution-util-sections.txt index f4878fd4fd..aa1ac5f920 100644 --- a/doc/reference/evolution-util/evolution-util-sections.txt +++ b/doc/reference/evolution-util/evolution-util-sections.txt @@ -162,6 +162,7 @@ EAlertBar e_alert_bar_new e_alert_bar_clear e_alert_bar_add_alert +e_alert_bar_close_alert E_ALERT_BAR E_IS_ALERT_BAR diff --git a/e-util/e-alert-bar.c b/e-util/e-alert-bar.c index c19fa74a47..4e621d7f56 100644 --- a/e-util/e-alert-bar.c +++ b/e-util/e-alert-bar.c @@ -297,11 +297,21 @@ alert_bar_get_request_mode (GtkWidget *widget) return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; } +static void +alert_bar_close (GtkInfoBar *info_bar) +{ + /* GtkInfoBar's close() method looks for a button with a response + * code of GTK_RESPONSE_CANCEL. But that does not apply here, so + * we have to override the method. */ + e_alert_bar_close_alert (E_ALERT_BAR (info_bar)); +} + static void e_alert_bar_class_init (EAlertBarClass *class) { GObjectClass *object_class; GtkWidgetClass *widget_class; + GtkInfoBarClass *info_bar_class; g_type_class_add_private (class, sizeof (EAlertBarPrivate)); @@ -311,6 +321,9 @@ e_alert_bar_class_init (EAlertBarClass *class) widget_class = GTK_WIDGET_CLASS (class); widget_class->get_request_mode = alert_bar_get_request_mode; + + info_bar_class = GTK_INFO_BAR_CLASS (class); + info_bar_class->close = alert_bar_close; } static void @@ -388,3 +401,30 @@ e_alert_bar_add_alert (EAlertBar *alert_bar, alert_bar_show_alert (alert_bar); } + +/** + * e_alert_bar_close_alert: + * @alert_bar: an #EAlertBar + * + * Closes the active #EAlert and returns %TRUE, or else returns %FALSE if + * there is no active #EAlert. + * + * Returns: whether an #EAlert was closed + **/ +gboolean +e_alert_bar_close_alert (EAlertBar *alert_bar) +{ + EAlert *alert; + gboolean alert_closed = FALSE; + + g_return_val_if_fail (E_IS_ALERT_BAR (alert_bar), FALSE); + + alert = g_queue_peek_head (&alert_bar->priv->alerts); + + if (alert != NULL) { + alert_bar_response_close (alert); + alert_closed = TRUE; + } + + return alert_closed; +} diff --git a/e-util/e-alert-bar.h b/e-util/e-alert-bar.h index d565f1ba84..560465756c 100644 --- a/e-util/e-alert-bar.h +++ b/e-util/e-alert-bar.h @@ -66,6 +66,7 @@ GtkWidget * e_alert_bar_new (void); void e_alert_bar_clear (EAlertBar *alert_bar); void e_alert_bar_add_alert (EAlertBar *alert_bar, EAlert *alert); +gboolean e_alert_bar_close_alert (EAlertBar *alert_bar); G_END_DECLS -- cgit v1.2.3