29 #include <glib/gi18n.h> 31 #include <gnc-quotes.hpp> 33 #include "dialog-utils.h" 36 #include "gnc-amount-edit.h" 37 #include "gnc-commodity-edit.h" 38 #include "gnc-general-select.h" 39 #include "gnc-component-manager.h" 41 #include "gnc-date-edit.h" 44 #include "gnc-gui-query.h" 46 #include "gnc-session.h" 50 #include "gnc-warnings.h" 54 #define DIALOG_PRICE_DB_CM_CLASS "dialog-price-edit-db" 55 #define STATE_SECTION "dialogs/edit_prices" 56 #define GNC_PREFS_GROUP "dialogs.pricedb-editor" 59 static QofLogModule log_module = GNC_MOD_GUI;
63 void gnc_prices_dialog_destroy_cb (GtkWidget *
object, gpointer data);
64 void gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data);
65 void gnc_prices_dialog_help_cb (GtkDialog *dialog, gpointer data);
66 void gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data);
67 void gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data);
68 void gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data);
69 void gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data);
70 void gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data);
71 static gboolean gnc_prices_dialog_key_press_cb (GtkWidget *widget,
84 GncTreeViewPrice * price_tree;
86 GtkWidget * edit_button;
87 GtkWidget * remove_button;
88 GtkWidget * add_button;
90 GtkWidget *remove_dialog;
91 GtkTreeView *remove_view;
92 GtkWidget *namespace_cbwe;
93 gchar *target_namespace_name;
99 gnc_prices_dialog_destroy_cb (GtkWidget *
object, gpointer data)
104 gnc_unregister_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
106 if (pdb_dialog->window)
108 gtk_widget_destroy (pdb_dialog->window);
109 pdb_dialog->window = NULL;
118 gnc_prices_dialog_delete_event_cb (GtkWidget *widget,
124 gnc_save_window_size (GNC_PREFS_GROUP,
125 GTK_WINDOW(pdb_dialog->window));
131 gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data)
136 gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
142 gnc_prices_dialog_help_cb (GtkDialog *dialog, gpointer data)
146 gnc_gnome_help (GTK_WINDOW (pdb_dialog->window), DF_MANUAL, DL_PRICE_DB);
151 gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data)
159 LEAVE(
"no price selected");
162 if (g_list_next(price_list))
164 g_list_free(price_list);
165 LEAVE(
"too many prices selected");
169 auto price =
static_cast<GNCPrice *
> (price_list->data);
170 gnc_price_edit_dialog (pdb_dialog->window, pdb_dialog->session,
171 price, GNC_PRICE_EDIT);
172 g_list_free (price_list);
178 remove_helper(GNCPrice *price, GNCPriceDB *pdb)
185 gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
193 LEAVE(
"no price selected");
198 auto length = g_list_length(price_list);
203 message = g_strdup_printf
205 ngettext(
"Are you sure you want to delete the selected price?",
206 "Are you sure you want to delete the %d selected prices?",
209 auto dialog = gtk_message_dialog_new (GTK_WINDOW(pdb_dialog->window),
210 GTK_DIALOG_DESTROY_WITH_PARENT,
211 GTK_MESSAGE_QUESTION,
213 "%s", _(
"Delete prices?"));
214 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
217 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
218 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
219 _(
"_Delete"), GTK_RESPONSE_YES,
221 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
222 response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_PRICE_QUOTES_DEL);
223 gtk_widget_destroy(dialog);
227 response = GTK_RESPONSE_YES;
230 if (response == GTK_RESPONSE_YES)
232 g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db);
234 g_list_free(price_list);
235 gnc_gui_refresh_all ();
241 enum GncPriceColumn {PRICED_NAMESPACE_NAME, PRICED_FULL_NAME, PRICED_COMM, PRICED_DATE, PRICED_COUNT};
244 continue_namespace_check (
const gchar *target_namespace_name,
const gchar *namespace_name)
246 if ((g_strcmp0 (target_namespace_name, GNC_COMMODITY_NS_CURRENCY) == 0) &&
247 (g_strcmp0 (namespace_name, GNC_COMMODITY_NS_CURRENCY) != 0))
250 if ((g_strcmp0 (target_namespace_name, GNC_COMMODITY_NS_NONISO_GUI) == 0) &&
251 (g_strcmp0 (namespace_name, GNC_COMMODITY_NS_CURRENCY) == 0))
254 if ((g_strcmp0 (target_namespace_name, GNC_COMMODITY_NS_NONISO_GUI) != 0) &&
255 (g_strcmp0 (target_namespace_name, GNC_COMMODITY_NS_CURRENCY) != 0) &&
256 (g_strcmp0 (target_namespace_name, namespace_name) != 0))
263 gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb,
const gchar *target_namespace_name)
266 auto model = gtk_tree_view_get_model (view);
267 const auto commodity_table = gnc_get_current_commodities ();
271 g_object_ref (G_OBJECT(model));
272 gtk_tree_view_set_model (GTK_TREE_VIEW(view),
nullptr);
274 gtk_list_store_clear (GTK_LIST_STORE(model));
276 for (
auto node_n = namespace_list; node_n; node_n = g_list_next (node_n))
278 auto tmp_namespace =
static_cast<gnc_commodity_namespace*
>(node_n->data);
281 DEBUG(
"Restricted to %s, looking at namespace %s", target_namespace_name, tmp_namespace_name_str);
282 if (continue_namespace_check (target_namespace_name, tmp_namespace_name_str))
286 for (
auto node_c = commodity_list; node_c; node_c = g_list_next (node_c))
288 auto tmp_commodity =
static_cast<gnc_commodity*
>(node_c->data);
295 auto node = g_list_last (list);
296 auto price =
static_cast<GNCPrice*
> (node->data);
297 auto price_time = gnc_price_get_time64 (price);
301 if (oldest > price_time)
305 auto num_str = g_strdup_printf (
"%d", num);
308 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
309 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
310 PRICED_NAMESPACE_NAME, tmp_namespace_gui_str,
311 PRICED_FULL_NAME, name_str,
312 PRICED_COMM, tmp_commodity,
313 PRICED_DATE, date_str,
314 PRICED_COUNT, num_str,
322 g_list_free (commodity_list);
324 g_list_free (namespace_list);
327 gtk_tree_view_set_model (GTK_TREE_VIEW(view), model);
328 g_object_unref (G_OBJECT(model));
334 gnc_prices_dialog_get_commodities (GtkTreeView *view)
336 auto model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
337 auto selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
338 auto list = gtk_tree_selection_get_selected_rows (selection, &model);
339 GList *comm_list =
nullptr;
342 for (
auto row = g_list_first (list); row; row = g_list_next (row))
344 auto path =
static_cast<GtkTreePath *
> (row->data);
346 if (gtk_tree_model_get_iter (model, &iter, path))
349 gtk_tree_model_get (model, &iter, PRICED_COMM, &comm, -1);
350 comm_list = g_list_prepend (comm_list, comm);
353 g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
355 return g_list_reverse (comm_list);
359 change_source_flag (PriceRemoveSourceFlags source, gboolean
set, gpointer data)
362 auto widget_ok = gtk_dialog_get_widget_for_response (GTK_DIALOG(pdb_dialog->remove_dialog),
364 auto widget_apply = gtk_dialog_get_widget_for_response (GTK_DIALOG(pdb_dialog->remove_dialog),
368 pdb_dialog->remove_source = pdb_dialog->remove_source | source;
370 pdb_dialog->remove_source = pdb_dialog->remove_source & (~source);
373 gboolean enable_button = (pdb_dialog->remove_source > 8 ? TRUE : FALSE);
374 gtk_widget_set_sensitive (widget_ok, enable_button);
375 gtk_widget_set_sensitive (widget_apply, enable_button);
377 DEBUG(
"Source is: %d, remove_source is %d", source, pdb_dialog->remove_source);
381 check_event_fq_cb (GtkWidget *widget, gpointer data)
384 gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
386 change_source_flag (PRICE_REMOVE_SOURCE_FQ, active, pdb_dialog);
390 check_event_user_cb (GtkWidget *widget, gpointer data)
393 gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
395 change_source_flag (PRICE_REMOVE_SOURCE_USER, active, pdb_dialog);
399 check_event_app_cb (GtkWidget *widget, gpointer data)
402 gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
404 change_source_flag (PRICE_REMOVE_SOURCE_APP, active, pdb_dialog);
408 selection_changed_cb (GtkTreeSelection *selection, gpointer data)
411 auto model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->remove_view));
412 auto rows = gtk_tree_selection_get_selected_rows (selection, &model);
415 change_source_flag (PRICE_REMOVE_SOURCE_COMM, have_rows, pdb_dialog);
416 g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free);
420 get_fiscal_end_date (
void)
424 memset (datebuff, 0,
sizeof(datebuff));
425 end = gnc_accounting_period_fiscal_end();
427 gnc_accounting_period_fiscal_end());
428 PINFO(
"Fiscal end date is %s", datebuff);
434 namespace_changed_cb (GtkComboBox *cbwe, gpointer data)
438 if (pdb_dialog->target_namespace_name)
439 g_free (pdb_dialog->target_namespace_name);
442 gnc_prices_dialog_load_view (pdb_dialog->remove_view,
443 pdb_dialog->price_db,
444 pdb_dialog->target_namespace_name);
447 static PriceRemoveKeepOptions
448 get_keep_options_value (GtkBuilder *builder)
451 return PRICE_REMOVE_KEEP_LAST_WEEKLY;
453 auto button = GTK_WIDGET(gtk_builder_get_object (builder,
"radiobutton_none"));
454 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)))
455 return PRICE_REMOVE_KEEP_NONE;
456 button = GTK_WIDGET(gtk_builder_get_object (builder,
"radiobutton_last_month"));
457 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)))
458 return PRICE_REMOVE_KEEP_LAST_MONTHLY;
459 button = GTK_WIDGET(gtk_builder_get_object (builder,
"radiobutton_last_quarter"));
460 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)))
461 return PRICE_REMOVE_KEEP_LAST_QUARTERLY;
462 button = GTK_WIDGET(gtk_builder_get_object (builder,
"radiobutton_last_period"));
463 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)))
464 return PRICE_REMOVE_KEEP_LAST_PERIOD;
465 button = GTK_WIDGET(gtk_builder_get_object (builder,
"radiobutton_scaled"));
466 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)))
467 return PRICE_REMOVE_KEEP_SCALED;
470 return PRICE_REMOVE_KEEP_LAST_WEEKLY;
474 gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
479 auto builder = gtk_builder_new();
480 gnc_builder_add_from_file (builder,
"dialog-price.glade",
"liststore3");
481 gnc_builder_add_from_file (builder,
"dialog-price.glade",
"liststore4");
482 gnc_builder_add_from_file (builder,
"dialog-price.glade",
"deletion_date_dialog");
484 pdb_dialog->remove_dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"deletion_date_dialog"));
486 auto box = GTK_WIDGET(gtk_builder_get_object (builder,
"date_hbox"));
487 auto date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
489 gtk_box_pack_start (GTK_BOX (box), date, FALSE, FALSE, 0);
490 gtk_widget_show (date);
491 gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(date)->date_entry), TRUE);
492 auto label = GTK_WIDGET(gtk_builder_get_object (builder,
"date_label"));
493 gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label);
496 pdb_dialog->namespace_cbwe = GTK_WIDGET(gtk_builder_get_object (builder,
"namespace_combo_we"));
498 gnc_cbwe_require_list_item (GTK_COMBO_BOX(pdb_dialog->namespace_cbwe));
499 gtk_combo_box_set_active (GTK_COMBO_BOX(pdb_dialog->namespace_cbwe), 1);
500 g_signal_connect (G_OBJECT(pdb_dialog->namespace_cbwe),
"changed",
501 G_CALLBACK(namespace_changed_cb), pdb_dialog);
504 pdb_dialog->remove_view = GTK_TREE_VIEW(gtk_builder_get_object (builder,
"commodty_treeview"));
505 auto selection = gtk_tree_view_get_selection (pdb_dialog->remove_view);
506 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
509 auto tree_column = gtk_tree_view_column_new();
510 gtk_tree_view_column_set_title (tree_column, _(
"Entries"));
511 gtk_tree_view_append_column (GTK_TREE_VIEW(pdb_dialog->remove_view), tree_column);
512 gtk_tree_view_column_set_alignment (tree_column, 0.5);
513 gtk_tree_view_column_set_expand (tree_column, TRUE);
514 auto cr = gtk_cell_renderer_text_new();
515 gtk_tree_view_column_pack_start (tree_column, cr, TRUE);
517 gtk_tree_view_column_set_attributes (tree_column, cr,
"text", PRICED_COUNT, NULL);
518 gtk_cell_renderer_set_alignment (cr, 0.5, 0.5);
521 pdb_dialog->target_namespace_name = g_strdup (GNC_COMMODITY_NS_NONISO_GUI);
522 gnc_prices_dialog_load_view (pdb_dialog->remove_view,
523 pdb_dialog->price_db,
524 pdb_dialog->target_namespace_name);
526 g_signal_connect (selection,
"changed", G_CALLBACK(selection_changed_cb), pdb_dialog);
528 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pdb_dialog);
530 gtk_window_set_transient_for (GTK_WINDOW (pdb_dialog->remove_dialog), GTK_WINDOW (pdb_dialog->window));
532 pdb_dialog->remove_source = PRICE_REMOVE_SOURCE_FQ;
533 change_source_flag (PRICE_REMOVE_SOURCE_FQ, TRUE, pdb_dialog);
535 auto button = GTK_WIDGET(gtk_builder_get_object (builder,
"checkbutton_fq"));
536 g_signal_connect (button,
"toggled", G_CALLBACK (check_event_fq_cb), pdb_dialog);
537 button = GTK_WIDGET(gtk_builder_get_object (builder,
"checkbutton_user"));
538 g_signal_connect (button,
"toggled", G_CALLBACK (check_event_user_cb), pdb_dialog);
539 button = GTK_WIDGET(gtk_builder_get_object (builder,
"checkbutton_app"));
540 g_signal_connect (button,
"toggled", G_CALLBACK (check_event_app_cb), pdb_dialog);
544 while (!leave && (response = gtk_dialog_run (GTK_DIALOG(pdb_dialog->remove_dialog))))
546 if ((response == GTK_RESPONSE_CLOSE) || (response == GTK_RESPONSE_DELETE_EVENT))
549 if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY))
551 const char *fmt = _(
"Are you sure you want to delete these prices?");
552 auto comm_list = gnc_prices_dialog_get_commodities (pdb_dialog->remove_view);
553 bool delete_entries =
false;
556 if ((g_list_length (comm_list) != 0) &&
557 (gnc_verify_dialog (GTK_WINDOW(pdb_dialog->remove_dialog), FALSE, fmt, NULL)))
560 GDate fiscal_end_date = get_fiscal_end_date ();
561 PriceRemoveKeepOptions keep = get_keep_options_value (builder);
562 delete_entries =
true;
565 auto model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->price_tree));
566 g_object_ref (G_OBJECT(model));
567 gtk_tree_view_set_model (GTK_TREE_VIEW(pdb_dialog->price_tree),
nullptr);
569 DEBUG(
"deleting prices for keep option %d", keep);
570 last = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
572 if (keep != PRICE_REMOVE_KEEP_SCALED)
574 &fiscal_end_date, last,
575 static_cast<PriceRemoveSourceFlags> (pdb_dialog->remove_source),
580 g_date_subtract_months (&tmp_date, 6);
584 &fiscal_end_date, tmp,
585 static_cast<PriceRemoveSourceFlags> (pdb_dialog->remove_source),
586 PRICE_REMOVE_KEEP_LAST_WEEKLY);
588 g_date_subtract_months (&tmp_date, 6);
592 &fiscal_end_date, tmp,
593 static_cast<PriceRemoveSourceFlags> (pdb_dialog->remove_source),
594 PRICE_REMOVE_KEEP_LAST_MONTHLY);
597 gtk_tree_view_set_model (GTK_TREE_VIEW(pdb_dialog->price_tree), model);
598 g_object_unref (G_OBJECT(model));
600 g_list_free (comm_list);
602 if (response == GTK_RESPONSE_OK)
610 gnc_prices_dialog_load_view (pdb_dialog->remove_view,
611 pdb_dialog->price_db,
612 pdb_dialog->target_namespace_name);
616 gnc_gui_refresh_all ();
618 if (pdb_dialog->target_namespace_name)
619 g_free (pdb_dialog->target_namespace_name);
621 gtk_widget_destroy (pdb_dialog->remove_dialog);
622 g_object_unref (G_OBJECT(builder));
628 gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data)
631 GNCPrice *price =
nullptr;
632 gboolean unref_price = FALSE;
640 price =
static_cast<GNCPrice *
> (price_list->data);
641 g_list_free (price_list);
647 auto comm = GNC_COMMODITY (comm_list->data);
652 price = GNC_PRICE (latest_price->data);
661 gnc_price_set_commodity (price, comm);
666 g_list_free (comm_list);
668 gnc_price_edit_dialog (pdb_dialog->window, pdb_dialog->session,
669 price, GNC_PRICE_NEW);
678 gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
685 gnc_set_busy_cursor (NULL, TRUE);
686 quotes.
fetch (pdb_dialog->book);
687 gnc_unset_busy_cursor (NULL);
689 gnc_warning_dialog(GTK_WINDOW(pdb_dialog->window),
"%s",
690 quotes.report_failures().c_str());
694 gnc_unset_busy_cursor(
nullptr);
695 PERR(
"Price retrieval failed: %s", err.what());
696 gnc_error_dialog(GTK_WINDOW(pdb_dialog->window), _(
"Price retrieval failed: %s"), err.what());
701 gnc_gui_refresh_all ();
708 gnc_prices_dialog_selection_changed (GtkTreeSelection *treeselection,
715 auto length = g_list_length (price_list);
716 g_list_free (price_list);
718 auto model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->price_tree));
719 auto rows = gtk_tree_selection_get_selected_rows (treeselection, &model);
722 if (g_list_length (rows) > length)
725 g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free);
727 gtk_widget_set_sensitive (pdb_dialog->edit_button,
729 gtk_widget_set_sensitive (pdb_dialog->remove_button,
731 gtk_widget_set_sensitive (pdb_dialog->add_button,
733 LEAVE(
"%d prices selected", length);
738 gnc_price_dialog_filter_ns_func (gnc_commodity_namespace *name_space,
745 if (g_strcmp0 (name, GNC_COMMODITY_NS_TEMPLATE) == 0)
751 for (
auto item = cm_list; !rv && item; item = g_list_next (item))
754 auto comm =
static_cast<gnc_commodity *
> (item->data);
759 g_list_free (cm_list);
765 gnc_price_dialog_filter_cm_func (gnc_commodity *commodity,
776 row_activated_cb (GtkTreeView *view, GtkTreePath *path,
777 GtkTreeViewColumn *column, gpointer data)
782 g_return_if_fail(view);
784 model = gtk_tree_view_get_model(view);
785 if (gtk_tree_model_get_iter(model, &iter, path))
787 if (gtk_tree_model_iter_has_child(model, &iter))
791 if (gtk_tree_view_row_expanded(view, path))
792 gtk_tree_view_collapse_row(view, path);
794 gtk_tree_view_expand_row(view, path, FALSE);
798 gnc_prices_dialog_edit_clicked(GTK_WIDGET(view), data);
804 gnc_prices_dialog_create (GtkWidget * parent,
PricesDialog *pdb_dialog)
806 GtkWidget *window, *scrolled_window;
809 GtkTreeSelection *selection;
812 builder = gtk_builder_new();
813 gnc_builder_add_from_file (builder,
"dialog-price.glade",
"prices_window");
815 window = GTK_WIDGET(gtk_builder_get_object (builder,
"prices_window"));
816 pdb_dialog->window = window;
819 gtk_widget_set_name (GTK_WIDGET(window),
"gnc-id-price-edit");
820 gnc_widget_style_context_add_class (GTK_WIDGET(window),
"gnc-class-securities");
822 pdb_dialog->session = gnc_get_current_session();
826 g_signal_connect (pdb_dialog->window,
"delete-event",
827 G_CALLBACK(gnc_prices_dialog_delete_event_cb), pdb_dialog);
829 g_signal_connect (pdb_dialog->window,
"key_press_event",
830 G_CALLBACK (gnc_prices_dialog_key_press_cb), pdb_dialog);
833 scrolled_window = GTK_WIDGET(gtk_builder_get_object (builder,
"price_list_window"));
835 "state-section", STATE_SECTION,
836 "show-column-menu", TRUE,
838 pdb_dialog->price_tree = GNC_TREE_VIEW_PRICE(view);
839 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
840 gnc_tree_view_price_set_filter (pdb_dialog->price_tree,
841 gnc_price_dialog_filter_ns_func,
842 gnc_price_dialog_filter_cm_func,
846 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
847 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
848 g_signal_connect (G_OBJECT (selection),
"changed",
849 G_CALLBACK (gnc_prices_dialog_selection_changed), pdb_dialog);
851 g_signal_connect (G_OBJECT (view),
"row-activated",
852 G_CALLBACK (row_activated_cb), pdb_dialog);
858 button = GTK_WIDGET(gtk_builder_get_object (builder,
"edit_button"));
859 pdb_dialog->edit_button = button;
861 button = GTK_WIDGET(gtk_builder_get_object (builder,
"remove_button"));
862 pdb_dialog->remove_button = button;
864 button = GTK_WIDGET(gtk_builder_get_object (builder,
"add_button"));
865 pdb_dialog->add_button = button;
869 button = GTK_WIDGET(gtk_builder_get_object (builder,
"get_quotes_button"));
870 gtk_widget_set_sensitive(button, FALSE);
873 button = GTK_WIDGET(gtk_builder_get_object (builder,
"close_button"));
874 gtk_widget_grab_default (button);
875 gtk_widget_grab_focus (button);
879 g_signal_connect (pdb_dialog->window,
"destroy",
880 G_CALLBACK(gnc_prices_dialog_destroy_cb), pdb_dialog);
882 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pdb_dialog);
883 g_object_unref(G_OBJECT(builder));
885 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(pdb_dialog->window), GTK_WINDOW (parent));
891 close_handler (gpointer user_data)
893 auto pdb_dialog =
static_cast<PricesDialog *
> (user_data);
896 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(pdb_dialog->window));
897 gtk_widget_destroy (GTK_WIDGET (pdb_dialog->window));
903 refresh_handler (GHashTable *changes, gpointer user_data)
911 show_handler (
const char *klass, gint component_id,
912 gpointer user_data, gpointer iter_data)
914 auto pdb_dialog =
static_cast<PricesDialog *
> (user_data);
919 LEAVE(
"no data structure");
923 gtk_window_present (GTK_WINDOW(pdb_dialog->window));
930 gnc_prices_dialog_key_press_cb (GtkWidget *widget, GdkEventKey *event,
935 if (event->keyval == GDK_KEY_Escape)
937 close_handler (pdb_dialog);
953 gnc_prices_dialog (GtkWidget * parent)
959 if (gnc_forall_gui_components (DIALOG_PRICE_DB_CM_CLASS, show_handler, NULL))
961 LEAVE(
"existing dialog raised");
967 gnc_prices_dialog_create (parent, pdb_dialog);
969 component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS,
970 refresh_handler, close_handler,
972 gnc_gui_component_set_session (component_id, pdb_dialog->session);
974 gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree));
976 gtk_widget_show (pdb_dialog->window);
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...
GNCPrice * gnc_price_create(QofBook *book)
gnc_price_create - returns a newly allocated and initialized price with a reference count of 1...
a simple price database for gnucash
const char * gnc_commodity_namespace_get_gui_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure in a form suitable to present to the user...
utility functions for the GnuCash UI
#define PINFO(format, args...)
Print an informational note.
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
Given a combo box, return the currently selected namespaces.
int gnc_pricedb_num_prices(GNCPriceDB *db, const gnc_commodity *c)
Get the number of prices, in any currency, for a given commodity.
void gnc_price_unref(GNCPrice *p)
gnc_price_unref - indicate you're finished with a price (i.e.
#define DEBUG(format, args...)
Print a debugging message.
bool had_failures() noexcept
Report if there were quotes requested but not retrieved.
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, GList *comm_list, GDate *fiscal_end_date, time64 cutoff, PriceRemoveSourceFlags source, PriceRemoveKeepOptions keep)
Remove and unref prices older than a certain time.
GDate time64_to_gdate(time64 t)
Returns the GDate in which the time64 occurs.
GList * gnc_tree_view_price_get_selected_commodities(GncTreeViewPrice *view)
This function returns a list of commodities associated with the selected rows that are not prices but...
GList * gnc_tree_view_price_get_selected_prices(GncTreeViewPrice *view)
This function returns a list of the prices associated with the selected items in the price tree view...
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
Return a list of all commodity data structures in the specified namespace.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
Dialog box should allow selection of anything.
GtkTreeView implementation for gnucash price tree.
Currency selection widget.
char * qof_print_date(time64 secs)
Convenience; calls through to qof_print_date_dmy_buff().
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
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...
General utilities for dealing with accounting periods.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
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.
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
All type declarations for the whole Gnucash engine.
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
Remove a price from the pricedb and unref the price.
gboolean gnc_pricedb_has_prices(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
Report whether the pricedb contains prices for one commodity in another.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
Return a list of all commodities in the commodity table that are in the given namespace.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
void fetch(QofBook *book)
Fetch quotes for all commodities in our db that have a quote source set.
#define LEAVE(format, args...)
Print a function exit debugging message.
time64 gnc_time(time64 *tbuf)
get the current time
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
GtkTreeView * gnc_tree_view_price_new(QofBook *book, const gchar *first_property_name,...)
Create a new price tree view.
gint gnc_list_length_cmp(const GList *list, size_t len)
Scans the GList elements the minimum number of iterations required to test it against a specified siz...
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table *table)
Return a list of all namespace data structures in the commodity table.
void gnc_ui_update_namespace_picker(GtkWidget *cbwe, const gchar *sel, dialog_commodity_mode mode)
Given a combo box, fill in the known commodity namespaces and then select one.
"select" and "new" commodity windows
void gnc_price_ref(GNCPrice *p)
gnc_price_ref - indicate your need for a given price to stick around (i.e.
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
Convenience: calls through to qof_print_date_dmy_buff().
gboolean gnc_quote_source_fq_installed(void)
This function indicates whether or not the Finance::Quote module is installed on a user's computer...
PriceList * gnc_pricedb_get_prices(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
Return all the prices for a given commodity in another.