diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-09-30 09:11:44 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-09-30 09:11:44 +0800 |
commit | 0e4c54eddced72c9639001849148fe1813c5dc4e (patch) | |
tree | 3ba53e853901d3b7e733b6aed145c5eb54e6a2fc /e-util/e-alert-sink.c | |
parent | d3b09614221d075452496a5198a3910d07eb2818 (diff) | |
download | gsoc2013-evolution-0e4c54eddced72c9639001849148fe1813c5dc4e.tar.gz gsoc2013-evolution-0e4c54eddced72c9639001849148fe1813c5dc4e.tar.zst gsoc2013-evolution-0e4c54eddced72c9639001849148fe1813c5dc4e.zip |
Messin around with EAlerts.
Trying out a new interface called EAlertSink. The idea is to centralize
how errors are shown to the user. A GtkWindow subclass would implement
the EAlertSink interface, which consists of a single method:
void (*submit_alert) (EAlertSink *alert_sink, EAlert *alert);
The subclass has complete control over what to do with the EAlert,
although I imagine we'll wind up implementing various alert-handling
policies as standalone widgets such as EAlertDialog. I'd like to try
an EAlertInfoBar.
Code that would otherwise display an error dialog itself would instead
pass the EAlert to an appropriate EAlertSink and be done with it.
Nothing is final yet. Still hacking on EAlert trying to find an API
that feels right for these use cases.
Diffstat (limited to 'e-util/e-alert-sink.c')
-rw-r--r-- | e-util/e-alert-sink.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/e-util/e-alert-sink.c b/e-util/e-alert-sink.c new file mode 100644 index 0000000000..de676ea778 --- /dev/null +++ b/e-util/e-alert-sink.c @@ -0,0 +1,92 @@ +/* + * e-alert-sink.c + * + * 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 <http://www.gnu.org/licenses/> + * + */ + +/** + * SECTION: e-alert-sink + * @short_description: an interface to handle alerts + * @include: e-util/e-alert-sink.h + * + * A widget that implements #EAlertSink means it can handle #EAlerts, + * usually by displaying them to the user. + **/ + +#include "e-alert-sink.h" + +#include "e-alert-dialog.h" + +G_DEFINE_INTERFACE ( + EAlertSink, + e_alert_sink, + GTK_TYPE_WIDGET) + +static void +alert_sink_submit_alert (EAlertSink *alert_sink, + EAlert *alert) +{ + GtkWidget *dialog; + gpointer parent; + + /* This is just a lame fallback handler. Implementors + * are strongly encouraged to override this method. */ + + parent = gtk_widget_get_toplevel (GTK_WIDGET (alert_sink)); + parent = gtk_widget_is_toplevel (parent) ? parent : NULL; + + dialog = e_alert_dialog_new (parent, alert); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} + +static void +e_alert_sink_default_init (EAlertSinkInterface *interface) +{ + interface->submit_alert = alert_sink_submit_alert; +} + +/** + * e_alert_sink_submit_alert: + * @widget: a #GtkWidget, either itself an #EAlertSink or a child of one + * @alert: an #EAlert + * + * This function is a place to pass #EAlert objects. Beyond that it has no + * well-defined behavior. It's up to the widget implementing the #EAlertSink + * interface to decide what to do with them. + * + * Either @widget or one of its parents must implement #EAlertSink. + * + * The default behavior is to display the @alert in a dialog. + **/ +void +e_alert_sink_submit_alert (GtkWidget *widget, + EAlert *alert) +{ + EAlertSinkInterface *interface; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (E_IS_ALERT (alert)); + + while (widget != NULL && !E_IS_ALERT_SINK (widget)) + widget = gtk_widget_get_parent (widget); + + g_return_if_fail (E_IS_ALERT_SINK (widget)); + + interface = E_ALERT_SINK_GET_INTERFACE (widget); + g_return_if_fail (interface->submit_alert != NULL); + + interface->submit_alert (E_ALERT_SINK (widget), alert); +} |