Continue reforming error message support. In this phase, drop actual
[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 #include "progname.h"
30
31
32 #include <gtk/gtk.h>
33 #include <glade/glade.h>
34
35 #include "helper.h"
36
37 extern GladeXML *xml;
38
39 #define _(A) A
40
41 static void handle_msg(const struct msg *);
42
43 void
44 message_dialog_init (void) 
45 {
46   msg_init(handle_msg);
47 }
48
49 static void
50 handle_msg(const struct msg *m)
51 {
52   GtkWindow *parent;
53   GtkWidget *dialog;
54
55   gint message_type;
56   const char *msg;
57
58   switch (m->severity)
59     {
60     case MSG_ERROR:
61       message_type = GTK_MESSAGE_ERROR;
62       break;
63     case MSG_WARNING:
64       message_type = GTK_MESSAGE_WARNING;
65       break;
66     case MSG_NOTE:
67     default:
68       message_type = GTK_MESSAGE_INFO;
69       break;
70     };
71   
72   switch (m->category) 
73     {
74     case MSG_SYNTAX:
75       msg = _("Script Error");
76       break;
77
78     case MSG_DATA:
79       msg = _("Data File Error");
80       break;
81
82     case MSG_GENERAL:
83     default:
84       msg = _("PSPP Error");
85       break;
86     };
87   
88   parent = GTK_WINDOW(get_widget_assert(xml, "data_editor"));
89
90   dialog = gtk_message_dialog_new(parent,
91                                   GTK_DIALOG_MODAL,
92                                   message_type,
93                                   GTK_BUTTONS_CLOSE,
94                                   msg);
95   
96   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
97                                            "%s", m->text);
98     
99   gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
100
101   gtk_dialog_run(GTK_DIALOG(dialog));
102
103   gtk_widget_destroy (dialog);
104 }
105
106 /* FIXME: This is a stub .
107  * A temporary workaround until getl.c is rearranged
108  */
109 void
110 msg_location (struct msg_locator *loc)
111 {
112         loc->file_name = 0;
113         loc->line_number = -1;
114 }
115