31 #include <qofinstance-p.h>
34 #include "gncAddressP.h"
35 #include "gncCustomerP.h"
62 #define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME
64 G_INLINE_FUNC
void mark_address (
GncAddress *address);
67 address->dirty = TRUE;
69 qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
87 G_DEFINE_TYPE(
GncAddress, gnc_address, QOF_TYPE_INSTANCE);
95 gnc_address_dispose(GObject *addrp)
97 G_OBJECT_CLASS(gnc_address_parent_class)->dispose(addrp);
101 gnc_address_finalize(GObject* addrp)
103 G_OBJECT_CLASS(gnc_address_parent_class)->finalize(addrp);
107 gnc_address_get_property (GObject *
object,
114 g_return_if_fail(GNC_IS_ADDRESS(
object));
116 address = GNC_ADDRESS(
object);
120 g_value_set_string(value, address->name);
123 g_value_set_string(value, address->addr1);
126 g_value_set_string(value, address->addr2);
129 g_value_set_string(value, address->addr3);
132 g_value_set_string(value, address->addr4);
135 g_value_set_string(value, address->phone);
138 g_value_set_string(value, address->fax);
141 g_value_set_string(value, address->email);
144 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
150 gnc_address_set_property (GObject *
object,
157 g_return_if_fail(GNC_IS_ADDRESS(
object));
159 address = GNC_ADDRESS(
object);
163 gncAddressSetName(address, g_value_get_string(value));
166 gncAddressSetAddr1(address, g_value_get_string(value));
169 gncAddressSetAddr2(address, g_value_get_string(value));
172 gncAddressSetAddr3(address, g_value_get_string(value));
175 gncAddressSetAddr4(address, g_value_get_string(value));
178 gncAddressSetPhone(address, g_value_get_string(value));
181 gncAddressSetFax(address, g_value_get_string(value));
184 gncAddressSetEmail(address, g_value_get_string(value));
187 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
209 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
212 gobject_class->dispose = gnc_address_dispose;
213 gobject_class->finalize = gnc_address_finalize;
214 gobject_class->set_property = gnc_address_set_property;
215 gobject_class->get_property = gnc_address_get_property;
217 qof_class->get_display_name = NULL;
218 qof_class->refers_to_object = NULL;
219 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
221 g_object_class_install_property
224 g_param_spec_string (
"name",
226 "The address name is an arbitrary string "
227 "assigned by the user. It is intended to "
228 "a short string to identify the address.",
232 g_object_class_install_property
235 g_param_spec_string (
"addr1",
237 "The address line 1 is an arbitrary string "
238 "assigned by the user. It is the first "
239 "line of the address.",
243 g_object_class_install_property
246 g_param_spec_string (
"addr2",
248 "The address line 2 is an arbitrary string "
249 "assigned by the user. It is the second "
250 "line of the address.",
254 g_object_class_install_property
257 g_param_spec_string (
"addr3",
259 "The address line 3 is an arbitrary string "
260 "assigned by the user. It is the third "
261 "line of the address.",
265 g_object_class_install_property
268 g_param_spec_string (
"addr4",
270 "The address line 4 is an arbitrary string "
271 "assigned by the user. It is the fourth "
272 "line of the address.",
276 g_object_class_install_property
279 g_param_spec_string (
"phone",
281 "The phone number is the number at this address.",
285 g_object_class_install_property
288 g_param_spec_string (
"fax",
290 "The fax number at this address.",
294 g_object_class_install_property
297 g_param_spec_string (
"email",
299 "The e-mail address at this address.",
311 if (!book)
return NULL;
313 addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
319 addr->name = CACHE_INSERT (
"");
320 addr->addr1 = CACHE_INSERT (
"");
321 addr->addr2 = CACHE_INSERT (
"");
322 addr->addr3 = CACHE_INSERT (
"");
323 addr->addr4 = CACHE_INSERT (
"");
324 addr->phone = CACHE_INSERT (
"");
325 addr->fax = CACHE_INSERT (
"");
326 addr->email = CACHE_INSERT (
"");
332 qofAddressCreate (
QofBook *book)
335 return gncAddressCreate(book, NULL);
345 if (addr->parent == NULL)
366 qof_instance_set_destroying(addr, TRUE);
367 gncAddressCommitEdit (addr);
377 CACHE_REMOVE (addr->name);
378 CACHE_REMOVE (addr->addr1);
379 CACHE_REMOVE (addr->addr2);
380 CACHE_REMOVE (addr->addr3);
381 CACHE_REMOVE (addr->addr4);
382 CACHE_REMOVE (addr->phone);
383 CACHE_REMOVE (addr->fax);
384 CACHE_REMOVE (addr->email);
387 g_object_unref (addr);
393 #define SET_STR(obj, member, str) { \
396 if (member == str) return; \
397 if (!g_strcmp0 (member, str)) return; \
398 gncAddressBeginEdit (obj); \
399 tmp = CACHE_INSERT (str); \
400 CACHE_REMOVE (member); \
404 void gncAddressSetName (
GncAddress *addr,
const char *name)
408 SET_STR(addr, addr->name, name);
410 gncAddressCommitEdit (addr);
413 void gncAddressSetAddr1 (
GncAddress *addr,
const char *addr1)
417 SET_STR(addr, addr->addr1, addr1);
419 gncAddressCommitEdit (addr);
422 void gncAddressSetAddr2 (
GncAddress *addr,
const char *addr2)
426 SET_STR(addr, addr->addr2, addr2);
428 gncAddressCommitEdit (addr);
431 void gncAddressSetAddr3 (
GncAddress *addr,
const char *addr3)
435 SET_STR(addr, addr->addr3, addr3);
437 gncAddressCommitEdit (addr);
440 void gncAddressSetAddr4 (
GncAddress *addr,
const char *addr4)
444 SET_STR(addr, addr->addr4, addr4);
446 gncAddressCommitEdit (addr);
449 void gncAddressSetPhone (
GncAddress *addr,
const char *phone)
453 SET_STR(addr, addr->phone, phone);
455 gncAddressCommitEdit (addr);
458 void gncAddressSetFax (
GncAddress *addr,
const char *fax)
462 SET_STR(addr, addr->fax, fax);
464 gncAddressCommitEdit (addr);
467 void gncAddressSetEmail (
GncAddress *addr,
const char *email)
471 SET_STR(addr, addr->email, email);
473 gncAddressCommitEdit (addr);
483 PERR(
"Address QofBackend Failure: %d", errcode);
484 gnc_engine_signal_commit_error( errcode );
487 static void gncAddressOnDone (
QofInstance *addr) { }
492 gncAddressFree (addr);
503 gncAddressOnDone, address_free);
509 const char * gncAddressGetName (
const GncAddress *addr)
511 if (!addr)
return NULL;
515 const char * gncAddressGetAddr1 (
const GncAddress *addr)
517 if (!addr)
return NULL;
521 const char * gncAddressGetAddr2 (
const GncAddress *addr)
523 if (!addr)
return NULL;
527 const char * gncAddressGetAddr3 (
const GncAddress *addr)
529 if (!addr)
return NULL;
533 const char * gncAddressGetAddr4 (
const GncAddress *addr)
535 if (!addr)
return NULL;
539 const char * gncAddressGetPhone (
const GncAddress *addr)
541 if (!addr)
return NULL;
545 const char * gncAddressGetFax (
const GncAddress *addr)
547 if (!addr)
return NULL;
551 const char * gncAddressGetEmail (
const GncAddress *addr)
553 if (!addr)
return NULL;
557 gboolean gncAddressIsDirty (
const GncAddress *addr)
559 if (!addr)
return FALSE;
571 if (!a && !b)
return 0;
572 if (!a && b)
return 1;
573 if (a && !b)
return -1;
575 return g_strcmp0 (a->name, b->name);
581 if (a == NULL && b == NULL)
return TRUE;
582 if (a == NULL || b == NULL)
return FALSE;
584 g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
585 g_return_val_if_fail(GNC_IS_ADDRESS(b), FALSE);
587 if (g_strcmp0(a->name, b->name) != 0)
589 PWARN(
"names differ: %s vs %s", a->name, b->name);
592 if (g_strcmp0(a->addr1, b->addr1) != 0)
594 PWARN(
"address lines 1 differ: %s vs %s", a->addr1, b->addr1);
597 if (g_strcmp0(a->addr2, b->addr2) != 0)
599 PWARN(
"address lines 2 differ: %s vs %s", a->addr2, b->addr1);
602 if (g_strcmp0(a->addr3, b->addr3) != 0)
604 PWARN(
"address lines 3 differ: %s vs %s", a->addr3, b->addr3);
607 if (g_strcmp0(a->addr4, b->addr4) != 0)
609 PWARN(
"address lines 4 differ: %s vs %s", a->addr4, b->addr4);
612 if (g_strcmp0(a->phone, b->phone) != 0)
614 PWARN(
"phone numbers differ: %s vs %s", a->phone, b->phone);
617 if (g_strcmp0(a->fax, b->fax) != 0)
619 PWARN(
"fax numbers differ: %s vs %s", a->fax, b->fax);
622 if (g_strcmp0(a->email, b->email) != 0)
624 PWARN(
"email addresses differ: %s vs %s", a->email, b->email);
634 DI(.e_type = ) GNC_ID_ADDRESS,
635 DI(.type_label = ) "Address",
636 DI(.create = ) (gpointer)qofAddressCreate,
637 DI(.book_begin = ) NULL,
638 DI(.book_end = ) NULL,
642 DI(.printable = ) NULL,
646 gboolean gncAddressRegister (
void)
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
const GncGUID * qof_instance_get_guid(gconstpointer)
QofBook * qof_instance_get_book(gconstpointer)
gboolean qof_collection_is_dirty(const QofCollection *col)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
gboolean kvp_frame_is_empty(const KvpFrame *frame)
void gnc_features_set_used(QofBook *book, const gchar *feature)
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_fcn, const QofParam *params)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
#define QOF_OBJECT_VERSION
gboolean qof_commit_edit(QofInstance *inst)
#define PERR(format, args...)
int gncAddressCompare(const GncAddress *a, const GncAddress *b)
compare two addresses
void qof_collection_foreach(const QofCollection *, QofInstanceForeachCB, gpointer user_data)
#define PWARN(format, args...)
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_begin_edit(QofInstance *inst)
int(* QofSortFunc)(gconstpointer, gconstpointer)
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
void qof_collection_mark_clean(QofCollection *)
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b)
Deeply compare two addresses.
gboolean qof_choice_add_class(const char *choice, char *add, char *param_name)
Add the choices for this parameter to the object.
void(* QofSetterFunc)(gpointer, gpointer)
gboolean qof_object_register(const QofObject *object)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
#define QOF_TYPE_CHOICE
Identify an object as containing a choice.
const gchar * QofLogModule
Utility functions for file access.