1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #define _(msgid) gettext (msgid)
24 #define N_(msgid) msgid
26 #include <libpspp/message.h>
27 #include <libpspp/str.h>
28 #include <libpspp/msg-locator.h>
29 #include "message-dialog.h"
34 #include <glade/glade.h>
39 static void enqueue_msg (const struct msg *m);
40 static gboolean popup_messages (gpointer);
42 #define MAX_EARLY_MESSAGES 100
43 static GQueue *early_queue;
45 static unsigned long dropped_messages;
47 #define MAX_LATE_MESSAGES 10
48 static GQueue *late_queue;
50 static int error_cnt, warning_cnt, note_cnt;
52 static GladeXML *message_xml;
53 static GtkDialog *message_dialog;
56 message_dialog_init (struct source_stream *ss)
58 early_queue = g_queue_new ();
60 late_queue = g_queue_new ();
61 error_cnt = warning_cnt = note_cnt = 0;
62 msg_init (ss, enqueue_msg);
63 message_xml = XML_NEW ("message-dialog.glade");
64 message_dialog = GTK_DIALOG (get_widget_assert (message_xml,
69 message_dialog_done (void)
72 g_queue_free (early_queue);
74 g_queue_free (late_queue);
75 gtk_widget_destroy (GTK_WIDGET (message_dialog));
76 g_object_unref (message_xml);
80 format_message (struct msg *m, struct string *msg)
84 if (m->where.file_name)
85 ds_put_format (msg, "%s:", m->where.file_name);
86 if (m->where.line_number != -1)
87 ds_put_format (msg, "%d:", m->where.line_number);
88 if (m->where.file_name || m->where.line_number != -1)
89 ds_put_char (msg, ' ');
97 label = _("syntax error");
101 label = _("data file error");
106 label = _("PSPP error");
114 label = _("syntax warning");
118 label = _("data file warning");
123 label = _("PSPP warning");
132 label = _("syntax information");
136 label = _("data file information");
141 label = _("PSPP information");
146 ds_put_format (msg, "%s: %s\n", label, m->text);
151 enqueue_msg (const struct msg *msg)
153 struct msg *m = msg_dup (msg);
168 if (g_queue_get_length (early_queue) < MAX_EARLY_MESSAGES)
170 if (g_queue_is_empty (early_queue))
171 g_idle_add (popup_messages, NULL);
172 g_queue_push_tail (early_queue, m);
176 if (g_queue_get_length (late_queue) >= MAX_LATE_MESSAGES)
178 struct msg *m = g_queue_pop_head (late_queue);
182 g_queue_push_tail (late_queue, m);
187 popup_messages (gpointer unused UNUSED)
189 GtkTextBuffer *text_buffer;
191 GtkTextView *text_view;
193 struct string lead = DS_EMPTY_INITIALIZER;
194 struct string msg = DS_EMPTY_INITIALIZER;
197 /* If a pointer grab is in effect, then the combination of that, and
198 a modal dialog box, will cause an impossible situation.
199 So don't pop it up just yet.
201 if ( gdk_pointer_is_grabbed ())
204 /* Compose the lead-in. */
205 message_cnt = error_cnt + warning_cnt + note_cnt;
206 if (dropped_messages == 0)
209 ngettext ("The PSPP processing engine reported the following message:",
210 "The PSPP processing engine reported the following messages:",
216 ngettext ("The PSPP processing engine reported %d message.",
217 "The PSPP processing engine reported %d messages.",
220 ds_put_cstr (&lead, " ");
223 ngettext ("%d of these messages are displayed below.",
224 "%d of these messages are displayed below.",
225 MAX_EARLY_MESSAGES + MAX_LATE_MESSAGES),
226 MAX_EARLY_MESSAGES + MAX_LATE_MESSAGES);
230 /* Compose the messages. */
231 while (!g_queue_is_empty (early_queue))
232 format_message (g_queue_pop_head (early_queue), &msg);
233 if (dropped_messages)
235 ds_put_format (&msg, "...\nOmitting %lu messages\n...\n",
237 dropped_messages = 0;
239 while (!g_queue_is_empty (late_queue))
240 format_message (g_queue_pop_head (late_queue), &msg);
242 /* Set up the dialog. */
243 if (message_xml == NULL || message_dialog == NULL)
246 text_buffer = gtk_text_buffer_new (NULL);
247 gtk_text_buffer_get_end_iter (text_buffer, &end);
248 gtk_text_buffer_insert (text_buffer, &end, ds_data (&msg), ds_length (&msg));
250 label = GTK_LABEL (get_widget_assert (message_xml, "lead-in"));
253 gtk_label_set_text (label, ds_cstr (&lead));
255 text_view = GTK_TEXT_VIEW (get_widget_assert (message_xml, "message"));
256 if (text_view == NULL)
258 gtk_text_view_set_buffer (text_view, text_buffer);
260 gtk_dialog_run (message_dialog);
261 gtk_widget_hide (GTK_WIDGET (message_dialog));
269 g_warning ("Could not create message dialog. "
270 "Is PSPPIRE properly installed?");
271 fputs (ds_cstr (&msg), stderr);