Example #1
0
static void convertFromVObject(VObject *vObj, nsIAbCard *aCard)
{
    if (vObj)
    {
        VObjectIterator t;

        convertNameValue(vObj, aCard);

        initPropIterator(&t, vObj);
        while (moreIteration(&t))
        {
            VObject * nextObject = nextVObject(&t);
            convertFromVObject(nextObject, aCard);
        }
    }
    return;
}
Example #2
0
static void writeVObject_(OFile *fp, VObject *o)
{
    if (NAME_OF(o)) {
	struct PreDefProp *pi;
	pi = lookupPropInfo(NAME_OF(o));

	if (pi && ((pi->flags & PD_BEGIN) != 0)) {
	    VObjectIterator t;
	    const char *begin = NAME_OF(o);
	    appendsOFile(fp,"BEGIN:");
	    appendsOFile(fp,begin);
	    appendcOFile(fp,'\n');
	    initPropIterator(&t,o);
	    while (moreIteration(&t)) {
		VObject *eachProp = nextVObject(&t);
		writeProp(fp, eachProp);
		}
	    appendsOFile(fp,"END:");
	    appendsOFile(fp,begin);
	    appendsOFile(fp,"\n\n");
	    }
	}
}
Example #3
0
static void writeProp(OFile *fp, VObject *o)
{
    if (NAME_OF(o)) {
	struct PreDefProp *pi;
	VObjectIterator t;
	const char **fields_ = 0;
	pi = lookupPropInfo(NAME_OF(o));
	if (pi && ((pi->flags & PD_BEGIN) != 0)) {
	    writeVObject_(fp,o);
	    return;
	    }
	if (isAPropertyOf(o,VCGroupingProp))
	    writeGroup(fp,o);
	else
	    appendsOFile(fp,NAME_OF(o));
	if (pi) fields_ = pi->fields;
	initPropIterator(&t,o);
	while (moreIteration(&t)) {
	    const char *s;
	    VObject *eachProp = nextVObject(&t);
	    s = NAME_OF(eachProp);
	    if (qstricmp(VCGroupingProp,s) && !inList(fields_,s))
		writeAttrValue(fp,eachProp);
	    }
	if (fields_) {
	    int i = 0, n = 0;
	    const char** fields = fields_;
	    /* output prop as fields */
	    bool printable = TRUE;
	    while (*fields && printable) {
		VObject *t = isAPropertyOf(o,*fields);
		if (includesUnprintable(t,TRUE))
		    printable = FALSE;
		fields++;
	    }
	    fields = fields_;
	    if (!printable)
		appendsOFileEncCs(fp);
	    appendcOFile(fp,':');
	    while (*fields) {
		VObject *t = isAPropertyOf(o,*fields);
		i++;
		if (t) n = i;
		fields++;
	    }
	    fields = fields_;
	    for (i=0;i<n;i++) {
		writeValue(fp,isAPropertyOf(o,*fields),0,TRUE);
		fields++;
		if (i<(n-1)) appendcOFile(fp,';');
	    }
	    }
	}


    if (VALUE_TYPE(o)) {
	    if ( includesUnprintable(o,FALSE) )
			appendsOFileEncCs(fp);
	unsigned long size = 0;
        VObject *p = isAPropertyOf(o,VCDataSizeProp);
	if (p) size = LONG_VALUE_OF(p);
	appendcOFile(fp,':');
	writeValue(fp,o,size,FALSE);
	}

    appendcOFile(fp,'\n');
}
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;
}