Fixed a multitude of C89 compatibility warnings.
[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   GtkWindow *parent ;
48   GtkWidget *dialog ;
49                     
50   gint message_type;
51
52   switch (klass)
53     {
54     case SE:
55     case IE:
56     case DE:
57     case ME:
58       message_type = GTK_MESSAGE_ERROR;
59       break;
60     case SW:
61     case DW:
62     case MW:
63       message_type = GTK_MESSAGE_WARNING;
64       break;
65     case SM:
66     case IS:
67     case MM:
68     default:
69       message_type = GTK_MESSAGE_INFO;
70       break;
71     };
72   
73   switch (klass) 
74     {
75     case SE:
76     case SW:
77     case SM:
78       msg = g_strdup(_("Script Error"));
79       break;
80
81     case IE:
82     case IS:
83       msg = g_strdup(_("Installation Error"));
84       break;
85
86     case DE:
87     case DW:
88       msg = g_strdup(_("Data File Error"));
89       break;
90
91     case ME:
92     case MW:
93     case MM:
94     default:
95       msg = g_strdup(_("PSPP Error"));
96       break;
97     };
98   
99   parent = GTK_WINDOW(get_widget_assert(xml, "data_editor"));
100
101   dialog = gtk_message_dialog_new(parent,
102                                   GTK_DIALOG_MODAL,
103                                   message_type,
104                                   GTK_BUTTONS_CLOSE,
105                                   msg);
106   
107   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), text);
108
109   g_free(text);
110   g_free(msg);
111     
112   gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
113
114   gtk_dialog_run(GTK_DIALOG(dialog));
115
116   gtk_widget_destroy (dialog);
117
118 }
119
120
121 void 
122 msg(int klass, const char *fmt, ...)
123 {
124   va_list ap;
125   va_start(ap, fmt);
126   vmsg(klass, fmt, ap);
127   va_end(ap);
128 }
129
130
131 void
132 err_vmsg (const struct error *e, const char *format, va_list args)
133 {
134   vmsg(e->class, format, args);
135 }
136
137
138 void 
139 err_assert_fail(const char *expr, const char *file, int line)
140 {
141   msg(ME, "Assertion failed: %s:%d; (%s)\n",file,line,expr);
142 }
143
144 /* The GUI is always interactive.
145    So this function does nothing */
146 void 
147 err_cond_fail(void)
148 {
149 }
150
151
152 void
153 err_failure(void)
154 {
155   msg(ME, _("Terminating NOW due to fatal error"));
156   gtk_main_quit();
157 }
158
159
160 /* FIXME: This is a stub .
161  * A temporary workaround until getl.c is rearranged
162  */
163 void
164 err_location (struct file_locator *f)
165 {
166         f->filename = 0;
167         f->line_number = -1;
168 }
169