52 #include <glib/gi18n.h> 62 #include "dialog-utils.h" 65 static QofLogModule log_module = GNC_MOD_GUI;
67 static void gnc_currency_edit_finalize (GObject *
object);
68 static void gnc_currency_edit_mnemonic_changed (GObject *gobject,
71 static void gnc_currency_edit_active_changed (GtkComboBox *gobject,
81 G_DEFINE_TYPE(GNCCurrencyEdit, gnc_currency_edit, GTK_TYPE_COMBO_BOX)
95 static GParamSpec *obj_properties[N_PROPERTIES] = {
nullptr, };
98 gnc_currency_edit_set_property (GObject *
object,
103 GNCCurrencyEdit *
self = GNC_CURRENCY_EDIT (
object);
107 case PROP_GCE_MNEMONIC:
108 g_free (self->mnemonic);
109 self->mnemonic = g_value_dup_string (value);
110 DEBUG (
"mnemonic: %s\n", self->mnemonic);
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
121 gnc_currency_edit_get_property (GObject *
object,
126 GNCCurrencyEdit *
self = GNC_CURRENCY_EDIT (
object);
130 case PROP_GCE_MNEMONIC:
131 g_value_set_string (value, self->mnemonic);
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
148 gnc_currency_edit_class_init (GNCCurrencyEditClass *klass)
150 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
152 gobject_class->set_property = gnc_currency_edit_set_property;
153 gobject_class->get_property = gnc_currency_edit_get_property;
154 gobject_class->finalize = gnc_currency_edit_finalize;
156 obj_properties[PROP_GCE_MNEMONIC] =
157 g_param_spec_string (
"mnemonic",
158 "Active currency's mnemonic",
159 "Active currency's mnemonic",
163 g_object_class_install_properties (gobject_class,
176 gnc_currency_edit_init (GNCCurrencyEdit *gce)
179 gtk_widget_set_name (GTK_WIDGET(gce),
"gnc-id-currency-edit");
181 g_signal_connect (gce,
"notify::mnemonic",
182 G_CALLBACK (gnc_currency_edit_mnemonic_changed), gce);
183 g_signal_connect (gce,
"changed",
184 G_CALLBACK (gnc_currency_edit_active_changed), gce);
199 gnc_currency_edit_finalize (GObject *
object)
201 g_return_if_fail (
object !=
nullptr);
202 g_return_if_fail (GNC_IS_CURRENCY_EDIT (
object));
204 GNCCurrencyEdit *
self = GNC_CURRENCY_EDIT(
object);
206 g_free (self->mnemonic);
208 G_OBJECT_CLASS(gnc_currency_edit_parent_class)->finalize (
object);
213 gnc_currency_edit_mnemonic_changed (GObject *gobject,
218 GNCCurrencyEdit *
self = GNC_CURRENCY_EDIT (gobject);
220 gnc_commodity *currency = gnc_commodity_table_lookup (gnc_get_current_commodities (),
221 GNC_COMMODITY_NS_CURRENCY,
228 DEBUG(
"gce %p, default currency mnemonic %s",
232 g_signal_handlers_block_by_func(G_OBJECT(
self),
233 (gpointer)gnc_currency_edit_mnemonic_changed,
236 g_signal_handlers_unblock_by_func(G_OBJECT(
self),
237 (gpointer)gnc_currency_edit_mnemonic_changed,
242 static void gnc_currency_edit_active_changed (GtkComboBox *gobject,
245 GNCCurrencyEdit *
self = GNC_CURRENCY_EDIT (gobject);
249 if (gtk_combo_box_get_active(GTK_COMBO_BOX(
self)) != -1)
254 g_signal_handlers_block_by_func(G_OBJECT(
self),
255 (gpointer)gnc_currency_edit_active_changed, user_data);
256 g_object_set (G_OBJECT (
self),
"mnemonic", mnemonic,
nullptr);
257 g_signal_handlers_unblock_by_func(G_OBJECT(
self),
258 (gpointer)gnc_currency_edit_active_changed, user_data);
265 CURRENCY_COL_NORMALIZED_FOLDED,
280 add_item(gnc_commodity *commodity, GNCCurrencyEdit *gce)
285 gchar *normalized, *normalized_folded;
287 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
290 normalized = g_utf8_normalize (
string, -1, G_NORMALIZE_NFC);
291 normalized_folded = normalized ? g_utf8_casefold (normalized, -1) : nullptr;
293 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
294 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
295 CURRENCY_COL_NAME,
string,
296 CURRENCY_COL_NORMALIZED_FOLDED, normalized_folded,
298 g_free (normalized_folded);
312 fill_currencies(GNCCurrencyEdit *gce)
317 (gnc_get_current_commodities (), GNC_COMMODITY_NS_CURRENCY);
318 g_list_foreach(currencies, (GFunc)add_item, gce);
319 g_list_free(currencies);
324 match_func (GtkEntryCompletion *completion,
const char *entry_str,
325 GtkTreeIter *iter, GtkTreeModel *model)
327 gchar *currency_name;
328 gboolean ret = FALSE;
329 gtk_tree_model_get (model, iter,
330 CURRENCY_COL_NORMALIZED_FOLDED, ¤cy_name,
332 if (currency_name && *currency_name && strstr (currency_name, entry_str))
334 g_free (currency_name);
346 GNCCurrencyEdit *gce;
348 GtkEntryCompletion* completion;
350 store = gtk_list_store_new (NUM_CURRENCY_COLS, G_TYPE_STRING, G_TYPE_STRING);
351 gce = GNC_CURRENCY_EDIT(g_object_new (GNC_TYPE_CURRENCY_EDIT,
355 g_object_unref (store);
358 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(gce), CURRENCY_COL_NAME);
362 gnc_cbwe_require_list_item(GTK_COMBO_BOX(gce));
365 fill_currencies (gce);
366 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store),
370 completion = gtk_entry_completion_new ();
371 gtk_entry_completion_set_model (completion, GTK_TREE_MODEL(store));
372 gtk_entry_completion_set_text_column (completion, CURRENCY_COL_NAME);
373 gtk_entry_completion_set_match_func (completion,
374 (GtkEntryCompletionMatchFunc)match_func,
375 GTK_TREE_MODEL(store),
nullptr);
376 gtk_entry_set_completion (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (gce))),
379 return GTK_WIDGET (gce);
396 const gnc_commodity *currency)
398 const gchar *printname;
400 g_return_if_fail(gce !=
nullptr);
401 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
402 g_return_if_fail(currency !=
nullptr);
419 gnc_commodity *commodity;
420 char *mnemonic, *name;
424 g_return_val_if_fail(gce !=
nullptr,
nullptr);
425 g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce),
nullptr);
427 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
429 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
430 gtk_tree_model_get (model, &iter, 0, &mnemonic, -1);
432 name = strchr(mnemonic,
' ');
435 commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
436 GNC_COMMODITY_NS_CURRENCY,
442 g_warning(
"Combo box returned 'inactive'. Using locale default currency.");
463 g_return_if_fail(gce !=
nullptr);
464 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
466 model = gtk_combo_box_get_model (GTK_COMBO_BOX(gce));
468 entry = gtk_bin_get_child (GTK_BIN(gce));
470 g_object_ref (model);
472 g_signal_handlers_block_by_func (G_OBJECT(gce),
473 (gpointer)gnc_currency_edit_active_changed, gce);
475 gtk_combo_box_set_model (GTK_COMBO_BOX(gce),
nullptr);
476 gtk_entry_set_text (GTK_ENTRY(entry),
"");
477 gtk_combo_box_set_active (GTK_COMBO_BOX(gce), -1);
478 gtk_combo_box_set_model (GTK_COMBO_BOX(gce), model);
480 g_signal_handlers_block_by_func (G_OBJECT(gce),
481 (gpointer)gnc_currency_edit_active_changed, gce);
483 g_object_unref (model);
void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text)
Find an entry in the GtkComboBox by its text value, and set the widget to that value.
void gnc_currency_edit_set_currency(GNCCurrencyEdit *gce, const gnc_commodity *currency)
Set the widget to display a certain currency name.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
utility functions for the GnuCash UI
#define DEBUG(format, args...)
Print a debugging message.
void gnc_currency_edit_clear_display(GNCCurrencyEdit *gce)
Clear the displayed currency of the widget.
Currency selection widget.
gnc_commodity * gnc_currency_edit_get_currency(GNCCurrencyEdit *gce)
Retrieve the displayed currency of the widget.
All type declarations for the whole Gnucash engine.
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.
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_locale_default_currency(void)
Returns the default currency of the current locale.
Commodity handling public routines.