|
GnuCash 2.4.99
|
00001 /********************************************************************\ 00002 * dialog-price-editor.c -- price editor dialog * 00003 * Copyright (C) 2001 Gnumatic, Inc. * 00004 * Author: Dave Peticolas <dave@krondo.com> * 00005 * Copyright (c) 2006 David Hampton <hampton@employees.org> * 00006 * Copyright (c) 2009 Herbert Thoma <herbie@hthoma.de> * 00007 * Copyright (c) 2011 Robert Fewell * 00008 * * 00009 * This program is free software; you can redistribute it and/or * 00010 * modify it under the terms of the GNU General Public License as * 00011 * published by the Free Software Foundation; either version 2 of * 00012 * the License, or (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License* 00020 * along with this program; if not, contact: * 00021 * * 00022 * Free Software Foundation Voice: +1-617-542-5942 * 00023 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00024 * Boston, MA 02110-1301, USA gnu@gnu.org * 00025 \********************************************************************/ 00026 00027 #include "config.h" 00028 00029 #include <gtk/gtk.h> 00030 #include <glib/gi18n.h> 00031 #include <time.h> 00032 00033 #include "dialog-utils.h" 00034 #include "gnc-gtk-utils.h" 00035 #include "gnc-amount-edit.h" 00036 #include "gnc-commodity-edit.h" 00037 #include "dialog-commodity.h" 00038 #include "gnc-general-select.h" 00039 #include "gnc-component-manager.h" 00040 #include "gnc-currency-edit.h" 00041 #include "gnc-date-edit.h" 00042 #include "qof.h" 00043 #include "gnc-pricedb.h" 00044 #include "gnc-session.h" 00045 #include "gnc-ui.h" 00046 #include "gnc-ui-util.h" 00047 #include "guile-util.h" 00048 #include "engine-helpers.h" 00049 00050 00051 #define DIALOG_PRICE_EDIT_CM_CLASS "dialog-price-edit" 00052 #define GCONF_SECTION "dialogs/price_editor" 00053 #define DIALOG_PRICE_EDIT_SOURCE "user:price-editor" 00054 00055 00056 /* This static indicates the debugging module that this .o belongs to. */ 00057 static QofLogModule log_module = GNC_MOD_GUI; 00058 00059 00060 typedef struct 00061 { 00062 GtkWidget * dialog; 00063 QofSession *session; 00064 QofBook *book; 00065 GNCPriceDB *price_db; 00066 GNCPriceEditType type; 00067 00068 GtkWidget * namespace_cbe; 00069 GtkWidget * commodity_cbe; 00070 GtkWidget * currency_edit; 00071 GtkWidget * date_edit; 00072 GtkWidget * source_entry; 00073 GtkWidget * type_combobox; 00074 GtkWidget * price_edit; 00075 00076 GtkWidget * cancel_button; 00077 GtkWidget * apply_button; 00078 GtkWidget * ok_button; 00079 00080 GNCPrice *price; 00081 gboolean changed; 00082 gboolean new; 00083 00084 } PriceEditDialog; 00085 00086 00087 void pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data); 00088 void pedit_data_changed_cb (GtkWidget *w, gpointer data); 00089 void pedit_commodity_ns_changed_cb (GtkComboBoxEntry *cbe, gpointer data); 00090 void pedit_commodity_changed_cb (GtkComboBoxEntry *cbe, gpointer data); 00091 00092 00093 static void 00094 gnc_prices_set_changed (PriceEditDialog *pedit_dialog, gboolean changed) 00095 { 00096 pedit_dialog->changed = changed; 00097 00098 gtk_widget_set_sensitive (pedit_dialog->apply_button, changed); 00099 } 00100 00101 00102 static int 00103 type_string_to_index (const char *type) 00104 { 00105 if (safe_strcmp (type, "bid") == 0) 00106 return 0; 00107 00108 if (safe_strcmp (type, "ask") == 0) 00109 return 1; 00110 00111 if (safe_strcmp (type, "last") == 0) 00112 return 2; 00113 00114 if (safe_strcmp (type, "nav") == 0) 00115 return 3; 00116 00117 return 4; 00118 } 00119 00120 00121 static const char * 00122 type_index_to_string (int index) 00123 { 00124 switch (index) 00125 { 00126 case 0: 00127 return "bid"; 00128 case 1: 00129 return "ask"; 00130 case 2: 00131 return "last"; 00132 case 3: 00133 return "nav"; 00134 default: 00135 return "unknown"; 00136 } 00137 } 00138 00139 00140 static void 00141 price_to_gui (PriceEditDialog *pedit_dialog) 00142 { 00143 gnc_commodity *commodity = NULL; 00144 gnc_commodity *currency = NULL; 00145 const gchar *namespace, *fullname; 00146 const char *source; 00147 const char *type; 00148 gnc_numeric value; 00149 Timespec date; 00150 00151 if (pedit_dialog->price) 00152 { 00153 commodity = gnc_price_get_commodity (pedit_dialog->price); 00154 } 00155 00156 if (commodity) 00157 { 00158 namespace = gnc_commodity_get_namespace(commodity); 00159 fullname = gnc_commodity_get_printname(commodity); 00160 gnc_ui_update_namespace_picker(pedit_dialog->namespace_cbe, 00161 namespace, DIAG_COMM_ALL); 00162 gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbe, 00163 namespace, fullname); 00164 00165 currency = gnc_price_get_currency (pedit_dialog->price); 00166 date = gnc_price_get_time (pedit_dialog->price); 00167 source = gnc_price_get_source (pedit_dialog->price); 00168 type = gnc_price_get_typestr (pedit_dialog->price); 00169 value = gnc_price_get_value (pedit_dialog->price); 00170 } 00171 else 00172 { 00173 currency = gnc_default_currency (); 00174 date.tv_sec = time (NULL); 00175 date.tv_nsec = 0; 00176 source = DIALOG_PRICE_EDIT_SOURCE; 00177 type = ""; 00178 value = gnc_numeric_zero (); 00179 } 00180 00181 00182 if (currency) 00183 { 00184 gnc_currency_edit_set_currency 00185 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency); 00186 } 00187 00188 gnc_date_edit_set_time (GNC_DATE_EDIT (pedit_dialog->date_edit), date.tv_sec); 00189 00190 gtk_entry_set_text (GTK_ENTRY (pedit_dialog->source_entry), source); 00191 00192 gtk_combo_box_set_active (GTK_COMBO_BOX(pedit_dialog->type_combobox), 00193 type_string_to_index (type)); 00194 00195 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), value); 00196 } 00197 00198 00199 static const char * 00200 gui_to_price (PriceEditDialog *pedit_dialog) 00201 { 00202 gnc_commodity *commodity; 00203 gnc_commodity *currency; 00204 gchar *namespace, *fullname; 00205 const char *source; 00206 const char *type; 00207 gnc_numeric value; 00208 Timespec date; 00209 00210 namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe); 00211 fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe)); 00212 commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), namespace, fullname); 00213 if (!commodity) 00214 return _("You must select a Security."); 00215 00216 currency = gnc_currency_edit_get_currency 00217 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit)); 00218 if (!currency) 00219 return _("You must select a Currency."); 00220 00221 date.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (pedit_dialog->date_edit)); 00222 date.tv_nsec = 0; 00223 00224 source = gtk_entry_get_text (GTK_ENTRY (pedit_dialog->source_entry)); 00225 00226 type = type_index_to_string 00227 (gtk_combo_box_get_active (GTK_COMBO_BOX (pedit_dialog->type_combobox))); 00228 00229 if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (pedit_dialog->price_edit))) 00230 return _("You must enter a valid amount."); 00231 00232 value = gnc_amount_edit_get_amount 00233 (GNC_AMOUNT_EDIT (pedit_dialog->price_edit)); 00234 00235 if (!pedit_dialog->price) 00236 pedit_dialog->price = gnc_price_create (pedit_dialog->book); 00237 gnc_price_begin_edit (pedit_dialog->price); 00238 gnc_price_set_commodity (pedit_dialog->price, commodity); 00239 gnc_price_set_currency (pedit_dialog->price, currency); 00240 gnc_price_set_time (pedit_dialog->price, date); 00241 gnc_price_set_source (pedit_dialog->price, source); 00242 gnc_price_set_typestr (pedit_dialog->price, type); 00243 gnc_price_set_value (pedit_dialog->price, value); 00244 gnc_price_commit_edit (pedit_dialog->price); 00245 00246 g_free(namespace); 00247 g_free(fullname); 00248 00249 return NULL; 00250 } 00251 00252 00253 static void 00254 pedit_dialog_destroy_cb (GtkWidget *widget, gpointer data) 00255 { 00256 PriceEditDialog *pedit_dialog = data; 00257 00258 gnc_unregister_gui_component_by_data (DIALOG_PRICE_EDIT_CM_CLASS, 00259 pedit_dialog); 00260 00261 if (pedit_dialog->price) 00262 { 00263 gnc_price_unref (pedit_dialog->price); 00264 pedit_dialog->price = NULL; 00265 pedit_dialog->new = FALSE; 00266 } 00267 00268 g_free (pedit_dialog); 00269 } 00270 00271 00272 void 00273 pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data) 00274 { 00275 PriceEditDialog *pedit_dialog = data; 00276 GNCPrice *new_price = NULL; 00277 const char *error_str; 00278 00279 if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY)) 00280 { 00281 error_str = gui_to_price (pedit_dialog); 00282 if (error_str) 00283 { 00284 gnc_warning_dialog (pedit_dialog->dialog, "%s", error_str); 00285 return; 00286 } 00287 00288 gnc_prices_set_changed (pedit_dialog, FALSE); 00289 if (TRUE == pedit_dialog->new) 00290 { 00291 gnc_pricedb_add_price (pedit_dialog->price_db, pedit_dialog->price); 00292 } 00293 00294 gnc_gui_refresh_all (); 00295 } 00296 00297 if (response == GTK_RESPONSE_APPLY) 00298 { 00299 new_price = gnc_price_clone (pedit_dialog->price, pedit_dialog->book); 00300 pedit_dialog->new = TRUE; 00301 00302 gnc_price_unref (pedit_dialog->price); 00303 pedit_dialog->price = new_price; 00304 } 00305 else 00306 { 00307 gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog)); 00308 gtk_widget_destroy (GTK_WIDGET (pedit_dialog->dialog)); 00309 pedit_dialog_destroy_cb (NULL, pedit_dialog); 00310 } 00311 } 00312 00313 00314 void 00315 pedit_commodity_ns_changed_cb (GtkComboBoxEntry *cbe, gpointer data) 00316 { 00317 PriceEditDialog *pedit_dialog = data; 00318 gchar *namespace; 00319 00320 gnc_prices_set_changed (pedit_dialog, TRUE); 00321 00322 namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe); 00323 gnc_ui_update_commodity_picker (pedit_dialog->commodity_cbe, namespace, NULL); 00324 00325 g_free(namespace); 00326 } 00327 00328 00329 void 00330 pedit_commodity_changed_cb (GtkComboBoxEntry *cbe, gpointer data) 00331 { 00332 gnc_commodity *commodity = NULL; 00333 gnc_commodity *currency = NULL; 00334 gchar *namespace, *fullname; 00335 GList *price_list; 00336 PriceEditDialog *pedit_dialog = data; 00337 00338 gnc_prices_set_changed (pedit_dialog, TRUE); 00339 00340 namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe); 00341 fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe)); 00342 commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), namespace, fullname); 00343 00344 if (commodity) 00345 { 00346 price_list = gnc_pricedb_lookup_latest_any_currency 00347 (pedit_dialog->price_db, commodity); 00348 if (price_list) 00349 { 00350 currency = gnc_price_get_currency((GNCPrice *)price_list->data); 00351 00352 if (currency) 00353 gnc_currency_edit_set_currency 00354 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency); 00355 00356 gnc_price_list_destroy(price_list); 00357 } 00358 else 00359 { 00360 gnc_currency_edit_set_currency 00361 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), gnc_default_currency()); 00362 } 00363 } 00364 00365 g_free(namespace); 00366 g_free(fullname); 00367 } 00368 00369 00370 void 00371 pedit_data_changed_cb (GtkWidget *w, gpointer data) 00372 { 00373 PriceEditDialog *pedit_dialog = data; 00374 00375 gnc_prices_set_changed (pedit_dialog, TRUE); 00376 } 00377 00378 00379 static void 00380 gnc_price_pedit_dialog_create (GtkWidget *parent, 00381 PriceEditDialog *pedit_dialog, 00382 QofSession *session) 00383 { 00384 GtkBuilder *builder; 00385 GNCPrintAmountInfo print_info; 00386 GtkWidget *dialog; 00387 GtkWidget *entry; 00388 GtkWidget *box; 00389 GtkWidget *w; 00390 GtkWidget *label; 00391 gchar *namespace; 00392 00393 00394 builder = gtk_builder_new(); 00395 gnc_builder_add_from_file (builder, "dialog-price.glade", "liststore1"); 00396 gnc_builder_add_from_file (builder, "dialog-price.glade", "Price Dialog"); 00397 00398 pedit_dialog->session = session; 00399 pedit_dialog->book = qof_session_get_book(pedit_dialog->session); 00400 pedit_dialog->price_db = gnc_pricedb_get_db(pedit_dialog->book); 00401 00402 dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Price Dialog")); 00403 pedit_dialog->dialog = dialog; 00404 00405 /* parent */ 00406 if (parent != NULL) 00407 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); 00408 00409 w = GTK_WIDGET(gtk_builder_get_object (builder, "namespace_cbe")); 00410 pedit_dialog->namespace_cbe = w; 00411 00412 /* namespace List Store - create here as we get an error if created in builder */ 00413 { 00414 GtkListStore *store; 00415 GtkTreeIter iter; 00416 gchar string[] = "Dummy namespace Line"; 00417 00418 store = gtk_list_store_new( 1, G_TYPE_STRING ); 00419 00420 gtk_list_store_append( store, &iter ); 00421 gtk_list_store_set( store, &iter, 0, string, -1 ); 00422 00423 gtk_combo_box_set_model( GTK_COMBO_BOX( pedit_dialog->namespace_cbe ), 00424 GTK_TREE_MODEL( store ) ); 00425 g_object_unref( G_OBJECT( store ) ); 00426 gtk_combo_box_entry_set_text_column( GTK_COMBO_BOX_ENTRY( pedit_dialog->namespace_cbe ), 0 ); 00427 } 00428 00429 gtk_combo_box_remove_text(GTK_COMBO_BOX(pedit_dialog->namespace_cbe), 0); 00430 gnc_ui_update_namespace_picker(w, NULL, DIAG_COMM_ALL); 00431 gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pedit_dialog->namespace_cbe)); 00432 gtk_combo_box_set_active(GTK_COMBO_BOX(pedit_dialog->namespace_cbe), 1); 00433 00434 w = GTK_WIDGET(gtk_builder_get_object (builder, "commodity_cbe")); 00435 pedit_dialog->commodity_cbe = w; 00436 00437 /* commodity List Store - create here as we get an error if created in builder */ 00438 { 00439 GtkListStore *store; 00440 GtkTreeIter iter; 00441 gchar string[] = "Dummy commodity Line"; 00442 00443 store = gtk_list_store_new( 1, G_TYPE_STRING ); 00444 00445 gtk_list_store_append( store, &iter ); 00446 gtk_list_store_set( store, &iter, 0, string, -1 ); 00447 00448 gtk_combo_box_set_model( GTK_COMBO_BOX( pedit_dialog->commodity_cbe ), 00449 GTK_TREE_MODEL( store ) ); 00450 g_object_unref( G_OBJECT( store ) ); 00451 gtk_combo_box_entry_set_text_column( GTK_COMBO_BOX_ENTRY( pedit_dialog->commodity_cbe ), 0 ); 00452 } 00453 00454 gtk_combo_box_remove_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe), 0); 00455 gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pedit_dialog->commodity_cbe)); 00456 namespace = gnc_ui_namespace_picker_ns(pedit_dialog->namespace_cbe); 00457 gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbe, namespace, NULL); 00458 g_free(namespace); 00459 00460 box = GTK_WIDGET(gtk_builder_get_object (builder, "currency_box")); 00461 w = gnc_currency_edit_new (); 00462 gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT (w), 00463 gnc_default_currency ()); 00464 pedit_dialog->currency_edit = w; 00465 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0); 00466 gtk_widget_show (w); 00467 g_signal_connect (G_OBJECT (GTK_COMBO_BOX(w)), "changed", 00468 G_CALLBACK (pedit_data_changed_cb), pedit_dialog); 00469 label = GTK_WIDGET(gtk_builder_get_object (builder, "currency_label")); 00470 gtk_label_set_mnemonic_widget (GTK_LABEL(label), w); 00471 00472 box = GTK_WIDGET(gtk_builder_get_object (builder, "date_box")); 00473 w = gnc_date_edit_new (time (NULL), FALSE, FALSE); 00474 pedit_dialog->date_edit = w; 00475 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0); 00476 gtk_widget_show (w); 00477 g_signal_connect (G_OBJECT (w), "date_changed", 00478 G_CALLBACK (pedit_data_changed_cb), pedit_dialog); 00479 g_signal_connect (G_OBJECT (GNC_DATE_EDIT (w)->date_entry), "changed", 00480 G_CALLBACK (pedit_data_changed_cb), pedit_dialog); 00481 gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(w)->date_entry), TRUE); 00482 label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label")); 00483 gnc_date_make_mnemonic_target (GNC_DATE_EDIT(w), label); 00484 00485 00486 w = GTK_WIDGET(gtk_builder_get_object (builder, "source_entry")); 00487 pedit_dialog->source_entry = w; 00488 00489 w = GTK_WIDGET(gtk_builder_get_object (builder, "type_combobox")); 00490 pedit_dialog->type_combobox = w; 00491 00492 box = GTK_WIDGET(gtk_builder_get_object (builder, "price_box")); 00493 w = gnc_amount_edit_new (); 00494 pedit_dialog->price_edit = w; 00495 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0); 00496 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (w), TRUE); 00497 print_info = gnc_default_price_print_info (); 00498 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (w), print_info); 00499 gtk_entry_set_activates_default(GTK_ENTRY(w), TRUE); 00500 gtk_widget_show (w); 00501 label = GTK_WIDGET(gtk_builder_get_object (builder, "price_label")); 00502 gtk_label_set_mnemonic_widget (GTK_LABEL(label), w); 00503 00504 entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (w)); 00505 g_signal_connect (G_OBJECT (entry), "changed", 00506 G_CALLBACK (pedit_data_changed_cb), pedit_dialog); 00507 00508 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_cancel_button")); 00509 pedit_dialog->cancel_button = w; 00510 00511 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_apply_button")); 00512 pedit_dialog->apply_button = w; 00513 gnc_prices_set_changed (pedit_dialog, FALSE); 00514 00515 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_ok_button")); 00516 pedit_dialog->ok_button = w; 00517 00518 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pedit_dialog); 00519 00520 g_object_unref(G_OBJECT(builder)); 00521 } 00522 00523 00524 static void 00525 close_handler (gpointer user_data) 00526 { 00527 PriceEditDialog *pedit_dialog = user_data; 00528 00529 gtk_dialog_response(GTK_DIALOG(pedit_dialog->dialog), GTK_RESPONSE_CANCEL); 00530 } 00531 00532 00533 static void 00534 refresh_handler (GHashTable *changes, gpointer user_data) 00535 { 00536 // PriceEditDialog *pedit_dialog = user_data; 00537 00538 // gnc_prices_load_prices (pedit_dialog); 00539 } 00540 00541 00542 static gboolean 00543 show_handler (const char *class, gint component_id, 00544 gpointer user_data, gpointer iter_data) 00545 { 00546 PriceEditDialog *pedit_dialog = user_data; 00547 GNCPrice * price = iter_data; 00548 00549 if (!pedit_dialog || (pedit_dialog->price != price)) 00550 return(FALSE); 00551 00552 gtk_window_present (GTK_WINDOW(pedit_dialog->dialog)); 00553 return(TRUE); 00554 } 00555 00556 00557 /********************************************************************\ 00558 * gnc_price_edit_dialog * 00559 * opens up a window to edit price information * 00560 * * 00561 * Args: parent - the parent of the window to be created * 00562 * Return: nothing * 00563 \********************************************************************/ 00564 void 00565 gnc_price_edit_dialog (GtkWidget * parent, 00566 QofSession *session, 00567 GNCPrice * price, 00568 GNCPriceEditType type) 00569 { 00570 PriceEditDialog *pedit_dialog; 00571 gint component_id; 00572 00573 if ((type == GNC_PRICE_EDIT) && 00574 (gnc_forall_gui_components (DIALOG_PRICE_EDIT_CM_CLASS, 00575 show_handler, price))) 00576 return; 00577 00578 pedit_dialog = g_new0 (PriceEditDialog, 1); 00579 gnc_price_pedit_dialog_create (parent, pedit_dialog, session); 00580 gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog)); 00581 pedit_dialog->type = type; 00582 00583 switch (type) 00584 { 00585 case GNC_PRICE_NEW: 00586 if (price) 00587 { 00588 price = gnc_price_clone(price, pedit_dialog->book); 00589 // } else { 00590 // price = gnc_price_create (pedit_dialog->book); 00591 gnc_price_set_source (price, DIALOG_PRICE_EDIT_SOURCE); 00592 } 00593 00594 pedit_dialog->new = TRUE; 00595 /* New price will only have one ref, this dialog. */ 00596 break; 00597 case GNC_PRICE_EDIT: 00598 gnc_price_ref(price); /* Add ref from this dialog */ 00599 pedit_dialog->new = FALSE; 00600 break; 00601 } 00602 00603 pedit_dialog->price = price; 00604 price_to_gui(pedit_dialog); 00605 gnc_prices_set_changed (pedit_dialog, FALSE); 00606 component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS, 00607 refresh_handler, close_handler, 00608 pedit_dialog); 00609 gnc_gui_component_set_session (component_id, pedit_dialog->session); 00610 gtk_widget_grab_focus (pedit_dialog->commodity_cbe); 00611 gtk_widget_show (pedit_dialog->dialog); 00612 } 00613 00614 00615 /********************************************************************\ 00616 * gnc_price_edit_by_guid * 00617 * opens up a window to edit price information * 00618 * * 00619 * Args: parent - the parent of the window to be created * 00620 * Return: nothing * 00621 \********************************************************************/ 00622 GNCPrice * 00623 gnc_price_edit_by_guid (GtkWidget * parent, const GncGUID * guid) 00624 { 00625 GNCPrice *price; 00626 QofSession *session; 00627 00628 session = gnc_get_current_session (); 00629 price = gnc_price_lookup (guid, qof_session_get_book(session)); 00630 if (price == NULL) 00631 return(NULL); 00632 00633 gnc_price_edit_dialog(parent, session, price, GNC_PRICE_EDIT); 00634 return price; 00635 }
1.7.4