GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-customer-import-gui.c
1 /*
2  * dialog-customer-import-gui.c --
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 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include <glib/gi18n.h>
34 
35 #include "gnc-ui.h"
36 #include "gnc-ui-util.h"
37 #include "gnc-component-manager.h"
38 #include "dialog-utils.h"
39 #include "gnc-gui-query.h"
40 #include "gnc-file.h"
41 #include "dialog-customer-import.h"
43 
45 {
46  GtkWidget *dialog;
47  GtkWidget *tree_view;
48  GtkWidget *entryFilename;
49  GtkListStore *store;
50  gint component_id;
51  GString *regexp;
52  gchar *type;
53  QofBook *book;
54 };
55 
56 // callback routines
57 void gnc_customer_import_gui_ok_cb (GtkWidget *widget, gpointer data);
58 void gnc_customer_import_gui_cancel_cb (GtkWidget *widget, gpointer data);
59 void gnc_customer_import_gui_help_cb (GtkWidget *widget, gpointer data);
60 void gnc_customer_import_gui_destroy_cb (GtkWidget *widget, gpointer data);
61 static void gnc_customer_import_gui_close_handler (gpointer user_data);
62 void gnc_customer_import_gui_buttonOpen_cb (GtkWidget *widget, gpointer data);
63 void gnc_customer_import_gui_filenameChanged_cb (GtkWidget *widget, gpointer data);
64 void gnc_customer_import_gui_option1_cb (GtkWidget *widget, gpointer data);
65 void gnc_customer_import_gui_option2_cb (GtkWidget *widget, gpointer data);
66 void gnc_customer_import_gui_option3_cb (GtkWidget *widget, gpointer data);
67 void gnc_customer_import_gui_option4_cb (GtkWidget *widget, gpointer data);
68 void gnc_customer_import_gui_option5_cb (GtkWidget *widget, gpointer data);
69 void gnc_customer_import_gui_type_cb (GtkWidget *widget, gpointer data);
70 
71 // utils
72 static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
73 static void gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg);
74 
75 
76 CustomerImportGui *
78 {
79  CustomerImportGui *gui;
80  //gktbuilderXML *xml;
81  GtkBuilder *builder;
82  GList *glist;
83  GtkCellRenderer *renderer;
84  GtkTreeViewColumn *column;
85 
86  // if window exists already, activate it
87  glist = gnc_find_gui_components ("dialog-customer_import_gui", NULL, NULL);
88  if (glist)
89  {
90  // window found
91  gui = g_list_nth_data (glist, 0);
92  g_list_free (glist);
93  gtk_window_present (GTK_WINDOW(gui->dialog));
94  return gui;
95  }
96 
97  // create new window
98  gui = g_new0 (CustomerImportGui, 1);
99 
100  builder = gtk_builder_new();
101  gnc_builder_add_from_file (builder, "dialog-customer-import-gui.glade", "customer_import Dialog");
102  gui->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "customer_import Dialog"));
103  gui->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview1"));
104  gui->entryFilename = GTK_WIDGET(gtk_builder_get_object (builder, "entryFilename"));
105  gui->type = "CUSTOMER"; // Set a default type to import
106 
107  gui->regexp = g_string_new ( "^(?<id>[^;]+);(?<company>[^;]*);(?<name>[^;]+);(?<addr1>[^;]+);?(?<addr2>[^;]*);?(?<addr3>[^;]*);?(?<addr4>[^;]*);?(?<phone>[^;]*);?(?<fax>[^;]*);?(?<email>[^;]*);?(?<shipname>[^;]*);?(?<shipaddr1>[^;]*);?(?<shipaddr2>[^;]*);?(?<shipaddr3>[^;]*);?(?<shipaddr4>[^;]*);?(?<shipphone>[^;]*);?(?<shipfax>[^;]*);?(?<shipemail>[^;]*)");
108  gui->book = gnc_get_current_book();
109 
110  // create model and bind to view
111  gui->store = gtk_list_store_new (CI_N_COLUMNS,
112  G_TYPE_STRING, G_TYPE_STRING,
113  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
114  G_TYPE_STRING,
115  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
116  gtk_tree_view_set_model( GTK_TREE_VIEW(gui->tree_view), GTK_TREE_MODEL(gui->store) );
117 #define CREATE_COLUMN(description,column_id) \
118  renderer = gtk_cell_renderer_text_new (); \
119  column = gtk_tree_view_column_new_with_attributes (description, renderer, "text", column_id, NULL); \
120  gtk_tree_view_column_set_resizable (column, TRUE); \
121  gtk_tree_view_append_column (GTK_TREE_VIEW (gui->tree_view), column);
122  CREATE_COLUMN ("id", CI_ID);
123  CREATE_COLUMN ("company", CI_COMPANY);
124  CREATE_COLUMN ("name", CI_NAME);
125  CREATE_COLUMN ("addr1", CI_ADDR1);
126  CREATE_COLUMN ("addr2", CI_ADDR2);
127  CREATE_COLUMN ("addr3", CI_ADDR3);
128  CREATE_COLUMN ("addr4", CI_ADDR4);
129  CREATE_COLUMN ("phone", CI_PHONE);
130  CREATE_COLUMN ("fax", CI_FAX);
131  CREATE_COLUMN ("email", CI_EMAIL);
132  CREATE_COLUMN ("notes", CI_NOTES);
133  CREATE_COLUMN ("shipname", CI_SHIPNAME);
134  CREATE_COLUMN ("shipaddr1", CI_SHIPADDR1);
135  CREATE_COLUMN ("shipaddr2", CI_SHIPADDR2);
136  CREATE_COLUMN ("shipaddr3", CI_SHIPADDR3);
137  CREATE_COLUMN ("shipaddr4", CI_SHIPADDR4);
138  CREATE_COLUMN ("shipphone", CI_SHIPPHONE);
139  CREATE_COLUMN ("shipfax", CI_SHIPFAX);
140  CREATE_COLUMN ("shipemail", CI_SHIPEMAIL);
141 
142  gui->component_id = gnc_register_gui_component ("dialog-customer_import_gui",
143  NULL,
144  gnc_customer_import_gui_close_handler,
145  gui);
146 
147  /* Setup signals */
148  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, gui);
149  gtk_widget_show_all ( gui->dialog );
150  return gui;
151 }
152 
153 static gchar *
154 gnc_plugin_customer_import_getFilename(void)
155 {
156  // prepare file import dialog
157  gchar *filename;
158  GList *filters;
159  GtkFileFilter *filter;
160  filters = NULL;
161  filter = gtk_file_filter_new ();
162  gtk_file_filter_set_name (filter, "comma separated values (*.csv)");
163  gtk_file_filter_add_pattern (filter, "*.csv");
164  filters = g_list_append( filters, filter );
165  filter = gtk_file_filter_new ();
166  gtk_file_filter_set_name (filter, "text files (*.txt)");
167  gtk_file_filter_add_pattern (filter, "*.txt");
168  filters = g_list_append( filters, filter );
169  filename = gnc_file_dialog(_("Import Customers from csv"), filters, NULL, GNC_FILE_DIALOG_IMPORT);
170 
171  return filename;
172 }
173 
174 void
175 gnc_customer_import_gui_ok_cb (GtkWidget *widget, gpointer data)
176 {
177  CustomerImportGui *gui = data;
178  gchar *filename = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->entryFilename) ) );
179  customer_import_stats stats;
180  customer_import_result res;
181  guint n_fixed, n_deleted, n_customers_created, n_customers_updated;
182  gchar *cv_type_text;
183 
184  // import
185  if (g_ascii_strcasecmp (gui->type, "CUSTOMER") == 0) cv_type_text = _("customers");
186  else cv_type_text = _("vendors");
187 
188  gtk_list_store_clear (gui->store);
189  res = gnc_customer_import_read_file (filename, gui->regexp->str, gui->store, 0, &stats);
190  if (res == CI_RESULT_OK)
191  {
192  gnc_customer_import_fix_customers (gui->store, &n_fixed, &n_deleted, gui->type);
193  gnc_customer_import_create_customers (gui->store, gui->book, &n_customers_created, &n_customers_updated, gui->type);
194  gnc_info_dialog (gui->dialog, _("Import results:\n%i lines were ignored\n%i lines imported:\n %u %s fixed\n %u %s ignored (not fixable)\n\n %u %s created\n %u %s updated (based on id)"), \
195  stats.n_ignored, stats.n_imported, n_fixed, cv_type_text, n_deleted, cv_type_text, n_customers_created, cv_type_text, n_customers_updated, cv_type_text);
196 
197  if (stats.n_ignored > 0)
198  gnc_info2_dialog (gui->dialog, _("These lines were ignored during import"), stats.ignored_lines->str);
199 
200  g_string_free (stats.ignored_lines, TRUE);
201  gnc_close_gui_component (gui->component_id);
202  }
203  else if (res == CI_RESULT_OPEN_FAILED)
204  {
205  gnc_error_dialog (gui->dialog, _("The input file can not be opened."));
206  }
207  else if (res == CI_RESULT_ERROR_IN_REGEXP)
208  {
209  //gnc_error_dialog (gui->dialog, "The regular expression is faulty:\n\n%s", stats.err->str);
210  }
211 }
212 
213 void
214 gnc_customer_import_gui_cancel_cb (GtkWidget *widget, gpointer data)
215 {
216  CustomerImportGui *gui = data;
217 
218  gnc_close_gui_component (gui->component_id);
219 }
220 
221 void
222 gnc_customer_import_gui_help_cb (GtkWidget *widget, gpointer data)
223 {
224  gnc_gnome_help(HF_HELP, HL_USAGE_BSNSS);
225 }
226 
227 static void
228 gnc_customer_import_gui_close_handler (gpointer user_data)
229 {
230  CustomerImportGui *gui = user_data;
231 
232  gtk_widget_destroy (gui->dialog);
233  // gui has already been freed by this point.
234  // gui->dialog = NULL;
235 }
236 
237 void
238 gnc_customer_import_gui_destroy_cb (GtkWidget *widget, gpointer data)
239 {
240  CustomerImportGui *gui = data;
241 
242  gnc_suspend_gui_refresh ();
243  gnc_unregister_gui_component (gui->component_id);
244  gnc_resume_gui_refresh ();
245 
246  g_object_unref (gui->store);
247  g_string_free (gui->regexp, TRUE);
248  g_free (gui);
249 }
250 
251 void gnc_customer_import_gui_buttonOpen_cb (GtkWidget *widget, gpointer data)
252 {
253  gchar *filename;
254  CustomerImportGui *gui = data;
255 
256  filename = gnc_plugin_customer_import_getFilename();
257  if (filename)
258  {
259  gtk_entry_set_text( GTK_ENTRY(gui->entryFilename), filename );
260  g_free( filename );
261  }
262 }
263 
264 void gnc_customer_import_gui_filenameChanged_cb (GtkWidget *widget, gpointer data)
265 {
266  CustomerImportGui *gui = data;
267  gchar *filename = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->entryFilename) ) );
268 
269  // generate preview
270  gtk_list_store_clear (gui->store);
271  gnc_customer_import_read_file (filename, gui->regexp->str, gui->store, 10, NULL);
272 
273  g_free( filename );
274 }
275 // Semicolon separated.
276 void gnc_customer_import_gui_option1_cb (GtkWidget *widget, gpointer data)
277 {
278  CustomerImportGui *gui = data;
279  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
280  return;
281  g_string_assign (gui->regexp, "^(?<id>[^;]*);(?<company>[^;]*);(?<name>[^;]*);(?<addr1>[^;]*);?(?<addr2>[^;]*);?(?<addr3>[^;]*);?(?<addr4>[^;]*);?(?<phone>[^;]*);?(?<fax>[^;]*);?(?<email>[^;]*);?(?<notes>[^;]*);?(?<shipname>[^;]*);?(?<shipaddr1>[^;]*);?(?<shipaddr2>[^;]*);?(?<shipaddr3>[^;]*);?(?<shipaddr4>[^;]*);?(?<shipphone>[^;]*);(?<shipfax>[^;]*);(?<shipemail>[^;]*)"); //;(?<account_posted>[^;]*);(?<memo_posted>[^;]*);(?<accu_splits>[^;]*)$");
282  gnc_customer_import_gui_filenameChanged_cb (gui->entryFilename, gui);
283 }
284 // Comma separated.
285 void gnc_customer_import_gui_option2_cb (GtkWidget *widget, gpointer data)
286 {
287  CustomerImportGui *gui = data;
288  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
289  return;
290  g_string_assign (gui->regexp, "^(?<id>[^,]*),(?<company>[^,]*),(?<name>[^,]*),(?<addr1>[^,]*),?(?<addr2>[^,]*),?(?<addr3>[^,]*),?(?<addr4>[^,]*),?(?<phone>[^,]*),?(?<fax>[^,]*),?(?<email>[^,]*),?(?<notes>[^,]*),?(?<shipname>[^,]*),?(?<shipaddr1>[^,]*),?(?<shipaddr2>[^,]*),?(?<shipaddr3>[^,]*),?(?<shipaddr4>[^,]*),?(?<shipphone>[^,]*),(?<shipfax>[^,]*),(?<shipemail>[^,]*)"); //,(?<account_posted>[^,]*),(?<memo_posted>[^,]*),(?<accu_splits>[^,]*)$");
291  gnc_customer_import_gui_filenameChanged_cb (gui->entryFilename, gui);
292 }
293 // Semicolon separated with quoted strings.
294 void gnc_customer_import_gui_option3_cb (GtkWidget *widget, gpointer data)
295 {
296  CustomerImportGui *gui = data;
297  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
298  return;
299  //g_string_assign (gui->regexp, "^((?<id>[^\";]*)|\"(?<id>[^\"]*)\");((?<company>[^\";]*)|\"(?<company>[^\"]*)\");((?<name>[^\";]*)|\"(?<name>[^\"]*)\");((?<addr1>[^\";]*)|\"(?<addr1>[^\"]*)\");((?<addr2>[^\";]*)|\"(?<addr2>[^\"]*)\");((?<addr3>[^\";]*)|\"(?<addr3>[^\"]*)\");((?<addr4>[^\";]*)|\"(?<addr4>[^\"]*)\");((?<phone>[^\";]*)|\"(?<phone>[^\"]*)\");((?<fax>[^\";]*)|\"(?<fax>[^\"]*)\");((?<email>[^\";]*)|\"(?<email>[^\"]*)\");((?<notes>[^\";]*)|\"(?<notes>[^\"]*)\");((?<shipname>[^\";]*)|\"(?<shipname>[^\"]*)\");((?<shipaddr1>[^\";]*)|\"(?<shipaddr1>[^\"]*)\");((?<shipaddr2>[^\";]*)|\"(?<shipaddr2>[^\"]*)\");((?<shipaddr3>[^\";]*)|\"(?<shipaddr3>[^\"]*)\");((?<shipaddr4>[^\";]*)|\"(?<shipaddr4>[^\"]*)\");((?<shipphone>[^\";]*)|\"(?<shipphone>[^\"]*)\");((?<shipfax>[^\";]*)|\"(?<shipfax>[^\"]*)\");((?<shipmail>[^\";]*)|\"(?<shipemail>[^\"]*)\")$");
300  g_string_assign (gui->regexp, "^((?<id>[^\";]*)|\"(?<id>[^\"]*)\");((?<company>[^\";]*)|\"(?<company>[^\"]*)\");((?<name>[^\";]*)|\"(?<name>[^\"]*)\");((?<addr1>[^\";]*)|\"(?<addr1>[^\"]*)\");((?<addr2>[^\";]*)|\"(?<addr2>[^\"]*)\");((?<addr3>[^\";]*)|\"(?<addr3>[^\"]*)\");((?<addr4>[^\";]*)|\"(?<addr4>[^\"]*)\");((?<phone>[^\";]*)|\"(?<phone>[^\"]*)\");((?<fax>[^\";]*)|\"(?<fax>[^\"]*)\");((?<email>[^\";]*)|\"(?<email>[^\"]*)\");((?<notes>[^\";]*)|\"(?<notes>[^\"]*)\");((?<shipname>[^\";]*)|\"(?<shipname>[^\"]*)\");((?<shipaddr1>[^\";]*)|\"(?<shipaddr1>[^\"]*)\");((?<shipaddr2>[^\";]*)|\"(?<shipaddr2>[^\"]*)\");((?<shipaddr3>[^\";]*)|\"(?<shipaddr3>[^\"]*)\");((?<shipaddr4>[^\";]*)|\"(?<shipaddr4>[^\"]*)\");((?<shipphone>[^\";]*)|\"(?<shipphone>[^\"]*)\");((?<shipfax>[^\";]*)|\"(?<shipfax>[^\"]*)\");((?<shipemail>[^\";]*)|\"(?<shipemail>[^\"]*)\")$");
301  gnc_customer_import_gui_filenameChanged_cb (gui->entryFilename, gui);
302 }
303 // Comma separated with quoted strings.
304 void gnc_customer_import_gui_option4_cb (GtkWidget *widget, gpointer data)
305 {
306  CustomerImportGui *gui = data;
307  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
308  return;
309  //g_string_assign (gui->regexp, "^(?<id>[^,]*),(?<company>[^,]*),(?<name>[^,]*),(?<addr1>[^,]*),?(?<addr2>[^,]*),?(?<addr3>[^,]*),?(?<addr4>[^,]*),?(?<phone>[^,]*),?(?<fax>[^,]*),?(?<email>[^,]*),?(?<notes>[^,]*),?(?<shipname>[^,]*),?(?<shipaddr1>[^,]*),?(?<shipaddr2>[^,]*),?(?<shipaddr3>[^,]*),?(?<shipaddr4>[^,]*),?(?<shipphone>[^,]*),(?<shipfax>[^,]*),(?<shipemail>[^,]*)"); //,(?<account_posted>[^,]*),(?<memo_posted>[^,]*),(?<accu_splits>[^,]*)$");
310  g_string_assign (gui->regexp, "^((?<id>[^\",]*)|\"(?<id>[^\"]*)\"),((?<company>[^\",]*)|\"(?<company>[^\"]*)\"),((?<name>[^\",]*)|\"(?<name>[^\"]*)\"),((?<addr1>[^\",]*)|\"(?<addr1>[^\"]*)\"),((?<addr2>[^\",]*)|\"(?<addr2>[^\"]*)\"),((?<addr3>[^\",]*)|\"(?<addr3>[^\"]*)\"),((?<addr4>[^\",]*)|\"(?<addr4>[^\"]*)\"),((?<phone>[^\",]*)|\"(?<phone>[^\"]*)\"),((?<fax>[^\",]*)|\"(?<fax>[^\"]*)\"),((?<email>[^\",]*)|\"(?<email>[^\"]*)\"),((?<notes>[^\",]*)|\"(?<notes>[^\"]*)\"),((?<shipname>[^\",]*)|\"(?<shipname>[^\"]*)\"),((?<shipaddr1>[^\",]*)|\"(?<shipaddr1>[^\"]*)\"),((?<shipaddr2>[^\",]*)|\"(?<shipaddr2>[^\"]*)\"),((?<shipaddr3>[^\",]*)|\"(?<shipaddr3>[^\"]*)\"),((?<shipaddr4>[^\",]*)|\"(?<shipaddr4>[^\"]*)\"),((?<shipphone>[^\",]*)|\"(?<shipphone>[^\"]*)\"),((?<shipfax>[^\",]*)|\"(?<shipfax>[^\"]*)\"),((?<shipemail>[^\",]*)|\"(?<shipemail>[^\"]*)\")$");
311  gnc_customer_import_gui_filenameChanged_cb (gui->entryFilename, gui);
312 }
313 void gnc_customer_import_gui_option5_cb (GtkWidget *widget, gpointer data)
314 {
315  CustomerImportGui *gui = data;
316  gchar *temp;
317  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
318  return;
319  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);
320  if (temp)
321  {
322  g_string_assign (gui->regexp, temp);
323  g_free (temp);
324  gnc_customer_import_gui_filenameChanged_cb (gui->entryFilename, gui);
325  }
326 }
327 
328 
329 
330 
331 /*****************************************************************
332  * Set whether we are importing a Customer or Vendor
333  * ****************************************************************/
334 void gnc_customer_import_gui_type_cb (GtkWidget *widget, gpointer data)
335 {
336  CustomerImportGui *gui = data;
337  const gchar *name;
338  if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
339  return;
340  name = gtk_buildable_get_name(GTK_BUILDABLE(widget));
341  if (name)
342  {
343  if (g_ascii_strcasecmp(name, "radiobutton_customer") == 0)gui->type = "CUSTOMER";
344  else if (g_ascii_strcasecmp(name, "radiobutton_vendor") == 0)gui->type = "VENDOR";
345  }
346  //printf ("TYPE set to, %s\n",gui->type); // DEBUG
347 
348 }
349 
350 
351 
352 /********************************************************************\
353  * gnc_input_dialog *
354  * simple convenience dialog to get a single value from the user *
355  * user may choose between "Ok" and "Cancel" *
356  * *
357  * NOTE: This function does not return until the dialog is closed *
358  * *
359  * Args: parent - the parent window or NULL *
360  * title - the title of the dialog *
361  * msg - the message to display *
362  * default_input - will be displayed as default input *
363  * Return: the input (text) the user entered, if pressed "Ok" *
364  * NULL, if pressed "Cancel" *
365 \********************************************************************/
366 static gchar *
367 gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
368 {
369  GtkWidget *dialog, *label, *content_area;
370  gint result;
371  GtkWidget *view;
372  GtkTextBuffer *buffer;
373  gchar *user_input;
374  GtkTextIter start, end;
375 
376  /* Create the widgets */
377  dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
378  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
379  GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
380  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
381  NULL);
382 #ifdef HAVE_GTK_2_14
383  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
384 #else
385  content_area = GTK_DIALOG (dialog)->vbox;
386 #endif
387 
388  // add a label
389  label = gtk_label_new (msg);
390  gtk_container_add (GTK_CONTAINER (content_area), label);
391 
392  // add a textview
393  view = gtk_text_view_new ();
394  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
395  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
396  gtk_text_buffer_set_text (buffer, default_input, -1);
397  gtk_container_add (GTK_CONTAINER (content_area), view);
398 
399  // run the dialog
400  gtk_widget_show_all (dialog);
401  result = gtk_dialog_run (GTK_DIALOG (dialog));
402 
403  if (result == GTK_RESPONSE_REJECT)
404  user_input = 0;
405  else
406  {
407  gtk_text_buffer_get_start_iter (buffer, &start);
408  gtk_text_buffer_get_end_iter (buffer, &end);
409  user_input = gtk_text_buffer_get_text (buffer,
410  &start, &end, FALSE);
411  }
412 
413  gtk_widget_destroy (dialog);
414 
415  return user_input;
416 }
417 
418 /********************************************************************\
419  * gnc_info2_dialog *
420  * displays an information dialog box (with scrollable text area) *
421  * *
422  * NOTE: This function does not return until the dialog is closed *
423  * *
424  * Args: parent - the parent window or NULL *
425  * title - the title of the dialog *
426  * msg - the message to display *
427  * Return: none *
428 \********************************************************************/
429 static void
430 gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg)
431 {
432  GtkWidget *dialog, *scrolledwindow, *content_area;
433  GtkWidget *view;
434  GtkTextBuffer *buffer;
435  gint width, height;
436 
437  /* Create the widgets */
438  dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
439  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
440  GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
441  NULL);
442 #ifdef HAVE_GTK_2_14
443  content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
444 #else
445  content_area = GTK_DIALOG (dialog)->vbox;
446 #endif
447 
448  // add a scroll area
449  scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
450  gtk_container_add (GTK_CONTAINER (content_area), scrolledwindow);
451 
452  // add a textview
453  view = gtk_text_view_new ();
454 // gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
455  gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
456  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
457  gtk_text_buffer_set_text (buffer, msg, -1);
458  gtk_container_add (GTK_CONTAINER (scrolledwindow), view);
459 
460  // run the dialog
461  if (parent)
462  {
463  gtk_window_get_size (GTK_WINDOW(parent), &width, &height);
464  gtk_window_set_default_size (GTK_WINDOW(dialog), width, height);
465  }
466  gtk_widget_show_all (dialog);
467  gtk_dialog_run (GTK_DIALOG (dialog));
468  gtk_widget_destroy (dialog);
469 }
core import functions for customer import plugin
utility functions for the GnuCash UI
GUI handling for customer import plugin.
void gnc_gnome_help(const char *file_name, const char *anchor)
CustomerImportGui * gnc_plugin_customer_import_showGUI(void)