r22173 - gnucash/trunk/src/engine - Add getter/setter for fake Employee name propery.

Geert Janssens gjanssens at code.gnucash.org
Tue May 8 07:38:58 EDT 2012


Author: gjanssens
Date: 2012-05-08 07:38:57 -0400 (Tue, 08 May 2012)
New Revision: 22173
Trac: http://svn.gnucash.org/trac/changeset/22173

Modified:
   gnucash/trunk/src/engine/gncEmployee.c
   gnucash/trunk/src/engine/gncEmployee.h
   gnucash/trunk/src/engine/gncOwner.c
Log:
Add getter/setter for fake Employee name propery.
This is done to get a more consistent owner interface and simplifies the python bindings

Modified: gnucash/trunk/src/engine/gncEmployee.c
===================================================================
--- gnucash/trunk/src/engine/gncEmployee.c	2012-05-08 11:38:39 UTC (rev 22172)
+++ gnucash/trunk/src/engine/gncEmployee.c	2012-05-08 11:38:57 UTC (rev 22173)
@@ -447,6 +447,18 @@
     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 @@
     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;
@@ -813,6 +836,10 @@
             (QofSetterFunc)gncEmployeeSetUsername
         },
         {
+            EMPLOYEE_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetName,
+            (QofSetterFunc)gncEmployeeSetName
+        },
+        {
             EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage,
             (QofSetterFunc)gncEmployeeSetLanguage
         },

Modified: gnucash/trunk/src/engine/gncEmployee.h
===================================================================
--- gnucash/trunk/src/engine/gncEmployee.h	2012-05-08 11:38:39 UTC (rev 22172)
+++ gnucash/trunk/src/engine/gncEmployee.h	2012-05-08 11:38:57 UTC (rev 22173)
@@ -66,6 +66,12 @@
  @{ */
 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 @@
 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 @@
 
 #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"

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2012-05-08 11:38:39 UTC (rev 22172)
+++ gnucash/trunk/src/engine/gncOwner.c	2012-05-08 11:38:57 UTC (rev 22173)
@@ -397,7 +397,7 @@
     case GNC_OWNER_VENDOR:
         return gncVendorGetName (owner->owner.vendor);
     case GNC_OWNER_EMPLOYEE:
-        return gncAddressGetName(gncEmployeeGetAddr (owner->owner.employee));
+        return gncEmployeeGetName (owner->owner.employee);
     }
 }
 



More information about the gnucash-changes mailing list