]> git.sur5r.net Git - glabels/blob - src/critical-error-handler.c
Imported Upstream version 3.0.0
[glabels] / src / critical-error-handler.c
1 /*
2  *  critical-error-handler.h
3  *  Copyright (C) 2005-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "critical-error-handler.h"
24
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
28 #include <stdlib.h>
29
30
31 static void critical_error_handler (const gchar    *log_domain,
32                                     GLogLevelFlags  log_level,
33                                     const gchar    *message,
34                                     gpointer        user_data);
35
36
37 /***************************************************************************/
38 /* Initialize error handler.                                               */
39 /***************************************************************************/
40 void
41 gl_critical_error_handler_init (void)
42 {
43         g_log_set_handler ("LibGlabels",
44                            G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
45                            critical_error_handler,
46                            "libglabels");
47
48         g_log_set_handler (G_LOG_DOMAIN,
49                            G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
50                            critical_error_handler,
51                            "glabels");
52 }
53
54
55 /*-------------------------------------------------------------------------*/
56 /* PRIVATE.  Actual error handler.                                         */
57 /*-------------------------------------------------------------------------*/
58 static void
59 critical_error_handler (const gchar    *log_domain,
60                         GLogLevelFlags  log_level,
61                         const gchar    *message,
62                         gpointer        user_data)
63 {
64         GtkWidget *dialog;
65
66         dialog = gtk_message_dialog_new (NULL,
67                                          GTK_DIALOG_MODAL,
68                                          GTK_MESSAGE_ERROR,
69                                          GTK_BUTTONS_NONE,
70                                          _("gLabels Fatal Error!"));
71         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
72                                                   "%s", message);
73         gtk_dialog_add_button (GTK_DIALOG (dialog),
74                                GTK_STOCK_QUIT, 0);
75
76         gtk_dialog_run (GTK_DIALOG (dialog));
77
78         abort ();
79 }
80
81
82
83 /*
84  * Local Variables:       -- emacs
85  * mode: C                -- emacs
86  * c-basic-offset: 8      -- emacs
87  * tab-width: 8           -- emacs
88  * indent-tabs-mode: nil  -- emacs
89  * End:                   -- emacs
90  */