/* Initializes IA's asst substructure. PARENT_WINDOW must be the
window to use as the assistant window's parent. */
-void
-init_assistant (struct import_assistant *ia, GtkWindow *parent_window)
+struct import_assistant *
+init_assistant (GtkWindow *parent_window)
{
+ struct import_assistant *ia = NULL;
+ ia = xzalloc (sizeof *ia);
struct assistant *a = &ia->asst;
+
+ ia->intro = xzalloc (sizeof *ia->intro);
+ ia->sheet_spec = xzalloc (sizeof *ia->sheet_spec);
+ ia->first_line = xzalloc (sizeof *ia->first_line);
+ ia->separators = xzalloc (sizeof *ia->separators);
+ ia->formats = xzalloc (sizeof *ia->formats);
+
a->builder = builder_new ("text-data-import.ui");
a->assistant = GTK_ASSISTANT (gtk_assistant_new ());
g_signal_connect (a->assistant, "prepare", G_CALLBACK (on_prepare), ia);
g_object_set (G_OBJECT (a->fixed_renderer),
"family", "Monospace",
(void *) NULL);
+ return ia;
}
/* Frees IA's asst substructure. */
on_prepare (GtkAssistant *assistant, GtkWidget *page,
struct import_assistant *ia)
{
- struct sheet_spec_page *ssp = &ia->sheet_spec;
+ struct sheet_spec_page *ssp = ia->sheet_spec;
int pn = gtk_assistant_get_current_page (assistant);
/* Prepare .... */
- if (page == ia->separators.page)
+ if (page == ia->separators->page)
prepare_separators_page (ia);
- else if (page == ia->formats.page)
+ else if (page == ia->formats->page)
prepare_formats_page (ia);
- else if (page == ia->sheet_spec.page && ssp->spreadsheet)
+ else if (page == ia->sheet_spec->page && ssp->spreadsheet)
{
prepare_sheet_spec_page (ia);
}
gtk_widget_show (ia->asst.reset_button);
- if (page == ia->formats.page)
+ if (page == ia->formats->page)
gtk_widget_show (ia->asst.paste_button);
else
gtk_widget_hide (ia->asst.paste_button);
gint page_num = gtk_assistant_get_current_page (ia->asst.assistant);
GtkWidget *page = gtk_assistant_get_nth_page (ia->asst.assistant, page_num);
- if (page == ia->intro.page)
+ if (page == ia->intro->page)
reset_intro_page (ia);
- else if (page == ia->first_line.page)
+ else if (page == ia->first_line->page)
reset_first_line_page (ia);
- else if (page == ia->separators.page)
+ else if (page == ia->separators->page)
reset_separators_page (ia);
- else if (page == ia->formats.page)
+ else if (page == ia->formats->page)
reset_formats_page (ia);
- else if (page == ia->sheet_spec.page)
+ else if (page == ia->sheet_spec->page)
reset_sheet_spec_page (ia);
}
void
update_assistant (struct import_assistant *ia)
{
- struct sheet_spec_page *ssp = &ia->sheet_spec;
+ struct sheet_spec_page *ssp = ia->sheet_spec;
struct file *file = &ia->file;
- struct separators_page *sepp = &ia->separators;
+ struct separators_page *sepp = ia->separators;
int rows = 0;
if (ssp->dict)
{
{
enum { MAX_LINE_LEN = 16384 }; /* Max length of an acceptable line. */
struct file *file = &ia->file;
- struct sheet_spec_page *ssp = &ia->sheet_spec;
+ struct sheet_spec_page *ssp = ia->sheet_spec;
struct spreadsheet_read_info sri;
struct spreadsheet_read_options opts;
if (ssp->spreadsheet == NULL)
ssp->spreadsheet = gnumeric_probe (sri.file_name);
- printf ("%s:%d %p %d\n", __FILE__, __LINE__, ssp->spreadsheet, ssp->spreadsheet->type);
-
if (ssp->spreadsheet == NULL)
ssp->spreadsheet = ods_probe (sri.file_name);
- printf ("%s:%d %p %d\n", __FILE__, __LINE__, ssp->spreadsheet, ssp->spreadsheet->type);
-
if (ssp->spreadsheet)
{
}
else
{
- printf ("%s:%d %p\n", __FILE__, __LINE__, ssp->spreadsheet);
-
struct string input;
struct line_reader *reader = line_reader_for_file (file->encoding, file->file_name, O_RDONLY);
if (reader == NULL)
void
init_first_line_page (struct import_assistant *ia)
{
- struct first_line_page *p = &ia->first_line;
+ struct first_line_page *p = ia->first_line;
GtkBuilder *builder = ia->asst.builder;
p->page = add_page_to_assistant (ia, get_widget_assert (builder, "FirstLine"),
void
reset_first_line_page (struct import_assistant *ia)
{
- ia->first_line.skip_lines = 0;
- ia->first_line.variable_names = false;
+ ia->first_line->skip_lines = 0;
+ ia->first_line->variable_names = false;
set_first_line (ia);
}
{
GtkTreePath *path;
- path = gtk_tree_path_new_from_indices (ia->first_line.skip_lines, -1);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (ia->first_line.tree_view),
+ path = gtk_tree_path_new_from_indices (ia->first_line->skip_lines, -1);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (ia->first_line->tree_view),
path, NULL, false);
gtk_tree_path_free (path);
gtk_toggle_button_set_active (
- GTK_TOGGLE_BUTTON (ia->first_line.variable_names_cb),
- ia->first_line.variable_names);
- gtk_widget_set_sensitive (ia->first_line.variable_names_cb,
- ia->first_line.skip_lines > 0);
+ GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb),
+ ia->first_line->variable_names);
+ gtk_widget_set_sensitive (ia->first_line->variable_names_cb,
+ ia->first_line->skip_lines > 0);
}
/* Sets IA's first_line substructure to match the widgets. */
GtkTreeIter iter;
GtkTreeModel *model;
- selection = gtk_tree_view_get_selection (ia->first_line.tree_view);
+ selection = gtk_tree_view_get_selection (ia->first_line->tree_view);
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
int row = gtk_tree_path_get_indices (path)[0];
gtk_tree_path_free (path);
- ia->first_line.skip_lines = row;
- ia->first_line.variable_names =
- (ia->first_line.skip_lines > 0
+ ia->first_line->skip_lines = row;
+ ia->first_line->variable_names =
+ (ia->first_line->skip_lines > 0
&& gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (ia->first_line.variable_names_cb)));
+ GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb)));
}
- gtk_widget_set_sensitive (ia->first_line.variable_names_cb,
- ia->first_line.skip_lines > 0);
+ gtk_widget_set_sensitive (ia->first_line->variable_names_cb,
+ ia->first_line->skip_lines > 0);
}
init_formats_page (struct import_assistant *ia)
{
GtkBuilder *builder = ia->asst.builder;
- struct formats_page *p = &ia->formats;
+ struct formats_page *p = ia->formats;
p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Formats"),
GTK_ASSISTANT_PAGE_CONFIRM);
void
destroy_formats_page (struct import_assistant *ia)
{
- struct formats_page *p = &ia->formats;
+ struct formats_page *p = ia->formats;
if (p->psppire_dict != NULL)
{
GtkBin *vars_scroller;
GtkWidget *old_var_sheet;
PsppireVarSheet *var_sheet;
- struct separators_page *seps = &ia->separators;
- struct formats_page *p = &ia->formats;
+ struct separators_page *seps = ia->separators;
+ struct formats_page *p = ia->formats;
struct fmt_guesser *fg;
unsigned long int number = 0;
size_t column_idx;
/* Choose variable format. */
fmt_guesser_clear (fg);
- for (row = ia->first_line.skip_lines; row < ia->file.line_cnt; row++)
+ for (row = ia->first_line->skip_lines; row < ia->file.line_cnt; row++)
fmt_guesser_add (fg, column->contents[row]);
fmt_guesser_guess (fg, &format);
fmt_fix_input (&format);
psppire_dict = psppire_dict_new_from_dict (dict);
g_signal_connect (psppire_dict, "variable_changed",
G_CALLBACK (on_variable_change), ia);
- ia->formats.dict = dict;
- ia->formats.psppire_dict = psppire_dict;
+ ia->formats->dict = dict;
+ ia->formats->psppire_dict = psppire_dict;
/* XXX: PsppireVarStore doesn't hold a reference to
psppire_dict for now, but it should. After it does, we
should g_object_ref the psppire_dict here, since we also
- hold a reference via ia->formats.dict. */
+ hold a reference via ia->formats->dict. */
var_store = psppire_var_store_new (psppire_dict);
g_object_set (var_store,
"format-type", PSPPIRE_VAR_STORE_INPUT_FORMATS,
gtk_container_add (GTK_CONTAINER (vars_scroller), GTK_WIDGET (var_sheet));
gtk_widget_show (GTK_WIDGET (var_sheet));
- gtk_widget_destroy (GTK_WIDGET (ia->formats.data_tree_view));
- ia->formats.data_tree_view = create_data_tree_view (
+ gtk_widget_destroy (GTK_WIDGET (ia->formats->data_tree_view));
+ ia->formats->data_tree_view = create_data_tree_view (
false,
GTK_CONTAINER (get_widget_assert (ia->asst.builder, "data-scroller")),
ia);
static void
clear_modified_vars (struct import_assistant *ia)
{
- struct formats_page *p = &ia->formats;
+ struct formats_page *p = ia->formats;
size_t i;
for (i = 0; i < p->modified_var_cnt; i++)
on_variable_change (PsppireDict *dict, int dict_idx,
struct import_assistant *ia)
{
- struct formats_page *p = &ia->formats;
- GtkTreeView *tv = ia->formats.data_tree_view;
+ struct formats_page *p = ia->formats;
+ GtkTreeView *tv = ia->formats->data_tree_view;
gint column_idx = dict_idx + 1;
push_watch_cursor (ia);
init_intro_page (struct import_assistant *ia)
{
GtkBuilder *builder = ia->asst.builder;
- struct intro_page *p = &ia->intro;
+ struct intro_page *p = ia->intro;
struct string s;
GtkWidget *hbox_n_cases ;
GtkWidget *hbox_percent ;
void
reset_intro_page (struct import_assistant *ia)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ia->intro.all_cases_button),
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ia->intro->all_cases_button),
true);
}
static void
on_intro_amount_changed (struct import_assistant *ia)
{
- struct intro_page *p = &ia->intro;
+ struct intro_page *p = ia->intro;
gtk_widget_set_sensitive (p->n_cases_spin,
gtk_toggle_button_get_active (
init_separators_page (struct import_assistant *ia)
{
GtkBuilder *builder = ia->asst.builder;
- struct separators_page *p = &ia->separators;
+ struct separators_page *p = ia->separators;
size_t i;
choose_likely_separators (ia);
void
destroy_separators_page (struct import_assistant *ia)
{
- struct separators_page *s = &ia->separators;
+ struct separators_page *s = ia->separators;
ds_destroy (&s->separators);
ds_destroy (&s->quotes);
static void
clear_fields (struct import_assistant *ia)
{
- struct separators_page *s = &ia->separators;
+ struct separators_page *s = ia->separators;
if (s->column_cnt > 0)
{
static void
split_fields (struct import_assistant *ia)
{
- struct separators_page *s = &ia->separators;
+ struct separators_page *s = ia->separators;
size_t columns_allocated;
bool space_sep;
size_t row;
static void
choose_column_names (struct import_assistant *ia)
{
- const struct first_line_page *f = &ia->first_line;
- struct separators_page *s = &ia->separators;
+ const struct first_line_page *f = ia->first_line;
+ struct separators_page *s = ia->separators;
struct dictionary *dict;
unsigned long int generated_name_count = 0;
struct column *col;
histogram[(unsigned char) line.string[i]]++;
}
- find_commonest_chars (histogram, "\"'", "", &ia->separators.quotes);
- find_commonest_chars (histogram, ",;:/|!\t-", ",",
- &ia->separators.separators);
- ia->separators.escape = true;
+ find_commonest_chars (histogram, "\"'", "", &ia->separators->quotes);
+ find_commonest_chars (histogram, ",;:/|!\t-", ",", &ia->separators->separators);
+ ia->separators->escape = true;
}
/* Chooses the most common character among those in TARGETS,
push_watch_cursor (ia);
- w = GTK_WIDGET (ia->separators.fields_tree_view);
+ w = GTK_WIDGET (ia->separators->fields_tree_view);
gtk_widget_destroy (w);
get_separators (ia);
split_fields (ia);
choose_column_names (ia);
- ia->separators.fields_tree_view = create_data_tree_view (
+ ia->separators->fields_tree_view = create_data_tree_view (
true,
GTK_CONTAINER (get_widget_assert (ia->asst.builder, "fields-scroller")),
ia);
static void
set_separators (struct import_assistant *ia)
{
- struct separators_page *s = &ia->separators;
+ struct separators_page *s = ia->separators;
unsigned int seps;
struct string custom;
bool any_custom;
static void
get_separators (struct import_assistant *ia)
{
- struct separators_page *s = &ia->separators;
+ struct separators_page *s = ia->separators;
int i;
ds_clear (&s->separators);
struct import_assistant *ia)
{
bool is_active = gtk_toggle_button_get_active (custom_cb);
- gtk_widget_set_sensitive (ia->separators.custom_entry, is_active);
+ gtk_widget_set_sensitive (ia->separators->custom_entry, is_active);
revise_fields_preview (ia);
}
on_quote_cb_toggle (GtkToggleButton *quote_cb, struct import_assistant *ia)
{
bool is_active = gtk_toggle_button_get_active (quote_cb);
- gtk_widget_set_sensitive (ia->separators.quote_combo, is_active);
- gtk_widget_set_sensitive (ia->separators.escape_cb, is_active);
+ gtk_widget_set_sensitive (ia->separators->quote_combo, is_active);
+ gtk_widget_set_sensitive (ia->separators->escape_cb, is_active);
revise_fields_preview (ia);
}
init_sheet_spec_page (struct import_assistant *ia)
{
GtkBuilder *builder = ia->asst.builder;
- struct sheet_spec_page *p = &ia->sheet_spec;
+ struct sheet_spec_page *p = ia->sheet_spec;
p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"),
GTK_ASSISTANT_PAGE_INTRO);
void
prepare_sheet_spec_page (struct import_assistant *ia)
{
- struct sheet_spec_page *p = &ia->sheet_spec;
+ struct sheet_spec_page *p = ia->sheet_spec;
GtkBuilder *builder = ia->asst.builder;
GtkWidget *sheet_entry = get_widget_assert (builder, "sheet-entry");
GtkBuilder *builder = ia->asst.builder;
struct file *file = &ia->file;
- struct sheet_spec_page *ssp = &ia->sheet_spec;
+ struct sheet_spec_page *ssp = ia->sheet_spec;
struct casereader *creader = NULL;
struct dictionary *dict = NULL;
text_data_import_assistant (PsppireDataWindow *dw)
{
GtkWindow *parent_window = GTK_WINDOW (dw);
- struct import_assistant *ia;
+ struct import_assistant *ia = init_assistant (parent_window);
struct sheet_spec_page *ssp ;
- ia = xzalloc (sizeof *ia);
if (!init_file (ia, parent_window))
{
free (ia);
return;
}
- init_assistant (ia, parent_window);
- ssp = &ia->sheet_spec;
+
+ ssp = ia->sheet_spec;
if (ssp->spreadsheet == NULL)
{
init_intro_page (ia);
static char *
generate_syntax (const struct import_assistant *ia)
{
- struct sheet_spec_page *ssp = &ia->sheet_spec;
+ struct sheet_spec_page *ssp = ia->sheet_spec;
struct string s = DS_EMPTY_INITIALIZER;
if (ia->file.encoding && strcmp (ia->file.encoding, "Auto"))
syntax_gen_pspp (&s, " /ENCODING=%sq\n", ia->file.encoding);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
- ia->intro.n_cases_button)))
+ ia->intro->n_cases_button)))
ds_put_format (&s, " /IMPORTCASES=FIRST %d\n",
gtk_spin_button_get_value_as_int (
- GTK_SPIN_BUTTON (ia->intro.n_cases_spin)));
+ GTK_SPIN_BUTTON (ia->intro->n_cases_spin)));
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
- ia->intro.percent_button)))
+ ia->intro->percent_button)))
ds_put_format (&s, " /IMPORTCASES=PERCENT %d\n",
gtk_spin_button_get_value_as_int (
- GTK_SPIN_BUTTON (ia->intro.percent_spin)));
+ GTK_SPIN_BUTTON (ia->intro->percent_spin)));
else
ds_put_cstr (&s, " /IMPORTCASES=ALL\n");
ds_put_cstr (&s,
" /ARRANGEMENT=DELIMITED\n"
" /DELCASE=LINE\n");
- if (ia->first_line.skip_lines > 0)
- ds_put_format (&s, " /FIRSTCASE=%d\n", ia->first_line.skip_lines + 1);
+ if (ia->first_line->skip_lines > 0)
+ ds_put_format (&s, " /FIRSTCASE=%d\n", ia->first_line->skip_lines + 1);
ds_put_cstr (&s, " /DELIMITERS=\"");
- if (ds_find_byte (&ia->separators.separators, '\t') != SIZE_MAX)
+ if (ds_find_byte (&ia->separators->separators, '\t') != SIZE_MAX)
ds_put_cstr (&s, "\\t");
- if (ds_find_byte (&ia->separators.separators, '\\') != SIZE_MAX)
+ if (ds_find_byte (&ia->separators->separators, '\\') != SIZE_MAX)
ds_put_cstr (&s, "\\\\");
- for (i = 0; i < ds_length (&ia->separators.separators); i++)
+ for (i = 0; i < ds_length (&ia->separators->separators); i++)
{
- char c = ds_at (&ia->separators.separators, i);
+ char c = ds_at (&ia->separators->separators, i);
if (c == '"')
ds_put_cstr (&s, "\"\"");
else if (c != '\t' && c != '\\')
ds_put_byte (&s, c);
}
ds_put_cstr (&s, "\"\n");
- if (!ds_is_empty (&ia->separators.quotes))
- syntax_gen_pspp (&s, " /QUALIFIER=%sq\n", ds_cstr (&ia->separators.quotes));
- if (!ds_is_empty (&ia->separators.quotes) && ia->separators.escape)
+ if (!ds_is_empty (&ia->separators->quotes))
+ syntax_gen_pspp (&s, " /QUALIFIER=%sq\n", ds_cstr (&ia->separators->quotes));
+ if (!ds_is_empty (&ia->separators->quotes) && ia->separators->escape)
ds_put_cstr (&s, " /ESCAPE\n");
ds_put_cstr (&s, " /VARIABLES=\n");
- var_cnt = dict_get_var_cnt (ia->formats.dict);
+ var_cnt = dict_get_var_cnt (ia->formats->dict);
for (i = 0; i < var_cnt; i++)
{
- struct variable *var = dict_get_var (ia->formats.dict, i);
+ struct variable *var = dict_get_var (ia->formats->dict, i);
char format_string[FMT_STRING_LEN_MAX + 1];
fmt_to_string (var_get_print_format (var), format_string);
ds_put_format (&s, " %s %s%s\n",
i == var_cnt - 1 ? "." : "");
}
- apply_dict (ia->formats.dict, &s);
+ apply_dict (ia->formats->dict, &s);
}
else
{
- const struct sheet_spec_page *ssp = &ia->sheet_spec;
+ const struct sheet_spec_page *ssp = ia->sheet_spec;
printf ("%s:%d %p %d\n", __FILE__, __LINE__, ssp->spreadsheet, ssp->spreadsheet->type);
column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
"column-number"));
- row = empty_list_store_iter_to_row (iter) + ia->first_line.skip_lines;
- field = ia->separators.columns[column].contents[row];
+ row = empty_list_store_iter_to_row (iter) + ia->first_line->skip_lines;
+ field = ia->separators->columns[column].contents[row];
if (field.string != NULL)
{
GValue text = {0, };
if (!get_tooltip_location (widget, wx, wy, ia, &row, &column))
return FALSE;
- if (ia->separators.columns[column].contents[row].string != NULL)
+ if (ia->separators->columns[column].contents[row].string != NULL)
return FALSE;
gtk_tooltip_set_text (tooltip,
char *tooltip;
bool ok;
- field = ia->separators.columns[column].contents[row];
- var = dict_get_var (ia->formats.dict, column);
+ field = ia->separators->columns[column].contents[row];
+ var = dict_get_var (ia->formats->dict, column);
value_init (&val, var_get_width (var));
in = var_get_print_format (var);
out = fmt_for_output_from_input (in);
char *error;
error = data_in (field, "UTF-8", in->type, &val, var_get_width (var),
- dict_get_encoding (ia->formats.dict));
+ dict_get_encoding (ia->formats->dict));
if (error != NULL)
{
tooltip = xasprintf (_("Cannot parse field content `%.*s' as "
}
if (outputp != NULL)
{
- *outputp = data_out (&val, dict_get_encoding (ia->formats.dict), &out);
+ *outputp = data_out (&val, dict_get_encoding (ia->formats->dict), &out);
}
value_destroy (&val, var_get_width (var));
ok = parse_field (ia,
(empty_list_store_iter_to_row (iter)
- + ia->first_line.skip_lines),
+ + ia->first_line->skip_lines),
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
"column-number")),
&output, NULL);
if (!ok)
return FALSE;
- *row = empty_list_store_iter_to_row (&iter) + ia->first_line.skip_lines;
+ *row = empty_list_store_iter_to_row (&iter) + ia->first_line->skip_lines;
return TRUE;
}
char *name;
if (input)
- column = &ia->separators.columns[dict_idx];
+ column = &ia->separators->columns[dict_idx];
else
- var = dict_get_var (ia->formats.dict, dict_idx);
+ var = dict_get_var (ia->formats->dict, dict_idx);
name = escape_underscores (input ? column->name : var_get_name (var));
char_cnt = input ? column->width : var_get_print_format (var)->w;
GtkTreeView *tree_view;
gint i;
- make_tree_view (ia, ia->first_line.skip_lines, &tree_view);
+ make_tree_view (ia, ia->first_line->skip_lines, &tree_view);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (tree_view),
GTK_SELECTION_NONE);
- for (i = 0; i < ia->separators.column_cnt; i++)
+ for (i = 0; i < ia->separators->column_cnt; i++)
gtk_tree_view_append_column (tree_view,
make_data_column (ia, tree_view, input, i));
{
struct file file;
struct assistant asst;
- struct intro_page intro;
- struct sheet_spec_page sheet_spec;
- struct first_line_page first_line;
- struct separators_page separators;
- struct formats_page formats;
+
+ struct intro_page *intro;
+ struct sheet_spec_page *sheet_spec;
+ struct first_line_page *first_line;
+ struct separators_page *separators;
+ struct formats_page *formats;
};
void reset_formats_page (struct import_assistant *);
void destroy_formats_page (struct import_assistant *ia);
-void init_assistant (struct import_assistant *, GtkWindow *);
+struct import_assistant * init_assistant (GtkWindow *);
void destroy_assistant (struct import_assistant *);