From 10251f9a2a51f37c2a42833c1d05cd5a8fdf6bb5 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 17 Feb 2013 02:06:43 -0600 Subject: Fix FTBFS --- tderesources/groupwise/kabc_groupwise.desktop | 50 -- tderesources/groupwise/kabc_groupwiseprefs.kcfgc | 8 - tderesources/groupwise/kabc_resourcegroupwise.cpp | 743 --------------------- tderesources/groupwise/kabc_resourcegroupwise.h | 169 ----- .../groupwise/kabc_resourcegroupwise_plugin.cpp | 40 -- .../groupwise/kabc_resourcegroupwiseconfig.cpp | 209 ------ .../groupwise/kabc_resourcegroupwiseconfig.h | 74 -- tderesources/groupwise/tdeabc_groupwise.desktop | 50 ++ tderesources/groupwise/tdeabc_groupwiseprefs.kcfgc | 8 + .../groupwise/tdeabc_resourcegroupwise.cpp | 743 +++++++++++++++++++++ tderesources/groupwise/tdeabc_resourcegroupwise.h | 169 +++++ .../groupwise/tdeabc_resourcegroupwise_plugin.cpp | 40 ++ .../groupwise/tdeabc_resourcegroupwiseconfig.cpp | 209 ++++++ .../groupwise/tdeabc_resourcegroupwiseconfig.h | 74 ++ .../groupwise/tderesources_kabc_groupwise.kcfg | 55 -- .../groupwise/tderesources_tdeabc_groupwise.kcfg | 55 ++ 16 files changed, 1348 insertions(+), 1348 deletions(-) delete mode 100644 tderesources/groupwise/kabc_groupwise.desktop delete mode 100644 tderesources/groupwise/kabc_groupwiseprefs.kcfgc delete mode 100644 tderesources/groupwise/kabc_resourcegroupwise.cpp delete mode 100644 tderesources/groupwise/kabc_resourcegroupwise.h delete mode 100644 tderesources/groupwise/kabc_resourcegroupwise_plugin.cpp delete mode 100644 tderesources/groupwise/kabc_resourcegroupwiseconfig.cpp delete mode 100644 tderesources/groupwise/kabc_resourcegroupwiseconfig.h create mode 100644 tderesources/groupwise/tdeabc_groupwise.desktop create mode 100644 tderesources/groupwise/tdeabc_groupwiseprefs.kcfgc create mode 100644 tderesources/groupwise/tdeabc_resourcegroupwise.cpp create mode 100644 tderesources/groupwise/tdeabc_resourcegroupwise.h create mode 100644 tderesources/groupwise/tdeabc_resourcegroupwise_plugin.cpp create mode 100644 tderesources/groupwise/tdeabc_resourcegroupwiseconfig.cpp create mode 100644 tderesources/groupwise/tdeabc_resourcegroupwiseconfig.h delete mode 100644 tderesources/groupwise/tderesources_kabc_groupwise.kcfg create mode 100644 tderesources/groupwise/tderesources_tdeabc_groupwise.kcfg (limited to 'tderesources/groupwise') diff --git a/tderesources/groupwise/kabc_groupwise.desktop b/tderesources/groupwise/kabc_groupwise.desktop deleted file mode 100644 index 695ab445b..000000000 --- a/tderesources/groupwise/kabc_groupwise.desktop +++ /dev/null @@ -1,50 +0,0 @@ -[Desktop Entry] -Name=Novell GroupWise Server -Name[af]=Novell GroupWise bediener -Name[bg]=Сървър Novell GroupWise -Name[br]=Servijer Novell GroupWise -Name[ca]=Servidor Novell GroupWise -Name[cs]=Novell GroupWise server -Name[da]=Novell GroupWise server -Name[el]=Εξυπηρετητής Novell GroupWise -Name[es]=Servidor de Novell GroupWise -Name[et]=Novelli GroupWise server -Name[eu]=Novell GroupWise zerbitzaria -Name[fa]=کارساز Novell GroupWise -Name[fi]=Novell GroupWise -palvelin -Name[fr]=Serveur de travail collaboratif GroupWise de Novell -Name[fy]=Novell GroupWise-tsjinner -Name[ga]=Freastalaí Novell GroupWise -Name[gl]=Servidor Novell GroupWise -Name[hu]=Novell GroupWise kiszolgáló -Name[is]=Novell GroupWise þjónn -Name[it]=Server Novell GroupWise -Name[ja]=Novell GroupWise サーバ -Name[ka]=სერვერი Novell GroupWise -Name[kk]=Novell GroupWise сервері -Name[km]=ម៉ាស៊ីន​បម្រើ GroupWise របស់​ណូវែល -Name[lt]=Novell GroupWise serveris -Name[ms]=Pelayan Novell GroupWise -Name[nb]=Novell GroupWise-tjener -Name[nds]=Novell-GroupWise-Server -Name[ne]=नोभेल समूहगत सर्भर -Name[nl]=Novell GroupWise-server -Name[nn]=Novell GroupWise-tenar -Name[pl]=Serwer Novell GroupWise -Name[pt]=Servidor Novell GroupWise -Name[pt_BR]=Servidor GroupWise da Novell -Name[ru]=Сервер Novell GroupWise -Name[sl]=Strežnik Novell GroupWise -Name[sr]=Novell-ов GroupWise сервер -Name[sr@Latn]=Novell-ov GroupWise server -Name[sv]=Novell Groupwise-server -Name[ta]=Novell குழுவாரிச் சேவகன் -Name[tr]=Novell GroupWise Sunucusu -Name[uk]=Сервер Novell GroupWise -Name[zh_CN]=Novell GroupWise 服务器 -Name[zh_TW]=Novell 群組伺服器 -X-TDE-Library=kabc_groupwise -Type=Service -ServiceTypes=KResources/Plugin -X-TDE-ResourceFamily=contact -X-TDE-ResourceType=groupwise diff --git a/tderesources/groupwise/kabc_groupwiseprefs.kcfgc b/tderesources/groupwise/kabc_groupwiseprefs.kcfgc deleted file mode 100644 index 08e997f64..000000000 --- a/tderesources/groupwise/kabc_groupwiseprefs.kcfgc +++ /dev/null @@ -1,8 +0,0 @@ -ClassName=GroupwisePrefs -File=tderesources_kabc_groupwise.kcfg -GlobalEnums=true -IncludeFiles=libtdepim/kresourceprefs.h -Inherits=KResourcePrefs -Mutators=true -NameSpace=KABC -Singleton=false diff --git a/tderesources/groupwise/kabc_resourcegroupwise.cpp b/tderesources/groupwise/kabc_resourcegroupwise.cpp deleted file mode 100644 index 8499aa9ff..000000000 --- a/tderesources/groupwise/kabc_resourcegroupwise.cpp +++ /dev/null @@ -1,743 +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 -#include - -#include -#include -#include -#include -#include - -#include "kabc_groupwiseprefs.h" - -#include "kabc_resourcegroupwise.h" - -using namespace KABC; - -ResourceGroupwise::ResourceGroupwise( const TDEConfig *config ) - : ResourceCached( config ) -{ - init(); - - mPrefs->addGroupPrefix( identifier() ); - - if ( config ) { - readConfig( config ); - } - initGroupwise(); -} - -ResourceGroupwise::ResourceGroupwise( const KURL &url, - const TQString &user, - const TQString &password, - const TQStringList &readAddressBooks, - const TQString &writeAddressBook ) - : ResourceCached( 0 ) -{ - init(); - - mPrefs->addGroupPrefix( identifier() ); - - mPrefs->setUrl( url.url() ); - mPrefs->setUser( user ); - mPrefs->setPassword( password ); - mPrefs->setReadAddressBooks( readAddressBooks ); - mPrefs->setWriteAddressBook( writeAddressBook ); - - initGroupwise(); -} - -void ResourceGroupwise::init() -{ - mJob = 0; - mProgress = 0; - mSABProgress = 0; - mUABProgress = 0; - mServerFirstSequence = 0; - mServerLastSequence = 0; - mServerLastPORebuildTime = 0; - mPrefs = new GroupwisePrefs; - mState = Start; - setType( "groupwise" ); -} - -void ResourceGroupwise::initGroupwise() -{ - mServer = new GroupwiseServer( mPrefs->url(), mPrefs->user(), - mPrefs->password(), this ); -} - -ResourceGroupwise::~ResourceGroupwise() -{ - delete mServer; - mServer = 0; - - delete mPrefs; - mPrefs = 0; -} - -void ResourceGroupwise::readConfig( const TDEConfig * ) -{ - mPrefs->readConfig(); - - readAddressBooks(); -} - -void ResourceGroupwise::writeConfig( TDEConfig *config ) -{ - Resource::writeConfig( config ); - - writeAddressBooks(); - - mPrefs->writeConfig(); -} - -void ResourceGroupwise::clearCache() -{ - idMapper().clear(); - mAddrMap.clear(); - TQFile file( cacheFile() ); - file.remove(); -} - -void ResourceGroupwise::readAddressBooks() -{ - TQStringList ids = prefs()->ids(); - TQStringList names = prefs()->names(); - TQStringList personals = prefs()->personals(); - TQStringList frequents = prefs()->frequents(); - - if ( ids.count() != names.count() || ids.count() != personals.count() || - ids.count() != frequents.count() ) { - kdError() << "Corrupt addressbook configuration" << endl; - return; - } - - mAddressBooks.clear(); - - for( uint i = 0; i < ids.count(); ++i ) { - GroupWise::AddressBook ab; - ab.id = ids[ i ]; - ab.name = names[ i ]; - ab.isPersonal = personals[ i ] == "1"; - ab.isFrequentContacts = frequents[ i ] == "1"; - - mAddressBooks.append( ab ); - } -} - -void ResourceGroupwise::writeAddressBooks() -{ - TQStringList ids; - TQStringList names; - TQStringList personals; - TQStringList frequents; - GroupWise::AddressBook::List::ConstIterator it; - for( it = mAddressBooks.begin(); it != mAddressBooks.end(); ++it ) { - ids.append( (*it).id ); - names.append( (*it).name ); - personals.append( (*it).isPersonal ? "1" : "0" ); - frequents.append( (*it).isFrequentContacts ? "1" : "0" ); - } - prefs()->setIds( ids ); - prefs()->setNames( names ); - prefs()->setPersonals( personals ); - prefs()->setFrequents( frequents ); -} - -void ResourceGroupwise::retrieveAddressBooks() -{ - bool firstRetrieve = mAddressBooks.isEmpty(); - - GroupwiseServer server( prefs()->url(), - prefs()->user(), - prefs()->password(), this ); - - if ( server.login() ) - { - mAddressBooks = server.addressBookList(); - server.logout(); - - TQStringList reads; - TQString write; - - GroupWise::AddressBook::List::ConstIterator it; - for( it = mAddressBooks.begin(); it != mAddressBooks.end(); ++it ) { - reads.append( (*it).id ); - if ( (*it).isPersonal ) { - if ( write.isEmpty() ) write = (*it).id; - } - else - prefs()->setSystemAddressBook( (*it).id ); - } - - if ( firstRetrieve ) { - prefs()->setReadAddressBooks( reads ); - prefs()->setWriteAddressBook( write ); - } - } - else - emit loadingError( this, server.errorText() ); -} - -Ticket *ResourceGroupwise::requestSaveTicket() -{ - if ( !addressBook() ) { - kdDebug(5700) << "no addressbook" << endl; - return 0; - } - - return createTicket( this ); -} - -void ResourceGroupwise::releaseSaveTicket( Ticket *ticket ) -{ - delete ticket; -} - -bool ResourceGroupwise::doOpen() -{ - return true; -} - -void ResourceGroupwise::doClose() -{ - kdDebug() << "ResourceGroupwise::doClose()" << endl; - - cancelLoad(); -} - -bool ResourceGroupwise::save( Ticket *ticket ) -{ - return asyncSave( ticket ); -} - -bool ResourceGroupwise::asyncSave( Ticket* ) -{ - if ( !mServer->login() ) return false; - - KABC::Addressee::List::Iterator it; - - KABC::Addressee::List addedList = addedAddressees(); - for ( it = addedList.begin(); it != addedList.end(); ++it ) { - if ( mServer->insertAddressee( mPrefs->writeAddressBook(), *it ) ) { - clearChange( *it ); - idMapper().setRemoteId( (*it).uid(), (*it).custom( "GWRESOURCE", "UID" ) ); - } - } - - KABC::Addressee::List changedList = changedAddressees(); - for ( it = changedList.begin(); it != changedList.end(); ++it ) { - if ( mServer->changeAddressee( *it ) ) - clearChange( *it ); - } - - KABC::Addressee::List deletedList = deletedAddressees(); - for ( it = deletedList.begin(); it != deletedList.end(); ++it ) { - if ( mServer->removeAddressee( *it ) ) - clearChange( *it ); - } - - if ( appIsWhiteListedForSAB() ) - saveCache(); - - mServer->logout(); - - return true; -} - -bool ResourceGroupwise::load() -{ - return asyncLoad(); -} - -bool ResourceGroupwise::asyncLoad() -{ - kdDebug() << "ResourceGroupwise::asyncLoad()" << endl; - //mPrefs->readConfig(); TODO: remove if the system addressbook is not read when disabled in config - - if ( mState != Start ) - { - kdDebug() << " Download still in progress" << endl; - return true; - } - - if ( appIsWhiteListedForSAB() ) - loadCache(); - - if ( !mProgress ) - { - mProgress = KPIM::ProgressManager::instance()->createProgressItem( - KPIM::ProgressManager::getUniqueID(), i18n( "Loading GroupWise resource %1" ).arg( resourceName() ), TQString(), true /*CanBeCancelled*/, mPrefs->url().startsWith("https" ) ); - connect( mProgress, TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), - TQT_SLOT( cancelLoad() ) ); - } - - if ( addressBooks().isEmpty() ) { - kdDebug() << " Retrieving default addressbook list." << endl; - retrieveAddressBooks(); - writeAddressBooks(); - } - - SABState sabState = systemAddressBookState(); - if ( shouldFetchSystemAddressBook() ) - { - if ( sabState == RefreshNeeded ) - { - kdDebug() << " Fetching system addressbook" << endl; - fetchAddressBooks( System ); - return true; - } - else if ( sabState == Stale ) - { - kdDebug() << " Updating system addressbook" << endl; - updateSystemAddressBook(); // we then fetch the user address books after doing this - return true; - } - } - else if ( shouldFetchUserAddressBooks() ) - { - kdDebug() << " Fetching user addressbook" << endl; - fetchAddressBooks( User ); - return true; - } - return true; -} - -void ResourceGroupwise::fetchAddressBooks( const BookType bookType ) -{ - KURL url = createAccessUrl( bookType, Fetch ); - if ( !url.isValid() ) - return; - - kdDebug() << k_funcinfo << ( bookType == System ? " System" : " User" ) << " URL: " << url << endl; - // sanity check - if ( bookType == User && !( mState == SABUptodate || mState == Start ) ) - { - kdDebug() << " **ERROR** - fetchAddressBooks( User ) called when SAB not up to date" << endl; - return; - } - - mState = ( bookType == System ? FetchingSAB : FetchingUAB ); - mJobData = TQString(); - - if ( mJob ) - { - kdDebug() << " **ERROR** - fetchAddressBooks() called when a job was already running!" << endl; - return; - } - - mJob = TDEIO::get( url, false, false ); // TODO: make the GW jobs call finished if the URL - // contains no address book IDs - kdDebug() << " Job address: " << mJob << endl; - connect( mJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), - TQT_SLOT( slotReadJobData( TDEIO::Job *, const TQByteArray & ) ) ); - connect( mJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), - TQT_SLOT( slotJobPercent( TDEIO::Job *, unsigned long ) ) ); - - if ( bookType == System ) - { - connect( mJob, TQT_SIGNAL( result( TDEIO::Job * ) ), - TQT_SLOT( fetchSABResult( TDEIO::Job * ) ) ); - mSABProgress = KPIM::ProgressManager::instance()->createProgressItem( - mProgress, KPIM::ProgressManager::getUniqueID(), - i18n( "Fetching System Address Book" ), TQString(), - false /*CannotBeCancelled*/, - mPrefs->url().startsWith("https" ) ); - } - else - { - connect( mJob, TQT_SIGNAL( result( TDEIO::Job * ) ), - TQT_SLOT( fetchUABResult( TDEIO::Job * ) ) ); - mUABProgress = KPIM::ProgressManager::instance()->createProgressItem( - mProgress, KPIM::ProgressManager::getUniqueID(), - i18n( "Fetching User Address Books" ), TQString(), - false /*CannotBeCancelled*/, - mPrefs->url().startsWith("https" ) ); - } - - return; -} - -void ResourceGroupwise::fetchSABResult( TDEIO::Job *job ) -{ - kdDebug() << "ResourceGroupwise::fetchSABResult() " << endl; - - if ( job->error() ) { - kdError() << job->errorString() << endl; - emit loadingError( this, job->errorString() ); - // TODO kill the rest of the load sequence as well - } - - mJob->disconnect( this ); - mJob = 0; - mState = SABUptodate; - if ( mSABProgress ) - mSABProgress->setComplete(); - - storeDeltaInfo(); - - if ( shouldFetchUserAddressBooks() ) - fetchAddressBooks( User ); - else - loadCompleted(); -} - -void ResourceGroupwise::fetchUABResult( TDEIO::Job *job ) -{ - kdDebug() << "ResourceGroupwise::fetchUABResult() " << endl; - - if ( job->error() ) { - kdError() << job->errorString() << endl; - emit loadingError( this, job->errorString() ); - } - - mJob->disconnect( this ); - mJob = 0; - mState = Uptodate; - if ( mUABProgress ) - mUABProgress->setComplete(); - loadCompleted(); -} - -void ResourceGroupwise::updateSystemAddressBook() -{ - kdDebug() << "ResourceGroupwise::updateSystemAddressBook()" << endl; - - if ( mState != Start ) { - kdWarning() << " Action already in progress" << endl; - return; - } - - if ( addressBooks().isEmpty() ) { - kdDebug() << " Retrieving default addressbook list." << endl; - retrieveAddressBooks(); - writeAddressBooks(); - } - - KURL url = createAccessUrl( System, Update, mPrefs->lastSequenceNumber(), mPrefs->lastTimePORebuild() ); - kdDebug() << " Update URL: " << url << endl; - - mJobData = TQString(); - mSABProgress = KPIM::ProgressManager::instance()->createProgressItem( - mProgress, KPIM::ProgressManager::getUniqueID(), - i18n( "Updating System Address Book" ), TQString(), - false /*CannotBeCancelled*/, - mPrefs->url().startsWith("https" ) ); - - mJob = TDEIO::get( url, false, false ); - mJob->setInteractive( false ); - connect( mJob, TQT_SIGNAL( result( TDEIO::Job * ) ), - TQT_SLOT( updateSABResult( TDEIO::Job * ) ) ); - connect( mJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), - TQT_SLOT( slotUpdateJobData( TDEIO::Job *, const TQByteArray & ) ) ); - connect( mJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), - TQT_SLOT( slotJobPercent( TDEIO::Job *, unsigned long ) ) ); - - return; -} - -void ResourceGroupwise::updateSABResult( TDEIO::Job *job ) -{ - kdDebug() << "ResourceGroupwise::updateSABResult() " << endl; - - mSABProgress->setComplete(); - mSABProgress = 0; - mJob->disconnect( this ); - mJob = 0; - - int errorCode = job->error(); - if ( errorCode != 0 ) { - if ( errorCode == TDEIO::ERR_NO_CONTENT ) // we need to refresh the SAB - { - kdDebug() << " update SAB failed, fetching all of it again" << endl; - mPrefs->setLastSequenceNumber( 0 ); - mPrefs->setFirstSequenceNumber( 0 ); - fetchAddressBooks( System ); - return; - } - } - - mState = SABUptodate; - storeDeltaInfo(); - - if ( shouldFetchUserAddressBooks() ) - fetchAddressBooks( User ); - else - loadCompleted(); -} - -void ResourceGroupwise::slotReadJobData( TDEIO::Job *job , const TQByteArray &data ) -{ - kdDebug() << "ResourceGroupwise::slotReadJobData()" << endl; - Q_UNUSED( job ); - - mJobData.append( data.data() ); - - KABC::VCardConverter conv; - TQTime profile; - profile.start(); - Addressee::List addressees = conv.parseVCards( mJobData ); - // kdDebug() << " parsed " << addressees.count() << " contacts in " << profile.elapsed() << "ms, now adding to resource..." << endl; - - Addressee::List::ConstIterator it; - for( it = addressees.begin(); it != addressees.end(); ++it ) { - KABC::Addressee addr = *it; - if ( !addr.isEmpty() ) { - addr.setResource( this ); - - TQString remote = addr.custom( "GWRESOURCE", "UID" ); - TQString local = idMapper().localId( remote ); - if ( local.isEmpty() ) { - idMapper().setRemoteId( addr.uid(), remote ); - } else { - addr.setUid( local ); - } - - insertAddressee( addr ); - clearChange( addr ); - } - } - mJobData = TQString(); -} - -void ResourceGroupwise::slotUpdateJobData( TDEIO::Job *job, const TQByteArray &data ) -{ - kdDebug() << "ResourceGroupwise::slotUpdateJobData()" << endl; - kdDebug() << " Job address: " << job << endl; - KABC::VCardConverter conv; - mJobData.append( data.data() ); - - Addressee::List addressees = conv.parseVCards( mJobData ); - Addressee::List::ConstIterator it; - - for( it = addressees.begin(); it != addressees.end(); ++it ) { - KABC::Addressee addr = *it; - if ( !addr.isEmpty() ) { - // if added or changed - TQString syncType = addr.custom( "GWRESOURCE", "SYNC" ); - TQString remote = addr.custom( "GWRESOURCE", "UID" ); - TQString local = idMapper().localId( remote ); - - if ( syncType == "ADD" || syncType == "UPD" ) - { - addr.setResource( this ); - if ( local.isEmpty() ) { - idMapper().setRemoteId( addr.uid(), remote ); - } else { - addr.setUid( local ); - } - - insertAddressee( addr ); - clearChange( addr ); - } - else if ( syncType == "DEL" ) - { - // if deleted - if ( !remote.isEmpty() ) - { - if ( !local.isEmpty() ) - { - idMapper().removeRemoteId( remote ); - KABC::Addressee addrToDelete = findByUid( local ); - removeAddressee( addrToDelete ); - } - } - else - kdError() << "Addressee to delete did not have a remote UID, unable to find the corresponding local contact" << endl; - } - } - } - mJobData = TQString(); -} - -void ResourceGroupwise::loadCompleted() -{ - kdDebug() << "ResourceGroupwise::loadCompleted()" << endl; - if ( mProgress ) - mProgress->setComplete(); - mProgress = 0; - mSABProgress = 0; - mUABProgress = 0; - mState = Start; - if ( appIsWhiteListedForSAB() ) - saveCache(); - emit loadingFinished( this ); - addressBook()->emitAddressBookChanged(); -} - -void ResourceGroupwise::slotJobPercent( TDEIO::Job *, unsigned long percent ) -{ - // TODO: make this act on the correct progress item - kdDebug() << "ResourceGroupwise::slotJobPercent() " << percent << endl; - if ( mProgress ) mProgress->setProgress( percent ); -} - -void ResourceGroupwise::cancelLoad() -{ - if ( mJob ) - { - mJob->disconnect( this ); - mJob->kill(); - } - mJob = 0; - if ( mProgress ) mProgress->setComplete(); - mProgress = 0; - mState = Start; -} - -ResourceGroupwise::SABState ResourceGroupwise::systemAddressBookState() -{ - unsigned long storedFirstSequence = mPrefs->firstSequenceNumber(); - unsigned long storedLastSequence = mPrefs->lastSequenceNumber(); - unsigned long storedLastPORebuildTime = mPrefs->lastTimePORebuild(); - - kdDebug() << "ResourceGroupwise::systemAddressBookState()" << endl; - kdDebug() << " Stored first seq no: " << storedFirstSequence << endl; - kdDebug() << " Stored last seq no: " << storedLastSequence << endl; - kdDebug() << " Stored last PO Rebuild time: " << storedLastPORebuildTime << endl; - - kdDebug() << " Fetching delta info to check if update possible" << endl; - if ( mServer->login() ) - { - GroupWise::DeltaInfo deltaInfo = mServer->getDeltaInfo( mPrefs->systemAddressBook() ); - mServer->logout(); - - mServerFirstSequence = deltaInfo.firstSequence; - mServerLastSequence = deltaInfo.lastSequence; - mServerLastPORebuildTime = deltaInfo.lastTimePORebuild; - - kdDebug() << " Server first seq no: " << mServerFirstSequence << endl; - kdDebug() << " Server last seq no: " << mServerLastSequence << endl; - kdDebug() << " Server last PO Rebuild time: " << mServerLastPORebuildTime << endl; - - if ( storedFirstSequence == 0 || storedLastSequence == 0 ) - { - kdDebug() << " no fetched SAB exists yet, can't update" << endl; - return RefreshNeeded; - } - - if ( mServerFirstSequence > storedLastSequence || storedLastPORebuildTime != mServerLastPORebuildTime) - { - kdDebug() << " New entries since the last fetch are no longer available as deltas, or the PO was rebuilt, refresh needed" << endl; - return RefreshNeeded; - } - - if ( mServerLastSequence == storedLastSequence ) - { - kdDebug() << " The local data is up to date" << endl; - return InSync; - } - } - else - emit loadingError( this, mServer->errorText() ); - - if ( storedFirstSequence == 0 || storedLastSequence == 0 ) - { - kdDebug() << " Fallthrough - no fetched SAB exists yet, refresh" << endl; - return RefreshNeeded; - } - else - kdDebug() << " Fallthrough - returning Stale" << endl; - return Stale; -} - -bool ResourceGroupwise::shouldFetchSystemAddressBook() -{ - - TQStringList ids = mPrefs->readAddressBooks(); - return ( appIsWhiteListedForSAB() && ids.find( mPrefs->systemAddressBook() ) != ids.end() ); -} - -bool ResourceGroupwise::shouldFetchUserAddressBooks() -{ - TQStringList ids = mPrefs->readAddressBooks(); - return ( ids.count() > 1 || ids.find( mPrefs->systemAddressBook() ) == ids.end() ); -} - -KURL ResourceGroupwise::createAccessUrl( BookType bookType, AccessMode mode, unsigned long lastSequenceNumber, unsigned long lastPORebuildTime ) -{ - // set up list of address book IDs to fetch - TQStringList ids; - if ( bookType == System ) - ids.append( mPrefs->systemAddressBook() ); - else - { - ids = mPrefs->readAddressBooks(); - ids.remove( mPrefs->systemAddressBook() ); - } - - if ( ids.isEmpty() ) - return KURL(); - - KURL url( prefs()->url() ); - if ( url.protocol() == "http" ) - url.setProtocol( "groupwise" ); - else - url.setProtocol( "groupwises" ); - - url.setPath( url.path() + "/addressbook/" ); - url.setUser( prefs()->user() ); - url.setPass( prefs()->password() ); - - TQString query = "?"; - TQStringList::ConstIterator it; - for( it = ids.begin(); it != ids.end(); ++it ) { - if ( it != ids.begin() ) query += "&"; - query += "addressbookid=" + *it; - } - - if ( mode == Update && lastSequenceNumber > 0 && lastPORebuildTime > 0 ) - { - query += TQString::fromLatin1( "&update=true&lastSeqNo=%1&PORebuildTime=%2" ).arg( lastSequenceNumber ).arg( lastPORebuildTime );; - } - url.setQuery( query ); - return url; -} - -void ResourceGroupwise::storeDeltaInfo() -{ - // update SAB delta info - kdDebug() << "ResourceGroupwise::storeDeltaInfo()" << endl; - kdDebug() << " Server first seq no: " << mServerFirstSequence << endl; - kdDebug() << " Server last seq no: " << mServerLastSequence << endl; - kdDebug() << " Server last PO Rebuild time: " << mServerLastPORebuildTime << endl; - - if ( mServerFirstSequence == 0 || mServerLastSequence == 0 || mServerLastPORebuildTime == 0 ) - return; - mPrefs->setFirstSequenceNumber( mServerFirstSequence ); - mPrefs->setLastSequenceNumber( mServerLastSequence ); - mPrefs->setLastTimePORebuild( mServerLastPORebuildTime ); - mPrefs->writeConfig(); -} - -bool ResourceGroupwise::appIsWhiteListedForSAB() -{ - if ( !mPrefs->systemAddressBookWhiteList().contains( tqApp->argv()[ 0 ] ) ) - { - kdDebug() << "Application " << tqApp->argv()[ 0 ] << " is _blacklisted_ to load the SAB" << endl; - return false; - } - return true; -} - -#include "kabc_resourcegroupwise.moc" diff --git a/tderesources/groupwise/kabc_resourcegroupwise.h b/tderesources/groupwise/kabc_resourcegroupwise.h deleted file mode 100644 index 0c7533eef..000000000 --- a/tderesources/groupwise/kabc_resourcegroupwise.h +++ /dev/null @@ -1,169 +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_RESOURCEGROUPWISE_H -#define KABC_RESOURCEGROUPWISE_H - -#include "soap/groupwiseserver.h" - -#include -#include - -#include - -#include - -class TDEConfig; - -class GroupwiseServer; - -namespace KABC { - -class GroupwisePrefs; - -class KDE_EXPORT ResourceGroupwise : public ResourceCached -{ - friend class ResourceGroupwiseConfig; - - Q_OBJECT - - - public: - ResourceGroupwise( const TDEConfig * ); - ResourceGroupwise( const KURL &url, - const TQString &user, const TQString &password, - const TQStringList &readAddressBooks, - const TQString &writeAddressBook ); - ~ResourceGroupwise(); - - void readConfig( const TDEConfig * ); - void writeConfig( TDEConfig * ); - - void readAddressBooks(); - void writeAddressBooks(); - - void retrieveAddressBooks(); - - GroupwisePrefs *prefs() const { return mPrefs; } - - GroupWise::AddressBook::List addressBooks() const { return mAddressBooks; } - - bool doOpen(); - void doClose(); - - Ticket *requestSaveTicket(); - void releaseSaveTicket( Ticket* ); - - bool load(); - bool asyncLoad(); - bool save( Ticket * ); - bool asyncSave( Ticket * ); - enum SABState { Error, Stale, InSync, RefreshNeeded }; - - /** - * Clears the cached data, in memory and on disk - */ - void clearCache(); - protected: - enum ResourceState { Start, FetchingSAB, SABUptodate, FetchingUAB, Uptodate }; - enum BookType { System, User }; - enum AccessMode { Fetch, Update }; - void init(); - void initGroupwise(); - - /* STATE CHANGING METHODS */ - /** - * Begin asynchronously fetching the system address book , replacing the cached copy - */ - void fetchAddressBooks( const BookType booktype ); - /** - * Asynchronously update the system address book - */ - void updateSystemAddressBook(); - /** - * Wrap up the load sequence - */ - void loadCompleted(); - - /** HELPER METHODS **/ - /** - * Check to see if a local download of the SAB already exists - */ - SABState systemAddressBookState(); - /** - * Check if the resource is configured to download the SAB - */ - bool shouldFetchSystemAddressBook(); - /** - * Check if the resource is configured to download personal address - * books - */ - bool shouldFetchUserAddressBooks(); - - /** - * Create a URL for a single addressbook access. - * To fetch an address book completely, use mode = Fetch - * To just update an addressbook, use mode = Update and give the ast sequence number already held - * If Update is given without a sequence number, the mode falls back to Fetch - */ - KURL createAccessUrl( BookType bookType, AccessMode mode, unsigned long lastSequenceNumber = 0, unsigned long lastPORebuildTime = 0 ); - - /** - * Persist the last known delta info. Call after the SAB is up to date. - */ - void storeDeltaInfo(); - - /** - * Check if the application which has loaded this resource is whitelisted - * to load the System Address Book (time-consuming) - */ - bool appIsWhiteListedForSAB(); - - private slots: - /** STATE CHANGING SLOTS **/ - void fetchSABResult( TDEIO::Job * ); - void fetchUABResult( TDEIO::Job * ); - void updateSABResult( TDEIO::Job * ); - /** DATA PROCESSING SLOTS **/ - void slotReadJobData( TDEIO::Job *, const TQByteArray & ); - void slotUpdateJobData( TDEIO::Job *, const TQByteArray & ); - /** HELPER TQT_SLOT **/ - void slotJobPercent( TDEIO::Job *job, unsigned long percent ); - - void cancelLoad(); - private: - GroupwisePrefs *mPrefs; - GroupWise::AddressBook::List mAddressBooks; - - GroupwiseServer *mServer; - - TDEIO::TransferJob *mJob; - KPIM::ProgressItem *mProgress; - KPIM::ProgressItem *mSABProgress; - KPIM::ProgressItem *mUABProgress; - TQString mJobData; - ResourceState mState; - unsigned long mServerFirstSequence, mServerLastSequence, mServerLastPORebuildTime; - - bool mLimitedMode; -}; - -} - -#endif diff --git a/tderesources/groupwise/kabc_resourcegroupwise_plugin.cpp b/tderesources/groupwise/kabc_resourcegroupwise_plugin.cpp deleted file mode 100644 index e71a66e5e..000000000 --- a/tderesources/groupwise/kabc_resourcegroupwise_plugin.cpp +++ /dev/null @@ -1,40 +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 "kabc_resourcegroupwise.h" -#include "kabc_resourcegroupwiseconfig.h" - -#include -#include - -using namespace KABC; - -typedef KRES::PluginFactory GroupwiseFactory; -// FIXME: Use K_EXPORT_COMPONENT_FACTORY( kabc_groupwise, GroupwiseFactory ); here -// Problem: How do I insert the catalogue??? -extern "C" -{ - void *init_kabc_groupwise() - { - TDEGlobal::locale()->insertCatalogue( "libkcal" ); - TDEGlobal::locale()->insertCatalogue( "kres_groupwise" ); - return new GroupwiseFactory; - } -} diff --git a/tderesources/groupwise/kabc_resourcegroupwiseconfig.cpp b/tderesources/groupwise/kabc_resourcegroupwiseconfig.cpp deleted file mode 100644 index 1212a6bc5..000000000 --- a/tderesources/groupwise/kabc_resourcegroupwiseconfig.cpp +++ /dev/null @@ -1,209 +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 "kabc_resourcegroupwiseconfig.h" - -#include "kabc_resourcegroupwise.h" -#include "kabc_groupwiseprefs.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace KABC; - -class AddressBookItem : public TQCheckListItem -{ - public: - AddressBookItem( TDEListView *parent, GroupWise::AddressBook ab ) - : TQCheckListItem( parent, "", CheckBox ), - mId( ab.id ) - { - setText( 0, ab.name ); - if ( ab.isPersonal ) setText( 1, i18n("Yes") ); - else setText( 1, i18n("No") ); - if ( ab.isFrequentContacts ) setText( 2, i18n("Yes") ); - else setText( 2, i18n("No") ); - } - - TQString id() const { return mId; } - - private: - TQString mId; -}; - -ResourceGroupwiseConfig::ResourceGroupwiseConfig( TQWidget* parent, const char* name ) - : KRES::ConfigWidget( parent, name ) -{ - TQGridLayout *mainLayout = new TQGridLayout( this, 7, 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 ); - - TQFrame *hline = new TQFrame( this ); - hline->setFrameStyle( TQFrame::HLine | TQFrame::Sunken ); - - mainLayout->addMultiCellWidget( hline, 3, 3, 0, 1 ); - - TQPushButton *updateButton = new TQPushButton( i18n( "Retrieve Address Book List From Server" ), this ); - mainLayout->addMultiCellWidget( updateButton, 4, 4, 0, 1 ); - - mAddressBookView = new TDEListView( this ); - mAddressBookView->addColumn( i18n( "Address Book" ) ); - mAddressBookView->addColumn( i18n( "Personal" ) ); - mAddressBookView->addColumn( i18n( "Frequent Contacts" ) ); - mAddressBookView->setFullWidth( true ); - - mainLayout->addMultiCellWidget( mAddressBookView, 5, 5, 0, 1 ); - - label = new TQLabel( i18n( "Address book for new contacts:" ), this ); - mAddressBookBox = new KComboBox( this ); - - mainLayout->addWidget( label, 6, 0 ); - mainLayout->addWidget( mAddressBookBox, 6, 1 ); - - connect( updateButton, TQT_SIGNAL( clicked() ), TQT_SLOT( updateAddressBookList() ) ); -} - -void ResourceGroupwiseConfig::loadSettings( KRES::Resource *res ) -{ - mResource = dynamic_cast( res ); - - if ( !mResource ) { - kdDebug(5700) << "ResourceGroupwiseConfig::loadSettings(): cast failed" << endl; - return; - } - - mURL->setURL( mResource->prefs()->url() ); - mUser->setText( mResource->prefs()->user() ); - mPassword->setText( mResource->prefs()->password() ); - mReadAddressBookIds = mResource->prefs()->readAddressBooks(); - updateAddressBookView(); -} - -void ResourceGroupwiseConfig::saveSettings( KRES::Resource *res ) -{ - ResourceGroupwise *resource = dynamic_cast( res ); - - if ( !resource ) { - kdDebug(5700) << "ResourceGroupwiseConfig::saveSettings(): cast failed" << endl; - return; - } - - saveServerSettings( resource ); - - saveAddressBookSettings(); -} - -void ResourceGroupwiseConfig::saveServerSettings( ResourceGroupwise *resource ) -{ - resource->prefs()->setUrl( mURL->url() ); - resource->prefs()->setUser( mUser->text() ); - resource->prefs()->setPassword( mPassword->text() ); -} - -void ResourceGroupwiseConfig::updateAddressBookList() -{ - saveServerSettings( mResource ); - - mResource->retrieveAddressBooks(); - - updateAddressBookView(); -} - -void ResourceGroupwiseConfig::saveAddressBookSettings() -{ - TQStringList selectedRead; - TQString selectedWrite; - - TQListViewItemIterator it2( mAddressBookView ); - while ( it2.current() ) { - AddressBookItem *item = static_cast( it2.current() ); - if ( item->isOn() ) - selectedRead.append( item->id() ); - - ++it2; - } - // check if the SAB was selected when the settings were loaded and is not selected now, - // if so, clear the resource to clear the SAB data that is no longer required. - // also, set the sequence numbers to 0 so that we know the SAB should be re-fetched in its entirety the next time we do load it - TQString sab = mResource->prefs()->systemAddressBook(); - if ( ( mReadAddressBookIds.find( sab ) != mReadAddressBookIds.end() ) && ( selectedRead.find( sab ) == selectedRead.end() ) ) - { - mResource->clearCache(); - mResource->prefs()->setLastSequenceNumber( 0 ); - mResource->prefs()->setFirstSequenceNumber( 0 ); - } - selectedWrite = mWriteAddressBookIds[ mAddressBookBox->currentItem() ]; - - mResource->prefs()->setReadAddressBooks( selectedRead ); - mResource->prefs()->setWriteAddressBook( selectedWrite ); -} - -void ResourceGroupwiseConfig::updateAddressBookView() -{ - if ( mAddressBookBox->count() != 0 ) // we loaded it already - saveAddressBookSettings(); - - mAddressBookView->clear(); - mAddressBookBox->clear(); - mWriteAddressBookIds.clear(); - - TQStringList selectedRead = mResource->prefs()->readAddressBooks(); - - GroupWise::AddressBook::List addressBooks = mResource->addressBooks(); - GroupWise::AddressBook::List::ConstIterator abIt; - for ( abIt = addressBooks.begin(); abIt != addressBooks.end(); ++abIt ) { - AddressBookItem *item = new AddressBookItem( mAddressBookView, *abIt ); - if ( selectedRead.find( (*abIt).id ) != selectedRead.end() ) - item->setOn( true ); - - mAddressBookBox->insertItem( (*abIt).name ); - mWriteAddressBookIds.append( (*abIt).id ); - } - - int index = mWriteAddressBookIds.findIndex( mResource->prefs()->writeAddressBook() ); - mAddressBookBox->setCurrentItem( index ); -} - -#include "kabc_resourcegroupwiseconfig.moc" diff --git a/tderesources/groupwise/kabc_resourcegroupwiseconfig.h b/tderesources/groupwise/kabc_resourcegroupwiseconfig.h deleted file mode 100644 index eb54803c0..000000000 --- a/tderesources/groupwise/kabc_resourcegroupwiseconfig.h +++ /dev/null @@ -1,74 +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_RESOURCEGROUPWISECONFIG_H -#define KABC_RESOURCEGROUPWISECONFIG_H - -#include "soap/groupwiseserver.h" - -#include -#include - -#include - -class KComboBox; -class KLineEdit; -class TDEListView; -class KURLRequester; - -namespace KABC { - -class ResourceGroupwise; - -class KDE_EXPORT ResourceGroupwiseConfig : public KRES::ConfigWidget -{ - Q_OBJECT - - - public: - ResourceGroupwiseConfig( TQWidget* parent = 0, const char* name = 0 ); - - public slots: - void loadSettings( KRES::Resource* ); - void saveSettings( KRES::Resource* ); - - protected slots: - void updateAddressBookList(); - - private: - void updateAddressBookView(); - void saveAddressBookSettings(); - void loadAddressBookSettings(); - void saveServerSettings( ResourceGroupwise *resource ); - - KURLRequester *mURL; - KLineEdit *mUser; - KLineEdit *mPassword; - - TDEListView *mAddressBookView; - KComboBox *mAddressBookBox; - - TQStringList mWriteAddressBookIds; - TQStringList mReadAddressBookIds; - ResourceGroupwise *mResource; -}; - -} - -#endif diff --git a/tderesources/groupwise/tdeabc_groupwise.desktop b/tderesources/groupwise/tdeabc_groupwise.desktop new file mode 100644 index 000000000..695ab445b --- /dev/null +++ b/tderesources/groupwise/tdeabc_groupwise.desktop @@ -0,0 +1,50 @@ +[Desktop Entry] +Name=Novell GroupWise Server +Name[af]=Novell GroupWise bediener +Name[bg]=Сървър Novell GroupWise +Name[br]=Servijer Novell GroupWise +Name[ca]=Servidor Novell GroupWise +Name[cs]=Novell GroupWise server +Name[da]=Novell GroupWise server +Name[el]=Εξυπηρετητής Novell GroupWise +Name[es]=Servidor de Novell GroupWise +Name[et]=Novelli GroupWise server +Name[eu]=Novell GroupWise zerbitzaria +Name[fa]=کارساز Novell GroupWise +Name[fi]=Novell GroupWise -palvelin +Name[fr]=Serveur de travail collaboratif GroupWise de Novell +Name[fy]=Novell GroupWise-tsjinner +Name[ga]=Freastalaí Novell GroupWise +Name[gl]=Servidor Novell GroupWise +Name[hu]=Novell GroupWise kiszolgáló +Name[is]=Novell GroupWise þjónn +Name[it]=Server Novell GroupWise +Name[ja]=Novell GroupWise サーバ +Name[ka]=სერვერი Novell GroupWise +Name[kk]=Novell GroupWise сервері +Name[km]=ម៉ាស៊ីន​បម្រើ GroupWise របស់​ណូវែល +Name[lt]=Novell GroupWise serveris +Name[ms]=Pelayan Novell GroupWise +Name[nb]=Novell GroupWise-tjener +Name[nds]=Novell-GroupWise-Server +Name[ne]=नोभेल समूहगत सर्भर +Name[nl]=Novell GroupWise-server +Name[nn]=Novell GroupWise-tenar +Name[pl]=Serwer Novell GroupWise +Name[pt]=Servidor Novell GroupWise +Name[pt_BR]=Servidor GroupWise da Novell +Name[ru]=Сервер Novell GroupWise +Name[sl]=Strežnik Novell GroupWise +Name[sr]=Novell-ов GroupWise сервер +Name[sr@Latn]=Novell-ov GroupWise server +Name[sv]=Novell Groupwise-server +Name[ta]=Novell குழுவாரிச் சேவகன் +Name[tr]=Novell GroupWise Sunucusu +Name[uk]=Сервер Novell GroupWise +Name[zh_CN]=Novell GroupWise 服务器 +Name[zh_TW]=Novell 群組伺服器 +X-TDE-Library=kabc_groupwise +Type=Service +ServiceTypes=KResources/Plugin +X-TDE-ResourceFamily=contact +X-TDE-ResourceType=groupwise diff --git a/tderesources/groupwise/tdeabc_groupwiseprefs.kcfgc b/tderesources/groupwise/tdeabc_groupwiseprefs.kcfgc new file mode 100644 index 000000000..0dd55c2f6 --- /dev/null +++ b/tderesources/groupwise/tdeabc_groupwiseprefs.kcfgc @@ -0,0 +1,8 @@ +ClassName=GroupwisePrefs +File=tderesources_tdeabc_groupwise.kcfg +GlobalEnums=true +IncludeFiles=libtdepim/kresourceprefs.h +Inherits=KResourcePrefs +Mutators=true +NameSpace=KABC +Singleton=false diff --git a/tderesources/groupwise/tdeabc_resourcegroupwise.cpp b/tderesources/groupwise/tdeabc_resourcegroupwise.cpp new file mode 100644 index 000000000..8499aa9ff --- /dev/null +++ b/tderesources/groupwise/tdeabc_resourcegroupwise.cpp @@ -0,0 +1,743 @@ +/* + 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 +#include + +#include +#include +#include +#include +#include + +#include "kabc_groupwiseprefs.h" + +#include "kabc_resourcegroupwise.h" + +using namespace KABC; + +ResourceGroupwise::ResourceGroupwise( const TDEConfig *config ) + : ResourceCached( config ) +{ + init(); + + mPrefs->addGroupPrefix( identifier() ); + + if ( config ) { + readConfig( config ); + } + initGroupwise(); +} + +ResourceGroupwise::ResourceGroupwise( const KURL &url, + const TQString &user, + const TQString &password, + const TQStringList &readAddressBooks, + const TQString &writeAddressBook ) + : ResourceCached( 0 ) +{ + init(); + + mPrefs->addGroupPrefix( identifier() ); + + mPrefs->setUrl( url.url() ); + mPrefs->setUser( user ); + mPrefs->setPassword( password ); + mPrefs->setReadAddressBooks( readAddressBooks ); + mPrefs->setWriteAddressBook( writeAddressBook ); + + initGroupwise(); +} + +void ResourceGroupwise::init() +{ + mJob = 0; + mProgress = 0; + mSABProgress = 0; + mUABProgress = 0; + mServerFirstSequence = 0; + mServerLastSequence = 0; + mServerLastPORebuildTime = 0; + mPrefs = new GroupwisePrefs; + mState = Start; + setType( "groupwise" ); +} + +void ResourceGroupwise::initGroupwise() +{ + mServer = new GroupwiseServer( mPrefs->url(), mPrefs->user(), + mPrefs->password(), this ); +} + +ResourceGroupwise::~ResourceGroupwise() +{ + delete mServer; + mServer = 0; + + delete mPrefs; + mPrefs = 0; +} + +void ResourceGroupwise::readConfig( const TDEConfig * ) +{ + mPrefs->readConfig(); + + readAddressBooks(); +} + +void ResourceGroupwise::writeConfig( TDEConfig *config ) +{ + Resource::writeConfig( config ); + + writeAddressBooks(); + + mPrefs->writeConfig(); +} + +void ResourceGroupwise::clearCache() +{ + idMapper().clear(); + mAddrMap.clear(); + TQFile file( cacheFile() ); + file.remove(); +} + +void ResourceGroupwise::readAddressBooks() +{ + TQStringList ids = prefs()->ids(); + TQStringList names = prefs()->names(); + TQStringList personals = prefs()->personals(); + TQStringList frequents = prefs()->frequents(); + + if ( ids.count() != names.count() || ids.count() != personals.count() || + ids.count() != frequents.count() ) { + kdError() << "Corrupt addressbook configuration" << endl; + return; + } + + mAddressBooks.clear(); + + for( uint i = 0; i < ids.count(); ++i ) { + GroupWise::AddressBook ab; + ab.id = ids[ i ]; + ab.name = names[ i ]; + ab.isPersonal = personals[ i ] == "1"; + ab.isFrequentContacts = frequents[ i ] == "1"; + + mAddressBooks.append( ab ); + } +} + +void ResourceGroupwise::writeAddressBooks() +{ + TQStringList ids; + TQStringList names; + TQStringList personals; + TQStringList frequents; + GroupWise::AddressBook::List::ConstIterator it; + for( it = mAddressBooks.begin(); it != mAddressBooks.end(); ++it ) { + ids.append( (*it).id ); + names.append( (*it).name ); + personals.append( (*it).isPersonal ? "1" : "0" ); + frequents.append( (*it).isFrequentContacts ? "1" : "0" ); + } + prefs()->setIds( ids ); + prefs()->setNames( names ); + prefs()->setPersonals( personals ); + prefs()->setFrequents( frequents ); +} + +void ResourceGroupwise::retrieveAddressBooks() +{ + bool firstRetrieve = mAddressBooks.isEmpty(); + + GroupwiseServer server( prefs()->url(), + prefs()->user(), + prefs()->password(), this ); + + if ( server.login() ) + { + mAddressBooks = server.addressBookList(); + server.logout(); + + TQStringList reads; + TQString write; + + GroupWise::AddressBook::List::ConstIterator it; + for( it = mAddressBooks.begin(); it != mAddressBooks.end(); ++it ) { + reads.append( (*it).id ); + if ( (*it).isPersonal ) { + if ( write.isEmpty() ) write = (*it).id; + } + else + prefs()->setSystemAddressBook( (*it).id ); + } + + if ( firstRetrieve ) { + prefs()->setReadAddressBooks( reads ); + prefs()->setWriteAddressBook( write ); + } + } + else + emit loadingError( this, server.errorText() ); +} + +Ticket *ResourceGroupwise::requestSaveTicket() +{ + if ( !addressBook() ) { + kdDebug(5700) << "no addressbook" << endl; + return 0; + } + + return createTicket( this ); +} + +void ResourceGroupwise::releaseSaveTicket( Ticket *ticket ) +{ + delete ticket; +} + +bool ResourceGroupwise::doOpen() +{ + return true; +} + +void ResourceGroupwise::doClose() +{ + kdDebug() << "ResourceGroupwise::doClose()" << endl; + + cancelLoad(); +} + +bool ResourceGroupwise::save( Ticket *ticket ) +{ + return asyncSave( ticket ); +} + +bool ResourceGroupwise::asyncSave( Ticket* ) +{ + if ( !mServer->login() ) return false; + + KABC::Addressee::List::Iterator it; + + KABC::Addressee::List addedList = addedAddressees(); + for ( it = addedList.begin(); it != addedList.end(); ++it ) { + if ( mServer->insertAddressee( mPrefs->writeAddressBook(), *it ) ) { + clearChange( *it ); + idMapper().setRemoteId( (*it).uid(), (*it).custom( "GWRESOURCE", "UID" ) ); + } + } + + KABC::Addressee::List changedList = changedAddressees(); + for ( it = changedList.begin(); it != changedList.end(); ++it ) { + if ( mServer->changeAddressee( *it ) ) + clearChange( *it ); + } + + KABC::Addressee::List deletedList = deletedAddressees(); + for ( it = deletedList.begin(); it != deletedList.end(); ++it ) { + if ( mServer->removeAddressee( *it ) ) + clearChange( *it ); + } + + if ( appIsWhiteListedForSAB() ) + saveCache(); + + mServer->logout(); + + return true; +} + +bool ResourceGroupwise::load() +{ + return asyncLoad(); +} + +bool ResourceGroupwise::asyncLoad() +{ + kdDebug() << "ResourceGroupwise::asyncLoad()" << endl; + //mPrefs->readConfig(); TODO: remove if the system addressbook is not read when disabled in config + + if ( mState != Start ) + { + kdDebug() << " Download still in progress" << endl; + return true; + } + + if ( appIsWhiteListedForSAB() ) + loadCache(); + + if ( !mProgress ) + { + mProgress = KPIM::ProgressManager::instance()->createProgressItem( + KPIM::ProgressManager::getUniqueID(), i18n( "Loading GroupWise resource %1" ).arg( resourceName() ), TQString(), true /*CanBeCancelled*/, mPrefs->url().startsWith("https" ) ); + connect( mProgress, TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), + TQT_SLOT( cancelLoad() ) ); + } + + if ( addressBooks().isEmpty() ) { + kdDebug() << " Retrieving default addressbook list." << endl; + retrieveAddressBooks(); + writeAddressBooks(); + } + + SABState sabState = systemAddressBookState(); + if ( shouldFetchSystemAddressBook() ) + { + if ( sabState == RefreshNeeded ) + { + kdDebug() << " Fetching system addressbook" << endl; + fetchAddressBooks( System ); + return true; + } + else if ( sabState == Stale ) + { + kdDebug() << " Updating system addressbook" << endl; + updateSystemAddressBook(); // we then fetch the user address books after doing this + return true; + } + } + else if ( shouldFetchUserAddressBooks() ) + { + kdDebug() << " Fetching user addressbook" << endl; + fetchAddressBooks( User ); + return true; + } + return true; +} + +void ResourceGroupwise::fetchAddressBooks( const BookType bookType ) +{ + KURL url = createAccessUrl( bookType, Fetch ); + if ( !url.isValid() ) + return; + + kdDebug() << k_funcinfo << ( bookType == System ? " System" : " User" ) << " URL: " << url << endl; + // sanity check + if ( bookType == User && !( mState == SABUptodate || mState == Start ) ) + { + kdDebug() << " **ERROR** - fetchAddressBooks( User ) called when SAB not up to date" << endl; + return; + } + + mState = ( bookType == System ? FetchingSAB : FetchingUAB ); + mJobData = TQString(); + + if ( mJob ) + { + kdDebug() << " **ERROR** - fetchAddressBooks() called when a job was already running!" << endl; + return; + } + + mJob = TDEIO::get( url, false, false ); // TODO: make the GW jobs call finished if the URL + // contains no address book IDs + kdDebug() << " Job address: " << mJob << endl; + connect( mJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotReadJobData( TDEIO::Job *, const TQByteArray & ) ) ); + connect( mJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), + TQT_SLOT( slotJobPercent( TDEIO::Job *, unsigned long ) ) ); + + if ( bookType == System ) + { + connect( mJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( fetchSABResult( TDEIO::Job * ) ) ); + mSABProgress = KPIM::ProgressManager::instance()->createProgressItem( + mProgress, KPIM::ProgressManager::getUniqueID(), + i18n( "Fetching System Address Book" ), TQString(), + false /*CannotBeCancelled*/, + mPrefs->url().startsWith("https" ) ); + } + else + { + connect( mJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( fetchUABResult( TDEIO::Job * ) ) ); + mUABProgress = KPIM::ProgressManager::instance()->createProgressItem( + mProgress, KPIM::ProgressManager::getUniqueID(), + i18n( "Fetching User Address Books" ), TQString(), + false /*CannotBeCancelled*/, + mPrefs->url().startsWith("https" ) ); + } + + return; +} + +void ResourceGroupwise::fetchSABResult( TDEIO::Job *job ) +{ + kdDebug() << "ResourceGroupwise::fetchSABResult() " << endl; + + if ( job->error() ) { + kdError() << job->errorString() << endl; + emit loadingError( this, job->errorString() ); + // TODO kill the rest of the load sequence as well + } + + mJob->disconnect( this ); + mJob = 0; + mState = SABUptodate; + if ( mSABProgress ) + mSABProgress->setComplete(); + + storeDeltaInfo(); + + if ( shouldFetchUserAddressBooks() ) + fetchAddressBooks( User ); + else + loadCompleted(); +} + +void ResourceGroupwise::fetchUABResult( TDEIO::Job *job ) +{ + kdDebug() << "ResourceGroupwise::fetchUABResult() " << endl; + + if ( job->error() ) { + kdError() << job->errorString() << endl; + emit loadingError( this, job->errorString() ); + } + + mJob->disconnect( this ); + mJob = 0; + mState = Uptodate; + if ( mUABProgress ) + mUABProgress->setComplete(); + loadCompleted(); +} + +void ResourceGroupwise::updateSystemAddressBook() +{ + kdDebug() << "ResourceGroupwise::updateSystemAddressBook()" << endl; + + if ( mState != Start ) { + kdWarning() << " Action already in progress" << endl; + return; + } + + if ( addressBooks().isEmpty() ) { + kdDebug() << " Retrieving default addressbook list." << endl; + retrieveAddressBooks(); + writeAddressBooks(); + } + + KURL url = createAccessUrl( System, Update, mPrefs->lastSequenceNumber(), mPrefs->lastTimePORebuild() ); + kdDebug() << " Update URL: " << url << endl; + + mJobData = TQString(); + mSABProgress = KPIM::ProgressManager::instance()->createProgressItem( + mProgress, KPIM::ProgressManager::getUniqueID(), + i18n( "Updating System Address Book" ), TQString(), + false /*CannotBeCancelled*/, + mPrefs->url().startsWith("https" ) ); + + mJob = TDEIO::get( url, false, false ); + mJob->setInteractive( false ); + connect( mJob, TQT_SIGNAL( result( TDEIO::Job * ) ), + TQT_SLOT( updateSABResult( TDEIO::Job * ) ) ); + connect( mJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ), + TQT_SLOT( slotUpdateJobData( TDEIO::Job *, const TQByteArray & ) ) ); + connect( mJob, TQT_SIGNAL( percent( TDEIO::Job *, unsigned long ) ), + TQT_SLOT( slotJobPercent( TDEIO::Job *, unsigned long ) ) ); + + return; +} + +void ResourceGroupwise::updateSABResult( TDEIO::Job *job ) +{ + kdDebug() << "ResourceGroupwise::updateSABResult() " << endl; + + mSABProgress->setComplete(); + mSABProgress = 0; + mJob->disconnect( this ); + mJob = 0; + + int errorCode = job->error(); + if ( errorCode != 0 ) { + if ( errorCode == TDEIO::ERR_NO_CONTENT ) // we need to refresh the SAB + { + kdDebug() << " update SAB failed, fetching all of it again" << endl; + mPrefs->setLastSequenceNumber( 0 ); + mPrefs->setFirstSequenceNumber( 0 ); + fetchAddressBooks( System ); + return; + } + } + + mState = SABUptodate; + storeDeltaInfo(); + + if ( shouldFetchUserAddressBooks() ) + fetchAddressBooks( User ); + else + loadCompleted(); +} + +void ResourceGroupwise::slotReadJobData( TDEIO::Job *job , const TQByteArray &data ) +{ + kdDebug() << "ResourceGroupwise::slotReadJobData()" << endl; + Q_UNUSED( job ); + + mJobData.append( data.data() ); + + KABC::VCardConverter conv; + TQTime profile; + profile.start(); + Addressee::List addressees = conv.parseVCards( mJobData ); + // kdDebug() << " parsed " << addressees.count() << " contacts in " << profile.elapsed() << "ms, now adding to resource..." << endl; + + Addressee::List::ConstIterator it; + for( it = addressees.begin(); it != addressees.end(); ++it ) { + KABC::Addressee addr = *it; + if ( !addr.isEmpty() ) { + addr.setResource( this ); + + TQString remote = addr.custom( "GWRESOURCE", "UID" ); + TQString local = idMapper().localId( remote ); + if ( local.isEmpty() ) { + idMapper().setRemoteId( addr.uid(), remote ); + } else { + addr.setUid( local ); + } + + insertAddressee( addr ); + clearChange( addr ); + } + } + mJobData = TQString(); +} + +void ResourceGroupwise::slotUpdateJobData( TDEIO::Job *job, const TQByteArray &data ) +{ + kdDebug() << "ResourceGroupwise::slotUpdateJobData()" << endl; + kdDebug() << " Job address: " << job << endl; + KABC::VCardConverter conv; + mJobData.append( data.data() ); + + Addressee::List addressees = conv.parseVCards( mJobData ); + Addressee::List::ConstIterator it; + + for( it = addressees.begin(); it != addressees.end(); ++it ) { + KABC::Addressee addr = *it; + if ( !addr.isEmpty() ) { + // if added or changed + TQString syncType = addr.custom( "GWRESOURCE", "SYNC" ); + TQString remote = addr.custom( "GWRESOURCE", "UID" ); + TQString local = idMapper().localId( remote ); + + if ( syncType == "ADD" || syncType == "UPD" ) + { + addr.setResource( this ); + if ( local.isEmpty() ) { + idMapper().setRemoteId( addr.uid(), remote ); + } else { + addr.setUid( local ); + } + + insertAddressee( addr ); + clearChange( addr ); + } + else if ( syncType == "DEL" ) + { + // if deleted + if ( !remote.isEmpty() ) + { + if ( !local.isEmpty() ) + { + idMapper().removeRemoteId( remote ); + KABC::Addressee addrToDelete = findByUid( local ); + removeAddressee( addrToDelete ); + } + } + else + kdError() << "Addressee to delete did not have a remote UID, unable to find the corresponding local contact" << endl; + } + } + } + mJobData = TQString(); +} + +void ResourceGroupwise::loadCompleted() +{ + kdDebug() << "ResourceGroupwise::loadCompleted()" << endl; + if ( mProgress ) + mProgress->setComplete(); + mProgress = 0; + mSABProgress = 0; + mUABProgress = 0; + mState = Start; + if ( appIsWhiteListedForSAB() ) + saveCache(); + emit loadingFinished( this ); + addressBook()->emitAddressBookChanged(); +} + +void ResourceGroupwise::slotJobPercent( TDEIO::Job *, unsigned long percent ) +{ + // TODO: make this act on the correct progress item + kdDebug() << "ResourceGroupwise::slotJobPercent() " << percent << endl; + if ( mProgress ) mProgress->setProgress( percent ); +} + +void ResourceGroupwise::cancelLoad() +{ + if ( mJob ) + { + mJob->disconnect( this ); + mJob->kill(); + } + mJob = 0; + if ( mProgress ) mProgress->setComplete(); + mProgress = 0; + mState = Start; +} + +ResourceGroupwise::SABState ResourceGroupwise::systemAddressBookState() +{ + unsigned long storedFirstSequence = mPrefs->firstSequenceNumber(); + unsigned long storedLastSequence = mPrefs->lastSequenceNumber(); + unsigned long storedLastPORebuildTime = mPrefs->lastTimePORebuild(); + + kdDebug() << "ResourceGroupwise::systemAddressBookState()" << endl; + kdDebug() << " Stored first seq no: " << storedFirstSequence << endl; + kdDebug() << " Stored last seq no: " << storedLastSequence << endl; + kdDebug() << " Stored last PO Rebuild time: " << storedLastPORebuildTime << endl; + + kdDebug() << " Fetching delta info to check if update possible" << endl; + if ( mServer->login() ) + { + GroupWise::DeltaInfo deltaInfo = mServer->getDeltaInfo( mPrefs->systemAddressBook() ); + mServer->logout(); + + mServerFirstSequence = deltaInfo.firstSequence; + mServerLastSequence = deltaInfo.lastSequence; + mServerLastPORebuildTime = deltaInfo.lastTimePORebuild; + + kdDebug() << " Server first seq no: " << mServerFirstSequence << endl; + kdDebug() << " Server last seq no: " << mServerLastSequence << endl; + kdDebug() << " Server last PO Rebuild time: " << mServerLastPORebuildTime << endl; + + if ( storedFirstSequence == 0 || storedLastSequence == 0 ) + { + kdDebug() << " no fetched SAB exists yet, can't update" << endl; + return RefreshNeeded; + } + + if ( mServerFirstSequence > storedLastSequence || storedLastPORebuildTime != mServerLastPORebuildTime) + { + kdDebug() << " New entries since the last fetch are no longer available as deltas, or the PO was rebuilt, refresh needed" << endl; + return RefreshNeeded; + } + + if ( mServerLastSequence == storedLastSequence ) + { + kdDebug() << " The local data is up to date" << endl; + return InSync; + } + } + else + emit loadingError( this, mServer->errorText() ); + + if ( storedFirstSequence == 0 || storedLastSequence == 0 ) + { + kdDebug() << " Fallthrough - no fetched SAB exists yet, refresh" << endl; + return RefreshNeeded; + } + else + kdDebug() << " Fallthrough - returning Stale" << endl; + return Stale; +} + +bool ResourceGroupwise::shouldFetchSystemAddressBook() +{ + + TQStringList ids = mPrefs->readAddressBooks(); + return ( appIsWhiteListedForSAB() && ids.find( mPrefs->systemAddressBook() ) != ids.end() ); +} + +bool ResourceGroupwise::shouldFetchUserAddressBooks() +{ + TQStringList ids = mPrefs->readAddressBooks(); + return ( ids.count() > 1 || ids.find( mPrefs->systemAddressBook() ) == ids.end() ); +} + +KURL ResourceGroupwise::createAccessUrl( BookType bookType, AccessMode mode, unsigned long lastSequenceNumber, unsigned long lastPORebuildTime ) +{ + // set up list of address book IDs to fetch + TQStringList ids; + if ( bookType == System ) + ids.append( mPrefs->systemAddressBook() ); + else + { + ids = mPrefs->readAddressBooks(); + ids.remove( mPrefs->systemAddressBook() ); + } + + if ( ids.isEmpty() ) + return KURL(); + + KURL url( prefs()->url() ); + if ( url.protocol() == "http" ) + url.setProtocol( "groupwise" ); + else + url.setProtocol( "groupwises" ); + + url.setPath( url.path() + "/addressbook/" ); + url.setUser( prefs()->user() ); + url.setPass( prefs()->password() ); + + TQString query = "?"; + TQStringList::ConstIterator it; + for( it = ids.begin(); it != ids.end(); ++it ) { + if ( it != ids.begin() ) query += "&"; + query += "addressbookid=" + *it; + } + + if ( mode == Update && lastSequenceNumber > 0 && lastPORebuildTime > 0 ) + { + query += TQString::fromLatin1( "&update=true&lastSeqNo=%1&PORebuildTime=%2" ).arg( lastSequenceNumber ).arg( lastPORebuildTime );; + } + url.setQuery( query ); + return url; +} + +void ResourceGroupwise::storeDeltaInfo() +{ + // update SAB delta info + kdDebug() << "ResourceGroupwise::storeDeltaInfo()" << endl; + kdDebug() << " Server first seq no: " << mServerFirstSequence << endl; + kdDebug() << " Server last seq no: " << mServerLastSequence << endl; + kdDebug() << " Server last PO Rebuild time: " << mServerLastPORebuildTime << endl; + + if ( mServerFirstSequence == 0 || mServerLastSequence == 0 || mServerLastPORebuildTime == 0 ) + return; + mPrefs->setFirstSequenceNumber( mServerFirstSequence ); + mPrefs->setLastSequenceNumber( mServerLastSequence ); + mPrefs->setLastTimePORebuild( mServerLastPORebuildTime ); + mPrefs->writeConfig(); +} + +bool ResourceGroupwise::appIsWhiteListedForSAB() +{ + if ( !mPrefs->systemAddressBookWhiteList().contains( tqApp->argv()[ 0 ] ) ) + { + kdDebug() << "Application " << tqApp->argv()[ 0 ] << " is _blacklisted_ to load the SAB" << endl; + return false; + } + return true; +} + +#include "kabc_resourcegroupwise.moc" diff --git a/tderesources/groupwise/tdeabc_resourcegroupwise.h b/tderesources/groupwise/tdeabc_resourcegroupwise.h new file mode 100644 index 000000000..0c7533eef --- /dev/null +++ b/tderesources/groupwise/tdeabc_resourcegroupwise.h @@ -0,0 +1,169 @@ +/* + 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_RESOURCEGROUPWISE_H +#define KABC_RESOURCEGROUPWISE_H + +#include "soap/groupwiseserver.h" + +#include +#include + +#include + +#include + +class TDEConfig; + +class GroupwiseServer; + +namespace KABC { + +class GroupwisePrefs; + +class KDE_EXPORT ResourceGroupwise : public ResourceCached +{ + friend class ResourceGroupwiseConfig; + + Q_OBJECT + + + public: + ResourceGroupwise( const TDEConfig * ); + ResourceGroupwise( const KURL &url, + const TQString &user, const TQString &password, + const TQStringList &readAddressBooks, + const TQString &writeAddressBook ); + ~ResourceGroupwise(); + + void readConfig( const TDEConfig * ); + void writeConfig( TDEConfig * ); + + void readAddressBooks(); + void writeAddressBooks(); + + void retrieveAddressBooks(); + + GroupwisePrefs *prefs() const { return mPrefs; } + + GroupWise::AddressBook::List addressBooks() const { return mAddressBooks; } + + bool doOpen(); + void doClose(); + + Ticket *requestSaveTicket(); + void releaseSaveTicket( Ticket* ); + + bool load(); + bool asyncLoad(); + bool save( Ticket * ); + bool asyncSave( Ticket * ); + enum SABState { Error, Stale, InSync, RefreshNeeded }; + + /** + * Clears the cached data, in memory and on disk + */ + void clearCache(); + protected: + enum ResourceState { Start, FetchingSAB, SABUptodate, FetchingUAB, Uptodate }; + enum BookType { System, User }; + enum AccessMode { Fetch, Update }; + void init(); + void initGroupwise(); + + /* STATE CHANGING METHODS */ + /** + * Begin asynchronously fetching the system address book , replacing the cached copy + */ + void fetchAddressBooks( const BookType booktype ); + /** + * Asynchronously update the system address book + */ + void updateSystemAddressBook(); + /** + * Wrap up the load sequence + */ + void loadCompleted(); + + /** HELPER METHODS **/ + /** + * Check to see if a local download of the SAB already exists + */ + SABState systemAddressBookState(); + /** + * Check if the resource is configured to download the SAB + */ + bool shouldFetchSystemAddressBook(); + /** + * Check if the resource is configured to download personal address + * books + */ + bool shouldFetchUserAddressBooks(); + + /** + * Create a URL for a single addressbook access. + * To fetch an address book completely, use mode = Fetch + * To just update an addressbook, use mode = Update and give the ast sequence number already held + * If Update is given without a sequence number, the mode falls back to Fetch + */ + KURL createAccessUrl( BookType bookType, AccessMode mode, unsigned long lastSequenceNumber = 0, unsigned long lastPORebuildTime = 0 ); + + /** + * Persist the last known delta info. Call after the SAB is up to date. + */ + void storeDeltaInfo(); + + /** + * Check if the application which has loaded this resource is whitelisted + * to load the System Address Book (time-consuming) + */ + bool appIsWhiteListedForSAB(); + + private slots: + /** STATE CHANGING SLOTS **/ + void fetchSABResult( TDEIO::Job * ); + void fetchUABResult( TDEIO::Job * ); + void updateSABResult( TDEIO::Job * ); + /** DATA PROCESSING SLOTS **/ + void slotReadJobData( TDEIO::Job *, const TQByteArray & ); + void slotUpdateJobData( TDEIO::Job *, const TQByteArray & ); + /** HELPER TQT_SLOT **/ + void slotJobPercent( TDEIO::Job *job, unsigned long percent ); + + void cancelLoad(); + private: + GroupwisePrefs *mPrefs; + GroupWise::AddressBook::List mAddressBooks; + + GroupwiseServer *mServer; + + TDEIO::TransferJob *mJob; + KPIM::ProgressItem *mProgress; + KPIM::ProgressItem *mSABProgress; + KPIM::ProgressItem *mUABProgress; + TQString mJobData; + ResourceState mState; + unsigned long mServerFirstSequence, mServerLastSequence, mServerLastPORebuildTime; + + bool mLimitedMode; +}; + +} + +#endif diff --git a/tderesources/groupwise/tdeabc_resourcegroupwise_plugin.cpp b/tderesources/groupwise/tdeabc_resourcegroupwise_plugin.cpp new file mode 100644 index 000000000..b3a94a901 --- /dev/null +++ b/tderesources/groupwise/tdeabc_resourcegroupwise_plugin.cpp @@ -0,0 +1,40 @@ +/* + 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 "kabc_resourcegroupwise.h" +#include "kabc_resourcegroupwiseconfig.h" + +#include +#include + +using namespace KABC; + +typedef KRES::PluginFactory GroupwiseFactory; +// FIXME: Use K_EXPORT_COMPONENT_FACTORY( kabc_groupwise, GroupwiseFactory ); here +// Problem: How do I insert the catalogue??? +extern "C" +{ + void *init_tdeabc_groupwise() + { + TDEGlobal::locale()->insertCatalogue( "libkcal" ); + TDEGlobal::locale()->insertCatalogue( "kres_groupwise" ); + return new GroupwiseFactory; + } +} diff --git a/tderesources/groupwise/tdeabc_resourcegroupwiseconfig.cpp b/tderesources/groupwise/tdeabc_resourcegroupwiseconfig.cpp new file mode 100644 index 000000000..1212a6bc5 --- /dev/null +++ b/tderesources/groupwise/tdeabc_resourcegroupwiseconfig.cpp @@ -0,0 +1,209 @@ +/* + 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 "kabc_resourcegroupwiseconfig.h" + +#include "kabc_resourcegroupwise.h" +#include "kabc_groupwiseprefs.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace KABC; + +class AddressBookItem : public TQCheckListItem +{ + public: + AddressBookItem( TDEListView *parent, GroupWise::AddressBook ab ) + : TQCheckListItem( parent, "", CheckBox ), + mId( ab.id ) + { + setText( 0, ab.name ); + if ( ab.isPersonal ) setText( 1, i18n("Yes") ); + else setText( 1, i18n("No") ); + if ( ab.isFrequentContacts ) setText( 2, i18n("Yes") ); + else setText( 2, i18n("No") ); + } + + TQString id() const { return mId; } + + private: + TQString mId; +}; + +ResourceGroupwiseConfig::ResourceGroupwiseConfig( TQWidget* parent, const char* name ) + : KRES::ConfigWidget( parent, name ) +{ + TQGridLayout *mainLayout = new TQGridLayout( this, 7, 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 ); + + TQFrame *hline = new TQFrame( this ); + hline->setFrameStyle( TQFrame::HLine | TQFrame::Sunken ); + + mainLayout->addMultiCellWidget( hline, 3, 3, 0, 1 ); + + TQPushButton *updateButton = new TQPushButton( i18n( "Retrieve Address Book List From Server" ), this ); + mainLayout->addMultiCellWidget( updateButton, 4, 4, 0, 1 ); + + mAddressBookView = new TDEListView( this ); + mAddressBookView->addColumn( i18n( "Address Book" ) ); + mAddressBookView->addColumn( i18n( "Personal" ) ); + mAddressBookView->addColumn( i18n( "Frequent Contacts" ) ); + mAddressBookView->setFullWidth( true ); + + mainLayout->addMultiCellWidget( mAddressBookView, 5, 5, 0, 1 ); + + label = new TQLabel( i18n( "Address book for new contacts:" ), this ); + mAddressBookBox = new KComboBox( this ); + + mainLayout->addWidget( label, 6, 0 ); + mainLayout->addWidget( mAddressBookBox, 6, 1 ); + + connect( updateButton, TQT_SIGNAL( clicked() ), TQT_SLOT( updateAddressBookList() ) ); +} + +void ResourceGroupwiseConfig::loadSettings( KRES::Resource *res ) +{ + mResource = dynamic_cast( res ); + + if ( !mResource ) { + kdDebug(5700) << "ResourceGroupwiseConfig::loadSettings(): cast failed" << endl; + return; + } + + mURL->setURL( mResource->prefs()->url() ); + mUser->setText( mResource->prefs()->user() ); + mPassword->setText( mResource->prefs()->password() ); + mReadAddressBookIds = mResource->prefs()->readAddressBooks(); + updateAddressBookView(); +} + +void ResourceGroupwiseConfig::saveSettings( KRES::Resource *res ) +{ + ResourceGroupwise *resource = dynamic_cast( res ); + + if ( !resource ) { + kdDebug(5700) << "ResourceGroupwiseConfig::saveSettings(): cast failed" << endl; + return; + } + + saveServerSettings( resource ); + + saveAddressBookSettings(); +} + +void ResourceGroupwiseConfig::saveServerSettings( ResourceGroupwise *resource ) +{ + resource->prefs()->setUrl( mURL->url() ); + resource->prefs()->setUser( mUser->text() ); + resource->prefs()->setPassword( mPassword->text() ); +} + +void ResourceGroupwiseConfig::updateAddressBookList() +{ + saveServerSettings( mResource ); + + mResource->retrieveAddressBooks(); + + updateAddressBookView(); +} + +void ResourceGroupwiseConfig::saveAddressBookSettings() +{ + TQStringList selectedRead; + TQString selectedWrite; + + TQListViewItemIterator it2( mAddressBookView ); + while ( it2.current() ) { + AddressBookItem *item = static_cast( it2.current() ); + if ( item->isOn() ) + selectedRead.append( item->id() ); + + ++it2; + } + // check if the SAB was selected when the settings were loaded and is not selected now, + // if so, clear the resource to clear the SAB data that is no longer required. + // also, set the sequence numbers to 0 so that we know the SAB should be re-fetched in its entirety the next time we do load it + TQString sab = mResource->prefs()->systemAddressBook(); + if ( ( mReadAddressBookIds.find( sab ) != mReadAddressBookIds.end() ) && ( selectedRead.find( sab ) == selectedRead.end() ) ) + { + mResource->clearCache(); + mResource->prefs()->setLastSequenceNumber( 0 ); + mResource->prefs()->setFirstSequenceNumber( 0 ); + } + selectedWrite = mWriteAddressBookIds[ mAddressBookBox->currentItem() ]; + + mResource->prefs()->setReadAddressBooks( selectedRead ); + mResource->prefs()->setWriteAddressBook( selectedWrite ); +} + +void ResourceGroupwiseConfig::updateAddressBookView() +{ + if ( mAddressBookBox->count() != 0 ) // we loaded it already + saveAddressBookSettings(); + + mAddressBookView->clear(); + mAddressBookBox->clear(); + mWriteAddressBookIds.clear(); + + TQStringList selectedRead = mResource->prefs()->readAddressBooks(); + + GroupWise::AddressBook::List addressBooks = mResource->addressBooks(); + GroupWise::AddressBook::List::ConstIterator abIt; + for ( abIt = addressBooks.begin(); abIt != addressBooks.end(); ++abIt ) { + AddressBookItem *item = new AddressBookItem( mAddressBookView, *abIt ); + if ( selectedRead.find( (*abIt).id ) != selectedRead.end() ) + item->setOn( true ); + + mAddressBookBox->insertItem( (*abIt).name ); + mWriteAddressBookIds.append( (*abIt).id ); + } + + int index = mWriteAddressBookIds.findIndex( mResource->prefs()->writeAddressBook() ); + mAddressBookBox->setCurrentItem( index ); +} + +#include "kabc_resourcegroupwiseconfig.moc" diff --git a/tderesources/groupwise/tdeabc_resourcegroupwiseconfig.h b/tderesources/groupwise/tdeabc_resourcegroupwiseconfig.h new file mode 100644 index 000000000..eb54803c0 --- /dev/null +++ b/tderesources/groupwise/tdeabc_resourcegroupwiseconfig.h @@ -0,0 +1,74 @@ +/* + 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_RESOURCEGROUPWISECONFIG_H +#define KABC_RESOURCEGROUPWISECONFIG_H + +#include "soap/groupwiseserver.h" + +#include +#include + +#include + +class KComboBox; +class KLineEdit; +class TDEListView; +class KURLRequester; + +namespace KABC { + +class ResourceGroupwise; + +class KDE_EXPORT ResourceGroupwiseConfig : public KRES::ConfigWidget +{ + Q_OBJECT + + + public: + ResourceGroupwiseConfig( TQWidget* parent = 0, const char* name = 0 ); + + public slots: + void loadSettings( KRES::Resource* ); + void saveSettings( KRES::Resource* ); + + protected slots: + void updateAddressBookList(); + + private: + void updateAddressBookView(); + void saveAddressBookSettings(); + void loadAddressBookSettings(); + void saveServerSettings( ResourceGroupwise *resource ); + + KURLRequester *mURL; + KLineEdit *mUser; + KLineEdit *mPassword; + + TDEListView *mAddressBookView; + KComboBox *mAddressBookBox; + + TQStringList mWriteAddressBookIds; + TQStringList mReadAddressBookIds; + ResourceGroupwise *mResource; +}; + +} + +#endif diff --git a/tderesources/groupwise/tderesources_kabc_groupwise.kcfg b/tderesources/groupwise/tderesources_kabc_groupwise.kcfg deleted file mode 100644 index 6bc3e4c3c..000000000 --- a/tderesources/groupwise/tderesources_kabc_groupwise.kcfg +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - URL of SOAP interface of GroupWise server - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - kmail,kaddressbook,kontact - - - diff --git a/tderesources/groupwise/tderesources_tdeabc_groupwise.kcfg b/tderesources/groupwise/tderesources_tdeabc_groupwise.kcfg new file mode 100644 index 000000000..188e50d9f --- /dev/null +++ b/tderesources/groupwise/tderesources_tdeabc_groupwise.kcfg @@ -0,0 +1,55 @@ + + + + + + + URL of SOAP interface of GroupWise server + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + kmail,kaddressbook,kontact + + + -- cgit v1.2.1