|
GnuCash 2.4.99
|
00001 /* 00002 * dialog-bi-import-gui.c -- Invoice Importer GUI 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of 00007 * the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, contact: 00016 * 00017 * Free Software Foundation Voice: +1-617-542-5942 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00019 * Boston, MA 02110-1301, USA gnu@gnu.org 00020 */ 00021 00030 #ifdef HAVE_CONFIG_H 00031 #include "config.h" 00032 #endif 00033 00034 #include <glib/gi18n.h> 00035 00036 #include "gnc-ui.h" 00037 #include "gnc-ui-util.h" 00038 #include "gnc-component-manager.h" 00039 #include "dialog-utils.h" 00040 #include "gnc-gui-query.h" 00041 #include "gnc-file.h" 00042 #include "gnc-gnome-utils.h" 00043 #include "dialog-bi-import.h" 00044 #include "dialog-bi-import-gui.h" 00045 00046 struct _bi_import_gui 00047 { 00048 GtkWidget *dialog; 00049 GtkWidget *tree_view; 00050 GtkWidget *entryFilename; 00051 GtkListStore *store; 00052 gint component_id; 00053 GString *regexp; 00054 QofBook *book; 00055 gchar *type; 00056 gchar *open_mode; 00057 }; 00058 00059 00060 // callback routines 00061 void gnc_bi_import_gui_ok_cb (GtkWidget *widget, gpointer data); 00062 void gnc_bi_import_gui_cancel_cb (GtkWidget *widget, gpointer data); 00063 void gnc_bi_import_gui_help_cb (GtkWidget *widget, gpointer data); 00064 void gnc_bi_import_gui_destroy_cb (GtkWidget *widget, gpointer data); 00065 static void gnc_bi_import_gui_close_handler (gpointer user_data); 00066 void gnc_bi_import_gui_buttonOpen_cb (GtkWidget *widget, gpointer data); 00067 void gnc_bi_import_gui_filenameChanged_cb (GtkWidget *widget, gpointer data); 00068 void gnc_bi_import_gui_option1_cb (GtkWidget *widget, gpointer data); 00069 void gnc_bi_import_gui_option2_cb (GtkWidget *widget, gpointer data); 00070 void gnc_bi_import_gui_option3_cb (GtkWidget *widget, gpointer data); 00071 void gnc_bi_import_gui_option4_cb (GtkWidget *widget, gpointer data); 00072 void gnc_bi_import_gui_option5_cb (GtkWidget *widget, gpointer data); 00073 void gnc_bi_import_gui_open_mode_cb (GtkWidget *widget, gpointer data); 00074 void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data); 00075 00076 // utils 00077 static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input); 00078 static void gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg); 00079 00080 00081 BillImportGui * 00082 gnc_plugin_bi_import_showGUI(void) 00083 { 00084 BillImportGui *gui; 00085 GtkBuilder *builder; 00086 GList *glist; 00087 GtkTreeIter iter; 00088 GtkCellRenderer *renderer; 00089 GtkTreeViewColumn *column; 00090 00091 // if window exists already, activate it 00092 glist = gnc_find_gui_components ("dialog-bi-import-gui", NULL, NULL); 00093 if (glist) 00094 { 00095 // window found 00096 gui = g_list_nth_data (glist, 0); 00097 g_list_free (glist); 00098 gtk_window_present (GTK_WINDOW(gui->dialog)); 00099 return gui; 00100 } 00101 00102 // create new window 00103 gui = g_new0 (BillImportGui, 1); 00104 gui->type = "BILL"; // Set default type to match gui. really shouldn't be here TODO change me 00105 gui->open_mode = "ALL"; 00106 00107 builder = gtk_builder_new(); 00108 gnc_builder_add_from_file (builder, "dialog-bi-import-gui.glade", "bi-import Dialog"); 00109 gui->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "bi-import Dialog")); 00110 gui->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview1")); 00111 gui->entryFilename = GTK_WIDGET(gtk_builder_get_object (builder, "entryFilename")); 00112 00113 gui->book = gnc_get_current_book(); 00114 00115 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>[^;]*)$"); 00116 00117 // create model and bind to view 00118 gui->store = gtk_list_store_new (N_COLUMNS, 00119 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, // invoice settings 00120 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 00121 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); // autopost settings 00122 gtk_tree_view_set_model( GTK_TREE_VIEW(gui->tree_view), GTK_TREE_MODEL(gui->store) ); 00123 #define CREATE_COLUMN(description,column_id) \ 00124 renderer = gtk_cell_renderer_text_new (); \ 00125 column = gtk_tree_view_column_new_with_attributes (description, renderer, "text", column_id, NULL); \ 00126 gtk_tree_view_column_set_resizable (column, TRUE); \ 00127 gtk_tree_view_append_column (GTK_TREE_VIEW (gui->tree_view), column); 00128 CREATE_COLUMN ("id", ID); 00129 CREATE_COLUMN ("date__opened", DATE_OPENED); 00130 CREATE_COLUMN ("owner__id", OWNER_ID); 00131 CREATE_COLUMN ("billing__id", BILLING_ID); 00132 CREATE_COLUMN ("notes", NOTES); 00133 00134 CREATE_COLUMN ("date", DATE); 00135 CREATE_COLUMN ("desc", DESC); 00136 CREATE_COLUMN ("action", ACTION); 00137 CREATE_COLUMN ("account", ACCOUNT); 00138 CREATE_COLUMN ("quantity", QUANTITY); 00139 CREATE_COLUMN ("price", PRICE); 00140 CREATE_COLUMN ("disc__type", DISC_TYPE); 00141 CREATE_COLUMN ("disc__how", DISC_HOW); 00142 CREATE_COLUMN ("discount", DISCOUNT); 00143 CREATE_COLUMN ("taxable", TAXABLE); 00144 CREATE_COLUMN ("taxincluded", TAXINCLUDED); 00145 CREATE_COLUMN ("tax__table", TAX_TABLE); 00146 00147 CREATE_COLUMN ("date__posted", DATE_POSTED); 00148 CREATE_COLUMN ("due__date", DUE_DATE); 00149 CREATE_COLUMN ("account__posted", ACCOUNT_POSTED); 00150 CREATE_COLUMN ("memo__posted", MEMO_POSTED); 00151 CREATE_COLUMN ("accu__splits", ACCU_SPLITS); 00152 00153 gui->component_id = gnc_register_gui_component ("dialog-bi-import-gui", 00154 NULL, 00155 gnc_bi_import_gui_close_handler, 00156 gui); 00157 00158 /* Setup signals */ 00159 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, gui); 00160 00161 gtk_widget_show_all ( gui->dialog ); 00162 00163 g_object_unref(G_OBJECT(builder)); 00164 00165 return gui; 00166 } 00167 00168 static gchar * 00169 gnc_plugin_bi_import_getFilename(void) 00170 { 00171 // prepare file import dialog 00172 gchar *filename; 00173 GList *filters; 00174 GtkFileFilter *filter; 00175 filters = NULL; 00176 filter = gtk_file_filter_new (); 00177 gtk_file_filter_set_name (filter, "comma separated values (*.csv)"); 00178 gtk_file_filter_add_pattern (filter, "*.csv"); 00179 filters = g_list_append( filters, filter ); 00180 filter = gtk_file_filter_new (); 00181 gtk_file_filter_set_name (filter, "text files (*.txt)"); 00182 gtk_file_filter_add_pattern (filter, "*.txt"); 00183 filters = g_list_append( filters, filter ); 00184 filename = gnc_file_dialog(_("Import Bills or Invoices from csv"), filters, NULL, GNC_FILE_DIALOG_IMPORT); 00185 00186 return filename; 00187 } 00188 00189 void 00190 gnc_bi_import_gui_ok_cb (GtkWidget *widget, gpointer data) 00191 { 00192 BillImportGui *gui = data; 00193 gchar *filename = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->entryFilename) ) ); 00194 bi_import_stats stats; 00195 bi_import_result res; 00196 guint n_fixed, n_deleted, n_invoices_created, n_invoices_updated; 00197 GString *info; 00198 00199 // import 00200 info = g_string_new(""); 00201 00202 gtk_list_store_clear (gui->store); 00203 res = gnc_bi_import_read_file (filename, gui->regexp->str, gui->store, 0, &stats); 00204 if (res == RESULT_OK) 00205 { 00206 gnc_bi_import_fix_bis (gui->store, &n_fixed, &n_deleted, info, gui->type); 00207 if (info->len > 0) 00208 gnc_info_dialog (gui->dialog, "%s", info->str); 00209 g_string_free( info, TRUE ); 00210 gnc_bi_import_create_bis (gui->store, gui->book, &n_invoices_created, &n_invoices_updated, gui->type, gui->open_mode); 00211 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); 00212 00213 if (stats.n_ignored > 0) 00214 gnc_info2_dialog (gui->dialog, _("These lines were ignored during import"), stats.ignored_lines->str); 00215 00216 g_string_free (stats.ignored_lines, TRUE); 00217 gnc_close_gui_component (gui->component_id); 00218 } 00219 else if (res == RESULT_OPEN_FAILED) 00220 { 00221 gnc_error_dialog (gui->dialog, _("The input file can not be opened.")); 00222 } 00223 else if (res == RESULT_ERROR_IN_REGEXP) 00224 { 00225 //gnc_error_dialog (gui->dialog, "The regular expression is faulty:\n\n%s", stats.err->str); 00226 } 00227 } 00228 00229 void 00230 gnc_bi_import_gui_cancel_cb (GtkWidget *widget, gpointer data) 00231 { 00232 BillImportGui *gui = data; 00233 00234 gnc_close_gui_component (gui->component_id); 00235 } 00236 00237 void 00238 gnc_bi_import_gui_help_cb (GtkWidget *widget, gpointer data) 00239 { 00240 gnc_gnome_help(HF_HELP, HL_USAGE); 00241 } 00242 00243 static void 00244 gnc_bi_import_gui_close_handler (gpointer user_data) 00245 { 00246 BillImportGui *gui = user_data; 00247 00248 gtk_widget_destroy (gui->dialog); 00249 // gui has already been freed by this point. 00250 // gui->dialog = NULL; 00251 } 00252 00253 void 00254 gnc_bi_import_gui_destroy_cb (GtkWidget *widget, gpointer data) 00255 { 00256 BillImportGui *gui = data; 00257 00258 gnc_suspend_gui_refresh (); 00259 gnc_unregister_gui_component (gui->component_id); 00260 gnc_resume_gui_refresh (); 00261 00262 g_object_unref (gui->store); 00263 g_string_free (gui->regexp, TRUE); 00264 g_free (gui); 00265 } 00266 00267 void gnc_bi_import_gui_buttonOpen_cb (GtkWidget *widget, gpointer data) 00268 { 00269 gchar *filename; 00270 BillImportGui *gui = data; 00271 00272 filename = gnc_plugin_bi_import_getFilename(); 00273 if (filename) 00274 { 00275 //printf("Setting filename"); // debug 00276 gtk_entry_set_text( GTK_ENTRY(gui->entryFilename), filename ); 00277 //printf("Set filename"); // debug 00278 g_free( filename ); 00279 } 00280 } 00281 00282 void gnc_bi_import_gui_filenameChanged_cb (GtkWidget *widget, gpointer data) 00283 { 00284 BillImportGui *gui = data; 00285 gchar *filename = g_strdup( gtk_entry_get_text( GTK_ENTRY(gui->entryFilename) ) ); 00286 00287 // generate preview 00288 gtk_list_store_clear (gui->store); 00289 gnc_bi_import_read_file (filename, gui->regexp->str, gui->store, 10, NULL); 00290 00291 g_free( filename ); 00292 } 00293 00294 void gnc_bi_import_gui_option1_cb (GtkWidget *widget, gpointer data) 00295 { 00296 BillImportGui *gui = data; 00297 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00298 return; 00299 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>[^;]*)$"); 00300 gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui); 00301 } 00302 00303 void gnc_bi_import_gui_option2_cb (GtkWidget *widget, gpointer data) 00304 { 00305 BillImportGui *gui = data; 00306 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00307 return; 00308 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>[^,]*)$"); 00309 gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui); 00310 } 00311 00312 void gnc_bi_import_gui_option3_cb (GtkWidget *widget, gpointer data) 00313 { 00314 BillImportGui *gui = data; 00315 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00316 return; 00317 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>[^\"]*)\")$"); 00318 gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui); 00319 } 00320 00321 void gnc_bi_import_gui_option4_cb (GtkWidget *widget, gpointer data) 00322 { 00323 BillImportGui *gui = data; 00324 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00325 return; 00326 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>[^\"]*)\")$"); 00327 gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui); 00328 } 00329 00330 void gnc_bi_import_gui_option5_cb (GtkWidget *widget, gpointer data) 00331 { 00332 BillImportGui *gui = data; 00333 gchar *temp; 00334 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00335 return; 00336 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); 00337 if (temp) 00338 { 00339 g_string_assign (gui->regexp, temp); 00340 g_free (temp); 00341 gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui); 00342 } 00343 } 00344 00345 void gnc_bi_import_gui_open_mode_cb (GtkWidget *widget, gpointer data) 00346 { 00347 BillImportGui *gui = data; 00348 const gchar *name; 00349 name = gtk_buildable_get_name(GTK_BUILDABLE(widget)); 00350 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00351 return; 00352 if (g_ascii_strcasecmp(name, "radiobuttonOpenAll") == 0)gui->open_mode = "ALL"; 00353 else if (g_ascii_strcasecmp(name, "radiobuttonOpenNotPosted") == 0)gui->open_mode = "NOT_POSTED"; 00354 else if (g_ascii_strcasecmp(name, "radiobuttonOpenNone") == 0)gui->open_mode = "NONE"; 00355 } 00356 00357 00358 /***************************************************************** 00359 * Set whether we are importing a bi, invoice, Customer or Vendor 00360 * ****************************************************************/ 00361 void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data) 00362 { 00363 BillImportGui *gui = data; 00364 const gchar *name; 00365 name = gtk_buildable_get_name(GTK_BUILDABLE(widget)); 00366 if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) )) 00367 return; 00368 if (g_ascii_strcasecmp(name, "radiobuttonInvoice") == 0)gui->type = "INVOICE"; 00369 else if (g_ascii_strcasecmp(name, "radiobuttonBill") == 0)gui->type = "BILL"; 00370 //printf ("TYPE set to, %s\n",gui->type); 00371 00372 } 00373 00374 00375 /********************************************************************\ 00376 * gnc_input_dialog * 00377 * simple convenience dialog to get a single value from the user * 00378 * user may choose between "Ok" and "Cancel" * 00379 * * 00380 * NOTE: This function does not return until the dialog is closed * 00381 * * 00382 * Args: parent - the parent window or NULL * 00383 * title - the title of the dialog * 00384 * msg - the message to display * 00385 * default_input - will be displayed as default input * 00386 * Return: the input (text) the user entered, if pressed "Ok" * 00387 * NULL, if pressed "Cancel" * 00388 \********************************************************************/ 00389 static gchar * 00390 gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input) 00391 { 00392 GtkWidget *dialog, *label, *content_area; 00393 gint result; 00394 GtkWidget *view; 00395 GtkTextBuffer *buffer; 00396 gchar *user_input; 00397 GtkTextIter start, end; 00398 00399 /* Create the widgets */ 00400 dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent), 00401 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 00402 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, 00403 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, 00404 NULL); 00405 #ifdef HAVE_GTK_2_14 00406 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); 00407 #else 00408 content_area = GTK_DIALOG (dialog)->vbox; 00409 #endif 00410 00411 // add a label 00412 label = gtk_label_new (msg); 00413 gtk_container_add (GTK_CONTAINER (content_area), label); 00414 00415 // add a textview 00416 view = gtk_text_view_new (); 00417 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR); 00418 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); 00419 gtk_text_buffer_set_text (buffer, default_input, -1); 00420 gtk_container_add (GTK_CONTAINER (content_area), view); 00421 00422 // run the dialog 00423 gtk_widget_show_all (dialog); 00424 result = gtk_dialog_run (GTK_DIALOG (dialog)); 00425 00426 if (result == GTK_RESPONSE_REJECT) 00427 user_input = 0; 00428 else 00429 { 00430 gtk_text_buffer_get_start_iter (buffer, &start); 00431 gtk_text_buffer_get_end_iter (buffer, &end); 00432 user_input = gtk_text_buffer_get_text (buffer, 00433 &start, &end, FALSE); 00434 } 00435 00436 gtk_widget_destroy (dialog); 00437 00438 return user_input; 00439 } 00440 00441 00442 /********************************************************************\ 00443 * gnc_info2_dialog * 00444 * displays an information dialog box (with scrollable text area) * 00445 * * 00446 * NOTE: This function does not return until the dialog is closed * 00447 * * 00448 * Args: parent - the parent window or NULL * 00449 * title - the title of the dialog * 00450 * msg - the message to display * 00451 * Return: none * 00452 \********************************************************************/ 00453 static void 00454 gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg) 00455 { 00456 GtkWidget *dialog, *scrolledwindow, *content_area; 00457 gint result; 00458 GtkWidget *view; 00459 GtkTextBuffer *buffer; 00460 gchar *user_input; 00461 GtkTextIter start, end; 00462 gint width, height; 00463 00464 /* Create the widgets */ 00465 dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent), 00466 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 00467 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, 00468 NULL); 00469 #ifdef HAVE_GTK_2_14 00470 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); 00471 #else 00472 content_area = GTK_DIALOG (dialog)->vbox; 00473 #endif 00474 00475 // add a scroll area 00476 scrolledwindow = gtk_scrolled_window_new (NULL, NULL); 00477 gtk_container_add (GTK_CONTAINER (content_area), scrolledwindow); 00478 00479 // add a textview 00480 view = gtk_text_view_new (); 00481 // gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR); 00482 gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE); 00483 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); 00484 gtk_text_buffer_set_text (buffer, msg, -1); 00485 gtk_container_add (GTK_CONTAINER (scrolledwindow), view); 00486 00487 // run the dialog 00488 if (parent) 00489 { 00490 gtk_window_get_size (GTK_WINDOW(parent), &width, &height); 00491 gtk_window_set_default_size (GTK_WINDOW(dialog), width, height); 00492 } 00493 gtk_widget_show_all (dialog); 00494 gtk_dialog_run (GTK_DIALOG (dialog)); 00495 gtk_widget_destroy (dialog); 00496 }
1.7.4