src/ui/gui/page-formats.h \
src/ui/gui/page-separators.c \
src/ui/gui/page-separators.h \
+ src/ui/gui/page-sheet-spec.c \
+ src/ui/gui/page-sheet-spec.h \
src/ui/gui/text-data-import-dialog.c \
src/ui/gui/text-data-import-dialog.h \
src/ui/gui/transpose-dialog.c \
if ( ia->spreadsheet)
{
if (pn == 0)
- {
- }
+ {
+ prepare_sheet_spec_page (ia);
+ }
else if (pn == 1)
{
+ post_sheet_spec_page (ia);
prepare_formats_page (ia);
}
}
reset_separators_page (ia);
else if (page == assist_get_page ((struct assist_page *) ia->formats))
reset_formats_page (ia);
+ else if (page == assist_get_page ((struct assist_page *) ia->sheet_spec))
+ reset_sheet_spec_page (ia);
}
/* Causes the assistant to close, returning RESPONSE for
gtk_file_filter_add_mime_type (filter, "text/tab-separated-values");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Gnumeric Spreadsheet Files"));
+ gtk_file_filter_add_mime_type (filter, "application/x-gnumeric");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("OpenDocument Spreadsheet Files"));
+ gtk_file_filter_add_mime_type (filter, "application/vnd.oasis.opendocument.spreadsheet");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All Spreadsheet Files"));
+ gtk_file_filter_add_mime_type (filter, "application/x-gnumeric");
+ gtk_file_filter_add_mime_type (filter, "application/vnd.oasis.opendocument.spreadsheet");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_file_chooser_set_extra_widget (
GTK_FILE_CHOOSER (dialog), psppire_encoding_selector_new ("Auto", true));
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2013 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
+ 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,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 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, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "page-sheet-spec.h"
+
+#include "ui/gui/text-data-import-dialog.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <gtk/gtk.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "data/data-in.h"
+#include "data/data-out.h"
+#include "data/format-guesser.h"
+#include "data/value-labels.h"
+#include "data/gnumeric-reader.h"
+#include "data/ods-reader.h"
+#include "data/spreadsheet-reader.h"
+#include "language/data-io/data-parser.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/assertion.h"
+#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"
+#include "ui/gui/builder-wrapper.h"
+#include "ui/gui/psppire-data-window.h"
+#include "ui/gui/psppire-dialog.h"
+#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-scanf.h"
+#include "ui/syntax-gen.h"
+
+#include "ui/gui/psppire-spreadsheet-model.h"
+
+#include <data/casereader.h>
+
+#include "gl/error.h"
+#include "gl/intprops.h"
+#include "gl/xalloc.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+struct import_assistant;
+
+/* The "sheet-spec" page of the assistant. */
+
+/* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */
+struct sheet_spec_page
+ {
+ GtkWidget *page;
+ struct casereader *reader;
+ struct dictionary *dict;
+
+ 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)
+{
+ GtkTreeIter iter;
+ gchar *range = NULL;
+ GtkTreeModel *model = gtk_combo_box_get_model (cb);
+ GtkBuilder *builder = ia->asst.builder;
+ GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
+
+ gtk_combo_box_get_active_iter (cb, &iter);
+ gtk_tree_model_get (model, &iter, PSPPIRE_SPREADSHEET_MODEL_COL_RANGE, &range, -1);
+ gtk_entry_set_text (GTK_ENTRY (range_entry), range ? range : "");
+ g_free (range);
+}
+
+/* Initializes IA's sheet_spec substructure. */
+struct sheet_spec_page *
+sheet_spec_page_create (struct import_assistant *ia)
+{
+ GtkBuilder *builder = ia->asst.builder;
+ struct sheet_spec_page *p = xzalloc (sizeof (*p));
+
+ GtkWidget *combo_box = get_widget_assert (builder, "sheet-entry");
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
+ "text", 0,
+ NULL);
+
+ g_signal_connect (combo_box, "changed", G_CALLBACK (on_sheet_combo_changed), ia);
+
+ add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"),
+ GTK_ASSISTANT_PAGE_INTRO);
+
+ return p;
+}
+
+/* Prepares IA's sheet_spec page. */
+void
+prepare_sheet_spec_page (struct import_assistant *ia)
+{
+ GtkBuilder *builder = ia->asst.builder;
+ GtkWidget *sheet_entry = get_widget_assert (builder, "sheet-entry");
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (sheet_entry),
+ psppire_spreadsheet_model_new (ia->spreadsheet));
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (sheet_entry), 0);
+}
+
+
+/* Resets IA's sheet_spec page to its initial state. */
+void
+reset_sheet_spec_page (struct import_assistant *ia)
+{
+ printf ("%s\n", __FUNCTION__);
+}
+
+/* Called when the Forward button is clicked,
+ but before displaying the new page.
+*/
+void
+post_sheet_spec_page (struct import_assistant *ia)
+{
+ int row_start = -1;
+ int row_stop = -1;
+ int col_start = -1;
+ int col_stop = -1;
+
+ GtkBuilder *builder = ia->asst.builder;
+
+ struct sheet_spec_page *ssp = ia->sheet_spec;
+ struct casereader *creader = NULL;
+ struct dictionary *dict = NULL;
+
+ 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 = 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 + 1;
+
+ if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop))
+ {
+ ssp->opts.cell_range = range;
+ }
+
+ 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:
+ case SPREADSHEET_GNUMERIC:
+ {
+ creader = spreadsheet_make_reader (ia->spreadsheet, &ssp->opts);
+ dict = ia->spreadsheet->dict;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ ssp->dict = dict;
+ ssp->reader = creader;
+
+ if (creader && dict)
+ {
+ update_assistant (ia);
+ }
+ else
+ {
+ GtkWidget * dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("An error occurred reading the spreadsheet file."));
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+}
+
+
+/*
+ Update IA according to the contents of DICT and CREADER.
+ CREADER will be destroyed by this function.
+*/
+void
+update_assistant (struct import_assistant *ia)
+{
+ struct sheet_spec_page *ssp = ia->sheet_spec;
+ int rows = 0;
+
+ if (ssp->dict)
+ {
+ struct ccase *c;
+ int col;
+
+ 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)
+ {
+ const struct variable *var = dict_get_var (ssp->dict, col);
+ ia->columns[col].name = xstrdup (var_get_name (var));
+ ia->columns[col].contents = NULL;
+ }
+
+ for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
+ {
+ rows++;
+ for (col = 0; col < ia->column_cnt ; ++col)
+ {
+ 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);
+
+ 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);
+ break;
+ }
+ }
+ }
+
+ ia->file.line_cnt = rows;
+}
--- /dev/null
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2013 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
+ 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,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 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, see <http://www.gnu.org/licenses/>. */
+
+#ifndef PAGE_SHEET_SPEC
+#define PAGE_SHEET_SPEC 1
+
+
+struct sheet_spec_page ;
+struct import_assistant;
+
+/* Initializes IA's sheet_spec substructure. */
+struct sheet_spec_page *sheet_spec_page_create (struct import_assistant *ia);
+
+char *sheet_spec_gen_syntax (const struct import_assistant *ia);
+
+
+#endif
#include "ui/gui/text-data-import-dialog.h"
#include "page-intro.h"
+#include "page-sheet-spec.h"
#include "page-first-line.h"
#include "page-separators.h"
#include "page-formats.h"
{
GtkWindow *parent_window = GTK_WINDOW (dw);
struct import_assistant *ia = init_assistant (parent_window);
+ struct sheet_spec_page *ssp ;
if (!init_file (ia, parent_window))
{
return;
}
+ ssp = ia->sheet_spec;
+ if (ia->spreadsheet)
+ {
+ ia->sheet_spec = sheet_spec_page_create (ia);
+ }
+ else
{
ia->intro = intro_page_create (ia);
ia->first_line = first_line_page_create (ia);
break;
}
+ if (ssp)
{
destroy_formats_page (ia);
destroy_separators_page (ia);
{
struct string s = DS_EMPTY_INITIALIZER;
+ if (ia->spreadsheet == NULL)
{
syntax_gen_pspp (&s,
"GET DATA"
if (ia->file.encoding && strcmp (ia->file.encoding, "Auto"))
syntax_gen_pspp (&s, " /ENCODING=%sq\n", ia->file.encoding);
-
intro_append_syntax (ia->intro, &s);
formats_append_syntax (ia, &s);
apply_dict (ia->dict, &s);
}
-
+ else
+ {
+ return sheet_spec_gen_syntax (ia);
+ }
+
return ds_cstr (&s);
}
</object>
</child>
</object>
- <object class="GtkAdjustment" id="adjustment1">
- <property name="value">100</property>
- <property name="lower">1</property>
- <property name="upper">100</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="adjustment2">
- <property name="value">1000</property>
- <property name="upper">100000000</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
+ <object class="GtkWindow" id="Sheet">
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="border_width">12</property>
+ <property name="title" translatable="yes">Importing Spreadsheet Data</property>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="intro-label1">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">Enter below the sheet number and the cell range which you wish to import.</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment4">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xscale">0</property>
+ <child>
+ <object class="GtkFrame" id="frame1">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkAlignment" id="alignment7">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkTable" id="table3">
+ <property name="visible">True</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <child>
+ <object class="GtkEntry" id="cell-range-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="sheet-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="active">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="cell-range-label">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Cells: </property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">cell-range-entry</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="sheet-label">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Sheet Index: </property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">sheet-entry</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="readnames-checkbox">
+ <property name="label" translatable="yes">Use first row as _variable names</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="image_position">right</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes"><b>Cells to Import</b></property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
</object>
</interface>