GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 [email protected] *
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 
40 #include "assistant-utils.h"
42 #include "csv-account-import.h"
43 
44 #define GNC_PREFS_GROUP "dialogs.import.csv"
45 #define ASSISTANT_CSV_IMPORT_CM_CLASS "assistant-csv-account-import"
46 
47 /* This static indicates the debugging module that this .o belongs to. */
48 static QofLogModule log_module = GNC_MOD_ASSISTANT;
49 
50 /*************************************************************************/
51 
52 void csv_import_assistant_prepare (GtkAssistant *assistant, GtkWidget *page, gpointer user_data);
53 void csv_import_assistant_finish (GtkAssistant *gtkassistant, gpointer user_data);
54 void csv_import_assistant_cancel (GtkAssistant *gtkassistant, gpointer user_data);
55 void csv_import_assistant_close (GtkAssistant *gtkassistant, gpointer user_data);
56 
57 void csv_import_assistant_start_page_prepare (GtkAssistant *gtkassistant, gpointer user_data);
58 void csv_import_assistant_account_page_prepare (GtkAssistant *gtkassistant, gpointer user_data);
59 void csv_import_assistant_file_page_prepare (GtkAssistant *assistant, gpointer user_data);
60 void csv_import_assistant_finish_page_prepare (GtkAssistant *assistant, gpointer user_data);
61 void csv_import_assistant_summary_page_prepare (GtkAssistant *assistant, gpointer user_data);
62 
63 void csv_import_sep_cb (GtkWidget *radio, gpointer user_data );
64 void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data );
65 
66 void csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info);
67 
68 static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
69 
70 static const gchar *finish_tree_string = N_(
71  "The accounts will be imported from the file '%s' when you click 'Apply'.\n\n"
72  "You can verify your selections by clicking on 'Back' or 'Cancel' to Abort Import.\n");
73 
74 static const gchar *new_book_finish_tree_string = N_(
75  "The accounts will be imported from the file '%s' when you click 'Apply'.\n\n"
76  "You can verify your selections by clicking on 'Back' or 'Cancel' to Abort Import.\n\n"
77  "If this is your initial import into a new file, you will first see "
78  "a dialog for setting book options, since these can affect how "
79  "imported data is converted to GnuCash transactions.\n"
80  "Note: After import, you may need to use 'View / Filter By / Other' menu option "
81  "and select to show unused Accounts.\n");
82 
83 /* Escape '_' in string */
84 static gchar *mnemonic_escape (const gchar *source);
85 static gchar *mnemonic_escape (const gchar *source)
86 {
87  const guchar *p;
88  gchar *dest;
89  gchar *q;
90 
91  g_return_val_if_fail (source != NULL, NULL);
92 
93  p = (guchar *) source;
94  q = dest = g_malloc (strlen (source) * 2 + 1);
95 
96  while (*p)
97  {
98  switch (*p)
99  {
100  case '_':
101  *q++ = '_';
102  *q++ = '_';
103  break;
104  default:
105  *q++ = *p;
106  break;
107  }
108  p++;
109  }
110  *q = 0;
111  return dest;
112 }
113 
114 static
115 void create_regex (GString *regex_str, const gchar *sep)
116 {
117  if (!sep) return;
118 
119  g_string_printf (regex_str,
120  "\\G(?<type>[^%s]*)%s"
121  "(?<full_name>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
122  "(?<name>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
123  "(?<code>\"(?:[^\"]|\"\")*\"|[^%s]*)%s?"
124  "(?<description>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
125  "(?<color>[^%s]*)%s"
126  "(?<notes>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
127  "(?<commoditym>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
128  "(?<commodityn>\"(?:[^\"]|\"\")*\"|[^%s]*)%s"
129  "(?<hidden>[^%s]*)%s"
130  "(?<tax>[^%s]*)%s"
131  "(?<place_holder>[^%s[:cntrl:]]*)(?:\\R*)",
132  sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep,
133  sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep);
134 
135 }
136 
137 /*************************************************************************/
138 
139 /**************************************************
140  * csv_file_chooser_confirm_cb
141  *
142  * call back for ok button in file chooser widget
143  **************************************************/
144 void
145 csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info)
146 {
147  GtkAssistant *assistant = GTK_ASSISTANT(info->window);
148  gint num = gtk_assistant_get_current_page (assistant);
149  GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
150 
151  gchar *file_name;
152  csv_import_result res;
153 
154  gtk_assistant_set_page_complete (assistant, page, FALSE);
155 
156  file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(info->file_chooser));
157 
158  if (file_name)
159  {
160  gchar *filepath = gnc_uri_get_path (file_name);
161  gchar *filedir = g_path_get_dirname (filepath);
162  info->starting_dir = g_strdup (filedir);
163  g_free (filedir);
164  g_free (filepath);
165 
166  info->file_name = g_strdup (file_name);
167 
168  // generate preview
169  gtk_list_store_clear (info->store);
170  res = csv_import_read_file (info->file_name, info->regexp->str, info->store, 1 );
171  if (res == RESULT_OPEN_FAILED)
172  gnc_error_dialog (info->window, _("The input file can not be opened."));
173  else if (res == RESULT_OK)
174  gtk_assistant_set_page_complete (assistant, page, TRUE);
175  else if (res == MATCH_FOUND)
176  gtk_assistant_set_page_complete (assistant, page, TRUE);
177  }
178  g_free (file_name);
179 
180  DEBUG("file_name selected is %s", info->file_name);
181  DEBUG("starting directory is %s", info->starting_dir);
182 
183  /* Step to next page if page is complete */
184  if(gtk_assistant_get_page_complete (assistant, page))
185  gtk_assistant_set_current_page (assistant, num + 1);
186 
187 }
188 
189 
190 /*******************************************************
191  * csv_import_hrows_cb
192  *
193  * call back for the start row / number of header rows
194  *******************************************************/
195 void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data)
196 {
197  CsvImportInfo *info = user_data;
198 
199  GtkTreeIter iter;
200  gboolean valid;
201  int num_rows;
202 
203  /* Get number of rows for header */
204  info->header_rows = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(spin));
205 
206  /* Get number of rows displayed */
207  num_rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(info->store), NULL);
208 
209  /* Modify background color for header rows */
210  if (info->header_rows == 0)
211  {
212  valid = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(info->store), &iter, NULL, 0 );
213  if (valid)
214  gtk_list_store_set (info->store, &iter, ROW_COLOR, NULL, -1);
215  }
216  else
217  {
218  if (info->header_rows - 1 < num_rows)
219  {
220  valid = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(info->store), &iter, NULL, info->header_rows - 1 );
221  if (valid)
222  gtk_list_store_set (info->store, &iter, ROW_COLOR, "pink", -1);
223  valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(info->store), &iter);
224  if (valid)
225  gtk_list_store_set (info->store, &iter, ROW_COLOR, NULL, -1);
226  }
227  }
228 }
229 
230 
231 /*******************************************************
232  * csv_import_sep_cb
233  *
234  * call back for type of separartor required
235  *******************************************************/
236 void csv_import_sep_cb (GtkWidget *radio, gpointer user_data)
237 {
238  CsvImportInfo *info = user_data;
239  const gchar *name;
240  gchar *temp;
241  gchar *sep = NULL;
242 
243  if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radio)))
244  {
245  LEAVE("1st callback of pair. Defer to 2nd callback.");
246  return;
247  }
248 
249  name = gtk_buildable_get_name (GTK_BUILDABLE(radio));
250  if (g_strcmp0 (name, "radio_semi") == 0)
251  sep = ";";
252  else if (g_strcmp0 (name, "radio_colon") == 0)
253  sep = ":";
254  else
255  sep = ","; /* Use as default as well */
256 
257  create_regex (info->regexp, sep);
258 
259  if (g_strcmp0 (name, "radio_custom") == 0)
260  {
261  temp = gnc_input_dialog (0, _("Adjust regular expression used for import"), _("This regular expression is used to parse the import file. Modify according to your needs.\n"), info->regexp->str);
262  if (temp)
263  {
264  g_string_assign (info->regexp, temp);
265  g_free (temp);
266  }
267  }
268 
269  /* Generate preview */
270  gtk_list_store_clear (info->store);
271 
272  if (csv_import_read_file (info->file_name, info->regexp->str, info->store, 11) == MATCH_FOUND)
273  gtk_widget_set_sensitive (info->header_row_spin, TRUE);
274  else
275  gtk_widget_set_sensitive (info->header_row_spin, FALSE);
276 
277  /* Reset Header spin to 0 */
278  gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 0);
279 }
280 
281 
282 /*******************************************************
283  * load_settings
284  *
285  * load the default settings for the assistant
286  *******************************************************/
287 static
288 void load_settings (CsvImportInfo *info)
289 {
290  info->header_rows = 0;
291  info->error = "";
292  info->starting_dir = NULL;
293  info->file_name = NULL;
294  info->error = "";
295 
296  /* The default directory for the user to select files. */
297  info->starting_dir = gnc_get_default_directory (GNC_PREFS_GROUP);
298 }
299 
300 
301 /* =============================================================== */
302 
303 
304 /********************************************************************\
305  * gnc_input_dialog *
306  * simple convenience dialog to get a single value from the user *
307  * user may choose between "Ok" and "Cancel" *
308  * *
309  * NOTE: This function does not return until the dialog is closed *
310  * *
311  * Args: parent - the parent window or NULL *
312  * title - the title of the dialog *
313  * msg - the message to display *
314  * default_input - will be displayed as default input *
315  * Return: the input (text) the user entered, if pressed "Ok" *
316  * NULL, if pressed "Cancel" *
317 \********************************************************************/
318 static gchar *
319 gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
320 {
321  GtkWidget *dialog, *label, *content_area;
322  gint result;
323  GtkWidget *view;
324  GtkTextBuffer *buffer;
325  gchar *user_input;
326  GtkTextIter start, end;
327 
328  /* Create the widgets */
329  dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW(parent),
330  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
331  GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
332  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
333  NULL);
334 
335  content_area = gtk_dialog_get_content_area (GTK_DIALOG(dialog));
336 
337  // add a label
338  label = gtk_label_new (msg);
339  gtk_container_add (GTK_CONTAINER(content_area), label);
340 
341  // add a textview
342  view = gtk_text_view_new ();
343  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(view), GTK_WRAP_WORD_CHAR);
344  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(view));
345  gtk_text_buffer_set_text (buffer, default_input, -1);
346  gtk_container_add (GTK_CONTAINER(content_area), view);
347 
348  // run the dialog
349  gtk_widget_show_all (dialog);
350  result = gtk_dialog_run (GTK_DIALOG(dialog));
351 
352  if (result == GTK_RESPONSE_REJECT)
353  user_input = 0;
354  else
355  {
356  gtk_text_buffer_get_start_iter (buffer, &start);
357  gtk_text_buffer_get_end_iter (buffer, &end);
358  user_input = gtk_text_buffer_get_text (buffer,
359  &start, &end, FALSE);
360  }
361 
362  gtk_widget_destroy (dialog);
363 
364  return user_input;
365 }
366 
367 
368 /* =============================================================== */
369 
370 
371 /*******************************************************
372  * Assistant page prepare functions
373  *******************************************************/
374 void
375 csv_import_assistant_start_page_prepare (GtkAssistant *assistant,
376  gpointer user_data)
377 {
378  gint num = gtk_assistant_get_current_page (assistant);
379  GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
380 
381  /* Enable the Assistant Buttons */
382  gtk_assistant_set_page_complete (assistant, page, TRUE);
383 }
384 
385 
386 void
387 csv_import_assistant_file_page_prepare (GtkAssistant *assistant,
388  gpointer user_data)
389 {
390  CsvImportInfo *info = user_data;
391  gint num = gtk_assistant_get_current_page (assistant);
392  GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
393 
394  /* Set the default directory */
395  if (info->starting_dir)
396  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(info->file_chooser), info->starting_dir);
397 
398  /* Disable the Forward Assistant Button */
399  gtk_assistant_set_page_complete (assistant, page, FALSE);
400 }
401 
402 
403 void
404 csv_import_assistant_account_page_prepare (GtkAssistant *assistant,
405  gpointer user_data)
406 {
407  CsvImportInfo *info = user_data;
408 
409  gtk_list_store_clear (info->store);
410 
411  if (csv_import_read_file (info->file_name, info->regexp->str, info->store, 11 ) == MATCH_FOUND)
412  gtk_widget_set_sensitive (info->header_row_spin, TRUE);
413  else
414  gtk_widget_set_sensitive (info->header_row_spin, FALSE);
415 }
416 
417 
418 void
419 csv_import_assistant_finish_page_prepare (GtkAssistant *assistant,
420  gpointer user_data)
421 {
422  CsvImportInfo *info = user_data;
423  gint num = gtk_assistant_get_current_page (assistant);
424  GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
425  gchar *text;
426 
427  /* Set Finish page text */
428  /* Before creating accounts, if this is a new book, tell user they can
429  * specify book options, since they affect how transactions are created */
430  if (info->new_book)
431  {
432  text = g_strdup_printf (gettext (new_book_finish_tree_string), info->file_name);
433  }
434  else
435  {
436  text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
437  }
438  gtk_label_set_text (GTK_LABEL(info->finish_label), text);
439  g_free (text);
440 
441  /* Save the Window size and directory */
442  gnc_set_default_directory (GNC_PREFS_GROUP, info->starting_dir);
443 
444  /* Enable the Assistant Buttons */
445  gtk_assistant_set_page_complete (assistant, page, TRUE);
446 }
447 
448 
449 void
450 csv_import_assistant_summary_page_prepare (GtkAssistant *assistant,
451  gpointer user_data)
452 {
453  CsvImportInfo *info = user_data;
454  gchar *text, *errtext, *mtext;
455 
456  /* Before creating accounts, if this is a new book, let user specify
457  * book options, since they affect how transactions are created */
458  if (info->new_book)
459  info->new_book = gnc_new_book_option_display (info->window);
460 
461  if (!g_strcmp0 (info->error, "") == 0)
462  {
463  GtkTextBuffer *buffer;
464 
465  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(info->summary_error_view));
466  text = g_strdup_printf (gettext ("Import completed but with errors!\n\nThe number of Accounts added was %u and "
467  "%u were updated.\n\nSee below for errors..."), info->num_new, info->num_updates);
468  errtext = g_strdup_printf ("%s", info->error);
469  gtk_text_buffer_set_text (buffer, errtext, -1);
470  g_free (errtext);
471  g_free (info->error);
472  }
473  else
474  text = g_strdup_printf (gettext ("Import completed successfully!\n\nThe number of Accounts added was %u and "
475  "%u were updated.\n"), info->num_new, info->num_updates);
476 
477  mtext = g_strdup_printf ("<span size=\"medium\"><b>%s</b></span>", text);
478  gtk_label_set_markup (GTK_LABEL(info->summary_label), mtext);
479 
480  g_free (text);
481  g_free (mtext);
482 }
483 
484 
485 void
486 csv_import_assistant_prepare (GtkAssistant *assistant, GtkWidget *page,
487  gpointer user_data)
488 {
489  gint currentpage = gtk_assistant_get_current_page (assistant);
490 
491  switch (currentpage)
492  {
493  case 0:
494  /* Current page is Import Start page */
495  csv_import_assistant_start_page_prepare (assistant, user_data);
496  break;
497  case 1:
498  /* Current page is File select page */
499  csv_import_assistant_file_page_prepare (assistant, user_data);
500  break;
501  case 2:
502  /* Current page is Account page */
503  csv_import_assistant_account_page_prepare (assistant, user_data);
504  break;
505  case 3:
506  /* Current page is Finish page */
507  csv_import_assistant_finish_page_prepare (assistant, user_data);
508  break;
509  case 4:
510  /* Current page is Summary page */
511  csv_import_assistant_summary_page_prepare (assistant, user_data);
512  break;
513  }
514 }
515 
516 
517 /*******************************************************
518  * Assistant call back functions
519  *******************************************************/
520 static void
521 csv_import_assistant_destroy_cb (GtkObject *object, gpointer user_data)
522 {
523  CsvImportInfo *info = user_data;
524  gnc_unregister_gui_component_by_data (ASSISTANT_CSV_IMPORT_CM_CLASS, info);
525  g_free (info);
526 }
527 
528 void
529 csv_import_assistant_cancel (GtkAssistant *assistant, gpointer user_data)
530 {
531  CsvImportInfo *info = user_data;
532  gnc_close_gui_component_by_data (ASSISTANT_CSV_IMPORT_CM_CLASS, info);
533 }
534 
535 void
536 csv_import_assistant_close (GtkAssistant *assistant, gpointer user_data)
537 {
538  CsvImportInfo *info = user_data;
539  gnc_close_gui_component_by_data (ASSISTANT_CSV_IMPORT_CM_CLASS, info);
540 }
541 
542 void
543 csv_import_assistant_finish (GtkAssistant *assistant, gpointer user_data)
544 {
545  CsvImportInfo *info = user_data;
546 
547  gtk_list_store_clear (info->store);
548  csv_import_read_file (info->file_name, info->regexp->str, info->store, 0 );
549  csv_account_import (info);
550 }
551 
552 static void
553 csv_import_close_handler (gpointer user_data)
554 {
555  CsvImportInfo *info = user_data;
556 
557  g_free (info->starting_dir);
558  g_free (info->file_name);
559  g_string_free (info->regexp, TRUE);
560 
561  gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->window));
562  gtk_widget_destroy (info->window);
563 }
564 
565 /*******************************************************
566  * Create the Assistant
567  *******************************************************/
568 static GtkWidget *
569 csv_import_assistant_create (CsvImportInfo *info)
570 {
571  GtkBuilder *builder;
572  GtkWidget *window;
573  GtkWidget *box, *h_box;
574  GtkWidget *button;
575  GtkCellRenderer *renderer;
576  GtkTreeViewColumn *column;
577  gchar *mnemonic_desc = NULL;
578 
579  builder = gtk_builder_new();
580  gnc_builder_add_from_file (builder, "assistant-csv-account-import.glade", "num_hrows_adj");
581  gnc_builder_add_from_file (builder, "assistant-csv-account-import.glade", "CSV Account Import Assistant");
582  window = GTK_WIDGET(gtk_builder_get_object (builder, "CSV Account Import Assistant"));
583  info->window = window;
584 
585  /* Set the assistant colors */
586  gnc_assistant_set_colors (GTK_ASSISTANT (info->window));
587 
588  /* Load default settings */
589  load_settings (info);
590 
591  /* Enable buttons on all page. */
592  gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
593  GTK_WIDGET(gtk_builder_get_object(builder, "start_page")),
594  TRUE);
595  gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
596  GTK_WIDGET(gtk_builder_get_object(builder, "file_page")),
597  FALSE);
598  gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
599  GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page")),
600  TRUE);
601  gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
602  GTK_WIDGET(gtk_builder_get_object(builder, "end_page")),
603  FALSE);
604  gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
605  GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")),
606  TRUE);
607 
608  /* Start Page */
609 
610  /* File chooser Page */
611  info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
612  g_signal_connect (G_OBJECT(info->file_chooser), "file-activated",
613  G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
614  button = gtk_button_new_from_stock (GTK_STOCK_OK);
615  gtk_widget_set_size_request (button, 100, -1);
616  gtk_widget_show (button);
617  h_box = gtk_hbox_new (TRUE, 0);
618  gtk_box_pack_start (GTK_BOX(h_box), button, FALSE, FALSE, 0);
619  gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(info->file_chooser), h_box);
620  g_signal_connect (G_OBJECT(button), "clicked",
621  G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
622 
623  box = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
624  gtk_box_pack_start (GTK_BOX(box), info->file_chooser, TRUE, TRUE, 6);
625  gtk_widget_show (info->file_chooser);
626 
627  /* Account Tree Page */
628  info->header_row_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_hrows"));
629  info->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));
630 
631  /* Comma Separated file default */
632  info->regexp = g_string_new ("");
633  create_regex (info->regexp, ",");
634 
635  /* create model and bind to view */
636  info->store = gtk_list_store_new (N_COLUMNS,
637  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
638  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
639  gtk_tree_view_set_model (GTK_TREE_VIEW(info->tree_view), GTK_TREE_MODEL(info->store));
640 #define CREATE_COLUMN(description,column_id) \
641  renderer = gtk_cell_renderer_text_new (); \
642  mnemonic_desc = mnemonic_escape (_(description)); \
643  column = gtk_tree_view_column_new_with_attributes (mnemonic_desc, renderer, "text", column_id, NULL); \
644  gtk_tree_view_column_add_attribute (column, renderer, "background", ROW_COLOR); \
645  gtk_tree_view_column_set_resizable (column, TRUE); \
646  gtk_tree_view_append_column (GTK_TREE_VIEW(info->tree_view), column); \
647  g_free (mnemonic_desc);
648  CREATE_COLUMN ("type", TYPE);
649  CREATE_COLUMN ("full_name", FULL_NAME);
650  CREATE_COLUMN ("name", NAME);
651  CREATE_COLUMN ("code", CODE);
652  CREATE_COLUMN ("description", DESCRIPTION);
653  CREATE_COLUMN ("color", COLOR);
654  CREATE_COLUMN ("notes", NOTES);
655  CREATE_COLUMN ("commoditym", COMMODITYM);
656  CREATE_COLUMN ("commodityn", COMMODITYN);
657  CREATE_COLUMN ("hidden", HIDDEN);
658  CREATE_COLUMN ("tax", TAX);
659  CREATE_COLUMN ("place_holder", PLACE_HOLDER);
660 
661  /* Finish Page */
662  info->finish_label = GTK_WIDGET(gtk_builder_get_object (builder, "end_page"));
663  /* Summary Page */
664  info->summary_label = GTK_WIDGET(gtk_builder_get_object (builder, "summary_label"));
665  info->summary_error_view = GTK_WIDGET(gtk_builder_get_object (builder, "summary_error_view"));
666 
667  g_signal_connect (G_OBJECT(window), "destroy",
668  G_CALLBACK(csv_import_assistant_destroy_cb), info);
669 
670  gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->window));
671 
672  gtk_builder_connect_signals (builder, info);
673  g_object_unref (G_OBJECT(builder));
674  return window;
675 }
676 
677 
678 /********************************************************************\
679  * gnc_file_csv_account_import *
680  * opens up a assistant to import accounts. *
681  * *
682  * Args: import_type *
683  * Return: nothing *
684 \********************************************************************/
685 void
687 {
688  CsvImportInfo *info;
689 
690  info = g_new0 (CsvImportInfo, 1);
691 
692  /* In order to trigger a book options display on the creation of a new book,
693  * we need to detect when we are dealing with a new book. */
694  info->new_book = gnc_is_new_book();
695 
696  csv_import_assistant_create (info);
697 
698  gnc_register_gui_component (ASSISTANT_CSV_IMPORT_CM_CLASS,
699  NULL, csv_import_close_handler,
700  info);
701 
702  gtk_widget_show_all (info->window);
703 
704  gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
705 }
utility functions for the GnuCash UI
#define DEBUG(format, args...)
Definition: qoflog.h:255
gchar * gnc_uri_get_path(const gchar *uri)
void gnc_file_csv_account_import(void)
CSV Import Assistant.
#define LEAVE(format, args...)
Definition: qoflog.h:271
Utility functions for convert uri in separate components and back.
const gchar * QofLogModule
Definition: qofid.h:89