📄 contact.cpp
字号:
This enum describes the three possible choices for gender. \value UnspecifiedGender \value Male \value Female*//*! Returns the gender of the contact as type GenderType.*/PimContact::GenderType PimContact::gender() const{ QString genderStr = find( Gender ); switch( genderStr.toInt() ) { case 1: return Male; case 2: return Female; case 0: default: return UnspecifiedGender; }}/*! Sets the person's birthday to \a d.*/void PimContact::setBirthday( const QDate &d ){ replace( Birthday, PimXmlIO::dateToXml( d ) );}/*! Return the person's birthday. QDate will be null if there is birthday has not been set.*/QDate PimContact::birthday() const{ return PimXmlIO::xmlToDate( find( Birthday ) );}/*! Sets the person's anniversary to \a d.*/void PimContact::setAnniversary( const QDate &d ){ replace( Anniversary, PimXmlIO::dateToXml( d ) );}/*! Return the person's anniversary date. QDate will be null if there is anniversary has not been set.*/QDate PimContact::anniversary() const{ return PimXmlIO::xmlToDate( find( Anniversary ) );}/*! Returns the full name of the contact, generated from the current user preferences. fileAs() in general will be a cached vopy of this. \sa setFileAs()*/QString PimContact::fullName() const{ return fullName(*this);}static bool nameFormatCache = FALSE;static QStringList formatList;static void readNameFormatConfig(){ // NameFormat // FirstName LastName // LastName , _ FirstName // LastName , _ FirstName | Company // read config for formatted name order. Config cfg("Contacts"); cfg.setGroup("formatting"); QStringList sl = cfg.readListEntry("NameFormat", ' '); if (sl.isEmpty()) { const QMap<int,QCString> k2i = PimContact::keyToIdentifierMap(); formatList.append(k2i[PimContact::NameTitle]); formatList.append(k2i[PimContact::FirstName]); formatList.append(k2i[PimContact::MiddleName]); formatList.append(k2i[PimContact::LastName]); formatList.append(k2i[PimContact::Suffix]); formatList.append("|"); formatList.append(k2i[PimContact::Company]); } else { formatList = sl; }}void qpe_setNameFormatCache(bool y){ nameFormatCache = y; if ( y ) readNameFormatConfig();}QString PimContact::fullName(const PimContact &cnt){ if (!nameFormatCache) readNameFormatConfig(); QStringList::Iterator it; QString name; const QMap<QCString, int> i2k = identifierToKeyMap(); bool any = FALSE; bool prev = FALSE; for( it = formatList.begin(); it != formatList.end(); ++it ) { QCString cit(*it); if (i2k.contains(cit)) { QString field = cnt.find(i2k[cit]); if (!field.isEmpty()) { if ( prev ) name += " "; name += field; any = TRUE; prev = TRUE; } } else if ( *it == "|" ) { if ( any ) break; name = ""; prev = FALSE; } else if ( *it == "_" ) { name += ' '; prev = FALSE; } else { if ( !name.isEmpty() ) { name += *it; } prev = FALSE; } } return name.simplifyWhiteSpace();}/*! Set the contact to be filed by the fullName().*/void PimContact::setFileAs(){ replace( FileAs, fullName() );}/*! Adds \a email to the list of email address for the contact. If no default email is set, the default email will be set to \a email.*/void PimContact::insertEmail( const QString &email ){ //qDebug("insertEmail %s", v.latin1()); QString e = email.simplifyWhiteSpace(); QString def = defaultEmail(); // if no default, set it as the default email and don't insert if ( def.isEmpty() ) { setDefaultEmail( e ); // will insert into the list for us return; } // otherwise, insert assuming doesn't already exist QString emailsStr = find( Emails ); if ( emailsStr.contains( e )) return; if ( !emailsStr.isEmpty() ) emailsStr += emailSeparator(); emailsStr += e; replace( Emails, emailsStr );}/*! Removes \a email from the list of email address for the contact. If the email is the default email, the default email will be set to the first one in the list.*/void PimContact::removeEmail( const QString &email ){ QString e = email.simplifyWhiteSpace(); QString def = defaultEmail(); QString emailsStr = find( Emails ); QStringList emails = emailList(); // otherwise, must first contain it if ( !emailsStr.contains( e ) ) return; // remove it //qDebug(" removing email from list %s", e.latin1()); emails.remove( e ); // reset the string emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator replace( Emails, emailsStr ); // if default, then replace the default email with the first one if ( def == e ) { //qDebug("removeEmail is default; setting new default"); if ( !emails.count() ) clearEmailList(); else // setDefaultEmail will remove e from the list setDefaultEmail( emails.first() ); }}/*! Clear the email list for the contact, including the default email.*/void PimContact::clearEmailList(){ mMap.remove( DefaultEmail ); mMap.remove( Emails );}/*! Returns a list of email addresses belonging to the contact, including the default email address.*/QStringList PimContact::emailList() const{ QString emailStr = find( Emails ); QStringList r; if ( !emailStr.isEmpty() ) { QStringList l = QStringList::split( emailSeparator(), emailStr ); for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) r += (*it).simplifyWhiteSpace(); } return r;}/*! Sets the default email to \a v and adds it to the list.*/void PimContact::setDefaultEmail( const QString &v ){ QString e = v.simplifyWhiteSpace(); //qDebug("PimContact::setDefaultEmail %s", e.latin1()); replace( DefaultEmail, e ); if ( !e.isEmpty() ) insertEmail( e );}/*! Sets the email list to \a emails*/void PimContact::setEmailList( const QStringList &emails ){ clearEmailList(); for ( QStringList::ConstIterator it = emails.begin(); it != emails.end(); ++it ) insertEmail( *it );}/*! Sets the children of the contact to \a children.*/void PimContact::setChildren( const QString &children ){ replace( Children, children );}// In pimrecord.cppvoid qpe_startVObjectInput();void qpe_endVObjectInput();void qpe_startVObjectOutput();void qpe_setVObjectProperty(const QString&, const QString&, const char* type, PimRecord*);void qpe_endVObjectOutput(VObject *,const char* type,const PimRecord*);VObject *qpe_safeAddPropValue( VObject *o, const char *prop, const QString &value );static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ){ return qpe_safeAddPropValue(o,prop,value); }VObject *qpe_safeAddProp( VObject *o, const char *prop);static inline VObject *safeAddProp( VObject *o, const char *prop){ return qpe_safeAddProp(o,prop); }static void safeAddAddress( VObject* vcard, const char* prop, const QString& bs, const QString& bc, const QString& bst, const QString& bz, const QString& bco){ // Not really needed now, since parse handles empty values if ( !!bs || !!bc || !!bst || !!bz || !!bco ) { VObject *adr= safeAddProp( vcard, VCAdrProp ); safeAddProp( adr, prop ); safeAddPropValue( adr, VCStreetAddressProp, bs ); safeAddPropValue( adr, VCCityProp, bc ); safeAddPropValue( adr, VCRegionProp, bst ); safeAddPropValue( adr, VCPostalCodeProp, bz ); safeAddPropValue( adr, VCCountryNameProp, bco ); }}/*! \internal*/VObject *PimContact::createVObject( const PimContact &c ){ qpe_startVObjectOutput(); VObject *vcard = newVObject( VCCardProp ); safeAddPropValue( vcard, VCVersionProp, "2.1" ); safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.p_uid().data1) ); // full name safeAddPropValue( vcard, VCFullNameProp, c.fileAs() ); // 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.nameTitle() ); safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); safeAddPropValue( vcard, VCPronunciationProp, c.firstNamePronunciation() ); safeAddPropValue( vcard, "X-Qtopia-LNSOUND", c.lastNamePronunciation() ); // home properties safeAddAddress( vcard, VCHomeProp, c.homeStreet(), c.homeCity(), c.homeState(), c.homeZip(), 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 safeAddAddress( vcard, VCWorkProp, c.businessStreet(), c.businessCity(), c.businessState(), c.businessZip(), 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 ); if (*it == c.defaultEmail()) safeAddProp( email, VCPreferredProp ); } safeAddPropValue( vcard, VCNoteProp, c.notes() ); safeAddPropValue( vcard, VCBirthDateProp, PimXmlIO::dateToXml( 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() ); } safeAddPropValue( vcard, "X-Qtopia-CSOUND", c.companyPronunciation() ); //photo QString pfn = c.customField("photofile"); if ( !pfn.isEmpty() ) { const char* format = "JPEG";#if 0 // load-and-save (allows non-JPEG images) QImage sp; if( !sp.load( pfn ) ) { qWarning("PimContact::createVObject - Unable to load contact photo"); } else { QBuffer buffer; buffer.open(IO_WriteOnly); QImageIO iio(&buffer,format); iio.setImage(sp); QString prettyEncPhoto; if ( iio.write() ) { QByteArray buf = buffer.buffer();#else // Just use the file (avoid compounding JPEG lossiness) QFile f(pfn); if ( f.open(IO_ReadOnly) ) { QByteArray buf = f.readAll(); if ( buf.size() ) {#endif VObject *po = addPropSizedValue( vcard, VCPhotoProp, buf.data(), buf.size() ); safeAddPropValue( po, "TYPE", format ); // should really be done by vobject.cpp, since it decides to use base64 safeAddPropValue( po, VCEncodingProp, "BASE64" ); } } } // 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() ); if ( c.gender() != PimContact::UnspecifiedGender ) safeAddPropValue( vcard, "X-Qtopia-Gender", QString::number( (int)c.gender() ) ); safeAddPropValue( vcard, "X-Qtopia-Anniversary", PimXmlIO::dateToXml( c.anniversary() ) ); safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); qpe_endVObjectOutput(vcard,"Address Book",&c); // No tr return vcard;}static PimContact parseVObject( VObject *obj ){ PimContact c;// int ds = 0;// char *photodata = 0; VObjectIterator it; initPropIterator( &it, obj ); while( moreIteration( &it ) ) { VObject *o = nextVObject( &it );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -