From da6f54f964c028f12c91450617d72451b1cd8e2c Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 17 Feb 2013 12:20:38 -0600 Subject: Fix FTBFS --- tderesources/slox/CMakeLists.txt | 4 +- tderesources/slox/Makefile.am | 8 +- tderesources/slox/kabcresourceslox.cpp | 684 ------------------------ tderesources/slox/kabcresourceslox.h | 114 ---- tderesources/slox/kabcresourceslox_plugin.cpp | 39 -- tderesources/slox/kabcresourcesloxconfig.cpp | 121 ----- tderesources/slox/kabcresourcesloxconfig.h | 62 --- tderesources/slox/kabcsloxprefs.kcfgc | 11 - tderesources/slox/tdeabcresourceslox.cpp | 684 ++++++++++++++++++++++++ tderesources/slox/tdeabcresourceslox.h | 114 ++++ tderesources/slox/tdeabcresourceslox_plugin.cpp | 39 ++ tderesources/slox/tdeabcresourcesloxconfig.cpp | 121 +++++ tderesources/slox/tdeabcresourcesloxconfig.h | 62 +++ tderesources/slox/tdeabcsloxprefs.kcfgc | 11 + tderesources/slox/webdavhandler.cpp | 2 +- 15 files changed, 1038 insertions(+), 1038 deletions(-) delete mode 100644 tderesources/slox/kabcresourceslox.cpp delete mode 100644 tderesources/slox/kabcresourceslox.h delete mode 100644 tderesources/slox/kabcresourceslox_plugin.cpp delete mode 100644 tderesources/slox/kabcresourcesloxconfig.cpp delete mode 100644 tderesources/slox/kabcresourcesloxconfig.h delete mode 100644 tderesources/slox/kabcsloxprefs.kcfgc create mode 100644 tderesources/slox/tdeabcresourceslox.cpp create mode 100644 tderesources/slox/tdeabcresourceslox.h create mode 100644 tderesources/slox/tdeabcresourceslox_plugin.cpp create mode 100644 tderesources/slox/tdeabcresourcesloxconfig.cpp create mode 100644 tderesources/slox/tdeabcresourcesloxconfig.h create mode 100644 tderesources/slox/tdeabcsloxprefs.kcfgc (limited to 'tderesources/slox') diff --git a/tderesources/slox/CMakeLists.txt b/tderesources/slox/CMakeLists.txt index 47d6dc703..0d932ecb6 100644 --- a/tderesources/slox/CMakeLists.txt +++ b/tderesources/slox/CMakeLists.txt @@ -41,7 +41,7 @@ tde_add_kpart( kcal_slox AUTOMOC ##### tdeabc_slox (module) ######################## tde_add_kpart( tdeabc_slox AUTOMOC - SOURCES kabcresourceslox_plugin.cpp + SOURCES tdeabcresourceslox_plugin.cpp LINK tdeabc_slox-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) @@ -63,7 +63,7 @@ tde_add_library( kslox SHARED AUTOMOC tde_add_library( tdeabc_slox SHARED AUTOMOC SOURCES - kabcresourceslox.cpp kabcresourcesloxconfig.cpp kabcsloxprefs.kcfgc + tdeabcresourceslox.cpp tdeabcresourcesloxconfig.cpp tdeabcsloxprefs.kcfgc VERSION 0.0.0 LINK kslox-shared DESTINATION ${LIB_INSTALL_DIR} diff --git a/tderesources/slox/Makefile.am b/tderesources/slox/Makefile.am index ee8a47f1c..6175de162 100644 --- a/tderesources/slox/Makefile.am +++ b/tderesources/slox/Makefile.am @@ -15,10 +15,10 @@ libkcal_slox_la_SOURCES = kcalresourceslox.cpp kcalresourcesloxconfig.cpp \ libkcal_slox_la_LDFLAGS = $(all_libraries) libkcal_slox_la_LIBADD = libkslox.la $(top_builddir)/libkcal/libkcal.la -libtdeabc_slox_la_SOURCES = kabcresourceslox.cpp kabcresourcesloxconfig.cpp \ - kabcsloxprefs.kcfgc +libtdeabc_slox_la_SOURCES = tdeabcresourceslox.cpp tdeabcresourcesloxconfig.cpp \ + tdeabcsloxprefs.kcfgc libtdeabc_slox_la_LDFLAGS = $(all_libraries) -libtdeabc_slox_la_LIBADD = libkslox.la -lkabc +libtdeabc_slox_la_LIBADD = libkslox.la -ltdeabc kde_module_LTLIBRARIES = kcal_slox.la tdeabc_slox.la @@ -27,7 +27,7 @@ kcal_slox_la_SOURCES = kcalresourceslox_plugin.cpp kcal_slox_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) kcal_slox_la_LIBADD = libkcal_slox.la -tdeabc_slox_la_SOURCES = kabcresourceslox_plugin.cpp +tdeabc_slox_la_SOURCES = tdeabcresourceslox_plugin.cpp tdeabc_slox_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) tdeabc_slox_la_LIBADD = libtdeabc_slox.la diff --git a/tderesources/slox/kabcresourceslox.cpp b/tderesources/slox/kabcresourceslox.cpp deleted file mode 100644 index 17b282969..000000000 --- a/tderesources/slox/kabcresourceslox.cpp +++ /dev/null @@ -1,684 +0,0 @@ -/* - This file is part of tdepim. - - Copyright (c) 2004 Cornelius Schumacher - Copyright (c) 2005 Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; 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 "webdavhandler.h" -#include "sloxaccounts.h" -#include "kabcsloxprefs.h" - -#include "kabcresourceslox.h" - -using namespace KABC; - -ResourceSlox::ResourceSlox( const TDEConfig *config ) - : ResourceCached( config ), SloxBase( this ) -{ - init(); - - mPrefs->addGroupPrefix( identifier() ); - - if ( config ) { - readConfig( config ); - } else { - setResourceName( i18n( "OpenXchange Server" ) ); - } -} - -ResourceSlox::ResourceSlox( const KURL &url, - const TQString &user, const TQString &password ) - : ResourceCached( 0 ), SloxBase( this ) -{ - init(); - - mPrefs->addGroupPrefix( identifier() ); - - mPrefs->setUrl( url.url() ); - mPrefs->setUser( user ); - mPrefs->setPassword( password ); -} - -void ResourceSlox::init() -{ - mPrefs = new SloxPrefs; - mWebdavHandler.setResource( this ); - - mDownloadJob = 0; - mUploadJob = 0; - mDownloadProgress = 0; - mUploadProgress = 0; - - // phone number mapping for SLOX - mPhoneNumberSloxMap[PhoneNumber::Work] << "phone" << "phone2"; - mPhoneNumberSloxMap[PhoneNumber::Home] << "privatephone" << "privatephone2"; - mPhoneNumberSloxMap[PhoneNumber::Cell | PhoneNumber::Work] << "mobile" << "mobile2"; - mPhoneNumberSloxMap[PhoneNumber::Cell | PhoneNumber::Home] << "privatemobile" << "privatemobile2"; - mPhoneNumberSloxMap[PhoneNumber::Fax | PhoneNumber::Work] << "fax" << "fax2"; - mPhoneNumberSloxMap[PhoneNumber::Fax | PhoneNumber::Home] << "privatefax" << "privatefax2"; - - // phone number mapping for OX (mapping partly taken from Kolab) - mPhoneNumberOxMap[PhoneNumber::Work] << "phone_business" << "phone_business2"; - mPhoneNumberOxMap[PhoneNumber::Home] << "phone_home" << "phone_home2"; - mPhoneNumberOxMap[PhoneNumber::Cell] << "mobile1"<< "mobile2"; - mPhoneNumberOxMap[PhoneNumber::Fax | PhoneNumber::Work] << "fax_business"; - mPhoneNumberOxMap[PhoneNumber::Fax | PhoneNumber::Home] << "fax_home"; - mPhoneNumberOxMap[PhoneNumber::Fax] << "fax_other"; - mPhoneNumberOxMap[PhoneNumber::Car] << "phone_car"; - mPhoneNumberOxMap[PhoneNumber::Isdn] << "isdn"; - mPhoneNumberOxMap[PhoneNumber::Pager] << "pager"; - mPhoneNumberOxMap[PhoneNumber::Pref] << "primary"; - mPhoneNumberOxMap[PhoneNumber::Voice] << "callback"; - mPhoneNumberOxMap[PhoneNumber::Video] << "radio"; - mPhoneNumberOxMap[PhoneNumber::Bbs] << "tty_tdd"; - mPhoneNumberOxMap[PhoneNumber::Modem] << "telex"; - mPhoneNumberOxMap[PhoneNumber::Pcs] << "phone_assistant"; - mPhoneNumberOxMap[PhoneNumber::Msg] << "phone_company"; -} - -ResourceSlox::~ResourceSlox() -{ - kdDebug() << "KABC::~ResourceSlox()" << endl; - - if ( mDownloadJob ) mDownloadJob->kill(); - - delete mPrefs; - - kdDebug() << "KABC::~ResourceSlox() done" << endl; -} - -void ResourceSlox::readConfig( const TDEConfig * ) -{ - mPrefs->readConfig(); -} - -void ResourceSlox::writeConfig( TDEConfig *config ) -{ - kdDebug() << "ResourceSlox::writeConfig() " << endl; - kdDebug() << mPrefs->url() << endl; - - Resource::writeConfig( config ); - - mPrefs->writeConfig(); -} - -Ticket *ResourceSlox::requestSaveTicket() -{ - if ( !addressBook() ) { - kdDebug(5700) << "no addressbook" << endl; - return 0; - } - - return createTicket( this ); -} - -void ResourceSlox::releaseSaveTicket( Ticket *ticket ) -{ - delete ticket; -} - -bool ResourceSlox::doOpen() -{ - return true; -} - -void ResourceSlox::doClose() -{ - cancelDownload(); - cancelUpload(); -} - -bool ResourceSlox::load() -{ - kdDebug() << "KABC::ResourceSlox::load()" << endl; - -#if 0 - return asyncLoad(); -#else - kdDebug() << "KABC::ResourceSlox::load() is a nop." << endl; - return true; -#endif -} - -bool ResourceSlox::asyncLoad() -{ - kdDebug() << "KABC::ResourceSlox::asyncLoad()" << endl; - - if ( mDownloadJob ) { - kdDebug() << "KABC::ResourceSlox::asyncLoad(): Loading still in progress." - << endl; - return true; - } - - loadCache(); - clearChanges(); - - KURL url = mPrefs->url(); - url.setPath( "/servlet/webdav.contacts/" ); - url.setUser( mPrefs->user() ); - url.setPass( mPrefs->password() ); - - TQString lastsync = "0"; - if ( mPrefs->useLastSync() ) { - TQDateTime dt = mPrefs->lastSync(); - if ( dt.isValid() ) - lastsync = WebdavHandler::qDateTimeToSlox( dt.addDays( -1 ) ); - } - - TQDomDocument doc; - TQDomElement root = WebdavHandler::addDavElement( doc, doc, "propfind" ); - TQDomElement prop = WebdavHandler::addDavElement( doc, root, "prop" ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( LastSync ), lastsync ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() ); - if ( type() == "ox" ) { - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "NEW_AND_MODIFIED" ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "DELETED" ); - } else - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "all" ); - - kdDebug() << "REQUEST CONTACTS: \n" << doc.toString( 2 ) << endl; - - mDownloadJob = TDEIO::davPropFind( url, doc, "0", false ); - connect( mDownloadJob, TQT_SIGNAL( result( TDEIO::Job * ) ), - TQT_SLOT( slotResult( TDEIO::Job * ) ) ); - connect( mDownloadJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), - TQT_SLOT( slotProgress( TDEIO::Job *, unsigned long ) ) ); - - mDownloadProgress = KPIM::ProgressManager::instance()->createProgressItem( - KPIM::ProgressManager::getUniqueID(), i18n("Downloading contacts") ); - connect( mDownloadProgress, - TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), - TQT_SLOT( cancelDownload() ) ); - - mPrefs->setLastSync( TQDateTime::currentDateTime() ); - - return true; -} - -void ResourceSlox::slotResult( TDEIO::Job *job ) -{ - kdDebug() << "ResourceSlox::slotResult()" << endl; - - if ( job->error() ) { - job->showErrorDialog( 0 ); - } else { - kdDebug() << "ResourceSlox::slotResult() success" << endl; - - TQDomDocument doc = mDownloadJob->response(); - - mWebdavHandler.log( doc.toString( 2 ) ); - - TQValueList items = WebdavHandler::getSloxItems( this, doc ); - - bool changed = false; - - TQValueList::ConstIterator it; - for( it = items.begin(); it != items.end(); ++it ) { - SloxItem item = *it; - TQString uid = "tderesources_slox_tdeabc_" + item.sloxId; - if ( item.status == SloxItem::Delete ) { - TQMap::Iterator it; - it = mAddrMap.find( uid ); - if ( it != mAddrMap.end() ) { - mAddrMap.remove( it ); - changed = true; - } - } else if ( item.status == SloxItem::Create ) { - Addressee a; - a.setUid( uid ); - - mWebdavHandler.clearSloxAttributeStatus(); - - TQDomNode n; - for( n = item.domNode.firstChild(); !n.isNull(); n = n.nextSibling() ) { - TQDomElement e = n.toElement(); - mWebdavHandler.parseSloxAttribute( e ); - parseContactAttribute( e, a ); - } - - mWebdavHandler.setSloxAttributes( a ); - - a.setResource( this ); - a.setChanged( false ); - - mAddrMap.replace( a.uid(), a ); - - // TODO: Do we need to try to associate addressees with slox accounts? - - changed = true; - } - } - - clearChanges(); - saveCache(); - } - - mDownloadJob = 0; - mDownloadProgress->setComplete(); - mDownloadProgress = 0; - - emit loadingFinished( this ); -} - -void ResourceSlox::slotUploadResult( TDEIO::Job *job ) -{ - kdDebug() << "ResourceSlox::slotUploadResult()" << endl; - - if ( job->error() ) { - job->showErrorDialog( 0 ); - } else { - kdDebug() << "ResourceSlox::slotUploadResult() success" << endl; - - TQDomDocument doc = mUploadJob->response(); - kdDebug() << k_funcinfo << "Upload result: " << endl; - kdDebug() << doc.toString() << endl; - - TQValueList items = WebdavHandler::getSloxItems( this, doc ); - - TQValueList::ConstIterator it; - for( it = items.begin(); it != items.end(); ++it ) { - SloxItem item = *it; - if ( !item.response.contains( "200" ) ) { - savingError( this, item.response + "\n" + item.responseDescription ); - continue; - } - if ( item.status == SloxItem::New ) { - TQMap::Iterator search_res; - search_res = mAddrMap.find( item.clientId ); - if ( search_res != mAddrMap.end() ) { - // use the id provided by the server - Addressee a = *search_res; - mAddrMap.remove( search_res ); - a.setUid( "tderesources_slox_tdeabc_" + item.sloxId ); - a.setResource( this ); - a.setChanged( false ); - mAddrMap.replace( a.uid(), a ); - saveCache(); - } - } - } - } - - clearChange( mUploadAddressee ); - - mUploadJob = 0; - mUploadProgress->setComplete(); - mUploadProgress = 0; - - uploadContacts(); -} - -void ResourceSlox::parseContactAttribute( const TQDomElement &e, Addressee &a ) -{ - TQString text = decodeText( e.text() ); - if ( text.isEmpty() ) return; - TQString tag = e.tagName(); - int pnType = 0; - - if ( tag == fieldName( Birthday ) ) { - TQDateTime dt = WebdavHandler::sloxToTQDateTime( text ); - a.setBirthday( dt.date() ); - } else if ( tag == fieldName( Role ) ) { - a.setRole( text ); - } else if ( tag == "salutation" ) { // what's this in OX? - a.setPrefix( text ); - } else if ( tag == fieldName( Title ) ) { - a.setTitle( text ); - } else if ( tag == fieldName( Organization ) ) { - a.setOrganization( text ); - } else if ( tag == fieldName( Department ) ) { -#if KDE_IS_VERSION(3,5,8) - a.setDepartment( text ); -#else - a.insertCustom( "KADDRESSBOOK", "X-Department", text ); -#endif - } else if ( tag == fieldName( FamilyName ) ) { - a.setFamilyName( text ); - } else if ( tag == fieldName( GivenName) ) { - a.setGivenName( text ); - } else if ( tag == fieldName( SecondName ) ) { - a.setAdditionalName( text ); - } else if ( tag == fieldName( DisplayName ) ) { - a.setFormattedName( text ); - } else if ( tag == fieldName( Suffix ) ) { - a.setSuffix( text ); - } else if ( tag == fieldName( PrimaryEmail ) ) { - a.insertEmail( text, true ); - } else if ( (pnType = phoneNumberType( tag )) ) { - a.insertPhoneNumber( PhoneNumber( text, pnType ) ); - } else if ( tag == fieldName( Comment ) ) { - a.setNote( text ); - } else if ( tag == fieldName( SecondaryEmail1 ) || tag == fieldName( SecondaryEmail2 ) || - tag == fieldName( SecondaryEmail3 ) ) { - a.insertEmail( text ); - } else if ( tag == fieldName( Url ) ) { - a.setUrl( text ); - } else if ( tag == fieldName( Image ) ) { - TQByteArray decodedPicture; - KCodecs::base64Decode( text.utf8(), decodedPicture ); - a.setPhoto( Picture( TQImage( decodedPicture ) ) ); - } else if ( tag == fieldName( NickName ) ) { - a.setNickName( text ); - } else if ( tag == fieldName( InstantMsg ) ) { - a.insertCustom( "KADDRESSBOOK", "X-IMAddress", text ); - } else if ( tag == fieldName( Office ) ) { - a.insertCustom( "KADDRESSBOOK", "X-Office", text ); - } else if ( tag == fieldName( Profession ) ) { - a.insertCustom( "KADDRESSBOOK", "X-Profession", text ); - } else if ( tag == fieldName( ManagersName ) ) { - a.insertCustom( "KADDRESSBOOK", "X-ManagersName", text ); - } else if ( tag == fieldName( AssistantsName ) ) { - a.insertCustom( "KADDRESSBOOK", "X-AssistantsName", text ); - } else if ( tag == fieldName( SpousesName ) ) { - a.insertCustom( "KADDRESSBOOK", "X-SpousesName", text ); - } else if ( tag == fieldName( Anniversary ) ) { - TQDateTime dt = WebdavHandler::sloxToTQDateTime( text ); - a.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt.toString( Qt::ISODate ) ); - } else if ( tag == fieldName( Categories ) ) { - a.setCategories( TQStringList::split( TQRegExp(",\\s*"), text ) ); - } else if ( type() == "ox" ) { // FIXME: Address reading is missing for SLOX - // read addresses - Address addr; - if ( tag.startsWith( fieldName( BusinessPrefix ) ) ) { - addr = a.address( KABC::Address::Work ); - } else if ( tag.startsWith( fieldName( OtherPrefix ) ) ) { - addr = a.address( 0 ); - } else { - addr = a.address( KABC::Address::Home ); - } - if ( tag.endsWith( fieldName( Street ) ) ) { - addr.setStreet( text ); - } else if ( tag.endsWith( fieldName( PostalCode ) ) ) { - addr.setPostalCode( text ); - } else if ( tag.endsWith( fieldName( City ) ) ) { - addr.setLocality( text ); - } else if ( tag.endsWith( fieldName( State ) ) ) { - addr.setRegion( text ); - } else if ( tag.endsWith( fieldName( Country ) ) ) { - addr.setCountry( text ); - } - a.insertAddress( addr ); - } -} - -int ResourceSlox::phoneNumberType( const TQString &fieldName ) const -{ - TQMap pnmap; - if ( type() == "ox" ) - pnmap = mPhoneNumberOxMap; - else - pnmap = mPhoneNumberSloxMap; - TQMap::ConstIterator it; - for ( it = pnmap.begin(); it != pnmap.end(); ++it ) { - TQStringList l = it.data(); - TQStringList::ConstIterator it2; - for ( it2 = l.begin(); it2 != l.end(); ++it2 ) - if ( (*it2) == fieldName ) - return it.key(); - } - return 0; -} - -bool ResourceSlox::save( Ticket* ) -{ - kdDebug() << k_funcinfo << endl; - - if ( readOnly() || !hasChanges() || type() != "ox" ) { - emit savingFinished( this ); - return true; - } - - if ( mDownloadJob ) { - kdWarning() << k_funcinfo << "download still in progress" << endl; - return false; - } - if ( mUploadJob ) { - kdWarning() << k_funcinfo << "upload still in progress" << endl; - return false; - } - - saveCache(); - uploadContacts(); - return true; -} - -bool ResourceSlox::asyncSave( Ticket* ) -{ - return false; // readonly -} - -void ResourceSlox::uploadContacts() -{ - TQDomDocument doc; - TQDomElement root = WebdavHandler::addDavElement( doc, doc, "propertyupdate" ); - TQDomElement set = WebdavHandler::addDavElement( doc, root, "set" ); - TQDomElement prop = WebdavHandler::addDavElement( doc, set, "prop" ); - - bool isDelete = false; - - KABC::Addressee::List addedAddr = addedAddressees(); - KABC::Addressee::List changedAddr = changedAddressees(); - KABC::Addressee::List deletedAddr = deletedAddressees(); - - if ( !addedAddr.isEmpty() ) { - mUploadAddressee = addedAddr.first(); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ClientId ), mUploadAddressee.uid() ); - } else if ( !changedAddr.isEmpty() ) { - mUploadAddressee = changedAddr.first(); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), - mUploadAddressee.uid().remove( 0, sizeof("tderesources_slox_tdeabc_") - 1) ); - } else if ( !deletedAddr.isEmpty() ) { - mUploadAddressee = deletedAddr.first(); - isDelete = true; - } else { - kdDebug() << k_funcinfo << "Upload finished." << endl; - emit savingFinished( this ); - return; - } - - if ( !isDelete ) { - createAddresseeFields( doc, prop, mUploadAddressee ); - } else { - TQString tmp_uid = mUploadAddressee.uid().remove( 0, sizeof("tderesources_slox_tdeabc_") - 1); // remove prefix from uid - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), tmp_uid ); - WebdavHandler::addSloxElement( this, doc, prop, "method", "DELETE" ); - } - - kdDebug() << k_funcinfo << doc.toString() << endl; - - KURL url = mPrefs->url(); - url.setPath( "/servlet/webdav.contacts/" ); - url.setUser( mPrefs->user() ); - url.setPass( mPrefs->password() ); - - mUploadJob = TDEIO::davPropPatch( url, doc, false ); - connect( mUploadJob, TQT_SIGNAL( result( TDEIO::Job * ) ), - TQT_SLOT( slotUploadResult( TDEIO::Job * ) ) ); - connect( mUploadJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), - TQT_SLOT( slotProgress( TDEIO::Job *, unsigned long ) ) ); - - mUploadProgress = KPIM::ProgressManager::instance()->createProgressItem( - KPIM::ProgressManager::getUniqueID(), i18n("Uploading contacts") ); - connect( mUploadProgress, - TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), - TQT_SLOT( cancelUpload() ) ); -} - -void ResourceSlox::createAddresseeFields( TQDomDocument &doc, TQDomElement &prop, - const Addressee &a ) -{ - // choose addressbook - WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() ); - - // person - WebdavHandler::addSloxElement( this, doc, prop, fieldName( GivenName ), a.givenName() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( FamilyName ), a.familyName() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Title ), a.title() ); - if ( !a.birthday().isNull() ) - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ), - WebdavHandler::qDateTimeToSlox( a.birthday() ) ); - else - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ) ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Role ), a.role() ); -#if KDE_IS_VERSION(3,5,8) - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Department ), - a.department( ) ); -#else - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Department ), - a.custom( "KADDRESSBOOK", "X-Department" ) ); -#endif - if ( type() == "ox" ) { // OX only fields - WebdavHandler::addSloxElement( this, doc, prop, fieldName( DisplayName ), a.formattedName() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondName ), a.additionalName() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Suffix ), a.suffix() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Organization ), a.organization() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( NickName ), a.nickName() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( InstantMsg ), - a.custom( "KADDRESSBOOK", "X-IMAddress" ) ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Office ), - a.custom( "KADDRESSBOOK", "X-Office" ) ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Profession ), - a.custom( "KADDRESSBOOK", "X-Profession" ) ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( ManagersName ), - a.custom( "KADDRESSBOOK", "X-ManagersName" ) ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( AssistantsName ), - a.custom( "KADDRESSBOOK", "X-AssistantsName" ) ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( SpousesName ), - a.custom( "KADDRESSBOOK", "X-SpousesName" ) ); - TQString anniversary = a.custom( "KADDRESSBOOK", "X-Anniversary" ); - if ( !anniversary.isEmpty() ) - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ), - WebdavHandler::qDateTimeToSlox( TQDateTime::fromString( anniversary, Qt::ISODate ).date() ) ); - else - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ) ); - } - - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Url ), a.url().url() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Comment ), a.note() ); - WebdavHandler::addSloxElement( this, doc, prop, fieldName( Categories ), a.categories().join( ", " ) ); - - // emails - TQStringList email_list = a.emails(); - TQStringList::const_iterator emails_it = email_list.begin(); - if ( emails_it != email_list.end() ) - WebdavHandler::addSloxElement( this, doc, prop, fieldName( PrimaryEmail ), *(emails_it++) ); - if ( emails_it != email_list.end() ) - WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail1 ), *(emails_it++) ); - if ( emails_it != email_list.end() ) - WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail2 ), *(emails_it++) ); - - // phone numbers - PhoneNumber::List pnlist = a.phoneNumbers(); - TQMap pnSaveMap; - if ( type() == "ox" ) - pnSaveMap = mPhoneNumberOxMap; - else - pnSaveMap = mPhoneNumberSloxMap; - for ( PhoneNumber::List::ConstIterator it = pnlist.begin() ; it != pnlist.end(); ++it ) { - if ( pnSaveMap.contains( (*it).type() ) ) { - TQStringList l = pnSaveMap[(*it).type()]; - TQString fn = l.first(); - l.remove( l.begin() ); - if ( !l.isEmpty() ) - pnSaveMap[(*it).type()] = l; - else - pnSaveMap.remove( (*it).type() ); - WebdavHandler::addSloxElement( this, doc, prop, fn, (*it).number() ); - } else - kdDebug() << k_funcinfo << "Can't save phone number " << (*it).number() << " of type " << (*it).type() << endl; - } - // send empty fields for the remaining ohone number fields - // it's not possible to delete phone numbers otherwise - for ( TQMap::ConstIterator it = pnSaveMap.begin(); it != pnSaveMap.end(); ++it ) { - TQStringList l = it.data(); - for ( TQStringList::ConstIterator it2 = l.begin(); it2 != l.end(); ++it2 ) - WebdavHandler::addSloxElement( this, doc, prop, (*it2) ); - } - - // write addresses - createAddressFields( doc, prop, fieldName( HomePrefix ), a.address( KABC::Address::Home ) ); - if ( type() == "ox" ) { - createAddressFields( doc, prop, fieldName( BusinessPrefix ), a.address( KABC::Address::Work ) ); - createAddressFields( doc, prop, fieldName( OtherPrefix ), a.address( 0 ) ); - } -} - -void KABC::ResourceSlox::createAddressFields( TQDomDocument &doc, TQDomElement &parent, - const TQString &prefix, const KABC::Address &addr ) -{ - WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Street ), addr.street() ); - WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( PostalCode ), addr.postalCode() ); - WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( City ), addr.locality() ); - WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( State ), addr.region() ); - WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Country ), addr.country() ); -} - -void ResourceSlox::slotProgress( TDEIO::Job *job, unsigned long percent ) -{ - if ( mDownloadProgress && job == mDownloadJob ) - mDownloadProgress->setProgress( percent ); - else if ( mUploadProgress && job == mUploadJob ) - mUploadProgress->setProgress( percent ); -} - -void ResourceSlox::cancelDownload() -{ - if ( mDownloadJob ) mDownloadJob->kill(); - mDownloadJob = 0; - if ( mDownloadProgress ) mDownloadProgress->setComplete(); - mDownloadProgress = 0; -} - -void ResourceSlox::cancelUpload() -{ - if ( mUploadJob ) mUploadJob->kill(); - mUploadJob = 0; - if ( mUploadProgress ) mUploadProgress->setComplete(); - mUploadProgress = 0; -} - -void ResourceSlox::setReadOnly( bool b ) -{ - if ( type() == "ox" ) - KABC::Resource::setReadOnly( b ); - else - KABC::Resource::setReadOnly( true ); -} - -bool ResourceSlox::readOnly() const -{ - if ( type() == "ox" ) - return KABC::Resource::readOnly(); - else - return true; -} - -#include "kabcresourceslox.moc" diff --git a/tderesources/slox/kabcresourceslox.h b/tderesources/slox/kabcresourceslox.h deleted file mode 100644 index b79167a16..000000000 --- a/tderesources/slox/kabcresourceslox.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - This file is part of tdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -#ifndef KABC_RESOURCESLOX_H -#define KABC_RESOURCESLOX_H - -#include "sloxbase.h" -#include "webdavhandler.h" - -#include -#include -#include - -#include -#include - -namespace TDEIO { -class DavJob; -class Job; -} - -namespace KPIM { -class ProgressItem; -} - -class TDEConfig; - -namespace KABC { - -class SloxPrefs; - -class KDE_EXPORT ResourceSlox : public ResourceCached, public SloxBase -{ - Q_OBJECT - - public: - ResourceSlox( const TDEConfig * ); - ResourceSlox( const KURL &url, - const TQString &user, const TQString &password ); - ~ResourceSlox(); - - void readConfig( const TDEConfig * ); - void writeConfig( TDEConfig * ); - - SloxPrefs *prefs() const { return mPrefs; } - - bool doOpen(); - void doClose(); - - Ticket *requestSaveTicket(); - void releaseSaveTicket( Ticket* ); - - bool load(); - bool asyncLoad(); - bool save( Ticket * ); - bool asyncSave( Ticket * ); - - void setReadOnly( bool ); - bool readOnly() const; - - protected: - void init(); - - int phoneNumberType( const TQString &fieldName ) const; - void parseContactAttribute( const TQDomElement &e, Addressee &a ); - - void createAddresseeFields( TQDomDocument &doc, TQDomElement &prop, const Addressee &a ); - void createAddressFields( TQDomDocument &doc, TQDomElement &parent, - const TQString &prefix, const KABC::Address &addr ); - - void uploadContacts(); - - protected slots: - void slotResult( TDEIO::Job *job ); - void slotUploadResult( TDEIO::Job *job ); - void slotProgress( TDEIO::Job *job, unsigned long percent ); - - void cancelDownload(); - void cancelUpload(); - - private: - SloxPrefs *mPrefs; - - TDEIO::DavJob *mDownloadJob; - TDEIO::DavJob *mUploadJob; - KPIM::ProgressItem *mDownloadProgress; - KPIM::ProgressItem *mUploadProgress; - - WebdavHandler mWebdavHandler; - - KABC::Addressee mUploadAddressee; - - TQMap mPhoneNumberSloxMap, mPhoneNumberOxMap; -}; - -} - -#endif diff --git a/tderesources/slox/kabcresourceslox_plugin.cpp b/tderesources/slox/kabcresourceslox_plugin.cpp deleted file mode 100644 index 93db76b3a..000000000 --- a/tderesources/slox/kabcresourceslox_plugin.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - This file is part of tdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "kabcresourceslox.h" -#include "kabcresourcesloxconfig.h" - -#include -#include - -using namespace KABC; - -typedef KRES::PluginFactory< ResourceSlox, ResourceSloxConfig > SloxFactory; - -extern "C" -{ - void *init_tdeabc_slox() - { - TDEGlobal::locale()->insertCatalogue( "libkcal" ); - TDEGlobal::locale()->insertCatalogue( "tdeabc_slox" ); - return new SloxFactory; - } -} diff --git a/tderesources/slox/kabcresourcesloxconfig.cpp b/tderesources/slox/kabcresourcesloxconfig.cpp deleted file mode 100644 index 72ba39d01..000000000 --- a/tderesources/slox/kabcresourcesloxconfig.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - This file is part of tdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include "kabcresourcesloxconfig.h" - -#include "kabcresourceslox.h" -#include "kabcsloxprefs.h" -#include "sloxbase.h" -#include "sloxfolder.h" -#include "sloxfolderdialog.h" -#include "sloxfoldermanager.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace KABC; - -ResourceSloxConfig::ResourceSloxConfig( TQWidget* parent, const char* name ) - : KRES::ConfigWidget( parent, name ), mRes( 0 ) -{ - TQGridLayout *mainLayout = new TQGridLayout( this, 5, 2, 0, KDialog::spacingHint() ); - - TQLabel *label = new TQLabel( i18n( "URL:" ), this ); - mURL = new KURLRequester( this ); - - mainLayout->addWidget( label, 0, 0 ); - mainLayout->addWidget( mURL, 0, 1 ); - - label = new TQLabel( i18n( "User:" ), this ); - mUser = new KLineEdit( this ); - - mainLayout->addWidget( label, 1, 0 ); - mainLayout->addWidget( mUser, 1, 1 ); - - label = new TQLabel( i18n( "Password:" ), this ); - mPassword = new KLineEdit( this ); - mPassword->setEchoMode( TQLineEdit::Password ); - - mainLayout->addWidget( label, 2, 0 ); - mainLayout->addWidget( mPassword, 2, 1 ); - - mLastSyncCheck = new TQCheckBox( i18n("Only load data since last sync"), - this ); - mainLayout->addMultiCellWidget( mLastSyncCheck, 3, 3, 0, 1 ); - - mFolderButton = new KPushButton( i18n("Select Folder..."), this ); - mainLayout->addMultiCellWidget( mFolderButton, 4, 4, 0, 1 ); - connect( mFolderButton, TQT_SIGNAL( clicked() ), TQT_SLOT( selectAddressFolder() ) ); - -} - -void ResourceSloxConfig::loadSettings( KRES::Resource *res ) -{ - ResourceSlox *resource = dynamic_cast( res ); - mRes = resource; - - if ( !resource ) { - kdDebug(5700) << "ResourceSloxConfig::loadSettings(): cast failed" << endl; - return; - } - - if ( mRes->resType() == "slox" ) - mFolderButton->setEnabled( false ); // TODO folder selection for SLOX - - mURL->setURL( resource->prefs()->url() ); - mUser->setText( resource->prefs()->user() ); - mPassword->setText( resource->prefs()->password() ); - mLastSyncCheck->setChecked( resource->prefs()->useLastSync() ); - mFolderId = resource->prefs()->folderId(); -} - -void ResourceSloxConfig::saveSettings( KRES::Resource *res ) -{ - ResourceSlox *resource = dynamic_cast( res ); - - if ( !resource ) { - kdDebug(5700) << "ResourceSloxConfig::saveSettings(): cast failed" << endl; - return; - } - - resource->prefs()->setUrl( mURL->url() ); - resource->prefs()->setUser( mUser->text() ); - resource->prefs()->setPassword( mPassword->text() ); - resource->prefs()->setUseLastSync( mLastSyncCheck->isChecked() ); - resource->prefs()->setFolderId( mFolderId ); -} - -void KABC::ResourceSloxConfig::selectAddressFolder( ) -{ - SloxFolderManager *manager = new SloxFolderManager( mRes, mURL->url() ); - SloxFolderDialog *dialog = new SloxFolderDialog( manager, Contacts, this ); - dialog->setSelectedFolder( mFolderId ); - if ( dialog->exec() == TQDialog::Accepted ) - mFolderId = dialog->selectedFolder(); -} - -#include "kabcresourcesloxconfig.moc" diff --git a/tderesources/slox/kabcresourcesloxconfig.h b/tderesources/slox/kabcresourcesloxconfig.h deleted file mode 100644 index 9cd54d831..000000000 --- a/tderesources/slox/kabcresourcesloxconfig.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - This file is part of tdepim. - - Copyright (c) 2004 Cornelius Schumacher - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -#ifndef RESOURCESLOXCONFIG_H -#define RESOURCESLOXCONFIG_H - -#include -#include - -class TQCheckBox; -class KLineEdit; -class KURLRequester; -class KPushButton; - -class SloxBase; - -namespace KABC { - -class KDE_EXPORT ResourceSloxConfig : public KRES::ConfigWidget -{ - Q_OBJECT - - - public: - ResourceSloxConfig( TQWidget* parent = 0, const char* name = 0 ); - - public slots: - void loadSettings( KRES::Resource* ); - void saveSettings( KRES::Resource* ); - - private slots: - void selectAddressFolder(); - - private: - KURLRequester *mURL; - KLineEdit *mUser; - KLineEdit *mPassword; - TQCheckBox *mLastSyncCheck; - KPushButton *mFolderButton; - TQString mFolderId; - SloxBase *mRes; -}; - -} - -#endif diff --git a/tderesources/slox/kabcsloxprefs.kcfgc b/tderesources/slox/kabcsloxprefs.kcfgc deleted file mode 100644 index 70c006f52..000000000 --- a/tderesources/slox/kabcsloxprefs.kcfgc +++ /dev/null @@ -1,11 +0,0 @@ -# Code generation options for tdeconfig_compiler -File=tderesources_tdeabc_slox.kcfg -ClassName=SloxPrefs -NameSpace=KABC -Singleton=false -Mutators=true -Inherits=KResourcePrefs -IncludeFiles=libtdepim/kresourceprefs.h -GlobalEnums=true -#ItemAccessors=true -#SetUserTexts=true diff --git a/tderesources/slox/tdeabcresourceslox.cpp b/tderesources/slox/tdeabcresourceslox.cpp new file mode 100644 index 000000000..77fea0b01 --- /dev/null +++ b/tderesources/slox/tdeabcresourceslox.cpp @@ -0,0 +1,684 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher + Copyright (c) 2005 Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; 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 "webdavhandler.h" +#include "sloxaccounts.h" +#include "tdeabcsloxprefs.h" + +#include "tdeabcresourceslox.h" + +using namespace KABC; + +ResourceSlox::ResourceSlox( const TDEConfig *config ) + : ResourceCached( config ), SloxBase( this ) +{ + init(); + + mPrefs->addGroupPrefix( identifier() ); + + if ( config ) { + readConfig( config ); + } else { + setResourceName( i18n( "OpenXchange Server" ) ); + } +} + +ResourceSlox::ResourceSlox( const KURL &url, + const TQString &user, const TQString &password ) + : ResourceCached( 0 ), SloxBase( this ) +{ + init(); + + mPrefs->addGroupPrefix( identifier() ); + + mPrefs->setUrl( url.url() ); + mPrefs->setUser( user ); + mPrefs->setPassword( password ); +} + +void ResourceSlox::init() +{ + mPrefs = new SloxPrefs; + mWebdavHandler.setResource( this ); + + mDownloadJob = 0; + mUploadJob = 0; + mDownloadProgress = 0; + mUploadProgress = 0; + + // phone number mapping for SLOX + mPhoneNumberSloxMap[PhoneNumber::Work] << "phone" << "phone2"; + mPhoneNumberSloxMap[PhoneNumber::Home] << "privatephone" << "privatephone2"; + mPhoneNumberSloxMap[PhoneNumber::Cell | PhoneNumber::Work] << "mobile" << "mobile2"; + mPhoneNumberSloxMap[PhoneNumber::Cell | PhoneNumber::Home] << "privatemobile" << "privatemobile2"; + mPhoneNumberSloxMap[PhoneNumber::Fax | PhoneNumber::Work] << "fax" << "fax2"; + mPhoneNumberSloxMap[PhoneNumber::Fax | PhoneNumber::Home] << "privatefax" << "privatefax2"; + + // phone number mapping for OX (mapping partly taken from Kolab) + mPhoneNumberOxMap[PhoneNumber::Work] << "phone_business" << "phone_business2"; + mPhoneNumberOxMap[PhoneNumber::Home] << "phone_home" << "phone_home2"; + mPhoneNumberOxMap[PhoneNumber::Cell] << "mobile1"<< "mobile2"; + mPhoneNumberOxMap[PhoneNumber::Fax | PhoneNumber::Work] << "fax_business"; + mPhoneNumberOxMap[PhoneNumber::Fax | PhoneNumber::Home] << "fax_home"; + mPhoneNumberOxMap[PhoneNumber::Fax] << "fax_other"; + mPhoneNumberOxMap[PhoneNumber::Car] << "phone_car"; + mPhoneNumberOxMap[PhoneNumber::Isdn] << "isdn"; + mPhoneNumberOxMap[PhoneNumber::Pager] << "pager"; + mPhoneNumberOxMap[PhoneNumber::Pref] << "primary"; + mPhoneNumberOxMap[PhoneNumber::Voice] << "callback"; + mPhoneNumberOxMap[PhoneNumber::Video] << "radio"; + mPhoneNumberOxMap[PhoneNumber::Bbs] << "tty_tdd"; + mPhoneNumberOxMap[PhoneNumber::Modem] << "telex"; + mPhoneNumberOxMap[PhoneNumber::Pcs] << "phone_assistant"; + mPhoneNumberOxMap[PhoneNumber::Msg] << "phone_company"; +} + +ResourceSlox::~ResourceSlox() +{ + kdDebug() << "KABC::~ResourceSlox()" << endl; + + if ( mDownloadJob ) mDownloadJob->kill(); + + delete mPrefs; + + kdDebug() << "KABC::~ResourceSlox() done" << endl; +} + +void ResourceSlox::readConfig( const TDEConfig * ) +{ + mPrefs->readConfig(); +} + +void ResourceSlox::writeConfig( TDEConfig *config ) +{ + kdDebug() << "ResourceSlox::writeConfig() " << endl; + kdDebug() << mPrefs->url() << endl; + + Resource::writeConfig( config ); + + mPrefs->writeConfig(); +} + +Ticket *ResourceSlox::requestSaveTicket() +{ + if ( !addressBook() ) { + kdDebug(5700) << "no addressbook" << endl; + return 0; + } + + return createTicket( this ); +} + +void ResourceSlox::releaseSaveTicket( Ticket *ticket ) +{ + delete ticket; +} + +bool ResourceSlox::doOpen() +{ + return true; +} + +void ResourceSlox::doClose() +{ + cancelDownload(); + cancelUpload(); +} + +bool ResourceSlox::load() +{ + kdDebug() << "KABC::ResourceSlox::load()" << endl; + +#if 0 + return asyncLoad(); +#else + kdDebug() << "KABC::ResourceSlox::load() is a nop." << endl; + return true; +#endif +} + +bool ResourceSlox::asyncLoad() +{ + kdDebug() << "KABC::ResourceSlox::asyncLoad()" << endl; + + if ( mDownloadJob ) { + kdDebug() << "KABC::ResourceSlox::asyncLoad(): Loading still in progress." + << endl; + return true; + } + + loadCache(); + clearChanges(); + + KURL url = mPrefs->url(); + url.setPath( "/servlet/webdav.contacts/" ); + url.setUser( mPrefs->user() ); + url.setPass( mPrefs->password() ); + + TQString lastsync = "0"; + if ( mPrefs->useLastSync() ) { + TQDateTime dt = mPrefs->lastSync(); + if ( dt.isValid() ) + lastsync = WebdavHandler::qDateTimeToSlox( dt.addDays( -1 ) ); + } + + TQDomDocument doc; + TQDomElement root = WebdavHandler::addDavElement( doc, doc, "propfind" ); + TQDomElement prop = WebdavHandler::addDavElement( doc, root, "prop" ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( LastSync ), lastsync ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() ); + if ( type() == "ox" ) { + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "NEW_AND_MODIFIED" ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "DELETED" ); + } else + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "all" ); + + kdDebug() << "REQUEST CONTACTS: \n" << doc.toString( 2 ) << endl; + + mDownloadJob = TDEIO::davPropFind( url, doc, "0", false ); + connect( mDownloadJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotResult( TDEIO::Job * ) ) ); + connect( mDownloadJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), + TQT_SLOT( slotProgress( TDEIO::Job *, unsigned long ) ) ); + + mDownloadProgress = KPIM::ProgressManager::instance()->createProgressItem( + KPIM::ProgressManager::getUniqueID(), i18n("Downloading contacts") ); + connect( mDownloadProgress, + TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), + TQT_SLOT( cancelDownload() ) ); + + mPrefs->setLastSync( TQDateTime::currentDateTime() ); + + return true; +} + +void ResourceSlox::slotResult( TDEIO::Job *job ) +{ + kdDebug() << "ResourceSlox::slotResult()" << endl; + + if ( job->error() ) { + job->showErrorDialog( 0 ); + } else { + kdDebug() << "ResourceSlox::slotResult() success" << endl; + + TQDomDocument doc = mDownloadJob->response(); + + mWebdavHandler.log( doc.toString( 2 ) ); + + TQValueList items = WebdavHandler::getSloxItems( this, doc ); + + bool changed = false; + + TQValueList::ConstIterator it; + for( it = items.begin(); it != items.end(); ++it ) { + SloxItem item = *it; + TQString uid = "tderesources_slox_tdeabc_" + item.sloxId; + if ( item.status == SloxItem::Delete ) { + TQMap::Iterator it; + it = mAddrMap.find( uid ); + if ( it != mAddrMap.end() ) { + mAddrMap.remove( it ); + changed = true; + } + } else if ( item.status == SloxItem::Create ) { + Addressee a; + a.setUid( uid ); + + mWebdavHandler.clearSloxAttributeStatus(); + + TQDomNode n; + for( n = item.domNode.firstChild(); !n.isNull(); n = n.nextSibling() ) { + TQDomElement e = n.toElement(); + mWebdavHandler.parseSloxAttribute( e ); + parseContactAttribute( e, a ); + } + + mWebdavHandler.setSloxAttributes( a ); + + a.setResource( this ); + a.setChanged( false ); + + mAddrMap.replace( a.uid(), a ); + + // TODO: Do we need to try to associate addressees with slox accounts? + + changed = true; + } + } + + clearChanges(); + saveCache(); + } + + mDownloadJob = 0; + mDownloadProgress->setComplete(); + mDownloadProgress = 0; + + emit loadingFinished( this ); +} + +void ResourceSlox::slotUploadResult( TDEIO::Job *job ) +{ + kdDebug() << "ResourceSlox::slotUploadResult()" << endl; + + if ( job->error() ) { + job->showErrorDialog( 0 ); + } else { + kdDebug() << "ResourceSlox::slotUploadResult() success" << endl; + + TQDomDocument doc = mUploadJob->response(); + kdDebug() << k_funcinfo << "Upload result: " << endl; + kdDebug() << doc.toString() << endl; + + TQValueList items = WebdavHandler::getSloxItems( this, doc ); + + TQValueList::ConstIterator it; + for( it = items.begin(); it != items.end(); ++it ) { + SloxItem item = *it; + if ( !item.response.contains( "200" ) ) { + savingError( this, item.response + "\n" + item.responseDescription ); + continue; + } + if ( item.status == SloxItem::New ) { + TQMap::Iterator search_res; + search_res = mAddrMap.find( item.clientId ); + if ( search_res != mAddrMap.end() ) { + // use the id provided by the server + Addressee a = *search_res; + mAddrMap.remove( search_res ); + a.setUid( "tderesources_slox_tdeabc_" + item.sloxId ); + a.setResource( this ); + a.setChanged( false ); + mAddrMap.replace( a.uid(), a ); + saveCache(); + } + } + } + } + + clearChange( mUploadAddressee ); + + mUploadJob = 0; + mUploadProgress->setComplete(); + mUploadProgress = 0; + + uploadContacts(); +} + +void ResourceSlox::parseContactAttribute( const TQDomElement &e, Addressee &a ) +{ + TQString text = decodeText( e.text() ); + if ( text.isEmpty() ) return; + TQString tag = e.tagName(); + int pnType = 0; + + if ( tag == fieldName( Birthday ) ) { + TQDateTime dt = WebdavHandler::sloxToTQDateTime( text ); + a.setBirthday( dt.date() ); + } else if ( tag == fieldName( Role ) ) { + a.setRole( text ); + } else if ( tag == "salutation" ) { // what's this in OX? + a.setPrefix( text ); + } else if ( tag == fieldName( Title ) ) { + a.setTitle( text ); + } else if ( tag == fieldName( Organization ) ) { + a.setOrganization( text ); + } else if ( tag == fieldName( Department ) ) { +#if KDE_IS_VERSION(3,5,8) + a.setDepartment( text ); +#else + a.insertCustom( "KADDRESSBOOK", "X-Department", text ); +#endif + } else if ( tag == fieldName( FamilyName ) ) { + a.setFamilyName( text ); + } else if ( tag == fieldName( GivenName) ) { + a.setGivenName( text ); + } else if ( tag == fieldName( SecondName ) ) { + a.setAdditionalName( text ); + } else if ( tag == fieldName( DisplayName ) ) { + a.setFormattedName( text ); + } else if ( tag == fieldName( Suffix ) ) { + a.setSuffix( text ); + } else if ( tag == fieldName( PrimaryEmail ) ) { + a.insertEmail( text, true ); + } else if ( (pnType = phoneNumberType( tag )) ) { + a.insertPhoneNumber( PhoneNumber( text, pnType ) ); + } else if ( tag == fieldName( Comment ) ) { + a.setNote( text ); + } else if ( tag == fieldName( SecondaryEmail1 ) || tag == fieldName( SecondaryEmail2 ) || + tag == fieldName( SecondaryEmail3 ) ) { + a.insertEmail( text ); + } else if ( tag == fieldName( Url ) ) { + a.setUrl( text ); + } else if ( tag == fieldName( Image ) ) { + TQByteArray decodedPicture; + KCodecs::base64Decode( text.utf8(), decodedPicture ); + a.setPhoto( Picture( TQImage( decodedPicture ) ) ); + } else if ( tag == fieldName( NickName ) ) { + a.setNickName( text ); + } else if ( tag == fieldName( InstantMsg ) ) { + a.insertCustom( "KADDRESSBOOK", "X-IMAddress", text ); + } else if ( tag == fieldName( Office ) ) { + a.insertCustom( "KADDRESSBOOK", "X-Office", text ); + } else if ( tag == fieldName( Profession ) ) { + a.insertCustom( "KADDRESSBOOK", "X-Profession", text ); + } else if ( tag == fieldName( ManagersName ) ) { + a.insertCustom( "KADDRESSBOOK", "X-ManagersName", text ); + } else if ( tag == fieldName( AssistantsName ) ) { + a.insertCustom( "KADDRESSBOOK", "X-AssistantsName", text ); + } else if ( tag == fieldName( SpousesName ) ) { + a.insertCustom( "KADDRESSBOOK", "X-SpousesName", text ); + } else if ( tag == fieldName( Anniversary ) ) { + TQDateTime dt = WebdavHandler::sloxToTQDateTime( text ); + a.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt.toString( Qt::ISODate ) ); + } else if ( tag == fieldName( Categories ) ) { + a.setCategories( TQStringList::split( TQRegExp(",\\s*"), text ) ); + } else if ( type() == "ox" ) { // FIXME: Address reading is missing for SLOX + // read addresses + Address addr; + if ( tag.startsWith( fieldName( BusinessPrefix ) ) ) { + addr = a.address( KABC::Address::Work ); + } else if ( tag.startsWith( fieldName( OtherPrefix ) ) ) { + addr = a.address( 0 ); + } else { + addr = a.address( KABC::Address::Home ); + } + if ( tag.endsWith( fieldName( Street ) ) ) { + addr.setStreet( text ); + } else if ( tag.endsWith( fieldName( PostalCode ) ) ) { + addr.setPostalCode( text ); + } else if ( tag.endsWith( fieldName( City ) ) ) { + addr.setLocality( text ); + } else if ( tag.endsWith( fieldName( State ) ) ) { + addr.setRegion( text ); + } else if ( tag.endsWith( fieldName( Country ) ) ) { + addr.setCountry( text ); + } + a.insertAddress( addr ); + } +} + +int ResourceSlox::phoneNumberType( const TQString &fieldName ) const +{ + TQMap pnmap; + if ( type() == "ox" ) + pnmap = mPhoneNumberOxMap; + else + pnmap = mPhoneNumberSloxMap; + TQMap::ConstIterator it; + for ( it = pnmap.begin(); it != pnmap.end(); ++it ) { + TQStringList l = it.data(); + TQStringList::ConstIterator it2; + for ( it2 = l.begin(); it2 != l.end(); ++it2 ) + if ( (*it2) == fieldName ) + return it.key(); + } + return 0; +} + +bool ResourceSlox::save( Ticket* ) +{ + kdDebug() << k_funcinfo << endl; + + if ( readOnly() || !hasChanges() || type() != "ox" ) { + emit savingFinished( this ); + return true; + } + + if ( mDownloadJob ) { + kdWarning() << k_funcinfo << "download still in progress" << endl; + return false; + } + if ( mUploadJob ) { + kdWarning() << k_funcinfo << "upload still in progress" << endl; + return false; + } + + saveCache(); + uploadContacts(); + return true; +} + +bool ResourceSlox::asyncSave( Ticket* ) +{ + return false; // readonly +} + +void ResourceSlox::uploadContacts() +{ + TQDomDocument doc; + TQDomElement root = WebdavHandler::addDavElement( doc, doc, "propertyupdate" ); + TQDomElement set = WebdavHandler::addDavElement( doc, root, "set" ); + TQDomElement prop = WebdavHandler::addDavElement( doc, set, "prop" ); + + bool isDelete = false; + + KABC::Addressee::List addedAddr = addedAddressees(); + KABC::Addressee::List changedAddr = changedAddressees(); + KABC::Addressee::List deletedAddr = deletedAddressees(); + + if ( !addedAddr.isEmpty() ) { + mUploadAddressee = addedAddr.first(); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ClientId ), mUploadAddressee.uid() ); + } else if ( !changedAddr.isEmpty() ) { + mUploadAddressee = changedAddr.first(); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), + mUploadAddressee.uid().remove( 0, sizeof("tderesources_slox_tdeabc_") - 1) ); + } else if ( !deletedAddr.isEmpty() ) { + mUploadAddressee = deletedAddr.first(); + isDelete = true; + } else { + kdDebug() << k_funcinfo << "Upload finished." << endl; + emit savingFinished( this ); + return; + } + + if ( !isDelete ) { + createAddresseeFields( doc, prop, mUploadAddressee ); + } else { + TQString tmp_uid = mUploadAddressee.uid().remove( 0, sizeof("tderesources_slox_tdeabc_") - 1); // remove prefix from uid + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), tmp_uid ); + WebdavHandler::addSloxElement( this, doc, prop, "method", "DELETE" ); + } + + kdDebug() << k_funcinfo << doc.toString() << endl; + + KURL url = mPrefs->url(); + url.setPath( "/servlet/webdav.contacts/" ); + url.setUser( mPrefs->user() ); + url.setPass( mPrefs->password() ); + + mUploadJob = TDEIO::davPropPatch( url, doc, false ); + connect( mUploadJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( slotUploadResult( TDEIO::Job * ) ) ); + connect( mUploadJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), + TQT_SLOT( slotProgress( TDEIO::Job *, unsigned long ) ) ); + + mUploadProgress = KPIM::ProgressManager::instance()->createProgressItem( + KPIM::ProgressManager::getUniqueID(), i18n("Uploading contacts") ); + connect( mUploadProgress, + TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), + TQT_SLOT( cancelUpload() ) ); +} + +void ResourceSlox::createAddresseeFields( TQDomDocument &doc, TQDomElement &prop, + const Addressee &a ) +{ + // choose addressbook + WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() ); + + // person + WebdavHandler::addSloxElement( this, doc, prop, fieldName( GivenName ), a.givenName() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( FamilyName ), a.familyName() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Title ), a.title() ); + if ( !a.birthday().isNull() ) + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ), + WebdavHandler::qDateTimeToSlox( a.birthday() ) ); + else + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ) ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Role ), a.role() ); +#if KDE_IS_VERSION(3,5,8) + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Department ), + a.department( ) ); +#else + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Department ), + a.custom( "KADDRESSBOOK", "X-Department" ) ); +#endif + if ( type() == "ox" ) { // OX only fields + WebdavHandler::addSloxElement( this, doc, prop, fieldName( DisplayName ), a.formattedName() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondName ), a.additionalName() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Suffix ), a.suffix() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Organization ), a.organization() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( NickName ), a.nickName() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( InstantMsg ), + a.custom( "KADDRESSBOOK", "X-IMAddress" ) ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Office ), + a.custom( "KADDRESSBOOK", "X-Office" ) ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Profession ), + a.custom( "KADDRESSBOOK", "X-Profession" ) ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( ManagersName ), + a.custom( "KADDRESSBOOK", "X-ManagersName" ) ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( AssistantsName ), + a.custom( "KADDRESSBOOK", "X-AssistantsName" ) ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( SpousesName ), + a.custom( "KADDRESSBOOK", "X-SpousesName" ) ); + TQString anniversary = a.custom( "KADDRESSBOOK", "X-Anniversary" ); + if ( !anniversary.isEmpty() ) + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ), + WebdavHandler::qDateTimeToSlox( TQDateTime::fromString( anniversary, Qt::ISODate ).date() ) ); + else + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ) ); + } + + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Url ), a.url().url() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Comment ), a.note() ); + WebdavHandler::addSloxElement( this, doc, prop, fieldName( Categories ), a.categories().join( ", " ) ); + + // emails + TQStringList email_list = a.emails(); + TQStringList::const_iterator emails_it = email_list.begin(); + if ( emails_it != email_list.end() ) + WebdavHandler::addSloxElement( this, doc, prop, fieldName( PrimaryEmail ), *(emails_it++) ); + if ( emails_it != email_list.end() ) + WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail1 ), *(emails_it++) ); + if ( emails_it != email_list.end() ) + WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail2 ), *(emails_it++) ); + + // phone numbers + PhoneNumber::List pnlist = a.phoneNumbers(); + TQMap pnSaveMap; + if ( type() == "ox" ) + pnSaveMap = mPhoneNumberOxMap; + else + pnSaveMap = mPhoneNumberSloxMap; + for ( PhoneNumber::List::ConstIterator it = pnlist.begin() ; it != pnlist.end(); ++it ) { + if ( pnSaveMap.contains( (*it).type() ) ) { + TQStringList l = pnSaveMap[(*it).type()]; + TQString fn = l.first(); + l.remove( l.begin() ); + if ( !l.isEmpty() ) + pnSaveMap[(*it).type()] = l; + else + pnSaveMap.remove( (*it).type() ); + WebdavHandler::addSloxElement( this, doc, prop, fn, (*it).number() ); + } else + kdDebug() << k_funcinfo << "Can't save phone number " << (*it).number() << " of type " << (*it).type() << endl; + } + // send empty fields for the remaining ohone number fields + // it's not possible to delete phone numbers otherwise + for ( TQMap::ConstIterator it = pnSaveMap.begin(); it != pnSaveMap.end(); ++it ) { + TQStringList l = it.data(); + for ( TQStringList::ConstIterator it2 = l.begin(); it2 != l.end(); ++it2 ) + WebdavHandler::addSloxElement( this, doc, prop, (*it2) ); + } + + // write addresses + createAddressFields( doc, prop, fieldName( HomePrefix ), a.address( KABC::Address::Home ) ); + if ( type() == "ox" ) { + createAddressFields( doc, prop, fieldName( BusinessPrefix ), a.address( KABC::Address::Work ) ); + createAddressFields( doc, prop, fieldName( OtherPrefix ), a.address( 0 ) ); + } +} + +void KABC::ResourceSlox::createAddressFields( TQDomDocument &doc, TQDomElement &parent, + const TQString &prefix, const KABC::Address &addr ) +{ + WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Street ), addr.street() ); + WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( PostalCode ), addr.postalCode() ); + WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( City ), addr.locality() ); + WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( State ), addr.region() ); + WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Country ), addr.country() ); +} + +void ResourceSlox::slotProgress( TDEIO::Job *job, unsigned long percent ) +{ + if ( mDownloadProgress && job == mDownloadJob ) + mDownloadProgress->setProgress( percent ); + else if ( mUploadProgress && job == mUploadJob ) + mUploadProgress->setProgress( percent ); +} + +void ResourceSlox::cancelDownload() +{ + if ( mDownloadJob ) mDownloadJob->kill(); + mDownloadJob = 0; + if ( mDownloadProgress ) mDownloadProgress->setComplete(); + mDownloadProgress = 0; +} + +void ResourceSlox::cancelUpload() +{ + if ( mUploadJob ) mUploadJob->kill(); + mUploadJob = 0; + if ( mUploadProgress ) mUploadProgress->setComplete(); + mUploadProgress = 0; +} + +void ResourceSlox::setReadOnly( bool b ) +{ + if ( type() == "ox" ) + KABC::Resource::setReadOnly( b ); + else + KABC::Resource::setReadOnly( true ); +} + +bool ResourceSlox::readOnly() const +{ + if ( type() == "ox" ) + return KABC::Resource::readOnly(); + else + return true; +} + +#include "tdeabcresourceslox.moc" diff --git a/tderesources/slox/tdeabcresourceslox.h b/tderesources/slox/tdeabcresourceslox.h new file mode 100644 index 000000000..b79167a16 --- /dev/null +++ b/tderesources/slox/tdeabcresourceslox.h @@ -0,0 +1,114 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef KABC_RESOURCESLOX_H +#define KABC_RESOURCESLOX_H + +#include "sloxbase.h" +#include "webdavhandler.h" + +#include +#include +#include + +#include +#include + +namespace TDEIO { +class DavJob; +class Job; +} + +namespace KPIM { +class ProgressItem; +} + +class TDEConfig; + +namespace KABC { + +class SloxPrefs; + +class KDE_EXPORT ResourceSlox : public ResourceCached, public SloxBase +{ + Q_OBJECT + + public: + ResourceSlox( const TDEConfig * ); + ResourceSlox( const KURL &url, + const TQString &user, const TQString &password ); + ~ResourceSlox(); + + void readConfig( const TDEConfig * ); + void writeConfig( TDEConfig * ); + + SloxPrefs *prefs() const { return mPrefs; } + + bool doOpen(); + void doClose(); + + Ticket *requestSaveTicket(); + void releaseSaveTicket( Ticket* ); + + bool load(); + bool asyncLoad(); + bool save( Ticket * ); + bool asyncSave( Ticket * ); + + void setReadOnly( bool ); + bool readOnly() const; + + protected: + void init(); + + int phoneNumberType( const TQString &fieldName ) const; + void parseContactAttribute( const TQDomElement &e, Addressee &a ); + + void createAddresseeFields( TQDomDocument &doc, TQDomElement &prop, const Addressee &a ); + void createAddressFields( TQDomDocument &doc, TQDomElement &parent, + const TQString &prefix, const KABC::Address &addr ); + + void uploadContacts(); + + protected slots: + void slotResult( TDEIO::Job *job ); + void slotUploadResult( TDEIO::Job *job ); + void slotProgress( TDEIO::Job *job, unsigned long percent ); + + void cancelDownload(); + void cancelUpload(); + + private: + SloxPrefs *mPrefs; + + TDEIO::DavJob *mDownloadJob; + TDEIO::DavJob *mUploadJob; + KPIM::ProgressItem *mDownloadProgress; + KPIM::ProgressItem *mUploadProgress; + + WebdavHandler mWebdavHandler; + + KABC::Addressee mUploadAddressee; + + TQMap mPhoneNumberSloxMap, mPhoneNumberOxMap; +}; + +} + +#endif diff --git a/tderesources/slox/tdeabcresourceslox_plugin.cpp b/tderesources/slox/tdeabcresourceslox_plugin.cpp new file mode 100644 index 000000000..b876c8597 --- /dev/null +++ b/tderesources/slox/tdeabcresourceslox_plugin.cpp @@ -0,0 +1,39 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "tdeabcresourceslox.h" +#include "tdeabcresourcesloxconfig.h" + +#include +#include + +using namespace KABC; + +typedef KRES::PluginFactory< ResourceSlox, ResourceSloxConfig > SloxFactory; + +extern "C" +{ + void *init_tdeabc_slox() + { + TDEGlobal::locale()->insertCatalogue( "libkcal" ); + TDEGlobal::locale()->insertCatalogue( "tdeabc_slox" ); + return new SloxFactory; + } +} diff --git a/tderesources/slox/tdeabcresourcesloxconfig.cpp b/tderesources/slox/tdeabcresourcesloxconfig.cpp new file mode 100644 index 000000000..919d156ae --- /dev/null +++ b/tderesources/slox/tdeabcresourcesloxconfig.cpp @@ -0,0 +1,121 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "tdeabcresourcesloxconfig.h" + +#include "tdeabcresourceslox.h" +#include "tdeabcsloxprefs.h" +#include "sloxbase.h" +#include "sloxfolder.h" +#include "sloxfolderdialog.h" +#include "sloxfoldermanager.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +using namespace KABC; + +ResourceSloxConfig::ResourceSloxConfig( TQWidget* parent, const char* name ) + : KRES::ConfigWidget( parent, name ), mRes( 0 ) +{ + TQGridLayout *mainLayout = new TQGridLayout( this, 5, 2, 0, KDialog::spacingHint() ); + + TQLabel *label = new TQLabel( i18n( "URL:" ), this ); + mURL = new KURLRequester( this ); + + mainLayout->addWidget( label, 0, 0 ); + mainLayout->addWidget( mURL, 0, 1 ); + + label = new TQLabel( i18n( "User:" ), this ); + mUser = new KLineEdit( this ); + + mainLayout->addWidget( label, 1, 0 ); + mainLayout->addWidget( mUser, 1, 1 ); + + label = new TQLabel( i18n( "Password:" ), this ); + mPassword = new KLineEdit( this ); + mPassword->setEchoMode( TQLineEdit::Password ); + + mainLayout->addWidget( label, 2, 0 ); + mainLayout->addWidget( mPassword, 2, 1 ); + + mLastSyncCheck = new TQCheckBox( i18n("Only load data since last sync"), + this ); + mainLayout->addMultiCellWidget( mLastSyncCheck, 3, 3, 0, 1 ); + + mFolderButton = new KPushButton( i18n("Select Folder..."), this ); + mainLayout->addMultiCellWidget( mFolderButton, 4, 4, 0, 1 ); + connect( mFolderButton, TQT_SIGNAL( clicked() ), TQT_SLOT( selectAddressFolder() ) ); + +} + +void ResourceSloxConfig::loadSettings( KRES::Resource *res ) +{ + ResourceSlox *resource = dynamic_cast( res ); + mRes = resource; + + if ( !resource ) { + kdDebug(5700) << "ResourceSloxConfig::loadSettings(): cast failed" << endl; + return; + } + + if ( mRes->resType() == "slox" ) + mFolderButton->setEnabled( false ); // TODO folder selection for SLOX + + mURL->setURL( resource->prefs()->url() ); + mUser->setText( resource->prefs()->user() ); + mPassword->setText( resource->prefs()->password() ); + mLastSyncCheck->setChecked( resource->prefs()->useLastSync() ); + mFolderId = resource->prefs()->folderId(); +} + +void ResourceSloxConfig::saveSettings( KRES::Resource *res ) +{ + ResourceSlox *resource = dynamic_cast( res ); + + if ( !resource ) { + kdDebug(5700) << "ResourceSloxConfig::saveSettings(): cast failed" << endl; + return; + } + + resource->prefs()->setUrl( mURL->url() ); + resource->prefs()->setUser( mUser->text() ); + resource->prefs()->setPassword( mPassword->text() ); + resource->prefs()->setUseLastSync( mLastSyncCheck->isChecked() ); + resource->prefs()->setFolderId( mFolderId ); +} + +void KABC::ResourceSloxConfig::selectAddressFolder( ) +{ + SloxFolderManager *manager = new SloxFolderManager( mRes, mURL->url() ); + SloxFolderDialog *dialog = new SloxFolderDialog( manager, Contacts, this ); + dialog->setSelectedFolder( mFolderId ); + if ( dialog->exec() == TQDialog::Accepted ) + mFolderId = dialog->selectedFolder(); +} + +#include "tdeabcresourcesloxconfig.moc" diff --git a/tderesources/slox/tdeabcresourcesloxconfig.h b/tderesources/slox/tdeabcresourcesloxconfig.h new file mode 100644 index 000000000..9cd54d831 --- /dev/null +++ b/tderesources/slox/tdeabcresourcesloxconfig.h @@ -0,0 +1,62 @@ +/* + This file is part of tdepim. + + Copyright (c) 2004 Cornelius Schumacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef RESOURCESLOXCONFIG_H +#define RESOURCESLOXCONFIG_H + +#include +#include + +class TQCheckBox; +class KLineEdit; +class KURLRequester; +class KPushButton; + +class SloxBase; + +namespace KABC { + +class KDE_EXPORT ResourceSloxConfig : public KRES::ConfigWidget +{ + Q_OBJECT + + + public: + ResourceSloxConfig( TQWidget* parent = 0, const char* name = 0 ); + + public slots: + void loadSettings( KRES::Resource* ); + void saveSettings( KRES::Resource* ); + + private slots: + void selectAddressFolder(); + + private: + KURLRequester *mURL; + KLineEdit *mUser; + KLineEdit *mPassword; + TQCheckBox *mLastSyncCheck; + KPushButton *mFolderButton; + TQString mFolderId; + SloxBase *mRes; +}; + +} + +#endif diff --git a/tderesources/slox/tdeabcsloxprefs.kcfgc b/tderesources/slox/tdeabcsloxprefs.kcfgc new file mode 100644 index 000000000..70c006f52 --- /dev/null +++ b/tderesources/slox/tdeabcsloxprefs.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for tdeconfig_compiler +File=tderesources_tdeabc_slox.kcfg +ClassName=SloxPrefs +NameSpace=KABC +Singleton=false +Mutators=true +Inherits=KResourcePrefs +IncludeFiles=libtdepim/kresourceprefs.h +GlobalEnums=true +#ItemAccessors=true +#SetUserTexts=true diff --git a/tderesources/slox/webdavhandler.cpp b/tderesources/slox/webdavhandler.cpp index 65caebf23..f3f33d610 100644 --- a/tderesources/slox/webdavhandler.cpp +++ b/tderesources/slox/webdavhandler.cpp @@ -291,5 +291,5 @@ void WebdavHandler::setSloxAttributes( KCal::Incidence *i ) void WebdavHandler::setSloxAttributes( KABC::Addressee & ) { - // FIXME: libkabc doesn't allow to set an individual addressee to read-only + // FIXME: libtdeabc doesn't allow to set an individual addressee to read-only } -- cgit v1.2.1