GnuCash c935c2f+
Loading...
Searching...
No Matches
dialog-price-editor.c
1/********************************************************************\
2 * dialog-price-editor.c -- price editor dialog *
3 * Copyright (C) 2001 Gnumatic, Inc. *
4 * Author: Dave Peticolas <dave@krondo.com> *
5 * Copyright (c) 2006 David Hampton <hampton@employees.org> *
6 * Copyright (c) 2009 Herbert Thoma <herbie@hthoma.de> *
7 * Copyright (c) 2011 Robert Fewell *
8 * *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public License as *
11 * published by the Free Software Foundation; either version 2 of *
12 * the License, or (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License*
20 * along with this program; if not, contact: *
21 * *
22 * Free Software Foundation Voice: +1-617-542-5942 *
23 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
24 * Boston, MA 02110-1301, USA gnu@gnu.org *
25\********************************************************************/
26
27#include <config.h>
28
29#include <gtk/gtk.h>
30#include <glib/gi18n.h>
31#include <time.h>
32
33#include "dialog-utils.h"
34#include "gnc-gtk-utils.h"
35#include "gnc-amount-edit.h"
36#include "gnc-commodity-edit.h"
37#include "dialog-commodity.h"
38#include "gnc-general-select.h"
39#include "gnc-component-manager.h"
40#include "gnc-currency-edit.h"
41#include "gnc-date-edit.h"
42#include "qof.h"
43#include "gnc-pricedb.h"
44#include "gnc-session.h"
45#include "gnc-ui.h"
46#include "gnc-ui-util.h"
47#include "gnc-warnings.h"
48#include "engine-helpers.h"
49
50
51#define DIALOG_PRICE_EDIT_CM_CLASS "dialog-price-edit"
52#define GNC_PREFS_GROUP "dialogs.price-editor"
53
54/* This static indicates the debugging module that this .o belongs to. */
55G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_GUI;
56
57
58typedef struct
59{
60 GtkWidget * dialog;
61 QofSession *session;
62 QofBook *book;
63 GNCPriceDB *price_db;
64 GNCPriceEditType type;
65
66 GtkWidget * namespace_cbwe;
67 GtkWidget * commodity_cbwe;
68 GtkWidget * currency_edit;
69 GtkWidget * date_edit;
70 GtkWidget * source_entry;
71 GtkWidget * type_combobox;
72 GtkWidget * price_edit;
73
74 GtkWidget * help_button;
75 GtkWidget * cancel_button;
76 GtkWidget * apply_button;
77 GtkWidget * ok_button;
78
79 GNCPrice *price;
80 gboolean changed;
81 gboolean is_new;
82
84
85void pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data);
86void pedit_data_changed_cb (GtkWidget *w, gpointer data);
87void pedit_commodity_ns_changed_cb (GtkComboBox *cbwe, gpointer data);
88void pedit_commodity_changed_cb (GtkComboBox *cbwe, gpointer data);
89
90
91static void
92gnc_prices_set_changed (PriceEditDialog *pedit_dialog, gboolean changed)
93{
94 pedit_dialog->changed = changed;
95
96 gtk_widget_set_sensitive (pedit_dialog->apply_button, changed);
97 gtk_widget_set_sensitive (pedit_dialog->ok_button, changed);
98}
99
100
101static int
102type_string_to_index (const char *type)
103{
104 if (g_strcmp0 (type, "bid") == 0)
105 return 0;
106
107 if (g_strcmp0 (type, "ask") == 0)
108 return 1;
109
110 if (g_strcmp0 (type, "last") == 0)
111 return 2;
112
113 if (g_strcmp0 (type, "nav") == 0)
114 return 3;
115
116 return 4;
117}
118
119
120static const char *
121type_index_to_string (int index)
122{
123 switch (index)
124 {
125 case 0:
126 return "bid";
127 case 1:
128 return "ask";
129 case 2:
130 return "last";
131 case 3:
132 return "nav";
133 default:
134 return "unknown";
135 }
136}
137
138
139static void
140price_to_gui (PriceEditDialog *pedit_dialog)
141{
142 GNCPrintAmountInfo print_info;
143 gnc_commodity *commodity = NULL;
144 gnc_commodity *currency = NULL;
145 const gchar *name_space, *fullname;
146 const char *source;
147 const char *type;
148 gnc_numeric value;
149 time64 date;
150
151 if (pedit_dialog->price)
152 {
153 commodity = gnc_price_get_commodity (pedit_dialog->price);
154 }
155
156 if (commodity)
157 {
158 name_space = gnc_commodity_get_namespace(commodity);
159 fullname = gnc_commodity_get_printname(commodity);
160 gnc_ui_update_namespace_picker(pedit_dialog->namespace_cbwe,
161 name_space, DIAG_COMM_ALL);
162 gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbwe,
163 name_space, fullname);
164
165 currency = gnc_price_get_currency (pedit_dialog->price);
166 date = gnc_price_get_time64 (pedit_dialog->price);
167 source = gnc_price_get_source_string (pedit_dialog->price);
168 type = gnc_price_get_typestr (pedit_dialog->price);
169 value = gnc_price_get_value (pedit_dialog->price);
170 }
171 else
172 {
173 currency = gnc_default_currency ();
174 date = gnc_time (NULL);
175 source = "user:price-editor"; //Sync with source_names in gnc-pricedb.c
176 type = "";
177 value = gnc_numeric_zero ();
178 }
179
180
181 if (currency)
182 {
184 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
185 }
186
187 gnc_date_edit_set_time (GNC_DATE_EDIT (pedit_dialog->date_edit), date);
188
189 gtk_entry_set_text (GTK_ENTRY (pedit_dialog->source_entry), source);
190
191 gtk_combo_box_set_active (GTK_COMBO_BOX(pedit_dialog->type_combobox),
192 type_string_to_index (type));
193
194 print_info = gnc_commodity_print_info (currency, FALSE);
195 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), print_info);
196 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), 0);
197
198 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), value);
199}
200
201
202static gboolean
203pedit_dialog_replace_found_price (PriceEditDialog *pedit_dialog,
204 const gnc_commodity *commodity,
205 const gnc_commodity *currency, time64 t)
206{
207 gboolean price_found = FALSE;
208 GNCPrice *test_price = gnc_pricedb_lookup_day_t64 (pedit_dialog->price_db,
209 commodity, currency, t);
210
211 if (test_price)
212 {
213 if (pedit_dialog->is_new) // new price
214 price_found = TRUE;
215 else // edit price
216 {
217 if (!gnc_price_equal (test_price, pedit_dialog->price))
218 price_found = TRUE;
219 }
220 gnc_price_unref (test_price);
221 }
222
223 if (price_found)
224 {
225 gint response;
226 GtkWidget *dialog;
227 gchar *message = _("Are you sure you want to replace the existing price?");
228
229 dialog = gtk_message_dialog_new (GTK_WINDOW (pedit_dialog->dialog),
230 GTK_DIALOG_DESTROY_WITH_PARENT,
231 GTK_MESSAGE_QUESTION,
232 GTK_BUTTONS_NONE,
233 "%s", _("Replace price?"));
234 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
235 "%s", message);
236
237 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
238 _("_Cancel"), GTK_RESPONSE_CANCEL,
239 _("_Replace"), GTK_RESPONSE_YES,
240 (gchar *)NULL);
241 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_YES);
242 response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_PRICE_QUOTES_REPLACE);
243 gtk_widget_destroy (dialog);
244
245 if (response == GTK_RESPONSE_CANCEL)
246 return FALSE;
247 }
248 return TRUE;
249}
250
251
252static const char *
253gui_to_price (PriceEditDialog *pedit_dialog)
254{
255 GNCPrintAmountInfo print_info;
256 gnc_commodity *commodity;
257 gnc_commodity *currency;
258 gchar *name_space;
259 const gchar *fullname;
260 const char *source;
261 const char *type;
262 gnc_numeric value;
263 time64 date;
264
265 name_space = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbwe);
266 fullname = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(pedit_dialog->commodity_cbwe)))));
267
268 commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), name_space, fullname);
269 if (!commodity)
270 {
271 g_free (name_space);
272 return _("You must select a Security.");
273 }
274
276 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit));
277 if (!currency)
278 {
279 g_free (name_space);
280 return _("You must select a Currency.");
281 }
282
283 date = gnc_date_edit_get_date (GNC_DATE_EDIT (pedit_dialog->date_edit));
284
285 source = gtk_entry_get_text (GTK_ENTRY (pedit_dialog->source_entry));
286
287 type = type_index_to_string
288 (gtk_combo_box_get_active (GTK_COMBO_BOX (pedit_dialog->type_combobox)));
289
290 print_info = gnc_commodity_print_info (currency, FALSE);
291 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), print_info);
292 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), 0);
293
294 if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), NULL))
295 {
296 g_free (name_space);
297 return _("You must enter a valid amount.");
298 }
299
300 value = gnc_amount_edit_get_amount
301 (GNC_AMOUNT_EDIT (pedit_dialog->price_edit));
302
303 // test for existing price on same day
304 if (pedit_dialog_replace_found_price (pedit_dialog, commodity, currency, date))
305 {
306 if (!pedit_dialog->price)
307 pedit_dialog->price = gnc_price_create (pedit_dialog->book);
308 gnc_price_begin_edit (pedit_dialog->price);
309 gnc_price_set_commodity (pedit_dialog->price, commodity);
310 gnc_price_set_currency (pedit_dialog->price, currency);
311 gnc_price_set_time64 (pedit_dialog->price, date);
312 gnc_price_set_source_string (pedit_dialog->price, source);
313 gnc_price_set_typestr (pedit_dialog->price, type);
314 gnc_price_set_value (pedit_dialog->price, value);
315 gnc_price_commit_edit (pedit_dialog->price);
316 g_free (name_space);
317 return NULL;
318 }
319 else
320 {
321 g_free (name_space);
322 return "CANCEL";
323 }
324}
325
326
327static void
328pedit_dialog_destroy_cb (GtkWidget *widget, gpointer data)
329{
330 PriceEditDialog *pedit_dialog = data;
331
332 gnc_unregister_gui_component_by_data (DIALOG_PRICE_EDIT_CM_CLASS,
333 pedit_dialog);
334
335 if (pedit_dialog->price)
336 {
337 gnc_price_unref (pedit_dialog->price);
338 pedit_dialog->price = NULL;
339 pedit_dialog->is_new = FALSE;
340 }
341
342 g_free (pedit_dialog);
343}
344
345
346void
347pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
348{
349 PriceEditDialog *pedit_dialog = data;
350 GNCPrice *new_price = NULL;
351 const char *error_str;
352
353 if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY))
354 {
355 error_str = gui_to_price (pedit_dialog);
356 if (g_strcmp0 (error_str, "CANCEL") == 0) // cancel from replace price dialog
357 {
358 // set the ok and cancel buttons sensitivity
359 gnc_prices_set_changed (pedit_dialog, FALSE);
360 return;
361 }
362 else if (error_str) // error string from gui
363 {
364 gnc_warning_dialog (GTK_WINDOW (pedit_dialog->dialog), "%s", error_str);
365 return;
366 }
367 // set the ok and cancel buttons sensitivity
368 gnc_prices_set_changed (pedit_dialog, FALSE);
369
370 if (pedit_dialog->is_new)
371 gnc_pricedb_add_price (pedit_dialog->price_db, pedit_dialog->price);
372
373 gnc_gui_refresh_all ();
374 }
375
376 if (response == GTK_RESPONSE_APPLY)
377 {
378 new_price = gnc_price_clone (pedit_dialog->price, pedit_dialog->book);
379 pedit_dialog->is_new = TRUE;
380
381 gnc_price_unref (pedit_dialog->price);
382 pedit_dialog->price = new_price;
383 }
384 else if (response == GTK_RESPONSE_HELP)
385 {
386 gnc_gnome_help (GTK_WINDOW (pedit_dialog->dialog), DF_MANUAL, DL_PRICE_EDIT);
387 }
388 else
389 {
390 gnc_save_window_size(GNC_PREFS_GROUP, GTK_WINDOW(pedit_dialog->dialog));
391 gtk_widget_destroy (GTK_WIDGET (pedit_dialog->dialog));
392 pedit_dialog_destroy_cb (NULL, pedit_dialog);
393 }
394}
395
396
397void
398pedit_commodity_ns_changed_cb (GtkComboBox *cbwe, gpointer data)
399{
400 PriceEditDialog *pedit_dialog = data;
401 gchar *name_space;
402
403 gnc_prices_set_changed (pedit_dialog, TRUE);
404
405 name_space = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbwe);
406 gnc_ui_update_commodity_picker (pedit_dialog->commodity_cbwe, name_space, NULL);
407
408 g_free(name_space);
409}
410
411
412void
413pedit_commodity_changed_cb (GtkComboBox *cbwe, gpointer data)
414{
415 gnc_commodity *commodity = NULL;
416 gnc_commodity *currency = NULL;
417 gchar *name_space;
418 const gchar *fullname;
419 GList *price_list;
420 PriceEditDialog *pedit_dialog = data;
421
422 gnc_prices_set_changed (pedit_dialog, TRUE);
423
424 name_space = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbwe);
425 fullname = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(pedit_dialog->commodity_cbwe)))));
426
427 commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), name_space, fullname);
428
429 if (commodity)
430 {
432 (pedit_dialog->price_db, commodity);
433 if (price_list)
434 {
435 GNCPrice * price = (GNCPrice*)price_list->data;
436 if (gnc_commodity_equiv(commodity, gnc_price_get_currency(price)))
437 currency = gnc_price_get_commodity((GNCPrice *)price);
438 else
439 currency = gnc_price_get_currency((GNCPrice *)price);
440
441 if (currency)
443 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
444
445 gnc_price_list_destroy(price_list);
446 }
447 else
448 {
450 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), gnc_default_currency());
451 }
452 }
453
454 g_free(name_space);
455}
456
457
458void
459pedit_data_changed_cb (GtkWidget *w, gpointer data)
460{
461 PriceEditDialog *pedit_dialog = data;
462
463 gnc_prices_set_changed (pedit_dialog, TRUE);
464}
465
466
467static void
468gnc_price_pedit_dialog_create (GtkWidget *parent,
469 PriceEditDialog *pedit_dialog,
470 QofSession *session)
471{
472 GtkBuilder *builder;
473 GNCPrintAmountInfo print_info;
474 GtkWidget *dialog;
475 GtkWidget *entry;
476 GtkWidget *box;
477 GtkWidget *w;
478 GtkWidget *label;
479 gchar *name_space;
480
481 builder = gtk_builder_new();
482 gnc_builder_add_from_file (builder, "dialog-price.glade", "liststore1");
483 gnc_builder_add_from_file (builder, "dialog-price.glade", "liststore2");
484 gnc_builder_add_from_file (builder, "dialog-price.glade", "liststore3");
485 gnc_builder_add_from_file (builder, "dialog-price.glade", "price_dialog");
486
487 pedit_dialog->session = session;
488 pedit_dialog->book = qof_session_get_book(pedit_dialog->session);
489 pedit_dialog->price_db = gnc_pricedb_get_db(pedit_dialog->book);
490
491 dialog = GTK_WIDGET(gtk_builder_get_object (builder, "price_dialog"));
492 pedit_dialog->dialog = dialog;
493
494 /* parent */
495 if (parent != NULL)
496 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
497
498 w = GTK_WIDGET(gtk_builder_get_object (builder, "namespace_cbwe"));
499 pedit_dialog->namespace_cbwe = w;
500
501 gnc_ui_update_namespace_picker(w, NULL, DIAG_COMM_ALL);
502 gnc_cbwe_require_list_item(GTK_COMBO_BOX(pedit_dialog->namespace_cbwe));
503 gtk_combo_box_set_active(GTK_COMBO_BOX(pedit_dialog->namespace_cbwe), 1);
504
505 w = GTK_WIDGET(gtk_builder_get_object (builder, "commodity_cbwe"));
506 pedit_dialog->commodity_cbwe = w;
507
508 gnc_cbwe_require_list_item(GTK_COMBO_BOX(pedit_dialog->commodity_cbwe));
509 name_space = gnc_ui_namespace_picker_ns(pedit_dialog->namespace_cbwe);
510 gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbwe, name_space, NULL);
511 g_free(name_space);
512
513 box = GTK_WIDGET(gtk_builder_get_object (builder, "currency_box"));
515 gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT (w),
517 pedit_dialog->currency_edit = w;
518 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
519 gtk_widget_show (w);
520 g_signal_connect (G_OBJECT (GTK_COMBO_BOX(w)), "changed",
521 G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
522 label = GTK_WIDGET(gtk_builder_get_object (builder, "currency_label"));
523 gtk_label_set_mnemonic_widget (GTK_LABEL(label), w);
524
525 box = GTK_WIDGET(gtk_builder_get_object (builder, "date_box"));
526 w = gnc_date_edit_new (time (NULL), FALSE, FALSE);
527 pedit_dialog->date_edit = w;
528 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
529 gtk_widget_show (w);
530 g_signal_connect (G_OBJECT (w), "date_changed",
531 G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
532 g_signal_connect (G_OBJECT (GNC_DATE_EDIT (w)->date_entry), "changed",
533 G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
534 gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(w)->date_entry), TRUE);
535 label = GTK_WIDGET(gtk_builder_get_object (builder, "date__label"));
536 gnc_date_make_mnemonic_target (GNC_DATE_EDIT(w), label);
537
538 w = GTK_WIDGET(gtk_builder_get_object (builder, "source_entry"));
539 pedit_dialog->source_entry = w;
540
541 w = GTK_WIDGET(gtk_builder_get_object (builder, "type_combobox"));
542 pedit_dialog->type_combobox = w;
543
544 box = GTK_WIDGET(gtk_builder_get_object (builder, "price_box"));
545 w = gnc_amount_edit_new ();
546 pedit_dialog->price_edit = w;
547 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
548 entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (w));
549 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (w), TRUE);
550 print_info = gnc_default_price_print_info (gnc_currency_edit_get_currency
551 (GNC_CURRENCY_EDIT (pedit_dialog->currency_edit)));
552 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (w), print_info);
553 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
554 gtk_widget_show (w);
555 label = GTK_WIDGET(gtk_builder_get_object (builder, "price_label"));
556 gnc_amount_edit_make_mnemonic_target (GNC_AMOUNT_EDIT(w), label);
557
558 g_signal_connect (G_OBJECT (w), "changed",
559 G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
560
561 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_help_button"));
562 pedit_dialog->help_button = w;
563
564 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_cancel_button"));
565 pedit_dialog->cancel_button = w;
566
567 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_apply_button"));
568 pedit_dialog->apply_button = w;
569
570 w = GTK_WIDGET(gtk_builder_get_object (builder, "pd_ok_button"));
571 pedit_dialog->ok_button = w;
572
573 gnc_prices_set_changed (pedit_dialog, FALSE);
574
575 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pedit_dialog);
576
577 g_object_unref(G_OBJECT(builder));
578}
579
580
581static void
582close_handler (gpointer user_data)
583{
584 PriceEditDialog *pedit_dialog = user_data;
585
586 gtk_dialog_response(GTK_DIALOG(pedit_dialog->dialog), GTK_RESPONSE_CANCEL);
587}
588
589
590static void
591refresh_handler (GHashTable *changes, gpointer user_data)
592{
593 // PriceEditDialog *pedit_dialog = user_data;
594
595 // gnc_prices_load_prices (pedit_dialog);
596}
597
598
599static gboolean
600show_handler (const char *klass, gint component_id,
601 gpointer user_data, gpointer iter_data)
602{
603 PriceEditDialog *pedit_dialog = user_data;
604 GNCPrice * price = iter_data;
605
606 if (!pedit_dialog || (pedit_dialog->price != price))
607 return(FALSE);
608
609 gtk_window_present (GTK_WINDOW(pedit_dialog->dialog));
610 return(TRUE);
611}
612
613
614/********************************************************************\
615 * gnc_price_edit_dialog *
616 * opens up a window to edit price information *
617 * *
618 * Args: parent - the parent of the window to be created *
619 * Return: nothing *
620\********************************************************************/
621void
622gnc_price_edit_dialog (GtkWidget * parent,
623 QofSession *session,
624 GNCPrice * price,
625 GNCPriceEditType type)
626{
627 PriceEditDialog *pedit_dialog;
628 gint component_id;
629
630 if ((type == GNC_PRICE_EDIT) &&
631 (gnc_forall_gui_components (DIALOG_PRICE_EDIT_CM_CLASS,
632 show_handler, price)))
633 return;
634
635 pedit_dialog = g_new0 (PriceEditDialog, 1);
636 gnc_price_pedit_dialog_create (parent, pedit_dialog, session);
637 gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(pedit_dialog->dialog), GTK_WINDOW(parent));
638 pedit_dialog->type = type;
639
640 switch (type)
641 {
642 case GNC_PRICE_NEW:
643 if (price)
644 {
645 price = gnc_price_clone(price, pedit_dialog->book);
646
647 gnc_price_set_source (price, PRICE_SOURCE_EDIT_DLG);
648 gnc_price_set_time64 (price, gnc_time (NULL));
649 gnc_price_set_value (price, gnc_numeric_zero ());
650 }
651
652 pedit_dialog->is_new = TRUE;
653 /* New price will only have one ref, this dialog. */
654 break;
655 case GNC_PRICE_EDIT:
656 gnc_price_ref(price); /* Add ref from this dialog */
657 pedit_dialog->is_new = FALSE;
658 break;
659 }
660
661 pedit_dialog->price = price;
662 price_to_gui(pedit_dialog);
663 gnc_prices_set_changed (pedit_dialog, FALSE);
664 component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS,
665 refresh_handler, close_handler,
666 pedit_dialog);
667 gnc_gui_component_set_session (component_id, pedit_dialog->session);
668 gtk_widget_grab_focus (pedit_dialog->commodity_cbwe);
669 gtk_widget_show (pedit_dialog->dialog);
670}
671
672
673/********************************************************************\
674 * gnc_price_edit_by_guid *
675 * opens up a window to edit price information *
676 * *
677 * Args: parent - the parent of the window to be created *
678 * Return: nothing *
679\********************************************************************/
680GNCPrice *
681gnc_price_edit_by_guid (GtkWidget * parent, const GncGUID * guid)
682{
683 GNCPrice *price;
684 QofSession *session = gnc_get_current_session();
685 QofBook* book = qof_session_get_book (session);
686
687 if (!book)
688 return (NULL);
689 price = gnc_price_lookup (guid, book);
690 if (price == NULL)
691 return(NULL);
692
693 gnc_price_edit_dialog(parent, session, price, GNC_PRICE_EDIT);
694 return price;
695}
"select" and "new" commodity windows
Currency selection widget.
gtk helper routines.
a simple price database for gnucash
utility functions for the GnuCash UI
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
time64 gnc_time(time64 *tbuf)
get the current time
Definition gnc-date.cpp:262
void gnc_currency_edit_set_currency(GNCCurrencyEdit *gce, const gnc_commodity *currency)
Set the widget to display a certain currency name.
GtkWidget * gnc_currency_edit_new(void)
Create a new GNCCurrencyEdit widget which can be used to provide an easy way to enter ISO currency co...
gnc_commodity * gnc_currency_edit_get_currency(GNCCurrencyEdit *gce)
Retrieve the displayed currency of the widget.
void gnc_ui_update_commodity_picker(GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
Given a combo box, fill in all the known commodities for the specified namespace, and then select one...
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
Given a combo box, return the currently selected namespaces.
@ DIAG_COMM_ALL
Dialog box should allow selection of anything.
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome's yelp for linux, and open to a given link within a gi...
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
PriceList * gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db, const gnc_commodity *commodity)
Find the most recent price between a commodity and all other commodities.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t)
Return the price between the two commodities on the indicated day.
gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
Add a price to the pricedb.
void gnc_price_list_destroy(PriceList *prices)
gnc_price_list_destroy - destroy the given price list, calling gnc_price_unref on all the prices incl...
void gnc_price_ref(GNCPrice *p)
gnc_price_ref - indicate your need for a given price to stick around (i.e.
GNCPrice * gnc_price_clone(GNCPrice *p, QofBook *book)
gnc_price_clone - returns a newly allocated price that's a content-wise duplicate of the given price,...
GNCPrice * gnc_price_create(QofBook *book)
gnc_price_create - returns a newly allocated and initialized price with a reference count of 1.
void gnc_price_unref(GNCPrice *p)
gnc_price_unref - indicate you're finished with a price (i.e.
The type used to store guids in C.
Definition guid.h:75
QofBook reference.
Definition qofbook-p.hpp:47