GnuCash 2.3.0
Data Structures | Files | Defines | Typedefs
GncCurrencyEdit
GUI

Data Structures

struct  _GNCCurrencyEditPrivate
struct  GNCCurrencyEdit
struct  GNCCurrencyEditClass

Files

file  gnc-currency-edit.c
 

Currency selection widget.


file  gnc-currency-edit.h
 

Currency selection widget.


Defines

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

Typedefs

typedef struct
_GNCCurrencyEditPrivate 
GNCCurrencyEditPrivate

Basic Object Implementation

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))

Define Documentation

#define GNC_TYPE_CURRENCY_EDIT   (gnc_currency_edit_get_type())

Definition at line 63 of file gnc-currency-edit.h.


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 252 of file gnc-currency-edit.c.

{
    gnc_commodity *commodity;
    const char *fullname;
    char *mnemonic, *name;
    GtkTreeModel *model;
    GtkTreeIter iter;
    GValue value = { 0 };

    g_return_val_if_fail(gce != NULL, NULL);
    g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), NULL);

    if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
    {
        model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
        gtk_tree_model_get_value(model, &iter, 0, &value);
        fullname = g_value_get_string(&value);
        mnemonic = g_strdup(fullname);
        g_value_unset(&value);

        name = strchr(mnemonic, ' ');
        if (name != NULL)
            *name = '\0';
        commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (),
                                                GNC_COMMODITY_NS_CURRENCY,
                                                mnemonic);
        g_free(mnemonic);
    }
    else
    {
        g_warning("Combo box returned 'inactive'. Using locale default currency.");
        commodity = gnc_locale_default_currency();
    }


    return commodity;
}
GType gnc_currency_edit_get_type ( void  )

Return the GType for the GNCCurrencyEdit currency selection widget.

Returns:
A GType value.

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

{
    static GType currency_edit_type = 0;

    if (currency_edit_type == 0)
    {
        static const GTypeInfo currency_edit_info =
        {
            sizeof (GNCCurrencyEditClass),
            NULL,
            NULL,
            (GClassInitFunc) gnc_currency_edit_class_init,
            NULL,
            NULL,
            sizeof (GNCCurrencyEdit),
            0, /* n_preallocs */
            (GInstanceInitFunc) gnc_currency_edit_init,
            NULL
        };

        currency_edit_type = g_type_register_static (GTK_TYPE_COMBO_BOX_ENTRY,
                             "GNCCurrencyEdit",
                             &currency_edit_info, 0);
    }

    return currency_edit_type;
}
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 193 of file gnc-currency-edit.c.

{
    GNCCurrencyEdit *gce;
    GtkListStore *store;

    store = gtk_list_store_new (1, G_TYPE_STRING);
    gce = g_object_new (GNC_TYPE_CURRENCY_EDIT,
                        "model", store,
                        "text-column", 0,
                        NULL);
    g_object_unref (store);

    /* Now the signals to make sure the user can't leave the
       widget without a valid currency. */
    gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(gce));

    /* Fill in all the data. */
    fill_currencies (gce);
    gtk_tree_sortable_set_sort_column_id
    (GTK_TREE_SORTABLE(store), 0, GTK_SORT_ASCENDING);

    return GTK_WIDGET (gce);
}
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 230 of file gnc-currency-edit.c.

{
    const gchar *printname;

    g_return_if_fail(gce != NULL);
    g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
    g_return_if_fail(currency != NULL);

    printname = gnc_commodity_get_printname(currency);
    gnc_cbe_set_by_string(GTK_COMBO_BOX_ENTRY(gce), printname);
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines