#include "data/ods-reader.h"
#include "data/spreadsheet-reader.h"
#include "data/value-labels.h"
+#include "data/casereader-provider.h"
#include "gl/intprops.h"
if (ia->spreadsheet)
spreadsheet_unref (ia->spreadsheet);
- destroy_columns (ia);
+ // destroy_columns (ia);
ds_destroy (&ia->separators);
ds_destroy (&ia->quotes);
chooser_page_leave (PsppireImportAssistant *ia, GtkWidget *page)
{
g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
- gchar *file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (page));
+ g_free (ia->file_name);
+ ia->file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (page));
gchar *encoding = psppire_encoding_selector_get_encoding (ia->encoding_selector);
if (!ia->spreadsheet)
{
- ia->text_file = psppire_text_file_new (file_name, encoding);
+ ia->text_file = psppire_text_file_new (ia->file_name, encoding);
gtk_tree_view_set_model (GTK_TREE_VIEW (ia->first_line_tree_view),
GTK_TREE_MODEL (ia->text_file));
}
- g_free (file_name);
+
g_free (encoding);
}
ia->builder = builder_new ("text-data-import.ui");
ia->current_page = -1 ;
- ia->column_cnt = 0;
- ia->columns = NULL;
+ /* ia->column_cnt = 0; */
+ /* ia->columns = NULL; */
+
+ ia->file_name = NULL;
ia->spreadsheet = NULL;
ia->watch_cursor = 0;
= psppire_delimited_text_new (GTK_TREE_MODEL (ia->text_file));
g_object_set (ia->delimiters_model, "first-line", n, NULL);
- ia->skip_lines = n;
+ // ia->skip_lines = n;
}
}
struct substring *contents;
};
+#if SHEET_MERGE
static void
destroy_columns (PsppireImportAssistant *ia)
free (ia->columns);
}
-#if SHEET_MERGE
+
/* Called to render one of the cells in the fields preview tree
view. */
(void *) NULL);
}
-#endif
-
/* Parses the contents of the field at (ROW,COLUMN) according to
its variable format. If OUTPUTP is non-null, then *OUTPUTP
receives the formatted output for that field (which must be
return ok;
}
-#if SHEET_MERGE
-
/* Called to render one of the cells in the data preview tree
view. */
static void
{
int i;
unsigned long int generated_name_count = 0;
+ dict_clear (ia->dict);
for (i = 0; i < gtk_tree_model_get_n_columns (ia->delimiters_model) - 1; ++i)
{
const gchar *candidate_name =
#endif
+static struct casereader_random_class my_casereader_class;
+
+static struct ccase *
+my_read (struct casereader *reader, void *aux, casenumber idx)
+{
+ PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (aux);
+ GtkTreeModel *tm = GTK_TREE_MODEL (ia->delimiters_model);
+
+ GtkTreePath *tp = gtk_tree_path_new_from_indices (idx, -1);
+
+ const struct caseproto *proto = casereader_get_proto (reader);
+
+ GtkTreeIter iter;
+ struct ccase *c = NULL;
+ if (gtk_tree_model_get_iter (tm, &iter, tp))
+ {
+ c = case_create (proto);
+ int i;
+ for (i = 0 ; i < caseproto_get_n_widths (proto); ++i)
+ {
+ GValue value = {0};
+ gtk_tree_model_get_value (tm, &iter, i + 1, &value);
+
+ const struct variable *var = dict_get_var (ia->dict, i);
+
+ const gchar *ss = g_value_get_string (&value);
+
+ union value *v = case_data_rw (c, var);
+ char *xx = data_in (ss_cstr (ss),
+ "UTF-8",
+ var_get_write_format (var)->type,
+ v, var_get_width (var), "UTF-8");
+
+ /* if (xx) */
+ /* g_print ("%s:%d Err %s\n", __FILE__, __LINE__, xx); */
+ free (xx);
+ g_value_unset (&value);
+ }
+ }
+
+ gtk_tree_path_free (tp);
+
+ return c;
+}
+
+static void
+my_destroy (struct casereader *reader, void *aux)
+{
+ PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (aux);
+ g_print ("%s:%d\n", __FILE__, __LINE__);
+}
+
+static void
+my_advance (struct casereader *reader, void *aux, casenumber cnt)
+{
+ g_print ("%s:%d\n", __FILE__, __LINE__);
+}
+
+
/* Called just before the formats page of the assistant is
displayed. */
static void
PsppireDict *dict = psppire_dict_new_from_dict (ia->dict);
g_object_set (ia->var_sheet, "data-model", dict, NULL);
+ my_casereader_class.read = my_read;
+ my_casereader_class.destroy = my_destroy;
+ my_casereader_class.advance = my_advance;
+
+ struct caseproto *proto = caseproto_create ();
+
+ int i;
+ for (i = 0 ; i < dict_get_var_cnt (ia->dict); ++i)
+ {
+ const struct variable *var = dict_get_var (ia->dict, i);
+ proto = caseproto_add_width (proto, var_get_width (var));
+ }
+
+ gint n_rows = gtk_tree_model_iter_n_children (ia->delimiters_model, NULL);
+
+ struct casereader *reader =
+ casereader_create_random (proto, n_rows, &my_casereader_class, ia);
+
PsppireDataStore *store = psppire_data_store_new (dict);
+ psppire_data_store_set_reader (store, reader);
+
g_object_set (ia->data_sheet, "data-model", store, NULL);
+
+ gtk_widget_show (ia->paste_button);
}
static void
}
}
-
static void
first_line_append_syntax (const PsppireImportAssistant *ia, struct string *s)
{
- if (ia->skip_lines > 0)
- ds_put_format (s, " /FIRSTCASE=%d\n", ia->skip_lines + 1);
-}
+ gint first_case = 0;
+ g_object_get (ia->delimiters_model, "first-line", &first_case, NULL);
+ if (first_case > 0)
+ ds_put_format (s, " /FIRSTCASE=%d\n", first_case + 1);
+}
static void
intro_append_syntax (const PsppireImportAssistant *ia, struct string *s)
gchar *file_name = NULL;
gchar *encoding = NULL;
g_object_get (ia->text_file,
- "filename", &file_name,
+ "file-name", &file_name,
"encoding", &encoding,
NULL);