1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "ui/gui/text-data-import-dialog.h"
23 #include <gtk-contrib/psppire-sheet.h>
29 #include "data/data-in.h"
30 #include "data/data-out.h"
31 #include "data/format-guesser.h"
32 #include "data/value-labels.h"
33 #include "language/data-io/data-parser.h"
34 #include "language/lexer/lexer.h"
35 #include "libpspp/assertion.h"
36 #include "libpspp/i18n.h"
37 #include "libpspp/line-reader.h"
38 #include "libpspp/message.h"
39 #include "ui/gui/checkbox-treeview.h"
40 #include "ui/gui/dialog-common.h"
41 #include "ui/gui/executor.h"
42 #include "ui/gui/helper.h"
43 #include "ui/gui/builder-wrapper.h"
44 #include "ui/gui/psppire-data-window.h"
45 #include "ui/gui/psppire-dialog.h"
46 #include "ui/gui/psppire-encoding-selector.h"
47 #include "ui/gui/psppire-empty-list-store.h"
48 #include "ui/gui/psppire-var-sheet.h"
49 #include "ui/gui/psppire-var-store.h"
50 #include "ui/gui/psppire-scanf.h"
51 #include "ui/syntax-gen.h"
54 #include "gl/intprops.h"
55 #include "gl/xalloc.h"
58 #define _(msgid) gettext (msgid)
59 #define N_(msgid) msgid
61 struct import_assistant;
65 /* The "intro" page of the assistant. */
67 static void on_intro_amount_changed (struct import_assistant *);
69 /* Initializes IA's intro substructure. */
71 init_intro_page (struct import_assistant *ia)
73 GtkBuilder *builder = ia->asst.builder;
74 struct intro_page *p = ia->intro;
76 GtkWidget *hbox_n_cases ;
77 GtkWidget *hbox_percent ;
81 p->n_cases_spin = gtk_spin_button_new_with_range (0, INT_MAX, 100);
83 hbox_n_cases = psppire_scanf_new (_("Only the first %4d cases"), &p->n_cases_spin);
85 table = get_widget_assert (builder, "button-table");
87 gtk_table_attach_defaults (GTK_TABLE (table), hbox_n_cases,
91 p->percent_spin = gtk_spin_button_new_with_range (0, 100, 10);
93 hbox_percent = psppire_scanf_new (_("Only the first %3d %% of file (approximately)"), &p->percent_spin);
95 gtk_table_attach_defaults (GTK_TABLE (table), hbox_percent,
99 p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Intro"),
100 GTK_ASSISTANT_PAGE_INTRO);
102 p->all_cases_button = get_widget_assert (builder, "import-all-cases");
104 p->n_cases_button = get_widget_assert (builder, "import-n-cases");
106 p->percent_button = get_widget_assert (builder, "import-percent");
108 g_signal_connect_swapped (p->all_cases_button, "toggled",
109 G_CALLBACK (on_intro_amount_changed), ia);
110 g_signal_connect_swapped (p->n_cases_button, "toggled",
111 G_CALLBACK (on_intro_amount_changed), ia);
112 g_signal_connect_swapped (p->percent_button, "toggled",
113 G_CALLBACK (on_intro_amount_changed), ia);
115 on_intro_amount_changed (ia);
118 ds_put_cstr (&s, _("This assistant will guide you through the process of "
119 "importing data into PSPP from a text file with one line "
120 "per case, in which fields are separated by tabs, "
121 "commas, or other delimiters.\n\n"));
122 if (ia->file.total_is_exact)
124 &s, ngettext ("The selected file contains %zu line of text. ",
125 "The selected file contains %zu lines of text. ",
128 else if (ia->file.total_lines > 0)
132 "The selected file contains approximately %lu line of text. ",
133 "The selected file contains approximately %lu lines of text. ",
134 ia->file.total_lines),
135 ia->file.total_lines);
138 "Only the first %zu line of the file will be shown for "
139 "preview purposes in the following screens. ",
140 "Only the first %zu lines of the file will be shown for "
141 "preview purposes in the following screens. ",
145 ds_put_cstr (&s, _("You may choose below how much of the file should "
146 "actually be imported."));
147 gtk_label_set_text (GTK_LABEL (get_widget_assert (builder, "intro-label")),
152 /* Resets IA's intro page to its initial state. */
154 reset_intro_page (struct import_assistant *ia)
156 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ia->intro->all_cases_button),
160 /* Called when one of the radio buttons is clicked. */
162 on_intro_amount_changed (struct import_assistant *ia)
164 struct intro_page *p = ia->intro;
166 gtk_widget_set_sensitive (p->n_cases_spin,
167 gtk_toggle_button_get_active (
168 GTK_TOGGLE_BUTTON (p->n_cases_button)));
170 gtk_widget_set_sensitive (p->percent_spin,
171 gtk_toggle_button_get_active (
172 GTK_TOGGLE_BUTTON (p->percent_button)));