GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-bi-import-gui.c
1 /*
2  * dialog-bi-import-gui.c -- Invoice Importer GUI
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (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, contact:
16  *
17  * Free Software Foundation Voice: +1-617-542-5942
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
19  * Boston, MA 02110-1301, USA [email protected]
20  */
21 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include <glib/gi18n.h>
35 
36 #include "gnc-ui.h"
37 #include "gnc-ui-util.h"
38 #include "gnc-component-manager.h"
39 #include "dialog-utils.h"
40 #include "gnc-gui-query.h"
41 #include "gnc-file.h"
42 #include "dialog-bi-import.h"
43 #include "dialog-bi-import-gui.h"
44 
46 {
47  GtkWidget *dialog;
48  GtkWidget *tree_view;
49  GtkWidget *entryFilename;
50  GtkListStore *store;
51  gint component_id;
52  GString *regexp;
53  QofBook *book;
54  gchar *type;
55  gchar *open_mode;
56 };
57 
58 
59 // callback routines
60 void gnc_bi_import_gui_ok_cb (GtkWidget *widget, gpointer data);
61 void gnc_bi_import_gui_cancel_cb (GtkWidget *widget, gpointer data);
62 void gnc_bi_import_gui_help_cb (GtkWidget *widget, gpointer data);
63 void gnc_bi_import_gui_destroy_cb (GtkWidget *widget, gpointer data);
64 static void gnc_bi_import_gui_close_handler (gpointer user_data);
65 void gnc_bi_import_gui_buttonOpen_cb (GtkWidget *widget, gpointer data);
66 void gnc_bi_import_gui_filenameChanged_cb (GtkWidget *widget, gpointer data);
67 void gnc_bi_import_gui_option1_cb (GtkWidget *widget, gpointer data);
68 void gnc_bi_import_gui_option2_cb (GtkWidget *widget, gpointer data);
69 void gnc_bi_import_gui_option3_cb (GtkWidget *widget, gpointer data);
70 void gnc_bi_import_gui_option4_cb (GtkWidget *widget, gpointer data);
71 void gnc_bi_import_gui_option5_cb (GtkWidget *widget, gpointer data);
72 void gnc_bi_import_gui_open_mode_cb (GtkWidget *widget, gpointer data);
73 void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data);
74 
75 // utils
76 static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
77 static void gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg);
78 
79 
80 BillImportGui *
82 {
83  BillImportGui *gui;
84  GtkBuilder *builder;
85  GList *glist;
86  GtkCellRenderer *renderer;
87  GtkTreeViewColumn *column;
88 
89  // if window exists already, activate it
90  glist = gnc_find_gui_components ("dialog-bi-import-gui", NULL, NULL);
91  if (glist)
92  {
93  // window found
94  gui = g_list_nth_data (glist, 0);
95  g_list_free (glist);
96  gtk_window_present (GTK_WINDOW(gui->dialog));
97  return gui;
98  }
99 
100  // create new window
101  gui = g_new0 (BillImportGui, 1);
102  gui->type = "BILL"; // Set default type to match gui. really shouldn't be here TODO change me
103  gui->open_mode = "ALL";
104 
105  builder = gtk_builder_new();
106  gnc_builder_add_from_file (builder, "dialog-bi-import-gui.glade", "bi-import Dialog");
107  gui->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "bi-import Dialog"));
108  gui->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview1"));
109  gui->entryFilename = GTK_WIDGET(gtk_builder_get_object (builder, "entryFilename"));
110 
111  gui->book = gnc_get_current_book();
112 
113  gui->regexp = g_string_new ( "^(?<id>[^;]*);(?<date_opened>[^;]*);(?<owner_id>[^;]*);(?<billing_id>[^;]*);?(?<notes>[^;]*);?(?<date>[^;]*);?(?<desc>[^;]*);?(?<action>[^;]*);?(?<account>[^;]*);?(?<quantity>[^;]*);?(?<price>[^;]*);?(?<disc_type>[^;]*);?(?<disc_how>[^;]*);?(?<discount>[^;]*);?(?<taxable>[^;]*);?(?<taxincluded>[^;]*);?(?<tax_table>[^;]*);(?<date_posted>[^;]*);(?<due_date>[^;]*);(?<account_posted>[^;]*);(?<memo_posted>[^;]*);(?<accu_splits>[^;]*)$");
114 
115  // create model and bind to view
116  gui->store = gtk_list_store_new (N_COLUMNS,
117  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, // invoice settings
118  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, // entry settings
119  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); // autopost settings
120  gtk_tree_view_set_model( GTK_TREE_VIEW(gui->tree_view), GTK_TREE_MODEL(gui->store) );
121 #define CREATE_COLUMN(description,column_id) \
122  renderer = gtk_cell_renderer_text_new (); \
123  column = gtk_tree_view_column_new_with_attributes (description, renderer, "text", column_id, NULL); \
124  gtk_tree_view_column_set_resizable (column, TRUE); \
125  gtk_tree_view_append_column (GTK_TREE_VIEW (gui->tree_view), column);
126  CREATE_COLUMN ("id", ID);
127  CREATE_COLUMN ("date__opened", DATE_OPENED);
128  CREATE_COLUMN ("owner__id", OWNER_ID);
129  CREATE_COLUMN ("billing__id", BILLING_ID);
130  CREATE_COLUMN ("notes", NOTES);
131 
132  CREATE_COLUMN ("date", DATE);
133  CREATE_COLUMN ("desc", DESC);
134  CREATE_COLUMN ("action", ACTION);
135  CREATE_COLUMN ("account", ACCOUNT);
136  CREATE_COLUMN ("quantity", QUANTITY);
137  CREATE_COLUMN ("price", PRICE);
138  CREATE_COLUMN ("disc__type", DISC_TYPE);
139  CREATE_COLUMN ("disc__how", DISC_HOW);
140  CREATE_COLUMN ("discount", DISCOUNT);
141  CREATE_COLUMN ("taxable", TAXABLE);
142  CREATE_COLUMN ("taxincluded", TAXINCLUDED);
143  CREATE_COLUMN ("tax__table", TAX_TABLE);
144 
145  CREATE_COLUMN ("date__posted", DATE_POSTED);
146  CREATE_COLUMN ("due__date", DUE_DATE);
147  CREATE_COLUMN ("account__posted", ACCOUNT_POSTED);
148  CREATE_COLUMN ("memo__posted", MEMO_POSTED);
149  CREATE_COLUMN ("accu__splits", ACCU_SPLITS);
150 
151  gui->component_id = gnc_register_gui_component ("dialog-bi-import-gui",
152  NULL,
153  gnc_bi_import_gui_close_handler,
154  gui);
155 
156  /* Setup signals */
157  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, gui);
158 
159  gtk_widget_show_all ( gui->dialog );
160 
161  g_object_unref(G_OBJECT(builder));
162 
163  return gui;
164 }
165 
166 static gchar *
167 gnc_plugin_bi_import_getFilename(void)
168 {
169  // prepare file import dialog
170  gchar *filename;
171  GList *filters;
172  GtkFileFilter *filter;
173  filters = NULL;
174  filter = gtk_file_filter_new ();
175  gtk_file_filter_set_name (filter, "comma separated values (*.csv)");
176  gtk_file_filter_add_pattern (filter, "*.csv");
177  filters = g_list_append( filters, filter );
178  filter = gtk_file_filter_new ();
179  gtk_file_filter_set_name (filter, "text files (*.txt)");
180  gtk_file_filter_add_pattern (filter, "*.txt");
181  filters = g_list_append( filters, filter );
182  filename = gnc_file_dialog(_("Import Bills or Invoices from csv"), filters, NULL, GNC_FILE_DIALOG_IMPORT);
183 
184  return filename;
185 }
186 
187 void
188 gnc_bi_import_gui_ok_cb (GtkWidget *widget, gpointer data)
189 {
190  BillImportGui *gui = data;
191  gchar *filename = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->entryFilename) ) );
192  bi_import_stats stats;
193  bi_import_result res;
194  guint n_fixed, n_deleted, n_invoices_created, n_invoices_updated;
195  GString *info;
196 
197  // import
198  info = g_string_new("");
199 
200  gtk_list_store_clear (gui->store);
201  res = gnc_bi_import_read_file (filename, gui->regexp->str, gui->store, 0, &stats);
202  if (res == RESULT_OK)
203  {
204  gnc_bi_import_fix_bis (gui->store, &n_fixed, &n_deleted, info, gui->type);
205  if (info->len > 0)
206  gnc_info_dialog (gui->dialog, "%s", info->str);
207  g_string_free( info, TRUE );
208  gnc_bi_import_create_bis (gui->store, gui->book, &n_invoices_created, &n_invoices_updated, gui->type, gui->open_mode, info);
209  gnc_info_dialog (gui->dialog, _("Import results:\n%i lines were ignored\n%i lines imported:\n %u fixes\n %u ignored (not fixable)\n\n %u created\n %u updated (based on id)"), stats.n_ignored, stats.n_imported, n_fixed, n_deleted, n_invoices_created, n_invoices_updated);
210 
211  if (stats.n_ignored > 0)
212  gnc_info2_dialog (gui->dialog, _("These lines were ignored during import"), stats.ignored_lines->str);
213 
214  g_string_free (stats.ignored_lines, TRUE);
215  gnc_close_gui_component (gui->component_id);
216  }
217  else if (res == RESULT_OPEN_FAILED)
218  {
219  gnc_error_dialog (gui->dialog, _("The input file can not be opened."));
220  }
221  else if (res == RESULT_ERROR_IN_REGEXP)
222  {
223  //gnc_error_dialog (gui->dialog, "The regular expression is faulty:\n\n%s", stats.err->str);
224  }
225 }
226 
227 void
228 gnc_bi_import_gui_cancel_cb (GtkWidget *widget, gpointer data)
229 {
230  BillImportGui *gui = data;
231 
232  gnc_close_gui_component (gui->component_id);
233 }
234 
235 void
236 gnc_bi_import_gui_help_cb (GtkWidget *widget, gpointer data)
237 {
238  gnc_gnome_help(HF_HELP, HL_USAGE_BSNSS);
239 }
240 
241 static void
242 gnc_bi_import_gui_close_handler (gpointer user_data)
243 {
244  BillImportGui *gui = user_data;
245 
246  gtk_widget_destroy (gui->dialog);
247  // gui has already been freed by this point.
248  // gui->dialog = NULL;
249 }
250 
251 void
252 gnc_bi_import_gui_destroy_cb (GtkWidget *widget, gpointer data)
253 {
254  BillImportGui *gui = data;
255 
256  gnc_suspend_gui_refresh ();
257  gnc_unregister_gui_component (gui->component_id);
258  gnc_resume_gui_refresh ();
259 
260  g_object_unref (gui->store);
261  g_string_free (gui->regexp, TRUE);
262  g_free (gui);
263 }
264 
265 void gnc_bi_import_gui_buttonOpen_cb (GtkWidget *widget, gpointer data)
266 {
267  gchar *filename;
268  BillImportGui *gui = data;
269 
270  filename = gnc_plugin_bi_import_getFilename();
271  if (filename)
272  {
273  //printf("Setting filename"); // debug
274  gtk_entry_set_text( GTK_ENTRY(gui->entryFilename), filename );
275  //printf("Set filename"); // debug
276  g_free( filename );
277  }
278 }
279 
280 void gnc_bi_import_gui_filenameChanged_cb (GtkWidget *widget, gpointer data)
281 {
282  BillImportGui *gui = data;
283  gchar *filename = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->entryFilename) ) );
284 
285  // generate preview
286  gtk_list_store_clear (gui->store);
287  gnc_bi_import_read_file (filename, gui->regexp->str, gui->store, 10, NULL);
288 
289  g_free( filename );
290 }
291 
292 void gnc_bi_import_gui_option1_cb (GtkWidget *widget, gpointer data)
293 {
294  BillImportGui *gui = data;
295  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
296  return;
297  g_string_assign (gui->regexp, "^(?<id>[^;]*);(?<date_opened>[^;]*);(?<owner_id>[^;]*);(?<billing_id>[^;]*);?(?<notes>[^;]*);?(?<date>[^;]*);?(?<desc>[^;]*);?(?<action>[^;]*);?(?<account>[^;]*);?(?<quantity>[^;]*);?(?<price>[^;]*);?(?<disc_type>[^;]*);?(?<disc_how>[^;]*);?(?<discount>[^;]*);?(?<taxable>[^;]*);?(?<taxincluded>[^;]*);?(?<tax_table>[^;]*);(?<date_posted>[^;]*);(?<due_date>[^;]*);(?<account_posted>[^;]*);(?<memo_posted>[^;]*);(?<accu_splits>[^;]*)$");
298  gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
299 }
300 
301 void gnc_bi_import_gui_option2_cb (GtkWidget *widget, gpointer data)
302 {
303  BillImportGui *gui = data;
304  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
305  return;
306  g_string_assign (gui->regexp, "^(?<id>[^,]*),(?<date_opened>[^,]*),(?<owner_id>[^,]*),(?<billing_id>[^,]*),?(?<notes>[^,]*),?(?<date>[^,]*),?(?<desc>[^,]*),?(?<action>[^,]*),?(?<account>[^,]*),?(?<quantity>[^,]*),?(?<price>[^,]*),?(?<disc_type>[^,]*),?(?<disc_how>[^,]*),?(?<discount>[^,]*),?(?<taxable>[^,]*),?(?<taxincluded>[^,]*),?(?<tax_table>[^,]*),(?<date_posted>[^,]*),(?<due_date>[^,]*),(?<account_posted>[^,]*),(?<memo_posted>[^,]*),(?<accu_splits>[^,]*)$");
307  gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
308 }
309 
310 void gnc_bi_import_gui_option3_cb (GtkWidget *widget, gpointer data)
311 {
312  BillImportGui *gui = data;
313  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
314  return;
315  g_string_assign (gui->regexp, "^((?<id>[^\";]*)|\"(?<id>[^\"]*)\");((?<date_opened>[^\";]*)|\"(?<date_opened>[^\"]*)\");((?<owner_id>[^\";]*)|\"(?<owner_id>[^\"]*)\");((?<billing_id>[^\";]*)|\"(?<billing_id>[^\"]*)\");((?<notes>[^\";]*)|\"(?<notes>[^\"]*)\");((?<date>[^\";]*)|\"(?<date>[^\"]*)\");((?<desc>[^\";]*)|\"(?<desc>[^\"]*)\");((?<action>[^\";]*)|\"(?<action>[^\"]*)\");((?<account>[^\";]*)|\"(?<account>[^\"]*)\");((?<quantity>[^\";]*)|\"(?<quantity>[^\"]*)\");((?<price>[^\";]*)|\"(?<price>[^\"]*)\");((?<disc_type>[^\";]*)|\"(?<disc_type>[^\"]*)\");((?<disc_how>[^\";]*)|\"(?<disc_how>[^\"]*)\");((?<discount>[^\";]*)|\"(?<discount>[^\"]*)\");((?<taxable>[^\";]*)|\"(?<taxable>[^\"]*)\");((?<taxincluded>[^\";]*)|\"(?<taxincluded>[^\"]*)\");((?<tax_table>[^\";]*)|\"(?<tax_table>[^\"]*)\");((?<date_posted>[^\";]*)|\"(?<date_posted>[^\"]*)\");((?<due_date>[^\";]*)|\"(?<due_date>[^\"]*)\");((?<account_posted>[^\";]*)|\"(?<account_posted>[^\"]*)\");((?<memo_posted>[^\";]*)|\"(?<memo_posted>[^\"]*)\");((?<accu_splits>[^\";]*)|\"(?<accu_splits>[^\"]*)\")$");
316  gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
317 }
318 
319 void gnc_bi_import_gui_option4_cb (GtkWidget *widget, gpointer data)
320 {
321  BillImportGui *gui = data;
322  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
323  return;
324  g_string_assign (gui->regexp, "^((?<id>[^\",]*)|\"(?<id>[^\"]*)\"),((?<date_opened>[^\",]*)|\"(?<date_opened>[^\"]*)\"),((?<owner_id>[^\",]*)|\"(?<owner_id>[^\"]*)\"),((?<billing_id>[^\",]*)|\"(?<billing_id>[^\"]*)\"),((?<notes>[^\",]*)|\"(?<notes>[^\"]*)\"),((?<date>[^\",]*)|\"(?<date>[^\"]*)\"),((?<desc>[^\",]*)|\"(?<desc>[^\"]*)\"),((?<action>[^\",]*)|\"(?<action>[^\"]*)\"),((?<account>[^\",]*)|\"(?<account>[^\"]*)\"),((?<quantity>[^\",]*)|\"(?<quantity>[^\"]*)\"),((?<price>[^\",]*)|\"(?<price>[^\"]*)\"),((?<disc_type>[^\",]*)|\"(?<disc_type>[^\"]*)\"),((?<disc_how>[^\",]*)|\"(?<disc_how>[^\"]*)\"),((?<discount>[^\",]*)|\"(?<discount>[^\"]*)\"),((?<taxable>[^\",]*)|\"(?<taxable>[^\"]*)\"),((?<taxincluded>[^\",]*)|\"(?<taxincluded>[^\"]*)\"),((?<tax_table>[^\",]*)|\"(?<tax_table>[^\"]*)\"),((?<date_posted>[^\",]*)|\"(?<date_posted>[^\"]*)\"),((?<due_date>[^\",]*)|\"(?<due_date>[^\"]*)\"),((?<account_posted>[^\",]*)|\"(?<account_posted>[^\"]*)\"),((?<memo_posted>[^\",]*)|\"(?<memo_posted>[^\"]*)\"),((?<accu_splits>[^\",]*)|\"(?<accu_splits>[^\"]*)\")$");
325  gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
326 }
327 
328 void gnc_bi_import_gui_option5_cb (GtkWidget *widget, gpointer data)
329 {
330  BillImportGui *gui = data;
331  gchar *temp;
332  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
333  return;
334  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"), gui->regexp->str);
335  if (temp)
336  {
337  g_string_assign (gui->regexp, temp);
338  g_free (temp);
339  gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
340  }
341 }
342 
343 void gnc_bi_import_gui_open_mode_cb (GtkWidget *widget, gpointer data)
344 {
345  BillImportGui *gui = data;
346  const gchar *name;
347  name = gtk_buildable_get_name(GTK_BUILDABLE(widget));
348  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
349  return;
350  if (g_ascii_strcasecmp(name, "radiobuttonOpenAll") == 0)gui->open_mode = "ALL";
351  else if (g_ascii_strcasecmp(name, "radiobuttonOpenNotPosted") == 0)gui->open_mode = "NOT_POSTED";
352  else if (g_ascii_strcasecmp(name, "radiobuttonOpenNone") == 0)gui->open_mode = "NONE";
353 }
354 
355 
356 /*****************************************************************
357  * Set whether we are importing a bill, invoice, Customer or Vendor
358  * ****************************************************************/
359 void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data)
360 {
361  BillImportGui *gui = data;
362  const gchar *name;
363  name = gtk_buildable_get_name(GTK_BUILDABLE(widget));
364  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
365  return;
366  if (g_ascii_strcasecmp(name, "radiobuttonInvoice") == 0)gui->type = "INVOICE";
367  else if (g_ascii_strcasecmp(name, "radiobuttonBill") == 0)gui->type = "BILL";
368  //printf ("TYPE set to, %s\n",gui->type);
369 
370 }
371 
372 
373 /********************************************************************\
374  * gnc_input_dialog *
375  * simple convenience dialog to get a single value from the user *
376  * user may choose between "Ok" and "Cancel" *
377  * *
378  * NOTE: This function does not return until the dialog is closed *
379  * *
380  * Args: parent - the parent window or NULL *
381  * title - the title of the dialog *
382  * msg - the message to display *
383  * default_input - will be displayed as default input *
384  * Return: the input (text) the user entered, if pressed "Ok" *
385  * NULL, if pressed "Cancel" *
386 \********************************************************************/
387 static gchar *
388 gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
389 {
390  GtkWidget *dialog, *label, *content_area;
391  gint result;
392  GtkWidget *view;
393  GtkTextBuffer *buffer;
394  gchar *user_input;
395  GtkTextIter start, end;
396 
397  /* Create the widgets */
398  dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
399  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
400  GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
401  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
402  NULL);
403 #ifdef HAVE_GTK_2_14
404  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
405 #else
406  content_area = GTK_DIALOG (dialog)->vbox;
407 #endif
408 
409  // add a label
410  label = gtk_label_new (msg);
411  gtk_container_add (GTK_CONTAINER (content_area), label);
412 
413  // add a textview
414  view = gtk_text_view_new ();
415  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
416  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
417  gtk_text_buffer_set_text (buffer, default_input, -1);
418  gtk_container_add (GTK_CONTAINER (content_area), view);
419 
420  // run the dialog
421  gtk_widget_show_all (dialog);
422  result = gtk_dialog_run (GTK_DIALOG (dialog));
423 
424  if (result == GTK_RESPONSE_REJECT)
425  user_input = 0;
426  else
427  {
428  gtk_text_buffer_get_start_iter (buffer, &start);
429  gtk_text_buffer_get_end_iter (buffer, &end);
430  user_input = gtk_text_buffer_get_text (buffer,
431  &start, &end, FALSE);
432  }
433 
434  gtk_widget_destroy (dialog);
435 
436  return user_input;
437 }
438 
439 
440 /********************************************************************\
441  * gnc_info2_dialog *
442  * displays an information dialog box (with scrollable text area) *
443  * *
444  * NOTE: This function does not return until the dialog is closed *
445  * *
446  * Args: parent - the parent window or NULL *
447  * title - the title of the dialog *
448  * msg - the message to display *
449  * Return: none *
450 \********************************************************************/
451 static void
452 gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg)
453 {
454  GtkWidget *dialog, *scrolledwindow, *content_area;
455  GtkWidget *view;
456  GtkTextBuffer *buffer;
457  gint width, height;
458 
459  /* Create the widgets */
460  dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
461  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
462  GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
463  NULL);
464 #ifdef HAVE_GTK_2_14
465  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
466 #else
467  content_area = GTK_DIALOG (dialog)->vbox;
468 #endif
469 
470  // add a scroll area
471  scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
472  gtk_container_add (GTK_CONTAINER (content_area), scrolledwindow);
473 
474  // add a textview
475  view = gtk_text_view_new ();
476 // gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
477  gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
478  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
479  gtk_text_buffer_set_text (buffer, msg, -1);
480  gtk_container_add (GTK_CONTAINER (scrolledwindow), view);
481 
482  // run the dialog
483  if (parent)
484  {
485  gtk_window_get_size (GTK_WINDOW(parent), &width, &height);
486  gtk_window_set_default_size (GTK_WINDOW(dialog), width, height);
487  }
488  gtk_widget_show_all (dialog);
489  gtk_dialog_run (GTK_DIALOG (dialog));
490  gtk_widget_destroy (dialog);
491 }
core import functions for invoice import plugin
GUI handling for bi-import plugin.
utility functions for the GnuCash UI
BillImportGui * gnc_plugin_bi_import_showGUI(void)
void gnc_bi_import_fix_bis(GtkListStore *store, guint *fixed, guint *deleted, GString *info, gchar *type)
try to fix some common errors in the csv representation of invoices
void gnc_gnome_help(const char *file_name, const char *anchor)