gpe-expenses 0.1.9
|
Data Structures | |
struct | QofCurrency |
qof-expenses currency data wrapper. More... | |
Files | |
file | qof-expenses.h |
QOF expense definitions. | |
Defines | |
#define | GPE_MOD_EXP "gpe-expenses-module" |
#define | GPE_QOF_EXPENSES "gpe_expenses" |
#define | QOF_EXPENSES_DESC "GPE QOF expenses" |
#define | EXP_DATE "expense_date" |
#define | EXP_TYPE "type_of_expense" |
#define | EXP_PAYMENT "form_of_payment" |
#define | EXP_CURRENCY "currency_code" |
#define | EXP_AMOUNT "expense_amount" |
#define | EXP_VENDOR "expense_vendor" |
#define | EXP_CITY "expense_city" |
#define | EXP_ATTENDEES "expense_attendees" |
#define | EXP_NOTE "expense_note" |
#define | EXP_CATEGORY "category" |
#define | EXP_DISTANCE "distance_unit" |
#define | EXP_KVP "currency_lookup" |
#define | PQ_CURRENCY_MNEMONIC "expense/currency/mnemonic" |
#define | PQ_CURRENCY_SYMBOL "expense/currency/symbol" |
#define | PQ_CURRENCY_FRACTION "expense/currency/fraction" |
#define | DISTANCE_LIST(_) |
#define | PAYMENT_TYPE_LIST(_) |
#define | EXPENSE_TYPE_LIST(_) |
#define | _GNU_SOURCE |
#define | _(String) dgettext (LIBRARY_GETTEXT_PACKAGE, String) |
#define | STRING(name, value) gchar * G_GNUC_UNUSED name##noop = _(#name); |
#define | MARKUP(name, list) |
Typedefs | |
typedef struct QofExp_s | QofExp |
Wraps QOF around pilot-link expenses. | |
typedef void(* | QofCurrencyCB )(gpointer key, gpointer value, gpointer user_data) |
Functions | |
void | qof_currency_foreach (QofCurrencyCB cb, gpointer user_data) |
QofCurrency * | qof_currency_lookup (QofInstance *inst, gint currency_code) |
Set details of a QofCurrency from a currency_code. | |
QofCurrency * | qof_currency_lookup_name (QofInstance *inst, gchar *mnemonic) |
Lookup a currency by name. | |
gboolean | ExpensesRegister (void) |
typedef for expense payment types. | |
static void G_GNUC_UNUSED | ExpenseTypetranslate (void) |
static void G_GNUC_UNUSED | ExpensePaymenttranslate (void) |
Like ::DB, Expenses uses UTC time within QOF and sets localtime when calling pilot-link code.
Gradually becoming a standard QOF method, whilst retaining compatibility with the simple pilot-link currency handling instead of going the whole hog to GnuCash currencies. The old Expense_t has been removed for easier sharing between applications.
The typed enumerators ::ExpenseDistance, ::ExpenseType and ::ExpensePayment may look strange initially because macros are used to ensure that the enum value and a string version of the enum are always in sync. This allows the QOF backends to write human-readable data stores by specifying an ExpenseType of "Parking" as:
<string type="type_of_expense">Parking</string>
instead of:
<string type="type_of_expense">5</string>
In particular, do not let the macro syntax _(name, value)
fool you into thinking it is related to _(String)
from gettext! Note how the enumerator is handled by doxygen:
enum ExpenseType { Airfare = 0, Breakfast = 1, Bus = 2, BusinessMeals, ...
Translation must only be used to represent the string version of the enum value in the user interface and all internal handling of the enum value must remain untranslated in the QofEntity itself as this would lock the data into a specific locale.
#define DISTANCE_LIST | ( | _ | ) |
_(Miles, = 0) \ _(Kilometers,)
Definition at line 162 of file qof-expenses.h.
#define EXPENSE_TYPE_LIST | ( | _ | ) |
_(Airfare, = 0) \ _(Breakfast, = 1) \ _(Bus, = 2) \ _(BusinessMeals, ) \ _(CarRental, ) \ _(Dinner, ) \ _(Entertainment, ) \ _(Fax, ) \ _(Gas, ) \ _(Gifts, ) \ _(Hotel, ) \ _(Incidentals, ) \ _(Laundry, ) \ _(Limo, ) \ _(Lodging, ) \ _(Lunch, ) \ _(Mileage, ) \ _(Other, ) \ _(Parking, ) \ _(Postage, ) \ _(Snack, ) \ _(Subway, ) \ _(Supplies, ) \ _(Taxi, ) \ _(Telephone, ) \ _(Tips, ) \ _(Tolls, ) \ _(Train, )
Definition at line 176 of file qof-expenses.h.
#define GPE_MOD_EXP "gpe-expenses-module" |
Definition at line 80 of file qof-expenses.h.
#define MARKUP | ( | name, | |
list | |||
) |
static void G_GNUC_UNUSED name##translate (void) \ { \ list(STRING) \ }
Definition at line 66 of file translate.c.
#define PAYMENT_TYPE_LIST | ( | _ | ) |
_(AmericanExpress, = 0) \ _(Cash, = 1 ) \ _(Cheque, ) \ _(CreditCard, ) \ _(MasterCard, ) \ _(Prepaid, ) \ _(VISA, ) \ _(Unfiled, )
Definition at line 166 of file qof-expenses.h.
#define PQ_CURRENCY_FRACTION "expense/currency/fraction" |
type: KVP_TYPE_GINT64 - inherited from pilot-link via pilot-qof.
Definition at line 101 of file qof-expenses.h.
Referenced by qof_currency_lookup().
#define PQ_CURRENCY_MNEMONIC "expense/currency/mnemonic" |
type: KVP_TYPE_STRING - inherited from pilot-link via pilot-qof.
Definition at line 97 of file qof-expenses.h.
Referenced by qof_currency_lookup().
#define PQ_CURRENCY_SYMBOL "expense/currency/symbol" |
type: KVP_TYPE_STRING - inherited from pilot-link via pilot-qof.
Definition at line 99 of file qof-expenses.h.
Referenced by qof_currency_lookup().
gboolean ExpensesRegister | ( | void | ) |
typedef for expense payment types.
dgettext
not the ordinary gettext
or the _(String)
macro.In your UI, to retrieve the translated string for an ExpensePayment, wrap ExpenseTypeasString in a call to the library translation support:
ExpensePayment i = Cash; GtkComboBox * my_combo_box; // set i to the enum value to display as a translated string gtk_combo_box_append_text (my_combo_box, dgettext(LIBRARY_GETTEXT_PACKAGE, ExpensePaymentasString(i))); // the combo_box has a translation of "Cash" added to the list.
You may choose to define your own macro for this.
Other translatable strings in your application code must continue to use gettext
or the _(String)
macro as normal.
In accordance with the gettext manual, the library code does not call setlocale (LC_ALL, "")
. It is the responsibility of the main program to set the locale. typedef for expense types
dgettext
not the ordinary gettext
or the _(String)
macro.In your UI, to retrieve the translated string for an ExpenseType, wrap ExpenseTypeasString in a call to the library translation support:
GtkComboBox * my_combo_box; ExpenseType i = Telephone; // set i to the enum value to display as a translated string gtk_combo_box_append_text (my_combo_box, dgettext(LIBRARY_GETTEXT_PACKAGE, ExpenseTypeasString(i))); // the combo_box has a translation of "Telephone" added to the list.
You may choose to define your own macro for this.
Other translatable strings in your application code must continue to use gettext
or the _(String)
macro as normal.
In accordance with the gettext manual, the library code does not call setlocale (LC_ALL, "")
. It is the responsibility of the main program to set the locale. Register this object with QOF
In accordance with the gettext manual, the library code does not call setlocale (LC_ALL, "")
. It is the responsibility of the main program to set the locale. The library just calls bindtextdomain with the domain for the library, LIBRARY_GETTEXT_PACKAGE which is exported via the libqofexpensesobjects API.
bindtextdomain (LIBRARY_GETTEXT_PACKAGE, LOCALE_DIR);
Definition at line 844 of file qof-expenses.c.
{ static QofParam params[] = { { EXP_DATE, QOF_TYPE_TIME, (QofAccessFunc) exp_getTime, (QofSetterFunc) exp_setTime, NULL }, { EXP_TYPE, QOF_TYPE_STRING, (QofAccessFunc) exp_getType, (QofSetterFunc) exp_setType, NULL }, { EXP_PAYMENT, QOF_TYPE_STRING, (QofAccessFunc) exp_getPayment, (QofSetterFunc) exp_setPayment, NULL }, { EXP_CURRENCY, QOF_TYPE_INT32, (QofAccessFunc) exp_getCurrency, (QofSetterFunc) exp_setCurrency, NULL }, { EXP_AMOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc) exp_getAmount, (QofSetterFunc) exp_setAmount, NULL }, { EXP_VENDOR, QOF_TYPE_STRING, (QofAccessFunc) exp_getVendor, (QofSetterFunc) exp_setVendor, NULL }, { EXP_CITY, QOF_TYPE_STRING, (QofAccessFunc) exp_getCity, (QofSetterFunc) exp_setCity, NULL }, { EXP_ATTENDEES, QOF_TYPE_STRING, (QofAccessFunc) exp_getAttendees, (QofSetterFunc) exp_setAttendees, NULL }, { EXP_NOTE, QOF_TYPE_STRING, (QofAccessFunc) exp_getNote, (QofSetterFunc) exp_setNote, NULL }, { EXP_DISTANCE, QOF_TYPE_STRING, (QofAccessFunc) exp_getDistance, (QofSetterFunc) exp_setDistance, NULL }, { EXP_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) exp_getCategory, (QofSetterFunc) exp_setCategory, NULL }, { EXP_KVP, QOF_TYPE_KVP, (QofAccessFunc) qof_instance_get_slots, NULL, NULL }, { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc) qof_instance_get_book, NULL, NULL }, { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc) qof_instance_get_guid, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL }, }; bindtextdomain (LIBRARY_GETTEXT_PACKAGE, LOCALE_DIR); qof_class_register (GPE_QOF_EXPENSES, NULL, params); if(!qof_currency_table) populate_currencies(); return qof_object_register (&expenses_object_def); }
QofCurrency* qof_currency_lookup | ( | QofInstance * | inst, |
gint | currency_code | ||
) |
Set details of a QofCurrency from a currency_code.
Lookup details of a QofCurrency from a short identifier. The QofInstance will have a KvpFrame set (replacing any existing values for the same keys) containing: -PQ_CURRENCY_MNEMONIC -PQ_CURRENCY_FRACTION -PQ_CURRENCY_SYMBOL
inst | The QofInstance to hold the KvpFrame containing the details of the currency. |
currency_code | The identifier of this currency. |
Definition at line 444 of file qof-expenses.c.
{ QofCurrency *currency; currency = NULL; if(!qof_currency_table) populate_currencies(); currency = (QofCurrency*)g_hash_table_lookup( qof_currency_table, GINT_TO_POINTER(currency_code)); if(!currency) { PERR (" unsupported currency! %d", currency_code); return NULL; } kvp_frame_set_string(qof_instance_get_slots(inst), PQ_CURRENCY_MNEMONIC, currency->mnemonic); kvp_frame_set_gint64(qof_instance_get_slots(inst), PQ_CURRENCY_FRACTION, currency->fraction); if(currency->non_utf8) { gchar * k_symbol = g_strdup (currency->symbol); kvp_frame_set_string(qof_instance_get_slots(inst), PQ_CURRENCY_SYMBOL, qof_util_make_utf8(k_symbol)); } else { kvp_frame_set_string(qof_instance_get_slots(inst), PQ_CURRENCY_SYMBOL, currency->symbol); } return currency; }
QofCurrency* qof_currency_lookup_name | ( | QofInstance * | inst, |
gchar * | mnemonic | ||
) |
Lookup a currency by name.
Slower than ::gpe_currency_lookup because the entire currency hash must be searched. Otherwise, equivalent.
Definition at line 430 of file qof-expenses.c.
{ QofCurrency *currency; currency = NULL; if(!qof_currency_table) populate_currencies(); currency = (QofCurrency*) g_hash_table_find (qof_currency_table, check_name, mnemonic); if (!currency) return NULL; qof_currency_lookup(inst, currency->pq_code); return currency; }