Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / ui / gui / message-dialog.c
index 693db49f70f2a9ddd1dcfd281b8d6a8820a0f5bd..fca13956b1f600fb8ea141ed54df6a02e1979c8f 100644 (file)
@@ -1,11 +1,9 @@
-/* 
-   PSPPIRE --- A Graphical User Interface for PSPP
-   Copyright (C) 2004,2005  Free Software Foundation
-   Written by John Darrington
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or modify
+   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. 
-*/
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 
 #include <stdio.h>
 #include <stdarg.h>
 
 #include <config.h>
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
 #include <libpspp/message.h>
+#include <libpspp/msg-locator.h>
 #include "message-dialog.h"
 #include "progname.h"
 
 
 #include <gtk/gtk.h>
 #include <glade/glade.h>
+#include <glib.h>
 
 #include "helper.h"
 
-extern GladeXML *xml;
+static void enqueue_msg (const struct msg *m);
+
+
+static GQueue *message_queue;
+
+
+void
+message_dialog_init (struct source_stream *ss)
+{
+  message_queue = g_queue_new ();
+  msg_init (ss, enqueue_msg);
+}
+
+void
+message_dialog_done (void)
+{
+  msg_done ();
+  g_queue_free (message_queue);
+}
+
+static gboolean
+dequeue_message (gpointer data)
+{
+  struct msg * m ;
+
+  /* If a pointer grab is in effect, then the combination of that, and
+     a modal dialog box, will cause an impossible situation.
+     So don't pop it up just yet.
+  */
+  if ( gdk_pointer_is_grabbed ())
+    return TRUE;
 
-#define _(A) A
+  m = g_queue_pop_tail (message_queue);
 
+  if ( m )
+    {
+      popup_message (m);
+      msg_destroy (m);
+      return TRUE;
+    }
 
-void 
-vmsg(int klass, const char *fmt, va_list args)
+  return FALSE;
+}
+
+static void
+enqueue_msg (const struct msg *msg)
 {
-  gchar *msg = 0;
-  gchar *text = g_strdup_vprintf (fmt, args);
+  struct msg *m = msg_dup (msg);
+
+  g_queue_push_head (message_queue, m);
+
+  g_idle_add (dequeue_message, 0);
+}
+
+
+void
+popup_message (const struct msg *m)
+{
+  GtkWidget *dialog;
+  gchar *location = NULL;
 
-  GtkWindow *parent ;
-  GtkWidget *dialog ;
-                   
   gint message_type;
+  const char *msg;
 
-  switch (klass)
+  switch (m->severity)
     {
-    case SE:
-    case DE:
-    case ME:
+    case MSG_ERROR:
       message_type = GTK_MESSAGE_ERROR;
       break;
-    case SW:
-    case DW:
-    case MW:
+    case MSG_WARNING:
       message_type = GTK_MESSAGE_WARNING;
       break;
-    case SM:
-    case MM:
+    case MSG_NOTE:
     default:
       message_type = GTK_MESSAGE_INFO;
       break;
     };
-  
-  switch (klass) 
+
+  switch (m->category)
     {
-    case SE:
-    case SW:
-    case SM:
-      msg = g_strdup(_("Script Error"));
+    case MSG_SYNTAX:
+      msg = _("Script Error");
       break;
 
-    case DE:
-    case DW:
-      msg = g_strdup(_("Data File Error"));
+    case MSG_DATA:
+      msg = _("Data File Error");
       break;
 
-    case ME:
-    case MW:
-    case MM:
+    case MSG_GENERAL:
     default:
-      msg = g_strdup(_("PSPP Error"));
+      msg = _("PSPP Error");
       break;
     };
-  
-  parent = GTK_WINDOW(get_widget_assert(xml, "data_editor"));
 
-  dialog = gtk_message_dialog_new(parent,
+  dialog = gtk_message_dialog_new ( NULL,
                                  GTK_DIALOG_MODAL,
                                  message_type,
                                  GTK_BUTTONS_CLOSE,
                                  msg);
-  
-  gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), text);
-
-  g_free(text);
-  g_free(msg);
-    
-  gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
-
-  gtk_dialog_run(GTK_DIALOG(dialog));
-
-  gtk_widget_destroy (dialog);
-
-}
-
-
-void 
-msg(int klass, const char *fmt, ...)
-{
-  va_list ap;
-  va_start(ap, fmt);
-  vmsg(klass, fmt, ap);
-  va_end(ap);
-}
-
-
-void
-err_vmsg (const struct error *e, const char *format, va_list args)
-{
-  vmsg(e->class, format, args);
-}
+  if ( m->where.line_number != -1)
+    {
+      location = g_strdup_printf (_("%s (line %d)"),
+                                 m->where.file_name ? m->where.file_name : "",
+                                 m->where.line_number);
+    }
+  else
+    {
+      location = g_strdup_printf (_("%s"),
+                                 m->where.file_name ? m->where.file_name : "");    }
 
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                           _("%s %s"),
+                                           location,
+                                           m->text);
+  g_free (location);
 
-void 
-err_assert_fail(const char *expr, const char *file, int line)
-{
-  msg(ME, "Assertion failed: %s:%d; (%s)\n",file,line,expr);
-}
+  gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
 
-/* Writes MESSAGE formatted with printf, to stderr, if the
-   verbosity level is at least LEVEL. */
-void
-verbose_msg (int level, const char *format, ...)
-{
-  /* Do nothing for now. */
-}
+  gtk_dialog_run (GTK_DIALOG (dialog));
 
-/* FIXME: This is a stub .
- * A temporary workaround until getl.c is rearranged
- */
-void
-err_location (struct file_locator *f)
-{
-       f->file_name = 0;
-       f->line_number = -1;
+  gtk_widget_destroy (dialog);
 }