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) |
Enumerations | |
enum | ExpenseDistance { Miles = 0, Kilometers } |
enum | ExpensePayment { AmericanExpress = 0, Cash = 1, Cheque, CreditCard, MasterCard, Prepaid, VISA, Unfiled } |
typedef for expense payment types. More... | |
enum | ExpenseType { 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 } |
typedef for expense types More... | |
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. | |
const gchar * | ExpenseDistanceasString (ExpenseDistance n) |
ExpenseDistance | ExpenseDistancefromString (const gchar *str) |
const gchar * | ExpensePaymentasString (ExpensePayment n) |
ExpensePayment | ExpensePaymentfromString (const gchar *str) |
const gchar * | ExpenseTypeasString (ExpenseType n) |
ExpenseType | ExpenseTypefromString (const gchar *str) |
gboolean | ExpensesRegister (void) |
Register this object with QOF. | |
static void G_GNUC_UNUSED | ExpenseTypetranslate (void) |
static void G_GNUC_UNUSED | ExpensePaymenttranslate (void) |
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>
<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 | ( | _ | ) |
#define EXPENSE_TYPE_LIST | ( | _ | ) |
Value:
_(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" |
#define MARKUP | ( | name, | |||
list | ) |
Value:
static void G_GNUC_UNUSED name##translate (void) \ { \ list(STRING) \ }
Definition at line 66 of file translate.c.
#define PAYMENT_TYPE_LIST | ( | _ | ) |
Value:
_(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().
enum ExpensePayment |
typedef for expense payment types.
dgettext
not the ordinary gettext
or the _(String)
macro.
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.
Definition at line 239 of file qof-expenses.h.
enum ExpenseType |
typedef for expense types
dgettext
not the ordinary gettext
or the _(String)
macro.
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.
Definition at line 273 of file qof-expenses.h.
gboolean ExpensesRegister | ( | void | ) |
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.
00845 { 00846 static QofParam params[] = { 00847 { EXP_DATE, QOF_TYPE_TIME, (QofAccessFunc) exp_getTime, (QofSetterFunc) exp_setTime, NULL }, 00848 { EXP_TYPE, QOF_TYPE_STRING, (QofAccessFunc) exp_getType, (QofSetterFunc) exp_setType, NULL }, 00849 { EXP_PAYMENT, QOF_TYPE_STRING, (QofAccessFunc) exp_getPayment, (QofSetterFunc) exp_setPayment, NULL }, 00850 { EXP_CURRENCY, QOF_TYPE_INT32, (QofAccessFunc) exp_getCurrency, (QofSetterFunc) exp_setCurrency, NULL }, 00851 { EXP_AMOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc) exp_getAmount, (QofSetterFunc) exp_setAmount, NULL }, 00852 { EXP_VENDOR, QOF_TYPE_STRING, (QofAccessFunc) exp_getVendor, (QofSetterFunc) exp_setVendor, NULL }, 00853 { EXP_CITY, QOF_TYPE_STRING, (QofAccessFunc) exp_getCity, (QofSetterFunc) exp_setCity, NULL }, 00854 { EXP_ATTENDEES, QOF_TYPE_STRING, (QofAccessFunc) exp_getAttendees, (QofSetterFunc) exp_setAttendees, NULL }, 00855 { EXP_NOTE, QOF_TYPE_STRING, (QofAccessFunc) exp_getNote, (QofSetterFunc) exp_setNote, NULL }, 00856 { EXP_DISTANCE, QOF_TYPE_STRING, (QofAccessFunc) exp_getDistance, (QofSetterFunc) exp_setDistance, NULL }, 00857 { EXP_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) exp_getCategory, (QofSetterFunc) exp_setCategory, NULL }, 00858 { EXP_KVP, QOF_TYPE_KVP, (QofAccessFunc) qof_instance_get_slots, NULL, NULL }, 00859 { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc) qof_instance_get_book, NULL, NULL }, 00860 { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc) qof_instance_get_guid, NULL, NULL }, 00861 { NULL, NULL, NULL, NULL, NULL }, 00862 }; 00863 00864 bindtextdomain (LIBRARY_GETTEXT_PACKAGE, LOCALE_DIR); 00865 00866 qof_class_register (GPE_QOF_EXPENSES, NULL, params); 00867 if(!qof_currency_table) populate_currencies(); 00868 00869 return qof_object_register (&expenses_object_def); 00870 }
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.
00445 { 00446 QofCurrency *currency; 00447 00448 currency = NULL; 00449 if(!qof_currency_table) populate_currencies(); 00450 currency = (QofCurrency*)g_hash_table_lookup( 00451 qof_currency_table, GINT_TO_POINTER(currency_code)); 00452 if(!currency) 00453 { 00454 PERR (" unsupported currency! %d", currency_code); 00455 return NULL; 00456 } 00457 kvp_frame_set_string(qof_instance_get_slots(inst), 00458 PQ_CURRENCY_MNEMONIC, currency->mnemonic); 00459 kvp_frame_set_gint64(qof_instance_get_slots(inst), 00460 PQ_CURRENCY_FRACTION, currency->fraction); 00461 if(currency->non_utf8) 00462 { 00463 gchar * k_symbol = g_strdup (currency->symbol); 00464 kvp_frame_set_string(qof_instance_get_slots(inst), 00465 PQ_CURRENCY_SYMBOL, qof_util_make_utf8(k_symbol)); 00466 } 00467 else 00468 { 00469 kvp_frame_set_string(qof_instance_get_slots(inst), 00470 PQ_CURRENCY_SYMBOL, currency->symbol); 00471 } 00472 return currency; 00473 }
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.
00431 { 00432 QofCurrency *currency; 00433 00434 currency = NULL; 00435 if(!qof_currency_table) populate_currencies(); 00436 currency = (QofCurrency*) g_hash_table_find 00437 (qof_currency_table, check_name, mnemonic); 00438 if (!currency) return NULL; 00439 qof_currency_lookup(inst, currency->pq_code); 00440 return currency; 00441 }