void ResourceSlox::createAddresseeFields( QDomDocument &doc, QDomElement &prop, const Addressee &a ) { // choose addressbook WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() ); // person WebdavHandler::addSloxElement( this, doc, prop, fieldName( GivenName ), a.givenName() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( FamilyName ), a.familyName() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Title ), a.title() ); if ( !a.birthday().isNull() ) WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ), WebdavHandler::qDateTimeToSlox( a.birthday() ) ); else WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ) ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Role ), a.role() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Department ), a.custom( "KADDRESSBOOK", "X-Department" ) ); if ( type() == "ox" ) { // OX only fields WebdavHandler::addSloxElement( this, doc, prop, fieldName( DisplayName ), a.formattedName() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondName ), a.additionalName() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Suffix ), a.suffix() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Organization ), a.organization() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( NickName ), a.nickName() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( InstantMsg ), a.custom( "KADDRESSBOOK", "X-IMAddress" ) ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Office ), a.custom( "KADDRESSBOOK", "X-Office" ) ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Profession ), a.custom( "KADDRESSBOOK", "X-Profession" ) ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( ManagersName ), a.custom( "KADDRESSBOOK", "X-ManagersName" ) ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( AssistantsName ), a.custom( "KADDRESSBOOK", "X-AssistantsName" ) ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( SpousesName ), a.custom( "KADDRESSBOOK", "X-SpousesName" ) ); QString anniversary = a.custom( "KADDRESSBOOK", "X-Anniversary" ); if ( !anniversary.isEmpty() ) WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ), WebdavHandler::qDateTimeToSlox( QDateTime::fromString( anniversary, Qt::ISODate ).date() ) ); else WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ) ); } WebdavHandler::addSloxElement( this, doc, prop, fieldName( Url ), a.url().url() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Comment ), a.note() ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( Categories ), a.categories().join( ", " ) ); // emails QStringList email_list = a.emails(); QStringList::const_iterator emails_it = email_list.begin(); if ( emails_it != email_list.end() ) WebdavHandler::addSloxElement( this, doc, prop, fieldName( PrimaryEmail ), *(emails_it++) ); if ( emails_it != email_list.end() ) WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail1 ), *(emails_it++) ); if ( emails_it != email_list.end() ) WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail2 ), *(emails_it++) ); // phone numbers PhoneNumber::List pnlist = a.phoneNumbers(); QMap<int, QStringList> pnSaveMap; if ( type() == "ox" ) pnSaveMap = mPhoneNumberOxMap; else pnSaveMap = mPhoneNumberSloxMap; for ( PhoneNumber::List::ConstIterator it = pnlist.begin() ; it != pnlist.end(); ++it ) { if ( pnSaveMap.contains( (*it).type() ) ) { QStringList l = pnSaveMap[(*it).type()]; QString fn = l.first(); l.remove( l.begin() ); if ( !l.isEmpty() ) pnSaveMap[(*it).type()] = l; else pnSaveMap.remove( (*it).type() ); WebdavHandler::addSloxElement( this, doc, prop, fn, (*it).number() ); } else kdDebug() << k_funcinfo << "Can't save phone number " << (*it).number() << " of type " << (*it).type() << endl; } // send empty fields for the remaining ohone number fields // it's not possible to delete phone numbers otherwise for ( QMap<int, QStringList>::ConstIterator it = pnSaveMap.begin(); it != pnSaveMap.end(); ++it ) { QStringList l = it.data(); for ( QStringList::ConstIterator it2 = l.begin(); it2 != l.end(); ++it2 ) WebdavHandler::addSloxElement( this, doc, prop, (*it2) ); } // write addresses createAddressFields( doc, prop, fieldName( HomePrefix ), a.address( KABC::Address::Home ) ); if ( type() == "ox" ) { createAddressFields( doc, prop, fieldName( BusinessPrefix ), a.address( KABC::Address::Work ) ); createAddressFields( doc, prop, fieldName( OtherPrefix ), a.address( 0 ) ); } }
bool LDIFConverter::addresseeToLDIF( const Addressee &addr, QString &str ) { if ( addr.isEmpty() ) return false; QTextStream t( str, IO_WriteOnly|IO_Append ); t.setEncoding( QTextStream::UnicodeUTF8 ); const Address homeAddr = addr.address( Address::Home ); const Address workAddr = addr.address( Address::Work ); ldif_out( t, "dn", QString( "cn=%1,mail=%2" ) .arg( addr.formattedName().simplifyWhiteSpace() ) .arg( addr.preferredEmail() ) ); ldif_out( t, "givenname", addr.givenName() ); ldif_out( t, "sn", addr.familyName() ); ldif_out( t, "cn", addr.formattedName().simplifyWhiteSpace() ); ldif_out( t, "uid", addr.uid() ); ldif_out( t, "nickname", addr.nickName() ); ldif_out( t, "xmozillanickname", addr.nickName() ); ldif_out( t, "mail", addr.preferredEmail() ); if ( addr.emails().count() > 1 ) ldif_out( t, "mozillasecondemail", addr.emails()[ 1 ] ); //ldif_out( t, "mozilla_AIMScreenName: %1\n", "screen_name" ); ldif_out( t, "telephonenumber", addr.phoneNumber( PhoneNumber::Work ).number() ); ldif_out( t, "facsimiletelephonenumber", addr.phoneNumber( PhoneNumber::Fax ).number() ); ldif_out( t, "homephone", addr.phoneNumber( PhoneNumber::Home ).number() ); ldif_out( t, "mobile", addr.phoneNumber( PhoneNumber::Cell ).number() ); // Netscape 7 ldif_out( t, "cellphone", addr.phoneNumber( PhoneNumber::Cell ).number() ); // Netscape 4.x ldif_out( t, "pager", addr.phoneNumber( PhoneNumber::Pager ).number() ); ldif_out( t, "pagerphone", addr.phoneNumber( PhoneNumber::Pager ).number() ); ldif_out( t, "streethomeaddress", homeAddr.street() ); ldif_out( t, "postalcode", workAddr.postalCode() ); ldif_out( t, "postofficebox", workAddr.postOfficeBox() ); QStringList streets = QStringList::split( '\n', homeAddr.street() ); if ( streets.count() > 0 ) ldif_out( t, "homepostaladdress", streets[ 0 ] ); // Netscape 7 if ( streets.count() > 1 ) ldif_out( t, "mozillahomepostaladdress2", streets[ 1 ] ); // Netscape 7 ldif_out( t, "mozillahomelocalityname", homeAddr.locality() ); // Netscape 7 ldif_out( t, "mozillahomestate", homeAddr.region() ); ldif_out( t, "mozillahomepostalcode", homeAddr.postalCode() ); ldif_out( t, "mozillahomecountryname", Address::ISOtoCountry(homeAddr.country()) ); ldif_out( t, "locality", workAddr.locality() ); ldif_out( t, "streetaddress", workAddr.street() ); // Netscape 4.x streets = QStringList::split( '\n', workAddr.street() ); if ( streets.count() > 0 ) ldif_out( t, "postaladdress", streets[ 0 ] ); if ( streets.count() > 1 ) ldif_out( t, "mozillapostaladdress2", streets[ 1 ] ); ldif_out( t, "countryname", Address::ISOtoCountry(workAddr.country()) ); ldif_out( t, "l", workAddr.locality() ); ldif_out( t, "c", Address::ISOtoCountry(workAddr.country()) ); ldif_out( t, "st", workAddr.region() ); ldif_out( t, "title", addr.title() ); ldif_out( t, "vocation", addr.prefix() ); ldif_out( t, "ou", addr.role() ); ldif_out( t, "o", addr.organization() ); ldif_out( t, "organization", addr.organization() ); ldif_out( t, "organizationname", addr.organization() ); // Compatibility with older kabc versions. if ( !addr.department().isEmpty() ) ldif_out( t, "department", addr.department() ); else ldif_out( t, "department", addr.custom("KADDRESSBOOK", "X-Department") ); ldif_out( t, "workurl", addr.url().prettyURL() ); ldif_out( t, "homeurl", addr.url().prettyURL() ); ldif_out( t, "description", addr.note() ); if (addr.revision().isValid()) ldif_out(t, "modifytimestamp", dateToVCardString( addr.revision()) ); t << "objectclass: top\n"; t << "objectclass: person\n"; t << "objectclass: organizationalPerson\n"; t << "\n"; return true; }
bool LDIFConverter::evaluatePair( Addressee &a, Address &homeAddr, Address &workAddr, QString &fieldname, QString &value ) { if ( fieldname == QString::fromLatin1( "dn" ) ) // ignore & return false! return false; if ( fieldname.startsWith("#") ) { return true; } if ( fieldname.isEmpty() && !a.note().isEmpty() ) { // some LDIF export filters are borken and add additional // comments on stand-alone lines. Just add them to the notes for now. a.setNote( a.note() + "\n" + value ); return true; } if ( fieldname == QString::fromLatin1( "givenname" ) ) { a.setGivenName( value ); return true; } if ( fieldname == QString::fromLatin1( "xmozillanickname") || fieldname == QString::fromLatin1( "nickname") ) { a.setNickName( value ); return true; } if ( fieldname == QString::fromLatin1( "sn" ) ) { a.setFamilyName( value ); return true; } if ( fieldname == QString::fromLatin1( "uid" ) ) { a.setUid( value ); return true; } if ( fieldname == QString::fromLatin1( "mail" ) || fieldname == QString::fromLatin1( "mozillasecondemail" ) ) { // mozilla if ( a.emails().findIndex( value ) == -1 ) a.insertEmail( value ); return true; } if ( fieldname == QString::fromLatin1( "title" ) ) { a.setTitle( value ); return true; } if ( fieldname == QString::fromLatin1( "vocation" ) ) { a.setPrefix( value ); return true; } if ( fieldname == QString::fromLatin1( "cn" ) ) { a.setFormattedName( value ); return true; } if ( fieldname == QString::fromLatin1( "o" ) || fieldname == QString::fromLatin1( "organization" ) || // Exchange fieldname == QString::fromLatin1( "organizationname" ) ) { // Exchange a.setOrganization( value ); return true; } if ( fieldname == QString::fromLatin1( "description" ) ) { addComment: if ( !a.note().isEmpty() ) a.setNote( a.note() + "\n" ); a.setNote( a.note() + value ); return true; } if ( fieldname == QString::fromLatin1( "custom1" ) || fieldname == QString::fromLatin1( "custom2" ) || fieldname == QString::fromLatin1( "custom3" ) || fieldname == QString::fromLatin1( "custom4" ) ) { goto addComment; } if ( fieldname == QString::fromLatin1( "homeurl" ) || fieldname == QString::fromLatin1( "workurl" ) ) { if (a.url().isEmpty()) { a.setUrl( KURL( value ) ); return true; } if ( a.url().prettyURL() == KURL(value).prettyURL() ) return true; // TODO: current version of kabc only supports one URL. // TODO: change this with KDE 4 } if ( fieldname == QString::fromLatin1( "homephone" ) ) { a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Home ) ); return true; } if ( fieldname == QString::fromLatin1( "telephonenumber" ) ) { a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Work ) ); return true; } if ( fieldname == QString::fromLatin1( "mobile" ) ) { // mozilla/Netscape 7 a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Cell ) ); return true; } if ( fieldname == QString::fromLatin1( "cellphone" ) ) { a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Cell ) ); return true; } if ( fieldname == QString::fromLatin1( "pager" ) || // mozilla fieldname == QString::fromLatin1( "pagerphone" ) ) { // mozilla a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Pager ) ); return true; } if ( fieldname == QString::fromLatin1( "facsimiletelephonenumber" ) ) { a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Fax ) ); return true; } if ( fieldname == QString::fromLatin1( "xmozillaanyphone" ) ) { // mozilla a.insertPhoneNumber( PhoneNumber( value, PhoneNumber::Work ) ); return true; } if ( fieldname == QString::fromLatin1( "street" ) || fieldname == QString::fromLatin1( "streethomeaddress" ) ) { homeAddr.setStreet( value ); return true; } if ( fieldname == QString::fromLatin1( "postaladdress" ) ) { // mozilla workAddr.setStreet( value ); return true; } if ( fieldname == QString::fromLatin1( "mozillapostaladdress2" ) ) { // mozilla workAddr.setStreet( workAddr.street() + QString::fromLatin1( "\n" ) + value ); return true; } if ( fieldname == QString::fromLatin1( "postalcode" ) ) { workAddr.setPostalCode( value ); return true; } if ( fieldname == QString::fromLatin1( "postofficebox" ) ) { workAddr.setPostOfficeBox( value ); return true; } if ( fieldname == QString::fromLatin1( "homepostaladdress" ) ) { // Netscape 7 homeAddr.setStreet( value ); return true; } if ( fieldname == QString::fromLatin1( "mozillahomepostaladdress2" ) ) { // mozilla homeAddr.setStreet( homeAddr.street() + QString::fromLatin1( "\n" ) + value ); return true; } if ( fieldname == QString::fromLatin1( "mozillahomelocalityname" ) ) { // mozilla homeAddr.setLocality( value ); return true; } if ( fieldname == QString::fromLatin1( "mozillahomestate" ) ) { // mozilla homeAddr.setRegion( value ); return true; } if ( fieldname == QString::fromLatin1( "mozillahomepostalcode" ) ) { // mozilla homeAddr.setPostalCode( value ); return true; } if ( fieldname == QString::fromLatin1( "mozillahomecountryname" ) ) { // mozilla if ( value.length() <= 2 ) value = Address::ISOtoCountry(value); homeAddr.setCountry( value ); return true; } if ( fieldname == QString::fromLatin1( "locality" ) ) { workAddr.setLocality( value ); return true; } if ( fieldname == QString::fromLatin1( "streetaddress" ) ) { // Netscape 4.x workAddr.setStreet( value ); return true; } if ( fieldname == QString::fromLatin1( "countryname" ) || fieldname == QString::fromLatin1( "c" ) ) { // mozilla if ( value.length() <= 2 ) value = Address::ISOtoCountry(value); workAddr.setCountry( value ); return true; } if ( fieldname == QString::fromLatin1( "l" ) ) { // mozilla workAddr.setLocality( value ); return true; } if ( fieldname == QString::fromLatin1( "st" ) ) { workAddr.setRegion( value ); return true; } if ( fieldname == QString::fromLatin1( "ou" ) ) { a.setRole( value ); return true; } if ( fieldname == QString::fromLatin1( "department" ) ) { a.setDepartment( value ); return true; } if ( fieldname == QString::fromLatin1( "member" ) ) { // this is a mozilla list member (cn=xxx, mail=yyy) QStringList list( QStringList::split( ',', value ) ); QString name, email; QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( (*it).startsWith( "cn=" ) ) name = (*it).mid( 3 ).stripWhiteSpace(); if ( (*it).startsWith( "mail=" ) ) email = (*it).mid( 5 ).stripWhiteSpace(); } if ( !name.isEmpty() && !email.isEmpty() ) email = " <" + email + ">"; a.insertEmail( name + email ); a.insertCategory( i18n( "List of Emails" ) ); return true; } if ( fieldname == QString::fromLatin1( "modifytimestamp" ) ) { if (value == QString::fromLatin1("0Z")) // ignore return true; QDateTime dt = VCardStringToDate( value ); if ( dt.isValid() ) { a.setRevision(dt); return true; } } if ( fieldname == QString::fromLatin1( "objectclass" ) ) // ignore return true; kdWarning() << QString("LDIFConverter: Unknown field for '%1': '%2=%3'\n") .arg(a.formattedName()).arg(fieldname).arg(value); return true; }
bool LDIFConverter::LDIFToAddressee( const QString &str, AddresseeList &addrList, QDateTime dt ) { if (str.isEmpty()) return true; bool endldif = false, end = false; LDIF ldif; LDIF::ParseVal ret; const char *latinstr = str.latin1(); int latinstrlen = qstrlen( latinstr ); QByteArray data; Addressee a; Address homeAddr, workAddr; data.setRawData( latinstr, latinstrlen ); ldif.setLDIF( data ); if (!dt.isValid()) dt = QDateTime::currentDateTime(); a.setRevision(dt); homeAddr = Address( Address::Home ); workAddr = Address( Address::Work ); do { ret = ldif.nextItem(); switch ( ret ) { case LDIF::Item: { QString fieldname = ldif.attr().lower(); QString value = QString::fromUtf8( ldif.val(), ldif.val().size() ); evaluatePair( a, homeAddr, workAddr, fieldname, value ); break; } case LDIF::EndEntry: // if the new address is not empty, append it if ( !a.formattedName().isEmpty() || !a.name().isEmpty() || !a.familyName().isEmpty() ) { if ( !homeAddr.isEmpty() ) a.insertAddress( homeAddr ); if ( !workAddr.isEmpty() ) a.insertAddress( workAddr ); addrList.append( a ); } a = Addressee(); a.setRevision(dt); homeAddr = Address( Address::Home ); workAddr = Address( Address::Work ); break; case LDIF::MoreData: { if ( endldif ) end = true; else { ldif.endLDIF(); endldif = true; break; } } default: break; } } while ( !end ); data.resetRawData( latinstr, latinstrlen ); return true; }
bool SortingTraits::FormattedName::lt( const Addressee &a1, const Addressee &a2 ) { return ( TQString::localeAwareCompare( a1.formattedName(), a2.formattedName() ) < 0 ); }
void VCardFormatImpl::saveAddressee( const Addressee &addressee, VCARD::VCard *v, bool intern ) { ContentLine cl; QString value; addTextValue( v, EntityName, addressee.name() ); addTextValue( v, EntityUID, addressee.uid() ); addTextValue( v, EntityFullName, addressee.formattedName() ); QStringList emails = addressee.emails(); QStringList::ConstIterator it4; for( it4 = emails.begin(); it4 != emails.end(); ++it4 ) { addTextValue( v, EntityEmail, *it4 ); } QStringList customs = addressee.customs(); QStringList::ConstIterator it5; for( it5 = customs.begin(); it5 != customs.end(); ++it5 ) { addCustomValue( v, *it5 ); } addTextValue( v, EntityURL, addressee.url().url() ); addNValue( v, addressee ); addTextValue( v, EntityNickname, addressee.nickName() ); addTextValue( v, EntityMailer, addressee.mailer() ); addTextValue( v, EntityTitle, addressee.title() ); addTextValue( v, EntityRole, addressee.role() ); addTextValue( v, EntityOrganisation, addressee.organization() ); addTextValue( v, EntityNote, addressee.note() ); addTextValue( v, EntityProductID, addressee.productId() ); addTextValue( v, EntitySortString, addressee.sortString() ); Address::List addresses = addressee.addresses(); Address::List::ConstIterator it3; for( it3 = addresses.begin(); it3 != addresses.end(); ++it3 ) { addAddressValue( v, *it3 ); addLabelValue( v, *it3 ); } PhoneNumber::List phoneNumbers = addressee.phoneNumbers(); PhoneNumber::List::ConstIterator it2; for( it2 = phoneNumbers.begin(); it2 != phoneNumbers.end(); ++it2 ) { addTelephoneValue( v, *it2 ); } Key::List keys = addressee.keys(); Key::List::ConstIterator it6; for( it6 = keys.begin(); it6 != keys.end(); ++it6 ) { addKeyValue( v, *it6 ); } addTextValue( v, EntityCategories, addressee.categories().join(",") ); addDateValue( v, EntityBirthday, addressee.birthday().date() ); addDateTimeValue( v, EntityRevision, addressee.revision() ); addGeoValue( v, addressee.geo() ); addUTCValue( v, addressee.timeZone() ); addClassValue( v, addressee.secrecy() ); addPictureValue( v, EntityPhoto, addressee.photo(), addressee, intern ); addPictureValue( v, EntityLogo, addressee.logo(), addressee, intern ); addAgentValue( v, addressee.agent() ); addSoundValue( v, addressee.sound(), addressee, intern ); }