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

📄 contact.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    initPropIterator( &it, obj );    while( moreIteration( &it ) ) {	VObject *o = nextVObject( &it );	QCString name = vObjectName( o );	// check this key/value for a CHARSET field.	VObjectIterator tnit;	initPropIterator( &tnit, o );	QTextCodec *tc = 0;	while( moreIteration( &tnit ) ) {	    VObject *otc = nextVObject( &tnit );	    if ( qstrcmp(vObjectName(otc), VCCharSetProp ) == 0) {		tc = QTextCodec::codecForName(vObjectStringZValue(otc));		break;	    }	}	QString value;	if (tc)	    value = tc->toUnicode( vObjectStringZValue( o ) );	else	    value = vObjectStringZValue( o );	if ( name == VCNameProp ) {	    VObjectIterator nit;	    initPropIterator( &nit, o );	    while( moreIteration( &nit ) ) {		VObject *o = nextVObject( &nit );		QCString name = vObjectTypeInfo( o );		if (tc) {		    value = tc->toUnicode( vObjectStringZValue( o ) );		    qDebug("Orig %s, utf %s", vObjectStringZValue( o ), value.utf8().data());		}		else		    value = vObjectStringZValue( o );		//QString value = vObjectStringZValue( o );		if ( name == VCNamePrefixesProp )		    c.setNameTitle( 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 == VCPronunciationProp )	    c.setFirstNamePronunciation( value );	else if ( name == "X-Qtopia-LNSOUND" )	    c.setLastNamePronunciation( 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 );		if (tc)		    value = tc->toUnicode( vObjectStringZValue( o ) );		else		    value = vObjectStringZValue( 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 if ( name == VCEncodingProp )		    ;		else		    type |= UNKNOWN;	    }	    // evil if, indicates that if there was even one property we didn't know, don't store this value.	    if ( (type & UNKNOWN) == UNKNOWN ) {		qWarning("found unkown attribute in vobject, %s", (const char *)name);	    }	    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;	    if (tc)		email = tc->toUnicode( vObjectStringZValue( o ) );	    else		email = vObjectStringZValue( o );	    //QString email = vObjectStringZValue( o );	    VObjectIterator nit;	    initPropIterator( &nit, o );	    bool isDefaultEmail = FALSE;	    while( moreIteration( &nit ) ) {		VObject *o = nextVObject( &nit );		QCString name = vObjectTypeInfo( o );		if ( name == VCPreferredProp)		    isDefaultEmail = TRUE;	    }	    if ( isDefaultEmail )		c.setDefaultEmail( email );	    else		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 );		if (tc)		    value = tc->toUnicode( vObjectStringZValue( o ) );		else		    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 == "X-Qtopia-CSOUND" )	    c.setCompanyPronunciation( value );	else if ( name == VCTitleProp ) {	    c.setJobTitle( value );	}	else if ( name == VCNoteProp ) {	    c.setNotes( value );	}	else if (name == VCBirthDateProp ) {	    c.setBirthday( PimXmlIO::xmlToDate( 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( (PimContact::GenderType) value.toInt() );	}	else if ( name == "X-Qtopia-Anniversary" ) {	    c.setAnniversary( PimXmlIO::xmlToDate( value ) );	}	else if ( name == "X-Qtopia-Nickname" ) {	    c.setNickname( value );	}	else if ( name == "X-Qtopia-Children" ) {	    c.setChildren( value );	} else {	    qpe_setVObjectProperty(name,value,"Address Book",&c); // No tr	}#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;}/*!   Write the list of \a contacts as vCard objects to the file   specified by \a filename.   \sa readVCard()*/void PimContact::writeVCard( const QString &filename, const QValueList<PimContact> &contacts){	QFileDirect f( filename.utf8().data() );	if ( !f.open( IO_WriteOnly ) ) {		qWarning("Unable to open vcard write");		return;	}    QValueList<PimContact>::ConstIterator it;    for( it = contacts.begin(); it != contacts.end(); ++it ) {	VObject *obj = createVObject( *it );	writeVObject(f.directHandle() , obj );	cleanVObject( obj );    }    cleanStrTbl();}/*!   Write the \a contact as a vCard object to the file   specified by \a filename.   \sa readVCard()*/void PimContact::writeVCard( const QString &filename, const PimContact &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();}/*!  Reads the file specified by \a filename as a list of vCards objects  and returns the list of near equivalent contacts.  \sa writeVCard()*/QValueList<PimContact> PimContact::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<PimContact> contacts;    qpe_startVObjectInput();    while ( obj ) {	contacts.append( parseVObject( obj ) );	VObject *t = obj;	obj = nextVObjectInList(obj);	cleanVObject( t );    }    qpe_endVObjectInput();    return contacts;}/*!  Returns TRUE if the part of contact matches \a regexp. Otherwise returns FALSE.*/bool PimContact::match( const QString &regexp ) const{    return match(QRegExp(regexp));}/*!  Returns TRUE if the part of contact matches \a r. Otherwise returns FALSE.*/bool PimContact::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;}/*!  Returns a suitable display string for the contact.  \sa fileAs(), fullName()*/QString PimContact::bestLabel() const{    QString str = fileAs();    // fileAs is _usually_ lastname, Firstname, but not always    if (str.stripWhiteSpace().isEmpty()) {	if (lastName().isEmpty() && firstName().isEmpty()) {	    if (str.stripWhiteSpace().isEmpty()) {		str = company();		if (str.stripWhiteSpace().isEmpty()) {		    str = defaultEmail();		}	    }	} else {	    // firstname or last name not empty.	    if (lastName().isEmpty()) {		// only first,		return firstName();	    } else {		str = lastName();		if (!firstName().isEmpty())		    str += ", " + firstName();	    }	}    }    return str;}#ifndef QT_NO_DATASTREAMQDataStream &operator>>( QDataStream &s, PimContact &c ){    s >> (PimRecord&)c;    s >> c.mMap;    return s;}QDataStream &operator<<( QDataStream &s, const PimContact &c ){    s << (const PimRecord&)c;    s << c.mMap;    return s;}#endifstatic const QtopiaPimMapEntry addressbookentries[] = {    // name    { "Title", // No tr	    QT_TRANSLATE_NOOP("PimContact",  "Title"), PimContact::NameTitle, 0 },    { "FirstName", QT_TRANSLATE_NOOP("PimContact",  "First Name" ), PimContact::FirstName, 20 },    { "MiddleName", QT_TRANSLATE_NOOP("PimContact",  "Middle Name" ), PimContact::MiddleName, 10 },    { "LastName", QT_TRANSLATE_NOOP("PimContact",  "Last Name" ), PimContact::LastName, 60 },    { "Suffix", QT_TRANSLATE_NOOP("PimContact",  "Suffix" ), PimContact::Suffix, 0 },    { "FileAs", QT_TRANSLATE_NOOP("PimContact",  "File As" ), PimContact::FileAs, 0 },    // email    { "DefaultEmail", QT_TRANSLATE_NOOP("PimContact",  "Default Email" ), PimContact::DefaultEmail, 50 },    { "Emails", QT_TRANSLATE_NOOP("PimContact",  "Emails" ), PimContact::Emails, 50 },

⌨️ 快捷键说明

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