pilot-qof  0.2.3
qof-address.c
Go to the documentation of this file.
00001 /***************************************************************************
00002 *            qof-address.c
00003 *
00004 *  Thu Oct 21 12:44:16 2004
00005 *  Copyright  2004-2007  Neil Williams  <linux@codehelp.co.uk>
00006 ****************************************************************************/
00007 /*
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 3 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00029 #include <glib.h>
00030 #include <glib/gprintf.h>
00031 #include <qof.h>
00032 #include "pi-address.h"
00033 #include "qof-address.h"
00034 #include "qof-main.h"
00035 #include "pilot-qof.h"
00036 
00037 #define QOF_ADDRESS_DESC "Pilot-link QOF address"
00038 
00039 static G_GNUC_UNUSED QofLogModule log_module = PQ_MOD_PILOT;
00040 
00046 typedef struct
00047 {
00048     QofInstance inst;
00049     Address_t wrap;             // 0.12
00050     gchar *category;
00051     const gchar *printable;
00052 } QofAddress;
00053 
00060 static QofAddress *
00061 address_create (QofBook * book)
00062 {
00063     Address_t *qa;
00064     QofAddress *obj;
00065     QofCollection *coll;
00066     GList *all;
00067 
00068     obj = g_new0 (QofAddress, 1);
00069     qof_instance_init (&obj->inst, PILOT_LINK_QOF_ADDRESS, book);
00070     coll = qof_book_get_collection (book, PILOT_LINK_QOF_ADDRESS);
00071     all = qof_collection_get_data (coll);
00072     all = g_list_prepend (all, obj);
00073     qof_collection_set_data (coll, all);
00074     qa = &obj->wrap;
00075     qa->entry[18] = strdup ("");
00076     return obj;
00077 }
00078 
00079 Address_t * address_get_pilot (QofInstance * inst)
00080 {
00081     QofAddress * a;
00082 
00083     a = (QofAddress *)inst;
00084     return &a->wrap;
00085 }
00086 
00087 static gchar *
00088 addr_getLastname (QofAddress * a)
00089 {
00090     Address_t *qa;
00091 
00092     g_return_val_if_fail (a != NULL, NULL);
00093     qa = &a->wrap;
00094     return qa->entry[entryLastname];
00095 }
00096 
00097 static gchar *
00098 addr_getFirstname (QofAddress * a)
00099 {
00100     Address_t *qa;
00101 
00102     g_return_val_if_fail (a != NULL, NULL);
00103     qa = &a->wrap;
00104     return qa->entry[entryFirstname];
00105 }
00106 
00107 static gchar *
00108 addr_getCompany (QofAddress * a)
00109 {
00110     Address_t *qa;
00111 
00112     g_return_val_if_fail (a != NULL, NULL);
00113     qa = &a->wrap;
00114     return qa->entry[entryCompany];
00115 }
00116 
00117 static gchar *
00118 addr_getPhoneOne (QofAddress * a)
00119 {
00120     Address_t *qa;
00121 
00122     g_return_val_if_fail (a != NULL, NULL);
00123     qa = &a->wrap;
00124     return qa->entry[entryPhone1];
00125 }
00126 
00127 static gchar *
00128 addr_getPhoneTwo (QofAddress * a)
00129 {
00130     Address_t *qa;
00131 
00132     g_return_val_if_fail (a != NULL, NULL);
00133     qa = &a->wrap;
00134     return qa->entry[entryPhone2];
00135 }
00136 
00137 static gchar *
00138 addr_getPhoneThree (QofAddress * a)
00139 {
00140     Address_t *qa;
00141 
00142     g_return_val_if_fail (a != NULL, NULL);
00143     qa = &a->wrap;
00144     return qa->entry[entryPhone3];
00145 }
00146 
00147 static gchar *
00148 addr_getPhoneFour (QofAddress * a)
00149 {
00150     Address_t *qa;
00151 
00152     g_return_val_if_fail (a != NULL, NULL);
00153     qa = &a->wrap;
00154     return qa->entry[entryPhone4];
00155 }
00156 
00157 static gchar *
00158 addr_getPhoneFive (QofAddress * a)
00159 {
00160     Address_t *qa;
00161 
00162     g_return_val_if_fail (a != NULL, NULL);
00163     qa = &a->wrap;
00164     return qa->entry[entryPhone5];
00165 }
00166 
00167 static gchar *
00168 addr_getCity (QofAddress * a)
00169 {
00170     Address_t *qa;
00171 
00172     g_return_val_if_fail (a != NULL, NULL);
00173     qa = &a->wrap;
00174     return qa->entry[entryCity];
00175 }
00176 
00177 static gchar *
00178 addr_getState (QofAddress * a)
00179 {
00180     Address_t *qa;
00181 
00182     g_return_val_if_fail (a != NULL, NULL);
00183     qa = &a->wrap;
00184     return qa->entry[entryState];
00185 }
00186 
00187 static gchar *
00188 addr_getZip (QofAddress * a)
00189 {
00190     Address_t *qa;
00191 
00192     g_return_val_if_fail (a != NULL, NULL);
00193     qa = &a->wrap;
00194     return qa->entry[entryZip];
00195 }
00196 
00197 static gchar *
00198 addr_getCountry (QofAddress * a)
00199 {
00200     Address_t *qa;
00201 
00202     g_return_val_if_fail (a != NULL, NULL);
00203     qa = &a->wrap;
00204     return qa->entry[entryCountry];
00205 }
00206 
00207 static gchar *
00208 addr_getTitle (QofAddress * a)
00209 {
00210     Address_t *qa;
00211 
00212     g_return_val_if_fail (a != NULL, NULL);
00213     qa = &a->wrap;
00214     return qa->entry[entryTitle];
00215 }
00216 
00217 static gchar *
00218 addr_getAddress (QofAddress * a)
00219 {
00220     Address_t *qa;
00221 
00222     g_return_val_if_fail (a != NULL, NULL);
00223     qa = &a->wrap;
00224     return qa->entry[entryAddress];
00225 }
00226 
00227 static gchar *
00228 addr_getCustomOne (QofAddress * a)
00229 {
00230     Address_t *qa;
00231 
00232     g_return_val_if_fail (a != NULL, NULL);
00233     qa = &a->wrap;
00234     return qa->entry[entryCustom1];
00235 }
00236 
00237 static gchar *
00238 addr_getCustomTwo (QofAddress * a)
00239 {
00240     Address_t *qa;
00241 
00242     g_return_val_if_fail (a != NULL, NULL);
00243     qa = &a->wrap;
00244     return qa->entry[entryCustom2];
00245 }
00246 
00247 static gchar *
00248 addr_getCustomThree (QofAddress * a)
00249 {
00250     Address_t *qa;
00251 
00252     g_return_val_if_fail (a != NULL, NULL);
00253     qa = &a->wrap;
00254     return qa->entry[entryCustom3];
00255 }
00256 
00257 static gchar *
00258 addr_getCustomFour (QofAddress * a)
00259 {
00260     Address_t *qa;
00261 
00262     g_return_val_if_fail (a != NULL, NULL);
00263     qa = &a->wrap;
00264     return qa->entry[entryCustom4];
00265 }
00266 
00267 static gchar *
00268 addr_getNote (QofAddress * a)
00269 {
00270     Address_t *qa;
00271 
00272     g_return_val_if_fail (a != NULL, NULL);
00273     qa = &a->wrap;
00274     return qa->entry[entryNote];
00275 }
00276 
00277 static gchar *
00278 addr_getCategory (QofAddress * a)
00279 {
00280     g_return_val_if_fail (a != NULL, NULL);
00281     return (a->category);
00282 }
00283 
00284 static void
00285 addr_setLastname (QofAddress * a, gchar * h)
00286 {
00287     Address_t *qa;
00288 
00289     g_return_if_fail (a != NULL);
00290     if (!h)
00291         return;
00292     qa = &a->wrap;
00293     qa->entry[entryLastname] = g_strdup (qof_util_make_utf8 (h));
00294 }
00295 
00296 static void
00297 addr_setFirstname (QofAddress * a, gchar * h)
00298 {
00299     Address_t *qa;
00300 
00301     g_return_if_fail (a != NULL);
00302     if (!h)
00303         return;
00304     qa = &a->wrap;
00305     qa->entry[entryFirstname] = g_strdup (qof_util_make_utf8 (h));
00306 }
00307 
00308 static void
00309 addr_setCompany (QofAddress * a, gchar * h)
00310 {
00311     Address_t *qa;
00312 
00313     g_return_if_fail (a != NULL);
00314     qa = &a->wrap;
00315     qa->entry[entryCompany] = g_strdup (qof_util_make_utf8 (h));
00316 }
00317 
00318 static void
00319 addr_setPhoneOne (QofAddress * a, gchar * h)
00320 {
00321     Address_t *qa;
00322 
00323     g_return_if_fail (a != NULL);
00324     if (!h)
00325         return;
00326     qa = &a->wrap;
00327     qa->entry[entryPhone1] = g_strdup (qof_util_make_utf8 (h));
00328 }
00329 
00330 static void
00331 addr_setPhoneTwo (QofAddress * a, gchar * h)
00332 {
00333     Address_t *qa;
00334 
00335     g_return_if_fail (a != NULL);
00336     qa = &a->wrap;
00337     qa->entry[entryPhone2] = g_strdup (qof_util_make_utf8 (h));
00338 }
00339 
00340 static void
00341 addr_setPhoneThree (QofAddress * a, gchar * h)
00342 {
00343     Address_t *qa;
00344 
00345     g_return_if_fail (a != NULL);
00346     if (!h)
00347         return;
00348     qa = &a->wrap;
00349     qa->entry[entryPhone3] = g_strdup (qof_util_make_utf8 (h));
00350 }
00351 
00352 static void
00353 addr_setPhoneFour (QofAddress * a, gchar * h)
00354 {
00355     Address_t *qa;
00356 
00357     g_return_if_fail (a != NULL);
00358     qa = &a->wrap;
00359     qa->entry[entryPhone4] = g_strdup (qof_util_make_utf8 (h));
00360 }
00361 
00362 static void
00363 addr_setPhoneFive (QofAddress * a, gchar * h)
00364 {
00365     Address_t *qa;
00366 
00367     g_return_if_fail (a != NULL);
00368     if (!h)
00369         return;
00370     qa = &a->wrap;
00371     qa->entry[entryPhone5] = g_strdup (qof_util_make_utf8 (h));
00372 }
00373 
00374 static void
00375 addr_setAddress (QofAddress * a, gchar * h)
00376 {
00377     Address_t *qa;
00378 
00379     g_return_if_fail (a != NULL);
00380     if (!h)
00381         return;
00382     qa = &a->wrap;
00383     qa->entry[entryAddress] = g_strdup (qof_util_make_utf8 (h));
00384 }
00385 
00386 static void
00387 addr_setCity (QofAddress * a, gchar * h)
00388 {
00389     Address_t *qa;
00390 
00391     g_return_if_fail (a != NULL);
00392     qa = &a->wrap;
00393     qa->entry[entryCity] = strdup (qof_util_make_utf8 (h));
00394 }
00395 
00396 static void
00397 addr_setState (QofAddress * a, gchar * h)
00398 {
00399     Address_t *qa;
00400 
00401     g_return_if_fail (a != NULL);
00402     qa = &a->wrap;
00403     qa->entry[entryState] = g_strdup (qof_util_make_utf8 (h));
00404 }
00405 
00406 static void
00407 addr_setZip (QofAddress * a, gchar * h)
00408 {
00409     Address_t *qa;
00410 
00411     g_return_if_fail (a != NULL);
00412     if (!h)
00413         return;
00414     qa = &a->wrap;
00415     qa->entry[entryZip] = g_strdup (qof_util_make_utf8 (h));
00416 }
00417 
00418 static void
00419 addr_setCountry (QofAddress * a, gchar * h)
00420 {
00421     Address_t *qa;
00422 
00423     g_return_if_fail (a != NULL);
00424     qa = &a->wrap;
00425     qa->entry[entryCountry] = g_strdup (qof_util_make_utf8 (h));
00426 }
00427 
00428 static void
00429 addr_setTitle (QofAddress * a, gchar * h)
00430 {
00431     Address_t *qa;
00432 
00433     g_return_if_fail (a != NULL);
00434     if (!h)
00435         return;
00436     qa = &a->wrap;
00437     qa->entry[entryTitle] = g_strdup (qof_util_make_utf8 (h));
00438 }
00439 
00440 static void
00441 addr_setCustomOne (QofAddress * a, gchar * h)
00442 {
00443     Address_t *qa;
00444 
00445     g_return_if_fail (a != NULL);
00446     if (!h)
00447         return;
00448     qa = &a->wrap;
00449     qa->entry[entryCustom1] = g_strdup (qof_util_make_utf8 (h));
00450 }
00451 
00452 static void
00453 addr_setCustomTwo (QofAddress * a, gchar * h)
00454 {
00455     Address_t *qa;
00456 
00457     g_return_if_fail (a != NULL);
00458     if (!h)
00459         return;
00460     qa = &a->wrap;
00461     qa->entry[entryCustom2] = g_strdup (qof_util_make_utf8 (h));
00462 }
00463 
00464 static void
00465 addr_setCustomThree (QofAddress * a, gchar * h)
00466 {
00467     Address_t *qa;
00468 
00469     g_return_if_fail (a);
00470     if (!h)
00471         return;
00472     qa = &a->wrap;
00473     qa->entry[entryCustom3] = g_strdup (qof_util_make_utf8 (h));
00474 }
00475 
00476 static void
00477 addr_setCustomFour (QofAddress * a, gchar * h)
00478 {
00479     Address_t *qa;
00480 
00481     g_return_if_fail (a);
00482     if (!h)
00483         return;
00484     qa = &a->wrap;
00485     qa->entry[entryCustom4] = g_strdup (qof_util_make_utf8 (h));
00486 }
00487 
00488 static void
00489 addr_setNote (QofAddress * a, gchar * h)
00490 {
00491     Address_t *qa;
00492 
00493     g_return_if_fail (a);
00494     if (!h)
00495         return;
00496     qa = &a->wrap;
00497     qa->entry[entryNote] = g_strdup (qof_util_make_utf8 (h));
00498 }
00499 
00500 static void
00501 addr_setCategory (QofAddress * a, gchar * h)
00502 {
00503     g_return_if_fail (a);
00504     if (!h)
00505         return;
00506     a->category = g_strdup (qof_util_make_utf8 (h));
00507 }
00508 
00509 static const gchar *
00510 addressPrintable (gpointer instance)
00511 {
00512     QofAddress *obj;
00513 
00514     obj = (QofAddress *) instance;
00515     if (!obj)
00516         return NULL;
00517     if (addr_getFirstname (obj))
00518     {
00519         obj->printable = g_strconcat (addr_getFirstname (obj), " ",
00520             addr_getLastname (obj), NULL);
00521         return obj->printable;
00522     }
00523     else
00524         return addr_getTitle (obj);
00525 }
00526 
00527 static QofObject address_object_def = {
00528   interface_version:QOF_OBJECT_VERSION,
00529   e_type:PILOT_LINK_QOF_ADDRESS,
00530   type_label:QOF_ADDRESS_DESC,
00531   create:(gpointer) address_create,
00532   book_begin:NULL,
00533   book_end:NULL,
00534   is_dirty:qof_collection_is_dirty,
00535   mark_clean:qof_collection_mark_clean,
00536   foreach:qof_collection_foreach,
00537   printable:addressPrintable,
00538   version_cmp:(gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
00539 };
00540 
00541 gboolean
00542 AddressRegister (void)
00543 {
00544     static QofParam params[] = {
00545         {ADDR_LAST_NAME, QOF_TYPE_STRING, (QofAccessFunc) addr_getLastname,
00546                 (QofSetterFunc) addr_setLastname},
00547         {ADDR_FIRST_NAME, QOF_TYPE_STRING,
00548                 (QofAccessFunc) addr_getFirstname,
00549                 (QofSetterFunc) addr_setFirstname},
00550         {ADDR_COMPANY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCompany,
00551                 (QofSetterFunc) addr_setCompany},
00552         {ADDR_PHONE_ONE, QOF_TYPE_STRING, (QofAccessFunc) addr_getPhoneOne,
00553                 (QofSetterFunc) addr_setPhoneOne},
00554         {ADDR_PHONE_TWO, QOF_TYPE_STRING, (QofAccessFunc) addr_getPhoneTwo,
00555                 (QofSetterFunc) addr_setPhoneTwo},
00556         {ADDR_PHONE_THREE, QOF_TYPE_STRING,
00557                 (QofAccessFunc) addr_getPhoneThree,
00558                 (QofSetterFunc) addr_setPhoneThree},
00559         {ADDR_PHONE_FOUR, QOF_TYPE_STRING,
00560                 (QofAccessFunc) addr_getPhoneFour,
00561                 (QofSetterFunc) addr_setPhoneFour},
00562         {ADDR_PHONE_FIVE, QOF_TYPE_STRING,
00563                 (QofAccessFunc) addr_getPhoneFive,
00564                 (QofSetterFunc) addr_setPhoneFive},
00565         {ADDR_ADDRESS, QOF_TYPE_STRING, (QofAccessFunc) addr_getAddress,
00566                 (QofSetterFunc) addr_setAddress},
00567         {ADDR_CITY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCity,
00568                 (QofSetterFunc) addr_setCity},
00569         {ADDR_STATE, QOF_TYPE_STRING, (QofAccessFunc) addr_getState,
00570                 (QofSetterFunc) addr_setState},
00571         {ADDR_ZIP, QOF_TYPE_STRING, (QofAccessFunc) addr_getZip,
00572                 (QofSetterFunc) addr_setZip},
00573         {ADDR_COUNTRY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCountry,
00574                 (QofSetterFunc) addr_setCountry},
00575         {ADDR_TITLE, QOF_TYPE_STRING, (QofAccessFunc) addr_getTitle,
00576                 (QofSetterFunc) addr_setTitle},
00577         {ADDR_CUSTOM_ONE, QOF_TYPE_STRING,
00578                 (QofAccessFunc) addr_getCustomOne,
00579                 (QofSetterFunc) addr_setCustomOne},
00580         {ADDR_CUSTOM_TWO, QOF_TYPE_STRING,
00581                 (QofAccessFunc) addr_getCustomTwo,
00582                 (QofSetterFunc) addr_setCustomTwo},
00583         {ADDR_CUSTOM_THREE, QOF_TYPE_STRING,
00584                 (QofAccessFunc) addr_getCustomThree,
00585                 (QofSetterFunc) addr_setCustomThree},
00586         {ADDR_CUSTOM_FOUR, QOF_TYPE_STRING,
00587                 (QofAccessFunc) addr_getCustomFour,
00588                 (QofSetterFunc) addr_setCustomFour},
00589         {ADDR_NOTE, QOF_TYPE_STRING, (QofAccessFunc) addr_getNote,
00590                 (QofSetterFunc) addr_setNote},
00591         {ADDR_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) addr_getCategory,
00592                 (QofSetterFunc) addr_setCategory},
00593         {QOF_PARAM_BOOK, QOF_ID_BOOK,
00594                 (QofAccessFunc) qof_instance_get_book, NULL},
00595         {QOF_PARAM_GUID, QOF_TYPE_GUID,
00596                 (QofAccessFunc) qof_instance_get_guid, NULL},
00597         {NULL},
00598     };
00599 
00600     qof_class_register (PILOT_LINK_QOF_ADDRESS, NULL, params);
00601 
00602 //  pilot_qof_pack_register (&address_pack_def);
00603 
00604     return qof_object_register (&address_object_def);
00605 }
00606