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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18130 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2009-06-13 23:35:22 +00:00
parent 6ff4b73352
commit c04176b323
4 changed files with 113 additions and 0 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -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,

View File

@ -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 */