diff --git a/src/business/business-core/gncAddress.c b/src/business/business-core/gncAddress.c index a3a5df3b96..5be503a2f1 100644 --- a/src/business/business-core/gncAddress.c +++ b/src/business/business-core/gncAddress.c @@ -64,6 +64,7 @@ void mark_address (GncAddress *address) { address->dirty = TRUE; + qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent); qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL); } diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c index e1a696f513..51b874911e 100644 --- a/src/business/business-core/gncCustomer.c +++ b/src/business/business-core/gncCustomer.c @@ -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 @@ GncCustomer *gncCustomerCreate (QofBook *book) 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 @@ int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b) 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) diff --git a/src/business/business-core/gncEmployee.c b/src/business/business-core/gncEmployee.c index 4e368a5f66..26547c53fd 100644 --- a/src/business/business-core/gncEmployee.c +++ b/src/business/business-core/gncEmployee.c @@ -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 @@ GncEmployee *gncEmployeeCreate (QofBook *book) 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 @@ static const char * _gncEmployeePrintable (gpointer item) 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, diff --git a/src/business/business-core/gncVendor.c b/src/business/business-core/gncVendor.c index 2f2707f47f..2068dcf841 100644 --- a/src/business/business-core/gncVendor.c +++ b/src/business/business-core/gncVendor.c @@ -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 @@ GncVendor *gncVendorCreate (QofBook *book) 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 @@ gboolean gncVendorIsDirty (const GncVendor *vendor) || 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 */