6e93f7e6b3a7d77d8d10a5918de1c58be87778ec
[pspp-builds.git] / src / ui / gui / message-dialog.c
1 /* 
2    PSPPIRE --- A Graphical User Interface for PSPP
3    Copyright (C) 2004,2005  Free Software Foundation
4    Written by John Darrington
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA. 
20 */
21
22
23 #include <stdio.h>
24 #include <stdarg.h>
25
26 #include <config.h>
27 #include <libpspp/message.h>
28 #include "message-dialog.h"
29
30
31 #include <gtk/gtk.h>
32 #include <glade/glade.h>
33
34 #include "helper.h"
35
36 extern GladeXML *xml;
37
38 #define _(A) A
39
40
41 void 
42 vmsg(int klass, const char *fmt, va_list args)
43 {
44   gchar *msg = 0;
45   gchar *text = g_strdup_vprintf (fmt, args);
46
47   gint message_type;
48
49   switch (klass)
50     {
51     case SE:
52     case IE:
53     case DE:
54     case ME:
55       message_type = GTK_MESSAGE_ERROR;
56       break;
57     case SW:
58     case DW:
59     case MW:
60       message_type = GTK_MESSAGE_WARNING;
61       break;
62     case SM:
63     case IS:
64     case MM:
65     default:
66       message_type = GTK_MESSAGE_INFO;
67       break;
68     };
69   
70   switch (klass) 
71     {
72     case SE:
73     case SW:
74     case SM:
75       msg = g_strdup(_("Script Error"));
76       break;
77
78     case IE:
79     case IS:
80       msg = g_strdup(_("Installation Error"));
81       break;
82
83     case DE:
84     case DW:
85       msg = g_strdup(_("Data File Error"));
86       break;
87
88     case ME:
89     case MW:
90     case MM:
91     default:
92       msg = g_strdup(_("PSPP Error"));
93       break;
94     };
95   
96   GtkWindow *parent = GTK_WINDOW(get_widget_assert(xml, "data_editor"));
97
98   GtkWidget *dialog  =  gtk_message_dialog_new(parent,
99                                                GTK_DIALOG_MODAL,
100                                                message_type,
101                                                GTK_BUTTONS_CLOSE,
102                                                msg);
103
104   
105   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), text);
106
107   g_free(text);
108   g_free(msg);
109     
110   gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
111
112   gtk_dialog_run(GTK_DIALOG(dialog));
113
114   gtk_widget_destroy (dialog);
115
116 }
117
118
119 void 
120 msg(int klass, const char *fmt, ...)
121 {
122   va_list ap;
123   va_start(ap, fmt);
124   vmsg(klass, fmt, ap);
125   va_end(ap);
126 }
127
128
129 void
130 err_vmsg (const struct error *e, const char *format, va_list args)
131 {
132   vmsg(e->class, format, args);
133 }
134
135
136 void 
137 err_assert_fail(const char *expr, const char *file, int line)
138 {
139   msg(ME, "Assertion failed: %s:%d; (%s)\n",file,line,expr);
140 }
141
142 /* The GUI is always interactive.
143    So this function does nothing */
144 void 
145 err_cond_fail(void)
146 {
147 }
148
149
150 void
151 err_failure(void)
152 {
153   msg(ME, _("Terminating NOW due to fatal error"));
154   gtk_main_quit();
155 }
156
157
158 /* FIXME: This is a stub .
159  * A temporary workaround until getl.c is rearranged
160  */
161 void
162 err_location (struct file_locator *f)
163 {
164         f->filename = 0;
165         f->line_number = -1;
166 }
167