⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contact.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  Email address should be separated by ';'s.*/void Contact::setEmails( const QString &str ){    replace( Qtopia::Emails, str );    if ( str.isEmpty() )        setDefaultEmail( QString::null );}/*  Sets the list of children for the contact to those contained in \a str.*/void Contact::setChildren( const QString &str ){    replace( Qtopia::Children, str );}// vcard conversion code/*  \internal*/static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ){    VObject *ret = 0;    if ( o && !value.isEmpty() )	ret = addPropValue( o, prop, value.latin1() );    return ret;}/*  \internal*/static inline VObject *safeAddProp( VObject *o, const char *prop){    VObject *ret = 0;    if ( o )	ret = addProp( o, prop );    return ret;}/*  \internal*/static VObject *createVObject( const Contact &c ){    VObject *vcard = newVObject( VCCardProp );    safeAddPropValue( vcard, VCVersionProp, "2.1" );    safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );    safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );    // full name    safeAddPropValue( vcard, VCFullNameProp, c.fullName() );    // name properties    VObject *name = safeAddProp( vcard, VCNameProp );    safeAddPropValue( name, VCFamilyNameProp, c.lastName() );    safeAddPropValue( name, VCGivenNameProp, c.firstName() );    safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );    safeAddPropValue( name, VCNamePrefixesProp, c.title() );    safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );    // home properties    VObject *home_adr= safeAddProp( vcard, VCAdrProp );    safeAddProp( home_adr, VCHomeProp );    safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );    safeAddPropValue( home_adr, VCCityProp, c.homeCity() );    safeAddPropValue( home_adr, VCRegionProp, c.homeState() );    safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );    safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );    VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );    safeAddProp( home_phone, VCHomeProp );    home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );    safeAddProp( home_phone, VCHomeProp );    safeAddProp( home_phone, VCCellularProp );    home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );    safeAddProp( home_phone, VCHomeProp );    safeAddProp( home_phone, VCFaxProp );    VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );    safeAddProp( url, VCHomeProp );    // work properties    VObject *work_adr= safeAddProp( vcard, VCAdrProp );    safeAddProp( work_adr, VCWorkProp );    safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );    safeAddPropValue( work_adr, VCCityProp, c.businessCity() );    safeAddPropValue( work_adr, VCRegionProp, c.businessState() );    safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );    safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );    VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );    safeAddProp( work_phone, VCWorkProp );    work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );    safeAddProp( work_phone, VCWorkProp );    safeAddProp( work_phone, VCCellularProp );    work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );    safeAddProp( work_phone, VCWorkProp );    safeAddProp( work_phone, VCFaxProp );    work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );    safeAddProp( work_phone, VCWorkProp );    safeAddProp( work_phone, VCPagerProp );    url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );    safeAddProp( url, VCWorkProp );    VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );    safeAddProp( title, VCWorkProp );    QStringList emails = c.emailList();    emails.prepend( c.defaultEmail() );    for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {	VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );	safeAddProp( email, VCInternetProp );    }    safeAddPropValue( vcard, VCNoteProp, c.notes() );    safeAddPropValue( vcard, VCBirthDateProp, c.birthday() );    if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {	VObject *org = safeAddProp( vcard, VCOrgProp );	safeAddPropValue( org, VCOrgNameProp, c.company() );	safeAddPropValue( org, VCOrgUnitProp, c.department() );	safeAddPropValue( org, VCOrgUnit2Prop, c.office() );    }    // some values we have to export as custom fields    safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );    safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );    safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );    safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );    safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );    safeAddPropValue( vcard, "X-Qtopia-Anniversary", c.anniversary() );    safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );    safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );    return vcard;}/*  \internal*/static Contact parseVObject( VObject *obj ){    Contact c;    bool haveDefaultEmail = FALSE;    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;		if ( (type & (VOICE|HOME) ) == (VOICE|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) )		    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 ) {		if ( haveDefaultEmail ) {		    QString str = c.emails();		    if ( !str.isEmpty() )			str += " "+email;		    c.setEmails( str );		} else {		    haveDefaultEmail = TRUE;		    {			QString newEmail = email;			int where;			newEmail.replace(QRegExp("<"), " "); //all '<' to ' '			newEmail.replace(QRegExp(">"), " "); //all '>' to ' '			where = newEmail.find( ' ' );			if (where >= 0)			    newEmail = newEmail.left(where);			newEmail = newEmail.stripWhiteSpace();			c.setDefaultEmail( newEmail );		    }		    c.setEmails( 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( value );	}	else if ( name == "X-Qtopia-Nickname" ) {	    c.setNickname( value );	}	else if ( name == "X-Qtopia-Children" ) {	    c.setChildren( 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;}/*  Writes the list of \a contacts as a set of VCards to the file \a filename.*/void Contact::writeVCard( const QString &filename, const QValueList<Contact> &contacts){	QFileDirect f( filename.utf8().data() );	if ( !f.open( IO_WriteOnly ) ) {		qWarning("Unable to open vcard write");		return;	}    QValueList<Contact>::ConstIterator it;    for( it = contacts.begin(); it != contacts.end(); ++it ) {	VObject *obj = createVObject( *it );	writeVObject(f.directHandle() , obj );	cleanVObject( obj );    }    cleanStrTbl();}/*  writes \a contact as a VCard to the file \a filename.*/void Contact::writeVCard( const QString &filename, const Contact &contact){	QFileDirect f( filename.utf8().data() );	if ( !f.open( IO_WriteOnly ) ) {		qWarning("Unable to open vcard write");		return;	}    VObject *obj = createVObject( contact );	writeVObject( f.directHandle() , obj );	cleanVObject( obj );	cleanStrTbl();}/*  Returns the set of contacts read as VCards from the file \a filename.*/QValueList<Contact> Contact::readVCard( const QString &filename ){    qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );    VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );    qDebug("vobject = %p", obj );    QValueList<Contact> contacts;    while ( obj ) {	contacts.append( parseVObject( obj ) );	VObject *t = obj;	obj = nextVObjectInList(obj);	cleanVObject( t );    }    return contacts;}/*  Returns TRUE if the contact matches the regular expression \a regexp.  Otherwise returns FALSE.*/bool Contact::match( const QString &regexp ) const{    return match(QRegExp(regexp));}/*  \overload  Returns TRUE if the contact matches the regular expression \a regexp.  Otherwise returns FALSE.*/bool Contact::match( const QRegExp &r ) const{    bool match;    match = false;    QMap<int, QString>::ConstIterator it;    for ( it = mMap.begin(); it != mMap.end(); ++it ) {	if ( (*it).find( r ) > -1 ) {	    match = true;	    break;	}    }    return match;}Qtopia::UidGen & Contact::uidGen(){  return sUidGen;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -