Whitespace changes only
[pspp] / src / ui / gui / page-sheet-spec.c
index fe8f90f3b7155e4c8a888c30697e3909f3aa9036..76b3ff6436279836879f4ef127d9afbbc74f90b3 100644 (file)
 
 #include <config.h>
 
+#include "page-sheet-spec.h"
+
 #include "ui/gui/text-data-import-dialog.h"
 
 #include <errno.h>
 #include <fcntl.h>
-#include <gtk-contrib/psppire-sheet.h>
 #include <gtk/gtk.h>
 #include <limits.h>
 #include <stdlib.h>
@@ -39,7 +40,6 @@
 #include "libpspp/i18n.h"
 #include "libpspp/line-reader.h"
 #include "libpspp/message.h"
-#include "ui/gui/checkbox-treeview.h"
 #include "ui/gui/dialog-common.h"
 #include "ui/gui/executor.h"
 #include "ui/gui/helper.h"
@@ -49,7 +49,6 @@
 #include "ui/gui/psppire-encoding-selector.h"
 #include "ui/gui/psppire-empty-list-store.h"
 #include "ui/gui/psppire-var-sheet.h"
-#include "ui/gui/psppire-var-store.h"
 #include "ui/gui/psppire-scanf.h"
 #include "ui/syntax-gen.h"
 
@@ -57,7 +56,6 @@
 
 #include <data/casereader.h>
 
-#include "gl/error.h"
 #include "gl/intprops.h"
 #include "gl/xalloc.h"
 
@@ -76,10 +74,51 @@ struct sheet_spec_page
     struct casereader *reader;
     struct dictionary *dict;
     
-    struct spreadsheet_read_info sri;
     struct spreadsheet_read_options opts;
   };
 
+
+char *
+sheet_spec_gen_syntax (const struct import_assistant *ia)
+{
+  const struct sheet_spec_page *ssp = ia->sheet_spec;
+  GtkBuilder *builder = ia->asst.builder;
+  GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
+  const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry));
+
+  struct string s = DS_EMPTY_INITIALIZER;
+
+  syntax_gen_pspp (&s,
+                  "GET DATA"
+                  "\n  /TYPE=%ss"
+                  "\n  /FILE=%sq"
+                  "\n  /SHEET=index %d"
+                  "\n  /READNAMES=%ss",
+                  (ia->spreadsheet->type == SPREADSHEET_GNUMERIC) ? "GNM" : "ODS",
+                  ia->file.file_name,                   
+                  ssp->opts.sheet_index,
+                  ssp->opts.read_names ? "ON" : "OFF");
+
+
+  if (range && 0 != strcmp ("", range))
+    {
+      syntax_gen_pspp (&s,
+                      "\n  /CELLRANGE=RANGE %sq", range);
+    }
+  else
+    {
+      syntax_gen_pspp (&s,
+                      "\n  /CELLRANGE=FULL");
+    }
+
+
+  syntax_gen_pspp (&s, ".");
+
+  
+  return ds_cstr (&s);
+}
+
+
 static void 
 on_sheet_combo_changed (GtkComboBox *cb, struct import_assistant *ia)
 {
@@ -123,11 +162,14 @@ prepare_sheet_spec_page (struct import_assistant *ia)
 {
   GtkBuilder *builder = ia->asst.builder;
   GtkWidget *sheet_entry = get_widget_assert (builder, "sheet-entry");
-  printf ("%s:%d %p\n", __FILE__, __LINE__, ia->spreadsheet);
+  GtkWidget *readnames_checkbox = get_widget_assert (builder, "readnames-checkbox");
+
   gtk_combo_box_set_model (GTK_COMBO_BOX (sheet_entry), 
                           psppire_spreadsheet_model_new (ia->spreadsheet));
 
-  gtk_combo_box_set_active (sheet_entry, 0);
+  gtk_combo_box_set_active (GTK_COMBO_BOX (sheet_entry), 0);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (readnames_checkbox), FALSE);
 }
 
 
@@ -135,7 +177,13 @@ prepare_sheet_spec_page (struct import_assistant *ia)
 void
 reset_sheet_spec_page (struct import_assistant *ia)
 {
-  printf ("%s\n", __FUNCTION__);
+  GtkBuilder *builder = ia->asst.builder;
+  GtkWidget *sheet_entry = get_widget_assert (builder, "sheet-entry");
+  GtkWidget *readnames_checkbox = get_widget_assert (builder, "readnames-checkbox");
+
+  gtk_combo_box_set_active (GTK_COMBO_BOX (sheet_entry), 0);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (readnames_checkbox), FALSE);
 }
 
 /* Called when the Forward button is clicked, 
@@ -155,45 +203,32 @@ post_sheet_spec_page (struct import_assistant *ia)
   struct casereader *creader = NULL;
   struct dictionary *dict = NULL;
 
-  GtkWidget *sheet_entry = get_widget_assert (builder, "sheet-entry");
-  GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
   GtkWidget *readnames_checkbox = get_widget_assert (builder, "readnames-checkbox");
-
+  GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
   const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry));
+  GtkWidget *combo_box = get_widget_assert (builder, "sheet-entry");
 
-  gint num = 1;
+  gint num = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box));
   
   ssp->opts.sheet_name = NULL;
   ssp->opts.cell_range = NULL;
-  ssp->opts.sheet_index = num;
-
-  printf ("%s:%d Range is %s\n", __FILE__, __LINE__, range);
-  printf ("%s:%d Sheet Number is %d\n", __FILE__, __LINE__, num);
+  ssp->opts.sheet_index = num + 1;
 
   if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop))
     {
-      ssp->opts.cell_range = range;
-      printf ("%s:%d Range is valid\n", __FILE__, __LINE__);
+      ssp->opts.cell_range = g_strdup (range);
     }
 
-  ssp->sri.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox));
-  ssp->sri.asw = -1;
+  ssp->opts.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox));
+  ssp->opts.asw = -1;
 
   switch (ia->spreadsheet->type)
     {
     case SPREADSHEET_ODS:
-      {
-       printf ("%s:%d\n", __FILE__, __LINE__);
-       creader = ods_make_reader (ia->spreadsheet, &ssp->sri, &ssp->opts);
-       dict = ia->spreadsheet->dict;
-      }
-      break;
     case SPREADSHEET_GNUMERIC:
       {
-       printf ("%s:%d\n",__FILE__, __LINE__);
-       creader = gnumeric_make_reader (ia->spreadsheet, &ssp->sri, &ssp->opts);
+       creader = spreadsheet_make_reader (ia->spreadsheet, &ssp->opts);
        dict = ia->spreadsheet->dict;
-       printf ("%s:%d Reader %p Dict %p\n",__FILE__, __LINE__, creader, dict);
       }
       break;
     default:
@@ -232,13 +267,11 @@ update_assistant (struct import_assistant *ia)
   struct sheet_spec_page *ssp = ia->sheet_spec;
   int rows = 0;
 
-  printf ("%s:%d\n");
   if (ssp->dict)
     {
       struct ccase *c;
       int col;
 
-      printf ("%s:%d\n");
       ia->column_cnt = dict_get_var_cnt (ssp->dict);
       ia->columns = xcalloc (ia->column_cnt, sizeof (*ia->columns));
       for (col = 0; col < ia->column_cnt ; ++col)
@@ -255,16 +288,16 @@ update_assistant (struct import_assistant *ia)
            {
              char *ss;
              const struct variable *var = dict_get_var (ssp->dict, col);
-
+             
              ia->columns[col].contents = xrealloc (ia->columns[col].contents,
-                                                     sizeof (struct substring) * rows);
-
+                                                   sizeof (struct substring) * rows);
+             
              ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), 
                             var_get_print_format (var));
-
+             
              ia->columns[col].contents[rows - 1] = ss_cstr (ss);
            }
-
+         
          if (rows > MAX_PREVIEW_LINES)
            {
              case_unref (c);
@@ -273,5 +306,5 @@ update_assistant (struct import_assistant *ia)
        }
     }
   
-  //  file->line_cnt = rows;
+  ia->file.line_cnt = rows;
 }