GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs
GncCurrencyEdit

Files

file  gnc-currency-edit.c
 Currency selection widget.
 
file  gnc-currency-edit.h
 Currency selection widget.
 

Data Structures

struct  _GNCCurrencyEditPrivate
 
struct  GNCCurrencyEdit
 
struct  GNCCurrencyEditClass
 

Macros

#define GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_CURRENCY_EDIT, GNCCurrencyEditPrivate))
 

Typedefs

typedef struct
_GNCCurrencyEditPrivate 
GNCCurrencyEditPrivate
 

Basic Object Implementation

enum  { PROP_0, PROP_GCE_MNEMONIC, N_PROPERTIES }
 
GType gnc_currency_edit_get_type (void)
 
GtkWidget * gnc_currency_edit_new (void)
 

Get/Set Functions

void gnc_currency_edit_set_currency (GNCCurrencyEdit *gce, const gnc_commodity *currency)
 
gnc_commoditygnc_currency_edit_get_currency (GNCCurrencyEdit *gce)
 

Basic Object Implementation

#define GNC_TYPE_CURRENCY_EDIT   (gnc_currency_edit_get_type())
 
#define GNC_CURRENCY_EDIT(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_CURRENCY_EDIT, GNCCurrencyEdit))
 
#define GNC_CURRENCY_EDIT_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_CURRENCY_EDIT, GNCCurrencyEditClass))
 
#define GNC_IS_CURRENCY_EDIT(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_CURRENCY_EDIT))
 

Detailed Description

Typedef Documentation

The instance private data for a content plugin.

Function Documentation

gnc_commodity * gnc_currency_edit_get_currency ( GNCCurrencyEdit gce)

Retrieve the displayed currency of the widget.

Parameters
gceThe currency editor widget whose values should be retrieved.
Returns
A pointer to the selected currency (a gnc_commodity structure).

Definition at line 427 of file gnc-currency-edit.c.

428 {
429  gnc_commodity *commodity;
430  const char *fullname;
431  char *mnemonic, *name;
432  GtkTreeModel *model;
433  GtkTreeIter iter;
434  GValue value = { 0 };
435 
436  g_return_val_if_fail(gce != NULL, NULL);
437  g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), NULL);
438 
439  if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
440  {
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);
446 
447  name = strchr(mnemonic, ' ');
448  if (name != NULL)
449  *name = '\0';
450  commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
451  GNC_COMMODITY_NS_CURRENCY,
452  mnemonic);
453  g_free(mnemonic);
454  }
455  else
456  {
457  g_warning("Combo box returned 'inactive'. Using locale default currency.");
458  commodity = gnc_locale_default_currency();
459  }
460 
461 
462  return commodity;
463 }
GType gnc_currency_edit_get_type ( void  )

Return the GType for the GNCCurrencyEdit currency selection widget.

Returns
A GType value.

Definition at line 100 of file gnc-currency-edit.c.

101 {
102  static GType currency_edit_type = 0;
103 
104  if (currency_edit_type == 0)
105  {
106  static const GTypeInfo currency_edit_info =
107  {
108  sizeof (GNCCurrencyEditClass),
109  NULL,
110  NULL,
111  (GClassInitFunc) gnc_currency_edit_class_init,
112  NULL,
113  NULL,
114  sizeof (GNCCurrencyEdit),
115  0, /* n_preallocs */
116  (GInstanceInitFunc) gnc_currency_edit_init,
117  NULL
118  };
119 
120  currency_edit_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
121  "GNCCurrencyEdit",
122  &currency_edit_info, 0);
123  }
124 
125  return currency_edit_type;
126 }
GtkWidget * gnc_currency_edit_new ( void  )

Create a new GNCCurrencyEdit widget which can be used to provide an easy way to enter ISO currency codes.

Returns
A GNCCurrencyEdit widget.

Definition at line 365 of file gnc-currency-edit.c.

366 {
367  GNCCurrencyEdit *gce;
368  GtkListStore *store;
369 
370  store = gtk_list_store_new (1, G_TYPE_STRING);
371  gce = g_object_new (GNC_TYPE_CURRENCY_EDIT,
372  "model", store,
373  "has-entry", TRUE,
374  NULL);
375  g_object_unref (store);
376 
377  /* Set the column for the text */
378  gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(gce), 0);
379 
380  /* Now the signals to make sure the user can't leave the
381  widget without a valid currency. */
382  gnc_cbwe_require_list_item(GTK_COMBO_BOX(gce));
383 
384  /* Fill in all the data. */
385  fill_currencies (gce);
386  gtk_tree_sortable_set_sort_column_id
387  (GTK_TREE_SORTABLE(store), 0, GTK_SORT_ASCENDING);
388 
389  return GTK_WIDGET (gce);
390 }
void gnc_currency_edit_set_currency ( GNCCurrencyEdit gce,
const gnc_commodity currency 
)

Set the widget to display a certain currency name.

Parameters
gceThe currency editor widget to set.
currencyThe currency to set as the displayed/selected value of the widget.

Definition at line 405 of file gnc-currency-edit.c.

407 {
408  const gchar *printname;
409 
410  g_return_if_fail(gce != NULL);
411  g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
412  g_return_if_fail(currency != NULL);
413 
414  printname = gnc_commodity_get_printname(currency);
415  gnc_cbwe_set_by_string(GTK_COMBO_BOX(gce), printname);
416 }
void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text)
Definition: gnc-gtk-utils.c:41
const char * gnc_commodity_get_printname(const gnc_commodity *cm)