31 #include <qofinstance-p.h> 34 #include "gncAddressP.h" 35 #include "gncCustomerP.h" 57 QofInstanceClass parent_class;
60 static QofLogModule log_module = GNC_MOD_BUSINESS;
62 #define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME 64 static inline void mark_address (
GncAddress *address);
67 address->dirty = TRUE;
70 qof_instance_set_dirty(address->parent);
71 qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
89 G_DEFINE_TYPE(
GncAddress, gnc_address, QOF_TYPE_INSTANCE)
97 gnc_address_dispose(GObject *addrp)
99 G_OBJECT_CLASS(gnc_address_parent_class)->dispose(addrp);
103 gnc_address_finalize(GObject* addrp)
105 G_OBJECT_CLASS(gnc_address_parent_class)->finalize(addrp);
109 gnc_address_get_property (GObject *
object,
116 g_return_if_fail(GNC_IS_ADDRESS(
object));
118 address = GNC_ADDRESS(
object);
122 g_value_set_string(value, address->name);
125 g_value_set_string(value, address->addr1);
128 g_value_set_string(value, address->addr2);
131 g_value_set_string(value, address->addr3);
134 g_value_set_string(value, address->addr4);
137 g_value_set_string(value, address->phone);
140 g_value_set_string(value, address->fax);
143 g_value_set_string(value, address->email);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
152 gnc_address_set_property (GObject *
object,
159 g_return_if_fail(GNC_IS_ADDRESS(
object));
161 address = GNC_ADDRESS(
object);
165 gncAddressSetName(address, g_value_get_string(value));
168 gncAddressSetAddr1(address, g_value_get_string(value));
171 gncAddressSetAddr2(address, g_value_get_string(value));
174 gncAddressSetAddr3(address, g_value_get_string(value));
177 gncAddressSetAddr4(address, g_value_get_string(value));
180 gncAddressSetPhone(address, g_value_get_string(value));
183 gncAddressSetFax(address, g_value_get_string(value));
186 gncAddressSetEmail(address, g_value_get_string(value));
189 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
209 gnc_address_class_init (GncAddressClass *klass)
211 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
212 QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
214 gobject_class->dispose = gnc_address_dispose;
215 gobject_class->finalize = gnc_address_finalize;
216 gobject_class->set_property = gnc_address_set_property;
217 gobject_class->get_property = gnc_address_get_property;
219 qof_class->get_display_name = NULL;
220 qof_class->refers_to_object = NULL;
221 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
223 g_object_class_install_property
226 g_param_spec_string (
"name",
228 "The address name is an arbitrary string " 229 "assigned by the user. It is intended to " 230 "a short string to identify the address.",
234 g_object_class_install_property
237 g_param_spec_string (
"addr1",
239 "The address line 1 is an arbitrary string " 240 "assigned by the user. It is the first " 241 "line of the address.",
245 g_object_class_install_property
248 g_param_spec_string (
"addr2",
250 "The address line 2 is an arbitrary string " 251 "assigned by the user. It is the second " 252 "line of the address.",
256 g_object_class_install_property
259 g_param_spec_string (
"addr3",
261 "The address line 3 is an arbitrary string " 262 "assigned by the user. It is the third " 263 "line of the address.",
267 g_object_class_install_property
270 g_param_spec_string (
"addr4",
272 "The address line 4 is an arbitrary string " 273 "assigned by the user. It is the fourth " 274 "line of the address.",
278 g_object_class_install_property
281 g_param_spec_string (
"phone",
283 "The phone number is the number at this address.",
287 g_object_class_install_property
290 g_param_spec_string (
"fax",
292 "The fax number at this address.",
296 g_object_class_install_property
299 g_param_spec_string (
"email",
301 "The e-mail address at this address.",
309 gncAddressCreate (QofBook *book,
QofInstance *prnt)
313 if (!book)
return NULL;
315 addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
321 addr->name = CACHE_INSERT (
"");
322 addr->addr1 = CACHE_INSERT (
"");
323 addr->addr2 = CACHE_INSERT (
"");
324 addr->addr3 = CACHE_INSERT (
"");
325 addr->addr4 = CACHE_INSERT (
"");
326 addr->phone = CACHE_INSERT (
"");
327 addr->fax = CACHE_INSERT (
"");
328 addr->email = CACHE_INSERT (
"");
334 qofAddressCreate (QofBook *book)
337 return gncAddressCreate(book, NULL);
347 if (addr->parent == NULL)
368 qof_instance_set_destroying(addr, TRUE);
369 gncAddressCommitEdit (addr);
379 CACHE_REMOVE (addr->name);
380 CACHE_REMOVE (addr->addr1);
381 CACHE_REMOVE (addr->addr2);
382 CACHE_REMOVE (addr->addr3);
383 CACHE_REMOVE (addr->addr4);
384 CACHE_REMOVE (addr->phone);
385 CACHE_REMOVE (addr->fax);
386 CACHE_REMOVE (addr->email);
389 g_object_unref (addr);
395 #define SET_STR(obj, member, str) { \ 396 if (member == str) return; \ 397 if (!g_strcmp0 (member, str)) return; \ 398 gncAddressBeginEdit (obj); \ 399 CACHE_REPLACE(member, str); \ 402 void gncAddressSetName (
GncAddress *addr,
const char *name)
406 SET_STR(addr, addr->name, name);
408 gncAddressCommitEdit (addr);
411 void gncAddressSetAddr1 (
GncAddress *addr,
const char *addr1)
415 SET_STR(addr, addr->addr1, addr1);
417 gncAddressCommitEdit (addr);
420 void gncAddressSetAddr2 (
GncAddress *addr,
const char *addr2)
424 SET_STR(addr, addr->addr2, addr2);
426 gncAddressCommitEdit (addr);
429 void gncAddressSetAddr3 (
GncAddress *addr,
const char *addr3)
433 SET_STR(addr, addr->addr3, addr3);
435 gncAddressCommitEdit (addr);
438 void gncAddressSetAddr4 (
GncAddress *addr,
const char *addr4)
442 SET_STR(addr, addr->addr4, addr4);
444 gncAddressCommitEdit (addr);
447 void gncAddressSetPhone (
GncAddress *addr,
const char *phone)
451 SET_STR(addr, addr->phone, phone);
453 gncAddressCommitEdit (addr);
456 void gncAddressSetFax (
GncAddress *addr,
const char *fax)
460 SET_STR(addr, addr->fax, fax);
462 gncAddressCommitEdit (addr);
465 void gncAddressSetEmail (
GncAddress *addr,
const char *email)
469 SET_STR(addr, addr->email, email);
471 gncAddressCommitEdit (addr);
481 PERR(
"Address QofBackend Failure: %d", errcode);
482 gnc_engine_signal_commit_error( errcode );
485 static void gncAddressOnDone (
QofInstance *addr) { }
490 gncAddressFree (addr);
501 gncAddressOnDone, address_free);
507 const char * gncAddressGetName (
const GncAddress *addr)
509 if (!addr)
return NULL;
513 const char * gncAddressGetAddr1 (
const GncAddress *addr)
515 if (!addr)
return NULL;
519 const char * gncAddressGetAddr2 (
const GncAddress *addr)
521 if (!addr)
return NULL;
525 const char * gncAddressGetAddr3 (
const GncAddress *addr)
527 if (!addr)
return NULL;
531 const char * gncAddressGetAddr4 (
const GncAddress *addr)
533 if (!addr)
return NULL;
537 const char * gncAddressGetPhone (
const GncAddress *addr)
539 if (!addr)
return NULL;
543 const char * gncAddressGetFax (
const GncAddress *addr)
545 if (!addr)
return NULL;
549 const char * gncAddressGetEmail (
const GncAddress *addr)
551 if (!addr)
return NULL;
555 gboolean gncAddressIsDirty (
const GncAddress *addr)
557 if (!addr)
return FALSE;
569 if (!a && !b)
return 0;
570 if (!a && b)
return 1;
571 if (a && !b)
return -1;
573 return g_strcmp0 (a->name, b->name);
579 if (a == NULL && b == NULL)
return TRUE;
580 if (a == NULL || b == NULL)
return FALSE;
582 g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
583 g_return_val_if_fail(GNC_IS_ADDRESS(b), FALSE);
585 if (g_strcmp0(a->name, b->name) != 0)
587 PWARN(
"names differ: %s vs %s", a->name, b->name);
590 if (g_strcmp0(a->addr1, b->addr1) != 0)
592 PWARN(
"address lines 1 differ: %s vs %s", a->addr1, b->addr1);
595 if (g_strcmp0(a->addr2, b->addr2) != 0)
597 PWARN(
"address lines 2 differ: %s vs %s", a->addr2, b->addr1);
600 if (g_strcmp0(a->addr3, b->addr3) != 0)
602 PWARN(
"address lines 3 differ: %s vs %s", a->addr3, b->addr3);
605 if (g_strcmp0(a->addr4, b->addr4) != 0)
607 PWARN(
"address lines 4 differ: %s vs %s", a->addr4, b->addr4);
610 if (g_strcmp0(a->phone, b->phone) != 0)
612 PWARN(
"phone numbers differ: %s vs %s", a->phone, b->phone);
615 if (g_strcmp0(a->fax, b->fax) != 0)
617 PWARN(
"fax numbers differ: %s vs %s", a->fax, b->fax);
620 if (g_strcmp0(a->email, b->email) != 0)
622 PWARN(
"email addresses differ: %s vs %s", a->email, b->email);
629 static QofObject GncAddressDesc =
632 DI(.e_type = ) GNC_ID_ADDRESS,
633 DI(.type_label = ) "Address",
634 DI(.create = ) (gpointer)qofAddressCreate,
635 DI(.book_begin = ) NULL,
636 DI(.book_end = ) NULL,
639 DI(.foreach = ) qof_collection_foreach,
640 DI(.printable = ) NULL,
644 gboolean gncAddressRegister (
void)
646 static QofParam params[] =
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature.
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
int gncAddressCompare(const GncAddress *a, const GncAddress *b)
compare two addresses
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
#define PWARN(format, args...)
Log a warning.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b)
Deeply compare two addresses.
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
gboolean qof_instance_has_kvp(QofInstance *inst)
Report whether a QofInstance has anything stored in KVP.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Utility functions for file access.