📄 contact.cpp
字号:
\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 title, suffix, first, middle and last name of the contact.*/QString PimContact::fullName() const{ return fullName(*this);}static bool readConfig = FALSE;static QStringList formatList;QString PimContact::fullName(const PimContact &cnt){ if (!readConfig) { // 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 = keyToIdentifierMap(); formatList.append(k2i[NameTitle]); formatList.append(k2i[FirstName]); formatList.append(k2i[MiddleName]); formatList.append(k2i[LastName]); formatList.append(k2i[Suffix]); } else { formatList = sl; } readConfig = TRUE; } QStringList::Iterator it; QString name; const QMap<QCString, int> i2k = identifierToKeyMap(); 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 ( !name.isEmpty() ) name += " "; name += field; } } else { if ( !name.isEmpty() ) name += *it; } }#if 0 if ( !firstName.isEmpty() ) { if ( !name.isEmpty() ) name += " "; name += firstName; } if ( !middleName.isEmpty() ) { if ( !name.isEmpty() ) } QString title = find( NameTitle ); QString firstName = find( FirstName ); QString middleName = find( MiddleName ); QString lastName = find( LastName ); QString suffix = find( Suffix ); QString name = title; if ( !firstName.isEmpty() ) { if ( !name.isEmpty() ) name += " "; name += firstName; } if ( !middleName.isEmpty() ) { if ( !name.isEmpty() ) name += " "; name += middleName; } if ( !lastName.isEmpty() ) { if ( !name.isEmpty() ) name += " "; name += lastName; } if ( !suffix.isEmpty() ) { if ( !name.isEmpty() ) name += " "; name += suffix; }#endif return name.simplifyWhiteSpace();}/*! Set the contact to be filed as a string constructed from the contact's name fields.*/void PimContact::setFileAs(){ QString lastName, firstName, middleName, fileas; lastName = find( LastName ); firstName = find( FirstName ); middleName = find( MiddleName ); if ( !lastName.isEmpty() && !firstName.isEmpty() && !middleName.isEmpty() ) fileas = lastName + ", " + firstName + " " + middleName; else if ( !lastName.isEmpty() && !firstName.isEmpty() ) fileas = lastName + ", " + firstName; else if ( !lastName.isEmpty() || !firstName.isEmpty() || !middleName.isEmpty() ) fileas = firstName + ( firstName.isEmpty() ? "" : " " ) + middleName + ( middleName.isEmpty() ? "" : " " ) + lastName; replace( FileAs, fileas );}/*! 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.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.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() ); // 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; VObjectIterator it;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -