00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #include <glib.h>
00031 #include <glib/gprintf.h>
00032 #include <qof.h>
00033 #include "pi-address.h"
00034 #include "qof-address.h"
00035 #include "qof-main.h"
00036 #include "pilot-qof.h"
00037
00038 #define ADDRESS_VERSION address_v1
00039 #define QOF_ADDRESS_DESC "Pilot-link QOF address"
00040
00041 static QofLogModule log_module = PQ_MOD_PILOT;
00042
00048 typedef struct
00049 {
00050 QofInstance inst;
00051 Address_t wrap;
00052 gchar *category;
00053 const gchar *printable;
00054 } QofAddress;
00055
00062 static QofAddress *
00063 address_create (QofBook * book)
00064 {
00065 Address_t *qa;
00066 QofAddress *obj;
00067 QofCollection *coll;
00068 GList *all;
00069
00070 obj = g_new0 (QofAddress, 1);
00071 qof_instance_init (&obj->inst, PILOT_LINK_QOF_ADDRESS, book);
00072 coll = qof_book_get_collection (book, PILOT_LINK_QOF_ADDRESS);
00073 all = qof_collection_get_data (coll);
00074 all = g_list_prepend (all, obj);
00075 qof_collection_set_data (coll, all);
00076 qa = &obj->wrap;
00077 qa->entry[19] = strdup ("");
00078 return obj;
00079 }
00080
00081 static gchar *
00082 addr_getLastname (QofAddress * a)
00083 {
00084 Address_t *qa;
00085
00086 g_return_val_if_fail (a != NULL, NULL);
00087 qa = &a->wrap;
00088 return qa->entry[entryLastname];
00089 }
00090
00091 static gchar *
00092 addr_getFirstname (QofAddress * a)
00093 {
00094 Address_t *qa;
00095
00096 g_return_val_if_fail (a != NULL, NULL);
00097 qa = &a->wrap;
00098 return qa->entry[entryFirstname];
00099 }
00100
00101 static gchar *
00102 addr_getCompany (QofAddress * a)
00103 {
00104 Address_t *qa;
00105
00106 g_return_val_if_fail (a != NULL, NULL);
00107 qa = &a->wrap;
00108 return qa->entry[entryCompany];
00109 }
00110
00111 static gchar *
00112 addr_getPhoneOne (QofAddress * a)
00113 {
00114 Address_t *qa;
00115
00116 g_return_val_if_fail (a != NULL, NULL);
00117 qa = &a->wrap;
00118 return qa->entry[entryPhone1];
00119 }
00120
00121 static gchar *
00122 addr_getPhoneTwo (QofAddress * a)
00123 {
00124 Address_t *qa;
00125
00126 g_return_val_if_fail (a != NULL, NULL);
00127 qa = &a->wrap;
00128 return qa->entry[entryPhone2];
00129 }
00130
00131 static gchar *
00132 addr_getPhoneThree (QofAddress * a)
00133 {
00134 Address_t *qa;
00135
00136 g_return_val_if_fail (a != NULL, NULL);
00137 qa = &a->wrap;
00138 return qa->entry[entryPhone3];
00139 }
00140
00141 static gchar *
00142 addr_getPhoneFour (QofAddress * a)
00143 {
00144 Address_t *qa;
00145
00146 g_return_val_if_fail (a != NULL, NULL);
00147 qa = &a->wrap;
00148 return qa->entry[entryPhone4];
00149 }
00150
00151 static gchar *
00152 addr_getPhoneFive (QofAddress * a)
00153 {
00154 Address_t *qa;
00155
00156 g_return_val_if_fail (a != NULL, NULL);
00157 qa = &a->wrap;
00158 return qa->entry[entryPhone5];
00159 }
00160
00161 static gchar *
00162 addr_getCity (QofAddress * a)
00163 {
00164 Address_t *qa;
00165
00166 g_return_val_if_fail (a != NULL, NULL);
00167 qa = &a->wrap;
00168 return qa->entry[entryCity];
00169 }
00170
00171 static gchar *
00172 addr_getState (QofAddress * a)
00173 {
00174 Address_t *qa;
00175
00176 g_return_val_if_fail (a != NULL, NULL);
00177 qa = &a->wrap;
00178 return qa->entry[entryState];
00179 }
00180
00181 static gchar *
00182 addr_getZip (QofAddress * a)
00183 {
00184 Address_t *qa;
00185
00186 g_return_val_if_fail (a != NULL, NULL);
00187 qa = &a->wrap;
00188 return qa->entry[entryZip];
00189 }
00190
00191 static gchar *
00192 addr_getCountry (QofAddress * a)
00193 {
00194 Address_t *qa;
00195
00196 g_return_val_if_fail (a != NULL, NULL);
00197 qa = &a->wrap;
00198 return qa->entry[entryCountry];
00199 }
00200
00201 static gchar *
00202 addr_getTitle (QofAddress * a)
00203 {
00204 Address_t *qa;
00205
00206 g_return_val_if_fail (a != NULL, NULL);
00207 qa = &a->wrap;
00208 return qa->entry[entryTitle];
00209 }
00210
00211 static gchar *
00212 addr_getAddress (QofAddress * a)
00213 {
00214 Address_t *qa;
00215
00216 g_return_val_if_fail (a != NULL, NULL);
00217 qa = &a->wrap;
00218 return qa->entry[entryAddress];
00219 }
00220
00221 static gchar *
00222 addr_getCustomOne (QofAddress * a)
00223 {
00224 Address_t *qa;
00225
00226 g_return_val_if_fail (a != NULL, NULL);
00227 qa = &a->wrap;
00228 return qa->entry[entryCustom1];
00229 }
00230
00231 static gchar *
00232 addr_getCustomTwo (QofAddress * a)
00233 {
00234 Address_t *qa;
00235
00236 g_return_val_if_fail (a != NULL, NULL);
00237 qa = &a->wrap;
00238 return qa->entry[entryCustom2];
00239 }
00240
00241 static gchar *
00242 addr_getCustomThree (QofAddress * a)
00243 {
00244 Address_t *qa;
00245
00246 g_return_val_if_fail (a != NULL, NULL);
00247 qa = &a->wrap;
00248 return qa->entry[entryCustom3];
00249 }
00250
00251 static gchar *
00252 addr_getCustomFour (QofAddress * a)
00253 {
00254 Address_t *qa;
00255
00256 g_return_val_if_fail (a != NULL, NULL);
00257 qa = &a->wrap;
00258 return qa->entry[entryCustom4];
00259 }
00260
00261 static gchar *
00262 addr_getNote (QofAddress * a)
00263 {
00264 Address_t *qa;
00265
00266 g_return_val_if_fail (a != NULL, NULL);
00267 qa = &a->wrap;
00268 return qa->entry[entryNote];
00269 }
00270
00271 static gchar *
00272 addr_getCategory (QofAddress * a)
00273 {
00274 g_return_val_if_fail (a != NULL, NULL);
00275 return (a->category);
00276 }
00277
00278 static void
00279 addr_setLastname (QofAddress * a, gchar * h)
00280 {
00281 Address_t *qa;
00282
00283 g_return_if_fail (a != NULL);
00284 if (!h)
00285 return;
00286 qa = &a->wrap;
00287 qa->entry[entryLastname] = g_strdup (qof_main_make_utf8 (h));
00288 }
00289
00290 static void
00291 addr_setFirstname (QofAddress * a, gchar * h)
00292 {
00293 Address_t *qa;
00294
00295 g_return_if_fail (a != NULL);
00296 if (!h)
00297 return;
00298 qa = &a->wrap;
00299 qa->entry[entryFirstname] = g_strdup (qof_main_make_utf8 (h));
00300 }
00301
00302 static void
00303 addr_setCompany (QofAddress * a, gchar * h)
00304 {
00305 Address_t *qa;
00306
00307 g_return_if_fail (a != NULL);
00308 qa = &a->wrap;
00309 qa->entry[entryCompany] = g_strdup (qof_main_make_utf8 (h));
00310 }
00311
00312 static void
00313 addr_setPhoneOne (QofAddress * a, gchar * h)
00314 {
00315 Address_t *qa;
00316
00317 g_return_if_fail (a != NULL);
00318 if (!h)
00319 return;
00320 qa = &a->wrap;
00321 qa->entry[entryPhone1] = g_strdup (qof_main_make_utf8 (h));
00322 }
00323
00324 static void
00325 addr_setPhoneTwo (QofAddress * a, gchar * h)
00326 {
00327 Address_t *qa;
00328
00329 g_return_if_fail (a != NULL);
00330 qa = &a->wrap;
00331 qa->entry[entryPhone2] = g_strdup (qof_main_make_utf8 (h));
00332 }
00333
00334 static void
00335 addr_setPhoneThree (QofAddress * a, gchar * h)
00336 {
00337 Address_t *qa;
00338
00339 g_return_if_fail (a != NULL);
00340 if (!h)
00341 return;
00342 qa = &a->wrap;
00343 qa->entry[entryPhone3] = g_strdup (qof_main_make_utf8 (h));
00344 }
00345
00346 static void
00347 addr_setPhoneFour (QofAddress * a, gchar * h)
00348 {
00349 Address_t *qa;
00350
00351 g_return_if_fail (a != NULL);
00352 qa = &a->wrap;
00353 qa->entry[entryPhone4] = g_strdup (qof_main_make_utf8 (h));
00354 }
00355
00356 static void
00357 addr_setPhoneFive (QofAddress * a, gchar * h)
00358 {
00359 Address_t *qa;
00360
00361 g_return_if_fail (a != NULL);
00362 if (!h)
00363 return;
00364 qa = &a->wrap;
00365 qa->entry[entryPhone5] = g_strdup (qof_main_make_utf8 (h));
00366 }
00367
00368 static void
00369 addr_setAddress (QofAddress * a, gchar * h)
00370 {
00371 Address_t *qa;
00372
00373 g_return_if_fail (a != NULL);
00374 if (!h)
00375 return;
00376 qa = &a->wrap;
00377 qa->entry[entryAddress] = g_strdup (qof_main_make_utf8 (h));
00378 }
00379
00380 static void
00381 addr_setCity (QofAddress * a, gchar * h)
00382 {
00383 Address_t *qa;
00384
00385 g_return_if_fail (a != NULL);
00386 qa = &a->wrap;
00387 qa->entry[entryCity] = strdup (qof_main_make_utf8 (h));
00388 }
00389
00390 static void
00391 addr_setState (QofAddress * a, gchar * h)
00392 {
00393 Address_t *qa;
00394
00395 g_return_if_fail (a != NULL);
00396 qa = &a->wrap;
00397 qa->entry[entryState] = g_strdup (qof_main_make_utf8 (h));
00398 }
00399
00400 static void
00401 addr_setZip (QofAddress * a, gchar * h)
00402 {
00403 Address_t *qa;
00404
00405 g_return_if_fail (a != NULL);
00406 if (!h)
00407 return;
00408 qa = &a->wrap;
00409 qa->entry[entryZip] = g_strdup (qof_main_make_utf8 (h));
00410 }
00411
00412 static void
00413 addr_setCountry (QofAddress * a, gchar * h)
00414 {
00415 Address_t *qa;
00416
00417 g_return_if_fail (a != NULL);
00418 qa = &a->wrap;
00419 qa->entry[entryCountry] = g_strdup (qof_main_make_utf8 (h));
00420 }
00421
00422 static void
00423 addr_setTitle (QofAddress * a, gchar * h)
00424 {
00425 Address_t *qa;
00426
00427 g_return_if_fail (a != NULL);
00428 if (!h)
00429 return;
00430 qa = &a->wrap;
00431 qa->entry[entryTitle] = g_strdup (qof_main_make_utf8 (h));
00432 }
00433
00434 static void
00435 addr_setCustomOne (QofAddress * a, gchar * h)
00436 {
00437 Address_t *qa;
00438
00439 g_return_if_fail (a != NULL);
00440 if (!h)
00441 return;
00442 qa = &a->wrap;
00443 qa->entry[entryCustom1] = g_strdup (qof_main_make_utf8 (h));
00444 }
00445
00446 static void
00447 addr_setCustomTwo (QofAddress * a, gchar * h)
00448 {
00449 Address_t *qa;
00450
00451 g_return_if_fail (a != NULL);
00452 if (!h)
00453 return;
00454 qa = &a->wrap;
00455 qa->entry[entryCustom2] = g_strdup (qof_main_make_utf8 (h));
00456 }
00457
00458 static void
00459 addr_setCustomThree (QofAddress * a, gchar * h)
00460 {
00461 Address_t *qa;
00462
00463 g_return_if_fail (a);
00464 if (!h)
00465 return;
00466 qa = &a->wrap;
00467 qa->entry[entryCustom3] = g_strdup (qof_main_make_utf8 (h));
00468 }
00469
00470 static void
00471 addr_setCustomFour (QofAddress * a, gchar * h)
00472 {
00473 Address_t *qa;
00474
00475 g_return_if_fail (a);
00476 if (!h)
00477 return;
00478 qa = &a->wrap;
00479 qa->entry[entryCustom4] = g_strdup (qof_main_make_utf8 (h));
00480 }
00481
00482 static void
00483 addr_setNote (QofAddress * a, gchar * h)
00484 {
00485 Address_t *qa;
00486
00487 g_return_if_fail (a);
00488 if (!h)
00489 return;
00490 qa = &a->wrap;
00491 qa->entry[entryNote] = g_strdup (qof_main_make_utf8 (h));
00492 }
00493
00494 static void
00495 addr_setCategory (QofAddress * a, gchar * h)
00496 {
00497 g_return_if_fail (a);
00498 if (!h)
00499 return;
00500 a->category = g_strdup (qof_main_make_utf8 (h));
00501 }
00502
00524 static gint
00525 address_pack (QofEntity * ent, gpointer user_data)
00526 {
00527 PQContext *context;
00528 Address_t *qa;
00529 QofAddress *obj;
00530 gint size;
00531
00532 size = 0;
00533 context = (PQContext *) user_data;
00534 g_return_val_if_fail ((context || ent), -1);
00535 obj = (QofAddress *) ent;
00536 qa = &obj->wrap;
00537 size = pack_Address (qa, context->pi_buf, ADDRESS_VERSION);
00538 PINFO (" result=%d", size);
00539 return size;
00540 }
00541
00548 static gint
00549 address_unpack (QofEntity * ent, gpointer user_data)
00550 {
00551 pi_buffer_t *pi_buf;
00552 Address_t *qa;
00553 PQContext *context;
00554 QofAddress *obj;
00555 gint size;
00556
00557 context = (PQContext *) user_data;
00558 g_return_val_if_fail (context != NULL, -1);
00559 g_return_val_if_fail (ent != NULL, -1);
00560 obj = (QofAddress *) ent;
00561 qa = &obj->wrap;
00562 pi_buf = (pi_buffer_t *) context->pi_buf;
00563 size = 0;
00564 size = unpack_Address (qa, pi_buf, ADDRESS_VERSION);
00565 PINFO (" category=%s", context->pi_cat->name[context->ent_category]);
00566 addr_setCategory (obj, context->names[context->ent_category]);
00567 return size;
00568 }
00569
00576 static gint
00577 addr_appinfo_unpack (QofEntity * ent, gpointer user_data)
00578 {
00579 AddressAppInfo_t app_a;
00580 PQContext *context;
00581 gint name_count;
00582
00583
00584 context = (PQContext *) user_data;
00585 g_return_val_if_fail (context != NULL, -1);
00586 ENTER (" ");
00587 unpack_AddressAppInfo (&app_a, context->app_buf->data, PQ_DEF_BUFSZ);
00588 for (name_count = 0; name_count < 16; name_count++)
00589 {
00590 g_sprintf (context->names[name_count], "%s",
00591 app_a.category.name[name_count]);
00592 }
00593 context->pi_cat = &app_a.category;
00594 LEAVE (" ");
00595 return 0;
00596 }
00597
00603 static gint
00604 qof_address_free (QofEntity * ent, gpointer user_data)
00605 {
00606 Address_t *qa;
00607 QofAddress *obj;
00608
00609 g_return_val_if_fail (ent != NULL, -1);
00610 ENTER (" ");
00611 obj = (QofAddress *) ent;
00612 qa = &obj->wrap;
00613 free_Address (qa);
00614 LEAVE (" ");
00615 return 0;
00616 }
00621 static const gchar *
00622 addressPrintable (gpointer instance)
00623 {
00624 QofAddress *obj;
00625
00626 obj = (QofAddress *) instance;
00627 if (!obj)
00628 return NULL;
00629 if (addr_getFirstname (obj))
00630 {
00631 obj->printable = g_strconcat (addr_getFirstname (obj), " ",
00632 addr_getLastname (obj), NULL);
00633 return obj->printable;
00634 }
00635 else
00636 return addr_getTitle (obj);
00637 }
00638
00639 static QofObject address_object_def = {
00640 interface_version:QOF_OBJECT_VERSION,
00641 e_type:PILOT_LINK_QOF_ADDRESS,
00642 type_label:QOF_ADDRESS_DESC,
00643 create:(gpointer) address_create,
00644 book_begin:NULL,
00645 book_end:NULL,
00646 is_dirty:qof_collection_is_dirty,
00647 mark_clean:qof_collection_mark_clean,
00648 foreach:qof_collection_foreach,
00649 printable:addressPrintable,
00650 version_cmp:(gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
00651 };
00652
00653 static PQPack address_pack_def = {
00654 e_type:PILOT_LINK_QOF_ADDRESS,
00655 pack_func:address_pack,
00656 unpack_func:address_unpack,
00657 free_pack_func:qof_address_free,
00658 palm_db_name:"AddressDB",
00659 app_info_unpack:addr_appinfo_unpack,
00660 };
00661
00662 gboolean
00663 AddressRegister (void)
00664 {
00665 static QofParam params[] = {
00666 {ADDR_LAST_NAME, QOF_TYPE_STRING, (QofAccessFunc) addr_getLastname,
00667 (QofSetterFunc) addr_setLastname},
00668 {ADDR_FIRST_NAME, QOF_TYPE_STRING,
00669 (QofAccessFunc) addr_getFirstname,
00670 (QofSetterFunc) addr_setFirstname},
00671 {ADDR_COMPANY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCompany,
00672 (QofSetterFunc) addr_setCompany},
00673 {ADDR_PHONE_ONE, QOF_TYPE_STRING, (QofAccessFunc) addr_getPhoneOne,
00674 (QofSetterFunc) addr_setPhoneOne},
00675 {ADDR_PHONE_TWO, QOF_TYPE_STRING, (QofAccessFunc) addr_getPhoneTwo,
00676 (QofSetterFunc) addr_setPhoneTwo},
00677 {ADDR_PHONE_THREE, QOF_TYPE_STRING,
00678 (QofAccessFunc) addr_getPhoneThree,
00679 (QofSetterFunc) addr_setPhoneThree},
00680 {ADDR_PHONE_FOUR, QOF_TYPE_STRING,
00681 (QofAccessFunc) addr_getPhoneFour,
00682 (QofSetterFunc) addr_setPhoneFour},
00683 {ADDR_PHONE_FIVE, QOF_TYPE_STRING,
00684 (QofAccessFunc) addr_getPhoneFive,
00685 (QofSetterFunc) addr_setPhoneFive},
00686 {ADDR_ADDRESS, QOF_TYPE_STRING, (QofAccessFunc) addr_getAddress,
00687 (QofSetterFunc) addr_setAddress},
00688 {ADDR_CITY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCity,
00689 (QofSetterFunc) addr_setCity},
00690 {ADDR_STATE, QOF_TYPE_STRING, (QofAccessFunc) addr_getState,
00691 (QofSetterFunc) addr_setState},
00692 {ADDR_ZIP, QOF_TYPE_STRING, (QofAccessFunc) addr_getZip,
00693 (QofSetterFunc) addr_setZip},
00694 {ADDR_COUNTRY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCountry,
00695 (QofSetterFunc) addr_setCountry},
00696 {ADDR_TITLE, QOF_TYPE_STRING, (QofAccessFunc) addr_getTitle,
00697 (QofSetterFunc) addr_setTitle},
00698 {ADDR_CUSTOM_ONE, QOF_TYPE_STRING,
00699 (QofAccessFunc) addr_getCustomOne,
00700 (QofSetterFunc) addr_setCustomOne},
00701 {ADDR_CUSTOM_TWO, QOF_TYPE_STRING,
00702 (QofAccessFunc) addr_getCustomTwo,
00703 (QofSetterFunc) addr_setCustomTwo},
00704 {ADDR_CUSTOM_THREE, QOF_TYPE_STRING,
00705 (QofAccessFunc) addr_getCustomThree,
00706 (QofSetterFunc) addr_setCustomThree},
00707 {ADDR_CUSTOM_FOUR, QOF_TYPE_STRING,
00708 (QofAccessFunc) addr_getCustomFour,
00709 (QofSetterFunc) addr_setCustomFour},
00710 {ADDR_NOTE, QOF_TYPE_STRING, (QofAccessFunc) addr_getNote,
00711 (QofSetterFunc) addr_setNote},
00712 {ADDR_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCategory,
00713 (QofSetterFunc) addr_setCategory},
00714 {QOF_PARAM_BOOK, QOF_ID_BOOK,
00715 (QofAccessFunc) qof_instance_get_book, NULL},
00716 {QOF_PARAM_GUID, QOF_TYPE_GUID,
00717 (QofAccessFunc) qof_instance_get_guid, NULL},
00718 {NULL},
00719 };
00720
00721 qof_class_register (PILOT_LINK_QOF_ADDRESS, NULL, params);
00722
00723 pilot_qof_pack_register (&address_pack_def);
00724
00725 return qof_object_register (&address_object_def);
00726 }
00727