You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
695 lines
22 KiB
695 lines
22 KiB
15 years ago
|
/*
|
||
|
This file is part of libkabc and/or kaddressbook.
|
||
|
Copyright (c) 2002 - 2004 Klarälvdalens Datakonsult AB
|
||
|
<info@klaralvdalens-datakonsult.se>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
In addition, as a special exception, the copyright holders give
|
||
|
permission to link the code of this program with any edition of
|
||
14 years ago
|
the TQt library by Trolltech AS, Norway (or with modified versions
|
||
|
of TQt that use the same license as TQt), and distribute linked
|
||
15 years ago
|
combinations including the two. You must obey the GNU General
|
||
|
Public License in all respects for all of the code used other than
|
||
14 years ago
|
TQt. If you modify this file, you may extend this exception to
|
||
15 years ago
|
your version of the file, but you are not obligated to do so. If
|
||
|
you do not wish to do so, delete this exception statement from
|
||
|
your version.
|
||
|
*/
|
||
|
|
||
|
#include "resourcekolab.h"
|
||
|
#include "contact.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
|
#include <tdetempfile.h>
|
||
12 years ago
|
#include <tdeio/observer.h>
|
||
|
#include <tdeio/uiserver_stub.h>
|
||
12 years ago
|
#include <tdeabc/vcardconverter.h>
|
||
12 years ago
|
#include <tdemainwindow.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <dcopclient.h>
|
||
|
|
||
15 years ago
|
#include <tqobject.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqfile.h>
|
||
|
#include <tqapplication.h>
|
||
15 years ago
|
|
||
|
#include <assert.h>
|
||
|
|
||
|
using namespace Kolab;
|
||
|
|
||
|
class KolabFactory : public KRES::PluginFactoryBase
|
||
|
{
|
||
|
public:
|
||
12 years ago
|
KRES::Resource *resource( const TDEConfig *config )
|
||
15 years ago
|
{
|
||
|
return new KABC::ResourceKolab( config );
|
||
|
}
|
||
|
|
||
15 years ago
|
KRES::ConfigWidget *configWidget( TQWidget* )
|
||
15 years ago
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdeabc_kolab,KolabFactory)
|
||
15 years ago
|
|
||
|
static const char* s_kmailContentsType = "Contact";
|
||
|
static const char* s_attachmentMimeTypeContact = "application/x-vnd.kolab.contact";
|
||
|
static const char* s_attachmentMimeTypeDistList = "application/x-vnd.kolab.contact.distlist";
|
||
|
static const char* s_inlineMimeType = "text/x-vcard";
|
||
|
|
||
12 years ago
|
KABC::ResourceKolab::ResourceKolab( const TDEConfig *config )
|
||
15 years ago
|
: KPIM::ResourceABC( config ),
|
||
|
Kolab::ResourceKolabBase( "ResourceKolab-KABC" ),
|
||
14 years ago
|
mCachedSubresource( TQString() ), mCachedSubresourceNotFound( false ), mLocked( false )
|
||
15 years ago
|
{
|
||
|
setType( "imap" );
|
||
14 years ago
|
if ( !config ) {
|
||
|
setResourceName( i18n( "Kolab Server" ) );
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
KABC::ResourceKolab::~ResourceKolab()
|
||
|
{
|
||
|
// The resource is deleted on exit (StdAddressBook's KStaticDeleter),
|
||
|
// and it wasn't closed before that, so close here to save the config.
|
||
|
if ( isOpen() ) {
|
||
|
close();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void KABC::ResourceKolab::loadSubResourceConfig( TDEConfig& config,
|
||
15 years ago
|
const TQString& name,
|
||
|
const TQString& label,
|
||
15 years ago
|
bool writable )
|
||
|
{
|
||
12 years ago
|
TDEConfigGroup group( &config, name );
|
||
15 years ago
|
bool active = group.readBoolEntry( "Active", true );
|
||
|
int completionWeight = group.readNumEntry( "CompletionWeight", 80 );
|
||
|
mSubResources.insert( name, Kolab::SubResource( active, writable, label,
|
||
|
completionWeight ) );
|
||
|
}
|
||
|
|
||
|
bool KABC::ResourceKolab::doOpen()
|
||
|
{
|
||
12 years ago
|
TDEConfig config( configFile() );
|
||
15 years ago
|
|
||
|
// Read the calendar entries
|
||
15 years ago
|
TQValueList<KMailICalIface::SubResource> subResources;
|
||
15 years ago
|
if ( !kmailSubresources( subResources, s_kmailContentsType ) )
|
||
|
return false;
|
||
|
mSubResources.clear();
|
||
15 years ago
|
TQValueList<KMailICalIface::SubResource>::ConstIterator it;
|
||
15 years ago
|
for ( it = subResources.begin(); it != subResources.end(); ++it ) {
|
||
|
loadSubResourceConfig( config, (*it).location, (*it).label, (*it).writable );
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void KABC::ResourceKolab::doClose()
|
||
|
{
|
||
14 years ago
|
writeConfig();
|
||
15 years ago
|
}
|
||
|
|
||
|
KABC::Ticket * KABC::ResourceKolab::requestSaveTicket()
|
||
|
{
|
||
|
if ( !addressBook() ) {
|
||
|
kdError() << "no addressbook" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
mLocked = true;
|
||
|
|
||
|
return createTicket( this );
|
||
|
}
|
||
|
|
||
|
void KABC::ResourceKolab::releaseSaveTicket( Ticket* ticket )
|
||
|
{
|
||
|
mLocked = false;
|
||
14 years ago
|
mCachedSubresource = TQString();
|
||
14 years ago
|
mCachedSubresourceNotFound = false;
|
||
15 years ago
|
delete ticket;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KABC::ResourceKolab::loadContact( const TQString& contactData,
|
||
|
const TQString& subResource,
|
||
14 years ago
|
TQ_UINT32 sernum,
|
||
15 years ago
|
KMailICalIface::StorageFormat format )
|
||
|
{
|
||
|
KABC::Addressee addr;
|
||
|
if ( format == KMailICalIface::StorageXML ) {
|
||
|
Contact contact( contactData, this, subResource, sernum ); // load
|
||
|
contact.saveTo( &addr );
|
||
|
} else {
|
||
|
KABC::VCardConverter converter;
|
||
14 years ago
|
#if defined(KABC_VCARD_ENCODING_FIX)
|
||
|
addr = converter.parseVCardRaw( contactData.utf8() );
|
||
|
#else
|
||
15 years ago
|
addr = converter.parseVCard( contactData );
|
||
14 years ago
|
#endif
|
||
15 years ago
|
}
|
||
|
|
||
|
addr.setResource( this );
|
||
|
addr.setChanged( false );
|
||
|
KABC::Resource::insertAddressee( addr ); // same as mAddrMap.insert( addr.uid(), addr );
|
||
|
mUidMap[ addr.uid() ] = StorageReference( subResource, sernum );
|
||
|
kdDebug(5650) << "Loaded contact uid=" << addr.uid() << " sernum=" << sernum << " fullName=" << addr.name() << endl;
|
||
|
return addr.uid();
|
||
|
}
|
||
|
|
||
|
static const struct { const char* mimetype; KMailICalIface::StorageFormat format; } s_formats[] =
|
||
|
{
|
||
|
{ s_attachmentMimeTypeContact, KMailICalIface::StorageXML },
|
||
|
{ s_attachmentMimeTypeDistList, KMailICalIface::StorageXML },
|
||
|
{ s_inlineMimeType, KMailICalIface::StorageIcalVcard }
|
||
|
};
|
||
|
|
||
15 years ago
|
bool KABC::ResourceKolab::loadSubResource( const TQString& subResource )
|
||
15 years ago
|
{
|
||
|
int count = 0;
|
||
14 years ago
|
if ( !kmailIncidencesCount( count, TQString(), subResource ) ) {
|
||
15 years ago
|
kdError() << "Communication problem in KABC::ResourceKolab::loadSubResource()\n";
|
||
|
return false;
|
||
|
}
|
||
|
if ( !count )
|
||
|
return true;
|
||
|
|
||
|
// Read that many contacts at a time.
|
||
|
// If this number is too small we lose time in kmail.
|
||
|
// If it's too big the progressbar is jumpy.
|
||
|
const int nbMessages = 200;
|
||
|
|
||
12 years ago
|
(void)Observer::self(); // ensure tdeio_uiserver is running
|
||
|
UIServer_stub uiserver( "tdeio_uiserver", "UIServer" );
|
||
15 years ago
|
int progressId = 0;
|
||
|
if ( count > 200 ) {
|
||
|
progressId = uiserver.newJob( kapp->dcopClient()->appId(), true );
|
||
|
uiserver.totalFiles( progressId, count );
|
||
|
uiserver.infoMessage( progressId, i18n( "Loading contacts..." ) );
|
||
|
uiserver.transferring( progressId, "Contacts" );
|
||
|
}
|
||
|
|
||
|
for ( int startIndex = 0; startIndex < count; startIndex += nbMessages ) {
|
||
|
|
||
|
// TODO it would be faster to pass the s_formats array to kmail and let it load
|
||
|
// all events - to avoid loading each mail 3 times. But then we need to extend the returned
|
||
15 years ago
|
// TQMap to also tell us the StorageFormat of each found contact...
|
||
15 years ago
|
for ( int indexFormat = 0; indexFormat < 3; ++indexFormat ) {
|
||
|
const char* mimetype = s_formats[indexFormat].mimetype;
|
||
|
KMailICalIface::StorageFormat format = s_formats[indexFormat].format;
|
||
14 years ago
|
TQMap<TQ_UINT32, TQString> lst;
|
||
15 years ago
|
if ( !kmailIncidences( lst, mimetype, subResource, startIndex, nbMessages ) ) {
|
||
|
kdError() << "Communication problem in KABC::ResourceKolab::loadSubResource()\n";
|
||
|
if ( progressId )
|
||
|
uiserver.jobFinished( progressId );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
for( TQMap<TQ_UINT32, TQString>::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
|
||
15 years ago
|
loadContact( it.data(), subResource, it.key(), format );
|
||
|
}
|
||
|
|
||
|
}
|
||
|
if ( progressId ) {
|
||
|
uiserver.processedFiles( progressId, startIndex );
|
||
|
uiserver.percent( progressId, 100 * startIndex / count );
|
||
|
}
|
||
|
|
||
|
// if ( progress.wasCanceled() ) {
|
||
|
// uiserver.jobFinished( progressId );
|
||
|
// return false;
|
||
|
// }
|
||
|
|
||
|
}
|
||
|
|
||
|
kdDebug(5650) << "Contacts kolab resource: got " << count << " contacts in " << subResource << endl;
|
||
|
|
||
|
if ( progressId )
|
||
|
uiserver.jobFinished( progressId );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool KABC::ResourceKolab::load()
|
||
|
{
|
||
|
mUidMap.clear();
|
||
|
mAddrMap.clear();
|
||
|
|
||
|
bool rc = true;
|
||
|
Kolab::ResourceMap::ConstIterator itR;
|
||
|
for ( itR = mSubResources.begin(); itR != mSubResources.end(); ++itR ) {
|
||
|
if ( !itR.data().active() )
|
||
|
// This resource is disabled
|
||
|
continue;
|
||
|
|
||
|
rc &= loadSubResource( itR.key() );
|
||
|
}
|
||
|
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
bool KABC::ResourceKolab::save( Ticket* )
|
||
|
{
|
||
|
bool rc = true;
|
||
|
|
||
|
for( ConstIterator it = begin(); it != end(); ++it )
|
||
|
if( (*it).changed() ) {
|
||
|
rc &= kmailUpdateAddressee( *it );
|
||
|
}
|
||
|
|
||
|
if ( !rc )
|
||
|
kdDebug(5650) << k_funcinfo << " failed." << endl;
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
namespace Kolab {
|
||
|
struct AttachmentList {
|
||
15 years ago
|
TQStringList attachmentURLs;
|
||
|
TQStringList attachmentNames;
|
||
|
TQStringList attachmentMimeTypes;
|
||
|
TQStringList deletedAttachments;
|
||
|
TQValueList<KTempFile *> tempFiles;
|
||
15 years ago
|
|
||
15 years ago
|
void addAttachment( const TQString& url, const TQString& name, const TQString& mimetype ) {
|
||
15 years ago
|
attachmentURLs.append( url );
|
||
|
attachmentNames.append( name );
|
||
|
attachmentMimeTypes.append( mimetype );
|
||
|
}
|
||
|
|
||
15 years ago
|
void updatePictureAttachment( const TQImage& image, const TQString& name );
|
||
|
void updateAttachment( const TQByteArray& data, const TQString& name, const char* mimetype );
|
||
15 years ago
|
};
|
||
|
} // namespace
|
||
|
|
||
15 years ago
|
void AttachmentList::updatePictureAttachment( const TQImage& image, const TQString& name )
|
||
15 years ago
|
{
|
||
|
assert( !name.isEmpty() );
|
||
|
if ( !image.isNull() ) {
|
||
14 years ago
|
KTempFile tempFile;
|
||
|
image.save( tempFile.file(), "PNG" );
|
||
|
tempFile.close();
|
||
15 years ago
|
KURL url;
|
||
14 years ago
|
url.setPath( tempFile.name() );
|
||
15 years ago
|
kdDebug(5650) << "picture saved to " << url.path() << endl;
|
||
|
addAttachment( url.url(), name, "image/png" );
|
||
|
} else {
|
||
|
deletedAttachments.append( name );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void AttachmentList::updateAttachment( const TQByteArray& data, const TQString& name, const char* mimetype )
|
||
15 years ago
|
{
|
||
|
assert( !name.isEmpty() );
|
||
|
if ( !data.isNull() ) {
|
||
14 years ago
|
KTempFile tempFile;
|
||
|
tempFile.file()->writeBlock( data );
|
||
|
tempFile.close();
|
||
15 years ago
|
KURL url;
|
||
14 years ago
|
url.setPath( tempFile.name() );
|
||
15 years ago
|
kdDebug(5650) << "data saved to " << url.path() << endl;
|
||
|
addAttachment( url.url(), name, mimetype );
|
||
|
} else {
|
||
|
deletedAttachments.append( name );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool KABC::ResourceKolab::kmailUpdateAddressee( const Addressee& addr )
|
||
|
{
|
||
15 years ago
|
const TQString uid = addr.uid();
|
||
|
TQString subResource;
|
||
14 years ago
|
TQ_UINT32 sernum;
|
||
13 years ago
|
if ( mUidMap.find( uid ) != mUidMap.end() ) {
|
||
15 years ago
|
subResource = mUidMap[ uid ].resource();
|
||
|
if ( !subresourceWritable( subResource ) ) {
|
||
|
kdWarning() << "Wow! Something tried to update a non-writable addressee! Fix this caller: " << kdBacktrace() << endl;
|
||
|
return false;
|
||
|
}
|
||
|
sernum = mUidMap[ uid ].serialNumber();
|
||
|
} else {
|
||
14 years ago
|
if ( !mCachedSubresource.isNull() || mCachedSubresourceNotFound ) {
|
||
15 years ago
|
subResource = mCachedSubresource;
|
||
|
} else {
|
||
14 years ago
|
subResource = findWritableResource( Kolab::Contacts, mSubResources );
|
||
15 years ago
|
// We were locked, remember the subresource we are working with until
|
||
|
// we are unlocked
|
||
14 years ago
|
if ( mLocked ) {
|
||
15 years ago
|
mCachedSubresource = subResource;
|
||
14 years ago
|
|
||
|
// If the subresource is empty here, it means findWritableResource() failed, for example
|
||
|
// because the user cancelled the resource selection dialog. Remember that, so we avoid
|
||
|
// asking multiple times when locked.
|
||
|
mCachedSubresourceNotFound = subResource.isEmpty();
|
||
|
}
|
||
15 years ago
|
}
|
||
|
if ( subResource.isEmpty() )
|
||
|
return false;
|
||
|
sernum = 0;
|
||
|
}
|
||
15 years ago
|
TQString data;
|
||
|
TQString mimetype;
|
||
15 years ago
|
AttachmentList att;
|
||
|
bool isXMLStorageFormat = kmailStorageFormat( subResource ) == KMailICalIface::StorageXML;
|
||
15 years ago
|
TQString subject = uid; // as per kolab2 spec
|
||
15 years ago
|
if ( isXMLStorageFormat ) {
|
||
|
Contact contact( &addr );
|
||
|
// The addressee is converted to: 1) the xml 2) the optional picture 3) the optional logo 4) the optional sound
|
||
|
data = contact.saveXML();
|
||
|
att.updatePictureAttachment( contact.picture(), contact.pictureAttachmentName() );
|
||
|
att.updatePictureAttachment( contact.logo(), contact.logoAttachmentName() );
|
||
|
// no way to know the mimetype. The addressee editor allows to attach _any_ kind of file,
|
||
|
// and the sound system sorts it out.
|
||
|
att.updateAttachment( contact.sound(), contact.soundAttachmentName(), "audio/unknown" );
|
||
|
mimetype = contact.isDistributionList() ?
|
||
|
s_attachmentMimeTypeDistList : s_attachmentMimeTypeContact;
|
||
|
} else {
|
||
|
mimetype = s_inlineMimeType;
|
||
|
KABC::VCardConverter converter;
|
||
14 years ago
|
#if defined(KABC_VCARD_ENCODING_FIX)
|
||
|
data = TQString::fromUtf8( converter.createVCardRaw( addr ) );
|
||
|
#else
|
||
15 years ago
|
data = converter.createVCard( addr );
|
||
14 years ago
|
#endif
|
||
15 years ago
|
subject.prepend( "vCard " ); // as per kolab1 spec
|
||
|
}
|
||
|
bool rc = kmailUpdate( subResource, sernum, data, mimetype, subject,
|
||
|
CustomHeaderMap(),
|
||
|
att.attachmentURLs, att.attachmentMimeTypes, att.attachmentNames,
|
||
|
att.deletedAttachments );
|
||
|
if ( !rc )
|
||
|
kdDebug(5650) << "kmailUpdate returned false!" << endl;
|
||
|
if ( rc ) {
|
||
|
kdDebug(5650) << "kmailUpdate returned, now sernum=" << sernum << " for uid=" << uid << endl;
|
||
|
mUidMap[ uid ] = StorageReference( subResource, sernum );
|
||
|
// This is ugly, but it's faster than doing
|
||
13 years ago
|
// mAddrMap.find(addr.uid()), which would give the same :-(
|
||
15 years ago
|
// Reason for this: The Changed attribute of Addressee should
|
||
|
// be mutable
|
||
|
const_cast<Addressee&>(addr).setChanged( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
for( TQValueList<KTempFile *>::Iterator it = att.tempFiles.begin(); it != att.tempFiles.end(); ++it ) {
|
||
15 years ago
|
(*it)->setAutoDelete( true );
|
||
|
delete (*it);
|
||
|
}
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
void KABC::ResourceKolab::insertAddressee( const Addressee& addr )
|
||
|
{
|
||
15 years ago
|
const TQString uid = addr.uid();
|
||
15 years ago
|
//kdDebug(5650) << k_funcinfo << uid << endl;
|
||
|
bool ok = false;
|
||
13 years ago
|
if ( mUidMap.contains( uid ) ) {
|
||
15 years ago
|
mUidsPendingUpdate.append( uid );
|
||
|
} else {
|
||
|
mUidsPendingAdding.append( uid );
|
||
|
}
|
||
|
|
||
|
ok = kmailUpdateAddressee( addr );
|
||
|
|
||
|
if ( ok )
|
||
|
Resource::insertAddressee( addr );
|
||
|
}
|
||
|
|
||
|
void KABC::ResourceKolab::removeAddressee( const Addressee& addr )
|
||
|
{
|
||
15 years ago
|
const TQString uid = addr.uid();
|
||
13 years ago
|
if ( mUidMap.find( uid ) == mUidMap.end() ) return;
|
||
15 years ago
|
//kdDebug(5650) << k_funcinfo << uid << endl;
|
||
15 years ago
|
const TQString resource = mUidMap[ uid ].resource();
|
||
15 years ago
|
if ( !subresourceWritable( resource ) ) {
|
||
|
kdWarning() << "Wow! Something tried to delete a non-writable addressee! Fix this caller: " << kdBacktrace() << endl;
|
||
|
return;
|
||
|
}
|
||
|
/* The user told us to delete, tell KMail */
|
||
|
kmailDeleteIncidence( resource,
|
||
|
mUidMap[ uid ].serialNumber() );
|
||
|
mUidsPendingDeletion.append( uid );
|
||
|
mUidMap.remove( uid );
|
||
|
|
||
|
Resource::removeAddressee( addr );
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* These are the DCOP slots that KMail call to notify when something
|
||
|
* changed.
|
||
|
*/
|
||
15 years ago
|
bool KABC::ResourceKolab::fromKMailAddIncidence( const TQString& type,
|
||
|
const TQString& subResource,
|
||
14 years ago
|
TQ_UINT32 sernum,
|
||
15 years ago
|
int format,
|
||
15 years ago
|
const TQString& contactXML )
|
||
15 years ago
|
{
|
||
|
// Check if this is a contact
|
||
|
if( type != s_kmailContentsType || !subresourceActive( subResource ) )
|
||
|
return false;
|
||
|
|
||
|
// Load contact to find the UID
|
||
15 years ago
|
const TQString uid = loadContact( contactXML, subResource, sernum,
|
||
15 years ago
|
( KMailICalIface::StorageFormat )format );
|
||
|
|
||
|
//kdDebug(5650) << k_funcinfo << uid << endl;
|
||
|
|
||
|
// Emit "addressbook changed" if this comes from kmail and not from the GUI
|
||
13 years ago
|
if ( !mUidsPendingAdding.contains( uid )
|
||
|
&& !mUidsPendingUpdate.contains( uid ) ) {
|
||
15 years ago
|
addressBook()->emitAddressBookChanged();
|
||
|
} else {
|
||
|
mUidsPendingAdding.remove( uid );
|
||
|
mUidsPendingUpdate.remove( uid );
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KABC::ResourceKolab::fromKMailDelIncidence( const TQString& type,
|
||
|
const TQString& subResource,
|
||
|
const TQString& uid )
|
||
15 years ago
|
{
|
||
|
// Check if this is a contact
|
||
|
if( type != s_kmailContentsType || !subresourceActive( subResource ) )
|
||
|
return;
|
||
|
|
||
|
//kdDebug(5650) << k_funcinfo << uid << endl;
|
||
|
|
||
|
// Can't be in both, by contract
|
||
13 years ago
|
if ( mUidsPendingDeletion.contains( uid ) ) {
|
||
15 years ago
|
mUidsPendingDeletion.remove( uid );
|
||
13 years ago
|
} else if ( mUidsPendingUpdate.contains( uid ) ) {
|
||
15 years ago
|
// It's good to know if was deleted, but we are waiting on a new one to
|
||
14 years ago
|
// replace it, so let's just sit tight.
|
||
15 years ago
|
} else {
|
||
|
// We didn't trigger this, so KMail did, remove the reference to the uid
|
||
|
mAddrMap.remove( uid );
|
||
|
mUidMap.remove( uid );
|
||
|
addressBook()->emitAddressBookChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KABC::ResourceKolab::fromKMailRefresh( const TQString& type,
|
||
|
const TQString& /*subResource*/ )
|
||
15 years ago
|
{
|
||
|
// Check if this is a contact
|
||
|
if( type != s_kmailContentsType ) return;
|
||
|
|
||
|
//kdDebug(5650) << k_funcinfo << endl;
|
||
|
|
||
|
load(); // ### should call loadSubResource(subResource) probably
|
||
|
addressBook()->emitAddressBookChanged();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KABC::ResourceKolab::fromKMailAddSubresource( const TQString& type,
|
||
|
const TQString& subResource,
|
||
|
const TQString& label,
|
||
15 years ago
|
bool writable,
|
||
|
bool )
|
||
|
{
|
||
|
if( type != s_kmailContentsType ) return;
|
||
|
|
||
13 years ago
|
if ( mSubResources.contains( subResource ) )
|
||
15 years ago
|
// Already registered
|
||
|
return;
|
||
|
|
||
12 years ago
|
TDEConfig config( configFile() );
|
||
15 years ago
|
config.setGroup( "Contact" );
|
||
|
loadSubResourceConfig( config, subResource, label, writable );
|
||
|
loadSubResource( subResource );
|
||
|
addressBook()->emitAddressBookChanged();
|
||
|
emit signalSubresourceAdded( this, type, subResource );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KABC::ResourceKolab::fromKMailDelSubresource( const TQString& type,
|
||
|
const TQString& subResource )
|
||
15 years ago
|
{
|
||
|
if( type != s_kmailContentsType ) return;
|
||
|
|
||
13 years ago
|
if ( !mSubResources.contains( subResource ) )
|
||
15 years ago
|
// Not registered
|
||
|
return;
|
||
|
|
||
|
// Ok, it's our job, and we have it here
|
||
|
mSubResources.erase( subResource );
|
||
|
|
||
12 years ago
|
TDEConfig config( configFile() );
|
||
15 years ago
|
config.deleteGroup( subResource );
|
||
|
config.sync();
|
||
|
|
||
|
// Make a list of all uids to remove
|
||
|
Kolab::UidMap::ConstIterator mapIt;
|
||
15 years ago
|
TQStringList uids;
|
||
15 years ago
|
for ( mapIt = mUidMap.begin(); mapIt != mUidMap.end(); ++mapIt )
|
||
|
if ( mapIt.data().resource() == subResource )
|
||
|
// We have a match
|
||
|
uids << mapIt.key();
|
||
|
|
||
|
// Finally delete all the incidences
|
||
|
if ( !uids.isEmpty() ) {
|
||
15 years ago
|
TQStringList::ConstIterator it;
|
||
15 years ago
|
for ( it = uids.begin(); it != uids.end(); ++it ) {
|
||
|
mAddrMap.remove( *it );
|
||
|
mUidMap.remove( *it );
|
||
|
}
|
||
|
|
||
|
addressBook()->emitAddressBookChanged();
|
||
|
}
|
||
|
|
||
|
emit signalSubresourceRemoved( this, type, subResource );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
14 years ago
|
void KABC::ResourceKolab::fromKMailAsyncLoadResult( const TQMap<TQ_UINT32, TQString>& map,
|
||
15 years ago
|
const TQString& /* type */,
|
||
|
const TQString& folder )
|
||
15 years ago
|
{
|
||
|
// FIXME
|
||
|
KMailICalIface::StorageFormat format = KMailICalIface::StorageXML;
|
||
14 years ago
|
for( TQMap<TQ_UINT32, TQString>::ConstIterator it = map.begin(); it != map.end(); ++it ) {
|
||
15 years ago
|
loadContact( it.data(), folder, it.key(), format );
|
||
|
}
|
||
|
if ( !addressBook() ){
|
||
|
kdDebug(5650) << "asyncLoadResult() : addressBook() returning NULL pointer.\n";
|
||
|
}else
|
||
|
addressBook()->emitAddressBookChanged();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KABC::ResourceKolab::subresources() const
|
||
15 years ago
|
{
|
||
|
return mSubResources.keys();
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KABC::ResourceKolab::subresourceActive( const TQString& subresource ) const
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( mSubResources.contains( subresource ) ) {
|
||
15 years ago
|
return mSubResources[ subresource ].active();
|
||
|
}
|
||
|
|
||
|
// Safe default bet:
|
||
|
kdDebug(5650) << "subresourceActive( " << subresource << " ): Safe bet\n";
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KABC::ResourceKolab::subresourceWritable( const TQString& subresource ) const
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( mSubResources.contains( subresource ) ) {
|
||
15 years ago
|
return mSubResources[ subresource ].writable();
|
||
|
}
|
||
|
return false; //better a safe default
|
||
|
}
|
||
|
|
||
15 years ago
|
int KABC::ResourceKolab::subresourceCompletionWeight( const TQString& subresource ) const
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( mSubResources.contains( subresource ) ) {
|
||
15 years ago
|
return mSubResources[ subresource ].completionWeight();
|
||
|
}
|
||
|
|
||
|
kdDebug(5650) << "subresourceCompletionWeight( " << subresource << " ): not found, using default\n";
|
||
|
|
||
|
return 80;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KABC::ResourceKolab::subresourceLabel( const TQString& subresource ) const
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( mSubResources.contains( subresource ) ) {
|
||
15 years ago
|
return mSubResources[ subresource ].label();
|
||
|
}
|
||
|
|
||
|
kdDebug(5650) << "subresourceLabel( " << subresource << " ): not found!\n";
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KABC::ResourceKolab::setSubresourceCompletionWeight( const TQString& subresource, int completionWeight )
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( mSubResources.contains( subresource ) ) {
|
||
15 years ago
|
mSubResources[ subresource ].setCompletionWeight( completionWeight );
|
||
|
} else {
|
||
|
kdDebug(5650) << "setSubresourceCompletionWeight: subresource " << subresource << " not found" << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQMap<TQString, TQString> KABC::ResourceKolab::uidToResourceMap() const
|
||
15 years ago
|
{
|
||
|
// TODO: Couldn't this be made simpler?
|
||
15 years ago
|
TQMap<TQString, TQString> map;
|
||
15 years ago
|
Kolab::UidMap::ConstIterator mapIt;
|
||
|
for ( mapIt = mUidMap.begin(); mapIt != mUidMap.end(); ++mapIt )
|
||
|
map[ mapIt.key() ] = mapIt.data().resource();
|
||
|
return map;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KABC::ResourceKolab::setSubresourceActive( const TQString &subresource, bool active )
|
||
15 years ago
|
{
|
||
13 years ago
|
if ( mSubResources.contains( subresource ) ) {
|
||
15 years ago
|
mSubResources[ subresource ].setActive( active );
|
||
|
load();
|
||
|
} else {
|
||
|
kdDebug(5650) << "setSubresourceCompletionWeight: subresource " << subresource << " not found" << endl;
|
||
|
}
|
||
14 years ago
|
writeConfig();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
/*virtual*/
|
||
13 years ago
|
bool KABC::ResourceKolab::addSubresource( const TQString& label, const TQString& parent )
|
||
15 years ago
|
{
|
||
13 years ago
|
return kmailAddSubresource( label, parent, s_kmailContentsType );
|
||
15 years ago
|
}
|
||
|
|
||
|
/*virtual*/
|
||
15 years ago
|
bool KABC::ResourceKolab::removeSubresource( const TQString& id )
|
||
15 years ago
|
{
|
||
|
return kmailRemoveSubresource( id );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KABC::ResourceKolab::writeConfig()
|
||
|
{
|
||
12 years ago
|
TDEConfig config( configFile() );
|
||
14 years ago
|
|
||
|
Kolab::ResourceMap::ConstIterator it;
|
||
|
for ( it = mSubResources.constBegin(); it != mSubResources.constEnd(); ++it ) {
|
||
|
config.setGroup( it.key() );
|
||
|
config.writeEntry( "Active", it.data().active() );
|
||
|
config.writeEntry( "CompletionWeight", it.data().completionWeight() );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
#include "resourcekolab.moc"
|