r18130 - gnucash/trunk/src/business/business-core - Fix bug #415127 - gncCustomer, gncEmployee and gncVendor now listen for

Phil Longstaff plongstaff at code.gnucash.org
Sat Jun 13 19:35:22 EDT 2009


Author: plongstaff
Date: 2009-06-13 19:35:22 -0400 (Sat, 13 Jun 2009)
New Revision: 18130
Trac: http://svn.gnucash.org/trac/changeset/18130

Modified:
   gnucash/trunk/src/business/business-core/gncAddress.c
   gnucash/trunk/src/business/business-core/gncCustomer.c
   gnucash/trunk/src/business/business-core/gncEmployee.c
   gnucash/trunk/src/business/business-core/gncVendor.c
Log:
Fix bug #415127 - gncCustomer, gncEmployee and gncVendor now listen for
modification events from their addresses, and mark themselves as dirty and
emit their own modification events.


Modified: gnucash/trunk/src/business/business-core/gncAddress.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.c	2009-06-13 21:50:40 UTC (rev 18129)
+++ gnucash/trunk/src/business/business-core/gncAddress.c	2009-06-13 23:35:22 UTC (rev 18130)
@@ -64,6 +64,7 @@
 {
   address->dirty = TRUE;
 
+  qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
   qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL);
 }
 

Modified: gnucash/trunk/src/business/business-core/gncCustomer.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.c	2009-06-13 21:50:40 UTC (rev 18129)
+++ gnucash/trunk/src/business/business-core/gncCustomer.c	2009-06-13 23:35:22 UTC (rev 18130)
@@ -45,6 +45,10 @@
 #include "gncJobP.h"
 #include "gncTaxTableP.h"
 
+static gint gs_address_event_handler_id = 0;
+static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
+			    gpointer user_data, gpointer event_data);
+
 struct _gncCustomer
 {
   QofInstance     inst;
@@ -129,6 +133,10 @@
   cust->credit = gnc_numeric_zero();
   cust->shipaddr = gncAddressCreate (book, &cust->inst);
 
+  if (gs_address_event_handler_id == 0) {
+    gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+  }
+
   qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
 
   return cust;
@@ -567,6 +575,35 @@
   return(strcmp(a->name, b->name));
 }
 
+/**
+ * Listens for MODIFY events from addresses.   If the address belongs to a customer,
+ * mark the customer as dirty.
+ *
+ * @param entity Entity for the event
+ * @param event_type Event type
+ * @param user_data User data registered with the handler
+ * @param event_data Event data passed with the event.
+ */
+static void
+listen_for_address_events(QofInstance *entity, QofEventId event_type,
+			    gpointer user_data, gpointer event_data)
+{
+  GncCustomer* cust;
+
+  if ((event_type & QOF_EVENT_MODIFY) == 0) {
+  	return;
+  }
+  if (!GNC_IS_ADDRESS(entity)) {
+    return;
+  }
+  if (!GNC_IS_CUSTOMER(event_data)) {
+    return;
+  }
+  cust = GNC_CUSTOMER(event_data);
+  gncCustomerBeginEdit(cust);
+  mark_customer(cust);
+  gncCustomerCommitEdit(cust);
+}
 /* ============================================================== */
 /* Package-Private functions */
 static const char * _gncCustomerPrintable (gpointer item)

Modified: gnucash/trunk/src/business/business-core/gncEmployee.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.c	2009-06-13 21:50:40 UTC (rev 18129)
+++ gnucash/trunk/src/business/business-core/gncEmployee.c	2009-06-13 23:35:22 UTC (rev 18130)
@@ -37,6 +37,10 @@
 #include "gncEmployee.h"
 #include "gncEmployeeP.h"
 
+static gint gs_address_event_handler_id = 0;
+static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
+			    gpointer user_data, gpointer event_data);
+
 struct _gncEmployee 
 {
   QofInstance     inst;
@@ -108,6 +112,10 @@
   employee->rate = gnc_numeric_zero();
   employee->active = TRUE;
   
+  if (gs_address_event_handler_id == 0) {
+    gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+  }
+
   qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
 
   return employee;
@@ -418,6 +426,36 @@
   return gncAddressGetName(v->addr);
 }
 
+/**
+ * Listens for MODIFY events from addresses.   If the address belongs to an employee,
+ * mark the employee as dirty.
+ *
+ * @param entity Entity for the event
+ * @param event_type Event type
+ * @param user_data User data registered with the handler
+ * @param event_data Event data passed with the event.
+ */
+static void
+listen_for_address_events(QofInstance *entity, QofEventId event_type,
+			    gpointer user_data, gpointer event_data)
+{
+  GncEmployee* empl;
+
+  if ((event_type & QOF_EVENT_MODIFY) == 0) {
+  	return;
+  }
+  if (!GNC_IS_ADDRESS(entity)) {
+    return;
+  }
+  if (!GNC_IS_EMPLOYEE(event_data)) {
+    return;
+  }
+  empl = GNC_EMPLOYEE(event_data);
+  gncEmployeeBeginEdit(empl);
+  mark_employee(empl);
+  gncEmployeeCommitEdit(empl);
+}
+
 static QofObject gncEmployeeDesc = 
 {
   .interface_version = QOF_OBJECT_VERSION,

Modified: gnucash/trunk/src/business/business-core/gncVendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.c	2009-06-13 21:50:40 UTC (rev 18129)
+++ gnucash/trunk/src/business/business-core/gncVendor.c	2009-06-13 23:35:22 UTC (rev 18130)
@@ -40,6 +40,10 @@
 #include "gncVendor.h"
 #include "gncVendorP.h"
 
+static gint gs_address_event_handler_id = 0;
+static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
+			    gpointer user_data, gpointer event_data);
+
 struct _gncVendor 
 {
   QofInstance     inst;
@@ -113,6 +117,10 @@
   vendor->active = TRUE;
   vendor->jobs = NULL;
 
+  if (gs_address_event_handler_id == 0) {
+    gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+  }
+
   qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
 
   return vendor;
@@ -509,6 +517,35 @@
           || gncAddressIsDirty (vendor->addr));
 }
 
+/**
+ * Listens for MODIFY events from addresses.   If the address belongs to a vendor,
+ * mark the vendor as dirty.
+ *
+ * @param entity Entity for the event
+ * @param event_type Event type
+ * @param user_data User data registered with the handler
+ * @param event_data Event data passed with the event.
+ */
+static void
+listen_for_address_events(QofInstance *entity, QofEventId event_type,
+			    gpointer user_data, gpointer event_data)
+{
+  GncVendor* v;
+
+  if ((event_type & QOF_EVENT_MODIFY) == 0) {
+  	return;
+  }
+  if (!GNC_IS_ADDRESS(entity)) {
+    return;
+  }
+  if (!GNC_IS_VENDOR(event_data)) {
+    return;
+  }
+  v = GNC_VENDOR(event_data);
+  gncVendorBeginEdit(v);
+  mark_vendor(v);
+  gncVendorCommitEdit(v);
+}
 /* ============================================================== */
 /* Package-Private functions */
 



More information about the gnucash-changes mailing list