Rewrite Import Dialog.
[pspp] / src / ui / gui / psppire-import-assistant.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2015  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17
18 #ifndef __PSPPIRE_IMPORT_ASSISTANT_H__
19 #define __PSPPIRE_IMPORT_ASSISTANT_H__
20
21 #include <glib-object.h>
22 #include <glib.h>
23
24 #include <gtk/gtk.h>
25
26 #include "libpspp/str.h"
27 #include "psppire-dict.h"
28 #include "data/spreadsheet-reader.h"
29
30 G_BEGIN_DECLS
31
32 struct spreadsheet;
33
34
35 #define PSPPIRE_TYPE_IMPORT_ASSISTANT (psppire_import_assistant_get_type ())
36
37 #define PSPPIRE_IMPORT_ASSISTANT(obj)   \
38                      (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
39                                                   PSPPIRE_TYPE_IMPORT_ASSISTANT, PsppireImportAssistant))
40
41 #define PSPPIRE_IMPORT_ASSISTANT_CLASS(klass) \
42                      (G_TYPE_CHECK_CLASS_CAST ((klass), \
43                                  PSPPIRE_TYPE_IMPORT_ASSISTANT, \
44                                  PsppireImportAssistantClass))
45
46 #define PSPPIRE_IS_IMPORT_ASSISTANT(obj) \
47                      (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_IMPORT_ASSISTANT))
48
49 #define PSPPIRE_IS_IMPORT_ASSISTANT_CLASS(klass) \
50                      (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_IMPORT_ASSISTANT))
51
52
53 #define PSPPIRE_IMPORT_ASSISTANT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
54                                    PSPPIRE_TYPE_IMPORT_ASSISTANT, \
55                                    PsppireImportAssistantClass))
56
57 typedef struct _PsppireImportAssistant       PsppireImportAssistant;
58 typedef struct _PsppireImportAssistantClass  PsppireImportAssistantClass;
59
60
61 struct first_line_page;
62
63 typedef void page_func (PsppireImportAssistant *, GtkWidget *page);
64
65 enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
66
67 struct _PsppireImportAssistant
68 {
69   GtkAssistant parent;
70
71   GtkBuilder *builder;
72
73   gint current_page;
74
75   /* START The chooser page of the assistant. */
76   GtkWidget *encoding_selector;
77   GtkFileFilter *default_filter;
78   /* END The chooser page of the assistant. */
79
80   
81   /* START The introduction page of the assistant. */
82     GtkWidget *all_cases_button;
83     GtkWidget *n_cases_button;
84     GtkWidget *n_cases_spin;
85     GtkWidget *percent_button;
86     GtkWidget *percent_spin;
87   /* END The introduction page of the assistant. */
88
89
90 /* START Page where the user chooses field separators. */
91
92   /* How to break lines into columns. */
93   struct string separators;   /* Field separators. */
94   struct string quotes;       /* Quote characters. */
95
96   GtkWidget *custom_cb;
97   GtkWidget *custom_entry;
98   GtkWidget *quote_cb;
99   GtkWidget *quote_combo;
100   GtkEntry *quote_entry;
101   GtkWidget *fields_tree_view;
102
103 /* END Page where the user chooses field separators. */
104
105
106 /* START Page where the user verifies and adjusts input formats. */
107   GtkWidget *data_tree_view;
108   PsppireDict *psppire_dict;
109   struct variable **modified_vars;
110   size_t modified_var_cnt;
111 /* END Page where the user verifies and adjusts input formats. */
112
113
114   /* START first line page */
115   GtkWidget *tree_view;
116   GtkWidget *variable_names_cb;
117   /* END first line page */
118
119   GMainLoop *main_loop;
120   GtkWidget *paste_button;
121   GtkWidget *reset_button;
122   int response;
123   int watch_cursor;
124
125   GtkCellRenderer *prop_renderer;
126   GtkCellRenderer *fixed_renderer;
127
128   // START     struct file file;
129   char *file_name;        /* File name. */
130
131   /* Relevant only for text files */
132
133   gchar *encoding;        /* Encoding. */
134   unsigned long int total_lines; /* Number of lines in file. */
135   gboolean total_is_exact;    /* Is total_lines exact (or an estimate)? */
136
137   /* The first several lines of the file. */
138   struct string lines[MAX_PREVIEW_LINES];
139   size_t line_cnt;
140
141   // END     struct file file;
142
143   struct sheet_spec_page *sheet_spec;
144   struct first_line_page *first_line;
145
146   /* The columns produced. */
147   struct column *columns;     /* Information about each column. */
148   size_t column_cnt;          /* Number of columns. */
149
150   int skip_lines;             /* Number of initial lines to skip? */
151   gboolean variable_names;        /* Variable names above first line of data? */
152   struct dictionary *dict;
153
154   struct spreadsheet *spreadsheet;
155 };
156
157 struct _PsppireImportAssistantClass
158 {
159   GtkAssistantClass parent_class;
160 };
161
162 GType psppire_import_assistant_get_type (void) ;
163
164
165 GtkWidget *psppire_import_assistant_new (GtkWindow *toplevel);
166
167 gchar *psppire_import_assistant_generate_syntax (PsppireImportAssistant *);
168
169 G_END_DECLS
170
171 #endif /* __PSPPIRE_IMPORT_ASSISTANT_H__ */