From a3e01ba75c1f4886f3d2f2abeeb2715f39957974 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 27 Jan 2013 13:41:53 -0600 Subject: Finish renaming ldapkio --- kabc/plugins/CMakeLists.txt | 2 +- kabc/plugins/Makefile.am | 2 +- kabc/plugins/ldapkio/CMakeLists.txt | 73 -- kabc/plugins/ldapkio/Makefile.am | 28 - kabc/plugins/ldapkio/ldapkio.desktop | 10 - kabc/plugins/ldapkio/resourceldapkio.cpp | 1041 -------------------- kabc/plugins/ldapkio/resourceldapkio.h | 171 ---- kabc/plugins/ldapkio/resourceldapkioconfig.cpp | 388 -------- kabc/plugins/ldapkio/resourceldapkioconfig.h | 118 --- kabc/plugins/ldapkio/resourceldapkioplugin.cpp | 36 - kabc/plugins/ldaptdeio/CMakeLists.txt | 73 ++ kabc/plugins/ldaptdeio/Makefile.am | 28 + kabc/plugins/ldaptdeio/ldaptdeio.desktop | 10 + kabc/plugins/ldaptdeio/resourceldaptdeio.cpp | 1041 ++++++++++++++++++++ kabc/plugins/ldaptdeio/resourceldaptdeio.h | 171 ++++ kabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp | 388 ++++++++ kabc/plugins/ldaptdeio/resourceldaptdeioconfig.h | 118 +++ kabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp | 36 + 18 files changed, 1867 insertions(+), 1867 deletions(-) delete mode 100644 kabc/plugins/ldapkio/CMakeLists.txt delete mode 100644 kabc/plugins/ldapkio/Makefile.am delete mode 100644 kabc/plugins/ldapkio/ldapkio.desktop delete mode 100644 kabc/plugins/ldapkio/resourceldapkio.cpp delete mode 100644 kabc/plugins/ldapkio/resourceldapkio.h delete mode 100644 kabc/plugins/ldapkio/resourceldapkioconfig.cpp delete mode 100644 kabc/plugins/ldapkio/resourceldapkioconfig.h delete mode 100644 kabc/plugins/ldapkio/resourceldapkioplugin.cpp create mode 100644 kabc/plugins/ldaptdeio/CMakeLists.txt create mode 100644 kabc/plugins/ldaptdeio/Makefile.am create mode 100644 kabc/plugins/ldaptdeio/ldaptdeio.desktop create mode 100644 kabc/plugins/ldaptdeio/resourceldaptdeio.cpp create mode 100644 kabc/plugins/ldaptdeio/resourceldaptdeio.h create mode 100644 kabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp create mode 100644 kabc/plugins/ldaptdeio/resourceldaptdeioconfig.h create mode 100644 kabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp (limited to 'kabc/plugins') diff --git a/kabc/plugins/CMakeLists.txt b/kabc/plugins/CMakeLists.txt index 019afd842..597486816 100644 --- a/kabc/plugins/CMakeLists.txt +++ b/kabc/plugins/CMakeLists.txt @@ -12,4 +12,4 @@ add_subdirectory( file ) add_subdirectory( dir ) add_subdirectory( net ) -add_subdirectory( ldapkio ) +add_subdirectory( ldaptdeio ) diff --git a/kabc/plugins/Makefile.am b/kabc/plugins/Makefile.am index 5a5dcb137..bdedbec0f 100644 --- a/kabc/plugins/Makefile.am +++ b/kabc/plugins/Makefile.am @@ -1 +1 @@ -SUBDIRS = file dir net ldapkio +SUBDIRS = file dir net ldaptdeio diff --git a/kabc/plugins/ldapkio/CMakeLists.txt b/kabc/plugins/ldapkio/CMakeLists.txt deleted file mode 100644 index 0869c54e1..000000000 --- a/kabc/plugins/ldapkio/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -################################################# -# -# (C) 2010 Serghei Amelian -# serghei (DOT) amelian (AT) gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_BINARY_DIR}/kabc - ${CMAKE_SOURCE_DIR}/kabc - - ${TQT_INCLUDE_DIRS} - ${CMAKE_BINARY_DIR}/tdecore - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/dcop - ${CMAKE_SOURCE_DIR}/tdecore - ${CMAKE_SOURCE_DIR}/tdeui - ${CMAKE_SOURCE_DIR}/tdeio - ${CMAKE_SOURCE_DIR}/tdeio/tdeio - ${CMAKE_SOURCE_DIR}/tdeio/tdefiles -) - -link_directories( - ${TQT_LIBRARY_DIRS} -) - - -##### headers ################################### - -install( FILES - resourceldapkio.h - DESTINATION ${INCLUDE_INSTALL_DIR}/kabc ) - - -##### other data ################################ - -install( FILES ldapkio.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc ) - - -##### kabc_ldapkio ############################## - -set( target kabc_ldapkio ) - -set( ${target}_SRCS - resourceldapkio.cpp resourceldapkioconfig.cpp -) - -tde_add_library( ${target} SHARED AUTOMOC - SOURCES ${${target}_SRCS} - VERSION 1.0.0 - LINK kabc-shared - DESTINATION ${LIB_INSTALL_DIR} -) - - -##### kabc_ldapkio ############################## - -set( target kabc_ldapkio ) - -set( ${target}_SRCS - resourceldapkioplugin.cpp -) - -tde_add_kpart( ${target} - SOURCES ${${target}_SRCS} - LINK kabc_ldaptdeio-shared - DESTINATION ${PLUGIN_INSTALL_DIR} -) diff --git a/kabc/plugins/ldapkio/Makefile.am b/kabc/plugins/ldapkio/Makefile.am deleted file mode 100644 index a9803f650..000000000 --- a/kabc/plugins/ldapkio/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -INCLUDES = -I$(top_srcdir)/kabc -I$(top_builddir)/kabc $(all_includes) - -# these are the headers for your project -noinst_HEADERS = resourceldapkioconfig.h - -lib_LTLIBRARIES = libkabc_ldapkio.la -libkabc_ldapkio_la_SOURCES = resourceldapkio.cpp resourceldapkioconfig.cpp -libkabc_ldapkio_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -version-info 1:0:0 -no-undefined -libkabc_ldapkio_la_LIBADD = $(LIB_KABC) $(LIB_KIO) $(LIB_QT) $(top_builddir)/tderesources/libtderesources.la $(LIB_TDEUI) $(LIB_TDECORE) -libkabc_ldapkio_la_COMPILE_FIRST = $(top_builddir)/kabc/addressee.h - -kde_module_LTLIBRARIES = kabc_ldapkio.la -kabc_ldapkio_la_SOURCES = resourceldapkioplugin.cpp -kabc_ldapkio_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -kabc_ldapkio_la_LIBADD = libkabc_ldapkio.la $(LIB_QT) $(LIB_TDECORE) - -METASOURCES = AUTO - -messages: rc.cpp - $(XGETTEXT) *.cpp -o $(podir)/kabc_ldapkio.pot - -kabcincludedir = $(includedir)/kabc -kabcinclude_HEADERS = resourceldapkio.h - -servicedir = $(kde_servicesdir)/tderesources/kabc -service_DATA = ldapkio.desktop - -resourceldapkioplugin.lo: ../../addressee.h diff --git a/kabc/plugins/ldapkio/ldapkio.desktop b/kabc/plugins/ldapkio/ldapkio.desktop deleted file mode 100644 index e70bf9c9d..000000000 --- a/kabc/plugins/ldapkio/ldapkio.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Name=LDAP -Name[bn]=এল-ডি-এ-পি (LDAP) -Name[hi]=एलडीएपी (LDAP) -Name[te]=ఎల్డిఏపి -X-TDE-Library=kabc_ldapkio -Type=Service -ServiceTypes=KResources/Plugin -X-TDE-ResourceFamily=contact -X-TDE-ResourceType=ldapkio diff --git a/kabc/plugins/ldapkio/resourceldapkio.cpp b/kabc/plugins/ldapkio/resourceldapkio.cpp deleted file mode 100644 index 034fb0ef8..000000000 --- a/kabc/plugins/ldapkio/resourceldapkio.cpp +++ /dev/null @@ -1,1041 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2003 Tobias Koenig - Copyright (c) 2004 Szombathelyi György - - 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 -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "resourceldapkio.h" -#include "resourceldapkioconfig.h" - -using namespace KABC; - -// Hack from Netaccess -void tqt_enter_modal( TQWidget *widget ); -void tqt_leave_modal( TQWidget *widget ); - -class ResourceLDAPTDEIO::ResourceLDAPTDEIOPrivate -{ - public: - LDIF mLdif; - bool mTLS,mSSL,mSubTree; - TQString mResultDn; - Addressee mAddr; - Address mAd; - Resource::Iterator mSaveIt; - bool mSASL; - TQString mMech; - TQString mRealm, mBindDN; - LDAPUrl mLDAPUrl; - int mVer, mSizeLimit, mTimeLimit, mRDNPrefix; - int mError; - int mCachePolicy; - bool mReadOnly; - bool mAutoCache; - TQString mCacheDst; - KTempFile *mTmp; -}; - -ResourceLDAPTDEIO::ResourceLDAPTDEIO( const TDEConfig *config ) - : Resource( config ) -{ - d = new ResourceLDAPTDEIOPrivate; - if ( config ) { - TQMap attrList; - TQStringList attributes = config->readListEntry( "LdapAttributes" ); - for ( uint pos = 0; pos < attributes.count(); pos += 2 ) - mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); - - mUser = config->readEntry( "LdapUser" ); - mPassword = KStringHandler::obscure( config->readEntry( "LdapPassword" ) ); - mDn = config->readEntry( "LdapDn" ); - mHost = config->readEntry( "LdapHost" ); - mPort = config->readNumEntry( "LdapPort", 389 ); - mFilter = config->readEntry( "LdapFilter" ); - mAnonymous = config->readBoolEntry( "LdapAnonymous" ); - d->mTLS = config->readBoolEntry( "LdapTLS" ); - d->mSSL = config->readBoolEntry( "LdapSSL" ); - d->mSubTree = config->readBoolEntry( "LdapSubTree" ); - d->mSASL = config->readBoolEntry( "LdapSASL" ); - d->mMech = config->readEntry( "LdapMech" ); - d->mRealm = config->readEntry( "LdapRealm" ); - d->mBindDN = config->readEntry( "LdapBindDN" ); - d->mVer = config->readNumEntry( "LdapVer", 3 ); - d->mTimeLimit = config->readNumEntry( "LdapTimeLimit", 0 ); - d->mSizeLimit = config->readNumEntry( "LdapSizeLimit", 0 ); - d->mRDNPrefix = config->readNumEntry( "LdapRDNPrefix", 0 ); - d->mCachePolicy = config->readNumEntry( "LdapCachePolicy", 0 ); - d->mAutoCache = config->readBoolEntry( "LdapAutoCache", true ); - } else { - mPort = 389; - mAnonymous = true; - mUser = mPassword = mHost = mFilter = mDn = ""; - d->mMech = d->mRealm = d->mBindDN = ""; - d->mTLS = d->mSSL = d->mSubTree = d->mSASL = false; - d->mVer = 3; d->mRDNPrefix = 0; - d->mTimeLimit = d->mSizeLimit = 0; - d->mCachePolicy = Cache_No; - d->mAutoCache = true; - } - d->mCacheDst = TDEGlobal::dirs()->saveLocation("cache", "ldapkio") + "/" + - type() + "_" + identifier(); - init(); -} - -ResourceLDAPTDEIO::~ResourceLDAPTDEIO() -{ - delete d; -} - -void ResourceLDAPTDEIO::enter_loop() -{ - TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal)); - dummy.setFocusPolicy( TQ_NoFocus ); - tqt_enter_modal(&dummy); - tqApp->enter_loop(); - tqt_leave_modal(&dummy); -} - -void ResourceLDAPTDEIO::entries( TDEIO::Job*, const TDEIO::UDSEntryList & list ) -{ - TDEIO::UDSEntryListConstIterator it = list.begin(); - TDEIO::UDSEntryListConstIterator end = list.end(); - for (; it != end; ++it) { - TDEIO::UDSEntry::ConstIterator it2 = (*it).begin(); - for( ; it2 != (*it).end(); it2++ ) { - if ( (*it2).m_uds == TDEIO::UDS_URL ) { - KURL tmpurl( (*it2).m_str ); - d->mResultDn = tmpurl.path(); - kdDebug(7125) << "findUid(): " << d->mResultDn << endl; - if ( d->mResultDn.startsWith("/") ) d->mResultDn.remove(0,1); - return; - } - } - } -} - -void ResourceLDAPTDEIO::listResult( TDEIO::Job *job) -{ - d->mError = job->error(); - if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) - mErrorMsg = job->errorString(); - else - mErrorMsg = ""; - tqApp->exit_loop(); -} - -TQString ResourceLDAPTDEIO::findUid( const TQString &uid ) -{ - LDAPUrl url( d->mLDAPUrl ); - TDEIO::UDSEntry entry; - - mErrorMsg = d->mResultDn = ""; - - url.setAttributes("dn"); - url.setFilter( "(" + mAttributes[ "uid" ] + "=" + uid + ")" + mFilter ); - url.setExtension( "x-dir", "one" ); - - kdDebug(7125) << "ResourceLDAPTDEIO::findUid() uid: " << uid << " url " << - url.prettyURL() << endl; - - TDEIO::ListJob * listJob = TDEIO::listDir( url, false /* no GUI */ ); - connect( listJob, - TQT_SIGNAL( entries( TDEIO::Job *, const TDEIO::UDSEntryList& ) ), - TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); - connect( listJob, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( listResult( TDEIO::Job* ) ) ); - - enter_loop(); - return d->mResultDn; -} - -TQCString ResourceLDAPTDEIO::addEntry( const TQString &attr, const TQString &value, bool mod ) -{ - TQCString tmp; - if ( !attr.isEmpty() ) { - if ( mod ) tmp += LDIF::assembleLine( "replace", attr ) + "\n"; - tmp += LDIF::assembleLine( attr, value ) + "\n"; - if ( mod ) tmp += "-\n"; - } - return ( tmp ); -} - -bool ResourceLDAPTDEIO::AddresseeToLDIF( TQByteArray &ldif, const Addressee &addr, - const TQString &olddn ) -{ - TQCString tmp; - TQString dn; - TQByteArray data; - bool mod = false; - - if ( olddn.isEmpty() ) { - //insert new entry - switch ( d->mRDNPrefix ) { - case 1: - dn = mAttributes[ "uid" ] + "=" + addr.uid() + "," +mDn; - break; - case 0: - default: - dn = mAttributes[ "commonName" ] + "=" + addr.assembledName() + "," +mDn; - break; - } - } else { - //modify existing entry - mod = true; - if ( olddn.startsWith( mAttributes[ "uid" ] ) ) { - dn = mAttributes[ "uid" ] + "=" + addr.uid() + "," + olddn.section( ',', 1 ); - } else if ( olddn.startsWith( mAttributes[ "commonName" ] ) ) { - dn = mAttributes[ "commonName" ] + "=" + addr.assembledName() + "," + - olddn.section( ',', 1 ); - } else { - dn = olddn; - } - - if ( olddn.lower() != dn.lower() ) { - tmp = LDIF::assembleLine( "dn", olddn ) + "\n"; - tmp += "changetype: modrdn\n"; - tmp += LDIF::assembleLine( "newrdn", dn.section( ',', 0, 0 ) ) + "\n"; - tmp += "deleteoldrdn: 1\n\n"; - } - } - - - tmp += LDIF::assembleLine( "dn", dn ) + "\n"; - if ( mod ) tmp += "changetype: modify\n"; - if ( !mod ) { - tmp += "objectClass: top\n"; - TQStringList obclass = TQStringList::split( ',', mAttributes[ "objectClass" ] ); - for ( TQStringList::iterator it = obclass.begin(); it != obclass.end(); it++ ) { - tmp += LDIF::assembleLine( "objectClass", *it ) + "\n"; - } - } - - tmp += addEntry( mAttributes[ "commonName" ], addr.assembledName(), mod ); - tmp += addEntry( mAttributes[ "formattedName" ], addr.formattedName(), mod ); - tmp += addEntry( mAttributes[ "givenName" ], addr.givenName(), mod ); - tmp += addEntry( mAttributes[ "familyName" ], addr.familyName(), mod ); - tmp += addEntry( mAttributes[ "uid" ], addr.uid(), mod ); - - PhoneNumber number; - number = addr.phoneNumber( PhoneNumber::Home ); - tmp += addEntry( mAttributes[ "phoneNumber" ], number.number().utf8(), mod ); - number = addr.phoneNumber( PhoneNumber::Work ); - tmp += addEntry( mAttributes[ "telephoneNumber" ], number.number().utf8(), mod ); - number = addr.phoneNumber( PhoneNumber::Fax ); - tmp += addEntry( mAttributes[ "facsimileTelephoneNumber" ], number.number().utf8(), mod ); - number = addr.phoneNumber( PhoneNumber::Cell ); - tmp += addEntry( mAttributes[ "mobile" ], number.number().utf8(), mod ); - number = addr.phoneNumber( PhoneNumber::Pager ); - tmp += addEntry( mAttributes[ "pager" ], number.number().utf8(), mod ); - - tmp += addEntry( mAttributes[ "description" ], addr.note(), mod ); - tmp += addEntry( mAttributes[ "title" ], addr.title(), mod ); - tmp += addEntry( mAttributes[ "organization" ], addr.organization(), mod ); - - Address ad = addr.address( Address::Home ); - if ( !ad.isEmpty() ) { - tmp += addEntry( mAttributes[ "street" ], ad.street(), mod ); - tmp += addEntry( mAttributes[ "state" ], ad.region(), mod ); - tmp += addEntry( mAttributes[ "city" ], ad.locality(), mod ); - tmp += addEntry( mAttributes[ "postalcode" ], ad.postalCode(), mod ); - } - - TQStringList emails = addr.emails(); - TQStringList::ConstIterator mailIt = emails.begin(); - - if ( !mAttributes[ "mail" ].isEmpty() ) { - if ( mod ) tmp += - LDIF::assembleLine( "replace", mAttributes[ "mail" ] ) + "\n"; - if ( mailIt != emails.end() ) { - tmp += LDIF::assembleLine( mAttributes[ "mail" ], *mailIt ) + "\n"; - mailIt ++; - } - if ( mod && mAttributes[ "mail" ] != mAttributes[ "mailAlias" ] ) tmp += "-\n"; - } - - if ( !mAttributes[ "mailAlias" ].isEmpty() ) { - if ( mod && mAttributes[ "mail" ] != mAttributes[ "mailAlias" ] ) tmp += - LDIF::assembleLine( "replace", mAttributes[ "mailAlias" ] ) + "\n"; - for ( ; mailIt != emails.end(); ++mailIt ) { - tmp += LDIF::assembleLine( mAttributes[ "mailAlias" ], *mailIt ) + "\n" ; - } - if ( mod ) tmp += "-\n"; - } - - if ( !mAttributes[ "jpegPhoto" ].isEmpty() ) { - TQByteArray pic; - TQBuffer buffer( pic ); - buffer.open( IO_WriteOnly ); - addr.photo().data().save( &buffer, "JPEG" ); - - if ( mod ) tmp += - LDIF::assembleLine( "replace", mAttributes[ "jpegPhoto" ] ) + "\n"; - tmp += LDIF::assembleLine( mAttributes[ "jpegPhoto" ], pic, 76 ) + "\n"; - if ( mod ) tmp += "-\n"; - } - - tmp += "\n"; - kdDebug(7125) << "ldif: " << TQString(TQString::fromUtf8(tmp)) << endl; - ldif = tmp; - return true; -} - -void ResourceLDAPTDEIO::setReadOnly( bool value ) -{ - //save the original readonly flag, because offline using disables writing - d->mReadOnly = true; - Resource::setReadOnly( value ); -} - -void ResourceLDAPTDEIO::init() -{ - if ( mPort == 0 ) mPort = 389; - - /** - If you want to add new attributes, append them here, add a - translation string in the ctor of AttributesDialog and - handle them in the load() method below. - These are the default values - */ - if ( !mAttributes.contains("objectClass") ) - mAttributes.insert( "objectClass", "inetOrgPerson" ); - if ( !mAttributes.contains("commonName") ) - mAttributes.insert( "commonName", "cn" ); - if ( !mAttributes.contains("formattedName") ) - mAttributes.insert( "formattedName", "displayName" ); - if ( !mAttributes.contains("familyName") ) - mAttributes.insert( "familyName", "sn" ); - if ( !mAttributes.contains("givenName") ) - mAttributes.insert( "givenName", "givenName" ); - if ( !mAttributes.contains("mail") ) - mAttributes.insert( "mail", "mail" ); - if ( !mAttributes.contains("mailAlias") ) - mAttributes.insert( "mailAlias", "" ); - if ( !mAttributes.contains("phoneNumber") ) - mAttributes.insert( "phoneNumber", "homePhone" ); - if ( !mAttributes.contains("telephoneNumber") ) - mAttributes.insert( "telephoneNumber", "telephoneNumber" ); - if ( !mAttributes.contains("facsimileTelephoneNumber") ) - mAttributes.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" ); - if ( !mAttributes.contains("mobile") ) - mAttributes.insert( "mobile", "mobile" ); - if ( !mAttributes.contains("pager") ) - mAttributes.insert( "pager", "pager" ); - if ( !mAttributes.contains("description") ) - mAttributes.insert( "description", "description" ); - - if ( !mAttributes.contains("title") ) - mAttributes.insert( "title", "title" ); - if ( !mAttributes.contains("street") ) - mAttributes.insert( "street", "street" ); - if ( !mAttributes.contains("state") ) - mAttributes.insert( "state", "st" ); - if ( !mAttributes.contains("city") ) - mAttributes.insert( "city", "l" ); - if ( !mAttributes.contains("organization") ) - mAttributes.insert( "organization", "o" ); - if ( !mAttributes.contains("postalcode") ) - mAttributes.insert( "postalcode", "postalCode" ); - - if ( !mAttributes.contains("uid") ) - mAttributes.insert( "uid", "uid" ); - if ( !mAttributes.contains("jpegPhoto") ) - mAttributes.insert( "jpegPhoto", "jpegPhoto" ); - - d->mLDAPUrl = KURL(); - if ( !mAnonymous ) { - d->mLDAPUrl.setUser( mUser ); - d->mLDAPUrl.setPass( mPassword ); - } - d->mLDAPUrl.setProtocol( d->mSSL ? "ldaps" : "ldap"); - d->mLDAPUrl.setHost( mHost ); - d->mLDAPUrl.setPort( mPort ); - d->mLDAPUrl.setDn( mDn ); - - if (!mAttributes.empty()) { - TQMap::Iterator it; - TQStringList attr; - for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { - if ( !it.data().isEmpty() && it.key() != "objectClass" ) - attr.append( it.data() ); - } - d->mLDAPUrl.setAttributes( attr ); - } - - d->mLDAPUrl.setScope( d->mSubTree ? LDAPUrl::Sub : LDAPUrl::One ); - if ( !mFilter.isEmpty() && mFilter != "(objectClass=*)" ) - d->mLDAPUrl.setFilter( mFilter ); - d->mLDAPUrl.setExtension( "x-dir", "base" ); - if ( d->mTLS ) d->mLDAPUrl.setExtension( "x-tls", "" ); - d->mLDAPUrl.setExtension( "x-ver", TQString::number( d->mVer ) ); - if ( d->mSizeLimit ) - d->mLDAPUrl.setExtension( "x-sizelimit", TQString::number( d->mSizeLimit ) ); - if ( d->mTimeLimit ) - d->mLDAPUrl.setExtension( "x-timelimit", TQString::number( d->mTimeLimit ) ); - if ( d->mSASL ) { - d->mLDAPUrl.setExtension( "x-sasl", "" ); - if ( !d->mBindDN.isEmpty() ) d->mLDAPUrl.setExtension( "bindname", d->mBindDN ); - if ( !d->mMech.isEmpty() ) d->mLDAPUrl.setExtension( "x-mech", d->mMech ); - if ( !d->mRealm.isEmpty() ) d->mLDAPUrl.setExtension( "x-realm", d->mRealm ); - } - - d->mReadOnly = readOnly(); - - kdDebug(7125) << "resource_ldapkio url: " << d->mLDAPUrl.prettyURL() << endl; -} - -void ResourceLDAPTDEIO::writeConfig( TDEConfig *config ) -{ - Resource::writeConfig( config ); - - config->writeEntry( "LdapUser", mUser ); - config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); - config->writeEntry( "LdapDn", mDn ); - config->writeEntry( "LdapHost", mHost ); - config->writeEntry( "LdapPort", mPort ); - config->writeEntry( "LdapFilter", mFilter ); - config->writeEntry( "LdapAnonymous", mAnonymous ); - config->writeEntry( "LdapTLS", d->mTLS ); - config->writeEntry( "LdapSSL", d->mSSL ); - config->writeEntry( "LdapSubTree", d->mSubTree ); - config->writeEntry( "LdapSASL", d->mSASL ); - config->writeEntry( "LdapMech", d->mMech ); - config->writeEntry( "LdapVer", d->mVer ); - config->writeEntry( "LdapTimeLimit", d->mTimeLimit ); - config->writeEntry( "LdapSizeLimit", d->mSizeLimit ); - config->writeEntry( "LdapRDNPrefix", d->mRDNPrefix ); - config->writeEntry( "LdapRealm", d->mRealm ); - config->writeEntry( "LdapBindDN", d->mBindDN ); - config->writeEntry( "LdapCachePolicy", d->mCachePolicy ); - config->writeEntry( "LdapAutoCache", d->mAutoCache ); - - TQStringList attributes; - TQMap::Iterator it; - for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) - attributes << it.key() << it.data(); - - config->writeEntry( "LdapAttributes", attributes ); -} - -Ticket *ResourceLDAPTDEIO::requestSaveTicket() -{ - if ( !addressBook() ) { - kdDebug(7125) << "no addressbook" << endl; - return 0; - } - - return createTicket( this ); -} - -void ResourceLDAPTDEIO::releaseSaveTicket( Ticket *ticket ) -{ - delete ticket; -} - -bool ResourceLDAPTDEIO::doOpen() -{ - return true; -} - -void ResourceLDAPTDEIO::doClose() -{ -} - -void ResourceLDAPTDEIO::createCache() -{ - d->mTmp = NULL; - if ( d->mCachePolicy == Cache_NoConnection && d->mAutoCache ) { - d->mTmp = new KTempFile( d->mCacheDst, "tmp" ); - d->mTmp->setAutoDelete( true ); - } -} - -void ResourceLDAPTDEIO::activateCache() -{ - if ( d->mTmp && d->mError == 0 ) { - d->mTmp->close(); - rename( TQFile::encodeName( d->mTmp->name() ), TQFile::encodeName( d->mCacheDst ) ); - } - if ( d->mTmp ) { - delete d->mTmp; - d->mTmp = 0; - } -} - -TDEIO::Job *ResourceLDAPTDEIO::loadFromCache() -{ - TDEIO::Job *job = NULL; - if ( d->mCachePolicy == Cache_Always || - ( d->mCachePolicy == Cache_NoConnection && - d->mError == TDEIO::ERR_COULD_NOT_CONNECT ) ) { - - d->mAddr = Addressee(); - d->mAd = Address( Address::Home ); - //initialize ldif parser - d->mLdif.startParsing(); - - Resource::setReadOnly( true ); - - KURL url( d->mCacheDst ); - job = TDEIO::get( url, true, false ); - connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), - this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) ); - } - return job; -} - -bool ResourceLDAPTDEIO::load() -{ - kdDebug(7125) << "ResourceLDAPTDEIO::load()" << endl; - TDEIO::Job *job; - - clear(); - //clear the addressee - d->mAddr = Addressee(); - d->mAd = Address( Address::Home ); - //initialize ldif parser - d->mLdif.startParsing(); - - //set to original settings, offline use will disable writing - Resource::setReadOnly( d->mReadOnly ); - - createCache(); - if ( d->mCachePolicy != Cache_Always ) { - job = TDEIO::get( d->mLDAPUrl, true, false ); - connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), - this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) ); - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) ); - enter_loop(); - } - - job = loadFromCache(); - if ( job ) { - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) ); - enter_loop(); - } - if ( mErrorMsg.isEmpty() ) { - kdDebug(7125) << "ResourceLDAPTDEIO load ok!" << endl; - return true; - } else { - kdDebug(7125) << "ResourceLDAPTDEIO load finished with error: " << mErrorMsg << endl; - addressBook()->error( mErrorMsg ); - return false; - } -} - -bool ResourceLDAPTDEIO::asyncLoad() -{ - clear(); - //clear the addressee - d->mAddr = Addressee(); - d->mAd = Address( Address::Home ); - //initialize ldif parser - d->mLdif.startParsing(); - - Resource::setReadOnly( d->mReadOnly ); - - createCache(); - if ( d->mCachePolicy != Cache_Always ) { - TDEIO::Job *job = TDEIO::get( d->mLDAPUrl, true, false ); - connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), - this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) ); - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( result( TDEIO::Job* ) ) ); - } else { - result( NULL ); - } - return true; -} - -void ResourceLDAPTDEIO::data( TDEIO::Job *, const TQByteArray &data ) -{ - if ( data.size() ) { - d->mLdif.setLDIF( data ); - if ( d->mTmp ) { - d->mTmp->file()->writeBlock( data ); - } - } else { - d->mLdif.endLDIF(); - } - - LDIF::ParseVal ret; - TQString name; - TQByteArray value; - do { - ret = d->mLdif.nextItem(); - switch ( ret ) { - case LDIF::NewEntry: - kdDebug(7125) << "new entry: " << d->mLdif.dn() << endl; - break; - case LDIF::Item: - name = d->mLdif.attr().lower(); - value = d->mLdif.val(); - if ( name == mAttributes[ "commonName" ].lower() ) { - if ( !d->mAddr.formattedName().isEmpty() ) { - TQString fn = d->mAddr.formattedName(); - d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) ); - d->mAddr.setFormattedName( fn ); - } else - d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "formattedName" ].lower() ) { - d->mAddr.setFormattedName( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "givenName" ].lower() ) { - d->mAddr.setGivenName( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "mail" ].lower() ) { - d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ), true ); - } else if ( name == mAttributes[ "mailAlias" ].lower() ) { - d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ), false ); - } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { - PhoneNumber phone; - phone.setNumber( TQString::fromUtf8( value, value.size() ) ); - d->mAddr.insertPhoneNumber( phone ); - } else if ( name == mAttributes[ "telephoneNumber" ].lower() ) { - PhoneNumber phone( TQString::fromUtf8( value, value.size() ), - PhoneNumber::Work ); - d->mAddr.insertPhoneNumber( phone ); - } else if ( name == mAttributes[ "facsimileTelephoneNumber" ].lower() ) { - PhoneNumber phone( TQString::fromUtf8( value, value.size() ), - PhoneNumber::Fax ); - d->mAddr.insertPhoneNumber( phone ); - } else if ( name == mAttributes[ "mobile" ].lower() ) { - PhoneNumber phone( TQString::fromUtf8( value, value.size() ), - PhoneNumber::Cell ); - d->mAddr.insertPhoneNumber( phone ); - } else if ( name == mAttributes[ "pager" ].lower() ) { - PhoneNumber phone( TQString::fromUtf8( value, value.size() ), - PhoneNumber::Pager ); - d->mAddr.insertPhoneNumber( phone ); - } else if ( name == mAttributes[ "description" ].lower() ) { - d->mAddr.setNote( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "title" ].lower() ) { - d->mAddr.setTitle( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "street" ].lower() ) { - d->mAd.setStreet( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "state" ].lower() ) { - d->mAd.setRegion( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "city" ].lower() ) { - d->mAd.setLocality( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "postalcode" ].lower() ) { - d->mAd.setPostalCode( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "organization" ].lower() ) { - d->mAddr.setOrganization( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "familyName" ].lower() ) { - d->mAddr.setFamilyName( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "uid" ].lower() ) { - d->mAddr.setUid( TQString::fromUtf8( value, value.size() ) ); - } else if ( name == mAttributes[ "jpegPhoto" ].lower() ) { - KABC::Picture photo; - TQImage img( value ); - if ( !img.isNull() ) { - photo.setData( img ); - photo.setType( "image/jpeg" ); - d->mAddr.setPhoto( photo ); - } - } - - break; - case LDIF::EndEntry: { - d->mAddr.setResource( this ); - d->mAddr.insertAddress( d->mAd ); - d->mAddr.setChanged( false ); - insertAddressee( d->mAddr ); - //clear the addressee - d->mAddr = Addressee(); - d->mAd = Address( Address::Home ); - } - break; - default: - break; - } - } while ( ret != LDIF::MoreData ); -} - -void ResourceLDAPTDEIO::loadCacheResult( TDEIO::Job *job ) -{ - mErrorMsg = ""; - d->mError = job->error(); - if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) { - mErrorMsg = job->errorString(); - } - if ( !mErrorMsg.isEmpty() ) - emit loadingError( this, mErrorMsg ); - else - emit loadingFinished( this ); -} - -void ResourceLDAPTDEIO::result( TDEIO::Job *job ) -{ - mErrorMsg = ""; - if ( job ) { - d->mError = job->error(); - if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) { - mErrorMsg = job->errorString(); - } - } else { - d->mError = 0; - } - activateCache(); - - TDEIO::Job *cjob; - cjob = loadFromCache(); - if ( cjob ) { - connect( cjob, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( loadCacheResult( TDEIO::Job* ) ) ); - } else { - if ( !mErrorMsg.isEmpty() ) - emit loadingError( this, mErrorMsg ); - else - emit loadingFinished( this ); - } -} - -bool ResourceLDAPTDEIO::save( Ticket* ) -{ - kdDebug(7125) << "ResourceLDAPTDEIO save" << endl; - - d->mSaveIt = begin(); - TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1, true, false, false ); - connect( job, TQT_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ), - this, TQT_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) ); - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) ); - enter_loop(); - if ( mErrorMsg.isEmpty() ) { - kdDebug(7125) << "ResourceLDAPTDEIO save ok!" << endl; - return true; - } else { - kdDebug(7125) << "ResourceLDAPTDEIO finished with error: " << mErrorMsg << endl; - addressBook()->error( mErrorMsg ); - return false; - } -} - -bool ResourceLDAPTDEIO::asyncSave( Ticket* ) -{ - kdDebug(7125) << "ResourceLDAPTDEIO asyncSave" << endl; - d->mSaveIt = begin(); - TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1, true, false, false ); - connect( job, TQT_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ), - this, TQT_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) ); - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), - this, TQT_SLOT( saveResult( TDEIO::Job* ) ) ); - return true; -} - -void ResourceLDAPTDEIO::syncLoadSaveResult( TDEIO::Job *job ) -{ - d->mError = job->error(); - if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) - mErrorMsg = job->errorString(); - else - mErrorMsg = ""; - activateCache(); - - tqApp->exit_loop(); -} - -void ResourceLDAPTDEIO::saveResult( TDEIO::Job *job ) -{ - d->mError = job->error(); - if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) - emit savingError( this, job->errorString() ); - else - emit savingFinished( this ); -} - -void ResourceLDAPTDEIO::saveData( TDEIO::Job*, TQByteArray& data ) -{ - while ( d->mSaveIt != end() && - !(*d->mSaveIt).changed() ) d->mSaveIt++; - - if ( d->mSaveIt == end() ) { - kdDebug(7125) << "ResourceLDAPTDEIO endData" << endl; - data.resize(0); - return; - } - - kdDebug(7125) << "ResourceLDAPTDEIO saveData: " << (*d->mSaveIt).assembledName() << endl; - - AddresseeToLDIF( data, *d->mSaveIt, findUid( (*d->mSaveIt).uid() ) ); -// kdDebug(7125) << "ResourceLDAPTDEIO save LDIF: " << TQString::fromUtf8(data) << endl; - // mark as unchanged - (*d->mSaveIt).setChanged( false ); - - d->mSaveIt++; -} - -void ResourceLDAPTDEIO::removeAddressee( const Addressee& addr ) -{ - TQString dn = findUid( addr.uid() ); - - kdDebug(7125) << "ResourceLDAPTDEIO: removeAddressee: " << dn << endl; - - if ( !mErrorMsg.isEmpty() ) { - addressBook()->error( mErrorMsg ); - return; - } - if ( !dn.isEmpty() ) { - kdDebug(7125) << "ResourceLDAPTDEIO: found uid: " << dn << endl; - LDAPUrl url( d->mLDAPUrl ); - url.setPath( "/" + dn ); - url.setExtension( "x-dir", "base" ); - url.setScope( LDAPUrl::Base ); - if ( TDEIO::NetAccess::del( url, NULL ) ) mAddrMap.erase( addr.uid() ); - } else { - //maybe it's not saved yet - mAddrMap.erase( addr.uid() ); - } -} - - -void ResourceLDAPTDEIO::setUser( const TQString &user ) -{ - mUser = user; -} - -TQString ResourceLDAPTDEIO::user() const -{ - return mUser; -} - -void ResourceLDAPTDEIO::setPassword( const TQString &password ) -{ - mPassword = password; -} - -TQString ResourceLDAPTDEIO::password() const -{ - return mPassword; -} - -void ResourceLDAPTDEIO::setDn( const TQString &dn ) -{ - mDn = dn; -} - -TQString ResourceLDAPTDEIO::dn() const -{ - return mDn; -} - -void ResourceLDAPTDEIO::setHost( const TQString &host ) -{ - mHost = host; -} - -TQString ResourceLDAPTDEIO::host() const -{ - return mHost; -} - -void ResourceLDAPTDEIO::setPort( int port ) -{ - mPort = port; -} - -int ResourceLDAPTDEIO::port() const -{ - return mPort; -} - -void ResourceLDAPTDEIO::setVer( int ver ) -{ - d->mVer = ver; -} - -int ResourceLDAPTDEIO::ver() const -{ - return d->mVer; -} - -void ResourceLDAPTDEIO::setSizeLimit( int sizelimit ) -{ - d->mSizeLimit = sizelimit; -} - -int ResourceLDAPTDEIO::sizeLimit() -{ - return d->mSizeLimit; -} - -void ResourceLDAPTDEIO::setTimeLimit( int timelimit ) -{ - d->mTimeLimit = timelimit; -} - -int ResourceLDAPTDEIO::timeLimit() -{ - return d->mTimeLimit; -} - -void ResourceLDAPTDEIO::setFilter( const TQString &filter ) -{ - mFilter = filter; -} - -TQString ResourceLDAPTDEIO::filter() const -{ - return mFilter; -} - -void ResourceLDAPTDEIO::setIsAnonymous( bool value ) -{ - mAnonymous = value; -} - -bool ResourceLDAPTDEIO::isAnonymous() const -{ - return mAnonymous; -} - -void ResourceLDAPTDEIO::setIsTLS( bool value ) -{ - d->mTLS = value; -} - -bool ResourceLDAPTDEIO::isTLS() const -{ - return d->mTLS; -} -void ResourceLDAPTDEIO::setIsSSL( bool value ) -{ - d->mSSL = value; -} - -bool ResourceLDAPTDEIO::isSSL() const -{ - return d->mSSL; -} - -void ResourceLDAPTDEIO::setIsSubTree( bool value ) -{ - d->mSubTree = value; -} - -bool ResourceLDAPTDEIO::isSubTree() const -{ - return d->mSubTree; -} - -void ResourceLDAPTDEIO::setAttributes( const TQMap &attributes ) -{ - mAttributes = attributes; -} - -TQMap ResourceLDAPTDEIO::attributes() const -{ - return mAttributes; -} - -void ResourceLDAPTDEIO::setRDNPrefix( int value ) -{ - d->mRDNPrefix = value; -} - -int ResourceLDAPTDEIO::RDNPrefix() const -{ - return d->mRDNPrefix; -} - -void ResourceLDAPTDEIO::setIsSASL( bool value ) -{ - d->mSASL = value; -} - -bool ResourceLDAPTDEIO::isSASL() const -{ - return d->mSASL; -} - -void ResourceLDAPTDEIO::setMech( const TQString &mech ) -{ - d->mMech = mech; -} - -TQString ResourceLDAPTDEIO::mech() const -{ - return d->mMech; -} - -void ResourceLDAPTDEIO::setRealm( const TQString &realm ) -{ - d->mRealm = realm; -} - -TQString ResourceLDAPTDEIO::realm() const -{ - return d->mRealm; -} - -void ResourceLDAPTDEIO::setBindDN( const TQString &binddn ) -{ - d->mBindDN = binddn; -} - -TQString ResourceLDAPTDEIO::bindDN() const -{ - return d->mBindDN; -} - -void ResourceLDAPTDEIO::setCachePolicy( int pol ) -{ - d->mCachePolicy = pol; -} - -int ResourceLDAPTDEIO::cachePolicy() const -{ - return d->mCachePolicy; -} - -void ResourceLDAPTDEIO::setAutoCache( bool value ) -{ - d->mAutoCache = value; -} - -bool ResourceLDAPTDEIO::autoCache() -{ - return d->mAutoCache; -} - -TQString ResourceLDAPTDEIO::cacheDst() const -{ - return d->mCacheDst; -} - - -#include "resourceldapkio.moc" diff --git a/kabc/plugins/ldapkio/resourceldapkio.h b/kabc/plugins/ldapkio/resourceldapkio.h deleted file mode 100644 index 5c9282b9c..000000000 --- a/kabc/plugins/ldapkio/resourceldapkio.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2003 Tobias Koenig - Copyright (c) 2004 Szombathelyi György - - 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. -*/ - -#ifndef KABC_RESOURCELDAP_H -#define KABC_RESOURCELDAP_H - -#include -#include -#include - -class TDEConfig; - -namespace KABC { - -class KABC_EXPORT ResourceLDAPTDEIO : public Resource -{ - Q_OBJECT - - public: - enum CachePolicy{ Cache_No, Cache_NoConnection, Cache_Always }; - - ResourceLDAPTDEIO( const TDEConfig* ); - virtual ~ResourceLDAPTDEIO(); - /** - * Call this after you used one of the set... methods - */ - virtual void init(); - - virtual void writeConfig( TDEConfig* ); - - virtual bool doOpen(); - virtual void doClose(); - - virtual Ticket *requestSaveTicket(); - virtual void releaseSaveTicket( Ticket* ); - - virtual bool readOnly() const { return Resource::readOnly(); } - virtual void setReadOnly( bool value ); - - virtual bool load(); - virtual bool asyncLoad(); - virtual bool save( Ticket * ticket ); - virtual bool asyncSave( Ticket * ticket ); - - virtual void removeAddressee( const Addressee& addr ); - - void setUser( const TQString &user ); - TQString user() const; - - void setPassword( const TQString &password ); - TQString password() const; - - void setRealm( const TQString &realm ); - TQString realm() const; - - void setBindDN( const TQString &binddn ); - TQString bindDN() const; - - void setDn( const TQString &dn ); - TQString dn() const; - - void setHost( const TQString &host ); - TQString host() const; - - void setPort( int port ); - int port() const; - - void setVer( int ver ); - int ver() const; - - void setSizeLimit( int sizelimit ); - int sizeLimit(); - - void setTimeLimit( int timelimit ); - int timeLimit(); - - void setFilter( const TQString &filter ); - TQString filter() const; - - void setIsAnonymous( bool value ); - bool isAnonymous() const; - - void setAttributes( const TQMap &attributes ); - TQMap attributes() const; - - void setRDNPrefix( int value ); - int RDNPrefix() const; - - void setIsTLS( bool value ); - bool isTLS() const ; - - void setIsSSL( bool value ); - bool isSSL() const; - - void setIsSubTree( bool value ); - bool isSubTree() const ; - - void setIsSASL( bool value ); - bool isSASL() const ; - - void setMech( const TQString &mech ); - TQString mech() const; - - void setCachePolicy( int pol ); - int cachePolicy() const; - - void setAutoCache( bool value ); - bool autoCache(); - - TQString cacheDst() const; - -protected slots: - void entries( TDEIO::Job*, const TDEIO::UDSEntryList& ); - void data( TDEIO::Job*, const TQByteArray& ); - void result( TDEIO::Job* ); - void listResult( TDEIO::Job* ); - void syncLoadSaveResult( TDEIO::Job* ); - void saveResult( TDEIO::Job* ); - void saveData( TDEIO::Job*, TQByteArray& ); - void loadCacheResult( TDEIO::Job* ); - - private: - TQString mUser; - TQString mPassword; - TQString mDn; - TQString mHost; - TQString mFilter; - int mPort; - bool mAnonymous; - TQMap mAttributes; - - KURL mLDAPUrl; - int mGetCounter; //KDE 4: remove - bool mErrorOccured; //KDE 4: remove - TQString mErrorMsg; - TQMap mJobMap; //KDE 4: remove - - TDEIO::Job *loadFromCache(); - void createCache(); - void activateCache(); - void enter_loop(); - TQCString addEntry( const TQString &attr, const TQString &value, bool mod ); - TQString findUid( const TQString &uid ); - bool AddresseeToLDIF( TQByteArray &ldif, const Addressee &addr, - const TQString &olddn ); - - class ResourceLDAPTDEIOPrivate; - ResourceLDAPTDEIOPrivate *d; -}; - -} - -#endif diff --git a/kabc/plugins/ldapkio/resourceldapkioconfig.cpp b/kabc/plugins/ldapkio/resourceldapkioconfig.cpp deleted file mode 100644 index b517cffa5..000000000 --- a/kabc/plugins/ldapkio/resourceldapkioconfig.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2002 - 2003 Tobias Koenig - - 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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "resourceldapkio.h" - -#include "resourceldapkioconfig.h" -#include "resourceldapkioconfig.moc" - -using namespace KABC; - -ResourceLDAPTDEIOConfig::ResourceLDAPTDEIOConfig( TQWidget* parent, const char* name ) - : KRES::ConfigWidget( parent, name ) -{ - TQBoxLayout *mainLayout = new TQVBoxLayout( this ); - mainLayout->setAutoAdd( true ); - cfg = new LdapConfigWidget( LdapConfigWidget::W_ALL, this ); - - mSubTree = new TQCheckBox( i18n( "Sub-tree query" ), this ); - TQHBox *box = new TQHBox( this ); - box->setSpacing( KDialog::spacingHint() ); - mEditButton = new TQPushButton( i18n( "Edit Attributes..." ), box ); - mCacheButton = new TQPushButton( i18n( "Offline Use..." ), box ); - - connect( mEditButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editAttributes() ) ); - connect( mCacheButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editCache() ) ); -} - -void ResourceLDAPTDEIOConfig::loadSettings( KRES::Resource *res ) -{ - ResourceLDAPTDEIO *resource = dynamic_cast( res ); - - if ( !resource ) { - kdDebug(5700) << "ResourceLDAPTDEIOConfig::loadSettings(): cast failed" << endl; - return; - } - - cfg->setUser( resource->user() ); - cfg->setPassword( resource->password() ); - cfg->setRealm( resource->realm() ); - cfg->setBindDN( resource->bindDN() ); - cfg->setHost( resource->host() ); - cfg->setPort( resource->port() ); - cfg->setVer( resource->ver() ); - cfg->setTimeLimit( resource->timeLimit() ); - cfg->setSizeLimit( resource->sizeLimit() ); - cfg->setDn( resource->dn() ); - cfg->setFilter( resource->filter() ); - cfg->setMech( resource->mech() ); - if ( resource->isTLS() ) cfg->setSecTLS(); - else if ( resource->isSSL() ) cfg->setSecSSL(); - else cfg->setSecNO(); - if ( resource->isAnonymous() ) cfg->setAuthAnon(); - else if ( resource->isSASL() ) cfg->setAuthSASL(); - else cfg->setAuthSimple(); - - mSubTree->setChecked( resource->isSubTree() ); - mAttributes = resource->attributes(); - mRDNPrefix = resource->RDNPrefix(); - mCachePolicy = resource->cachePolicy(); - mCacheDst = resource->cacheDst(); - mAutoCache = resource->autoCache(); -} - -void ResourceLDAPTDEIOConfig::saveSettings( KRES::Resource *res ) -{ - ResourceLDAPTDEIO *resource = dynamic_cast( res ); - - if ( !resource ) { - kdDebug(5700) << "ResourceLDAPTDEIOConfig::saveSettings(): cast failed" << endl; - return; - } - - resource->setUser( cfg->user() ); - resource->setPassword( cfg->password() ); - resource->setRealm( cfg->realm() ); - resource->setBindDN( cfg->bindDN() ); - resource->setHost( cfg->host() ); - resource->setPort( cfg->port() ); - resource->setVer( cfg->ver() ); - resource->setTimeLimit( cfg->timeLimit() ); - resource->setSizeLimit( cfg->sizeLimit() ); - resource->setDn( cfg->dn() ); - resource->setFilter( cfg->filter() ); - resource->setIsAnonymous( cfg->isAuthAnon() ); - resource->setIsSASL( cfg->isAuthSASL() ); - resource->setMech( cfg->mech() ); - resource->setIsTLS( cfg->isSecTLS() ); - resource->setIsSSL( cfg->isSecSSL() ); - resource->setIsSubTree( mSubTree->isChecked() ); - resource->setAttributes( mAttributes ); - resource->setRDNPrefix( mRDNPrefix ); - resource->setCachePolicy( mCachePolicy ); - resource->init(); - -} - -void ResourceLDAPTDEIOConfig::editAttributes() -{ - AttributesDialog dlg( mAttributes, mRDNPrefix, this ); - if ( dlg.exec() ) { - mAttributes = dlg.attributes(); - mRDNPrefix = dlg.rdnprefix(); - } -} - -void ResourceLDAPTDEIOConfig::editCache() -{ - LDAPUrl src; - TQStringList attr; - - src = cfg->url(); - src.setScope( mSubTree->isChecked() ? LDAPUrl::Sub : LDAPUrl::One ); - if (!mAttributes.empty()) { - TQMap::Iterator it; - TQStringList attr; - for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { - if ( !it.data().isEmpty() && it.key() != "objectClass" ) - attr.append( it.data() ); - } - src.setAttributes( attr ); - } - src.setExtension( "x-dir", "base" ); - OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this ); - if ( dlg.exec() ) { - mCachePolicy = dlg.cachePolicy(); - mAutoCache = dlg.autoCache(); - } - -} - -AttributesDialog::AttributesDialog( const TQMap &attributes, - int rdnprefix, - TQWidget *parent, const char *name ) - : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel, - Ok, parent, name, true, true ) -{ - mNameDict.setAutoDelete( true ); - mNameDict.insert( "objectClass", new TQString( i18n( "Object classes" ) ) ); - mNameDict.insert( "commonName", new TQString( i18n( "Common name" ) ) ); - mNameDict.insert( "formattedName", new TQString( i18n( "Formatted name" ) ) ); - mNameDict.insert( "familyName", new TQString( i18n( "Family name" ) ) ); - mNameDict.insert( "givenName", new TQString( i18n( "Given name" ) ) ); - mNameDict.insert( "organization", new TQString( i18n( "Organization" ) ) ); - mNameDict.insert( "title", new TQString( i18n( "Title" ) ) ); - mNameDict.insert( "street", new TQString( i18n( "Street" ) ) ); - mNameDict.insert( "state", new TQString( i18n( "State" ) ) ); - mNameDict.insert( "city", new TQString( i18n( "City" ) ) ); - mNameDict.insert( "postalcode", new TQString( i18n( "Postal code" ) ) ); - mNameDict.insert( "mail", new TQString( i18n( "Email" ) ) ); - mNameDict.insert( "mailAlias", new TQString( i18n( "Email alias" ) ) ); - mNameDict.insert( "phoneNumber", new TQString( i18n( "Telephone number" ) ) ); - mNameDict.insert( "telephoneNumber", new TQString( i18n( "Work telephone number" ) ) ); - mNameDict.insert( "facsimileTelephoneNumber", new TQString( i18n( "Fax number" ) ) ); - mNameDict.insert( "mobile", new TQString( i18n( "Cell phone number" ) ) ); - mNameDict.insert( "pager", new TQString( i18n( "Pager" ) ) ); - mNameDict.insert( "description", new TQString( i18n( "Note" ) ) ); - mNameDict.insert( "uid", new TQString( i18n( "UID" ) ) ); - mNameDict.insert( "jpegPhoto", new TQString( i18n( "Photo" ) ) ); - - // default map - mDefaultMap.insert( "objectClass", "inetOrgPerson" ); - mDefaultMap.insert( "commonName", "cn" ); - mDefaultMap.insert( "formattedName", "displayName" ); - mDefaultMap.insert( "familyName", "sn" ); - mDefaultMap.insert( "givenName", "givenName" ); - mDefaultMap.insert( "title", "title" ); - mDefaultMap.insert( "street", "street" ); - mDefaultMap.insert( "state", "st" ); - mDefaultMap.insert( "city", "l" ); - mDefaultMap.insert( "organization", "o" ); - mDefaultMap.insert( "postalcode", "postalCode" ); - mDefaultMap.insert( "mail", "mail" ); - mDefaultMap.insert( "mailAlias", "" ); - mDefaultMap.insert( "phoneNumber", "homePhone" ); - mDefaultMap.insert( "telephoneNumber", "telephoneNumber" ); - mDefaultMap.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" ); - mDefaultMap.insert( "mobile", "mobile" ); - mDefaultMap.insert( "pager", "pager" ); - mDefaultMap.insert( "description", "description" ); - mDefaultMap.insert( "uid", "uid" ); - mDefaultMap.insert( "jpegPhoto", "jpegPhoto" ); - - // overwrite the default values here - TQMap kolabMap, netscapeMap, evolutionMap, outlookMap; - - // kolab - kolabMap.insert( "formattedName", "display-name" ); - kolabMap.insert( "mailAlias", "mailalias" ); - - // evolution - evolutionMap.insert( "formattedName", "fileAs" ); - - mMapList.append( attributes ); - mMapList.append( kolabMap ); - mMapList.append( netscapeMap ); - mMapList.append( evolutionMap ); - mMapList.append( outlookMap ); - - TQFrame *page = plainPage(); - TQGridLayout *layout = new TQGridLayout( page, 4, ( attributes.count() + 4 ) >> 1, - 0, spacingHint() ); - - TQLabel *label = new TQLabel( i18n( "Template:" ), page ); - layout->addWidget( label, 0, 0 ); - mMapCombo = new KComboBox( page ); - layout->addWidget( mMapCombo, 0, 1 ); - - mMapCombo->insertItem( i18n( "User Defined" ) ); - mMapCombo->insertItem( i18n( "Kolab" ) ); - mMapCombo->insertItem( i18n( "Netscape" ) ); - mMapCombo->insertItem( i18n( "Evolution" ) ); - mMapCombo->insertItem( i18n( "Outlook" ) ); - connect( mMapCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( mapChanged( int ) ) ); - - label = new TQLabel( i18n( "RDN prefix attribute:" ), page ); - layout->addWidget( label, 1, 0 ); - mRDNCombo = new KComboBox( page ); - layout->addWidget( mRDNCombo, 1, 1 ); - mRDNCombo->insertItem( i18n( "commonName" ) ); - mRDNCombo->insertItem( i18n( "UID" ) ); - mRDNCombo->setCurrentItem( rdnprefix ); - - TQMap::ConstIterator it; - int i, j = 0; - for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) { - if ( mNameDict[ it.key() ] == 0 ) { - i--; - continue; - } - if ( (uint)(i - 2) == ( mNameDict.count() >> 1 ) ) { - i = 0; - j = 2; - } - kdDebug(7125) << "itkey: " << it.key() << " i: " << i << endl; - label = new TQLabel( *mNameDict[ it.key() ] + ":", page ); - KLineEdit *lineedit = new KLineEdit( page ); - mLineEditDict.insert( it.key(), lineedit ); - lineedit->setText( it.data() ); - label->setBuddy( lineedit ); - layout->addWidget( label, i, j ); - layout->addWidget( lineedit, i, j+1 ); - } - - for ( i = 1; i < mMapCombo->count(); i++ ) { - TQDictIterator it2( mLineEditDict ); - for ( ; it2.current(); ++it2 ) { - if ( mMapList[ i ].contains( it2.currentKey() ) ) { - if ( mMapList[ i ][ it2.currentKey() ] != it2.current()->text() ) break; - } else { - if ( mDefaultMap[ it2.currentKey() ] != it2.current()->text() ) break; - } - } - if ( !it2.current() ) { - mMapCombo->setCurrentItem( i ); - break; - } - } - - KAcceleratorManager::manage( this ); -} - -AttributesDialog::~AttributesDialog() -{ -} - -TQMap AttributesDialog::attributes() const -{ - TQMap map; - - TQDictIterator it( mLineEditDict ); - for ( ; it.current(); ++it ) - map.insert( it.currentKey(), it.current()->text() ); - - return map; -} - -int AttributesDialog::rdnprefix() const -{ - return mRDNCombo->currentItem(); -} - -void AttributesDialog::mapChanged( int pos ) -{ - - // apply first the default and than the spezific changes - TQMap::Iterator it; - for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it ) - mLineEditDict[ it.key() ]->setText( it.data() ); - - for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) { - if ( !it.data().isEmpty() ) { - KLineEdit *le = mLineEditDict[ it.key() ]; - if ( le ) le->setText( it.data() ); - } - } -} - -OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KURL &src, - const TQString &dst, TQWidget *parent, const char *name ) - : KDialogBase( Plain, i18n( "Offline Configuration" ), Ok | Cancel, - Ok, parent, name, true, true ) -{ - TQFrame *page = plainPage(); - TQVBoxLayout *layout = new TQVBoxLayout( page ); - layout->setAutoAdd( true ); - - mSrc = src; mDst = dst; - mCacheGroup = new TQButtonGroup( 1, Qt::Horizontal, - i18n("Offline Cache Policy"), page ); - - TQRadioButton *bt; - new TQRadioButton( i18n("Do not use offline cache"), mCacheGroup ); - bt = new TQRadioButton( i18n("Use local copy if no connection"), mCacheGroup ); - new TQRadioButton( i18n("Always use local copy"), mCacheGroup ); - mCacheGroup->setButton( cachePolicy ); - - mAutoCache = new TQCheckBox( i18n("Refresh offline cache automatically"), - page ); - mAutoCache->setChecked( autoCache ); - mAutoCache->setEnabled( bt->isChecked() ); - - connect( bt, TQT_SIGNAL(toggled(bool)), mAutoCache, TQT_SLOT(setEnabled(bool)) ); - - TQPushButton *lcache = new TQPushButton( i18n("Load into Cache"), page ); - connect( lcache, TQT_SIGNAL( clicked() ), TQT_SLOT( loadCache() ) ); -} - -OfflineDialog::~OfflineDialog() -{ -} - -bool OfflineDialog::autoCache() const -{ - return mAutoCache->isChecked(); -} - -int OfflineDialog::cachePolicy() const -{ - return mCacheGroup->selectedId(); -} - -void OfflineDialog::loadCache() -{ - if ( TDEIO::NetAccess::download( mSrc, mDst, this ) ) { - KMessageBox::information( this, - i18n("Successfully downloaded directory server contents!") ); - } else { - KMessageBox::error( this, - i18n("An error occurred downloading directory server contents into file %1.").arg(mDst) ); - } -} diff --git a/kabc/plugins/ldapkio/resourceldapkioconfig.h b/kabc/plugins/ldapkio/resourceldapkioconfig.h deleted file mode 100644 index 0fde41d64..000000000 --- a/kabc/plugins/ldapkio/resourceldapkioconfig.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2002 - 2003 Tobias Koenig - - 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. -*/ - -#ifndef RESOURCELDAPCONFIG_H -#define RESOURCELDAPCONFIG_H - -#include -#include -#include -#include - -#include -#include -#include -#include - - -class TQCheckBox; -class TQPushButton; -class TQSpinBox; -class TQString; - -class KComboBox; -class KLineEdit; - -namespace KABC { - -class KABC_EXPORT ResourceLDAPTDEIOConfig : public KRES::ConfigWidget -{ - Q_OBJECT - - public: - ResourceLDAPTDEIOConfig( TQWidget* parent = 0, const char* name = 0 ); - - public slots: - void loadSettings( KRES::Resource* ); - void saveSettings( KRES::Resource* ); - - private slots: - void editAttributes(); - void editCache(); - private: - TQPushButton *mEditButton, *mCacheButton; - LdapConfigWidget *cfg; - TQCheckBox *mSubTree; - TQMap mAttributes; - int mRDNPrefix, mCachePolicy; - bool mAutoCache; - TQString mCacheDst; -}; - -class AttributesDialog : public KDialogBase -{ - Q_OBJECT - - public: - AttributesDialog( const TQMap &attributes, int rdnprefix, - TQWidget *parent, const char *name = 0 ); - ~AttributesDialog(); - - TQMap attributes() const; - int rdnprefix() const; - - private slots: - void mapChanged( int pos ); - - private: - enum { UserMap, KolabMap, NetscapeMap, EvolutionMap, OutlookMap }; - - KComboBox *mMapCombo, *mRDNCombo; - TQValueList< TQMap > mMapList; - TQMap mDefaultMap; - TQDict mLineEditDict; - TQDict mNameDict; -}; - -class OfflineDialog : public KDialogBase -{ - Q_OBJECT - - public: - OfflineDialog( bool autoCache, int cachePolicy, const KURL &src, - const TQString &dst, TQWidget *parent, const char *name = 0 ); - ~OfflineDialog(); - - int cachePolicy() const; - bool autoCache() const; - - private slots: - void loadCache(); - - private: - KURL mSrc; - TQString mDst; - TQButtonGroup *mCacheGroup; - TQCheckBox *mAutoCache; -}; - -} - -#endif diff --git a/kabc/plugins/ldapkio/resourceldapkioplugin.cpp b/kabc/plugins/ldapkio/resourceldapkioplugin.cpp deleted file mode 100644 index 6d928412d..000000000 --- a/kabc/plugins/ldapkio/resourceldapkioplugin.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2003 Tobias Koenig - - 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 "resourceldapkio.h" -#include "resourceldapkioconfig.h" - -#include -#include - -using namespace KABC; - -extern "C" -{ - KDE_EXPORT void *init_kabc_ldapkio() - { - TDEGlobal::locale()->insertCatalogue("kabc_ldapkio"); - return new KRES::PluginFactory(); - } -} diff --git a/kabc/plugins/ldaptdeio/CMakeLists.txt b/kabc/plugins/ldaptdeio/CMakeLists.txt new file mode 100644 index 000000000..75098cc9d --- /dev/null +++ b/kabc/plugins/ldaptdeio/CMakeLists.txt @@ -0,0 +1,73 @@ +################################################# +# +# (C) 2010 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR}/kabc + ${CMAKE_SOURCE_DIR}/kabc + + ${TQT_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR}/tdecore + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/dcop + ${CMAKE_SOURCE_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/tdeui + ${CMAKE_SOURCE_DIR}/tdeio + ${CMAKE_SOURCE_DIR}/tdeio/tdeio + ${CMAKE_SOURCE_DIR}/tdeio/tdefiles +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### headers ################################### + +install( FILES + resourceldaptdeio.h + DESTINATION ${INCLUDE_INSTALL_DIR}/kabc ) + + +##### other data ################################ + +install( FILES ldaptdeio.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc ) + + +##### kabc_ldaptdeio ############################## + +set( target kabc_ldaptdeio ) + +set( ${target}_SRCS + resourceldaptdeio.cpp resourceldaptdeioconfig.cpp +) + +tde_add_library( ${target} SHARED AUTOMOC + SOURCES ${${target}_SRCS} + VERSION 1.0.0 + LINK kabc-shared + DESTINATION ${LIB_INSTALL_DIR} +) + + +##### kabc_ldaptdeio ############################## + +set( target kabc_ldaptdeio ) + +set( ${target}_SRCS + resourceldaptdeioplugin.cpp +) + +tde_add_kpart( ${target} + SOURCES ${${target}_SRCS} + LINK kabc_ldaptdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/kabc/plugins/ldaptdeio/Makefile.am b/kabc/plugins/ldaptdeio/Makefile.am new file mode 100644 index 000000000..9c2d31ad7 --- /dev/null +++ b/kabc/plugins/ldaptdeio/Makefile.am @@ -0,0 +1,28 @@ +INCLUDES = -I$(top_srcdir)/kabc -I$(top_builddir)/kabc $(all_includes) + +# these are the headers for your project +noinst_HEADERS = resourceldaptdeioconfig.h + +lib_LTLIBRARIES = libkabc_ldaptdeio.la +libkabc_ldaptdeio_la_SOURCES = resourceldaptdeio.cpp resourceldaptdeioconfig.cpp +libkabc_ldaptdeio_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -version-info 1:0:0 -no-undefined +libkabc_ldaptdeio_la_LIBADD = $(LIB_KABC) $(LIB_KIO) $(LIB_QT) $(top_builddir)/tderesources/libtderesources.la $(LIB_TDEUI) $(LIB_TDECORE) +libkabc_ldaptdeio_la_COMPILE_FIRST = $(top_builddir)/kabc/addressee.h + +kde_module_LTLIBRARIES = kabc_ldaptdeio.la +kabc_ldaptdeio_la_SOURCES = resourceldaptdeioplugin.cpp +kabc_ldaptdeio_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +kabc_ldaptdeio_la_LIBADD = libkabc_ldaptdeio.la $(LIB_QT) $(LIB_TDECORE) + +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kabc_ldaptdeio.pot + +kabcincludedir = $(includedir)/kabc +kabcinclude_HEADERS = resourceldaptdeio.h + +servicedir = $(kde_servicesdir)/tderesources/kabc +service_DATA = ldaptdeio.desktop + +resourceldaptdeioplugin.lo: ../../addressee.h diff --git a/kabc/plugins/ldaptdeio/ldaptdeio.desktop b/kabc/plugins/ldaptdeio/ldaptdeio.desktop new file mode 100644 index 000000000..9bcd13337 --- /dev/null +++ b/kabc/plugins/ldaptdeio/ldaptdeio.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=LDAP +Name[bn]=এল-ডি-এ-পি (LDAP) +Name[hi]=एलडीएपी (LDAP) +Name[te]=ఎల్డిఏపి +X-TDE-Library=kabc_ldaptdeio +Type=Service +ServiceTypes=KResources/Plugin +X-TDE-ResourceFamily=contact +X-TDE-ResourceType=ldaptdeio diff --git a/kabc/plugins/ldaptdeio/resourceldaptdeio.cpp b/kabc/plugins/ldaptdeio/resourceldaptdeio.cpp new file mode 100644 index 000000000..b28289ecb --- /dev/null +++ b/kabc/plugins/ldaptdeio/resourceldaptdeio.cpp @@ -0,0 +1,1041 @@ +/* + This file is part of libkabc. + Copyright (c) 2003 Tobias Koenig + Copyright (c) 2004 Szombathelyi György + + 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 +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "resourceldaptdeio.h" +#include "resourceldaptdeioconfig.h" + +using namespace KABC; + +// Hack from Netaccess +void tqt_enter_modal( TQWidget *widget ); +void tqt_leave_modal( TQWidget *widget ); + +class ResourceLDAPTDEIO::ResourceLDAPTDEIOPrivate +{ + public: + LDIF mLdif; + bool mTLS,mSSL,mSubTree; + TQString mResultDn; + Addressee mAddr; + Address mAd; + Resource::Iterator mSaveIt; + bool mSASL; + TQString mMech; + TQString mRealm, mBindDN; + LDAPUrl mLDAPUrl; + int mVer, mSizeLimit, mTimeLimit, mRDNPrefix; + int mError; + int mCachePolicy; + bool mReadOnly; + bool mAutoCache; + TQString mCacheDst; + KTempFile *mTmp; +}; + +ResourceLDAPTDEIO::ResourceLDAPTDEIO( const TDEConfig *config ) + : Resource( config ) +{ + d = new ResourceLDAPTDEIOPrivate; + if ( config ) { + TQMap attrList; + TQStringList attributes = config->readListEntry( "LdapAttributes" ); + for ( uint pos = 0; pos < attributes.count(); pos += 2 ) + mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); + + mUser = config->readEntry( "LdapUser" ); + mPassword = KStringHandler::obscure( config->readEntry( "LdapPassword" ) ); + mDn = config->readEntry( "LdapDn" ); + mHost = config->readEntry( "LdapHost" ); + mPort = config->readNumEntry( "LdapPort", 389 ); + mFilter = config->readEntry( "LdapFilter" ); + mAnonymous = config->readBoolEntry( "LdapAnonymous" ); + d->mTLS = config->readBoolEntry( "LdapTLS" ); + d->mSSL = config->readBoolEntry( "LdapSSL" ); + d->mSubTree = config->readBoolEntry( "LdapSubTree" ); + d->mSASL = config->readBoolEntry( "LdapSASL" ); + d->mMech = config->readEntry( "LdapMech" ); + d->mRealm = config->readEntry( "LdapRealm" ); + d->mBindDN = config->readEntry( "LdapBindDN" ); + d->mVer = config->readNumEntry( "LdapVer", 3 ); + d->mTimeLimit = config->readNumEntry( "LdapTimeLimit", 0 ); + d->mSizeLimit = config->readNumEntry( "LdapSizeLimit", 0 ); + d->mRDNPrefix = config->readNumEntry( "LdapRDNPrefix", 0 ); + d->mCachePolicy = config->readNumEntry( "LdapCachePolicy", 0 ); + d->mAutoCache = config->readBoolEntry( "LdapAutoCache", true ); + } else { + mPort = 389; + mAnonymous = true; + mUser = mPassword = mHost = mFilter = mDn = ""; + d->mMech = d->mRealm = d->mBindDN = ""; + d->mTLS = d->mSSL = d->mSubTree = d->mSASL = false; + d->mVer = 3; d->mRDNPrefix = 0; + d->mTimeLimit = d->mSizeLimit = 0; + d->mCachePolicy = Cache_No; + d->mAutoCache = true; + } + d->mCacheDst = TDEGlobal::dirs()->saveLocation("cache", "ldaptdeio") + "/" + + type() + "_" + identifier(); + init(); +} + +ResourceLDAPTDEIO::~ResourceLDAPTDEIO() +{ + delete d; +} + +void ResourceLDAPTDEIO::enter_loop() +{ + TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal)); + dummy.setFocusPolicy( TQ_NoFocus ); + tqt_enter_modal(&dummy); + tqApp->enter_loop(); + tqt_leave_modal(&dummy); +} + +void ResourceLDAPTDEIO::entries( TDEIO::Job*, const TDEIO::UDSEntryList & list ) +{ + TDEIO::UDSEntryListConstIterator it = list.begin(); + TDEIO::UDSEntryListConstIterator end = list.end(); + for (; it != end; ++it) { + TDEIO::UDSEntry::ConstIterator it2 = (*it).begin(); + for( ; it2 != (*it).end(); it2++ ) { + if ( (*it2).m_uds == TDEIO::UDS_URL ) { + KURL tmpurl( (*it2).m_str ); + d->mResultDn = tmpurl.path(); + kdDebug(7125) << "findUid(): " << d->mResultDn << endl; + if ( d->mResultDn.startsWith("/") ) d->mResultDn.remove(0,1); + return; + } + } + } +} + +void ResourceLDAPTDEIO::listResult( TDEIO::Job *job) +{ + d->mError = job->error(); + if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) + mErrorMsg = job->errorString(); + else + mErrorMsg = ""; + tqApp->exit_loop(); +} + +TQString ResourceLDAPTDEIO::findUid( const TQString &uid ) +{ + LDAPUrl url( d->mLDAPUrl ); + TDEIO::UDSEntry entry; + + mErrorMsg = d->mResultDn = ""; + + url.setAttributes("dn"); + url.setFilter( "(" + mAttributes[ "uid" ] + "=" + uid + ")" + mFilter ); + url.setExtension( "x-dir", "one" ); + + kdDebug(7125) << "ResourceLDAPTDEIO::findUid() uid: " << uid << " url " << + url.prettyURL() << endl; + + TDEIO::ListJob * listJob = TDEIO::listDir( url, false /* no GUI */ ); + connect( listJob, + TQT_SIGNAL( entries( TDEIO::Job *, const TDEIO::UDSEntryList& ) ), + TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); + connect( listJob, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( listResult( TDEIO::Job* ) ) ); + + enter_loop(); + return d->mResultDn; +} + +TQCString ResourceLDAPTDEIO::addEntry( const TQString &attr, const TQString &value, bool mod ) +{ + TQCString tmp; + if ( !attr.isEmpty() ) { + if ( mod ) tmp += LDIF::assembleLine( "replace", attr ) + "\n"; + tmp += LDIF::assembleLine( attr, value ) + "\n"; + if ( mod ) tmp += "-\n"; + } + return ( tmp ); +} + +bool ResourceLDAPTDEIO::AddresseeToLDIF( TQByteArray &ldif, const Addressee &addr, + const TQString &olddn ) +{ + TQCString tmp; + TQString dn; + TQByteArray data; + bool mod = false; + + if ( olddn.isEmpty() ) { + //insert new entry + switch ( d->mRDNPrefix ) { + case 1: + dn = mAttributes[ "uid" ] + "=" + addr.uid() + "," +mDn; + break; + case 0: + default: + dn = mAttributes[ "commonName" ] + "=" + addr.assembledName() + "," +mDn; + break; + } + } else { + //modify existing entry + mod = true; + if ( olddn.startsWith( mAttributes[ "uid" ] ) ) { + dn = mAttributes[ "uid" ] + "=" + addr.uid() + "," + olddn.section( ',', 1 ); + } else if ( olddn.startsWith( mAttributes[ "commonName" ] ) ) { + dn = mAttributes[ "commonName" ] + "=" + addr.assembledName() + "," + + olddn.section( ',', 1 ); + } else { + dn = olddn; + } + + if ( olddn.lower() != dn.lower() ) { + tmp = LDIF::assembleLine( "dn", olddn ) + "\n"; + tmp += "changetype: modrdn\n"; + tmp += LDIF::assembleLine( "newrdn", dn.section( ',', 0, 0 ) ) + "\n"; + tmp += "deleteoldrdn: 1\n\n"; + } + } + + + tmp += LDIF::assembleLine( "dn", dn ) + "\n"; + if ( mod ) tmp += "changetype: modify\n"; + if ( !mod ) { + tmp += "objectClass: top\n"; + TQStringList obclass = TQStringList::split( ',', mAttributes[ "objectClass" ] ); + for ( TQStringList::iterator it = obclass.begin(); it != obclass.end(); it++ ) { + tmp += LDIF::assembleLine( "objectClass", *it ) + "\n"; + } + } + + tmp += addEntry( mAttributes[ "commonName" ], addr.assembledName(), mod ); + tmp += addEntry( mAttributes[ "formattedName" ], addr.formattedName(), mod ); + tmp += addEntry( mAttributes[ "givenName" ], addr.givenName(), mod ); + tmp += addEntry( mAttributes[ "familyName" ], addr.familyName(), mod ); + tmp += addEntry( mAttributes[ "uid" ], addr.uid(), mod ); + + PhoneNumber number; + number = addr.phoneNumber( PhoneNumber::Home ); + tmp += addEntry( mAttributes[ "phoneNumber" ], number.number().utf8(), mod ); + number = addr.phoneNumber( PhoneNumber::Work ); + tmp += addEntry( mAttributes[ "telephoneNumber" ], number.number().utf8(), mod ); + number = addr.phoneNumber( PhoneNumber::Fax ); + tmp += addEntry( mAttributes[ "facsimileTelephoneNumber" ], number.number().utf8(), mod ); + number = addr.phoneNumber( PhoneNumber::Cell ); + tmp += addEntry( mAttributes[ "mobile" ], number.number().utf8(), mod ); + number = addr.phoneNumber( PhoneNumber::Pager ); + tmp += addEntry( mAttributes[ "pager" ], number.number().utf8(), mod ); + + tmp += addEntry( mAttributes[ "description" ], addr.note(), mod ); + tmp += addEntry( mAttributes[ "title" ], addr.title(), mod ); + tmp += addEntry( mAttributes[ "organization" ], addr.organization(), mod ); + + Address ad = addr.address( Address::Home ); + if ( !ad.isEmpty() ) { + tmp += addEntry( mAttributes[ "street" ], ad.street(), mod ); + tmp += addEntry( mAttributes[ "state" ], ad.region(), mod ); + tmp += addEntry( mAttributes[ "city" ], ad.locality(), mod ); + tmp += addEntry( mAttributes[ "postalcode" ], ad.postalCode(), mod ); + } + + TQStringList emails = addr.emails(); + TQStringList::ConstIterator mailIt = emails.begin(); + + if ( !mAttributes[ "mail" ].isEmpty() ) { + if ( mod ) tmp += + LDIF::assembleLine( "replace", mAttributes[ "mail" ] ) + "\n"; + if ( mailIt != emails.end() ) { + tmp += LDIF::assembleLine( mAttributes[ "mail" ], *mailIt ) + "\n"; + mailIt ++; + } + if ( mod && mAttributes[ "mail" ] != mAttributes[ "mailAlias" ] ) tmp += "-\n"; + } + + if ( !mAttributes[ "mailAlias" ].isEmpty() ) { + if ( mod && mAttributes[ "mail" ] != mAttributes[ "mailAlias" ] ) tmp += + LDIF::assembleLine( "replace", mAttributes[ "mailAlias" ] ) + "\n"; + for ( ; mailIt != emails.end(); ++mailIt ) { + tmp += LDIF::assembleLine( mAttributes[ "mailAlias" ], *mailIt ) + "\n" ; + } + if ( mod ) tmp += "-\n"; + } + + if ( !mAttributes[ "jpegPhoto" ].isEmpty() ) { + TQByteArray pic; + TQBuffer buffer( pic ); + buffer.open( IO_WriteOnly ); + addr.photo().data().save( &buffer, "JPEG" ); + + if ( mod ) tmp += + LDIF::assembleLine( "replace", mAttributes[ "jpegPhoto" ] ) + "\n"; + tmp += LDIF::assembleLine( mAttributes[ "jpegPhoto" ], pic, 76 ) + "\n"; + if ( mod ) tmp += "-\n"; + } + + tmp += "\n"; + kdDebug(7125) << "ldif: " << TQString(TQString::fromUtf8(tmp)) << endl; + ldif = tmp; + return true; +} + +void ResourceLDAPTDEIO::setReadOnly( bool value ) +{ + //save the original readonly flag, because offline using disables writing + d->mReadOnly = true; + Resource::setReadOnly( value ); +} + +void ResourceLDAPTDEIO::init() +{ + if ( mPort == 0 ) mPort = 389; + + /** + If you want to add new attributes, append them here, add a + translation string in the ctor of AttributesDialog and + handle them in the load() method below. + These are the default values + */ + if ( !mAttributes.contains("objectClass") ) + mAttributes.insert( "objectClass", "inetOrgPerson" ); + if ( !mAttributes.contains("commonName") ) + mAttributes.insert( "commonName", "cn" ); + if ( !mAttributes.contains("formattedName") ) + mAttributes.insert( "formattedName", "displayName" ); + if ( !mAttributes.contains("familyName") ) + mAttributes.insert( "familyName", "sn" ); + if ( !mAttributes.contains("givenName") ) + mAttributes.insert( "givenName", "givenName" ); + if ( !mAttributes.contains("mail") ) + mAttributes.insert( "mail", "mail" ); + if ( !mAttributes.contains("mailAlias") ) + mAttributes.insert( "mailAlias", "" ); + if ( !mAttributes.contains("phoneNumber") ) + mAttributes.insert( "phoneNumber", "homePhone" ); + if ( !mAttributes.contains("telephoneNumber") ) + mAttributes.insert( "telephoneNumber", "telephoneNumber" ); + if ( !mAttributes.contains("facsimileTelephoneNumber") ) + mAttributes.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" ); + if ( !mAttributes.contains("mobile") ) + mAttributes.insert( "mobile", "mobile" ); + if ( !mAttributes.contains("pager") ) + mAttributes.insert( "pager", "pager" ); + if ( !mAttributes.contains("description") ) + mAttributes.insert( "description", "description" ); + + if ( !mAttributes.contains("title") ) + mAttributes.insert( "title", "title" ); + if ( !mAttributes.contains("street") ) + mAttributes.insert( "street", "street" ); + if ( !mAttributes.contains("state") ) + mAttributes.insert( "state", "st" ); + if ( !mAttributes.contains("city") ) + mAttributes.insert( "city", "l" ); + if ( !mAttributes.contains("organization") ) + mAttributes.insert( "organization", "o" ); + if ( !mAttributes.contains("postalcode") ) + mAttributes.insert( "postalcode", "postalCode" ); + + if ( !mAttributes.contains("uid") ) + mAttributes.insert( "uid", "uid" ); + if ( !mAttributes.contains("jpegPhoto") ) + mAttributes.insert( "jpegPhoto", "jpegPhoto" ); + + d->mLDAPUrl = KURL(); + if ( !mAnonymous ) { + d->mLDAPUrl.setUser( mUser ); + d->mLDAPUrl.setPass( mPassword ); + } + d->mLDAPUrl.setProtocol( d->mSSL ? "ldaps" : "ldap"); + d->mLDAPUrl.setHost( mHost ); + d->mLDAPUrl.setPort( mPort ); + d->mLDAPUrl.setDn( mDn ); + + if (!mAttributes.empty()) { + TQMap::Iterator it; + TQStringList attr; + for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { + if ( !it.data().isEmpty() && it.key() != "objectClass" ) + attr.append( it.data() ); + } + d->mLDAPUrl.setAttributes( attr ); + } + + d->mLDAPUrl.setScope( d->mSubTree ? LDAPUrl::Sub : LDAPUrl::One ); + if ( !mFilter.isEmpty() && mFilter != "(objectClass=*)" ) + d->mLDAPUrl.setFilter( mFilter ); + d->mLDAPUrl.setExtension( "x-dir", "base" ); + if ( d->mTLS ) d->mLDAPUrl.setExtension( "x-tls", "" ); + d->mLDAPUrl.setExtension( "x-ver", TQString::number( d->mVer ) ); + if ( d->mSizeLimit ) + d->mLDAPUrl.setExtension( "x-sizelimit", TQString::number( d->mSizeLimit ) ); + if ( d->mTimeLimit ) + d->mLDAPUrl.setExtension( "x-timelimit", TQString::number( d->mTimeLimit ) ); + if ( d->mSASL ) { + d->mLDAPUrl.setExtension( "x-sasl", "" ); + if ( !d->mBindDN.isEmpty() ) d->mLDAPUrl.setExtension( "bindname", d->mBindDN ); + if ( !d->mMech.isEmpty() ) d->mLDAPUrl.setExtension( "x-mech", d->mMech ); + if ( !d->mRealm.isEmpty() ) d->mLDAPUrl.setExtension( "x-realm", d->mRealm ); + } + + d->mReadOnly = readOnly(); + + kdDebug(7125) << "resource_ldaptdeio url: " << d->mLDAPUrl.prettyURL() << endl; +} + +void ResourceLDAPTDEIO::writeConfig( TDEConfig *config ) +{ + Resource::writeConfig( config ); + + config->writeEntry( "LdapUser", mUser ); + config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); + config->writeEntry( "LdapDn", mDn ); + config->writeEntry( "LdapHost", mHost ); + config->writeEntry( "LdapPort", mPort ); + config->writeEntry( "LdapFilter", mFilter ); + config->writeEntry( "LdapAnonymous", mAnonymous ); + config->writeEntry( "LdapTLS", d->mTLS ); + config->writeEntry( "LdapSSL", d->mSSL ); + config->writeEntry( "LdapSubTree", d->mSubTree ); + config->writeEntry( "LdapSASL", d->mSASL ); + config->writeEntry( "LdapMech", d->mMech ); + config->writeEntry( "LdapVer", d->mVer ); + config->writeEntry( "LdapTimeLimit", d->mTimeLimit ); + config->writeEntry( "LdapSizeLimit", d->mSizeLimit ); + config->writeEntry( "LdapRDNPrefix", d->mRDNPrefix ); + config->writeEntry( "LdapRealm", d->mRealm ); + config->writeEntry( "LdapBindDN", d->mBindDN ); + config->writeEntry( "LdapCachePolicy", d->mCachePolicy ); + config->writeEntry( "LdapAutoCache", d->mAutoCache ); + + TQStringList attributes; + TQMap::Iterator it; + for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) + attributes << it.key() << it.data(); + + config->writeEntry( "LdapAttributes", attributes ); +} + +Ticket *ResourceLDAPTDEIO::requestSaveTicket() +{ + if ( !addressBook() ) { + kdDebug(7125) << "no addressbook" << endl; + return 0; + } + + return createTicket( this ); +} + +void ResourceLDAPTDEIO::releaseSaveTicket( Ticket *ticket ) +{ + delete ticket; +} + +bool ResourceLDAPTDEIO::doOpen() +{ + return true; +} + +void ResourceLDAPTDEIO::doClose() +{ +} + +void ResourceLDAPTDEIO::createCache() +{ + d->mTmp = NULL; + if ( d->mCachePolicy == Cache_NoConnection && d->mAutoCache ) { + d->mTmp = new KTempFile( d->mCacheDst, "tmp" ); + d->mTmp->setAutoDelete( true ); + } +} + +void ResourceLDAPTDEIO::activateCache() +{ + if ( d->mTmp && d->mError == 0 ) { + d->mTmp->close(); + rename( TQFile::encodeName( d->mTmp->name() ), TQFile::encodeName( d->mCacheDst ) ); + } + if ( d->mTmp ) { + delete d->mTmp; + d->mTmp = 0; + } +} + +TDEIO::Job *ResourceLDAPTDEIO::loadFromCache() +{ + TDEIO::Job *job = NULL; + if ( d->mCachePolicy == Cache_Always || + ( d->mCachePolicy == Cache_NoConnection && + d->mError == TDEIO::ERR_COULD_NOT_CONNECT ) ) { + + d->mAddr = Addressee(); + d->mAd = Address( Address::Home ); + //initialize ldif parser + d->mLdif.startParsing(); + + Resource::setReadOnly( true ); + + KURL url( d->mCacheDst ); + job = TDEIO::get( url, true, false ); + connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), + this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) ); + } + return job; +} + +bool ResourceLDAPTDEIO::load() +{ + kdDebug(7125) << "ResourceLDAPTDEIO::load()" << endl; + TDEIO::Job *job; + + clear(); + //clear the addressee + d->mAddr = Addressee(); + d->mAd = Address( Address::Home ); + //initialize ldif parser + d->mLdif.startParsing(); + + //set to original settings, offline use will disable writing + Resource::setReadOnly( d->mReadOnly ); + + createCache(); + if ( d->mCachePolicy != Cache_Always ) { + job = TDEIO::get( d->mLDAPUrl, true, false ); + connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), + this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) ); + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) ); + enter_loop(); + } + + job = loadFromCache(); + if ( job ) { + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) ); + enter_loop(); + } + if ( mErrorMsg.isEmpty() ) { + kdDebug(7125) << "ResourceLDAPTDEIO load ok!" << endl; + return true; + } else { + kdDebug(7125) << "ResourceLDAPTDEIO load finished with error: " << mErrorMsg << endl; + addressBook()->error( mErrorMsg ); + return false; + } +} + +bool ResourceLDAPTDEIO::asyncLoad() +{ + clear(); + //clear the addressee + d->mAddr = Addressee(); + d->mAd = Address( Address::Home ); + //initialize ldif parser + d->mLdif.startParsing(); + + Resource::setReadOnly( d->mReadOnly ); + + createCache(); + if ( d->mCachePolicy != Cache_Always ) { + TDEIO::Job *job = TDEIO::get( d->mLDAPUrl, true, false ); + connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), + this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) ); + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( result( TDEIO::Job* ) ) ); + } else { + result( NULL ); + } + return true; +} + +void ResourceLDAPTDEIO::data( TDEIO::Job *, const TQByteArray &data ) +{ + if ( data.size() ) { + d->mLdif.setLDIF( data ); + if ( d->mTmp ) { + d->mTmp->file()->writeBlock( data ); + } + } else { + d->mLdif.endLDIF(); + } + + LDIF::ParseVal ret; + TQString name; + TQByteArray value; + do { + ret = d->mLdif.nextItem(); + switch ( ret ) { + case LDIF::NewEntry: + kdDebug(7125) << "new entry: " << d->mLdif.dn() << endl; + break; + case LDIF::Item: + name = d->mLdif.attr().lower(); + value = d->mLdif.val(); + if ( name == mAttributes[ "commonName" ].lower() ) { + if ( !d->mAddr.formattedName().isEmpty() ) { + TQString fn = d->mAddr.formattedName(); + d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) ); + d->mAddr.setFormattedName( fn ); + } else + d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "formattedName" ].lower() ) { + d->mAddr.setFormattedName( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "givenName" ].lower() ) { + d->mAddr.setGivenName( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "mail" ].lower() ) { + d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ), true ); + } else if ( name == mAttributes[ "mailAlias" ].lower() ) { + d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ), false ); + } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { + PhoneNumber phone; + phone.setNumber( TQString::fromUtf8( value, value.size() ) ); + d->mAddr.insertPhoneNumber( phone ); + } else if ( name == mAttributes[ "telephoneNumber" ].lower() ) { + PhoneNumber phone( TQString::fromUtf8( value, value.size() ), + PhoneNumber::Work ); + d->mAddr.insertPhoneNumber( phone ); + } else if ( name == mAttributes[ "facsimileTelephoneNumber" ].lower() ) { + PhoneNumber phone( TQString::fromUtf8( value, value.size() ), + PhoneNumber::Fax ); + d->mAddr.insertPhoneNumber( phone ); + } else if ( name == mAttributes[ "mobile" ].lower() ) { + PhoneNumber phone( TQString::fromUtf8( value, value.size() ), + PhoneNumber::Cell ); + d->mAddr.insertPhoneNumber( phone ); + } else if ( name == mAttributes[ "pager" ].lower() ) { + PhoneNumber phone( TQString::fromUtf8( value, value.size() ), + PhoneNumber::Pager ); + d->mAddr.insertPhoneNumber( phone ); + } else if ( name == mAttributes[ "description" ].lower() ) { + d->mAddr.setNote( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "title" ].lower() ) { + d->mAddr.setTitle( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "street" ].lower() ) { + d->mAd.setStreet( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "state" ].lower() ) { + d->mAd.setRegion( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "city" ].lower() ) { + d->mAd.setLocality( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "postalcode" ].lower() ) { + d->mAd.setPostalCode( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "organization" ].lower() ) { + d->mAddr.setOrganization( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "familyName" ].lower() ) { + d->mAddr.setFamilyName( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "uid" ].lower() ) { + d->mAddr.setUid( TQString::fromUtf8( value, value.size() ) ); + } else if ( name == mAttributes[ "jpegPhoto" ].lower() ) { + KABC::Picture photo; + TQImage img( value ); + if ( !img.isNull() ) { + photo.setData( img ); + photo.setType( "image/jpeg" ); + d->mAddr.setPhoto( photo ); + } + } + + break; + case LDIF::EndEntry: { + d->mAddr.setResource( this ); + d->mAddr.insertAddress( d->mAd ); + d->mAddr.setChanged( false ); + insertAddressee( d->mAddr ); + //clear the addressee + d->mAddr = Addressee(); + d->mAd = Address( Address::Home ); + } + break; + default: + break; + } + } while ( ret != LDIF::MoreData ); +} + +void ResourceLDAPTDEIO::loadCacheResult( TDEIO::Job *job ) +{ + mErrorMsg = ""; + d->mError = job->error(); + if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) { + mErrorMsg = job->errorString(); + } + if ( !mErrorMsg.isEmpty() ) + emit loadingError( this, mErrorMsg ); + else + emit loadingFinished( this ); +} + +void ResourceLDAPTDEIO::result( TDEIO::Job *job ) +{ + mErrorMsg = ""; + if ( job ) { + d->mError = job->error(); + if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) { + mErrorMsg = job->errorString(); + } + } else { + d->mError = 0; + } + activateCache(); + + TDEIO::Job *cjob; + cjob = loadFromCache(); + if ( cjob ) { + connect( cjob, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( loadCacheResult( TDEIO::Job* ) ) ); + } else { + if ( !mErrorMsg.isEmpty() ) + emit loadingError( this, mErrorMsg ); + else + emit loadingFinished( this ); + } +} + +bool ResourceLDAPTDEIO::save( Ticket* ) +{ + kdDebug(7125) << "ResourceLDAPTDEIO save" << endl; + + d->mSaveIt = begin(); + TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1, true, false, false ); + connect( job, TQT_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ), + this, TQT_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) ); + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) ); + enter_loop(); + if ( mErrorMsg.isEmpty() ) { + kdDebug(7125) << "ResourceLDAPTDEIO save ok!" << endl; + return true; + } else { + kdDebug(7125) << "ResourceLDAPTDEIO finished with error: " << mErrorMsg << endl; + addressBook()->error( mErrorMsg ); + return false; + } +} + +bool ResourceLDAPTDEIO::asyncSave( Ticket* ) +{ + kdDebug(7125) << "ResourceLDAPTDEIO asyncSave" << endl; + d->mSaveIt = begin(); + TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1, true, false, false ); + connect( job, TQT_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ), + this, TQT_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) ); + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), + this, TQT_SLOT( saveResult( TDEIO::Job* ) ) ); + return true; +} + +void ResourceLDAPTDEIO::syncLoadSaveResult( TDEIO::Job *job ) +{ + d->mError = job->error(); + if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) + mErrorMsg = job->errorString(); + else + mErrorMsg = ""; + activateCache(); + + tqApp->exit_loop(); +} + +void ResourceLDAPTDEIO::saveResult( TDEIO::Job *job ) +{ + d->mError = job->error(); + if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) + emit savingError( this, job->errorString() ); + else + emit savingFinished( this ); +} + +void ResourceLDAPTDEIO::saveData( TDEIO::Job*, TQByteArray& data ) +{ + while ( d->mSaveIt != end() && + !(*d->mSaveIt).changed() ) d->mSaveIt++; + + if ( d->mSaveIt == end() ) { + kdDebug(7125) << "ResourceLDAPTDEIO endData" << endl; + data.resize(0); + return; + } + + kdDebug(7125) << "ResourceLDAPTDEIO saveData: " << (*d->mSaveIt).assembledName() << endl; + + AddresseeToLDIF( data, *d->mSaveIt, findUid( (*d->mSaveIt).uid() ) ); +// kdDebug(7125) << "ResourceLDAPTDEIO save LDIF: " << TQString::fromUtf8(data) << endl; + // mark as unchanged + (*d->mSaveIt).setChanged( false ); + + d->mSaveIt++; +} + +void ResourceLDAPTDEIO::removeAddressee( const Addressee& addr ) +{ + TQString dn = findUid( addr.uid() ); + + kdDebug(7125) << "ResourceLDAPTDEIO: removeAddressee: " << dn << endl; + + if ( !mErrorMsg.isEmpty() ) { + addressBook()->error( mErrorMsg ); + return; + } + if ( !dn.isEmpty() ) { + kdDebug(7125) << "ResourceLDAPTDEIO: found uid: " << dn << endl; + LDAPUrl url( d->mLDAPUrl ); + url.setPath( "/" + dn ); + url.setExtension( "x-dir", "base" ); + url.setScope( LDAPUrl::Base ); + if ( TDEIO::NetAccess::del( url, NULL ) ) mAddrMap.erase( addr.uid() ); + } else { + //maybe it's not saved yet + mAddrMap.erase( addr.uid() ); + } +} + + +void ResourceLDAPTDEIO::setUser( const TQString &user ) +{ + mUser = user; +} + +TQString ResourceLDAPTDEIO::user() const +{ + return mUser; +} + +void ResourceLDAPTDEIO::setPassword( const TQString &password ) +{ + mPassword = password; +} + +TQString ResourceLDAPTDEIO::password() const +{ + return mPassword; +} + +void ResourceLDAPTDEIO::setDn( const TQString &dn ) +{ + mDn = dn; +} + +TQString ResourceLDAPTDEIO::dn() const +{ + return mDn; +} + +void ResourceLDAPTDEIO::setHost( const TQString &host ) +{ + mHost = host; +} + +TQString ResourceLDAPTDEIO::host() const +{ + return mHost; +} + +void ResourceLDAPTDEIO::setPort( int port ) +{ + mPort = port; +} + +int ResourceLDAPTDEIO::port() const +{ + return mPort; +} + +void ResourceLDAPTDEIO::setVer( int ver ) +{ + d->mVer = ver; +} + +int ResourceLDAPTDEIO::ver() const +{ + return d->mVer; +} + +void ResourceLDAPTDEIO::setSizeLimit( int sizelimit ) +{ + d->mSizeLimit = sizelimit; +} + +int ResourceLDAPTDEIO::sizeLimit() +{ + return d->mSizeLimit; +} + +void ResourceLDAPTDEIO::setTimeLimit( int timelimit ) +{ + d->mTimeLimit = timelimit; +} + +int ResourceLDAPTDEIO::timeLimit() +{ + return d->mTimeLimit; +} + +void ResourceLDAPTDEIO::setFilter( const TQString &filter ) +{ + mFilter = filter; +} + +TQString ResourceLDAPTDEIO::filter() const +{ + return mFilter; +} + +void ResourceLDAPTDEIO::setIsAnonymous( bool value ) +{ + mAnonymous = value; +} + +bool ResourceLDAPTDEIO::isAnonymous() const +{ + return mAnonymous; +} + +void ResourceLDAPTDEIO::setIsTLS( bool value ) +{ + d->mTLS = value; +} + +bool ResourceLDAPTDEIO::isTLS() const +{ + return d->mTLS; +} +void ResourceLDAPTDEIO::setIsSSL( bool value ) +{ + d->mSSL = value; +} + +bool ResourceLDAPTDEIO::isSSL() const +{ + return d->mSSL; +} + +void ResourceLDAPTDEIO::setIsSubTree( bool value ) +{ + d->mSubTree = value; +} + +bool ResourceLDAPTDEIO::isSubTree() const +{ + return d->mSubTree; +} + +void ResourceLDAPTDEIO::setAttributes( const TQMap &attributes ) +{ + mAttributes = attributes; +} + +TQMap ResourceLDAPTDEIO::attributes() const +{ + return mAttributes; +} + +void ResourceLDAPTDEIO::setRDNPrefix( int value ) +{ + d->mRDNPrefix = value; +} + +int ResourceLDAPTDEIO::RDNPrefix() const +{ + return d->mRDNPrefix; +} + +void ResourceLDAPTDEIO::setIsSASL( bool value ) +{ + d->mSASL = value; +} + +bool ResourceLDAPTDEIO::isSASL() const +{ + return d->mSASL; +} + +void ResourceLDAPTDEIO::setMech( const TQString &mech ) +{ + d->mMech = mech; +} + +TQString ResourceLDAPTDEIO::mech() const +{ + return d->mMech; +} + +void ResourceLDAPTDEIO::setRealm( const TQString &realm ) +{ + d->mRealm = realm; +} + +TQString ResourceLDAPTDEIO::realm() const +{ + return d->mRealm; +} + +void ResourceLDAPTDEIO::setBindDN( const TQString &binddn ) +{ + d->mBindDN = binddn; +} + +TQString ResourceLDAPTDEIO::bindDN() const +{ + return d->mBindDN; +} + +void ResourceLDAPTDEIO::setCachePolicy( int pol ) +{ + d->mCachePolicy = pol; +} + +int ResourceLDAPTDEIO::cachePolicy() const +{ + return d->mCachePolicy; +} + +void ResourceLDAPTDEIO::setAutoCache( bool value ) +{ + d->mAutoCache = value; +} + +bool ResourceLDAPTDEIO::autoCache() +{ + return d->mAutoCache; +} + +TQString ResourceLDAPTDEIO::cacheDst() const +{ + return d->mCacheDst; +} + + +#include "resourceldaptdeio.moc" diff --git a/kabc/plugins/ldaptdeio/resourceldaptdeio.h b/kabc/plugins/ldaptdeio/resourceldaptdeio.h new file mode 100644 index 000000000..5c9282b9c --- /dev/null +++ b/kabc/plugins/ldaptdeio/resourceldaptdeio.h @@ -0,0 +1,171 @@ +/* + This file is part of libkabc. + Copyright (c) 2003 Tobias Koenig + Copyright (c) 2004 Szombathelyi György + + 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. +*/ + +#ifndef KABC_RESOURCELDAP_H +#define KABC_RESOURCELDAP_H + +#include +#include +#include + +class TDEConfig; + +namespace KABC { + +class KABC_EXPORT ResourceLDAPTDEIO : public Resource +{ + Q_OBJECT + + public: + enum CachePolicy{ Cache_No, Cache_NoConnection, Cache_Always }; + + ResourceLDAPTDEIO( const TDEConfig* ); + virtual ~ResourceLDAPTDEIO(); + /** + * Call this after you used one of the set... methods + */ + virtual void init(); + + virtual void writeConfig( TDEConfig* ); + + virtual bool doOpen(); + virtual void doClose(); + + virtual Ticket *requestSaveTicket(); + virtual void releaseSaveTicket( Ticket* ); + + virtual bool readOnly() const { return Resource::readOnly(); } + virtual void setReadOnly( bool value ); + + virtual bool load(); + virtual bool asyncLoad(); + virtual bool save( Ticket * ticket ); + virtual bool asyncSave( Ticket * ticket ); + + virtual void removeAddressee( const Addressee& addr ); + + void setUser( const TQString &user ); + TQString user() const; + + void setPassword( const TQString &password ); + TQString password() const; + + void setRealm( const TQString &realm ); + TQString realm() const; + + void setBindDN( const TQString &binddn ); + TQString bindDN() const; + + void setDn( const TQString &dn ); + TQString dn() const; + + void setHost( const TQString &host ); + TQString host() const; + + void setPort( int port ); + int port() const; + + void setVer( int ver ); + int ver() const; + + void setSizeLimit( int sizelimit ); + int sizeLimit(); + + void setTimeLimit( int timelimit ); + int timeLimit(); + + void setFilter( const TQString &filter ); + TQString filter() const; + + void setIsAnonymous( bool value ); + bool isAnonymous() const; + + void setAttributes( const TQMap &attributes ); + TQMap attributes() const; + + void setRDNPrefix( int value ); + int RDNPrefix() const; + + void setIsTLS( bool value ); + bool isTLS() const ; + + void setIsSSL( bool value ); + bool isSSL() const; + + void setIsSubTree( bool value ); + bool isSubTree() const ; + + void setIsSASL( bool value ); + bool isSASL() const ; + + void setMech( const TQString &mech ); + TQString mech() const; + + void setCachePolicy( int pol ); + int cachePolicy() const; + + void setAutoCache( bool value ); + bool autoCache(); + + TQString cacheDst() const; + +protected slots: + void entries( TDEIO::Job*, const TDEIO::UDSEntryList& ); + void data( TDEIO::Job*, const TQByteArray& ); + void result( TDEIO::Job* ); + void listResult( TDEIO::Job* ); + void syncLoadSaveResult( TDEIO::Job* ); + void saveResult( TDEIO::Job* ); + void saveData( TDEIO::Job*, TQByteArray& ); + void loadCacheResult( TDEIO::Job* ); + + private: + TQString mUser; + TQString mPassword; + TQString mDn; + TQString mHost; + TQString mFilter; + int mPort; + bool mAnonymous; + TQMap mAttributes; + + KURL mLDAPUrl; + int mGetCounter; //KDE 4: remove + bool mErrorOccured; //KDE 4: remove + TQString mErrorMsg; + TQMap mJobMap; //KDE 4: remove + + TDEIO::Job *loadFromCache(); + void createCache(); + void activateCache(); + void enter_loop(); + TQCString addEntry( const TQString &attr, const TQString &value, bool mod ); + TQString findUid( const TQString &uid ); + bool AddresseeToLDIF( TQByteArray &ldif, const Addressee &addr, + const TQString &olddn ); + + class ResourceLDAPTDEIOPrivate; + ResourceLDAPTDEIOPrivate *d; +}; + +} + +#endif diff --git a/kabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp b/kabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp new file mode 100644 index 000000000..a8060c17a --- /dev/null +++ b/kabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp @@ -0,0 +1,388 @@ +/* + This file is part of libkabc. + Copyright (c) 2002 - 2003 Tobias Koenig + + 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "resourceldaptdeio.h" + +#include "resourceldaptdeioconfig.h" +#include "resourceldaptdeioconfig.moc" + +using namespace KABC; + +ResourceLDAPTDEIOConfig::ResourceLDAPTDEIOConfig( TQWidget* parent, const char* name ) + : KRES::ConfigWidget( parent, name ) +{ + TQBoxLayout *mainLayout = new TQVBoxLayout( this ); + mainLayout->setAutoAdd( true ); + cfg = new LdapConfigWidget( LdapConfigWidget::W_ALL, this ); + + mSubTree = new TQCheckBox( i18n( "Sub-tree query" ), this ); + TQHBox *box = new TQHBox( this ); + box->setSpacing( KDialog::spacingHint() ); + mEditButton = new TQPushButton( i18n( "Edit Attributes..." ), box ); + mCacheButton = new TQPushButton( i18n( "Offline Use..." ), box ); + + connect( mEditButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editAttributes() ) ); + connect( mCacheButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editCache() ) ); +} + +void ResourceLDAPTDEIOConfig::loadSettings( KRES::Resource *res ) +{ + ResourceLDAPTDEIO *resource = dynamic_cast( res ); + + if ( !resource ) { + kdDebug(5700) << "ResourceLDAPTDEIOConfig::loadSettings(): cast failed" << endl; + return; + } + + cfg->setUser( resource->user() ); + cfg->setPassword( resource->password() ); + cfg->setRealm( resource->realm() ); + cfg->setBindDN( resource->bindDN() ); + cfg->setHost( resource->host() ); + cfg->setPort( resource->port() ); + cfg->setVer( resource->ver() ); + cfg->setTimeLimit( resource->timeLimit() ); + cfg->setSizeLimit( resource->sizeLimit() ); + cfg->setDn( resource->dn() ); + cfg->setFilter( resource->filter() ); + cfg->setMech( resource->mech() ); + if ( resource->isTLS() ) cfg->setSecTLS(); + else if ( resource->isSSL() ) cfg->setSecSSL(); + else cfg->setSecNO(); + if ( resource->isAnonymous() ) cfg->setAuthAnon(); + else if ( resource->isSASL() ) cfg->setAuthSASL(); + else cfg->setAuthSimple(); + + mSubTree->setChecked( resource->isSubTree() ); + mAttributes = resource->attributes(); + mRDNPrefix = resource->RDNPrefix(); + mCachePolicy = resource->cachePolicy(); + mCacheDst = resource->cacheDst(); + mAutoCache = resource->autoCache(); +} + +void ResourceLDAPTDEIOConfig::saveSettings( KRES::Resource *res ) +{ + ResourceLDAPTDEIO *resource = dynamic_cast( res ); + + if ( !resource ) { + kdDebug(5700) << "ResourceLDAPTDEIOConfig::saveSettings(): cast failed" << endl; + return; + } + + resource->setUser( cfg->user() ); + resource->setPassword( cfg->password() ); + resource->setRealm( cfg->realm() ); + resource->setBindDN( cfg->bindDN() ); + resource->setHost( cfg->host() ); + resource->setPort( cfg->port() ); + resource->setVer( cfg->ver() ); + resource->setTimeLimit( cfg->timeLimit() ); + resource->setSizeLimit( cfg->sizeLimit() ); + resource->setDn( cfg->dn() ); + resource->setFilter( cfg->filter() ); + resource->setIsAnonymous( cfg->isAuthAnon() ); + resource->setIsSASL( cfg->isAuthSASL() ); + resource->setMech( cfg->mech() ); + resource->setIsTLS( cfg->isSecTLS() ); + resource->setIsSSL( cfg->isSecSSL() ); + resource->setIsSubTree( mSubTree->isChecked() ); + resource->setAttributes( mAttributes ); + resource->setRDNPrefix( mRDNPrefix ); + resource->setCachePolicy( mCachePolicy ); + resource->init(); + +} + +void ResourceLDAPTDEIOConfig::editAttributes() +{ + AttributesDialog dlg( mAttributes, mRDNPrefix, this ); + if ( dlg.exec() ) { + mAttributes = dlg.attributes(); + mRDNPrefix = dlg.rdnprefix(); + } +} + +void ResourceLDAPTDEIOConfig::editCache() +{ + LDAPUrl src; + TQStringList attr; + + src = cfg->url(); + src.setScope( mSubTree->isChecked() ? LDAPUrl::Sub : LDAPUrl::One ); + if (!mAttributes.empty()) { + TQMap::Iterator it; + TQStringList attr; + for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { + if ( !it.data().isEmpty() && it.key() != "objectClass" ) + attr.append( it.data() ); + } + src.setAttributes( attr ); + } + src.setExtension( "x-dir", "base" ); + OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this ); + if ( dlg.exec() ) { + mCachePolicy = dlg.cachePolicy(); + mAutoCache = dlg.autoCache(); + } + +} + +AttributesDialog::AttributesDialog( const TQMap &attributes, + int rdnprefix, + TQWidget *parent, const char *name ) + : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel, + Ok, parent, name, true, true ) +{ + mNameDict.setAutoDelete( true ); + mNameDict.insert( "objectClass", new TQString( i18n( "Object classes" ) ) ); + mNameDict.insert( "commonName", new TQString( i18n( "Common name" ) ) ); + mNameDict.insert( "formattedName", new TQString( i18n( "Formatted name" ) ) ); + mNameDict.insert( "familyName", new TQString( i18n( "Family name" ) ) ); + mNameDict.insert( "givenName", new TQString( i18n( "Given name" ) ) ); + mNameDict.insert( "organization", new TQString( i18n( "Organization" ) ) ); + mNameDict.insert( "title", new TQString( i18n( "Title" ) ) ); + mNameDict.insert( "street", new TQString( i18n( "Street" ) ) ); + mNameDict.insert( "state", new TQString( i18n( "State" ) ) ); + mNameDict.insert( "city", new TQString( i18n( "City" ) ) ); + mNameDict.insert( "postalcode", new TQString( i18n( "Postal code" ) ) ); + mNameDict.insert( "mail", new TQString( i18n( "Email" ) ) ); + mNameDict.insert( "mailAlias", new TQString( i18n( "Email alias" ) ) ); + mNameDict.insert( "phoneNumber", new TQString( i18n( "Telephone number" ) ) ); + mNameDict.insert( "telephoneNumber", new TQString( i18n( "Work telephone number" ) ) ); + mNameDict.insert( "facsimileTelephoneNumber", new TQString( i18n( "Fax number" ) ) ); + mNameDict.insert( "mobile", new TQString( i18n( "Cell phone number" ) ) ); + mNameDict.insert( "pager", new TQString( i18n( "Pager" ) ) ); + mNameDict.insert( "description", new TQString( i18n( "Note" ) ) ); + mNameDict.insert( "uid", new TQString( i18n( "UID" ) ) ); + mNameDict.insert( "jpegPhoto", new TQString( i18n( "Photo" ) ) ); + + // default map + mDefaultMap.insert( "objectClass", "inetOrgPerson" ); + mDefaultMap.insert( "commonName", "cn" ); + mDefaultMap.insert( "formattedName", "displayName" ); + mDefaultMap.insert( "familyName", "sn" ); + mDefaultMap.insert( "givenName", "givenName" ); + mDefaultMap.insert( "title", "title" ); + mDefaultMap.insert( "street", "street" ); + mDefaultMap.insert( "state", "st" ); + mDefaultMap.insert( "city", "l" ); + mDefaultMap.insert( "organization", "o" ); + mDefaultMap.insert( "postalcode", "postalCode" ); + mDefaultMap.insert( "mail", "mail" ); + mDefaultMap.insert( "mailAlias", "" ); + mDefaultMap.insert( "phoneNumber", "homePhone" ); + mDefaultMap.insert( "telephoneNumber", "telephoneNumber" ); + mDefaultMap.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" ); + mDefaultMap.insert( "mobile", "mobile" ); + mDefaultMap.insert( "pager", "pager" ); + mDefaultMap.insert( "description", "description" ); + mDefaultMap.insert( "uid", "uid" ); + mDefaultMap.insert( "jpegPhoto", "jpegPhoto" ); + + // overwrite the default values here + TQMap kolabMap, netscapeMap, evolutionMap, outlookMap; + + // kolab + kolabMap.insert( "formattedName", "display-name" ); + kolabMap.insert( "mailAlias", "mailalias" ); + + // evolution + evolutionMap.insert( "formattedName", "fileAs" ); + + mMapList.append( attributes ); + mMapList.append( kolabMap ); + mMapList.append( netscapeMap ); + mMapList.append( evolutionMap ); + mMapList.append( outlookMap ); + + TQFrame *page = plainPage(); + TQGridLayout *layout = new TQGridLayout( page, 4, ( attributes.count() + 4 ) >> 1, + 0, spacingHint() ); + + TQLabel *label = new TQLabel( i18n( "Template:" ), page ); + layout->addWidget( label, 0, 0 ); + mMapCombo = new KComboBox( page ); + layout->addWidget( mMapCombo, 0, 1 ); + + mMapCombo->insertItem( i18n( "User Defined" ) ); + mMapCombo->insertItem( i18n( "Kolab" ) ); + mMapCombo->insertItem( i18n( "Netscape" ) ); + mMapCombo->insertItem( i18n( "Evolution" ) ); + mMapCombo->insertItem( i18n( "Outlook" ) ); + connect( mMapCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( mapChanged( int ) ) ); + + label = new TQLabel( i18n( "RDN prefix attribute:" ), page ); + layout->addWidget( label, 1, 0 ); + mRDNCombo = new KComboBox( page ); + layout->addWidget( mRDNCombo, 1, 1 ); + mRDNCombo->insertItem( i18n( "commonName" ) ); + mRDNCombo->insertItem( i18n( "UID" ) ); + mRDNCombo->setCurrentItem( rdnprefix ); + + TQMap::ConstIterator it; + int i, j = 0; + for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) { + if ( mNameDict[ it.key() ] == 0 ) { + i--; + continue; + } + if ( (uint)(i - 2) == ( mNameDict.count() >> 1 ) ) { + i = 0; + j = 2; + } + kdDebug(7125) << "itkey: " << it.key() << " i: " << i << endl; + label = new TQLabel( *mNameDict[ it.key() ] + ":", page ); + KLineEdit *lineedit = new KLineEdit( page ); + mLineEditDict.insert( it.key(), lineedit ); + lineedit->setText( it.data() ); + label->setBuddy( lineedit ); + layout->addWidget( label, i, j ); + layout->addWidget( lineedit, i, j+1 ); + } + + for ( i = 1; i < mMapCombo->count(); i++ ) { + TQDictIterator it2( mLineEditDict ); + for ( ; it2.current(); ++it2 ) { + if ( mMapList[ i ].contains( it2.currentKey() ) ) { + if ( mMapList[ i ][ it2.currentKey() ] != it2.current()->text() ) break; + } else { + if ( mDefaultMap[ it2.currentKey() ] != it2.current()->text() ) break; + } + } + if ( !it2.current() ) { + mMapCombo->setCurrentItem( i ); + break; + } + } + + KAcceleratorManager::manage( this ); +} + +AttributesDialog::~AttributesDialog() +{ +} + +TQMap AttributesDialog::attributes() const +{ + TQMap map; + + TQDictIterator it( mLineEditDict ); + for ( ; it.current(); ++it ) + map.insert( it.currentKey(), it.current()->text() ); + + return map; +} + +int AttributesDialog::rdnprefix() const +{ + return mRDNCombo->currentItem(); +} + +void AttributesDialog::mapChanged( int pos ) +{ + + // apply first the default and than the spezific changes + TQMap::Iterator it; + for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it ) + mLineEditDict[ it.key() ]->setText( it.data() ); + + for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) { + if ( !it.data().isEmpty() ) { + KLineEdit *le = mLineEditDict[ it.key() ]; + if ( le ) le->setText( it.data() ); + } + } +} + +OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KURL &src, + const TQString &dst, TQWidget *parent, const char *name ) + : KDialogBase( Plain, i18n( "Offline Configuration" ), Ok | Cancel, + Ok, parent, name, true, true ) +{ + TQFrame *page = plainPage(); + TQVBoxLayout *layout = new TQVBoxLayout( page ); + layout->setAutoAdd( true ); + + mSrc = src; mDst = dst; + mCacheGroup = new TQButtonGroup( 1, Qt::Horizontal, + i18n("Offline Cache Policy"), page ); + + TQRadioButton *bt; + new TQRadioButton( i18n("Do not use offline cache"), mCacheGroup ); + bt = new TQRadioButton( i18n("Use local copy if no connection"), mCacheGroup ); + new TQRadioButton( i18n("Always use local copy"), mCacheGroup ); + mCacheGroup->setButton( cachePolicy ); + + mAutoCache = new TQCheckBox( i18n("Refresh offline cache automatically"), + page ); + mAutoCache->setChecked( autoCache ); + mAutoCache->setEnabled( bt->isChecked() ); + + connect( bt, TQT_SIGNAL(toggled(bool)), mAutoCache, TQT_SLOT(setEnabled(bool)) ); + + TQPushButton *lcache = new TQPushButton( i18n("Load into Cache"), page ); + connect( lcache, TQT_SIGNAL( clicked() ), TQT_SLOT( loadCache() ) ); +} + +OfflineDialog::~OfflineDialog() +{ +} + +bool OfflineDialog::autoCache() const +{ + return mAutoCache->isChecked(); +} + +int OfflineDialog::cachePolicy() const +{ + return mCacheGroup->selectedId(); +} + +void OfflineDialog::loadCache() +{ + if ( TDEIO::NetAccess::download( mSrc, mDst, this ) ) { + KMessageBox::information( this, + i18n("Successfully downloaded directory server contents!") ); + } else { + KMessageBox::error( this, + i18n("An error occurred downloading directory server contents into file %1.").arg(mDst) ); + } +} diff --git a/kabc/plugins/ldaptdeio/resourceldaptdeioconfig.h b/kabc/plugins/ldaptdeio/resourceldaptdeioconfig.h new file mode 100644 index 000000000..0fde41d64 --- /dev/null +++ b/kabc/plugins/ldaptdeio/resourceldaptdeioconfig.h @@ -0,0 +1,118 @@ +/* + This file is part of libkabc. + Copyright (c) 2002 - 2003 Tobias Koenig + + 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. +*/ + +#ifndef RESOURCELDAPCONFIG_H +#define RESOURCELDAPCONFIG_H + +#include +#include +#include +#include + +#include +#include +#include +#include + + +class TQCheckBox; +class TQPushButton; +class TQSpinBox; +class TQString; + +class KComboBox; +class KLineEdit; + +namespace KABC { + +class KABC_EXPORT ResourceLDAPTDEIOConfig : public KRES::ConfigWidget +{ + Q_OBJECT + + public: + ResourceLDAPTDEIOConfig( TQWidget* parent = 0, const char* name = 0 ); + + public slots: + void loadSettings( KRES::Resource* ); + void saveSettings( KRES::Resource* ); + + private slots: + void editAttributes(); + void editCache(); + private: + TQPushButton *mEditButton, *mCacheButton; + LdapConfigWidget *cfg; + TQCheckBox *mSubTree; + TQMap mAttributes; + int mRDNPrefix, mCachePolicy; + bool mAutoCache; + TQString mCacheDst; +}; + +class AttributesDialog : public KDialogBase +{ + Q_OBJECT + + public: + AttributesDialog( const TQMap &attributes, int rdnprefix, + TQWidget *parent, const char *name = 0 ); + ~AttributesDialog(); + + TQMap attributes() const; + int rdnprefix() const; + + private slots: + void mapChanged( int pos ); + + private: + enum { UserMap, KolabMap, NetscapeMap, EvolutionMap, OutlookMap }; + + KComboBox *mMapCombo, *mRDNCombo; + TQValueList< TQMap > mMapList; + TQMap mDefaultMap; + TQDict mLineEditDict; + TQDict mNameDict; +}; + +class OfflineDialog : public KDialogBase +{ + Q_OBJECT + + public: + OfflineDialog( bool autoCache, int cachePolicy, const KURL &src, + const TQString &dst, TQWidget *parent, const char *name = 0 ); + ~OfflineDialog(); + + int cachePolicy() const; + bool autoCache() const; + + private slots: + void loadCache(); + + private: + KURL mSrc; + TQString mDst; + TQButtonGroup *mCacheGroup; + TQCheckBox *mAutoCache; +}; + +} + +#endif diff --git a/kabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp b/kabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp new file mode 100644 index 000000000..ac08e8e2b --- /dev/null +++ b/kabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp @@ -0,0 +1,36 @@ +/* + This file is part of libkabc. + Copyright (c) 2003 Tobias Koenig + + 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 "resourceldaptdeio.h" +#include "resourceldaptdeioconfig.h" + +#include +#include + +using namespace KABC; + +extern "C" +{ + KDE_EXPORT void *init_kabc_ldaptdeio() + { + TDEGlobal::locale()->insertCatalogue("kabc_ldaptdeio"); + return new KRES::PluginFactory(); + } +} -- cgit v1.2.1