76 static void gnc_currency_edit_finalize (GObject *
object);
77 static void gnc_currency_edit_mnemonic_changed (GObject *gobject,
80 static void gnc_currency_edit_active_changed (GtkComboBox *gobject,
83 static GtkComboBoxClass *parent_class;
91 #define GET_PRIVATE(o) \
92 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_CURRENCY_EDIT, GNCCurrencyEditPrivate))
102 static GType currency_edit_type = 0;
104 if (currency_edit_type == 0)
106 static const GTypeInfo currency_edit_info =
111 (GClassInitFunc) gnc_currency_edit_class_init,
116 (GInstanceInitFunc) gnc_currency_edit_init,
120 currency_edit_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
122 ¤cy_edit_info, 0);
125 return currency_edit_type;
137 static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
140 gnc_currency_edit_set_property (GObject *
object,
150 case PROP_GCE_MNEMONIC:
151 g_free (priv->mnemonic);
152 priv->mnemonic = g_value_dup_string (value);
153 DEBUG (
"mnemonic: %s\n", priv->mnemonic);
158 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
164 gnc_currency_edit_get_property (GObject *
object,
174 case PROP_GCE_MNEMONIC:
175 g_value_set_string (value, priv->mnemonic);
180 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, property_id, pspec);
197 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
198 parent_class = g_type_class_peek_parent (klass);
202 gobject_class->set_property = gnc_currency_edit_set_property;
203 gobject_class->get_property = gnc_currency_edit_get_property;
204 gobject_class->finalize = gnc_currency_edit_finalize;
206 obj_properties[PROP_GCE_MNEMONIC] =
207 g_param_spec_string (
"mnemonic",
208 "Active currency's mnemonic",
209 "Active currency's mnemonic",
213 g_object_class_install_properties (gobject_class,
228 g_signal_connect (gce,
"notify::mnemonic",
229 G_CALLBACK (gnc_currency_edit_mnemonic_changed), gce);
230 g_signal_connect (gce,
"changed",
231 G_CALLBACK (gnc_currency_edit_active_changed), gce);
246 gnc_currency_edit_finalize (GObject *
object)
251 g_return_if_fail (
object != NULL);
252 g_return_if_fail (GNC_IS_CURRENCY_EDIT (
object));
254 period = GNC_CURRENCY_EDIT(
object);
255 priv = GET_PRIVATE(period);
257 g_free (priv->mnemonic);
262 if (G_OBJECT_CLASS(parent_class)->finalize)
263 (* G_OBJECT_CLASS(parent_class)->finalize) (
object);
268 gnc_currency_edit_mnemonic_changed (GObject *gobject,
276 gnc_commodity *currency = gnc_commodity_table_lookup (gnc_get_current_commodities (),
277 GNC_COMMODITY_NS_CURRENCY,
283 currency = gnc_locale_default_currency();
284 DEBUG(
"gce %p, default currency mnemonic %s",
288 g_signal_handlers_block_by_func(G_OBJECT(
self),
289 G_CALLBACK(gnc_currency_edit_mnemonic_changed), user_data);
291 g_signal_handlers_unblock_by_func(G_OBJECT(
self),
292 G_CALLBACK(gnc_currency_edit_mnemonic_changed), user_data);
296 static void gnc_currency_edit_active_changed (GtkComboBox *gobject,
305 g_signal_handlers_block_by_func(G_OBJECT(
self),
306 G_CALLBACK(gnc_currency_edit_active_changed), user_data);
307 g_object_set (G_OBJECT (
self),
"mnemonic", mnemonic, NULL);
308 g_signal_handlers_unblock_by_func(G_OBJECT(
self),
309 G_CALLBACK(gnc_currency_edit_active_changed), user_data);
329 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
333 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
334 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
string, -1);
353 (gnc_get_current_commodities (), GNC_COMMODITY_NS_CURRENCY);
354 g_list_foreach(currencies, (GFunc)add_item, gce);
355 g_list_free(currencies);
370 store = gtk_list_store_new (1, G_TYPE_STRING);
371 gce = g_object_new (GNC_TYPE_CURRENCY_EDIT,
375 g_object_unref (store);
378 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(gce), 0);
382 gnc_cbwe_require_list_item(GTK_COMBO_BOX(gce));
385 fill_currencies (gce);
386 gtk_tree_sortable_set_sort_column_id
387 (GTK_TREE_SORTABLE(store), 0, GTK_SORT_ASCENDING);
389 return GTK_WIDGET (gce);
408 const gchar *printname;
410 g_return_if_fail(gce != NULL);
411 g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
412 g_return_if_fail(currency != NULL);
430 const char *fullname;
431 char *mnemonic, *name;
434 GValue value = { 0 };
436 g_return_val_if_fail(gce != NULL, NULL);
437 g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), NULL);
439 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
441 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
442 gtk_tree_model_get_value(model, &iter, 0, &value);
443 fullname = g_value_get_string(&value);
444 mnemonic = g_strdup(fullname);
445 g_value_unset(&value);
447 name = strchr(mnemonic,
' ');
450 commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
451 GNC_COMMODITY_NS_CURRENCY,
457 g_warning(
"Combo box returned 'inactive'. Using locale default currency.");
458 commodity = gnc_locale_default_currency();
void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text)
void gnc_currency_edit_set_currency(GNCCurrencyEdit *gce, const gnc_commodity *currency)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
utility functions for the GnuCash UI
GType gnc_currency_edit_get_type(void)
#define DEBUG(format, args...)
Currency selection widget.
gnc_commodity * gnc_currency_edit_get_currency(GNCCurrencyEdit *gce)
All type declarations for the whole Gnucash engine.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
GtkWidget * gnc_currency_edit_new(void)
Commodity handling public routines.
const gchar * QofLogModule
struct _GNCCurrencyEditPrivate GNCCurrencyEditPrivate