28 #include <glib/gi18n.h> 31 #include "dialog-utils.h" 33 #include "gnc-component-manager.h" 40 #include "gnc-session.h" 41 #include "gnc-warnings.h" 47 #define DIALOG_COMMODITIES_CM_CLASS "dialog-commodities" 48 #define STATE_SECTION "dialogs/edit_commodities" 49 #define GNC_PREFS_GROUP "dialogs.commodities" 50 #define GNC_PREF_INCL_ISO "include-iso" 61 GncTreeViewCommodity * commodity_tree;
62 GtkWidget * edit_button;
63 GtkWidget * remove_button;
64 gboolean show_currencies;
70 void gnc_commodities_window_destroy_cb (GtkWidget *
object,
CommoditiesDialog *cd);
73 void gnc_commodities_dialog_add_clicked (GtkWidget *widget, gpointer data);
74 void gnc_commodities_dialog_edit_clicked (GtkWidget *widget, gpointer data);
75 void gnc_commodities_dialog_remove_clicked (GtkWidget *widget, gpointer data);
76 void gnc_commodities_dialog_close_clicked (GtkWidget *widget, gpointer data);
77 void gnc_commodities_show_currencies_toggled (GtkToggleButton *toggle,
CommoditiesDialog *cd);
80 gboolean gnc_commodities_window_key_press_cb (GtkWidget *widget,
88 gnc_unregister_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
92 gtk_widget_destroy (cd->window);
99 gnc_commodities_window_delete_event_cb (GtkWidget *widget,
105 gnc_save_window_size (GNC_PREFS_GROUP,
106 GTK_WINDOW(cd->window));
111 gnc_commodities_dialog_edit_clicked (GtkWidget *widget, gpointer data)
114 gnc_commodity *commodity;
117 if (commodity == NULL)
123 gnc_gui_refresh_all ();
128 row_activated_cb (GtkTreeView *view, GtkTreePath *path,
134 g_return_if_fail(view);
136 model = gtk_tree_view_get_model(view);
137 if (gtk_tree_model_get_iter(model, &iter, path))
139 if (gtk_tree_model_iter_has_child(model, &iter))
143 if (gtk_tree_view_row_expanded(view, path))
144 gtk_tree_view_collapse_row(view, path);
146 gtk_tree_view_expand_row(view, path, FALSE);
150 gnc_commodities_dialog_edit_clicked (NULL, cd);
155 gnc_commodities_dialog_remove_clicked (GtkWidget *widget, gpointer data)
161 gnc_commodity *commodity;
163 const gchar *message, *warning;
167 if (commodity == NULL)
170 std::vector<Account*> commodity_accounts;
172 gnc_account_foreach_descendant (gnc_book_get_root_account(cd->book),
173 [commodity, &commodity_accounts](
auto acct)
175 if (commodity == xaccAccountGetCommodity (acct))
176 commodity_accounts.push_back (acct);
181 if (!commodity_accounts.empty())
183 std::string msg{_(
"This commodity is currently used by the following accounts. You may " 184 "not delete it.\n")};
186 for (
const auto acct : commodity_accounts)
189 msg.append (
"\n* ").append (full_name);
193 gnc_warning_dialog (GTK_WINDOW (cd->window),
"%s", msg.c_str());
201 message = _(
"This commodity has price quotes. Are " 202 "you sure you want to delete the selected " 203 "commodity and its price quotes?");
204 warning = GNC_PREF_WARN_PRICE_COMM_DEL_QUOTES;
208 message = _(
"Are you sure you want to delete the " 209 "selected commodity?");
210 warning = GNC_PREF_WARN_PRICE_COMM_DEL;
213 dialog = gtk_message_dialog_new (GTK_WINDOW(cd->window),
214 GTK_DIALOG_DESTROY_WITH_PARENT,
215 GTK_MESSAGE_QUESTION,
217 "%s", _(
"Delete commodity?"));
218 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
220 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
221 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
222 _(
"_Delete"), GTK_RESPONSE_OK,
224 response = gnc_dialog_run (GTK_DIALOG(dialog), warning);
225 gtk_widget_destroy (dialog);
227 if (response == GTK_RESPONSE_OK)
229 gnc_commodity_table *ct;
232 for (node = prices; node; node = node->next)
240 gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW(cd->commodity_tree)));
244 gnc_gui_refresh_all ();
248 gnc_commodities_dialog_add_clicked (GtkWidget *widget, gpointer data)
251 gnc_commodity *commodity;
252 gnc_commodity *ret_commodity;
253 const char *name_space;
266 gnc_commodities_dialog_close_clicked (GtkWidget *widget, gpointer data)
270 gnc_close_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
274 gnc_commodities_dialog_selection_changed (GtkTreeSelection *selection,
278 gnc_commodity *commodity;
282 gtk_widget_set_sensitive (cd->edit_button, commodity != NULL);
283 gtk_widget_set_sensitive (cd->remove_button, remove_ok);
287 gnc_commodities_show_currencies_toggled (GtkToggleButton *toggle,
290 cd->show_currencies = gtk_toggle_button_get_active (toggle);
295 gnc_commodities_dialog_filter_ns_func (gnc_commodity_namespace *name_space,
304 if (g_strcmp0 (name, GNC_COMMODITY_NS_TEMPLATE) == 0)
313 gboolean rv = (list != NULL);
319 gnc_commodities_dialog_filter_cm_func (gnc_commodity *commodity,
324 if (cd->show_currencies)
333 GtkWidget *scrolled_window;
336 GtkTreeSelection *selection;
338 builder = gtk_builder_new();
339 gnc_builder_add_from_file (builder,
"dialog-commodities.glade",
"securities_window");
341 cd->window = GTK_WIDGET(gtk_builder_get_object (builder,
"securities_window"));
342 cd->session = gnc_get_current_session();
347 gtk_widget_set_name (GTK_WIDGET(cd->window),
"gnc-id-commodity");
348 gnc_widget_style_context_add_class (GTK_WIDGET(cd->window),
"gnc-class-securities");
351 cd->remove_button = GTK_WIDGET(gtk_builder_get_object (builder,
"remove_button"));
352 cd->edit_button = GTK_WIDGET(gtk_builder_get_object (builder,
"edit_button"));
355 scrolled_window = GTK_WIDGET(gtk_builder_get_object (builder,
"commodity_list_window"));
357 "state-section", STATE_SECTION,
358 "show-column-menu", TRUE,
360 cd->commodity_tree = GNC_TREE_VIEW_COMMODITY(view);
361 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
362 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(cd->commodity_tree), TRUE);
364 gnc_commodities_dialog_filter_ns_func,
365 gnc_commodities_dialog_filter_cm_func,
367 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
368 g_signal_connect (G_OBJECT (selection),
"changed",
369 G_CALLBACK (gnc_commodities_dialog_selection_changed), cd);
371 g_signal_connect (G_OBJECT (cd->commodity_tree),
"row-activated",
372 G_CALLBACK (row_activated_cb), cd);
375 button = GTK_WIDGET(gtk_builder_get_object (builder,
"show_currencies_button"));
376 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), cd->show_currencies);
379 button = GTK_WIDGET(gtk_builder_get_object (builder,
"close_button"));
380 gtk_widget_grab_default (button);
381 gtk_widget_grab_focus (button);
383 g_signal_connect (cd->window,
"destroy",
384 G_CALLBACK(gnc_commodities_window_destroy_cb), cd);
386 g_signal_connect (cd->window,
"delete-event",
387 G_CALLBACK(gnc_commodities_window_delete_event_cb), cd);
389 g_signal_connect (cd->window,
"key_press_event",
390 G_CALLBACK (gnc_commodities_window_key_press_cb), cd);
392 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, cd);
393 g_object_unref (G_OBJECT(builder));
395 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(cd->window), GTK_WINDOW(parent));
399 close_handler (gpointer user_data)
403 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(cd->window));
407 gtk_widget_destroy (cd->window);
411 refresh_handler (GHashTable *changes, gpointer user_data)
415 g_return_if_fail(cd != NULL);
421 show_handler (
const char *klass, gint component_id,
422 gpointer user_data, gpointer iter_data)
428 gtk_window_present (GTK_WINDOW(cd->window));
433 gnc_commodities_window_key_press_cb (GtkWidget *widget, GdkEventKey *event,
438 if (event->keyval == GDK_KEY_Escape)
455 gnc_commodities_dialog (GtkWidget * parent)
459 if (gnc_forall_gui_components (DIALOG_COMMODITIES_CM_CLASS,
465 gnc_commodities_dialog_create (parent, cd);
467 component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS,
468 refresh_handler, close_handler,
470 gnc_gui_component_set_session (component_id, cd->session);
472 gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree));
474 gtk_widget_show (cd->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...
GtkTreeView * gnc_tree_view_commodity_new(QofBook *book, const gchar *first_property_name,...)
Create a new commodity tree view.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
void gnc_tree_view_commodity_set_filter(GncTreeViewCommodity *view, gnc_tree_view_commodity_ns_filter_func ns_func, gnc_tree_view_commodity_cm_filter_func cm_func, gpointer data, GDestroyNotify destroy)
This function attaches a filter function to the given commodity tree.
utility functions for the GnuCash UI
gnc_commodity * gnc_ui_new_commodity_modal(const char *default_namespace, GtkWidget *parent)
Ask the user to provide the information necessary to create a new commodity.
gboolean gnc_ui_edit_commodity_modal(gnc_commodity *commodity, GtkWidget *parent)
Given an existing commodity, uses the gnc_ui_build_commodity_dialog() routine to build a basic edit d...
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
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.
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
void gnc_tree_view_commodity_select_commodity(GncTreeViewCommodity *view, gnc_commodity *commodity)
Select the commodity in the associated commodity tree view.
Account public routines (C++ api)
gboolean gnc_prefs_set_bool(const gchar *group, const gchar *pref_name, gboolean value)
Store a boolean value into the preferences backend.
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
Gnome specific utility functions.
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
Remove a price from the pricedb and unref the price.
Generic api to store and retrieve preferences.
gnc_commodity * gnc_tree_view_commodity_get_selected_commodity(GncTreeViewCommodity *view)
This function returns the commodity associated with the selected item in the commodity tree view...
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
GtkTreeView implementation for gnucash commodity tree.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
Remove a commodity from the commodity table.
void gnc_tree_view_commodity_refilter(GncTreeViewCommodity *view)
This function forces the commodity tree filter to be evaluated.
"select" and "new" commodity windows
Commodity handling public routines.
void gnc_commodity_destroy(gnc_commodity *cm)
Destroy a commodity.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
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.