You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
626 lines
24 KiB
626 lines
24 KiB
15 years ago
|
/*
|
||
|
This file is part of the exchange resource.
|
||
|
Copyright (c) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "exchangeconvertercontact.h"
|
||
|
#include <libkcal/freebusyurlstore.h>
|
||
|
#include <webdavhandler.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
|
||
|
using namespace KABC;
|
||
|
|
||
|
ExchangeConverterContact::ExchangeConverterContact()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
#define propertyDAV( prop ) \
|
||
|
WebdavHandler::addElement( doc, props, "d:" prop )
|
||
|
#define propertyNS( ns, prop ) \
|
||
|
WebdavHandler::addElementNS( doc, props, ns, prop )
|
||
|
#define propertyContact( prop ) \
|
||
|
WebdavHandler::addElement( doc, props, "c:" prop )
|
||
|
#define propertyCalendar( prop ) \
|
||
|
WebdavHandler::addElement( doc, props, "cal:" prop )
|
||
|
#define propertyHTTPMail( prop ) \
|
||
|
WebdavHandler::addElement( doc, props, "m:" prop )
|
||
|
#define property( prop ) \
|
||
|
Webdavhandler::addElement( doc, props, prop )
|
||
|
|
||
15 years ago
|
void ExchangeConverterContact::createRequest( TQDomDocument &doc, TQDomElement &props )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomAttr att_c = doc.createAttribute( "xmlns:c" );
|
||
15 years ago
|
att_c.setValue( "urn:schemas:contacts:" );
|
||
|
doc.documentElement().setAttributeNode( att_c );
|
||
15 years ago
|
TQDomAttr att_cal = doc.createAttribute( "xmlns:cal" );
|
||
15 years ago
|
att_cal.setValue( "urn:schemas:calendar:" );
|
||
|
doc.documentElement().setAttributeNode( att_cal );
|
||
14 years ago
|
|
||
15 years ago
|
propertyDAV( "contentclass" );
|
||
|
propertyDAV( "getcontenttype" );
|
||
|
propertyNS( "http://schemas.microsoft.com/exchange/", "outlookmessageclass" );
|
||
|
propertyDAV( "getetag" );
|
||
|
propertyDAV( "href" );
|
||
|
propertyDAV( "creationdate" );
|
||
|
propertyDAV( "getlastmodified" );
|
||
|
propertyDAV( "isreadonly" );
|
||
|
propertyContact( "cn" );
|
||
|
// propertyContact( "uid" );
|
||
|
propertyDAV( "uid" );
|
||
|
propertyContact( "fileas" );
|
||
|
propertyContact( "cn" );
|
||
|
propertyContact( "givenName" );
|
||
|
propertyContact( "initials" );
|
||
|
propertyContact( "middlename" );
|
||
|
propertyContact( "namesuffix" );
|
||
|
propertyContact( "personaltitle" );
|
||
|
propertyContact( "sn" );
|
||
|
propertyContact( "title" );
|
||
|
propertyContact( "o" );
|
||
|
propertyContact( "department" );
|
||
|
propertyContact( "roomnumber" );
|
||
|
propertyContact( "profession" );
|
||
|
propertyContact( "manager" );
|
||
|
propertyContact( "secretarycn" );
|
||
|
propertyContact( "email1" );
|
||
|
propertyContact( "email2" );
|
||
|
propertyContact( "email3" );
|
||
|
propertyContact( "personalHomePage" );
|
||
|
propertyContact( "businesshomepage" );
|
||
|
propertyContact( "fburl" );
|
||
|
// TODO: Does this work?
|
||
|
// propertyNS( "urn:schemas-microsoft-com:office:office", "Keywords" );
|
||
|
propertyDAV( "sensitivity" );
|
||
|
propertyContact( "telephoneNumber" );
|
||
|
propertyContact( "telephonenumber2" );
|
||
|
propertyContact( "officetelephonenumber" );
|
||
|
propertyContact( "office2telephonenumber" );
|
||
|
propertyContact( "secretaryphone" );
|
||
|
propertyContact( "organizationmainphone" );
|
||
|
propertyContact( "otherTelephone" );
|
||
|
propertyContact( "homePhone" );
|
||
|
propertyContact( "homephone2" );
|
||
|
propertyContact( "mobile" );
|
||
|
propertyContact( "othermobile" );
|
||
|
propertyContact( "facsimiletelephonenumber" );
|
||
|
propertyContact( "homefax" );
|
||
|
propertyContact( "otherfax" );
|
||
|
propertyContact( "pager" );
|
||
|
propertyContact( "otherpager" );
|
||
|
propertyContact( "internationalisdnnumber" );
|
||
|
propertyContact( "callbackphone" );
|
||
|
propertyContact( "telexnumber" );
|
||
|
propertyContact( "ttytddphone" );
|
||
|
propertyContact( "workaddress" );
|
||
|
propertyContact( "street" );
|
||
|
propertyContact( "postofficebox" );
|
||
|
propertyContact( "l" );
|
||
|
propertyContact( "postalcode" );
|
||
|
propertyContact( "st" );
|
||
|
propertyContact( "co" );
|
||
|
propertyContact( "c" );
|
||
|
propertyContact( "homepostaladdress" );
|
||
|
propertyContact( "homeStreet" );
|
||
|
propertyContact( "homepostofficebox" );
|
||
|
propertyContact( "homeCity" );
|
||
|
propertyContact( "homePostalCode" );
|
||
|
propertyContact( "homeState" );
|
||
|
propertyContact( "homeCountry" );
|
||
|
propertyContact( "homeCountrycode" );
|
||
|
propertyContact( "mailingpostaladdress" );
|
||
|
propertyContact( "mailingstreet" );
|
||
|
propertyContact( "mailingpostofficebox" );
|
||
|
propertyContact( "mailingcity" );
|
||
|
propertyContact( "mailingpostalcode" );
|
||
|
propertyContact( "mailingstate" );
|
||
|
propertyContact( "mailingcountry" );
|
||
|
propertyContact( "mailingcountrycode" );
|
||
|
propertyContact( "otherpostaladdress" );
|
||
|
propertyContact( "otherstreet" );
|
||
|
propertyContact( "otherpostofficebox" );
|
||
|
propertyContact( "othercity" );
|
||
|
propertyContact( "otherpostalcode" );
|
||
|
propertyContact( "otherstate" );
|
||
|
propertyContact( "othercountry" );
|
||
|
propertyContact( "othercountrycode" );
|
||
|
propertyContact( "nickname" );
|
||
|
propertyContact( "spousecn" );
|
||
|
propertyContact( "bday" );
|
||
|
propertyContact( "weddinganniversary" );
|
||
|
propertyCalendar( "geolatitude" );
|
||
|
propertyCalendar( "geolongitude" );
|
||
|
propertyContact( "mapurl" );
|
||
|
propertyContact( "location" );
|
||
|
propertyHTTPMail( "textdescription" );
|
||
|
propertyHTTPMail( "date" );
|
||
|
propertyContact( "usercertificate" );
|
||
|
}
|
||
|
#undef propertyDAV
|
||
|
#undef propertyNS
|
||
|
#undef propertyContact
|
||
|
#undef propertyCalendar
|
||
|
#undef propertyHTTPMail
|
||
|
#undef property
|
||
|
|
||
|
|
||
14 years ago
|
bool ExchangeConverterContact::extractAddress( const TQDomElement &node,
|
||
15 years ago
|
Addressee &addressee, int type,
|
||
14 years ago
|
const TQString &street, const TQString &pobox, const TQString &location,
|
||
|
const TQString &postalcode, const TQString &state, const TQString &country,
|
||
15 years ago
|
const TQString &/*countycode*/ )
|
||
15 years ago
|
{
|
||
|
bool haveAddr = false;
|
||
|
Address addr( type );
|
||
15 years ago
|
TQString tmpstr;
|
||
15 years ago
|
|
||
|
if ( WebdavHandler::extractString( node, street, tmpstr ) ) {
|
||
|
addr.setStreet( tmpstr );
|
||
|
haveAddr = true;
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, pobox, tmpstr ) ) {
|
||
|
addr.setPostOfficeBox( tmpstr );
|
||
|
haveAddr = true;
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, location, tmpstr ) ) {
|
||
|
addr.setLocality( tmpstr );
|
||
|
haveAddr = true;
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, postalcode, tmpstr ) ) {
|
||
|
addr.setPostalCode( tmpstr );
|
||
|
haveAddr = true;
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, state, tmpstr ) ) {
|
||
|
addr.setRegion( tmpstr );
|
||
|
haveAddr = true;
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, country, tmpstr ) ) {
|
||
|
addr.setCountry( tmpstr );
|
||
|
haveAddr = true;
|
||
|
}
|
||
|
// if ( WebdavHandler::extractString( node, countrycode, tmpstr ) ) {
|
||
|
// addr.setCountryCode( tmpstr );
|
||
|
// haveAddr = true;
|
||
|
// }
|
||
|
if ( haveAddr ) {
|
||
|
addressee.insertAddress( addr );
|
||
|
}
|
||
|
return haveAddr;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
14 years ago
|
For the complete list of Exchange <=> KABC field mappings see the file
|
||
15 years ago
|
Person.mapping */
|
||
14 years ago
|
bool ExchangeConverterContact::readAddressee( const TQDomElement &node, Addressee &addressee )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString tmpstr;
|
||
15 years ago
|
long tmplng;
|
||
14 years ago
|
|
||
15 years ago
|
// The UID is absolutely required!
|
||
|
if ( WebdavHandler::extractString( node, "uid", tmpstr ) ) {
|
||
|
addressee.setUid( tmpstr );
|
||
|
} else {
|
||
|
kdDebug()<<"Addressee does not have a UID"<<endl;
|
||
|
return false;
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, "getetag", tmpstr ) )
|
||
13 years ago
|
addressee.insertCustom( "TDEPIM-Exchange-Resource", "fingerprint", tmpstr );
|
||
15 years ago
|
if ( WebdavHandler::extractString( node, "href", tmpstr ) )
|
||
13 years ago
|
addressee.insertCustom( "TDEPIM-Exchange-Resource", "href", tmpstr );
|
||
14 years ago
|
|
||
15 years ago
|
/* KDE4: addressee does not have any creation or modification date :-(( */
|
||
|
/* KDE4: read-only not supported by libkabc */
|
||
|
|
||
|
// Name: first, family, pre/postfixes, common name
|
||
|
if ( WebdavHandler::extractString( node, "fileas", tmpstr ) ||
|
||
|
WebdavHandler::extractString( node, "cn", tmpstr ) )
|
||
|
addressee.setFormattedName( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "givenName", tmpstr ) )
|
||
15 years ago
|
addressee.setGivenName( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "middlename", tmpstr ) )
|
||
15 years ago
|
addressee.setAdditionalName( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "sn", tmpstr ) )
|
||
15 years ago
|
addressee.setFamilyName( tmpstr );
|
||
|
//urn:schemas:contacts:initials not used -
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "namesuffix", tmpstr ) )
|
||
15 years ago
|
addressee.setSuffix( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "personaltitle", tmpstr ) )
|
||
15 years ago
|
addressee.setPrefix( tmpstr );
|
||
|
|
||
|
// Role
|
||
|
if ( WebdavHandler::extractString( node, "title", tmpstr ) )
|
||
|
addressee.setRole( tmpstr );
|
||
|
|
||
|
// Company-Related settings
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "o", tmpstr ) )
|
||
15 years ago
|
addressee.setOrganization( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "department", tmpstr ) )
|
||
|
{
|
||
|
#if KDE_IS_VERSION(3,5,8)
|
||
|
addressee.setDepartment( tmpstr );
|
||
|
#else
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-Department", tmpstr );
|
||
14 years ago
|
#endif
|
||
|
}
|
||
|
if ( WebdavHandler::extractString( node, "roomnumber", tmpstr ) )
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-Office", tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "profession", tmpstr ) )
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-Profession", tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "manager", tmpstr ) )
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", tmpstr );
|
||
|
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "secretarycn", tmpstr ) )
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", tmpstr );
|
||
|
|
||
|
|
||
|
// Web-Related settings
|
||
|
if ( WebdavHandler::extractString( node, "email1", tmpstr ) )
|
||
|
addressee.insertEmail( tmpstr, true );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "email2", tmpstr ) )
|
||
15 years ago
|
addressee.insertEmail( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "email3", tmpstr ) )
|
||
15 years ago
|
addressee.insertEmail( tmpstr );
|
||
14 years ago
|
|
||
15 years ago
|
// No kabc field for personalHomePage
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "businesshomepage", tmpstr ) )
|
||
15 years ago
|
addressee.setUrl( tmpstr );
|
||
|
|
||
|
if ( WebdavHandler::extractString( node, "fburl", tmpstr ) ) {
|
||
|
KCal::FreeBusyUrlStore::self()->writeUrl( addressee.preferredEmail(), tmpstr );
|
||
|
KCal::FreeBusyUrlStore::self()->sync();
|
||
|
}
|
||
|
|
||
|
|
||
|
// General stuff:
|
||
15 years ago
|
TQStringList tmplst;
|
||
14 years ago
|
if ( WebdavHandler::extractStringList( node, "Keywords", tmplst ) )
|
||
15 years ago
|
addressee.setCategories( tmplst );
|
||
|
// Exchange sentitivity values:
|
||
|
// 0 None, 1 Personal, 2 Private, 3 Company Confidential
|
||
|
if ( WebdavHandler::extractLong( node, "sensitivity", tmplng ) ) {
|
||
|
switch( tmplng ) {
|
||
|
case 0: addressee.setSecrecy( KABC::Secrecy::Public ); break;
|
||
14 years ago
|
case 1:
|
||
15 years ago
|
case 2: addressee.setSecrecy( KABC::Secrecy::Private ); break;
|
||
|
case 3: addressee.setSecrecy( KABC::Secrecy::Confidential ); break;
|
||
|
default: kdWarning() << "Unknown sensitivity: " << tmplng << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#define insertPhone( name, type ) \
|
||
|
if ( WebdavHandler::extractString( node, name, tmpstr ) ) \
|
||
|
addressee.insertPhoneNumber( KABC::PhoneNumber( tmpstr, type ) );
|
||
|
// Phone numbers
|
||
|
insertPhone( "telephoneNumber", PhoneNumber::Work );
|
||
|
//insertPhone( "telephonenumber2", PhoneNumber::Work );
|
||
|
insertPhone( "officetelephonenumber", PhoneNumber::Work );
|
||
|
//insertPhone( "office2telephonenumber", PhoneNumber::Work );
|
||
|
//insertPhone( "secretaryphone", PhoneNumber::Work );
|
||
|
//insertPhone( "organizationmainphone", PhoneNumber::Work );
|
||
|
insertPhone( "otherTelephone", 0 );
|
||
|
insertPhone( "homePhone", PhoneNumber::Home );
|
||
|
//insertPhone( "homephone2", PhoneNumber::Home );
|
||
|
insertPhone( "mobile", PhoneNumber::Cell );
|
||
|
//insertPhone( "othermobile", PhoneNumber::Cell );
|
||
|
insertPhone( "facsimiletelephonenumber",PhoneNumber::Fax );
|
||
|
insertPhone( "homefax", PhoneNumber::Fax | PhoneNumber::Home );
|
||
|
insertPhone( "otherfax", PhoneNumber::Fax | PhoneNumber::Work );
|
||
|
insertPhone( "pager", PhoneNumber::Pager | PhoneNumber::Work );
|
||
|
insertPhone( "otherpager", PhoneNumber::Pager );
|
||
|
insertPhone( "internationalisdnnumber", PhoneNumber::Isdn );
|
||
|
insertPhone( "callbackphone", PhoneNumber::Msg );
|
||
|
insertPhone( "telexnumber", PhoneNumber::Bbs );
|
||
|
insertPhone( "ttytddphone", PhoneNumber::Pcs );
|
||
14 years ago
|
#undef insertPhone
|
||
15 years ago
|
|
||
|
// Addresses: Work, Home, Mailing and Other:
|
||
|
extractAddress( node, addressee, Address::Work | Address::Pref,
|
||
|
"street", "postofficebox", "l", "postalcode", "st", "co", "c" );
|
||
|
extractAddress( node, addressee, Address::Home,
|
||
14 years ago
|
"homeStreet", "homepostofficebox", "homeCity", "homePostalCode",
|
||
15 years ago
|
"homeState", "homeCountry", "homeCountrycode" );
|
||
|
// Exchange doesn't support writing/changing the mailing address fields,
|
||
|
// so don't download it. It's equal to either the home or work address anyway
|
||
|
/* extractAddress( node, addressee, Address::Postal,
|
||
14 years ago
|
"mailingstreet", "mailingpostofficebox", "mailingcity", "mailingpostalcode",
|
||
15 years ago
|
"mailingstate", "mailingcountry", "mailingcountrycode" );*/
|
||
|
extractAddress( node, addressee, 0,
|
||
14 years ago
|
"otherstreet", "otherpostofficebox", "othercity", "otherpostalcode",
|
||
15 years ago
|
"otherstate", "othercountry", "othercountrycode" );
|
||
|
|
||
|
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "nickname", tmpstr ) )
|
||
15 years ago
|
addressee.setNickName( tmpstr );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "spousecn", tmpstr ) )
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", tmpstr );
|
||
|
|
||
15 years ago
|
TQDateTime tmpdt;
|
||
14 years ago
|
if ( WebdavHandler::extractDateTime( node, "bday", tmpdt ) )
|
||
15 years ago
|
addressee.setBirthday( tmpdt.date() );
|
||
14 years ago
|
if ( WebdavHandler::extractString( node, "weddinganniversary", tmpstr ) )
|
||
15 years ago
|
addressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", tmpstr );
|
||
|
|
||
|
// TODO? timeZone()
|
||
|
|
||
|
float lt,lng;
|
||
14 years ago
|
if ( WebdavHandler::extractFloat( node, "geolatitude", lt ) &&
|
||
15 years ago
|
WebdavHandler::extractFloat( node, "geolongitude", lng ) )
|
||
|
addressee.setGeo( Geo( lt, lng ) );
|
||
|
// TODO: mapurl
|
||
|
// TODO: location
|
||
|
|
||
|
if ( WebdavHandler::extractString( node, "textdescription", tmpstr ) )
|
||
|
addressee.setNote( tmpstr );
|
||
|
|
||
14 years ago
|
// if ( WebdavHandler::extractString( node, "usercertificate", tmpstr ) )
|
||
15 years ago
|
// addressee.setKeys()
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
Addressee::List ExchangeConverterContact::parseWebDAV( const TQDomDocument& davdata )
|
||
15 years ago
|
{
|
||
|
// TODO: Handle multiple addressees per reply!
|
||
|
Addressee::List list;
|
||
|
|
||
15 years ago
|
TQDomElement prop = davdata.documentElement().namedItem( "response" )
|
||
15 years ago
|
.namedItem( "propstat" ).namedItem( "prop" ).toElement();
|
||
|
if ( prop.isNull() ) {
|
||
|
kdDebug()<<"ExchangeConverterContact::parseWebDAV, no response->propstat->prop element!"<<endl;
|
||
|
return list;
|
||
|
}
|
||
14 years ago
|
|
||
15 years ago
|
TQString contentclass;
|
||
15 years ago
|
bool success = WebdavHandler::extractString( prop, "contentclass", contentclass );
|
||
|
if ( !success ) {
|
||
|
kdDebug()<<"ExchangeConverterContact::parseWebDAV, No contentclass entry"<<endl;
|
||
|
return list;
|
||
|
}
|
||
14 years ago
|
|
||
15 years ago
|
success = false;
|
||
|
Addressee addressee;
|
||
|
if ( contentclass == "urn:content-classes:person" ) {
|
||
|
success = readAddressee( prop, addressee );
|
||
14 years ago
|
}
|
||
|
|
||
15 years ago
|
if ( success ) {
|
||
|
list.append( addressee );
|
||
|
} else {
|
||
14 years ago
|
|
||
15 years ago
|
}
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
#define domDavProperty( name, value ) \
|
||
|
WebdavHandler::addElement( doc, prop, "d:" name, value );
|
||
|
#define domProperty( NS, name, value ) \
|
||
|
WebdavHandler::addElementNS( doc, prop, NS, name, value );
|
||
|
#define domContactProperty( name, value ) \
|
||
|
WebdavHandler::addElement( doc, prop, "c:" name, value );
|
||
|
#define domCalendarProperty( name, value ) \
|
||
|
WebdavHandler::addElement( doc, prop, "cal:" name, value );
|
||
|
#define domPhoneProperty( name, type ) \
|
||
|
domContactProperty( name, addr.phoneNumber( type ).number() );
|
||
|
|
||
|
|
||
15 years ago
|
TQDomDocument ExchangeConverterContact::createWebDAV( Addressee addr )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomDocument doc;
|
||
|
TQDomElement root = WebdavHandler::addDavElement( doc, doc, "d:propertyupdate" );
|
||
|
TQDomElement set = WebdavHandler::addElement( doc, root, "d:set" );
|
||
|
TQDomElement prop = WebdavHandler::addElement( doc, set, "d:prop" );
|
||
14 years ago
|
|
||
15 years ago
|
TQDomAttr att_c = doc.createAttribute( "xmlns:c" );
|
||
15 years ago
|
att_c.setValue( "urn:schemas:contacts:" );
|
||
|
doc.documentElement().setAttributeNode( att_c );
|
||
14 years ago
|
|
||
15 years ago
|
TQDomAttr att_b = doc.createAttribute( "xmlns:b" );
|
||
15 years ago
|
att_b.setValue( "urn:schemas-microsoft-com:datatypes" );
|
||
|
root.setAttributeNode( att_b );
|
||
|
|
||
|
domDavProperty( "contentclass", "urn:content-classes:person" );
|
||
|
domProperty( "http://schemas.microsoft.com/exchange/",
|
||
|
"outlookmessageclass", "IPM.Contact" );
|
||
|
// domContactProperty( "uid", addr.uid() );
|
||
14 years ago
|
|
||
15 years ago
|
domContactProperty( "fileas", addr.formattedName() );
|
||
|
domContactProperty( "givenName", addr.givenName() );
|
||
|
domContactProperty( "middlename", addr.additionalName() );
|
||
|
domContactProperty( "sn", addr.familyName() );
|
||
|
domContactProperty( "namesuffix", addr.suffix() );
|
||
|
domContactProperty( "personaltitle", addr.prefix() );
|
||
14 years ago
|
|
||
15 years ago
|
domContactProperty( "title", addr.role() );
|
||
|
domContactProperty( "o", addr.organization() );
|
||
14 years ago
|
#if KDE_IS_VERSION(3,5,8)
|
||
|
domContactProperty( "department", addr.department() );
|
||
|
#else
|
||
15 years ago
|
domContactProperty( "department", addr.custom( "KADDRESSBOOK", "X-Department" ) );
|
||
14 years ago
|
#endif
|
||
15 years ago
|
domContactProperty( "roomnumber", addr.custom( "KADDRESSBOOK", "X-Office" ) );
|
||
|
domContactProperty( "profession", addr.custom( "KADDRESSBOOK", "X-Profession" ) );
|
||
|
domContactProperty( "manager", addr.custom( "KADDRESSBOOK", "X-ManagersName" ) );
|
||
|
domContactProperty( "secretarycn", addr.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
|
||
14 years ago
|
|
||
15 years ago
|
TQStringList emails = addr.emails();
|
||
|
TQString prefemail = addr.preferredEmail();
|
||
13 years ago
|
if ( emails.contains( prefemail ) )
|
||
15 years ago
|
emails.remove( prefemail );
|
||
|
emails.prepend( prefemail );
|
||
|
if ( emails.count() > 0 ) {
|
||
|
domContactProperty( "email1", emails[0] );
|
||
|
}
|
||
|
if ( emails.count() > 1 ) {
|
||
|
domContactProperty( "email2", emails[1] );
|
||
|
}
|
||
|
if ( emails.count() > 2 ) {
|
||
|
domContactProperty( "email3", emails[2] );
|
||
|
}
|
||
14 years ago
|
|
||
15 years ago
|
// No value for "personalHomePage"
|
||
|
domContactProperty( "businesshomepage", addr.url().url() );
|
||
14 years ago
|
|
||
15 years ago
|
TQString fburl = KCal::FreeBusyUrlStore::self()->readUrl( addr.preferredEmail() );
|
||
15 years ago
|
if ( !fburl.isEmpty() ) {
|
||
|
domContactProperty( "fburl", fburl );
|
||
|
}
|
||
|
|
||
|
/* FIXME: This doesn't work!
|
||
15 years ago
|
TQStringList cats = addr.categories();
|
||
15 years ago
|
if ( cats.isEmpty() ) {
|
||
14 years ago
|
TQDomElement catsnode = WebdavHandler::addElementNS( doc, prop,
|
||
15 years ago
|
"urn:schemas-microsoft-com:office:office", "Keywords" );
|
||
15 years ago
|
for ( TQStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
|
||
15 years ago
|
WebdavHandler::addElementNS( doc, catsnode, "xml:", "v", *it );
|
||
|
}
|
||
|
} else {
|
||
14 years ago
|
// TQDomElement catsnode = addProperty( doc, prop,
|
||
15 years ago
|
// "urn:schemas-microsoft-com:office:office", "Keywords", "" );
|
||
|
}*/
|
||
14 years ago
|
|
||
15 years ago
|
// Exchange sentitivity values:
|
||
|
// 0 None, 1 Personal, 2 Private, 3 Company Confidential
|
||
15 years ago
|
TQString value;
|
||
15 years ago
|
switch ( addr.secrecy().type() ) {
|
||
|
case KABC::Secrecy::Private: value = "2"; break;
|
||
|
case KABC::Secrecy::Confidential: value = "3"; break;
|
||
|
default: value = "0";
|
||
|
}
|
||
|
domDavProperty( "sensitivity", value );
|
||
|
|
||
|
// Phone numbers
|
||
|
domPhoneProperty( "telephoneNumber", PhoneNumber::Work );
|
||
|
// domPhoneProperty( "telephonenumber2", PhoneNumber::Work );
|
||
|
domPhoneProperty( "officetelephonenumber", PhoneNumber::Work );
|
||
|
// domPhoneProperty( "office2telephonenumber", PhoneNumber::Work );
|
||
|
// domPhoneProperty( "secretaryphone", PhoneNumber::Work );
|
||
|
// domPhoneProperty( "organizationmainphone", PhoneNumber::Work );
|
||
|
domPhoneProperty( "otherTelephone", 0 );
|
||
|
domPhoneProperty( "homePhone", PhoneNumber::Home );
|
||
|
// domPhoneProperty( "homephone2", PhoneNumber::Home );
|
||
|
domPhoneProperty( "mobile", PhoneNumber::Cell );
|
||
|
domPhoneProperty( "othermobile", PhoneNumber::Cell | PhoneNumber::Home );
|
||
|
domPhoneProperty( "facsimiletelephonenumber", PhoneNumber::Fax );
|
||
|
domPhoneProperty( "homefax", PhoneNumber::Fax | PhoneNumber::Home );
|
||
|
domPhoneProperty( "otherfax", PhoneNumber::Fax | PhoneNumber::Work );
|
||
|
domPhoneProperty( "pager", PhoneNumber::Pager | PhoneNumber::Work );
|
||
|
domPhoneProperty( "otherpager", PhoneNumber::Pager );
|
||
|
domPhoneProperty( "internationalisdnnumber", PhoneNumber::Isdn );
|
||
|
domPhoneProperty( "callbackphone", PhoneNumber::Msg );
|
||
|
domPhoneProperty( "telexnumber", PhoneNumber::Bbs );
|
||
|
domPhoneProperty( "ttytddphone", PhoneNumber::Pcs );
|
||
|
|
||
14 years ago
|
|
||
15 years ago
|
// work address:
|
||
|
Address workaddr = addr.address( Address::Work | Address::Pref );
|
||
|
if ( !workaddr.isEmpty() ) {
|
||
|
domContactProperty( "street", workaddr.street() );
|
||
|
domContactProperty( "postofficebox", workaddr.postOfficeBox() );
|
||
|
domContactProperty( "l", workaddr.locality() );
|
||
|
domContactProperty( "postalcode", workaddr.postalCode() );
|
||
|
domContactProperty( "st", workaddr.region() );
|
||
|
domContactProperty( "co", workaddr.country() );
|
||
|
// domContactProperty( "c", workaddr.countryCode() );
|
||
|
}
|
||
|
|
||
|
// home address:
|
||
|
Address homeaddr = addr.address( Address::Home );
|
||
|
if ( !homeaddr.isEmpty() ) {
|
||
|
domContactProperty( "homeStreet", homeaddr.street() );
|
||
|
domContactProperty( "homepostofficebox", homeaddr.postOfficeBox() );
|
||
|
domContactProperty( "homeCity", homeaddr.locality() );
|
||
|
domContactProperty( "homePostalCode", homeaddr.postalCode() );
|
||
|
domContactProperty( "homeState", homeaddr.region() );
|
||
|
domContactProperty( "homeCountry", homeaddr.country() );
|
||
|
// domContactProperty( "homeCountrycode", homeaddr.countryCode() );
|
||
|
}
|
||
14 years ago
|
|
||
15 years ago
|
// mailing address:
|
||
|
// Exchange doesn't support writing/changing the mailing address fields
|
||
|
/* Address mailingaddr = addr.address( Address::Postal );
|
||
|
if ( !mailingaddr.isEmpty() ) {
|
||
|
domContactProperty( "mailingstreet", mailingaddr.street() );
|
||
|
domContactProperty( "mailingpostofficebox", mailingaddr.postOfficeBox() );
|
||
|
domContactProperty( "mailingcity", mailingaddr.locality() );
|
||
|
domContactProperty( "mailingpostalcode", mailingaddr.postalCode() );
|
||
|
domContactProperty( "mailingstate", mailingaddr.region() );
|
||
|
domContactProperty( "mailingcountry", mailingaddr.country() );
|
||
|
// domContactProperty( "mailingcountrycode", mailingaddr.countryCode() );
|
||
|
}*/
|
||
|
|
||
|
// other address:
|
||
|
Address otheraddr = addr.address( 0 );
|
||
|
if ( !otheraddr.isEmpty() ) {
|
||
|
domContactProperty( "otherstreet", otheraddr.street() );
|
||
|
domContactProperty( "otherpostofficebox", otheraddr.postOfficeBox() );
|
||
|
domContactProperty( "othercity", otheraddr.locality() );
|
||
|
domContactProperty( "otherpostalcode", otheraddr.postalCode() );
|
||
|
domContactProperty( "otherstate", otheraddr.region() );
|
||
|
domContactProperty( "othercountry", otheraddr.country() );
|
||
|
// domContactProperty( "othercountrycode", otheraddr.countryCode() );
|
||
|
}
|
||
14 years ago
|
|
||
|
|
||
15 years ago
|
domContactProperty( "nickname", addr.nickName() );
|
||
|
domContactProperty( "spousecn", addr.custom( "KADDRESSBOOK", "X-SpousesName" ) );
|
||
|
|
||
|
// TODO: Birthday and Anniversary:
|
||
|
// FIXME: Exchange uses the date in the form 8/13, i.e. possibly without a
|
||
|
// year! How shall I deal with this?
|
||
15 years ago
|
/* TQDate dt = addr.birthday().date();
|
||
14 years ago
|
TQString str = (dt.isValid())?(dt.toString( TQt::ISODate )):(TQString());
|
||
15 years ago
|
if ( !str.isEmpty() ) {
|
||
15 years ago
|
TQDomElement el = domContactProperty( "bday", str );
|
||
15 years ago
|
el.setAttribute( "b:dt", "date" );
|
||
|
}
|
||
14 years ago
|
dt = TQDate::fromString( addr.custom( "KADDRESSBOOK", "X-Anniversary" ), TQt::ISODate );
|
||
|
str = (dt.isValid())?(dt.toString( TQt::ISODate )):(TQString());
|
||
15 years ago
|
if ( !str.isEmpty() ) {
|
||
15 years ago
|
TQDomElement el = domContactProperty( "weddinganniversary", str );
|
||
15 years ago
|
el.setAttribute( "b:dt", "date" );
|
||
|
}*/
|
||
|
|
||
|
// ? TODO: timeZone()
|
||
|
/*
|
||
|
KABC::Geo geo = addr.geo();
|
||
|
if ( geo.isValid() ) {
|
||
|
// TODO: Do we need to set any other attribute to make it a float?
|
||
15 years ago
|
TQDomAttr att_cal = doc.createAttribute( "xmlns:cal" );
|
||
15 years ago
|
att_cal.setValue( "urn:schemas:calendar:" );
|
||
|
doc.documentElement().setAttributeNode( att_cal );
|
||
15 years ago
|
TQDomElement el = domCalendarProperty( "geolatitude", TQString::number( geo.latitude() ) );
|
||
15 years ago
|
el.setAttribute( "b:dt", "float" );
|
||
15 years ago
|
el = domCalendarProperty( "geolongitude", TQString::number( geo.longitude() ) );
|
||
15 years ago
|
el.setAttribute( "b:dt", "float" );
|
||
|
}
|
||
|
*/
|
||
|
domContactProperty( "textdescription", addr.note() );
|
||
|
|
||
|
// TODO:usercertificate
|
||
|
// TODO: custom fields
|
||
|
kdDebug()<<"DOM document: "<<doc.toString() << endl;
|
||
14 years ago
|
|
||
15 years ago
|
return doc;
|
||
|
}
|
||
|
#undef domDavProperty
|
||
|
#undef domProperty
|
||
|
#undef domContactProperty
|
||
|
#undef domPhoneProperty
|