Changeset 2459

Show
Ignore:
Timestamp:
08/16/07 14:58:17 (1 year ago)
Author:
paule
Message:

Better handling of name, organization & home/work address fields on contacts - xmlformat keys are now ordered as expected & code is a bit neater

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/opie-sync/src/opie_format.c

    r2454 r2459  
    5252        gchar** emailtokens; 
    5353        struct _xmlAttr *iprop; 
    54         OSyncXMLField *oxf_name = NULL; 
    55         OSyncXMLField *oxf_organisation = NULL; 
    56         OSyncXMLField *oxf_homeaddress = NULL; 
    57         OSyncXMLField *oxf_workaddress = NULL; 
    5854        OSyncXMLField *out_xmlfield = NULL; 
    5955                 
     
    8177                        if (iprop->children && iprop->children->content) 
    8278                        { 
    83                                 if ( (!strcasecmp(iprop->name, "FirstName")) 
    84                                         || (!strcasecmp(iprop->name, "MiddleName")) 
    85                                         || (!strcasecmp(iprop->name, "LastName")) 
    86                                         || (!strcasecmp(iprop->name,"Suffix")) ) 
    87                                 { 
    88                                         if (!oxf_name) 
    89                                                 oxf_name = osync_xmlfield_new(out_xmlformat, "Name", error); 
    90                                          
    91                                         if (!strcasecmp(iprop->name, "FirstName")) 
    92                                                 osync_xmlfield_set_key_value(oxf_name, "FirstName", iprop->children->content); 
    93                                         else if (!strcasecmp(iprop->name, "MiddleName")) 
    94                                                 osync_xmlfield_set_key_value(oxf_name, "Additional", iprop->children->content); 
    95                                         else if (!strcasecmp(iprop->name, "LastName")) 
    96                                                 osync_xmlfield_set_key_value(oxf_name, "LastName", iprop->children->content); 
    97                                         else if (!strcasecmp(iprop->name,"Suffix")) 
    98                                                 osync_xmlfield_set_key_value(oxf_name, "Suffix", iprop->children->content); 
    99                                 } 
    100                                 else if ( (!strcasecmp(iprop->name, "Company")) 
    101                                         || (!strcasecmp(iprop->name, "Department")) 
    102                                         || (!strcasecmp(iprop->name, "Office")) ) 
    103                                 { 
    104                                         if (!oxf_organisation) 
    105                                                 oxf_organisation = osync_xmlfield_new(out_xmlformat, "Organization", error); 
    106                                          
    107                                         if (!strcasecmp(iprop->name, "Company")) 
    108                                                 osync_xmlfield_set_key_value(oxf_organisation, "Name", iprop->children->content); 
    109                                         if (!strcasecmp(iprop->name, "Department")) 
    110                                                 osync_xmlfield_set_key_value(oxf_organisation, "Department", iprop->children->content); 
    111                                         if (!strcasecmp(iprop->name, "Office")) 
    112                                                 osync_xmlfield_set_key_value(oxf_organisation, "Unit", iprop->children->content); 
    113                                 } 
    114                                 else if(!strcasecmp(iprop->name, "FileAs")) 
     79                                if (!strcasecmp(iprop->name, "FileAs")) 
    11580                                { 
    11681                                        /* File-as. This is what the Evo plugin does, so copy it. */ 
     
    198163                                        osync_xmlfield_set_attr(out_xmlfield, "Type", "Pager"); /* FIXME is this still supported? */ 
    199164                                } 
    200                                 else if ( (!strcasecmp(iprop->name, "HomeStreet")) 
    201                                         || (!strcasecmp(iprop->name, "HomeCity")) 
    202                                         || (!strcasecmp(iprop->name, "HomeState")) 
    203                                         || (!strcasecmp(iprop->name,"HomeZip")) 
    204                                         || (!strcasecmp(iprop->name,"HomeCountry")) ) 
    205                                 { 
    206                                         if (!oxf_homeaddress) 
    207                                                 oxf_homeaddress = osync_xmlfield_new(out_xmlformat, "Address", error); 
    208                                          
    209                                         if (!strcasecmp(iprop->name, "HomeStreet")) 
    210                                                 osync_xmlfield_set_key_value(oxf_homeaddress, "Street", iprop->children->content); 
    211                                         else if (!strcasecmp(iprop->name, "HomeCity")) 
    212                                                 osync_xmlfield_set_key_value(oxf_homeaddress, "Locality", iprop->children->content); 
    213                                         else if (!strcasecmp(iprop->name, "HomeState")) 
    214                                                 osync_xmlfield_set_key_value(oxf_homeaddress, "Region", iprop->children->content); 
    215                                         else if (!strcasecmp(iprop->name, "HomeZip")) 
    216                                                 osync_xmlfield_set_key_value(oxf_homeaddress, "PostalCode", iprop->children->content); 
    217                                         else if (!strcasecmp(iprop->name,"HomeCountry")) 
    218                                                 osync_xmlfield_set_key_value(oxf_homeaddress, "Country", iprop->children->content); 
    219                                         osync_xmlfield_set_attr(oxf_homeaddress, "Location", "Home"); 
    220                                 } 
    221                                 else if ( (!strcasecmp(iprop->name, "BusinessStreet")) 
    222                                         || (!strcasecmp(iprop->name, "BusinessCity")) 
    223                                         || (!strcasecmp(iprop->name, "BusinessState")) 
    224                                         || (!strcasecmp(iprop->name,"BusinessZip")) 
    225                                         || (!strcasecmp(iprop->name,"BusinessCountry")) ) 
    226                                 { 
    227                                         if (!oxf_workaddress) 
    228                                                 oxf_workaddress = osync_xmlfield_new(out_xmlformat, "Address", error); 
    229                                          
    230                                         if (!strcasecmp(iprop->name, "BusinessStreet")) 
    231                                                 osync_xmlfield_set_key_value(oxf_workaddress, "Street", iprop->children->content); 
    232                                         else if (!strcasecmp(iprop->name, "BusinessCity")) 
    233                                                 osync_xmlfield_set_key_value(oxf_workaddress, "Locality", iprop->children->content); 
    234                                         else if (!strcasecmp(iprop->name, "BusinessState")) 
    235                                                 osync_xmlfield_set_key_value(oxf_workaddress, "Region", iprop->children->content); 
    236                                         else if (!strcasecmp(iprop->name, "BusinessZip")) 
    237                                                 osync_xmlfield_set_key_value(oxf_workaddress, "PostalCode", iprop->children->content); 
    238                                         else if (!strcasecmp(iprop->name,"BusinessCountry")) 
    239                                                 osync_xmlfield_set_key_value(oxf_workaddress, "Country", iprop->children->content); 
    240                                         osync_xmlfield_set_attr(oxf_workaddress, "Location", "Work"); 
    241                                 } 
    242165                                else if(!strcasecmp(iprop->name, "HomeWebPage")) 
    243166                                { 
     
    318241        } 
    319242 
     243        GSList *attrs = NULL; 
     244        GSList *keys = NULL; 
     245         
     246        /* Name */ 
     247        dual_list_append(&attrs, "LastName",   &keys, "LastName"); 
     248        dual_list_append(&attrs, "FirstName",  &keys, "FirstName"); 
     249        dual_list_append(&attrs, "MiddleName", &keys, "Additional"); 
     250        dual_list_append(&attrs, "Suffix",     &keys, "Suffix"); 
     251        out_xmlfield = xml_attrs_to_xmlfield_keys(icur, out_xmlformat, "Name", attrs, keys, error); 
     252        dual_list_clear(&attrs, &keys); 
     253         
     254        /* Organization */ 
     255        dual_list_append(&attrs, "Company",    &keys, "Name"); 
     256        dual_list_append(&attrs, "Department", &keys, "Department"); 
     257        dual_list_append(&attrs, "Office",     &keys, "Unit"); 
     258        out_xmlfield = xml_attrs_to_xmlfield_keys(icur, out_xmlformat, "Organization", attrs, keys, error); 
     259        dual_list_clear(&attrs, &keys); 
     260         
     261        /* Home Address */ 
     262        dual_list_append(&attrs, "HomeStreet",  &keys, "Street"); 
     263        dual_list_append(&attrs, "HomeCity",    &keys, "Locality"); 
     264        dual_list_append(&attrs, "HomeState",   &keys, "Region"); 
     265        dual_list_append(&attrs, "HomeZip",     &keys, "PostalCode"); 
     266        dual_list_append(&attrs, "HomeCountry", &keys, "Country"); 
     267        out_xmlfield = xml_attrs_to_xmlfield_keys(icur, out_xmlformat, "Address", attrs, keys, error); 
     268        if(out_xmlfield) 
     269                osync_xmlfield_set_attr(out_xmlfield, "Location", "Home"); 
     270        dual_list_clear(&attrs, &keys); 
     271         
     272        /* Work Address */ 
     273        dual_list_append(&attrs, "BusinessStreet",  &keys, "Street"); 
     274        dual_list_append(&attrs, "BusinessCity",    &keys, "Locality"); 
     275        dual_list_append(&attrs, "BusinessState",   &keys, "Region"); 
     276        dual_list_append(&attrs, "BusinessZip",     &keys, "PostalCode"); 
     277        dual_list_append(&attrs, "BusinessCountry", &keys, "Country"); 
     278        out_xmlfield = xml_attrs_to_xmlfield_keys(icur, out_xmlformat, "Address", attrs, keys, error); 
     279        if(out_xmlfield) 
     280                osync_xmlfield_set_attr(out_xmlfield, "Location", "Work"); 
     281        dual_list_clear(&attrs, &keys); 
     282         
     283         
    320284        *free_input = TRUE; 
    321285        *output = (char *)out_xmlformat; 
     
    326290        // FIXME: remove this later by adding in a pre-sorted way? 
    327291        osync_xmlformat_sort(out_xmlformat); 
    328         if(oxf_name) 
    329                 osync_xmlfield_sort(oxf_name); 
    330         if(oxf_organisation) 
    331                 osync_xmlfield_sort(oxf_organisation); 
    332         if(oxf_homeaddress) 
    333                 osync_xmlfield_sort(oxf_homeaddress); 
    334         if(oxf_workaddress) 
    335                 osync_xmlfield_sort(oxf_workaddress); 
    336292         
    337293        unsigned int size; 
     
    14421398        } 
    14431399        return utime; 
     1400} 
     1401 
     1402OSyncXMLField *xml_attrs_to_xmlfield_keys(xmlNode *node, OSyncXMLFormat *out_xmlformat, const char *fieldname, GSList *attrs, GSList *keys, OSyncError **error) { 
     1403        GSList *attrsptr = attrs; 
     1404        GSList *keysptr = keys; 
     1405        OSyncXMLField *out_xmlfield = NULL; 
     1406         
     1407        while(attrsptr) { 
     1408                char *attr = ((char *)(attrsptr->data)); 
     1409                char *value = xmlGetProp(node, attr); 
     1410                if(value) { 
     1411                        char *key = (char *)(keysptr->data); 
     1412                        if(!out_xmlfield) 
     1413                                out_xmlfield = osync_xmlfield_new(out_xmlformat, fieldname, error); 
     1414                        osync_xmlfield_set_key_value(out_xmlfield, key, value); 
     1415                } 
     1416                 
     1417                attrsptr = g_slist_next(attrsptr); 
     1418                keysptr = g_slist_next(keysptr); 
     1419        } 
     1420         
     1421        return out_xmlfield; 
     1422} 
     1423 
     1424void dual_list_append(GSList **list1, void *item1, GSList **list2, void *item2) { 
     1425        *list1 = g_slist_append(*list1, item1); 
     1426        *list2 = g_slist_append(*list2, item2); 
     1427} 
     1428 
     1429void dual_list_clear(GSList **list1, GSList **list2) { 
     1430        g_slist_free(*list1); 
     1431        *list1 = NULL; 
     1432        g_slist_free(*list2); 
     1433        *list2 = NULL; 
    14441434} 
    14451435 
  • plugins/opie-sync/src/opie_format.h

    r2451 r2459  
    3030void xml_uid_attr_to_xmlfield(const char *uid, const char *nodename, OSyncXMLFormat *out_xmlformat, OSyncError **error); 
    3131time_t xmlfield_vtime_to_attr_time_t(OSyncXMLField *xmlfield, xmlNode *node_to, const char *attrname); 
     32OSyncXMLField *xml_attrs_to_xmlfield_keys(xmlNode *node, OSyncXMLFormat *out_xmlformat, const char *fieldname, GSList *attrs, GSList *keys, OSyncError **error); 
     33void dual_list_append(GSList **list1, void *item1, GSList **list2, void *item2); 
     34void dual_list_clear(GSList **list1, GSList **list2); 
    3235void xmlfield_categories_to_attr(OSyncXMLField *in_xmlfield, xmlNode *node_to, const char *category_attr); 
    3336void xml_recur_attr_to_xmlfield(xmlNode *item_node, OSyncXMLFormat *out_xmlformat, GDate *startdate, OSyncError **error); 
     
    3942#endif /* _OPIE_FORMAT_H */ 
    4043 
    41  
    42  
    43