New file: builder-wrapper.h and builder-wrapper.c
[pspp-builds.git] / src / ui / gui / psppire-data-window.c
index 604bd566a5ff2f1bcd7c8707082cc56567f81083..b2607a0ca2dff3ded02cb242f3648d4bab1df2c1 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2010, 2011  Free Software Foundation
+   Copyright (C) 2008, 2009, 2010, 2011, 2012  Free Software Foundation
 
    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
 #include "data/session.h"
 #include "language/lexer/lexer.h"
 #include "libpspp/message.h"
+#include "libpspp/str.h"
 #include "ui/gui/aggregate-dialog.h"
+#include "ui/gui/autorecode-dialog.h"
 #include "ui/gui/binomial-dialog.h"
+#include "ui/gui/builder-wrapper.h"
 #include "ui/gui/chi-square-dialog.h"
 #include "ui/gui/comments-dialog.h"
 #include "ui/gui/compute-dialog.h"
 #include "ui/gui/correlation-dialog.h"
+#include "ui/gui/count-dialog.h"
 #include "ui/gui/crosstabs-dialog.h"
 #include "ui/gui/descriptives-dialog.h"
 #include "ui/gui/entry-dialog.h"
 #include "ui/gui/goto-case-dialog.h"
 #include "ui/gui/help-menu.h"
 #include "ui/gui/helper.h"
+#include "ui/gui/helper.h"
+#include "ui/gui/k-means-dialog.h"
 #include "ui/gui/k-related-dialog.h"
+#include "ui/gui/npar-two-sample-related.h"
 #include "ui/gui/oneway-anova-dialog.h"
 #include "ui/gui/psppire-data-window.h"
 #include "ui/gui/psppire-syntax-window.h"
 #include "ui/gui/psppire-window.h"
 #include "ui/gui/psppire.h"
 #include "ui/gui/rank-dialog.h"
+#include "ui/gui/runs-dialog.h"
+#include "ui/gui/ks-one-sample-dialog.h"
 #include "ui/gui/recode-dialog.h"
 #include "ui/gui/regression-dialog.h"
 #include "ui/gui/reliability-dialog.h"
 #include "ui/gui/t-test-paired-samples.h"
 #include "ui/gui/text-data-import-dialog.h"
 #include "ui/gui/transpose-dialog.h"
+#include "ui/gui/univariate-dialog.h"
 #include "ui/gui/variable-info-dialog.h"
 #include "ui/gui/weight-cases-dialog.h"
 #include "ui/syntax-gen.h"
 
 #include "gl/c-strcase.h"
+#include "gl/c-strcasestr.h"
 #include "gl/xvasprintf.h"
 
 #include <gettext.h>
@@ -359,8 +370,9 @@ name_has_suffix (const gchar *name)
 static gboolean
 load_file (PsppireWindow *de, const gchar *file_name)
 {
-  gchar *utf8_file_name;
   struct string filename;
+  gchar *utf8_file_name;
+  const char *mime_type;
   gchar *syntax;
   bool ok;
 
@@ -378,10 +390,15 @@ load_file (PsppireWindow *de, const gchar *file_name)
   ok = execute_syntax (PSPPIRE_DATA_WINDOW (de),
                        lex_reader_for_string (syntax));
   g_free (syntax);
-  return ok;
-}
 
+  mime_type = (name_has_por_suffix (file_name)
+               ? "application/x-spss-por"
+               : "application/x-spss-sav");
 
+  add_most_recent (file_name, mime_type);
+
+  return ok;
+}
 
 /* Save DE to file */
 static void
@@ -479,6 +496,7 @@ static void
 data_pick_filename (PsppireWindow *window)
 {
   PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (window);
+  GtkFileFilter *filter = gtk_file_filter_new ();
   GtkWidget *button_sys;
   GtkWidget *dialog =
     gtk_file_chooser_dialog_new (_("Save"),
@@ -488,16 +506,15 @@ data_pick_filename (PsppireWindow *window)
                                 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                                 NULL);
 
-  GtkFileFilter *filter = gtk_file_filter_new ();
+  g_object_set (dialog, "local-only", FALSE, NULL);
+
   gtk_file_filter_set_name (filter, _("System Files (*.sav)"));
-  gtk_file_filter_add_pattern (filter, "*.sav");
-  gtk_file_filter_add_pattern (filter, "*.SAV");
+  gtk_file_filter_add_mime_type (filter, "application/x-spss-sav");
   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
 
   filter = gtk_file_filter_new ();
   gtk_file_filter_set_name (filter, _("Portable Files (*.por) "));
-  gtk_file_filter_add_pattern (filter, "*.por");
-  gtk_file_filter_add_pattern (filter, "*.POR");
+  gtk_file_filter_add_mime_type (filter, "application/x-spss-por");
   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
 
   filter = gtk_file_filter_new ();
@@ -584,7 +601,7 @@ confirm_delete_dataset (PsppireDataWindow *de,
                           GTK_STOCK_DELETE, GTK_RESPONSE_OK,
                           NULL);
 
-  g_object_set (dialog, "icon-name", "psppicon", NULL);
+  g_object_set (dialog, "icon-name", "pspp", NULL);
 
   result = gtk_dialog_run (GTK_DIALOG (dialog));
 
@@ -756,21 +773,63 @@ on_recent_data_select (GtkMenuShell *menushell,
   g_free (file);
 }
 
+static char *
+charset_from_mime_type (const char *mime_type)
+{
+  const char *charset;
+  struct string s;
+  const char *p;
+
+  if (mime_type == NULL)
+    return NULL;
+
+  charset = c_strcasestr (mime_type, "charset=");
+  if (charset == NULL)
+    return NULL;
+
+  ds_init_empty (&s);
+  p = charset + 8;
+  if (*p == '"')
+    {
+      /* Parse a "quoted-string" as defined by RFC 822. */
+      for (p++; *p != '\0' && *p != '"'; p++)
+        {
+          if (*p != '\\')
+            ds_put_byte (&s, *p);
+          else if (*++p != '\0')
+            ds_put_byte (&s, *p);
+        }
+    }
+  else
+    {
+      /* Parse a "token" as defined by RFC 2045. */
+      while (*p > 32 && *p < 127 && strchr ("()<>@,;:\\\"/[]?=", *p) == NULL)
+        ds_put_byte (&s, *p++);
+    }
+  if (!ds_is_empty (&s))
+    return ds_steal_cstr (&s);
+
+  ds_destroy (&s);
+  return NULL;
+}
+
 static void
 on_recent_files_select (GtkMenuShell *menushell,   gpointer user_data)
 {
+  GtkRecentInfo *item;
+  char *encoding;
+  GtkWidget *se;
   gchar *file;
 
-  GtkWidget *se ;
-
-  gchar *uri =
-    gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
+  /* Get the file name and its encoding. */
+  item = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (menushell));
+  file = g_filename_from_uri (gtk_recent_info_get_uri (item), NULL, NULL);
+  encoding = charset_from_mime_type (gtk_recent_info_get_mime_type (item));
+  gtk_recent_info_unref (item);
 
-  file = g_filename_from_uri (uri, NULL, NULL);
-
-  g_free (uri);
+  se = psppire_syntax_window_new (encoding);
 
-  se = psppire_syntax_window_new (NULL);
+  free (encoding);
 
   if ( psppire_window_load (PSPPIRE_WINDOW (se), file) ) 
     gtk_widget_show (se);
@@ -781,6 +840,7 @@ on_recent_files_select (GtkMenuShell *menushell,   gpointer user_data)
 }
 
 
+
 static void
 enable_delete_cases (GtkWidget *w, gint case_num, gpointer data)
 {
@@ -1016,6 +1076,8 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   connect_action (de, "transform_compute", G_CALLBACK (compute_dialog));
 
+  connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog));
+
   connect_action (de, "edit_find", G_CALLBACK (find_dialog));
 
   connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog));
@@ -1036,6 +1098,8 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
  
   connect_action (de, "transform_rank", G_CALLBACK (rank_dialog));
+
+  connect_action (de, "transform_count", G_CALLBACK (count_dialog));
  
   connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
  
@@ -1055,15 +1119,22 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
  
   connect_action (de, "roc-curve", G_CALLBACK (roc_dialog));
 
+  connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog));
+
+  connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
+
   connect_action (de, "correlation", G_CALLBACK (correlation_dialog));
  
   connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
 
-  connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
+  connect_action (de, "k-means", G_CALLBACK (k_means_dialog));
 
+  connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
   connect_action (de, "binomial", G_CALLBACK (binomial_dialog));
-
+  connect_action (de, "runs", G_CALLBACK (runs_dialog));
+  connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog));
   connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
+  connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog));
  
 
   {
@@ -1082,13 +1153,14 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
     GtkWidget *menu_files = gtk_recent_chooser_menu_new_for_manager (
       gtk_recent_manager_get_default ());
 
+    g_object_set (menu_data, "show-tips",  TRUE, NULL);
+    g_object_set (menu_files, "show-tips",  TRUE, NULL);
+
     {
       GtkRecentFilter *filter = gtk_recent_filter_new ();
 
-      gtk_recent_filter_add_pattern (filter, "*.sav");
-      gtk_recent_filter_add_pattern (filter, "*.SAV");
-      gtk_recent_filter_add_pattern (filter, "*.por");
-      gtk_recent_filter_add_pattern (filter, "*.POR");
+      gtk_recent_filter_add_mime_type (filter, "application/x-spss-sav");
+      gtk_recent_filter_add_mime_type (filter, "application/x-spss-por");
 
       gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu_data), GTK_RECENT_SORT_MRU);