GnuCash c935c2f+
Loading...
Searching...
No Matches
assistant-csv-account-import.c
Go to the documentation of this file.
1/*******************************************************************\
2 * assistant-csv-account-import.c -- An assistant for importing *
3 * Accounts from a file. *
4 * *
5 * Copyright (C) 2012 Robert Fewell *
6 * *
7 * This program is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU General Public License as *
9 * published by the Free Software Foundation; either version 2 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License*
18 * along with this program; if not, contact: *
19 * *
20 * Free Software Foundation Voice: +1-617-542-5942 *
21 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
22 * Boston, MA 02110-1301, USA gnu@gnu.org *
23\********************************************************************/
28#include <config.h>
29
30#include <gtk/gtk.h>
31#include <glib/gi18n.h>
32
33#include "dialog-utils.h"
34#include "gnc-ui.h"
35#include "gnc-uri-utils.h"
36#include "gnc-ui-util.h"
37
38#include "gnc-component-manager.h"
39
41#include "csv-account-import.h"
42
43#define GNC_PREFS_GROUP "dialogs.import.csv"
44#define ASSISTANT_CSV_IMPORT_CM_CLASS "assistant-csv-account-import"
45
46/* This static indicates the debugging module that this .o belongs to. */
47static QofLogModule log_module = GNC_MOD_ASSISTANT;
48
49/*************************************************************************/
50
51void csv_import_assistant_prepare (GtkAssistant *assistant, GtkWidget *page, gpointer user_data);
52void csv_import_assistant_finish (GtkAssistant *gtkassistant, gpointer user_data);
53void csv_import_assistant_cancel (GtkAssistant *gtkassistant, gpointer user_data);
54void csv_import_assistant_close (GtkAssistant *gtkassistant, gpointer user_data);
55
56void csv_import_assistant_start_page_prepare (GtkAssistant *gtkassistant, gpointer user_data);
57void csv_import_assistant_account_page_prepare (GtkAssistant *gtkassistant, gpointer user_data);
58void csv_import_assistant_file_page_prepare (GtkAssistant *assistant, gpointer user_data);
59void csv_import_assistant_finish_page_prepare (GtkAssistant *assistant, gpointer user_data);
60void csv_import_assistant_summary_page_prepare (GtkAssistant *assistant, gpointer user_data);
61
62void csv_import_sep_cb (GtkWidget *radio, gpointer user_data );
63void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data );
64
65void csv_import_file_chooser_file_activated_cb (GtkFileChooser *chooser, CsvImportInfo *info);
66void csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvImportInfo *info);
67
68static const gchar *finish_tree_string = N_(
69 "The accounts will be imported from the file '%s' when you click 'Apply'.\n\n"
70 "You can verify your selections by clicking on 'Back' or 'Cancel' to Abort Import.\n");
71
72static const gchar *new_book_finish_tree_string = N_(
73 "The accounts will be imported from the file '%s' when you click 'Apply'.\n\n"
74 "You can verify your selections by clicking on 'Back' or 'Cancel' to Abort Import.\n\n"
75 "If this is your initial import into a new file, you will first see "
76 "a dialog for setting book options, since these can affect how "
77 "imported data is converted to GnuCash transactions.\n"
78 "Note: After import, you may need to use 'View / Filter By / Other' menu option "
79 "and select to show unused Accounts.\n");
80
81/* Escape '_' in string */
82static gchar *mnemonic_escape (const gchar *source);
83static gchar *mnemonic_escape (const gchar *source)
84{
85 const guchar *p;
86 gchar *dest;
87 gchar *q;
88
89 g_return_val_if_fail (source != NULL, NULL);
90
91 p = (guchar *) source;
92 q = dest = g_malloc (strlen (source) * 2 + 1);
93
94 while (*p)
95 {
96 switch (*p)
97 {
98 case '_':
99 *q++ = '_';
100 *q++ = '_';
101 break;
102 default:
103 *q++ = *p;
104 break;
105 }
106 p++;
107 }
108 *q = 0;
109 return dest;
110}
111
112static
113void create_regex (GString *regex_str, const gchar *sep)
114{
115 if (!sep) return;
116
117 g_string_printf (regex_str,
118 "\\G(?<type>[^%s]*)%s"
119 "(?<full_name>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
120 "(?<name>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
121 "(?<code>\"(?:[^\"]|\"\")*\"|[^%s]*)%s?"
122 "(?<description>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
123 "(?<color>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
124 "(?<notes>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
125 "(?<symbol>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
126 "(?<namespace>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
127 "(?<hidden>[^%s]*)%s"
128 "(?<tax>[^%s]*)%s"
129 "(?<placeholder>[^%s[:cntrl:]]*)(?:\\R*)",
130 sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep,
131 sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep);
132
133}
134
135/*************************************************************************/
136
137/**************************************************
138 * csv_import_assistant_check_filename
139 *
140 * check for a valid filename for GtkFileChooser callbacks
141 **************************************************/
142static gboolean
143csv_import_assistant_check_filename (GtkFileChooser *chooser,
144 CsvImportInfo *info)
145{
146 gchar *file_name = gtk_file_chooser_get_filename (chooser);
147
148 /* Test for a valid filename and not a directory */
149 if (file_name && !g_file_test (file_name, G_FILE_TEST_IS_DIR))
150 {
151 gchar *filepath = gnc_uri_get_path (file_name);
152 gchar *filedir = g_path_get_dirname (filepath);
153
154 g_free (info->file_name);
155 info->file_name = g_strdup (file_name);
156
157 g_free (info->starting_dir);
158 info->starting_dir = g_strdup (filedir);
159
160 g_free (filedir);
161 g_free (filepath);
162 g_free (file_name);
163
164 DEBUG("file_name selected is %s", info->file_name);
165 DEBUG("starting directory is %s", info->starting_dir);
166 return TRUE;
167 }
168 g_free (file_name);
169 return FALSE;
170}
171
172
173/**************************************************
174 * csv_import_file_chooser_file_activated_cb
175 *
176 * call back for GtkFileChooser file-activated signal
177 **************************************************/
178void
179csv_import_file_chooser_file_activated_cb (GtkFileChooser *chooser,
180 CsvImportInfo *info)
181{
182 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
183 gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
184
185 /* Test for a valid filename and not a directory */
186 if (csv_import_assistant_check_filename (chooser, info))
187 {
188 gtk_assistant_set_page_complete (assistant, info->file_page, TRUE);
189 gtk_assistant_next_page (assistant);
190 }
191}
192
193
194/**************************************************
195 * csv_import_file_chooser_selection_changed_cb
196 *
197 * call back for file chooser widget
198 **************************************************/
199void
200csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser,
201 CsvImportInfo *info)
202{
203 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
204 gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
205
206 /* Enable the "Next" button based on a valid filename */
207 gtk_assistant_set_page_complete (assistant, info->file_page,
208 csv_import_assistant_check_filename (chooser, info));
209}
210
211
212/*******************************************************
213 * csv_import_hrows_cb
214 *
215 * call back for the start row / number of header rows
216 *******************************************************/
217void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data)
218{
219 CsvImportInfo *info = user_data;
220
221 GtkTreeIter iter;
222 gboolean valid;
223 int num_rows;
224
225 /* Get number of rows for header */
226 info->header_rows = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin));
227
228 /* Get number of rows displayed */
229 num_rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(info->store), NULL);
230
231 /* Modify background color for header rows */
232 if (info->header_rows == 0)
233 {
234 valid = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(info->store), &iter, NULL, 0 );
235 if (valid)
236 gtk_list_store_set (info->store, &iter, ROW_COLOR, NULL, -1);
237 }
238 else
239 {
240 if (info->header_rows - 1 < num_rows)
241 {
242 valid = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(info->store), &iter, NULL, info->header_rows - 1 );
243 if (valid)
244 gtk_list_store_set (info->store, &iter, ROW_COLOR, "pink", -1);
245 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(info->store), &iter);
246 if (valid)
247 gtk_list_store_set (info->store, &iter, ROW_COLOR, NULL, -1);
248 }
249 }
250}
251
252
253/*******************************************************
254 * csv_import_assistant_enable_account_forward
255 *
256 * enable "Next" button on account_page if store has rows
257 *******************************************************/
258static void csv_import_assistant_enable_account_forward (CsvImportInfo *info)
259{
260 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
261 gboolean store_has_rows = TRUE;
262
263 /* if the store is empty, disable "Next" button */
264 if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL(info->store), NULL) == 0)
265 store_has_rows = FALSE;
266
267 gtk_assistant_set_page_complete (assistant, info->account_page, store_has_rows);
268}
269
270
271/*******************************************************
272 * csv_import_sep_cb
273 *
274 * call back for type of separator required
275 *******************************************************/
276void csv_import_sep_cb (GtkWidget *radio, gpointer user_data)
277{
278 CsvImportInfo *info = user_data;
279 const gchar *name;
280 gchar *temp;
281 gchar *sep = NULL;
282
283 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radio)))
284 {
285 LEAVE("1st callback of pair. Defer to 2nd callback.");
286 return;
287 }
288
289 name = gtk_buildable_get_name (GTK_BUILDABLE(radio));
290 if (g_strcmp0 (name, "radio_semi") == 0)
291 sep = ";";
292 else if (g_strcmp0 (name, "radio_colon") == 0)
293 sep = ":";
294 else
295 sep = ","; /* Use as default as well */
296
297 create_regex (info->regexp, sep);
298
299 if (g_strcmp0 (name, "radio_custom") == 0)
300 {
301 temp = gnc_input_dialog (GTK_WIDGET (info->assistant),
302 _("Adjust regular expression used for import"),
303 _("This regular expression is used to parse the import file. Modify according to your needs.\n"),
304 info->regexp->str);
305 if (temp)
306 {
307 g_string_assign (info->regexp, temp);
308 g_free (temp);
309 }
310 }
311
312 /* Generate preview */
313 gtk_list_store_clear (info->store);
314 gtk_widget_set_sensitive (info->header_row_spin, TRUE);
315
316 if (csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 11) == MATCH_FOUND)
317 gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 1); // set header spin to 1
318 else
319 gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 0); //reset header spin to 0
320
321 /* if the store has rows, enable "Next" button */
322 csv_import_assistant_enable_account_forward (info);
323}
324
325
326/*******************************************************
327 * load_settings
328 *
329 * load the default settings for the assistant
330 *******************************************************/
331static
332void load_settings (CsvImportInfo *info)
333{
334 info->header_rows = 0;
335 info->error = "";
336 info->starting_dir = NULL;
337 info->file_name = NULL;
338 info->error = "";
339
340 /* The default directory for the user to select files. */
341 info->starting_dir = gnc_get_default_directory (GNC_PREFS_GROUP);
342}
343
344
345/* =============================================================== */
346
347/*******************************************************
348 * Assistant page prepare functions
349 *******************************************************/
350void
351csv_import_assistant_start_page_prepare (GtkAssistant *assistant,
352 gpointer user_data)
353{
354 gint num = gtk_assistant_get_current_page (assistant);
355 GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
356
357 /* Enable the Assistant Buttons */
358 gtk_assistant_set_page_complete (assistant, page, TRUE);
359}
360
361
362void
363csv_import_assistant_file_page_prepare (GtkAssistant *assistant,
364 gpointer user_data)
365{
366 CsvImportInfo *info = user_data;
367
368 /* Set the default directory */
369 if (info->starting_dir)
370 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(info->file_chooser), info->starting_dir);
371
372 /* Disable the "Next" Assistant Button */
373 gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
374}
375
376
377void
378csv_import_assistant_account_page_prepare (GtkAssistant *assistant,
379 gpointer user_data)
380{
381 CsvImportInfo *info = user_data;
382 csv_import_result res;
383
384 /* Disable the "Next" Assistant Button */
385 gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
386
387 /* test read one line */
388 gtk_list_store_clear (info->store);
389 res = csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 1 );
390 if (res == RESULT_OPEN_FAILED)
391 {
392 gnc_error_dialog (GTK_WINDOW (info->assistant), _("The input file can not be opened."));
393 gtk_assistant_previous_page (assistant);
394 }
395 else if (res == RESULT_OK)
396 gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
397 else if (res == MATCH_FOUND)
398 gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
399
400 // generate preview
401 gtk_list_store_clear (info->store);
402
403 gtk_widget_set_sensitive (info->header_row_spin, TRUE);
404
405 if (csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 11 ) == MATCH_FOUND)
406 gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 1); // set header spin to 1
407 else
408 gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 0); //reset header spin to 0
409
410 /* if the store has rows, enable "Next" button */
411 csv_import_assistant_enable_account_forward (info);
412}
413
414
415void
416csv_import_assistant_finish_page_prepare (GtkAssistant *assistant,
417 gpointer user_data)
418{
419 CsvImportInfo *info = user_data;
420 gchar *text;
421
422 /* Set Finish page text */
423 /* Before creating accounts, if this is a new book, tell user they can
424 * specify book options, since they affect how transactions are created */
425 if (info->new_book)
426 text = g_strdup_printf (gettext (new_book_finish_tree_string), info->file_name);
427 else
428 text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
429
430 gtk_label_set_text (GTK_LABEL(info->finish_label), text);
431 g_free (text);
432
433 /* Save the Window size and directory */
434 gnc_set_default_directory (GNC_PREFS_GROUP, info->starting_dir);
435
436 /* Enable the Assistant Buttons */
437 gtk_assistant_set_page_complete (assistant, info->finish_label, TRUE);
438}
439
440
441void
442csv_import_assistant_summary_page_prepare (GtkAssistant *assistant,
443 gpointer user_data)
444{
445 CsvImportInfo *info = user_data;
446 gchar *text, *errtext, *mtext;
447
448 /* Before creating accounts, if this is a new book, let user specify
449 * book options, since they affect how transactions are created */
450 if (info->new_book)
451 info->new_book = gnc_new_book_option_display (info->assistant);
452
453 if (g_strcmp0 (info->error, "") != 0)
454 {
455 GtkTextBuffer *buffer;
456
457 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(info->summary_error_view));
458 text = g_strdup_printf (gettext ("Import completed but with errors!\n\nThe number of Accounts added was %u and "
459 "%u were updated.\n\nSee below for errors…"), info->num_new, info->num_updates);
460 errtext = g_strdup_printf ("%s", info->error);
461 gtk_text_buffer_set_text (buffer, errtext, -1);
462 g_free (errtext);
463 g_free (info->error);
464 }
465 else
466 text = g_strdup_printf (gettext ("Import completed successfully!\n\nThe number of Accounts added was %u and "
467 "%u were updated.\n"), info->num_new, info->num_updates);
468
469 mtext = g_strdup_printf ("<span size=\"medium\"><b>%s</b></span>", text);
470 gtk_label_set_markup (GTK_LABEL(info->summary_label), mtext);
471
472 g_free (text);
473 g_free (mtext);
474}
475
476
477void
478csv_import_assistant_prepare (GtkAssistant *assistant, GtkWidget *page,
479 gpointer user_data)
480{
481 gint currentpage = gtk_assistant_get_current_page (assistant);
482
483 switch (currentpage)
484 {
485 case 0:
486 /* Current page is Import Start page */
487 csv_import_assistant_start_page_prepare (assistant, user_data);
488 break;
489 case 1:
490 /* Current page is File select page */
491 csv_import_assistant_file_page_prepare (assistant, user_data);
492 break;
493 case 2:
494 /* Current page is Account page */
495 csv_import_assistant_account_page_prepare (assistant, user_data);
496 break;
497 case 3:
498 /* Current page is Finish page */
499 csv_import_assistant_finish_page_prepare (assistant, user_data);
500 break;
501 case 4:
502 /* Current page is Summary page */
503 csv_import_assistant_summary_page_prepare (assistant, user_data);
504 break;
505 }
506}
507
508
509/*******************************************************
510 * Assistant call back functions
511 *******************************************************/
512static void
513csv_import_assistant_destroy_cb (GtkWidget *object, gpointer user_data)
514{
515 CsvImportInfo *info = user_data;
516 gnc_unregister_gui_component_by_data (ASSISTANT_CSV_IMPORT_CM_CLASS, info);
517 g_free (info);
518}
519
520void
521csv_import_assistant_cancel (GtkAssistant *assistant, gpointer user_data)
522{
523 CsvImportInfo *info = user_data;
524 gnc_close_gui_component_by_data (ASSISTANT_CSV_IMPORT_CM_CLASS, info);
525}
526
527void
528csv_import_assistant_close (GtkAssistant *assistant, gpointer user_data)
529{
530 CsvImportInfo *info = user_data;
531 gnc_close_gui_component_by_data (ASSISTANT_CSV_IMPORT_CM_CLASS, info);
532}
533
534void
535csv_import_assistant_finish (GtkAssistant *assistant, gpointer user_data)
536{
537 CsvImportInfo *info = user_data;
538
539 gtk_list_store_clear (info->store);
540 csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 0 );
541 csv_account_import (info);
542}
543
544static void
545csv_import_close_handler (gpointer user_data)
546{
547 CsvImportInfo *info = user_data;
548
549 g_free (info->starting_dir);
550 g_free (info->file_name);
551 g_string_free (info->regexp, TRUE);
552 g_object_unref (info->store);
553
554 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->assistant));
555 gtk_widget_destroy (info->assistant);
556}
557
558/*******************************************************
559 * Create the Assistant
560 *******************************************************/
561static GtkWidget *
562csv_import_assistant_create (CsvImportInfo *info)
563{
564 GtkBuilder *builder;
565 GtkCellRenderer *renderer;
566 GtkTreeViewColumn *column;
567 gchar *mnemonic_desc = NULL;
568
569 builder = gtk_builder_new();
570 gnc_builder_add_from_file (builder, "assistant-csv-account-import.glade", "num_hrows_adj");
571 gnc_builder_add_from_file (builder, "assistant-csv-account-import.glade", "csv_account_import_assistant");
572 info->assistant = GTK_WIDGET(gtk_builder_get_object (builder, "csv_account_import_assistant"));
573
574 // Set the name for this assistant so it can be easily manipulated with css
575 gtk_widget_set_name (GTK_WIDGET(info->assistant), "gnc-id-assistant-csv-account-import");
576 gnc_widget_style_context_add_class (GTK_WIDGET(info->assistant), "gnc-class-imports");
577
578 /* Load default settings */
579 load_settings (info);
580
581 /* Enable buttons on all page. */
582 gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
583 GTK_WIDGET(gtk_builder_get_object(builder, "start_page")),
584 TRUE);
585 gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
586 GTK_WIDGET(gtk_builder_get_object(builder, "file_page")),
587 FALSE);
588 gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
589 GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page")),
590 TRUE);
591 gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
592 GTK_WIDGET(gtk_builder_get_object(builder, "end_page")),
593 FALSE);
594 gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
595 GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")),
596 TRUE);
597
598 /* Start Page */
599
600 /* File chooser Page */
601 info->file_page = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
602 info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
603 g_signal_connect (G_OBJECT(info->file_chooser), "selection-changed",
604 G_CALLBACK(csv_import_file_chooser_selection_changed_cb), info);
605 g_signal_connect (G_OBJECT(info->file_chooser), "file-activated",
606 G_CALLBACK(csv_import_file_chooser_file_activated_cb), info);
607
608 gtk_box_pack_start (GTK_BOX(info->file_page), info->file_chooser, TRUE, TRUE, 6);
609 gtk_widget_show (info->file_chooser);
610
611 /* Account Tree Page */
612 info->account_page = GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page"));
613 info->header_row_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_hrows"));
614 info->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));
615
616 /* Comma Separated file default */
617 info->regexp = g_string_new ("");
618 create_regex (info->regexp, ",");
619
620 /* create model and bind to view */
621 info->store = gtk_list_store_new (N_COLUMNS,
622 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
623 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
624 gtk_tree_view_set_model (GTK_TREE_VIEW(info->tree_view), GTK_TREE_MODEL(info->store));
625#define CREATE_COLUMN(description,column_id) \
626 renderer = gtk_cell_renderer_text_new (); \
627 mnemonic_desc = mnemonic_escape (_(description)); \
628 column = gtk_tree_view_column_new_with_attributes (mnemonic_desc, renderer, "text", column_id, NULL); \
629 gtk_tree_view_column_add_attribute (column, renderer, "background", ROW_COLOR); \
630 gtk_tree_view_column_set_resizable (column, TRUE); \
631 gtk_tree_view_append_column (GTK_TREE_VIEW(info->tree_view), column); \
632 g_free (mnemonic_desc);
633 CREATE_COLUMN ("Type", TYPE);
634 CREATE_COLUMN ("Account Full Name", FULL_NAME);
635 CREATE_COLUMN ("Account Name", NAME);
636 CREATE_COLUMN ("Account Code", CODE);
637 CREATE_COLUMN ("Description", DESCRIPTION);
638 CREATE_COLUMN ("Account Color", COLOR);
639 CREATE_COLUMN ("Notes", NOTES);
640 CREATE_COLUMN ("Symbol", SYMBOL);
641 CREATE_COLUMN ("Namespace", NAMESPACE);
642 CREATE_COLUMN ("Hidden", HIDDEN);
643 CREATE_COLUMN ("Tax Info", TAX);
644 CREATE_COLUMN ("Placeholder", PLACE_HOLDER);
645
646 /* Finish Page */
647 info->finish_label = GTK_WIDGET(gtk_builder_get_object (builder, "end_page"));
648 /* Summary Page */
649 info->summary_label = GTK_WIDGET(gtk_builder_get_object (builder, "summary_label"));
650 info->summary_error_view = GTK_WIDGET(gtk_builder_get_object (builder, "summary_error_view"));
651
652 g_signal_connect (G_OBJECT(info->assistant), "destroy",
653 G_CALLBACK(csv_import_assistant_destroy_cb), info);
654
655 gnc_restore_window_size (GNC_PREFS_GROUP,
656 GTK_WINDOW(info->assistant), gnc_ui_get_main_window(NULL));
657
658 gtk_builder_connect_signals (builder, info);
659 g_object_unref (G_OBJECT(builder));
660 return info->assistant;
661}
662
663
664/********************************************************************\
665 * gnc_file_csv_account_import *
666 * opens up a assistant to import accounts. *
667 * *
668 * Args: import_type *
669 * Return: nothing *
670\********************************************************************/
671void
673{
674 CsvImportInfo *info;
675
676 info = g_new0 (CsvImportInfo, 1);
677
678 /* In order to trigger a book options display on the creation of a new book,
679 * we need to detect when we are dealing with a new book. */
680 info->new_book = gnc_is_new_book();
681
682 csv_import_assistant_create (info);
683
684 gnc_register_gui_component (ASSISTANT_CSV_IMPORT_CM_CLASS,
685 NULL, csv_import_close_handler,
686 info);
687
688 gtk_widget_show_all (info->assistant);
689
690 gnc_window_adjust_for_screen (GTK_WINDOW(info->assistant));
691}
void gnc_file_csv_account_import(void)
The gnc_file_csv_account_import() will let the user import accounts from a delimited file.
CSV Import Assistant.
utility functions for the GnuCash UI
Utility functions for convert uri in separate components and back.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.