52#include <glib/gi18n.h>
64#include "dialog-utils.h"
67static QofLogModule log_module = GNC_MOD_GUI;
69static void gnc_currency_edit_finalize (GObject *
object);
70static void gnc_currency_edit_mnemonic_changed (GObject *gobject,
73static void gnc_currency_edit_active_changed (GtkComboBox *gobject,
84G_DEFINE_TYPE(GNCCurrencyEdit, gnc_currency_edit, GTK_TYPE_COMBO_BOX)
98static GParamSpec *obj_properties[N_PROPERTIES] = {
nullptr, };
101gnc_currency_edit_set_property (GObject *
object,
106 GNCCurrencyEdit *self = GNC_CURRENCY_EDIT (
object);
110 case PROP_GCE_MNEMONIC:
111 g_free (self->mnemonic);
112 self->mnemonic = g_value_dup_string (value);
113 DEBUG (
"mnemonic: %s\n", self->mnemonic);
118 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
124gnc_currency_edit_get_property (GObject *
object,
129 GNCCurrencyEdit *self = GNC_CURRENCY_EDIT (
object);
133 case PROP_GCE_MNEMONIC:
134 g_value_set_string (value, self->mnemonic);
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
151gnc_currency_edit_class_init (GNCCurrencyEditClass *klass)
153 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
155 gobject_class->set_property = gnc_currency_edit_set_property;
156 gobject_class->get_property = gnc_currency_edit_get_property;
157 gobject_class->finalize = gnc_currency_edit_finalize;
159 obj_properties[PROP_GCE_MNEMONIC] =
160 g_param_spec_string (
"mnemonic",
161 "Active currency's mnemonic",
162 "Active currency's mnemonic",
166 g_object_class_install_properties (gobject_class,
179gnc_currency_edit_init (GNCCurrencyEdit *gce)
182 gtk_widget_set_name (GTK_WIDGET(gce),
"gnc-id-currency-edit");
184 g_signal_connect (gce,
"notify::mnemonic",
185 G_CALLBACK (gnc_currency_edit_mnemonic_changed), gce);
186 g_signal_connect (gce,
"changed",
187 G_CALLBACK (gnc_currency_edit_active_changed), gce);
202gnc_currency_edit_finalize (GObject *
object)
204 g_return_if_fail (
object !=
nullptr);
205 g_return_if_fail (GNC_IS_CURRENCY_EDIT (
object));
207 GNCCurrencyEdit *self = GNC_CURRENCY_EDIT(
object);
209 g_free (self->mnemonic);
211 G_OBJECT_CLASS(gnc_currency_edit_parent_class)->finalize (
object);
216gnc_currency_edit_mnemonic_changed (GObject *gobject,
221 GNCCurrencyEdit *self = GNC_CURRENCY_EDIT (gobject);
223 gnc_commodity *currency = gnc_commodity_table_lookup (gnc_get_current_commodities (),
224 GNC_COMMODITY_NS_CURRENCY,
231 DEBUG(
"gce %p, default currency mnemonic %s",
235 g_signal_handlers_block_by_func(G_OBJECT(self),
236 (gpointer)gnc_currency_edit_mnemonic_changed,
239 g_signal_handlers_unblock_by_func(G_OBJECT(self),
240 (gpointer)gnc_currency_edit_mnemonic_changed,
245static void gnc_currency_edit_active_changed (GtkComboBox *gobject,
248 GNCCurrencyEdit *self = GNC_CURRENCY_EDIT (gobject);
252 if (gtk_combo_box_get_active(GTK_COMBO_BOX(self)) != -1)
257 g_signal_handlers_block_by_func(G_OBJECT(self),
258 (gpointer)gnc_currency_edit_active_changed, user_data);
259 g_object_set (G_OBJECT (self),
"mnemonic", mnemonic,
nullptr);
260 g_signal_handlers_unblock_by_func(G_OBJECT(self),
261 (gpointer)gnc_currency_edit_active_changed, user_data);
268 CURRENCY_COL_NORMALIZED_FOLDED,
283add_item(gnc_commodity *commodity, GNCCurrencyEdit *gce)
288 gchar *normalized, *normalized_folded;
290 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
293 normalized = g_utf8_normalize (
string, -1, G_NORMALIZE_NFC);
294 normalized_folded = normalized ? g_utf8_casefold (normalized, -1) : nullptr;
296 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
297 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
298 CURRENCY_COL_NAME,
string,
299 CURRENCY_COL_NORMALIZED_FOLDED, normalized_folded,
301 gce->widest = std::max (gce->widest, g_utf8_strlen (
string, -1));
302 g_free (normalized_folded);
316fill_currencies(GNCCurrencyEdit *gce)
321 (gnc_get_current_commodities (), GNC_COMMODITY_NS_CURRENCY);
322 g_list_foreach(currencies, (GFunc)add_item, gce);
323 g_list_free(currencies);
325 auto entry = gtk_bin_get_child (GTK_BIN (gce));
326 gtk_entry_set_width_chars (GTK_ENTRY (entry), gce->widest);
331match_func (GtkEntryCompletion *completion,
const char *entry_str,
332 GtkTreeIter *iter, GtkTreeModel *model)
334 gchar *currency_name;
335 gboolean ret = FALSE;
336 gtk_tree_model_get (model, iter,
337 CURRENCY_COL_NORMALIZED_FOLDED, ¤cy_name,
339 if (currency_name && *currency_name && strstr (currency_name, entry_str))
341 g_free (currency_name);
353 GNCCurrencyEdit *gce;
355 GtkEntryCompletion* completion;
357 store = gtk_list_store_new (NUM_CURRENCY_COLS, G_TYPE_STRING, G_TYPE_STRING);
358 gce = GNC_CURRENCY_EDIT(g_object_new (GNC_TYPE_CURRENCY_EDIT,
362 g_object_unref (store);
365 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(gce), CURRENCY_COL_NAME);
369 gnc_cbwe_require_list_item(GTK_COMBO_BOX(gce));
372 fill_currencies (gce);
373 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store),
377 completion = gtk_entry_completion_new ();
378 gtk_entry_completion_set_model (completion, GTK_TREE_MODEL(store));
379 gtk_entry_completion_set_text_column (completion, CURRENCY_COL_NAME);
380 gtk_entry_completion_set_match_func (completion,
381 (GtkEntryCompletionMatchFunc)match_func,
382 GTK_TREE_MODEL(store),
nullptr);
383 gtk_entry_set_completion (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (gce))),
386 return GTK_WIDGET (gce);
403 const gnc_commodity *currency)
405 const gchar *printname;
407 g_return_if_fail(gce !=
nullptr);
408 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
409 g_return_if_fail(currency !=
nullptr);
426 gnc_commodity *commodity;
427 char *mnemonic, *name;
431 g_return_val_if_fail(gce !=
nullptr,
nullptr);
432 g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce),
nullptr);
434 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
436 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
437 gtk_tree_model_get (model, &iter, 0, &mnemonic, -1);
439 name = strchr(mnemonic,
' ');
442 commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
443 GNC_COMMODITY_NS_CURRENCY,
449 g_warning(
"Combo box returned 'inactive'. Using locale default currency.");
470 g_return_if_fail(gce !=
nullptr);
471 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
473 model = gtk_combo_box_get_model (GTK_COMBO_BOX(gce));
475 entry = gtk_bin_get_child (GTK_BIN(gce));
477 g_object_ref (model);
479 g_signal_handlers_block_by_func (G_OBJECT(gce),
480 (gpointer)gnc_currency_edit_active_changed, gce);
482 gtk_combo_box_set_model (GTK_COMBO_BOX(gce),
nullptr);
483 gtk_entry_set_text (GTK_ENTRY(entry),
"");
484 gtk_combo_box_set_active (GTK_COMBO_BOX(gce), -1);
485 gtk_combo_box_set_model (GTK_COMBO_BOX(gce), model);
487 g_signal_handlers_unblock_by_func (G_OBJECT(gce),
488 (gpointer)gnc_currency_edit_active_changed, gce);
490 g_object_unref (model);
Commodity handling public routines.
Currency selection widget.
All type declarations for the whole Gnucash engine.
utility functions for the GnuCash UI
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
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.
void gnc_currency_edit_set_currency(GNCCurrencyEdit *gce, const gnc_commodity *currency)
Set the widget to display a certain currency name.
void gnc_currency_edit_clear_display(GNCCurrencyEdit *gce)
Clear the displayed currency of the widget.
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_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.
gnc_commodity * gnc_locale_default_currency(void)
Returns the default currency of the current locale.
#define DEBUG(format, args...)
Print a debugging message.