LCOV - code coverage report
Current view: top level - libgnucash/engine - gncAddress.c (source / functions) Coverage Total Hit
Test: gnucash.info Lines: 83.6 % 275 230
Test Date: 2025-02-07 16:25:45 Functions: 86.0 % 43 37
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /********************************************************************\
       2                 :             :  * gncAddress.c -- an Address object                                *
       3                 :             :  *                                                                  *
       4                 :             :  * This program is free software; you can redistribute it and/or    *
       5                 :             :  * modify it under the terms of the GNU General Public License as   *
       6                 :             :  * published by the Free Software Foundation; either version 2 of   *
       7                 :             :  * the License, or (at your option) any later version.              *
       8                 :             :  *                                                                  *
       9                 :             :  * This program is distributed in the hope that it will be useful,  *
      10                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
      11                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
      12                 :             :  * GNU General Public License for more details.                     *
      13                 :             :  *                                                                  *
      14                 :             :  * You should have received a copy of the GNU General Public License*
      15                 :             :  * along with this program; if not, contact:                        *
      16                 :             :  *                                                                  *
      17                 :             :  * Free Software Foundation           Voice:  +1-617-542-5942       *
      18                 :             :  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
      19                 :             :  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
      20                 :             :  *                                                                  *
      21                 :             : \********************************************************************/
      22                 :             : 
      23                 :             : /*
      24                 :             :  * Copyright (C) 2001 Derek Atkins
      25                 :             :  * Author: Derek Atkins <warlord@MIT.EDU>
      26                 :             :  */
      27                 :             : 
      28                 :             : #include <config.h>
      29                 :             : 
      30                 :             : #include <glib.h>
      31                 :             : #include <qofinstance-p.h>
      32                 :             : 
      33                 :             : #include "gncAddress.h"
      34                 :             : #include "gncAddressP.h"
      35                 :             : #include "gncCustomerP.h"
      36                 :             : #include "gnc-features.h"
      37                 :             : 
      38                 :             : struct _gncAddress
      39                 :             : {
      40                 :             :     QofInstance inst;
      41                 :             : 
      42                 :             :     QofBook *     book;
      43                 :             :     QofInstance * parent;
      44                 :             :     gboolean      dirty;
      45                 :             :     const char *  name;
      46                 :             :     const char *  addr1;
      47                 :             :     const char *  addr2;
      48                 :             :     const char *  addr3;
      49                 :             :     const char *  addr4;
      50                 :             :     const char *  phone;
      51                 :             :     const char *  fax;
      52                 :             :     const char *  email;
      53                 :             : };
      54                 :             : 
      55                 :             : struct _gncAddressClass
      56                 :             : {
      57                 :             :     QofInstanceClass parent_class;
      58                 :             : };
      59                 :             : 
      60                 :             : static QofLogModule log_module = GNC_MOD_BUSINESS;
      61                 :             : 
      62                 :             : #define _GNC_MOD_NAME   GNC_ADDRESS_MODULE_NAME
      63                 :             : 
      64                 :             : static inline void mark_address (GncAddress *address);
      65                 :          39 : void mark_address (GncAddress *address)
      66                 :             : {
      67                 :          39 :     address->dirty = TRUE;
      68                 :             : 
      69                 :          39 :     if (address->parent)
      70                 :          39 :         qof_instance_set_dirty(address->parent);
      71                 :          39 :     qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
      72                 :          39 :     qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL);
      73                 :          39 : }
      74                 :             : 
      75                 :             : enum
      76                 :             : {
      77                 :             :     PROP_0,
      78                 :             :     PROP_NAME,
      79                 :             :     PROP_ADDR1,
      80                 :             :     PROP_ADDR2,
      81                 :             :     PROP_ADDR3,
      82                 :             :     PROP_ADDR4,
      83                 :             :     PROP_PHONE,
      84                 :             :     PROP_FAX,
      85                 :             :     PROP_EMAIL
      86                 :             : };
      87                 :             : 
      88                 :             : /* GObject Initialization */
      89                 :      296849 : G_DEFINE_TYPE(GncAddress, gnc_address, QOF_TYPE_INSTANCE)
      90                 :             : 
      91                 :             : static void
      92                 :         117 : gnc_address_init(GncAddress* addr)
      93                 :             : {
      94                 :         117 : }
      95                 :             : 
      96                 :             : static void
      97                 :          69 : gnc_address_dispose(GObject *addrp)
      98                 :             : {
      99                 :          69 :     G_OBJECT_CLASS(gnc_address_parent_class)->dispose(addrp);
     100                 :          69 : }
     101                 :             : 
     102                 :             : static void
     103                 :          69 : gnc_address_finalize(GObject* addrp)
     104                 :             : {
     105                 :          69 :     G_OBJECT_CLASS(gnc_address_parent_class)->finalize(addrp);
     106                 :          69 : }
     107                 :             : 
     108                 :             : static void
     109                 :          32 : gnc_address_get_property (GObject         *object,
     110                 :             :                           guint            prop_id,
     111                 :             :                           GValue          *value,
     112                 :             :                           GParamSpec      *pspec)
     113                 :             : {
     114                 :             :     GncAddress *address;
     115                 :             : 
     116                 :          32 :     g_return_if_fail(GNC_IS_ADDRESS(object));
     117                 :             : 
     118                 :          32 :     address = GNC_ADDRESS(object);
     119                 :          32 :     switch (prop_id)
     120                 :             :     {
     121                 :           4 :     case PROP_NAME:
     122                 :           4 :         g_value_set_string(value, address->name);
     123                 :           4 :         break;
     124                 :           4 :     case PROP_ADDR1:
     125                 :           4 :         g_value_set_string(value, address->addr1);
     126                 :           4 :         break;
     127                 :           4 :     case PROP_ADDR2:
     128                 :           4 :         g_value_set_string(value, address->addr2);
     129                 :           4 :         break;
     130                 :           4 :     case PROP_ADDR3:
     131                 :           4 :         g_value_set_string(value, address->addr3);
     132                 :           4 :         break;
     133                 :           4 :     case PROP_ADDR4:
     134                 :           4 :         g_value_set_string(value, address->addr4);
     135                 :           4 :         break;
     136                 :           4 :     case PROP_PHONE:
     137                 :           4 :         g_value_set_string(value, address->phone);
     138                 :           4 :         break;
     139                 :           4 :     case PROP_FAX:
     140                 :           4 :         g_value_set_string(value, address->fax);
     141                 :           4 :         break;
     142                 :           4 :     case PROP_EMAIL:
     143                 :           4 :         g_value_set_string(value, address->email);
     144                 :           4 :         break;
     145                 :           0 :     default:
     146                 :           0 :         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     147                 :           0 :         break;
     148                 :             :     }
     149                 :             : }
     150                 :             : 
     151                 :             : static void
     152                 :          32 : gnc_address_set_property (GObject         *object,
     153                 :             :                           guint            prop_id,
     154                 :             :                           const GValue          *value,
     155                 :             :                           GParamSpec      *pspec)
     156                 :             : {
     157                 :             :     GncAddress *address;
     158                 :             : 
     159                 :          32 :     g_return_if_fail(GNC_IS_ADDRESS(object));
     160                 :             : 
     161                 :          32 :     address = GNC_ADDRESS(object);
     162                 :          32 :     switch (prop_id)
     163                 :             :     {
     164                 :           4 :     case PROP_NAME:
     165                 :           4 :         gncAddressSetName(address, g_value_get_string(value));
     166                 :           4 :         break;
     167                 :           4 :     case PROP_ADDR1:
     168                 :           4 :         gncAddressSetAddr1(address, g_value_get_string(value));
     169                 :           4 :         break;
     170                 :           4 :     case PROP_ADDR2:
     171                 :           4 :         gncAddressSetAddr2(address, g_value_get_string(value));
     172                 :           4 :         break;
     173                 :           4 :     case PROP_ADDR3:
     174                 :           4 :         gncAddressSetAddr3(address, g_value_get_string(value));
     175                 :           4 :         break;
     176                 :           4 :     case PROP_ADDR4:
     177                 :           4 :         gncAddressSetAddr4(address, g_value_get_string(value));
     178                 :           4 :         break;
     179                 :           4 :     case PROP_PHONE:
     180                 :           4 :         gncAddressSetPhone(address, g_value_get_string(value));
     181                 :           4 :         break;
     182                 :           4 :     case PROP_FAX:
     183                 :           4 :         gncAddressSetFax(address, g_value_get_string(value));
     184                 :           4 :         break;
     185                 :           4 :     case PROP_EMAIL:
     186                 :           4 :         gncAddressSetEmail(address, g_value_get_string(value));
     187                 :           4 :         break;
     188                 :           0 :     default:
     189                 :           0 :         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     190                 :           0 :         break;
     191                 :             :     }
     192                 :             : }
     193                 :             : 
     194                 :             : /** Returns a list of my type of object which refers to an object.  For example, when called as
     195                 :             :         qof_instance_get_typed_referring_object_list(taxtable, account);
     196                 :             :     it will return the list of taxtables which refer to a specific account.  The result should be the
     197                 :             :     same regardless of which taxtable object is used.  The list must be freed by the caller but the
     198                 :             :     objects on the list must not.
     199                 :             :  */
     200                 :             : static GList*
     201                 :           0 : impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
     202                 :             : {
     203                 :             :     /* Refers to nothing.  The parent field doesn't really count since the parent knows which address
     204                 :             :        belongs to it. */
     205                 :           0 :     return NULL;
     206                 :             : }
     207                 :             : 
     208                 :             : static void
     209                 :          15 : gnc_address_class_init (GncAddressClass *klass)
     210                 :             : {
     211                 :          15 :     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
     212                 :          15 :     QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
     213                 :             : 
     214                 :          15 :     gobject_class->dispose = gnc_address_dispose;
     215                 :          15 :     gobject_class->finalize = gnc_address_finalize;
     216                 :          15 :     gobject_class->set_property = gnc_address_set_property;
     217                 :          15 :     gobject_class->get_property = gnc_address_get_property;
     218                 :             : 
     219                 :          15 :     qof_class->get_display_name = NULL;
     220                 :          15 :     qof_class->refers_to_object = NULL;
     221                 :          15 :     qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
     222                 :             : 
     223                 :          15 :     g_object_class_install_property
     224                 :             :     (gobject_class,
     225                 :             :      PROP_NAME,
     226                 :             :      g_param_spec_string ("name",
     227                 :             :                           "Address 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.",
     231                 :             :                           NULL,
     232                 :             :                           G_PARAM_READWRITE));
     233                 :             : 
     234                 :          15 :     g_object_class_install_property
     235                 :             :     (gobject_class,
     236                 :             :      PROP_ADDR1,
     237                 :             :      g_param_spec_string ("addr1",
     238                 :             :                           "Address Line 1",
     239                 :             :                           "The address line 1 is an arbitrary string "
     240                 :             :                           "assigned by the user.  It is the first "
     241                 :             :                           "line of the address.",
     242                 :             :                           NULL,
     243                 :             :                           G_PARAM_READWRITE));
     244                 :             : 
     245                 :          15 :     g_object_class_install_property
     246                 :             :     (gobject_class,
     247                 :             :      PROP_ADDR2,
     248                 :             :      g_param_spec_string ("addr2",
     249                 :             :                           "Address Line 2",
     250                 :             :                           "The address line 2 is an arbitrary string "
     251                 :             :                           "assigned by the user.  It is the second "
     252                 :             :                           "line of the address.",
     253                 :             :                           NULL,
     254                 :             :                           G_PARAM_READWRITE));
     255                 :             : 
     256                 :          15 :     g_object_class_install_property
     257                 :             :     (gobject_class,
     258                 :             :      PROP_ADDR3,
     259                 :             :      g_param_spec_string ("addr3",
     260                 :             :                           "Address Line 3",
     261                 :             :                           "The address line 3 is an arbitrary string "
     262                 :             :                           "assigned by the user.  It is the third "
     263                 :             :                           "line of the address.",
     264                 :             :                           NULL,
     265                 :             :                           G_PARAM_READWRITE));
     266                 :             : 
     267                 :          15 :     g_object_class_install_property
     268                 :             :     (gobject_class,
     269                 :             :      PROP_ADDR4,
     270                 :             :      g_param_spec_string ("addr4",
     271                 :             :                           "Address Line 4",
     272                 :             :                           "The address line 4 is an arbitrary string "
     273                 :             :                           "assigned by the user.  It is the fourth "
     274                 :             :                           "line of the address.",
     275                 :             :                           NULL,
     276                 :             :                           G_PARAM_READWRITE));
     277                 :             : 
     278                 :          15 :     g_object_class_install_property
     279                 :             :     (gobject_class,
     280                 :             :      PROP_PHONE,
     281                 :             :      g_param_spec_string ("phone",
     282                 :             :                           "Phone",
     283                 :             :                           "The phone number is the number at this address.",
     284                 :             :                           NULL,
     285                 :             :                           G_PARAM_READWRITE));
     286                 :             : 
     287                 :          15 :     g_object_class_install_property
     288                 :             :     (gobject_class,
     289                 :             :      PROP_FAX,
     290                 :             :      g_param_spec_string ("fax",
     291                 :             :                           "Fax",
     292                 :             :                           "The fax number at this address.",
     293                 :             :                           NULL,
     294                 :             :                           G_PARAM_READWRITE));
     295                 :             : 
     296                 :          15 :     g_object_class_install_property
     297                 :             :     (gobject_class,
     298                 :             :      PROP_EMAIL,
     299                 :             :      g_param_spec_string ("email",
     300                 :             :                           "E-mail address",
     301                 :             :                           "The e-mail address at this address.",
     302                 :             :                           NULL,
     303                 :             :                           G_PARAM_READWRITE));
     304                 :          15 : }
     305                 :             : 
     306                 :             : /* Create/Destroy functions */
     307                 :             : 
     308                 :             : GncAddress *
     309                 :         118 : gncAddressCreate (QofBook *book, QofInstance *prnt)
     310                 :             : {
     311                 :             :     GncAddress *addr;
     312                 :             : 
     313                 :         118 :     if (!book) return NULL;
     314                 :             : 
     315                 :         117 :     addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
     316                 :         117 :     qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
     317                 :         117 :     addr->book = book;
     318                 :         117 :     addr->dirty = FALSE;
     319                 :         117 :     addr->parent = prnt;
     320                 :             : 
     321                 :         117 :     addr->name = CACHE_INSERT ("");
     322                 :         117 :     addr->addr1 = CACHE_INSERT ("");
     323                 :         117 :     addr->addr2 = CACHE_INSERT ("");
     324                 :         117 :     addr->addr3 = CACHE_INSERT ("");
     325                 :         117 :     addr->addr4 = CACHE_INSERT ("");
     326                 :         117 :     addr->phone = CACHE_INSERT ("");
     327                 :         117 :     addr->fax = CACHE_INSERT ("");
     328                 :         117 :     addr->email = CACHE_INSERT ("");
     329                 :             : 
     330                 :         117 :     return addr;
     331                 :             : }
     332                 :             : 
     333                 :             : static GncAddress *
     334                 :           0 : qofAddressCreate (QofBook *book)
     335                 :             : {
     336                 :             :     /* The address will get set later by another function */
     337                 :           0 :     return gncAddressCreate(book, NULL);
     338                 :             : }
     339                 :             : 
     340                 :             : static void
     341                 :           0 : qofAddressSetOwner(GncAddress *addr, QofInstance *ent)
     342                 :             : {
     343                 :           0 :     if (!addr || !ent)
     344                 :             :     {
     345                 :           0 :         return;
     346                 :             :     }
     347                 :           0 :     if (addr->parent == NULL)
     348                 :             :     {
     349                 :           0 :         addr->parent = ent;
     350                 :             :     }
     351                 :             : }
     352                 :             : 
     353                 :             : static QofInstance*
     354                 :           0 : qofAddressGetOwner(const GncAddress *addr)
     355                 :             : {
     356                 :             : 
     357                 :           0 :     if (!addr)
     358                 :             :     {
     359                 :           0 :         return NULL;
     360                 :             :     }
     361                 :           0 :     return addr->parent;
     362                 :             : }
     363                 :             : 
     364                 :             : void
     365                 :          69 : gncAddressDestroy (GncAddress *addr)
     366                 :             : {
     367                 :          69 :     if (!addr) return;
     368                 :          69 :     qof_instance_set_destroying(addr, TRUE);
     369                 :          69 :     gncAddressCommitEdit (addr);
     370                 :             : }
     371                 :             : 
     372                 :             : static void
     373                 :          69 : gncAddressFree (GncAddress *addr)
     374                 :             : {
     375                 :          69 :     if (!addr) return;
     376                 :             : 
     377                 :          69 :     qof_event_gen (&addr->inst, QOF_EVENT_DESTROY, NULL);
     378                 :             : 
     379                 :          69 :     CACHE_REMOVE (addr->name);
     380                 :          69 :     CACHE_REMOVE (addr->addr1);
     381                 :          69 :     CACHE_REMOVE (addr->addr2);
     382                 :          69 :     CACHE_REMOVE (addr->addr3);
     383                 :          69 :     CACHE_REMOVE (addr->addr4);
     384                 :          69 :     CACHE_REMOVE (addr->phone);
     385                 :          69 :     CACHE_REMOVE (addr->fax);
     386                 :          69 :     CACHE_REMOVE (addr->email);
     387                 :             : 
     388                 :             :     /* qof_instance_release (&addr->inst); */
     389                 :          69 :     g_object_unref (addr);
     390                 :             : }
     391                 :             : 
     392                 :             : 
     393                 :             : /* Set functions */
     394                 :             : 
     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); \
     400                 :             :         }
     401                 :             : 
     402                 :          14 : void gncAddressSetName (GncAddress *addr, const char *name)
     403                 :             : {
     404                 :          14 :     if (!addr) return;
     405                 :          14 :     if (!name) return;
     406                 :          14 :     SET_STR(addr, addr->name, name);
     407                 :          11 :     mark_address (addr);
     408                 :          11 :     gncAddressCommitEdit (addr);
     409                 :             : }
     410                 :             : 
     411                 :           9 : void gncAddressSetAddr1 (GncAddress *addr, const char *addr1)
     412                 :             : {
     413                 :           9 :     if (!addr) return;
     414                 :           9 :     if (!addr1) return;
     415                 :           9 :     SET_STR(addr, addr->addr1, addr1);
     416                 :           6 :     mark_address (addr);
     417                 :           6 :     gncAddressCommitEdit (addr);
     418                 :             : }
     419                 :             : 
     420                 :           9 : void gncAddressSetAddr2 (GncAddress *addr, const char *addr2)
     421                 :             : {
     422                 :           9 :     if (!addr) return;
     423                 :           9 :     if (!addr2) return;
     424                 :           9 :     SET_STR(addr, addr->addr2, addr2);
     425                 :           6 :     mark_address (addr);
     426                 :           6 :     gncAddressCommitEdit (addr);
     427                 :             : }
     428                 :             : 
     429                 :           6 : void gncAddressSetAddr3 (GncAddress *addr, const char *addr3)
     430                 :             : {
     431                 :           6 :     if (!addr) return;
     432                 :           6 :     if (!addr3) return;
     433                 :           6 :     SET_STR(addr, addr->addr3, addr3);
     434                 :           2 :     mark_address (addr);
     435                 :           2 :     gncAddressCommitEdit (addr);
     436                 :             : }
     437                 :             : 
     438                 :           6 : void gncAddressSetAddr4 (GncAddress *addr, const char *addr4)
     439                 :             : {
     440                 :           6 :     if (!addr) return;
     441                 :           6 :     if (!addr4) return;
     442                 :           6 :     SET_STR(addr, addr->addr4, addr4);
     443                 :           2 :     mark_address (addr);
     444                 :           2 :     gncAddressCommitEdit (addr);
     445                 :             : }
     446                 :             : 
     447                 :          10 : void gncAddressSetPhone (GncAddress *addr, const char *phone)
     448                 :             : {
     449                 :          10 :     if (!addr) return;
     450                 :          10 :     if (!phone) return;
     451                 :          10 :     SET_STR(addr, addr->phone, phone);
     452                 :           7 :     mark_address (addr);
     453                 :           7 :     gncAddressCommitEdit (addr);
     454                 :             : }
     455                 :             : 
     456                 :           5 : void gncAddressSetFax (GncAddress *addr, const char *fax)
     457                 :             : {
     458                 :           5 :     if (!addr) return;
     459                 :           5 :     if (!fax) return;
     460                 :           5 :     SET_STR(addr, addr->fax, fax);
     461                 :           1 :     mark_address (addr);
     462                 :           1 :     gncAddressCommitEdit (addr);
     463                 :             : }
     464                 :             : 
     465                 :           8 : void gncAddressSetEmail (GncAddress *addr, const char *email)
     466                 :             : {
     467                 :           8 :     if (!addr) return;
     468                 :           8 :     if (!email) return;
     469                 :           8 :     SET_STR(addr, addr->email, email);
     470                 :           4 :     mark_address (addr);
     471                 :           4 :     gncAddressCommitEdit (addr);
     472                 :             : }
     473                 :             : 
     474                 :         108 : void gncAddressBeginEdit (GncAddress *addr)
     475                 :             : {
     476                 :         108 :     qof_begin_edit (&addr->inst);
     477                 :         108 : }
     478                 :             : 
     479                 :           0 : static void gncAddressOnError (QofInstance *inst, QofBackendError errcode)
     480                 :             : {
     481                 :           0 :     PERR("Address QofBackend Failure: %d", errcode);
     482                 :           0 :     gnc_engine_signal_commit_error( errcode );
     483                 :           0 : }
     484                 :             : 
     485                 :          35 : static void gncAddressOnDone (QofInstance *addr) { }
     486                 :             : 
     487                 :          69 : static void address_free (QofInstance *inst)
     488                 :             : {
     489                 :          69 :     GncAddress *addr = (GncAddress *) inst;
     490                 :          69 :     gncAddressFree (addr);
     491                 :          69 : }
     492                 :             : 
     493                 :         108 : void gncAddressCommitEdit (GncAddress *addr)
     494                 :             : {
     495                 :             :     /* GnuCash 2.6.3 and earlier didn't handle address kvp's... */
     496                 :         108 :      if (qof_instance_has_kvp(QOF_INSTANCE(addr)))
     497                 :           0 :         gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (addr)), GNC_FEATURE_KVP_EXTRA_DATA);
     498                 :             : 
     499                 :         108 :     if (!qof_commit_edit (QOF_INSTANCE(addr))) return;
     500                 :         104 :     qof_commit_edit_part2 (&addr->inst, gncAddressOnError,
     501                 :             :                            gncAddressOnDone, address_free);
     502                 :             : }
     503                 :             : 
     504                 :             : 
     505                 :             : /* Get Functions */
     506                 :             : 
     507                 :          71 : const char * gncAddressGetName (const GncAddress *addr)
     508                 :             : {
     509                 :          71 :     if (!addr) return NULL;
     510                 :          71 :     return addr->name;
     511                 :             : }
     512                 :             : 
     513                 :          42 : const char * gncAddressGetAddr1 (const GncAddress *addr)
     514                 :             : {
     515                 :          42 :     if (!addr) return NULL;
     516                 :          42 :     return addr->addr1;
     517                 :             : }
     518                 :             : 
     519                 :          42 : const char * gncAddressGetAddr2 (const GncAddress *addr)
     520                 :             : {
     521                 :          42 :     if (!addr) return NULL;
     522                 :          42 :     return addr->addr2;
     523                 :             : }
     524                 :             : 
     525                 :          42 : const char * gncAddressGetAddr3 (const GncAddress *addr)
     526                 :             : {
     527                 :          42 :     if (!addr) return NULL;
     528                 :          42 :     return addr->addr3;
     529                 :             : }
     530                 :             : 
     531                 :          42 : const char * gncAddressGetAddr4 (const GncAddress *addr)
     532                 :             : {
     533                 :          42 :     if (!addr) return NULL;
     534                 :          42 :     return addr->addr4;
     535                 :             : }
     536                 :             : 
     537                 :          11 : const char * gncAddressGetPhone (const GncAddress *addr)
     538                 :             : {
     539                 :          11 :     if (!addr) return NULL;
     540                 :          11 :     return addr->phone;
     541                 :             : }
     542                 :             : 
     543                 :          11 : const char * gncAddressGetFax (const GncAddress *addr)
     544                 :             : {
     545                 :          11 :     if (!addr) return NULL;
     546                 :          11 :     return addr->fax;
     547                 :             : }
     548                 :             : 
     549                 :          11 : const char * gncAddressGetEmail (const GncAddress *addr)
     550                 :             : {
     551                 :          11 :     if (!addr) return NULL;
     552                 :          11 :     return addr->email;
     553                 :             : }
     554                 :             : 
     555                 :          39 : gboolean gncAddressIsDirty (const GncAddress *addr)
     556                 :             : {
     557                 :          39 :     if (!addr) return FALSE;
     558                 :          39 :     return addr->dirty;
     559                 :             : }
     560                 :             : 
     561                 :         225 : void gncAddressClearDirty (GncAddress *addr)
     562                 :             : {
     563                 :         225 :     if (!addr) return;
     564                 :         225 :     addr->dirty = FALSE;
     565                 :             : }
     566                 :             : 
     567                 :           0 : int gncAddressCompare (const GncAddress *a, const GncAddress *b)
     568                 :             : {
     569                 :           0 :     if (!a && !b) return 0;
     570                 :           0 :     if (!a && b) return 1;
     571                 :           0 :     if (a && !b) return -1;
     572                 :             : 
     573                 :           0 :     return g_strcmp0 (a->name, b->name);
     574                 :             : }
     575                 :             : 
     576                 :             : gboolean
     577                 :          10 : gncAddressEqual(const GncAddress* a, const GncAddress* b)
     578                 :             : {
     579                 :          10 :     if (a == NULL && b == NULL) return TRUE;
     580                 :          10 :     if (a == NULL || b == NULL) return FALSE;
     581                 :             : 
     582                 :          10 :     g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
     583                 :          10 :     g_return_val_if_fail(GNC_IS_ADDRESS(b), FALSE);
     584                 :             : 
     585                 :          10 :     if (g_strcmp0(a->name, b->name) != 0)
     586                 :             :     {
     587                 :           0 :         PWARN("names differ: %s vs %s", a->name, b->name);
     588                 :           0 :         return FALSE;
     589                 :             :     }
     590                 :          10 :     if (g_strcmp0(a->addr1, b->addr1) != 0)
     591                 :             :     {
     592                 :           0 :         PWARN("address lines 1 differ: %s vs %s", a->addr1, b->addr1);
     593                 :           0 :         return FALSE;
     594                 :             :     }
     595                 :          10 :     if (g_strcmp0(a->addr2, b->addr2) != 0)
     596                 :             :     {
     597                 :           0 :         PWARN("address lines 2 differ: %s vs %s", a->addr2, b->addr1);
     598                 :           0 :         return FALSE;
     599                 :             :     }
     600                 :          10 :     if (g_strcmp0(a->addr3, b->addr3) != 0)
     601                 :             :     {
     602                 :           0 :         PWARN("address lines 3 differ: %s vs %s", a->addr3, b->addr3);
     603                 :           0 :         return FALSE;
     604                 :             :     }
     605                 :          10 :     if (g_strcmp0(a->addr4, b->addr4) != 0)
     606                 :             :     {
     607                 :           0 :         PWARN("address lines 4 differ: %s vs %s", a->addr4, b->addr4);
     608                 :           0 :         return FALSE;
     609                 :             :     }
     610                 :          10 :     if (g_strcmp0(a->phone, b->phone) != 0)
     611                 :             :     {
     612                 :           0 :         PWARN("phone numbers differ: %s vs %s", a->phone, b->phone);
     613                 :           0 :         return FALSE;
     614                 :             :     }
     615                 :          10 :     if (g_strcmp0(a->fax, b->fax) != 0)
     616                 :             :     {
     617                 :           0 :         PWARN("fax numbers differ: %s vs %s", a->fax, b->fax);
     618                 :           0 :         return FALSE;
     619                 :             :     }
     620                 :          10 :     if (g_strcmp0(a->email, b->email) != 0)
     621                 :             :     {
     622                 :           0 :         PWARN("email addresses differ: %s vs %s", a->email, b->email);
     623                 :           0 :         return FALSE;
     624                 :             :     }
     625                 :             : 
     626                 :          10 :     return TRUE;
     627                 :             : }
     628                 :             : 
     629                 :             : static QofObject GncAddressDesc =
     630                 :             : {
     631                 :             :     DI(.interface_version = ) QOF_OBJECT_VERSION,
     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,
     637                 :             :     DI(.is_dirty          = ) qof_collection_is_dirty,
     638                 :             :     DI(.mark_clean        = ) qof_collection_mark_clean,
     639                 :             :     DI(.foreach           = ) qof_collection_foreach,
     640                 :             :     DI(.printable         = ) NULL,
     641                 :             :     DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
     642                 :             : };
     643                 :             : 
     644                 :          81 : gboolean gncAddressRegister (void)
     645                 :             : {
     646                 :             :     static QofParam params[] =
     647                 :             :     {
     648                 :             : 
     649                 :             :         { ADDRESS_NAME,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetName,  (QofSetterFunc)gncAddressSetName },
     650                 :             :         { ADDRESS_ONE,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr1, (QofSetterFunc)gncAddressSetAddr1 },
     651                 :             :         { ADDRESS_TWO,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr2, (QofSetterFunc)gncAddressSetAddr2 },
     652                 :             :         { ADDRESS_THREE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr3, (QofSetterFunc)gncAddressSetAddr3 },
     653                 :             :         { ADDRESS_FOUR,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr4, (QofSetterFunc)gncAddressSetAddr4 },
     654                 :             :         { ADDRESS_PHONE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetPhone, (QofSetterFunc)gncAddressSetPhone },
     655                 :             :         { ADDRESS_FAX,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetFax,   (QofSetterFunc)gncAddressSetFax },
     656                 :             :         { ADDRESS_EMAIL, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetEmail, (QofSetterFunc)gncAddressSetEmail },
     657                 :             :         { ADDRESS_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofAddressGetOwner, (QofSetterFunc)qofAddressSetOwner },
     658                 :             :         { QOF_PARAM_BOOK, QOF_ID_BOOK,   (QofAccessFunc)qof_instance_get_book, NULL },
     659                 :             :         { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
     660                 :             :         { NULL },
     661                 :             :     };
     662                 :             : 
     663                 :          81 :     qof_class_register (GNC_ID_ADDRESS, (QofSortFunc)gncAddressCompare, params);
     664                 :             : 
     665                 :          81 :     return qof_object_register(&GncAddressDesc);
     666                 :             : }
        

Generated by: LCOV version 2.0-1