No issues found
1 /*
2 * e-alert-sink.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 /**
20 * SECTION: e-alert-sink
21 * @short_description: an interface to handle alerts
22 * @include: libevolution-utils/e-alert-sink.h
23 *
24 * A widget that implements #EAlertSink means it can handle #EAlerts,
25 * usually by displaying them to the user.
26 **/
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #include "e-alert-sink.h"
33
34 #include "e-alert-dialog.h"
35
36 G_DEFINE_INTERFACE (
37 EAlertSink,
38 e_alert_sink,
39 GTK_TYPE_WIDGET)
40
41 static void
42 alert_sink_fallback (GtkWidget *widget,
43 EAlert *alert)
44 {
45 GtkWidget *dialog;
46 gpointer parent;
47
48 parent = gtk_widget_get_toplevel (widget);
49 parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
50
51 dialog = e_alert_dialog_new (parent, alert);
52 gtk_dialog_run (GTK_DIALOG (dialog));
53 gtk_widget_destroy (dialog);
54 }
55
56 static void
57 alert_sink_submit_alert (EAlertSink *alert_sink,
58 EAlert *alert)
59 {
60 /* This is just a lame fallback handler. Implementors
61 * are strongly encouraged to override this method. */
62 alert_sink_fallback (GTK_WIDGET (alert_sink), alert);
63 }
64
65 static void
66 e_alert_sink_default_init (EAlertSinkInterface *interface)
67 {
68 interface->submit_alert = alert_sink_submit_alert;
69 }
70
71 /**
72 * e_alert_sink_submit_alert:
73 * @alert_sink: an #EAlertSink
74 * @alert: an #EAlert
75 *
76 * This function is a place to pass #EAlert objects. Beyond that it has no
77 * well-defined behavior. It's up to the widget implementing the #EAlertSink
78 * interface to decide what to do with them.
79 **/
80 void
81 e_alert_sink_submit_alert (EAlertSink *alert_sink,
82 EAlert *alert)
83 {
84 EAlertSinkInterface *interface;
85
86 g_return_if_fail (E_IS_ALERT_SINK (alert_sink));
87 g_return_if_fail (E_IS_ALERT (alert));
88
89 interface = E_ALERT_SINK_GET_INTERFACE (alert_sink);
90 g_return_if_fail (interface->submit_alert != NULL);
91
92 interface->submit_alert (alert_sink, alert);
93 }