28 #include <glib/gi18n.h>
31 #include "dialog-utils.h"
33 #include "gnc-component-manager.h"
40 #include "gnc-session.h"
41 #include "gnome-utils/gnc-warnings.h"
44 #define DIALOG_COMMODITIES_CM_CLASS "dialog-commodities"
45 #define STATE_SECTION "dialogs/edit_commodities"
46 #define GNC_PREFS_GROUP "dialogs.commodities"
47 #define GNC_PREF_INCL_ISO "include-iso"
59 GtkWidget * edit_button;
60 GtkWidget * remove_button;
61 gboolean show_currencies;
67 void gnc_commodities_window_destroy_cb (GtkObject *
object,
CommoditiesDialog *cd);
68 void gnc_commodities_dialog_response (GtkDialog *dialog, gint response,
CommoditiesDialog *cd);
69 void gnc_commodities_show_currencies_toggled (GtkToggleButton *toggle,
CommoditiesDialog *cd);
76 gnc_unregister_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
87 if (commodity == NULL)
91 gnc_gui_refresh_all ();
95 row_activated_cb (GtkTreeView *view, GtkTreePath *path,
101 g_return_if_fail(view);
103 model = gtk_tree_view_get_model(view);
104 if (gtk_tree_model_get_iter(model, &iter, path))
106 if (gtk_tree_model_iter_has_child(model, &iter))
110 if (gtk_tree_view_row_expanded(view, path))
111 gtk_tree_view_collapse_row(view, path);
113 gtk_tree_view_expand_row(view, path, FALSE);
131 const gchar *message, *warning;
135 if (commodity == NULL)
141 for (node = accounts; node; node = node->next)
156 const char *message = _(
"That commodity is currently used by "
157 "at least one of your accounts. You may "
160 gnc_warning_dialog (cd->dialog,
"%s", message);
161 g_list_free (accounts);
164 g_list_free (accounts);
170 message = _(
"This commodity has price quotes. Are "
171 "you sure you want to delete the selected "
172 "commodity and its price quotes?");
173 warning = GNC_PREF_WARN_PRICE_COMM_DEL_QUOTES;
177 message = _(
"Are you sure you want to delete the "
178 "selected commodity?");
179 warning = GNC_PREF_WARN_PRICE_COMM_DEL;
182 dialog = gtk_message_dialog_new(GTK_WINDOW(cd->dialog),
183 GTK_DIALOG_DESTROY_WITH_PARENT,
184 GTK_MESSAGE_QUESTION,
186 "%s", _(
"Delete commodity?"));
187 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
189 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
190 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
191 GTK_STOCK_DELETE, GTK_RESPONSE_OK,
193 response = gnc_dialog_run(GTK_DIALOG(dialog), warning);
194 gtk_widget_destroy(dialog);
196 if (response == GTK_RESPONSE_OK)
201 for (node = prices; node; node = node->next)
210 gnc_gui_refresh_all ();
217 const char *name_space;
229 gnc_commodities_dialog_response (GtkDialog *dialog,
235 case GNC_RESPONSE_NEW:
239 case GNC_RESPONSE_DELETE:
243 case GNC_RESPONSE_EDIT:
247 case GTK_RESPONSE_CLOSE:
249 gnc_close_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
255 gnc_commodities_dialog_selection_changed (GtkTreeSelection *selection,
263 gtk_widget_set_sensitive (cd->edit_button, commodity != NULL);
264 gtk_widget_set_sensitive (cd->remove_button, remove_ok);
268 gnc_commodities_show_currencies_toggled (GtkToggleButton *toggle,
272 cd->show_currencies = gtk_toggle_button_get_active (toggle);
286 if (g_strcmp0 (name,
"template") == 0)
295 return (list != NULL);
299 gnc_commodities_dialog_filter_cm_func (
gnc_commodity *commodity,
304 if (cd->show_currencies)
313 GtkWidget *scrolled_window;
316 GtkTreeSelection *selection;
318 builder = gtk_builder_new();
319 gnc_builder_add_from_file (builder,
"dialog-commodities.glade",
"Securities Dialog");
321 cd->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Securities Dialog"));
322 cd->session = gnc_get_current_session();
326 gtk_builder_connect_signals(builder, cd);
330 gtk_window_set_transient_for (GTK_WINDOW (cd->dialog), GTK_WINDOW (parent));
333 cd->remove_button = GTK_WIDGET(gtk_builder_get_object (builder,
"remove_button"));
334 cd->edit_button = GTK_WIDGET(gtk_builder_get_object (builder,
"edit_button"));
338 scrolled_window = GTK_WIDGET(gtk_builder_get_object (builder,
"commodity_list_window"));
340 "state-section", STATE_SECTION,
341 "show-column-menu", TRUE,
343 cd->commodity_tree = GNC_TREE_VIEW_COMMODITY(view);
344 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
345 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(cd->commodity_tree), TRUE);
347 gnc_commodities_dialog_filter_ns_func,
348 gnc_commodities_dialog_filter_cm_func,
350 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
351 g_signal_connect (G_OBJECT (selection),
"changed",
352 G_CALLBACK (gnc_commodities_dialog_selection_changed), cd);
354 g_signal_connect (G_OBJECT (cd->commodity_tree),
"row-activated",
355 G_CALLBACK (row_activated_cb), cd);
358 button = GTK_WIDGET(gtk_builder_get_object (builder,
"show_currencies_button"));
359 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), cd->show_currencies);
361 g_object_unref(G_OBJECT(builder));
362 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(cd->dialog));
366 close_handler (gpointer user_data)
370 gnc_save_window_size(GNC_PREFS_GROUP, GTK_WINDOW(cd->dialog));
374 gtk_widget_destroy(cd->dialog);
378 refresh_handler (GHashTable *changes, gpointer user_data)
382 g_return_if_fail(cd != NULL);
388 show_handler (
const char *klass, gint component_id,
389 gpointer user_data, gpointer iter_data)
395 gtk_window_present (GTK_WINDOW(cd->dialog));
407 gnc_commodities_dialog (GtkWidget * parent)
412 if (gnc_forall_gui_components (DIALOG_COMMODITIES_CM_CLASS,
418 gnc_commodities_dialog_create (parent, cd);
420 component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS,
421 refresh_handler, close_handler,
423 gnc_gui_component_set_session (component_id, cd->session);
425 gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree));
427 gtk_widget_show (cd->dialog);
void gnc_price_list_destroy(PriceList *prices)
GtkTreeView * gnc_tree_view_commodity_new(QofBook *book, const gchar *first_property_name,...)
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *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)
utility functions for the GnuCash UI
gnc_commodity * gnc_ui_new_commodity_modal(const char *default_namespace, GtkWidget *parent)
gboolean gnc_ui_edit_commodity_modal(gnc_commodity *commodity, GtkWidget *parent)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
QofBook * qof_session_get_book(const QofSession *session)
gboolean gnc_prefs_set_bool(const gchar *group, const gchar *pref_name, gboolean value)
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Gnome specific utility functions.
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
Generic api to store and retrieve preferences.
GList * gnc_account_get_descendants(const Account *account)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
gnc_commodity * gnc_tree_view_commodity_get_selected_commodity(GncTreeViewCommodity *view)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
GtkTreeView implementation for gnucash commodity tree.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
void gnc_tree_view_commodity_refilter(GncTreeViewCommodity *view)
"select" and "new" commodity windows
Commodity handling public routines.
void gnc_commodity_destroy(gnc_commodity *cm)
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
PriceList * gnc_pricedb_get_prices(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)