From dbcd08db01c0a33ce404b526c522c7713971210e Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 8 May 2012 11:38:57 +0000 Subject: [PATCH] Add getter/setter for fake Employee name propery. This is done to get a more consistent owner interface and simplifies the python bindings git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22173 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/gncEmployee.c | 27 +++++++++++++++++++++++++++ src/engine/gncEmployee.h | 13 +++++++++++++ src/engine/gncOwner.c | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/engine/gncEmployee.c b/src/engine/gncEmployee.c index decbb66325..ce31a6c087 100644 --- a/src/engine/gncEmployee.c +++ b/src/engine/gncEmployee.c @@ -447,6 +447,18 @@ void gncEmployeeSetUsername (GncEmployee *employee, const char *username) gncEmployeeCommitEdit (employee); } +/* Employees don't have a name property defined, but + * in order to get a consistent interface with other owner types, + * this function fakes one by setting the name property of + * the employee's address. + */ +void gncEmployeeSetName (GncEmployee *employee, const char *name) +{ + if (!employee) return; + if (!name) return; + gncAddressSetName (gncEmployeeGetAddr (employee), name); +} + void gncEmployeeSetLanguage (GncEmployee *employee, const char *language) { if (!employee) return; @@ -555,6 +567,17 @@ const char * gncEmployeeGetUsername (const GncEmployee *employee) return employee->username; } +/* Employees don't have a name property defined, but + * in order to get a consistent interface with other owner types, + * this function fakes one by returning the name property of + * the employee's address. + */ +const char * gncEmployeeGetName (const GncEmployee *employee) +{ + if (!employee) return NULL; + return gncAddressGetName ( gncEmployeeGetAddr (employee)); +} + GncAddress * gncEmployeeGetAddr (const GncEmployee *employee) { if (!employee) return NULL; @@ -812,6 +835,10 @@ gboolean gncEmployeeRegister (void) EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername, (QofSetterFunc)gncEmployeeSetUsername }, + { + EMPLOYEE_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetName, + (QofSetterFunc)gncEmployeeSetName + }, { EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage, (QofSetterFunc)gncEmployeeSetLanguage diff --git a/src/engine/gncEmployee.h b/src/engine/gncEmployee.h index 6e448895dd..901123b621 100644 --- a/src/engine/gncEmployee.h +++ b/src/engine/gncEmployee.h @@ -66,6 +66,12 @@ int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b); @{ */ void gncEmployeeSetID (GncEmployee *employee, const char *id); void gncEmployeeSetUsername (GncEmployee *employee, const char *username); +/* Note: Employees don't have a name property defined, but + * in order to get a consistent interface with other owner types, + * this function fakes one by setting the name property of + * the employee's address. + */ +void gncEmployeeSetName (GncEmployee *employee, const char *name); void gncEmployeeSetLanguage (GncEmployee *employee, const char *language); void gncEmployeeSetAcl (GncEmployee *employee, const char *acl); void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday); @@ -82,6 +88,12 @@ void qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent); QofBook * gncEmployeeGetBook (GncEmployee *employee); const char * gncEmployeeGetID (const GncEmployee *employee); const char * gncEmployeeGetUsername (const GncEmployee *employee); +/* Note: Employees don't have a name property defined, but + * in order to get a consistent interface with other owner types, + * this function fakes one by returning the name property of + * the employee's address. + */ +const char * gncEmployeeGetName (const GncEmployee *employee); GncAddress * gncEmployeeGetAddr (const GncEmployee *employee); const char * gncEmployeeGetLanguage (const GncEmployee *employee); const char * gncEmployeeGetAcl (const GncEmployee *employee); @@ -107,6 +119,7 @@ static inline GncEmployee * gncEmployeeLookup (const QofBook *book, const GncGUI #define EMPLOYEE_ID "id" #define EMPLOYEE_USERNAME "username" +#define EMPLOYEE_NAME "name" #define EMPLOYEE_ADDR "addr" #define EMPLOYEE_LANGUAGE "native language" #define EMPLOYEE_ACL "acl" diff --git a/src/engine/gncOwner.c b/src/engine/gncOwner.c index 575f4c6f44..7a65c2212f 100644 --- a/src/engine/gncOwner.c +++ b/src/engine/gncOwner.c @@ -397,7 +397,7 @@ const char * gncOwnerGetName (const GncOwner *owner) case GNC_OWNER_VENDOR: return gncVendorGetName (owner->owner.vendor); case GNC_OWNER_EMPLOYEE: - return gncAddressGetName(gncEmployeeGetAddr (owner->owner.employee)); + return gncEmployeeGetName (owner->owner.employee); } }