bool ResourceSql::load() { QSqlQuery query( "select addressId, name, familyName, givenName, " "additionalName, prefix, suffix, nickname, birthday, " "mailer, timezone, geo_latitude, geo_longitude, title, " "role, organization, note, productId, revision, " "sortString, url from kaddressbook_main_" + mUser); while(query.next()) { QString addrId = query.value(0).toString(); Addressee addr; addr.setResource(this); addr.setUid(addrId); addr.setName(query.value(1).toString()); addr.setFamilyName(query.value(2).toString()); addr.setGivenName(query.value(3).toString()); addr.setAdditionalName(query.value(4).toString()); addr.setPrefix(query.value(5).toString()); addr.setSuffix(query.value(6).toString()); addr.setNickName(query.value(7).toString()); addr.setBirthday(query.value(8).toDateTime()); addr.setMailer(query.value(9).toString()); addr.setTimeZone(TimeZone(query.value(10).toInt())); addr.setGeo(Geo(query.value(11).toDouble(), query.value(12).toDouble())); addr.setTitle(query.value(13).toString()); addr.setRole(query.value(14).toString()); addr.setOrganization(query.value(15).toString()); addr.setNote(query.value(16).toString()); addr.setProductId(query.value(17).toString()); addr.setRevision(query.value(18).toDateTime()); addr.setSortString(query.value(19).toString()); addr.setUrl(query.value(20).toString()); // emails { QSqlQuery emailsQuery( "select email, preferred from kaddressbook_emails " "where addressId = '" + addrId + "'"); while(emailsQuery.next()) addr.insertEmail(emailsQuery.value(0).toString(), emailsQuery.value(1).toInt()); } // phones { QSqlQuery phonesQuery( "select number, type from kaddressbook_phones " "where addressId = '" + addrId + "'"); while(phonesQuery.next()) addr.insertPhoneNumber(PhoneNumber(phonesQuery.value(0).toString(), phonesQuery.value(1).toInt())); } // addresses { QSqlQuery addressesQuery( "select postOfficeBox, extended, street, " "locality, region, postalCode, country, label, type " "from kaddressbook_addresses where addressId = '" + addrId + "'"); while(addressesQuery.next()) { Address a; a.setPostOfficeBox(addressesQuery.value(0).toString()); a.setExtended(addressesQuery.value(1).toString()); a.setStreet(addressesQuery.value(2).toString()); a.setLocality(addressesQuery.value(3).toString()); a.setRegion(addressesQuery.value(4).toString()); a.setPostalCode(addressesQuery.value(5).toString()); a.setCountry(addressesQuery.value(6).toString()); a.setLabel(addressesQuery.value(7).toString()); a.setType(addressesQuery.value(8).toInt()); addr.insertAddress(a); } } // categories { QSqlQuery categoriesQuery( "select category from kaddressbook_categories " "where addressId = '" + addrId + "'"); while(categoriesQuery.next()) addr.insertCategory(categoriesQuery.value(0).toString()); } // customs { QSqlQuery customsQuery( "select app, name, value from kaddressbook_customs " "where addressId = '" + addrId + "'"); while(customsQuery.next()) addr.insertCustom(customsQuery.value(0).toString(), customsQuery.value(1).toString(), customsQuery.value(2).toString()); } addressBook()->insertAddressee(addr); } 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; }