DLLEXPORT(const char *) vObjectTypeInfo(VObject *o) { const char *type = vObjectName( o ); if ( strcmp( type, "type" ) == 0 || strcmp( type, "TYPE" ) == 0 || strcmp( type, "Type" ) == 0 ) type = vObjectStringZValue( o ); return type; }
VObject* addPropValue(VObject *o, const char *p, const char *v) { VObject *prop; prop = addProp(o,p); if (v) { setVObjectUStringZValue_(prop, fakeUnicode(v,0)); if (needsQuotedPrintable (v)) { if (PL_strcasecmp (VCCardProp, vObjectName(o)) == 0) addProp (prop, VCQuotedPrintableProp); else addProp (o, VCQuotedPrintableProp); } } else setVObjectUStringZValue_(prop, fakeUnicode("",0)); return prop; }
static void convertNameValue(VObject *vObj, nsIAbCard *aCard) { const char *cardPropName = NULL; // if the vCard property is not a root property then we need to determine its exact property. // a good example of this is VCTelephoneProp, this prop has four objects underneath it: // fax, work and home and cellular. if (PL_strcasecmp(VCCityProp, vObjectName(vObj)) == 0) cardPropName = kWorkCityProperty; else if (PL_strcasecmp(VCTelephoneProp, vObjectName(vObj)) == 0) { if (isAPropertyOf(vObj, VCFaxProp)) cardPropName = kFaxProperty; else if (isAPropertyOf(vObj, VCWorkProp)) cardPropName = kWorkPhoneProperty; else if (isAPropertyOf(vObj, VCHomeProp)) cardPropName = kHomePhoneProperty; else if (isAPropertyOf(vObj, VCCellularProp)) cardPropName = kCellularProperty; else if (isAPropertyOf(vObj, VCPagerProp)) cardPropName = kPagerProperty; else return; } else if (PL_strcasecmp(VCEmailAddressProp, vObjectName(vObj)) == 0) cardPropName = kPriEmailProperty; else if (PL_strcasecmp(VCFamilyNameProp, vObjectName(vObj)) == 0) cardPropName = kLastNameProperty; else if (PL_strcasecmp(VCFullNameProp, vObjectName(vObj)) == 0) cardPropName = kDisplayNameProperty; else if (PL_strcasecmp(VCGivenNameProp, vObjectName(vObj)) == 0) cardPropName = kFirstNameProperty; else if (PL_strcasecmp(VCOrgNameProp, vObjectName(vObj)) == 0) cardPropName = kCompanyProperty; else if (PL_strcasecmp(VCOrgUnitProp, vObjectName(vObj)) == 0) cardPropName = kDepartmentProperty; else if (PL_strcasecmp(VCPostalCodeProp, vObjectName(vObj)) == 0) cardPropName = kWorkZipCodeProperty; else if (PL_strcasecmp(VCRegionProp, vObjectName(vObj)) == 0) cardPropName = kWorkStateProperty; else if (PL_strcasecmp(VCStreetAddressProp, vObjectName(vObj)) == 0) cardPropName = kWorkAddressProperty; else if (PL_strcasecmp(VCPostalBoxProp, vObjectName(vObj)) == 0) cardPropName = kWorkAddress2Property; else if (PL_strcasecmp(VCCountryNameProp, vObjectName(vObj)) == 0) cardPropName = kWorkCountryProperty; else if (PL_strcasecmp(VCTitleProp, vObjectName(vObj)) == 0) cardPropName = kJobTitleProperty; else if (PL_strcasecmp(VCUseHTML, vObjectName(vObj)) == 0) cardPropName = kPreferMailFormatProperty; else if (PL_strcasecmp(VCNoteProp, vObjectName(vObj)) == 0) cardPropName = kNotesProperty; else if (PL_strcasecmp(VCURLProp, vObjectName(vObj)) == 0) cardPropName = kWorkWebPageProperty; else return; if (!VALUE_TYPE(vObj)) return; char *cardPropValue = getCString(vObj); aCard->SetPropertyAsAUTF8String(cardPropName, nsDependentCString(cardPropValue)); PR_FREEIF(cardPropValue); return; }
OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) { OContact c; VObjectIterator it; initPropIterator( &it, obj ); while( moreIteration( &it ) ) { VObject *o = nextVObject( &it ); QCString name = vObjectName( o ); QCString value = vObjectStringZValue( o ); if ( name == VCNameProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); QString value = vObjectStringZValue( o ); if ( name == VCNamePrefixesProp ) c.setTitle( value ); else if ( name == VCNameSuffixesProp ) c.setSuffix( value ); else if ( name == VCFamilyNameProp ) c.setLastName( value ); else if ( name == VCGivenNameProp ) c.setFirstName( value ); else if ( name == VCAdditionalNamesProp ) c.setMiddleName( value ); } } else if ( name == VCAdrProp ) { bool work = TRUE; // default address is work address QString street; QString city; QString region; QString postal; QString country; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QString value = vObjectStringZValue( o ); if ( name == VCHomeProp ) work = FALSE; else if ( name == VCWorkProp ) work = TRUE; else if ( name == VCStreetAddressProp ) street = value; else if ( name == VCCityProp ) city = value; else if ( name == VCRegionProp ) region = value; else if ( name == VCPostalCodeProp ) postal = value; else if ( name == VCCountryNameProp ) country = value; } if ( work ) { c.setBusinessStreet( street ); c.setBusinessCity( city ); c.setBusinessCountry( country ); c.setBusinessZip( postal ); c.setBusinessState( region ); } else { c.setHomeStreet( street ); c.setHomeCity( city ); c.setHomeCountry( country ); c.setHomeZip( postal ); c.setHomeState( region ); } } else if ( name == VCTelephoneProp ) { enum { HOME = 0x01, WORK = 0x02, VOICE = 0x04, CELL = 0x08, FAX = 0x10, PAGER = 0x20, UNKNOWN = 0x80 }; int type = 0; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); if ( name == VCHomeProp ) type |= HOME; else if ( name == VCWorkProp ) type |= WORK; else if ( name == VCVoiceProp ) type |= VOICE; else if ( name == VCCellularProp ) type |= CELL; else if ( name == VCFaxProp ) type |= FAX; else if ( name == VCPagerProp ) type |= PAGER; else if ( name == VCPreferredProp ) ; else type |= UNKNOWN; } if ( (type & UNKNOWN) != UNKNOWN ) { if ( ( type & (HOME|WORK) ) == 0 ) // default type |= HOME; if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default type |= VOICE; qWarning("value %s %d", value.data(), type ); if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) c.setHomePhone( value ); if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) c.setHomeFax( value ); if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) c.setHomeMobile( value ); if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) c.setBusinessPhone( value ); if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) c.setBusinessFax( value ); if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) c.setBusinessMobile( value ); if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) c.setBusinessPager( value ); } } else if ( name == VCEmailAddressProp ) { QString email = vObjectStringZValue( o ); bool valid = TRUE; VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); if ( name != VCInternetProp && name != VCHomeProp && name != VCWorkProp && name != VCPreferredProp ) // ### preffered should map to default email valid = FALSE; } if ( valid ) { c.insertEmail( email ); } } else if ( name == VCURLProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectTypeInfo( o ); if ( name == VCHomeProp ) c.setHomeWebpage( value ); else if ( name == VCWorkProp ) c.setBusinessWebpage( value ); } } else if ( name == VCOrgProp ) { VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QString value = vObjectStringZValue( o ); if ( name == VCOrgNameProp ) c.setCompany( value ); else if ( name == VCOrgUnitProp ) c.setDepartment( value ); else if ( name == VCOrgUnit2Prop ) c.setOffice( value ); } } else if ( name == VCTitleProp ) { c.setJobTitle( value ); } else if ( name == "X-Qtopia-Profession" ) { c.setProfession( value ); } else if ( name == "X-Qtopia-Manager" ) { c.setManager( value ); } else if ( name == "X-Qtopia-Assistant" ) { c.setAssistant( value ); } else if ( name == "X-Qtopia-Spouse" ) { c.setSpouse( value ); } else if ( name == "X-Qtopia-Gender" ) { c.setGender( value ); } else if ( name == "X-Qtopia-Anniversary" ) { c.setAnniversary( convVCardDateToDate( value ) ); } else if ( name == "X-Qtopia-Nickname" ) { c.setNickname( value ); } else if ( name == "X-Qtopia-Children" ) { c.setChildren( value ); } else if ( name == VCBirthDateProp ) { // Reading Birthdate regarding RFC 2425 (5.8.4) c.setBirthday( convVCardDateToDate( value ) ); } else if ( name == VCCommentProp ) { c.setNotes( value ); } #if 0 else { printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); VObjectIterator nit; initPropIterator( &nit, o ); while( moreIteration( &nit ) ) { VObject *o = nextVObject( &nit ); QCString name = vObjectName( o ); QString value = vObjectStringZValue( o ); printf(" subprop: %s = %s\n", name.data(), value.latin1() ); } } #endif } c.setFileAs(); return c; }