From cc29364f06178f8f6b457384f2ec37a042bd9d43 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 1 Sep 2010 00:37:02 +0000 Subject: * Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch * Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed * Added journal read support to the CalDAV resource * Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kresources/kolab/kabc/contact.cpp | 72 +++-- kresources/kolab/kabc/contact.h | 7 +- kresources/kolab/kabc/kolab.desktop | 1 - kresources/kolab/kabc/resourcekolab.cpp | 64 ++-- kresources/kolab/kabc/resourcekolab.h | 3 + kresources/kolab/kcal/event.cpp | 7 +- kresources/kolab/kcal/incidence.cpp | 248 +++++++++++++-- kresources/kolab/kcal/incidence.h | 9 +- kresources/kolab/kcal/kolab.desktop | 1 - kresources/kolab/kcal/resourcekolab.cpp | 437 ++++++++++++++++++-------- kresources/kolab/kcal/resourcekolab.h | 64 +++- kresources/kolab/kcal/task.cpp | 171 ++++++++-- kresources/kolab/kcal/task.h | 16 +- kresources/kolab/knotes/kolabresource.desktop | 1 - kresources/kolab/knotes/note.cpp | 41 ++- kresources/kolab/knotes/resourcekolab.cpp | 92 ++++-- kresources/kolab/knotes/resourcekolab.h | 3 + kresources/kolab/shared/kmailconnection.cpp | 40 ++- kresources/kolab/shared/kolabbase.cpp | 19 +- kresources/kolab/shared/resourcekolabbase.cpp | 38 ++- kresources/kolab/shared/resourcekolabbase.h | 12 +- 21 files changed, 1039 insertions(+), 307 deletions(-) (limited to 'kresources/kolab') diff --git a/kresources/kolab/kabc/contact.cpp b/kresources/kolab/kabc/contact.cpp index fc9087316..26a91e679 100644 --- a/kresources/kolab/kabc/contact.cpp +++ b/kresources/kolab/kabc/contact.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -222,15 +223,15 @@ TQString Contact::profession() const return mProfession; } -// void Contact::setJobTitle( const TQString& title ) -// { -// mJobTitle = title; -// } +void Contact::setJobTitle( const TQString& title ) +{ + mJobTitle = title; +} -// TQString Contact::jobTitle() const -// { -// return mJobTitle; -// } +TQString Contact::jobTitle() const +{ + return mJobTitle; +} void Contact::setManagerName( const TQString& name ) { @@ -485,6 +486,11 @@ void Contact::saveCustomAttributes( TQDomElement& element ) const if ( (*it).app == s_unhandledTagAppName ) { writeString( element, (*it).name, (*it).value ); } else { + // skip writing the freebusyurl as it is a hack we need to remove eventually + if ( (*it).name == TQString::fromLatin1( "FreeBusyURL" ) ) { + continue; + } + // Let's use attributes so that other tag-preserving-code doesn't need sub-elements TQDomElement e = element.ownerDocument().createElement( "x-custom" ); element.appendChild( e ); @@ -659,7 +665,7 @@ bool Contact::loadAttribute( TQDomElement& element ) case 'j': if ( tagName == "job-title" ) { // see saveAttributes: is mapped to the Role field - setRole( element.text() ); + setJobTitle( element.text() ); return true; } break; @@ -766,7 +772,6 @@ bool Contact::saveAttributes( TQDomElement& element ) const { // Save the base class elements KolabBase::saveAttributes( element ); - if ( mIsDistributionList ) { writeString( element, "display-name", fullName() ); saveDistrListMembers( element ); @@ -779,11 +784,8 @@ bool Contact::saveAttributes( TQDomElement& element ) const writeString( element, "department", department() ); writeString( element, "office-location", officeLocation() ); writeString( element, "profession", profession() ); - // is gone; jobTitle() is not shown in the addresseeeditor, - // so let's bind to role() - //writeString( element, "role", role() ); - //writeString( element, "job-title", jobTitle() ); - writeString( element, "job-title", role() ); + writeString( element, "role", role() ); + writeString( element, "job-title", jobTitle() ); writeString( element, "manager-name", managerName() ); writeString( element, "assistant", assistant() ); writeString( element, "nick-name", nickName() ); @@ -891,28 +893,28 @@ static TQStringList phoneTypeToString( int /*KABC::PhoneNumber::Types*/ type ) type = type & ~KABC::PhoneNumber::Work; } - // To support both "home1" and "home2", map Home+Pref to home1 + // To support both "home1" and "home2", map Home+Pref to home2 if ( ( type & KABC::PhoneNumber::Home ) && ( type & KABC::PhoneNumber::Pref ) ) { - types << "home1"; + types << "home2"; type = type & ~KABC::PhoneNumber::Home; type = type & ~KABC::PhoneNumber::Pref; } - // To support both "business1" and "business2", map Work+Pref to business1 + // To support both "business1" and "business2", map Work+Pref to business2 if ( ( type & KABC::PhoneNumber::Work ) && ( type & KABC::PhoneNumber::Pref ) ) { - types << "business1"; + types << "business2"; type = type & ~KABC::PhoneNumber::Work; type = type & ~KABC::PhoneNumber::Pref; } if ( type & KABC::PhoneNumber::Home ) - types << "home2"; + types << "home1"; if ( type & KABC::PhoneNumber::Msg ) // Msg==messaging types << "company"; if ( type & KABC::PhoneNumber::Work ) - types << "business2"; + types << "business1"; if ( type & KABC::PhoneNumber::Pref ) types << "primary"; if ( type & KABC::PhoneNumber::Voice ) @@ -942,13 +944,13 @@ static int /*KABC::PhoneNumber::Types*/ phoneTypeFromString( const TQString& typ return KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax; if ( type == "businessfax" ) return KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax; - if ( type == "business1" ) - return KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref; if ( type == "business2" ) + return KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref; + if ( type == "business1" ) return KABC::PhoneNumber::Work; - if ( type == "home1" ) - return KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref; if ( type == "home2" ) + return KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref; + if ( type == "home1" ) return KABC::PhoneNumber::Home; if ( type == "company" ) return KABC::PhoneNumber::Msg; @@ -1019,11 +1021,15 @@ void Contact::setFields( const KABC::Addressee* addressee ) setOrganization( addressee->organization() ); setWebPage( addressee->url().url() ); setIMAddress( addressee->custom( "KADDRESSBOOK", "X-IMAddress" ) ); +#if KDE_IS_VERSION(3,5,8) + setDepartment( addressee->department()); +#else setDepartment( addressee->custom( "KADDRESSBOOK", "X-Department" ) ); +#endif setOfficeLocation( addressee->custom( "KADDRESSBOOK", "X-Office" ) ); setProfession( addressee->custom( "KADDRESSBOOK", "X-Profession" ) ); setRole( addressee->role() ); - //setJobTitle( addressee->title() ); + setJobTitle( addressee->title() ); setManagerName( addressee->custom( "KADDRESSBOOK", "X-ManagersName" ) ); setAssistant( addressee->custom( "KADDRESSBOOK", "X-AssistantsName" ) ); setNickName( addressee->nickName() ); @@ -1129,6 +1135,11 @@ void Contact::setFields( const KABC::Addressee* addressee ) } } + TQString url = KCal::FreeBusyUrlStore::self()->readUrl( addressee->preferredEmail() ); + if ( !url.isEmpty() ) { + setFreeBusyUrl( url ); + } + // Those fields, although defined in Addressee, are not used in KDE // (e.g. not visible in kaddressbook/addresseeeditorwidget.cpp) // So it doesn't matter much if we don't have them in the XML. @@ -1136,9 +1147,6 @@ void Contact::setFields( const KABC::Addressee* addressee ) // Things KAddressBook can't handle, so they are saved as unhandled tags: // initials, children, gender, language - - // TODO: Free/Busy URL. This is done rather awkward in KAddressBook - - // it stores it in a local file through a korganizer file :-( } // The loading is: xml -> Contact -> addressee, this is the second part @@ -1173,11 +1181,15 @@ void Contact::saveTo( KABC::Addressee* addressee ) addressee->setOrganization( organization() ); addressee->setUrl( webPage() ); addressee->insertCustom( "KADDRESSBOOK", "X-IMAddress", imAddress() ); +#if KDE_IS_VERSION(3,5,8) + addressee->setDepartment( department() ); +#else addressee->insertCustom( "KADDRESSBOOK", "X-Department", department() ); +#endif addressee->insertCustom( "KADDRESSBOOK", "X-Office", officeLocation() ); addressee->insertCustom( "KADDRESSBOOK", "X-Profession", profession() ); addressee->setRole( role() ); - //addressee->setTitle( jobTitle() ); + addressee->setTitle( jobTitle() ); addressee->insertCustom( "KADDRESSBOOK", "X-ManagersName", managerName() ); addressee->insertCustom( "KADDRESSBOOK", "X-AssistantsName", assistant() ); addressee->setNickName( nickName() ); diff --git a/kresources/kolab/kabc/contact.h b/kresources/kolab/kabc/contact.h index 39a235cc2..a9465642f 100644 --- a/kresources/kolab/kabc/contact.h +++ b/kresources/kolab/kabc/contact.h @@ -121,9 +121,8 @@ public: void setProfession( const TQString& profession ); TQString profession() const; - // not shown in the kaddressbook GUI - //void setJobTitle( const TQString& title ); - //TQString jobTitle() const; + void setJobTitle( const TQString& title ); + TQString jobTitle() const; void setManagerName( const TQString& name ); TQString managerName() const; @@ -245,7 +244,7 @@ private: TQString mDepartment; TQString mOfficeLocation; TQString mProfession; - //TQString mJobTitle; + TQString mJobTitle; TQString mManagerName; TQString mAssistant; TQString mNickName; diff --git a/kresources/kolab/kabc/kolab.desktop b/kresources/kolab/kabc/kolab.desktop index d75090a7a..8339f9c22 100644 --- a/kresources/kolab/kabc/kolab.desktop +++ b/kresources/kolab/kabc/kolab.desktop @@ -21,7 +21,6 @@ Name[hu]=IMAP-kiszolgálón tárolt címjegyzék a KMailen keresztül Name[is]=Vistfangaskrá á IMAP þjóni gegnum KMail Name[it]=Rubrica indirizzi su server IMAP via KMail Name[ja]=KMail 経由 IMAP サーバのアドレス帳 -Name[ka]=წიგნაკი IMAP-ის სერვერზე KMail-ის საშუალებით Name[kk]=KMail арқылы IMAP серверіндегі адрестік кітапша Name[km]=សៀវភៅ​អាសយដ្ឋាន​លើ​ម៉ាស៊ីន​បម្រើ IMAP តាម​រយៈ KMail Name[lt]=Adresų knygelė IMAP serveryje per KMail diff --git a/kresources/kolab/kabc/resourcekolab.cpp b/kresources/kolab/kabc/resourcekolab.cpp index 034c32d78..ae8e225fb 100644 --- a/kresources/kolab/kabc/resourcekolab.cpp +++ b/kresources/kolab/kabc/resourcekolab.cpp @@ -79,9 +79,12 @@ static const char* s_inlineMimeType = "text/x-vcard"; KABC::ResourceKolab::ResourceKolab( const KConfig *config ) : KPIM::ResourceABC( config ), Kolab::ResourceKolabBase( "ResourceKolab-KABC" ), - mCachedSubresource( TQString::null ), mLocked( false ) + mCachedSubresource( TQString::null ), mCachedSubresourceNotFound( false ), mLocked( false ) { setType( "imap" ); + if ( !config ) { + setResourceName( i18n( "Kolab Server" ) ); + } } KABC::ResourceKolab::~ResourceKolab() @@ -124,14 +127,7 @@ bool KABC::ResourceKolab::doOpen() void KABC::ResourceKolab::doClose() { - KConfig config( configFile() ); - - Kolab::ResourceMap::ConstIterator it; - for ( it = mSubResources.begin(); it != mSubResources.end(); ++it ) { - config.setGroup( it.key() ); - config.writeEntry( "Active", it.data().active() ); - config.writeEntry( "CompletionWeight", it.data().completionWeight() ); - } + writeConfig(); } KABC::Ticket * KABC::ResourceKolab::requestSaveTicket() @@ -149,6 +145,7 @@ void KABC::ResourceKolab::releaseSaveTicket( Ticket* ticket ) { mLocked = false; mCachedSubresource = TQString::null; + mCachedSubresourceNotFound = false; delete ticket; } @@ -163,7 +160,11 @@ TQString KABC::ResourceKolab::loadContact( const TQString& contactData, contact.saveTo( &addr ); } else { KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + addr = converter.parseVCardRaw( contactData.utf8() ); +#else addr = converter.parseVCard( contactData ); +#endif } addr.setResource( this ); @@ -301,11 +302,11 @@ void AttachmentList::updatePictureAttachment( const TQImage& image, const TQStri { assert( !name.isEmpty() ); if ( !image.isNull() ) { - KTempFile* tempFile = new KTempFile; - image.save( tempFile->file(), "PNG" ); - tempFile->close(); + KTempFile tempFile; + image.save( tempFile.file(), "PNG" ); + tempFile.close(); KURL url; - url.setPath( tempFile->name() ); + url.setPath( tempFile.name() ); kdDebug(5650) << "picture saved to " << url.path() << endl; addAttachment( url.url(), name, "image/png" ); } else { @@ -317,11 +318,11 @@ void AttachmentList::updateAttachment( const TQByteArray& data, const TQString& { assert( !name.isEmpty() ); if ( !data.isNull() ) { - KTempFile* tempFile = new KTempFile; - tempFile->file()->writeBlock( data ); - tempFile->close(); + KTempFile tempFile; + tempFile.file()->writeBlock( data ); + tempFile.close(); KURL url; - url.setPath( tempFile->name() ); + url.setPath( tempFile.name() ); kdDebug(5650) << "data saved to " << url.path() << endl; addAttachment( url.url(), name, mimetype ); } else { @@ -342,14 +343,20 @@ bool KABC::ResourceKolab::kmailUpdateAddressee( const Addressee& addr ) } sernum = mUidMap[ uid ].serialNumber(); } else { - if ( !mCachedSubresource.isNull() ) { + if ( !mCachedSubresource.isNull() || mCachedSubresourceNotFound ) { subResource = mCachedSubresource; } else { - subResource = findWritableResource( mSubResources ); + subResource = findWritableResource( Kolab::Contacts, mSubResources ); // We were locked, remember the subresource we are working with until // we are unlocked - if ( mLocked ) + if ( mLocked ) { mCachedSubresource = subResource; + + // 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(); + } } if ( subResource.isEmpty() ) return false; @@ -374,7 +381,11 @@ bool KABC::ResourceKolab::kmailUpdateAddressee( const Addressee& addr ) } else { mimetype = s_inlineMimeType; KABC::VCardConverter converter; +#if defined(KABC_VCARD_ENCODING_FIX) + data = TQString::fromUtf8( converter.createVCardRaw( addr ) ); +#else data = converter.createVCard( addr ); +#endif subject.prepend( "vCard " ); // as per kolab1 spec } bool rc = kmailUpdate( subResource, sernum, data, mimetype, subject, @@ -652,6 +663,7 @@ void KABC::ResourceKolab::setSubresourceActive( const TQString &subresource, boo } else { kdDebug(5650) << "setSubresourceCompletionWeight: subresource " << subresource << " not found" << endl; } + writeConfig(); } @@ -667,4 +679,16 @@ bool KABC::ResourceKolab::removeSubresource( const TQString& id ) return kmailRemoveSubresource( id ); } +void KABC::ResourceKolab::writeConfig() +{ + KConfig config( configFile() ); + + 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() ); + } +} + #include "resourcekolab.moc" diff --git a/kresources/kolab/kabc/resourcekolab.h b/kresources/kolab/kabc/resourcekolab.h index 1da472015..9158375a1 100644 --- a/kresources/kolab/kabc/resourcekolab.h +++ b/kresources/kolab/kabc/resourcekolab.h @@ -164,9 +164,12 @@ protected: return Kolab::ResourceKolabBase::configFile( "kabc" ); } + void writeConfig(); + // The list of subresources Kolab::ResourceMap mSubResources; TQString mCachedSubresource; + bool mCachedSubresourceNotFound; bool mLocked; }; diff --git a/kresources/kolab/kcal/event.cpp b/kresources/kolab/kcal/event.cpp index 0f25eb73d..e1d58a13c 100644 --- a/kresources/kolab/kcal/event.cpp +++ b/kresources/kolab/kcal/event.cpp @@ -190,7 +190,9 @@ void Event::setFields( const KCal::Event* event ) { Incidence::setFields( event ); - if ( event->hasEndDate() ) { + // note: if hasEndDate() is false and hasDuration() is true + // dtEnd() returns start+duration + if ( event->hasEndDate() || event->hasDuration() ) { if ( event->doesFloat() ) { // This is a floating event. Don't timezone move this one mFloatingStatus = AllDay; @@ -199,8 +201,9 @@ void Event::setFields( const KCal::Event* event ) mFloatingStatus = HasTime; setEndDate( localToUTC( event->dtEnd() ) ); } - } else + } else { mHasEndDate = false; + } setTransparency( event->transparency() ); } diff --git a/kresources/kolab/kcal/incidence.cpp b/kresources/kolab/kcal/incidence.cpp index 74f41fd8d..de076eb98 100644 --- a/kresources/kolab/kcal/incidence.cpp +++ b/kresources/kolab/kcal/incidence.cpp @@ -39,6 +39,8 @@ #include #include +#include + #include #include #include @@ -50,7 +52,6 @@ using namespace Kolab; Incidence::Incidence( KCal::ResourceKolab *res, const TQString &subResource, Q_UINT32 sernum, const TQString& tz ) : KolabBase( tz ), mFloatingStatus( Unset ), mHasAlarm( false ), - mRevision( 0 ), mResource( res ), mSubResource( subResource ), mSernum( sernum ) @@ -163,16 +164,6 @@ TQString Incidence::internalUID() const return mInternalUID; } -void Incidence::setRevision( int revision ) -{ - mRevision = revision; -} - -int Incidence::revision() const -{ - return mRevision; -} - bool Incidence::loadAttendeeAttribute( TQDomElement& element, Attendee& attendee ) { @@ -183,8 +174,16 @@ bool Incidence::loadAttendeeAttribute( TQDomElement& element, TQDomElement e = n.toElement(); TQString tagName = e.tagName(); - if ( tagName == "display-name" ) - attendee.displayName = e.text(); + if ( tagName == "display-name" ) { + // Quote the text in case it contains commas or other quotable chars. + TQString tusername = KPIM::quoteNameIfNecessary( e.text() ); + + TQString tname, temail; + // ignore the return value because it will always be false since + // tusername does not contain "@domain". + KPIM::getNameAndMail( tusername, tname, temail ); + attendee.displayName = tname; + } else if ( tagName == "smtp-address" ) attendee.smtpAddress = e.text(); else if ( tagName == "status" ) @@ -249,6 +248,69 @@ void Incidence::saveAttachments( TQDomElement& element ) const } } +void Incidence::saveAlarms( TQDomElement& element ) const +{ + if ( mAlarms.isEmpty() ) return; + + TQDomElement list = element.ownerDocument().createElement( "advanced-alarms" ); + element.appendChild( list ); + for ( KCal::Alarm::List::ConstIterator it = mAlarms.constBegin(); it != mAlarms.constEnd(); ++it ) { + KCal::Alarm* a = *it; + TQDomElement e = list.ownerDocument().createElement( "alarm" ); + list.appendChild( e ); + + writeString( e, "enabled", a->enabled() ? "1" : "0" ); + if ( a->hasStartOffset() ) { + writeString( e, "start-offset", TQString::number( a->startOffset().asSeconds()/60 ) ); + } + if ( a->hasEndOffset() ) { + writeString( e, "end-offset", TQString::number( a->endOffset().asSeconds()/60 ) ); + } + if ( a->repeatCount() ) { + writeString( e, "repeat-count", TQString::number( a->repeatCount() ) ); + writeString( e, "repeat-interval", TQString::number( a->snoozeTime() ) ); + } + + switch ( a->type() ) { + case KCal::Alarm::Invalid: + break; + case KCal::Alarm::Display: + e.setAttribute( "type", "display" ); + writeString( e, "text", a->text() ); + break; + case KCal::Alarm::Procedure: + e.setAttribute( "type", "procedure" ); + writeString( e, "program", a->programFile() ); + writeString( e, "arguments", a->programArguments() ); + break; + case KCal::Alarm::Email: + { + e.setAttribute( "type", "email" ); + TQDomElement addresses = e.ownerDocument().createElement( "addresses" ); + e.appendChild( addresses ); + for ( TQValueList::ConstIterator it = a->mailAddresses().constBegin(); it != a->mailAddresses().constEnd(); ++it ) { + writeString( addresses, "address", (*it).fullName() ); + } + writeString( e, "subject", a->mailSubject() ); + writeString( e, "mail-text", a->mailText() ); + TQDomElement attachments = e.ownerDocument().createElement( "attachments" ); + e.appendChild( attachments ); + for ( TQStringList::ConstIterator it = a->mailAttachments().constBegin(); it != a->mailAttachments().constEnd(); ++it ) { + writeString( attachments, "attachment", *it ); + } + break; + } + case KCal::Alarm::Audio: + e.setAttribute( "type", "audio" ); + writeString( e, "file", a->audioFile() ); + break; + default: + kdWarning() << "Unhandled alarm type:" << a->type() << endl; + break; + } + } +} + void Incidence::saveRecurrence( TQDomElement& element ) const { TQDomElement e = element.ownerDocument().createElement( "recurrence" ); @@ -289,8 +351,14 @@ void Incidence::loadRecurrence( const TQDomElement& element ) TQDomElement e = n.toElement(); TQString tagName = e.tagName(); - if ( tagName == "interval" ) - mRecurrence.interval = e.text().toInt(); + if ( tagName == "interval" ) { + //kolab/issue4229, sometimes the interval value can be empty + if ( e.text().isEmpty() || e.text().toInt() <= 0 ) { + mRecurrence.interval = 1; + } else { + mRecurrence.interval = e.text().toInt(); + } + } else if ( tagName == "day" ) // can be present multiple times mRecurrence.days.append( e.text() ); else if ( tagName == "daynumber" ) @@ -309,6 +377,118 @@ void Incidence::loadRecurrence( const TQDomElement& element ) } } +static void loadAddressesHelper( const TQDomElement& element, KCal::Alarm* a ) +{ + for ( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + TQString tagName = e.tagName(); + + if ( tagName == "address" ) { + a->addMailAddress( KCal::Person( e.text() ) ); + } else { + kdWarning() << "Unhandled tag" << tagName << endl; + } + } + } +} + +static void loadAttachmentsHelper( const TQDomElement& element, KCal::Alarm* a ) +{ + for ( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + TQString tagName = e.tagName(); + + if ( tagName == "attachment" ) { + a->addMailAttachment( e.text() ); + } else { + kdWarning() << "Unhandled tag" << tagName << endl; + } + } + } +} + +static void loadAlarmHelper( const TQDomElement& element, KCal::Alarm* a ) +{ + for ( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + TQString tagName = e.tagName(); + + if ( tagName == "start-offset" ) { + a->setStartOffset( e.text().toInt()*60 ); + } else if ( tagName == "end-offset" ) { + a->setEndOffset( e.text().toInt()*60 ); + } else if ( tagName == "repeat-count" ) { + a->setRepeatCount( e.text().toInt() ); + } else if ( tagName == "repeat-interval" ) { + a->setSnoozeTime( e.text().toInt() ); + } else if ( tagName == "text" ) { + a->setText( e.text() ); + } else if ( tagName == "program" ) { + a->setProgramFile( e.text() ); + } else if ( tagName == "arguments" ) { + a->setProgramArguments( e.text() ); + } else if ( tagName == "addresses" ) { + loadAddressesHelper( e, a ); + } else if ( tagName == "subject" ) { + a->setMailSubject( e.text() ); + } else if ( tagName == "mail-text" ) { + a->setMailText( e.text() ); + } else if ( tagName == "attachments" ) { + loadAttachmentsHelper( e, a ); + } else if ( tagName == "file" ) { + a->setAudioFile( e.text() ); + } else if ( tagName == "enabled" ) { + a->setEnabled( e.text().toInt() != 0 ); + } else { + kdWarning() << "Unhandled tag" << tagName << endl; + } + } + } +} + +void Incidence::loadAlarms( const TQDomElement& element ) +{ + for ( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + if ( n.isComment() ) + continue; + if ( n.isElement() ) { + TQDomElement e = n.toElement(); + TQString tagName = e.tagName(); + + if ( tagName == "alarm" ) { + KCal::Alarm *a = new KCal::Alarm( 0 ); + a->setEnabled( true ); // default to enabled, unless some XML attribute says otherwise. + TQString type = e.attribute( "type" ); + if ( type == "display" ) { + a->setType( KCal::Alarm::Display ); + } else if ( type == "procedure" ) { + a->setType( KCal::Alarm::Procedure ); + } else if ( type == "email" ) { + a->setType( KCal::Alarm::Email ); + } else if ( type == "audio" ) { + a->setType( KCal::Alarm::Audio ); + } else { + kdWarning() << "Unhandled alarm type:" << type << endl; + } + + loadAlarmHelper( e, a ); + mAlarms << a; + } else { + kdWarning() << "Unhandled tag" << tagName << endl; + } + } + } +} + bool Incidence::loadAttribute( TQDomElement& element ) { TQString tagName = element.tagName(); @@ -340,20 +520,17 @@ bool Incidence::loadAttribute( TQDomElement& element ) } else if ( tagName == "alarm" ) // Alarms should be minutes before. Libkcal uses event time + alarm time setAlarm( - element.text().toInt() ); + else if ( tagName == "advanced-alarms" ) + loadAlarms( element ); else if ( tagName == "x-kde-internaluid" ) setInternalUID( element.text() ); - else if ( tagName == "revision" ) { - bool ok; - int revision = element.text().toInt( &ok ); - if ( ok ) - setRevision( revision ); - } else if ( tagName == "x-custom" ) + else if ( tagName == "x-custom" ) loadCustomAttributes( element ); else { bool ok = KolabBase::loadAttribute( element ); if ( !ok ) { // Unhandled tag - save for later storage - kdDebug() << "Saving unhandled tag " << element.tagName() << endl; + //kdDebug() << "Saving unhandled tag " << element.tagName() << endl; Custom c; c.key = TQCString( "X-KDE-KolabUnhandled-" ) + element.tagName().latin1(); c.value = element.text(); @@ -385,8 +562,8 @@ bool Incidence::saveAttributes( TQDomElement& element ) const int alarmTime = qRound( -alarm() ); writeString( element, "alarm", TQString::number( alarmTime ) ); } + saveAlarms( element ); writeString( element, "x-kde-internaluid", internalUID() ); - writeString( element, "revision", TQString::number( revision() ) ); saveCustomAttributes( element ); return true; } @@ -424,13 +601,15 @@ static KCal::Attendee::PartStat attendeeStringToStatus( const TQString& s ) return KCal::Attendee::NeedsAction; if ( s == "tentative" ) return KCal::Attendee::Tentative; + if ( s == "accepted" ) + return KCal::Attendee::Accepted; if ( s == "declined" ) return KCal::Attendee::Declined; if ( s == "delegated" ) return KCal::Attendee::Delegated; // Default: - return KCal::Attendee::Accepted; + return KCal::Attendee::None; } static TQString attendeeStatusToString( KCal::Attendee::PartStat status ) @@ -649,6 +828,14 @@ void Incidence::setFields( const KCal::Incidence* incidence ) mAttachments.push_back( a ); } + mAlarms.clear(); + + // Alarms + const KCal::Alarm::List alarms = incidence->alarms(); + for ( KCal::Alarm::List::ConstIterator it = alarms.begin(); it != alarms.end(); ++it ) { + mAlarms.push_back( *it ); + } + if ( incidence->doesRecur() ) { setRecurrence( incidence->recurrence() ); mRecurrence.exclusions = incidence->recurrence()->exDates(); @@ -711,10 +898,17 @@ void Incidence::saveTo( KCal::Incidence* incidence ) incidence->setSummary( summary() ); incidence->setLocation( location() ); - if ( mHasAlarm ) { + if ( mHasAlarm && mAlarms.isEmpty() ) { KCal::Alarm* alarm = incidence->newAlarm(); alarm->setStartOffset( qRound( mAlarm * 60.0 ) ); alarm->setEnabled( true ); + alarm->setType( KCal::Alarm::Display ); + } else if ( !mAlarms.isEmpty() ) { + for ( KCal::Alarm::List::ConstIterator it = mAlarms.constBegin(); it != mAlarms.constEnd(); ++it ) { + KCal::Alarm *alarm = *it; + alarm->setParent( incidence ); + incidence->addAlarm( alarm ); + } } if ( organizer().displayName.isEmpty() ) @@ -803,7 +997,7 @@ void Incidence::saveTo( KCal::Incidence* incidence ) if ( hasPilotSyncStatus() ) incidence->setSyncStatus( pilotSyncStatus() ); - for( TQValueList::ConstIterator it = mCustomList.begin(); it != mCustomList.end(); ++it ) { + for( TQValueList::ConstIterator it = mCustomList.constBegin(); it != mCustomList.constEnd(); ++it ) { incidence->setNonKDECustomProperty( (*it).key, (*it).value ); } @@ -836,7 +1030,7 @@ void Incidence::loadAttachments() TQString Incidence::productID() const { - return TQString( "KOrganizer " ) + korgVersion + ", Kolab resource"; + return TQString( "KOrganizer %1, Kolab resource" ).arg( korgVersion ); } // Unhandled KCal::Incidence fields: diff --git a/kresources/kolab/kcal/incidence.h b/kresources/kolab/kcal/incidence.h index 32b112aaf..582d34c38 100644 --- a/kresources/kolab/kcal/incidence.h +++ b/kresources/kolab/kcal/incidence.h @@ -41,6 +41,7 @@ class TQDomElement; namespace KCal { class Incidence; class Recurrence; + class Alarm; class Attachment; class ResourceKolab; } @@ -115,9 +116,6 @@ public: void setInternalUID( const TQString& iuid ); TQString internalUID() const; - virtual void setRevision( int ); - virtual int revision() const; - // Load the attributes of this class virtual bool loadAttribute( TQDomElement& ); @@ -136,6 +134,9 @@ protected: void saveAttendees( TQDomElement& element ) const; void saveAttachments( TQDomElement& element ) const; + void loadAlarms( const TQDomElement& element ); + void saveAlarms( TQDomElement& element ) const; + void loadRecurrence( const TQDomElement& element ); void saveRecurrence( TQDomElement& element ) const; void saveCustomAttributes( TQDomElement& element ) const; @@ -154,9 +155,9 @@ protected: bool mHasAlarm; Recurrence mRecurrence; TQValueList mAttendees; + TQValueList mAlarms; TQValueList mAttachments; TQString mInternalUID; - int mRevision; struct Custom { TQCString key; diff --git a/kresources/kolab/kcal/kolab.desktop b/kresources/kolab/kcal/kolab.desktop index 579e6406d..c0a7daa56 100644 --- a/kresources/kolab/kcal/kolab.desktop +++ b/kresources/kolab/kcal/kolab.desktop @@ -21,7 +21,6 @@ Name[hu]=IMAP-kiszolgálón tárolt naptár a KMailen keresztül Name[is]=Dagatal á IMAP þjóni gegnum KMail Name[it]=Calendario su server IMAP via KMail Name[ja]=KMail 経由 IMAP サーバのカレンダー -Name[ka]=კალენდარი IMAP სერვერზე KMail-ის საშუალებით Name[kk]=KMail арқылы IMAP серверіндегі күнтізбе Name[km]=ប្រតិទិន​លើ​ម៉ាស៊ីន​បម្រើ IMAP តាម​រយៈ KMail Name[lt]=Kalendorius IMAP serveryje per KMail diff --git a/kresources/kolab/kcal/resourcekolab.cpp b/kresources/kolab/kcal/resourcekolab.cpp index b61b12110..1f5f486ff 100644 --- a/kresources/kolab/kcal/resourcekolab.cpp +++ b/kresources/kolab/kcal/resourcekolab.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -72,8 +71,11 @@ static const char* incidenceInlineMimeType = "text/calendar"; ResourceKolab::ResourceKolab( const KConfig *config ) : ResourceCalendar( config ), ResourceKolabBase( "ResourceKolab-libkcal" ), mCalendar( TQString::fromLatin1("UTC") ), mOpen( false ),mResourceChangedTimer( 0, - "mResourceChangedTimer" ) + "mResourceChangedTimer" ), mBatchAddingInProgress( false ) { + if ( !config ) { + setResourceName( i18n( "Kolab Server" ) ); + } setType( "imap" ); connect( &mResourceChangedTimer, TQT_SIGNAL( timeout() ), this, TQT_SLOT( slotEmitResourceChanged() ) ); @@ -132,7 +134,7 @@ bool ResourceKolab::doOpen() && openResource( config, kmailJournalContentsType, mJournalSubResources ); } -static void closeResource( KConfig& config, ResourceMap& map ) +static void writeResourceConfig( KConfig& config, ResourceMap& map ) { ResourceMap::ConstIterator it; for ( it = map.begin(); it != map.end(); ++it ) { @@ -148,10 +150,7 @@ void ResourceKolab::doClose() return; mOpen = false; - KConfig config( configFile() ); - closeResource( config, mEventSubResources ); - closeResource( config, mTodoSubResources ); - closeResource( config, mJournalSubResources ); + writeConfig(); } bool ResourceKolab::loadSubResource( const TQString& subResource, @@ -217,11 +216,20 @@ bool ResourceKolab::loadSubResource( const TQString& subResource, bool ResourceKolab::doLoad() { if (!mUidMap.isEmpty() ) { + emit resourceLoaded( this ); return true; } mUidMap.clear(); - return loadAllEvents() & loadAllTodos() & loadAllJournals(); + bool result = loadAllEvents() & loadAllTodos() & loadAllJournals(); + if ( result ) { + emit resourceLoaded( this ); + } else { + // FIXME: anyone know if the resource correctly calls loadError() + // if it has one? + } + + return result; } bool ResourceKolab::doLoadAll( ResourceMap& map, const char* mimetype ) @@ -297,19 +305,54 @@ bool ResourceKolab::doSave() && kmailTriggerSync( kmailJournalContentsType ); */ } -void ResourceKolab::incidenceUpdatedSilent( KCal::IncidenceBase* incidencebase) +void ResourceKolab::incidenceUpdatedSilent( KCal::IncidenceBase* incidencebase ) { - const TQString uid = incidencebase->uid(); + const TQString uid = incidencebase->uid(); //kdDebug() << k_funcinfo << uid << endl; if ( mUidsPendingUpdate.contains( uid ) || mUidsPendingAdding.contains( uid ) ) { /* We are currently processing this event ( removing and readding or * adding it ). If so, ignore this update. Keep the last of these around * and process once we hear back from KMail on this event. */ - mPendingUpdates.replace( uid, incidencebase ); + mPendingUpdates.remove( uid ); + mPendingUpdates.insert( uid, incidencebase ); return; } + { // start optimization + /** + KOrganizer and libkcal like calling two Incidence::updated() + for only one user change. That's because after a change, + IncidenceChanger calls incidence->setRevision( rev++ ); + which also calls Incidence::updated(). + + Lets ignore the first updated() and only send to kmail + the second. This makes things faster. + */ + + //IncidenceBase doesn't have revision(), downcast needed. + Incidence *i = dynamic_cast( incidencebase ); + + if ( i ) { + bool ignoreThisUpdate = false; + + if ( !mLastKnownRevisions.contains( uid ) ) { + mLastKnownRevisions[uid] = i->revision(); + } + + // update the last known revision + if ( mLastKnownRevisions[uid] < i->revision() ) { + mLastKnownRevisions[uid] = i->revision(); + } else { + ignoreThisUpdate = true; + } + + if ( ignoreThisUpdate ) { + return; + } + } + } // end optimization + TQString subResource; Q_UINT32 sernum = 0; if ( mUidMap.contains( uid ) ) { @@ -317,78 +360,85 @@ void ResourceKolab::incidenceUpdatedSilent( KCal::IncidenceBase* incidencebase) sernum = mUidMap[ uid ].serialNumber(); mUidsPendingUpdate.append( uid ); } - sendKMailUpdate( incidencebase, subResource, sernum ); + sendKMailUpdate( incidencebase, subResource, sernum ); } void ResourceKolab::incidenceUpdated( KCal::IncidenceBase* incidencebase ) { - if ( incidencebase->isReadOnly() ) return; + if ( incidencebase->isReadOnly() ) { + return; + } + incidencebase->setSyncStatusSilent( KCal::Event::SYNCMOD ); incidencebase->setLastModified( TQDateTime::currentDateTime() ); + // we should probably update the revision number here, // or internally in the Event itself when certain things change. // need to verify with ical documentation. incidenceUpdatedSilent( incidencebase ); - } void ResourceKolab::resolveConflict( KCal::Incidence* inc, const TQString& subresource, Q_UINT32 sernum ) { - if ( ! inc ) - return; - if ( ! mResolveConflict ) { - // we should do no conflict resolution - delete inc; - return; - } - const TQString origUid = inc->uid(); - Incidence* local = mCalendar.incidence( origUid ); - Incidence* localIncidence = 0; - Incidence* addedIncidence = 0; - Incidence* result = 0; - if ( local ) { - if (*local == *inc) { - // real duplicate, remove the second one - result = local; - } else { - KIncidenceChooser* ch = new KIncidenceChooser(); - ch->setIncidence( local ,inc ); - if ( KIncidenceChooser::chooseMode == KIncidenceChooser::ask ) { - connect ( this, TQT_SIGNAL( useGlobalMode() ), ch, TQT_SLOT ( useGlobalMode() ) ); - if ( ch->exec() ) - if ( KIncidenceChooser::chooseMode != KIncidenceChooser::ask ) - emit useGlobalMode() ; - } - result = ch->getIncidence(); - delete ch; - } - } else { - // nothing there locally, just take the new one. Can't Happen (TM) - result = inc; - } - if ( result == local ) { - delete inc; - localIncidence = local; - } else if ( result == inc ) { - addedIncidence = inc; - } else if ( result == 0 ) { // take both - addedIncidence = inc; - addedIncidence->setSummary( i18n("Copy of: %1").arg( addedIncidence->summary() ) ); - addedIncidence->setUid( CalFormat::createUniqueId() ); - localIncidence = local; - } - bool silent = mSilent; - mSilent = false; - if ( !localIncidence ) { - deleteIncidence( local ); // remove local from kmail - } - mUidsPendingDeletion.append( origUid ); - if ( addedIncidence ) { - sendKMailUpdate( addedIncidence, subresource, sernum ); - } else { - kmailDeleteIncidence( subresource, sernum );// remove new from kmail - } - mSilent = silent; + if ( !inc ) { + return; + } + + if ( !mResolveConflict ) { + // we should do no conflict resolution + delete inc; + return; + } + const TQString origUid = inc->uid(); + Incidence* local = mCalendar.incidence( origUid ); + Incidence* localIncidence = 0; + Incidence* addedIncidence = 0; + Incidence* result = 0; + if ( local ) { + if ( *local == *inc ) { + // real duplicate, remove the second one + result = local; + } else { + KIncidenceChooser* ch = new KIncidenceChooser(); + ch->setIncidence( local ,inc ); + if ( KIncidenceChooser::chooseMode == KIncidenceChooser::ask ) { + connect ( this, TQT_SIGNAL( useGlobalMode() ), ch, TQT_SLOT ( useGlobalMode() ) ); + if ( ch->exec() ) { + if ( KIncidenceChooser::chooseMode != KIncidenceChooser::ask ) { + emit useGlobalMode() ; + } + } + } + result = ch->getIncidence(); + delete ch; + } + } else { + // nothing there locally, just take the new one. Can't Happen (TM) + result = inc; + } + if ( result == local ) { + delete inc; + localIncidence = local; + } else if ( result == inc ) { + addedIncidence = inc; + } else if ( result == 0 ) { // take both + addedIncidence = inc; + addedIncidence->setSummary( i18n("Copy of: %1").arg( addedIncidence->summary() ) ); + addedIncidence->setUid( CalFormat::createUniqueId() ); + localIncidence = local; + } + const bool silent = mSilent; + mSilent = false; + if ( !localIncidence ) { + deleteIncidence( local ); // remove local from kmail + } + mUidsPendingDeletion.append( origUid ); + if ( addedIncidence ) { + sendKMailUpdate( addedIncidence, subresource, sernum ); + } else { + kmailDeleteIncidence( subresource, sernum );// remove new from kmail + } + mSilent = silent; } void ResourceKolab::addIncidence( const char* mimetype, const TQString& data, const TQString& subResource, Q_UINT32 sernum ) @@ -457,15 +507,24 @@ bool ResourceKolab::sendKMailUpdate( KCal::IncidenceBase* incidencebase, const T TQStringList attURLs, attMimeTypes, attNames; TQValueList tmpFiles; for ( KCal::Attachment::List::ConstIterator it = atts.constBegin(); it != atts.constEnd(); ++it ) { - KTempFile* tempFile = new KTempFile; - TQCString decoded = KCodecs::base64Decode( TQCString( (*it)->data() ) ); - tempFile->file()->writeBlock( decoded.data(), decoded.length() ); - tempFile->close(); - KURL url; - url.setPath( tempFile->name() ); - attURLs.append( url.url() ); - attMimeTypes.append( (*it)->mimeType() ); - attNames.append( (*it)->label() ); + if ( (*it)->isUri() ) { + continue; + } + KTempFile *tempFile = new KTempFile; + if ( tempFile->status() == 0 ) { // open ok + const TQByteArray decoded = (*it)->decodedData() ; + + tempFile->file()->writeBlock( decoded.data(), decoded.count() ); + KURL url; + url.setPath( tempFile->name() ); + attURLs.append( url.url() ); + attMimeTypes.append( (*it)->mimeType() ); + attNames.append( (*it)->label() ); + tempFile->close(); + tmpFiles.append( tempFile ); + } else { + kdWarning(5006) << "Cannot open temporary file for attachment"; + } } TQStringList deletedAtts; if ( kmailListAttachments( deletedAtts, subresource, sernum ) ) { @@ -474,8 +533,9 @@ bool ResourceKolab::sendKMailUpdate( KCal::IncidenceBase* incidencebase, const T } } CustomHeaderMap customHeaders; - if ( incidence->schedulingID() != incidence->uid() ) + if ( incidence->schedulingID() != incidence->uid() ) { customHeaders.insert( "X-Kolab-SchedulingID", incidence->schedulingID() ); + } TQString subject = incidencebase->uid(); if ( !isXMLStorageFormat ) subject.prepend( "iCal " ); // conform to the old style @@ -499,34 +559,49 @@ bool ResourceKolab::addIncidence( KCal::Incidence* incidence, const TQString& _s Q_UINT32 sernum ) { Q_ASSERT( incidence ); - if ( !incidence ) return false; + if ( !incidence ) { + return false; + } + + kdDebug() << "Resourcekolab, adding incidence " + << incidence->summary() + << "; subresource = " << _subresource + << "; sernum = " << sernum + << "; mBatchAddingInProgress = " << mBatchAddingInProgress + << endl; + TQString uid = incidence->uid(); TQString subResource = _subresource; Kolab::ResourceMap *map = &mEventSubResources; // don't use a ref here! const TQString& type = incidence->type(); - if ( type == "Event" ) + if ( type == "Event" ) { map = &mEventSubResources; - else if ( type == "Todo" ) + } else if ( type == "Todo" ) { map = &mTodoSubResources; - else if ( type == "Journal" ) + } else if ( type == "Journal" ) { map = &mJournalSubResources; - else + } else { kdWarning() << "unknown type " << type << endl; + } if ( !mSilent ) { /* We got this one from the user, tell KMail. */ // Find out if this event was previously stored in KMail bool newIncidence = _subresource.isEmpty(); if ( newIncidence ) { + ResourceType type = Incidences; // Add a description of the incidence TQString text = ""; - if ( incidence->type() == "Event" ) + if ( incidence->type() == "Event" ) { + type = Events; text += i18n( "Choose the folder where you want to store this event" ); - else if ( incidence->type() == "Todo" ) + } else if ( incidence->type() == "Todo" ) { + type = Tasks; text += i18n( "Choose the folder where you want to store this task" ); - else + } else { text += i18n( "Choose the folder where you want to store this incidence" ); + } text += "
"; if ( !incidence->summary().isEmpty() ) text += i18n( "Summary: %1" ).arg( incidence->summary() ) + "
"; @@ -541,24 +616,51 @@ bool ResourceKolab::addIncidence( KCal::Incidence* incidence, const TQString& _s text += "
"; if ( incidence->type() == "Event" ) { Event* event = static_cast( incidence ); - if ( event->hasEndDate() ) - if ( !event->doesFloat() ) + if ( event->hasEndDate() ) { + if ( !event->doesFloat() ) { text += i18n( "End: %1, %2" ) .arg( event->dtEndDateStr(), event->dtEndTimeStr() ); - else + } else { text += i18n( "End: %1" ).arg( event->dtEndDateStr() ); + } + } text += "
"; } - subResource = findWritableResource( *map, text ); + + // Lets not warn the user 100 times that there's no writable resource + // and not ask 100 times which resource to use + if ( !mBatchAddingInProgress || !mLastUsedResources.contains( type ) ) { + subResource = findWritableResource( type, *map, text ); + mLastUsedResources[type] = subResource; + } else { + subResource = mLastUsedResources[type]; + } + + if ( subResource.isEmpty() ) { + switch( mErrorCode ) { + case NoWritableFound: + setException( new ErrorFormat( ErrorFormat::NoWritableFound ) ); + break; + case UserCancel: + setException( new ErrorFormat( ErrorFormat::UserCancel ) ); + break; + case NoError: + break; + } + } } - if ( subResource.isEmpty() ) + if ( subResource.isEmpty() ) { + endAddingIncidences(); // cleanup + kdDebug(5650) << "ResourceKolab: subResource is empty" << endl; return false; + } mNewIncidencesMap.insert( uid, subResource ); if ( !sendKMailUpdate( incidence, subResource, sernum ) ) { kdError(5650) << "Communication problem in ResourceKolab::addIncidence()\n"; + endAddingIncidences(); // cleanup return false; } else { // KMail is doing it's best to add the event now, put a sticker on it, @@ -568,13 +670,14 @@ bool ResourceKolab::addIncidence( KCal::Incidence* incidence, const TQString& _s /* Add to the cache immediately if this is a new event coming from * KOrganizer. It relies on the incidence being in the calendar when * addIncidence returns. */ - if ( newIncidence ) { + if ( newIncidence || sernum == 0 ) { mCalendar.addIncidence( incidence ); - incidence->registerObserver( this ); + incidence->registerObserver( this ); } } } else { /* KMail told us */ - bool ourOwnUpdate = mUidsPendingUpdate.contains( uid ); + const bool ourOwnUpdate = mUidsPendingUpdate.contains( uid ); + kdDebug( 5650 ) << "addIncidence: ourOwnUpdate " << ourOwnUpdate << endl; /* Check if we updated this one, which means kmail deleted and added it. * We know the new state, so lets just not do much at all. The old incidence * in the calendar remains valid, but the serial number changed, so we need to @@ -592,6 +695,7 @@ bool ResourceKolab::addIncidence( KCal::Incidence* incidence, const TQString& _s if ( mUidMap.contains( uid ) ) { if ( mUidMap[ uid ].resource() == subResource ) { if ( (*map)[ subResource ].writable() ) { + kdDebug( 5650 ) << "lets resolve the conflict " << endl; resolveConflict( incidence, subResource, sernum ); } else { kdWarning( 5650 ) << "Duplicate event in a read-only folder detected! " @@ -601,8 +705,13 @@ bool ResourceKolab::addIncidence( KCal::Incidence* incidence, const TQString& _s } else { // duplicate uid in a different folder, do the internal-uid tango incidence->setSchedulingID( uid ); - incidence->setUid(CalFormat::createUniqueId( ) ); + + incidence->setUid( CalFormat::createUniqueId( ) ); uid = incidence->uid(); + + /* Will be needed when kmail triggers a delete, so we don't delete the inocent + * incidence that's sharing the uid with this one */ + mOriginalUID2fakeUID[qMakePair( incidence->schedulingID(), subResource )] = uid; } } /* Add to the cache if the add didn't come from KOrganizer, in which case @@ -636,13 +745,18 @@ bool ResourceKolab::addIncidence( KCal::Incidence* incidence, const TQString& _s return true; } +bool ResourceKolab::addEvent( KCal::Event *event ) +{ + return addEvent( event, TQString() ); +} -bool ResourceKolab::addEvent( KCal::Event* event ) +bool ResourceKolab::addEvent( KCal::Event *event, const TQString &subResource ) { - if ( mUidMap.contains( event->uid() ) ) + if ( mUidMap.contains( event->uid() ) ) { return true; //noop - else - return addIncidence( event, TQString::null, 0 ); + } else { + return addIncidence( event, subResource, 0 ); + } } void ResourceKolab::addEvent( const TQString& xml, const TQString& subresource, @@ -650,14 +764,16 @@ void ResourceKolab::addEvent( const TQString& xml, const TQString& subresource, { KCal::Event* event = Kolab::Event::xmlToEvent( xml, mCalendar.timeZoneId(), this, subresource, sernum ); Q_ASSERT( event ); - if( event ) { + if ( event ) { addIncidence( event, subresource, sernum ); } } bool ResourceKolab::deleteIncidence( KCal::Incidence* incidence ) { - if ( incidence->isReadOnly() ) return false; + if ( incidence->isReadOnly() ) { + return false; + } const TQString uid = incidence->uid(); if( !mUidMap.contains( uid ) ) return false; // Odd @@ -709,12 +825,18 @@ KCal::Event::List ResourceKolab::rawEvents( const TQDate& start, return mCalendar.rawEvents( start, end, inclusive ); } -bool ResourceKolab::addTodo( KCal::Todo* todo ) +bool ResourceKolab::addTodo( KCal::Todo *todo ) { - if ( mUidMap.contains( todo->uid() ) ) + return addTodo( todo, TQString() ); +} + +bool ResourceKolab::addTodo( KCal::Todo *todo, const TQString &subResource ) +{ + if ( mUidMap.contains( todo->uid() ) ) { return true; //noop - else - return addIncidence( todo, TQString::null, 0 ); + } else { + return addIncidence( todo, subResource, 0 ); + } } void ResourceKolab::addTodo( const TQString& xml, const TQString& subresource, @@ -722,8 +844,9 @@ void ResourceKolab::addTodo( const TQString& xml, const TQString& subresource, { KCal::Todo* todo = Kolab::Task::xmlToTask( xml, mCalendar.timeZoneId(), this, subresource, sernum ); Q_ASSERT( todo ); - if( todo ) - addIncidence( todo, subresource, sernum ); + if ( todo ) { + addIncidence( todo, subresource, sernum ); + } } bool ResourceKolab::deleteTodo( KCal::Todo* todo ) @@ -746,12 +869,17 @@ KCal::Todo::List ResourceKolab::rawTodosForDate( const TQDate& date ) return mCalendar.rawTodosForDate( date ); } -bool ResourceKolab::addJournal( KCal::Journal* journal ) +bool ResourceKolab::addJournal( KCal::Journal *journal ) +{ + return addJournal( journal, TQString() ); +} + +bool ResourceKolab::addJournal( KCal::Journal *journal, const TQString &subResource ) { if ( mUidMap.contains( journal->uid() ) ) return true; //noop else - return addIncidence( journal, TQString::null, 0 ); + return addIncidence( journal, subResource, 0 ); } void ResourceKolab::addJournal( const TQString& xml, const TQString& subresource, @@ -839,27 +967,33 @@ bool ResourceKolab::fromKMailAddIncidence( const TQString& type, bool rc = true; TemporarySilencer t( this ); // RAII if ( type != kmailCalendarContentsType && type != kmailTodoContentsType - && type != kmailJournalContentsType ) + && type != kmailJournalContentsType ) { // Not ours return false; - if ( !subresourceActive( subResource ) ) return true; + } + + if ( !subresourceActive( subResource ) ) { + return true; + } if ( format == KMailICalIface::StorageXML ) { // If this data file is one of ours, load it here - if ( type == kmailCalendarContentsType ) + if ( type == kmailCalendarContentsType ) { addEvent( data, subResource, sernum ); - else if ( type == kmailTodoContentsType ) + } else if ( type == kmailTodoContentsType ) { addTodo( data, subResource, sernum ); - else if ( type == kmailJournalContentsType ) + } else if ( type == kmailJournalContentsType ) { addJournal( data, subResource, sernum ); - else + } else { rc = false; + } } else { Incidence *inc = mFormat.fromString( data ); - if ( !inc ) - rc = false; - else + if ( inc ) { addIncidence( inc, subResource, sernum ); + } else { + rc = false; + } } return rc; } @@ -881,13 +1015,25 @@ void ResourceKolab::fromKMailDelIncidence( const TQString& type, // It's good to know if was deleted, but we are waiting on a new one to // replace it, so let's just sit tight. } else { + TQString uidToUse; + + QPair p( uid, subResource ); + if ( mOriginalUID2fakeUID.contains( p ) ) { + // Incidence with the same uid in a different folder... + // use the UID that addIncidence(...) generated + uidToUse = mOriginalUID2fakeUID[p]; + } else { + uidToUse = uid; + } + // We didn't trigger this, so KMail did, remove the reference to the uid - KCal::Incidence* incidence = mCalendar.incidence( uid ); + KCal::Incidence* incidence = mCalendar.incidence( uidToUse ); if( incidence ) { incidence->unRegisterObserver( this ); mCalendar.deleteIncidence( incidence ); } - mUidMap.remove( uid ); + mUidMap.remove( uidToUse ); + mOriginalUID2fakeUID.remove( p ); mResourceChangedTimer.changeInterval( 100 ); } } @@ -1039,6 +1185,23 @@ void ResourceKolab::setSubresourceActive( const TQString &subresource, bool v ) } mResourceChangedTimer.changeInterval( 100 ); } + TQTimer::singleShot( 0, this, TQT_SLOT(writeConfig()) ); +} + +bool ResourceKolab::subresourceWritable( const TQString& subresource ) const +{ + // Workaround: The ResourceView in KOrganizer wants to know this + // before it opens the resource :-( Make sure we are open + const_cast( this )->doOpen(); + + if ( mEventSubResources.contains( subresource ) ) + return mEventSubResources[ subresource ].writable(); + if ( mTodoSubResources.contains( subresource ) ) + return mTodoSubResources[ subresource ].writable(); + if ( mJournalSubResources.contains( subresource ) ) + return mJournalSubResources[ subresource ].writable(); + + return false; //better a safe default } void ResourceKolab::slotEmitResourceChanged() @@ -1053,7 +1216,6 @@ KABC::Lock* ResourceKolab::lock() return new KABC::LockNull( true ); } - Kolab::ResourceMap* ResourceKolab::subResourceMap( const TQString& contentsType ) { if ( contentsType == kmailCalendarContentsType ) { @@ -1122,6 +1284,7 @@ bool ResourceKolab::unloadSubResource( const TQString& subResource ) const bool silent = mSilent; mSilent = true; Kolab::UidMap::Iterator mapIt = mUidMap.begin(); + TQPtrList incidences; while ( mapIt != mUidMap.end() ) { Kolab::UidMap::Iterator it = mapIt++; @@ -1130,11 +1293,18 @@ bool ResourceKolab::unloadSubResource( const TQString& subResource ) // FIXME incidence() is expensive KCal::Incidence* incidence = mCalendar.incidence( it.key() ); if( incidence ) { - incidence->unRegisterObserver( this ); - mCalendar.deleteIncidence( incidence ); + // register all observers first before actually deleting them + // in case of inter-incidence relations the other part will get + // the change notification otherwise + incidence->unRegisterObserver( this ); + incidences.append( incidence ); } mUidMap.remove( it ); } + TQPtrListIterator it( incidences ); + for ( ; it.current(); ++it ) { + mCalendar.deleteIncidence( it.current() ); + } mSilent = silent; return true; } @@ -1150,4 +1320,23 @@ TQString ResourceKolab::subresourceType( const TQString &resource ) return TQString(); } +void ResourceKolab::writeConfig() +{ + KConfig config( configFile() ); + writeResourceConfig( config, mEventSubResources ); + writeResourceConfig( config, mTodoSubResources ); + writeResourceConfig( config, mJournalSubResources ); +} + +void ResourceKolab::beginAddingIncidences() +{ + mBatchAddingInProgress = true; +} + +void ResourceKolab::endAddingIncidences() +{ + mBatchAddingInProgress = false; + mLastUsedResources.clear(); +} + #include "resourcekolab.moc" diff --git a/kresources/kolab/kcal/resourcekolab.h b/kresources/kolab/kcal/resourcekolab.h index e68c2c6bf..dda5ba32a 100644 --- a/kresources/kolab/kcal/resourcekolab.h +++ b/kresources/kolab/kcal/resourcekolab.h @@ -70,8 +70,9 @@ public: void doClose(); // The libkcal functions. See the resource for descriptions - bool addEvent( KCal::Event* anEvent ); - bool deleteEvent( KCal::Event* ); + KDE_DEPRECATED bool addEvent( KCal::Event *event ); + bool addEvent( KCal::Event *event, const TQString &subResource ); + bool deleteEvent( KCal::Event * ); KCal::Event* event( const TQString &UniqueStr ); KCal::Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); KCal::Event::List rawEventsForDate( @@ -82,15 +83,17 @@ public: KCal::Event::List rawEvents( const TQDate& start, const TQDate& end, bool inclusive = false ); - bool addTodo( KCal::Todo* todo ); - bool deleteTodo( KCal::Todo* ); - KCal::Todo* todo( const TQString& uid ); + KDE_DEPRECATED bool addTodo( KCal::Todo * todo ); + bool addTodo( KCal::Todo *todo, const TQString &subResource ); + bool deleteTodo( KCal::Todo * ); + KCal::Todo* todo( const TQString &uid ); KCal::Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); KCal::Todo::List rawTodosForDate( const TQDate& date ); - bool addJournal( KCal::Journal* ); - bool deleteJournal( KCal::Journal* ); - KCal::Journal* journal( const TQString& uid ); + KDE_DEPRECATED bool addJournal( KCal::Journal * ); + bool addJournal( KCal::Journal *, const TQString &subResource ); + bool deleteJournal( KCal::Journal * ); + KCal::Journal* journal( const TQString &uid ); KCal::Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending ); KCal::Journal::List rawJournalsForDate( const TQDate &date ); @@ -128,6 +131,9 @@ public: /** (De)activate the subresource */ virtual void setSubresourceActive( const TQString &, bool ); + /** Is this subresource writable? */ + bool subresourceWritable( const TQString& ) const; + /** What is the label for this subresource? */ virtual const TQString labelForSubresource( const TQString& resource ) const; @@ -140,10 +146,16 @@ public: KABC::Lock* lock(); + void beginAddingIncidences(); + + void endAddingIncidences(); + signals: void useGlobalMode(); protected slots: void slotEmitResourceChanged(); + void writeConfig(); + protected: /** * Return list of alarms which are relevant for the current user. These @@ -157,7 +169,11 @@ private: void addIncidence( const char* mimetype, const TQString& xml, const TQString& subResource, Q_UINT32 sernum ); - bool addIncidence( KCal::Incidence* i, const TQString& subresource, + + /** + Caller guarantees i is not null. + */ + bool addIncidence( KCal::Incidence *i, const TQString& subresource, Q_UINT32 sernum ); void addEvent( const TQString& xml, const TQString& subresource, @@ -215,6 +231,36 @@ private: */ TQMap mNewIncidencesMap; int mProgressDialogIncidenceLimit; + + /** + * If a user has a subresource for viewing another user's folder then it can happen + * that addIncidence(...) adds an incidence with an already existing UID. + * + * When this happens, addIncidence(...) sets a new random UID and stores the + * original UID using incidence->setSchedulingID(uid) because KCal doesn't + * allow two incidences to have the same UID. + * + * This map keeps track of the generated UIDs (which are local) so we can delete the + * right incidence inside fromKMailDelIncidence(...) whenever we sync. + * + * The key is originalUID,subResource and the value is the fake UID. + */ + TQMap< QPair, TQString > mOriginalUID2fakeUID; + + bool mBatchAddingInProgress; + TQMap mLastUsedResources; + + /** + Indexed by uid, it holds the last known revision of an incidence. + If we receive an update where the incidence still has the same + revision as the last known, we ignore it and don't send it to kmail, + because shortly after, IncidenceChanger will increment the revision + and that will trigger another update. + + If we didn't discard the first update, kmail would have been updated twice. + */ + TQMap mLastKnownRevisions; + }; struct TemporarySilencer { diff --git a/kresources/kolab/kcal/task.cpp b/kresources/kolab/kcal/task.cpp index 7bbdba978..36876b7d5 100644 --- a/kresources/kolab/kcal/task.cpp +++ b/kresources/kolab/kcal/task.cpp @@ -38,6 +38,41 @@ using namespace Kolab; +// Kolab Storage Specification: +// "The priority can be a number between 1 and 5, with 1 being the highest priority." +// iCalendar (RFC 2445): +// "The priority is specified as an integer in the range +// zero to nine. A value of zero specifies an +// undefined priority. A value of one is the +// highest priority. A value of nine is the lowest +// priority." + +static int kcalPriorityToKolab( const int kcalPriority ) +{ + if ( kcalPriority >= 0 && kcalPriority <= 9 ) { + // We'll map undefined (0) to 3 (default) + // 0 1 2 3 4 5 6 7 8 9 + static const int priorityMap[10] = { 3, 1, 1, 2, 2, 3, 3, 4, 4, 5 }; + return priorityMap[kcalPriority]; + } + else { + kdWarning() << "kcalPriorityToKolab(): Got invalid priority " << kcalPriority << endl; + return 3; + } +} + +static int kolabPrioritytoKCal( const int kolabPriority ) +{ + if ( kolabPriority >= 1 && kolabPriority <= 5 ) { + // 1 2 3 4 5 + static const int priorityMap[5] = { 1, 3, 5, 7, 9 }; + return priorityMap[kolabPriority - 1]; + } + else { + kdWarning() << "kolabPrioritytoKCal(): Got invalid priority " << kolabPriority << endl; + return 5; + } +} KCal::Todo* Task::xmlToTask( const TQString& xml, const TQString& tz, KCal::ResourceKolab *res, const TQString& subResource, Q_UINT32 sernum ) @@ -115,6 +150,26 @@ void Task::setDueDate( const TQDateTime& date ) { mDueDate = date; mHasDueDate = true; + mFloatingStatus = HasTime; +} + +void Task::setDueDate( const TQDate &date ) +{ + mDueDate = date; + mHasDueDate = true; + mFloatingStatus = AllDay; +} + + +void Task::setDueDate( const TQString &date ) +{ + if ( date.length() > 10 ) { + // This is a date + time + setDueDate( stringToDateTime( date ) ); + } else { + // This is only a date + setDueDate( stringToDate( date ) ); + } } TQDateTime Task::dueDate() const @@ -159,10 +214,18 @@ bool Task::loadAttribute( TQDomElement& element ) if ( tagName == "priority" ) { bool ok; - int priority = element.text().toInt( &ok ); - if ( !ok || priority < 0 || priority > 9 ) - priority = 5; - setPriority( priority ); + mKolabPriorityFromDom = element.text().toInt( &ok ); + if ( !ok || mKolabPriorityFromDom < 1 || mKolabPriorityFromDom > 5 ) { + kdWarning() << "loadAttribute(): Invalid \"priority\" value: " << element.text() << endl; + mKolabPriorityFromDom = -1; + } + } else if ( tagName == "x-kcal-priority" ) { + bool ok; + mKCalPriorityFromDom = element.text().toInt( &ok ); + if ( !ok || mKCalPriorityFromDom < 0 || mKCalPriorityFromDom > 9 ) { + kdWarning() << "loadAttribute(): Invalid \"x-kcal-priority\" value: " << element.text() << endl; + mKCalPriorityFromDom = -1; + } } else if ( tagName == "completed" ) { bool ok; int percent = element.text().toInt( &ok ); @@ -182,13 +245,13 @@ bool Task::loadAttribute( TQDomElement& element ) else // Default setStatus( KCal::Incidence::StatusNone ); - } else if ( tagName == "due-date" ) - setDueDate( stringToDateTime( element.text() ) ); - else if ( tagName == "parent" ) + } else if ( tagName == "due-date" ) { + setDueDate( element.text() ); + } else if ( tagName == "parent" ) { setParent( element.text() ); - else if ( tagName == "x-completed-date" ) + } else if ( tagName == "x-completed-date" ) { setCompletedDate( stringToDateTime( element.text() ) ); - else if ( tagName == "start-date" ) { + } else if ( tagName == "start-date" ) { setHasStartDate( true ); setStartDate( element.text() ); } else @@ -203,7 +266,11 @@ bool Task::saveAttributes( TQDomElement& element ) const // Save the base class elements Incidence::saveAttributes( element ); - writeString( element, "priority", TQString::number( priority() ) ); + // We need to save x-kcal-priority as well, since the Kolab priority can only save values from + // 1 to 5, but we have values from 0 to 9, and do not want to loose them + writeString( element, "priority", TQString::number( kcalPriorityToKolab( priority() ) ) ); + writeString( element, "x-kcal-priority", TQString::number( priority() ) ); + writeString( element, "completed", TQString::number( percentCompleted() ) ); switch( status() ) { @@ -232,14 +299,21 @@ bool Task::saveAttributes( TQDomElement& element ) const break; } - if ( hasDueDate() ) - writeString( element, "due-date", dateTimeToString( dueDate() ) ); + if ( hasDueDate() ) { + if ( mFloatingStatus == HasTime ) { + writeString( element, "due-date", dateTimeToString( dueDate() ) ); + } else { + writeString( element, "due-date", dateToString( dueDate().date() ) ); + } + } - if ( !parent().isNull() ) + if ( !parent().isNull() ) { writeString( element, "parent", parent() ); + } - if ( hasCompletedDate() && percentCompleted() == 100) + if ( hasCompletedDate() && percentCompleted() == 100 ) { writeString( element, "x-completed-date", dateTimeToString( completedDate() ) ); + } return true; } @@ -247,6 +321,9 @@ bool Task::saveAttributes( TQDomElement& element ) const bool Task::loadXML( const TQDomDocument& document ) { + mKolabPriorityFromDom = -1; + mKCalPriorityFromDom = -1; + TQDomElement top = document.documentElement(); if ( top.tagName() != "task" ) { @@ -269,6 +346,7 @@ bool Task::loadXML( const TQDomDocument& document ) } loadAttachments(); + decideAndSetPriority(); return true; } @@ -278,7 +356,7 @@ TQString Task::saveXML() const TQDomElement element = document.createElement( "task" ); element.setAttribute( "version", "1.0" ); saveAttributes( element ); - if ( !hasStartDate() ) { + if ( !hasStartDate() && startDate().isValid() ) { // events and journals always have a start date, but tasks don't. // Remove the entry done by the inherited save above, because we // don't have one. @@ -299,21 +377,68 @@ void Task::setFields( const KCal::Todo* task ) setStatus( task->status() ); setHasStartDate( task->hasStartDate() ); - if ( task->hasDueDate() ) + if ( task->hasDueDate() ) { setDueDate( localToUTC( task->dtDue() ) ); - else + if ( task->doesFloat() ) { + // This is a floating task. Don't timezone move this one + mFloatingStatus = AllDay; + setDueDate( task->dtDue().date() ); + } else { + mFloatingStatus = HasTime; + setDueDate( localToUTC( task->dtDue() ) ); + } + } else { mHasDueDate = false; - if ( task->relatedTo() ) + } + + if ( task->relatedTo() ) { setParent( task->relatedTo()->uid() ); - else if ( !task->relatedToUid().isEmpty() ) - setParent( task->relatedToUid() ); - else + } else if ( !task->relatedToUid().isEmpty() ) { + setParent( task->relatedToUid( ) ); + } else { setParent( TQString::null ); + } - if ( task->hasCompletedDate() && task->percentComplete() == 100 ) + if ( task->hasCompletedDate() && task->percentComplete() == 100 ) { setCompletedDate( localToUTC( task->completed() ) ); - else + } else { mHasCompletedDate = false; + } +} + +void Task::decideAndSetPriority() +{ + // If we have both Kolab and KCal values in the XML, we prefer the KCal value, but only if the + // values are still in sync + if ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom != -1 ) { + const bool inSync = ( kcalPriorityToKolab( mKCalPriorityFromDom ) == mKolabPriorityFromDom ); + if ( inSync ) { + setPriority( mKCalPriorityFromDom ); + } + else { + // Out of sync, some other client changed the Kolab priority, so we have to ignore our + // KCal priority + setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) ); + } + } + + // Only KCal priority set, use that. + else if ( mKolabPriorityFromDom == -1 && mKCalPriorityFromDom != -1 ) { + kdWarning() << "decideAndSetPriority(): No Kolab priority found, only the KCal priority!" << endl; + setPriority( mKCalPriorityFromDom ); + } + + // Only Kolab priority set, use that + else if ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom == -1 ) { + setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) ); + } + + // No priority set, use the default + else { + // According the RFC 2445, we should use 0 here, for undefined priority, but AFAIK KOrganizer + // doesn't support that, so we'll use 5. + setPriority( 5 ); + } } void Task::saveTo( KCal::Todo* task ) diff --git a/kresources/kolab/kcal/task.h b/kresources/kolab/kcal/task.h index 5dfb55854..f7e7c6d51 100644 --- a/kresources/kolab/kcal/task.h +++ b/kresources/kolab/kcal/task.h @@ -86,7 +86,9 @@ public: virtual void setHasStartDate( bool ); virtual bool hasStartDate() const; - virtual void setDueDate( const TQDateTime& date ); + virtual void setDueDate( const TQDateTime &date ); + virtual void setDueDate( const TQString &date ); + virtual void setDueDate( const TQDate &date ); virtual TQDateTime dueDate() const; virtual bool hasDueDate() const; @@ -110,7 +112,19 @@ protected: // Read all known fields from this ical todo void setFields( const KCal::Todo* ); + // This sets the priority of this task by looking at mKolabPriorityFromDom and + // mKCalPriorityFromDom. + void decideAndSetPriority(); + + // This is the KCal priority, not the Kolab priority. + // See kcalPriorityToKolab() and kolabPrioritytoKCal(). int mPriority; + + // Those priority values are the raw values read by loadAttribute(). + // They will be converted later in decideAndSetPriority(). + int mKolabPriorityFromDom; + int mKCalPriorityFromDom; + int mPercentCompleted; KCal::Incidence::Status mStatus; TQString mParent; diff --git a/kresources/kolab/knotes/kolabresource.desktop b/kresources/kolab/knotes/kolabresource.desktop index d74e3f59b..317032d17 100644 --- a/kresources/kolab/knotes/kolabresource.desktop +++ b/kresources/kolab/knotes/kolabresource.desktop @@ -21,7 +21,6 @@ Name[hu]=IMAP-kiszolgáló a KMailen keresztül Name[is]=IMAP þjónn gegnum KMail Name[it]=Server IMAP via KMail Name[ja]=KMail 経由 IMAP サーバ -Name[ka]= IMAP-ს სერვერთან დაშვება KMail-ის საშუალებით Name[kk]=KMail арқылы IMAP сервері Name[km]=ម៉ាស៊ីន​បម្រើ IMAP តាម​រយៈ KMail Name[lt]=IMAP serveris per KMail diff --git a/kresources/kolab/knotes/note.cpp b/kresources/kolab/knotes/note.cpp index 66556aaf8..168dae562 100644 --- a/kresources/kolab/knotes/note.cpp +++ b/kresources/kolab/knotes/note.cpp @@ -108,7 +108,6 @@ bool Note::richText() const bool Note::loadAttribute( TQDomElement& element ) { TQString tagName = element.tagName(); - if ( tagName == "summary" ) setSummary( element.text() ); else if ( tagName == "foreground-color" ) @@ -136,8 +135,10 @@ bool Note::saveAttributes( TQDomElement& element ) const #endif writeString( element, "summary", summary() ); - writeString( element, "foreground-color", colorToString( foregroundColor() ) ); - writeString( element, "background-color", colorToString( backgroundColor() ) ); + if ( foregroundColor().isValid() ) + writeString( element, "foreground-color", colorToString( foregroundColor() ) ); + if ( backgroundColor().isValid() ) + writeString( element, "background-color", colorToString( backgroundColor() ) ); writeString( element, "knotes-richtext", mRichText ? "true" : "false" ); return true; @@ -183,11 +184,27 @@ void Note::setFields( const KCal::Journal* journal ) { KolabBase::setFields( journal ); - // TODO: background and foreground setSummary( journal->summary() ); - setBackgroundColor( journal->customProperty( "KNotes", "BgColor" ) ); - setForegroundColor( journal->customProperty( "KNotes", "FgColor" ) ); - setRichText( journal->customProperty( "KNotes", "RichText" ) == "true" ); + + TQString property = journal->customProperty( "KNotes", "BgColor" ); + if ( !property.isNull() ) { + setBackgroundColor( property ); + } else { + setBackgroundColor( "yellow" ); + } + property = journal->customProperty( "KNotes", "FgColor" ); + if ( !property.isNull() ) { + setForegroundColor( property ); + } else { + setForegroundColor( "black" ); + } + + property = journal->customProperty( "KNotes", "RichText" ); + if ( !property.isNull() ) { + setRichText( property == "true" ? true : false ); + } else { + setRichText( "false" ); + } } void Note::saveTo( KCal::Journal* journal ) @@ -196,10 +213,12 @@ void Note::saveTo( KCal::Journal* journal ) // TODO: background and foreground journal->setSummary( summary() ); - journal->setCustomProperty( "KNotes", "FgColor", - colorToString( foregroundColor() ) ); - journal->setCustomProperty( "KNotes", "BgColor", - colorToString( backgroundColor() ) ); + if ( foregroundColor().isValid() ) + journal->setCustomProperty( "KNotes", "FgColor", + colorToString( foregroundColor() ) ); + if ( backgroundColor().isValid() ) + journal->setCustomProperty( "KNotes", "BgColor", + colorToString( backgroundColor() ) ); journal->setCustomProperty( "KNotes", "RichText", richText() ? "true" : "false" ); } diff --git a/kresources/kolab/knotes/resourcekolab.cpp b/kresources/kolab/knotes/resourcekolab.cpp index 1d633b62a..d917d0ac2 100644 --- a/kresources/kolab/knotes/resourcekolab.cpp +++ b/kresources/kolab/knotes/resourcekolab.cpp @@ -41,6 +41,7 @@ #include #include +#include using namespace Kolab; @@ -53,6 +54,9 @@ ResourceKolab::ResourceKolab( const KConfig *config ) : ResourceNotes( config ), ResourceKolabBase( "ResourceKolab-KNotes" ), mCalendar( TQString::fromLatin1("UTC") ) { + if ( !config ) { + setResourceName( i18n( "Kolab Server" ) ); + } setType( "imap" ); } @@ -73,7 +77,7 @@ bool ResourceKolab::doOpen() // Make the resource map from the folder list TQValueList::ConstIterator it; mSubResources.clear(); - for ( it = subResources.begin(); it != subResources.end(); ++it ) { + for ( it = subResources.constBegin(); it != subResources.constEnd(); ++it ) { const TQString subResource = (*it).location; const bool active = config.readBoolEntry( subResource, true ); mSubResources[ subResource ] = Kolab::SubResource( active, (*it).writable, (*it).label ); @@ -87,7 +91,7 @@ void ResourceKolab::doClose() KConfig config( configFile() ); config.setGroup( configGroupName ); Kolab::ResourceMap::ConstIterator it; - for ( it = mSubResources.begin(); it != mSubResources.end(); ++it ) + for ( it = mSubResources.constBegin(); it != mSubResources.constEnd(); ++it ) config.writeEntry( it.key(), it.data().active() ); } @@ -113,8 +117,8 @@ bool ResourceKolab::loadSubResource( const TQString& subResource, // Populate with the new entries const bool silent = mSilent; mSilent = true; - TQMap::Iterator it; - for ( it = lst.begin(); it != lst.end(); ++it ) { + TQMap::ConstIterator it; + for ( it = lst.constBegin(); it != lst.constEnd(); ++it ) { KCal::Journal* journal = addNote( it.data(), subResource, it.key(), mimetype ); if ( !journal ) kdDebug(5500) << "loading note " << it.key() << " failed" << endl; @@ -134,7 +138,7 @@ bool ResourceKolab::load() bool rc = true; Kolab::ResourceMap::ConstIterator itR; - for ( itR = mSubResources.begin(); itR != mSubResources.end(); ++itR ) { + for ( itR = mSubResources.constBegin(); itR != mSubResources.constEnd(); ++itR ) { if ( !itR.data().active() ) // This subResource is disabled continue; @@ -162,25 +166,35 @@ bool ResourceKolab::addNote( KCal::Journal* journal ) KCal::Journal* ResourceKolab::addNote( const TQString& data, const TQString& subresource, Q_UINT32 sernum, const TQString &mimetype ) { - KCal::Journal* journal = 0; - // FIXME: This does not take into account the time zone! + KCal::Journal *journal = 0; + + // FIXME: This does not take into account the time zone! KCal::ICalFormat formatter; - if ( mimetype == attachmentMimeType ) + if ( mimetype == attachmentMimeType ) { journal = Note::xmlToJournal( data ); - else + } else { journal = static_cast( formatter.fromString( data ) ); - + } Q_ASSERT( journal ); - if( journal && !mUidMap.contains( journal->uid() ) ) - if ( addNote( journal, subresource, sernum ) ) - return journal; - else - delete journal; - return 0; + + bool addedOk = journal && + !mUidMap.contains( journal->uid() ) && + addNote( journal, subresource, sernum ); + + // for debugging + if ( journal && mUidMap.contains( journal->uid() ) ) { + kdDebug(5500) << "mUidMap already contains " << journal->uid() << endl; + } + + if ( !addedOk ) { + delete journal; + journal = 0; + } + + return journal; } -bool ResourceKolab::addNote( KCal::Journal* journal, - const TQString& subresource, Q_UINT32 sernum ) +bool ResourceKolab::addNote( KCal::Journal *journal, const TQString &subresource, Q_UINT32 sernum ) { kdDebug(5500) << "ResourceKolab::addNote( KCal::Journal*, '" << subresource << "', " << sernum << " )\n"; @@ -188,12 +202,15 @@ bool ResourceKolab::addNote( KCal::Journal* journal, // Find out if this note was previously stored in KMail bool newNote = subresource.isEmpty(); - mCalendar.addJournal( journal ); + if ( !mCalendar.addJournal( journal ) ) { + return false; + } - TQString resource = - newNote ? findWritableResource( mSubResources ) : subresource; - if ( resource.isEmpty() ) // canceled + TQString resource = newNote ? findWritableResource( Kolab::Notes, mSubResources ) : subresource; + if ( resource.isEmpty() ) { + // canceled return false; + } if ( !mSilent ) { TQString xml = Note::journalToXML( journal ); @@ -209,7 +226,6 @@ bool ResourceKolab::addNote( KCal::Journal* journal, mUidMap[ journal->uid() ] = StorageReference( resource, sernum ); return true; } - return false; } @@ -225,9 +241,7 @@ bool ResourceKolab::deleteNote( KCal::Journal* journal ) mUidMap[ uid ].serialNumber() ); } mUidMap.remove( uid ); - manager()->deleteNote( journal ); - mCalendar.deleteJournal( journal ); - return true; + return mCalendar.deleteJournal( journal ); } KCal::Alarm::List ResourceKolab::alarms( const TQDateTime& from, const TQDateTime& to ) @@ -239,7 +253,7 @@ KCal::Alarm::List ResourceKolab::alarms( const TQDateTime& from, const TQDateTim { TQDateTime preTime = from.addSecs( -1 ); KCal::Alarm::List::ConstIterator it; - for( it = (*note)->alarms().begin(); it != (*note)->alarms().end(); ++it ) + for( it = (*note)->alarms().constBegin(); it != (*note)->alarms().constEnd(); ++it ) { if ( (*it)->enabled() ) { @@ -261,7 +275,7 @@ void ResourceKolab::incidenceUpdated( KCal::IncidenceBase* i ) subResource = mUidMap[ i->uid() ].resource(); sernum = mUidMap[ i->uid() ].serialNumber(); } else { // can this happen? - subResource = findWritableResource( mSubResources ); + subResource = findWritableResource( Kolab::Notes, mSubResources ); if ( subResource.isEmpty() ) // canceled return; sernum = 0; @@ -313,8 +327,11 @@ void ResourceKolab::fromKMailDelIncidence( const TQString& type, const bool silent = mSilent; mSilent = true; KCal::Journal* j = mCalendar.journal( uid ); - if( j ) - deleteNote( j ); + if ( j ) { + if ( deleteNote( j ) ) { + manager()->deleteNote( j ); + } + } mSilent = silent; } @@ -370,7 +387,7 @@ void ResourceKolab::fromKMailDelSubresource( const TQString& type, // Make a list of all uids to remove Kolab::UidMap::ConstIterator mapIt; TQStringList uids; - for ( mapIt = mUidMap.begin(); mapIt != mUidMap.end(); ++mapIt ) + for ( mapIt = mUidMap.constBegin(); mapIt != mUidMap.constEnd(); ++mapIt ) if ( mapIt.data().resource() == subResource ) // We have a match uids << mapIt.key(); @@ -380,7 +397,7 @@ void ResourceKolab::fromKMailDelSubresource( const TQString& type, const bool silent = mSilent; mSilent = true; TQStringList::ConstIterator it; - for ( it = uids.begin(); it != uids.end(); ++it ) { + for ( it = uids.constBegin(); it != uids.constEnd(); ++it ) { KCal::Journal* j = mCalendar.journal( *it ); if( j ) deleteNote( j ); @@ -405,7 +422,7 @@ void ResourceKolab::fromKMailAsyncLoadResult( const TQMap& m mimetype = attachmentMimeType; else mimetype = inlineMimeType; - for( TQMap::ConstIterator it = map.begin(); it != map.end(); ++it ) { + for( TQMap::ConstIterator it = map.constBegin(); it != map.constEnd(); ++it ) { KCal::Journal* journal = addNote( it.data(), folder, it.key(), mimetype ); if ( !journal ) kdDebug(5500) << "loading note " << it.key() << " failed" << endl; @@ -433,5 +450,14 @@ bool ResourceKolab::subresourceActive( const TQString& res ) const return true; } +bool ResourceKolab::subresourceWritable( const TQString& res ) const +{ + if ( mSubResources.contains( res ) ) { + return mSubResources[ res ].writable(); + } + + // Safe default bet: + return false; +} #include "resourcekolab.moc" diff --git a/kresources/kolab/knotes/resourcekolab.h b/kresources/kolab/knotes/resourcekolab.h index a738a30a5..6ff994ccf 100644 --- a/kresources/kolab/knotes/resourcekolab.h +++ b/kresources/kolab/knotes/resourcekolab.h @@ -102,6 +102,9 @@ public: /** Is this subresource active? */ bool subresourceActive( const TQString& ) const; + /** Is this subresource writable? */ + bool subresourceWritable( const TQString& ) const; + signals: void signalSubresourceAdded( Resource*, const TQString&, const TQString& ); void signalSubresourceRemoved( Resource*, const TQString&, const TQString& ); diff --git a/kresources/kolab/shared/kmailconnection.cpp b/kresources/kolab/shared/kmailconnection.cpp index 9135e16db..66674abfa 100644 --- a/kresources/kolab/shared/kmailconnection.cpp +++ b/kresources/kolab/shared/kmailconnection.cpp @@ -73,16 +73,38 @@ static const TQCString dcopObjectId = "KMailICalIface"; bool KMailConnection::connectToKMail() { if ( !mKMailIcalIfaceStub ) { - TQString error; TQCString dcopService; - int result = KDCOPServiceStarter::self()-> - findServiceFor( "DCOP/ResourceBackend/IMAP", TQString::null, - TQString::null, &error, &dcopService ); - if ( result != 0 ) { - kdError(5650) << "Couldn't connect to the IMAP resource backend\n"; - // TODO: You might want to show "error" (if not empty) here, - // using e.g. KMessageBox - return false; + + // if we are kmail (and probably kontact as well) ourselves, don't try to start us again + // this prevents a DCOP deadlock when launching the kmail while kontact is the IMAP backend + // provider (and probably vice versa) + if ( kapp->instanceName() == "kmail" ) { + // someone, probably ourselves, already offers the interface, if not stop here + const QCStringList services = kapp->dcopClient()->registeredApplications(); + for ( uint i = 0; i < services.count(); ++i ) { + if ( services[i].find( "anonymous" ) == 0 ) // querying anonymous-XXXXX deadlocks as well, what are those anyway? + continue; + const QCStringList objs = kapp->dcopClient()->remoteObjects( services[i] ); + if ( objs.contains( dcopObjectId ) ) { + dcopService = services[i]; + break; + } + } + if ( dcopService.isEmpty() ) { + kdError(5650) << k_funcinfo << "Not connecting to KMail to prevent DCOP deadlock" << endl; + return false; + } + } else { + TQString error; + int result = KDCOPServiceStarter::self()-> + findServiceFor( "DCOP/ResourceBackend/IMAP", TQString::null, + TQString::null, &error, &dcopService ); + if ( result != 0 ) { + kdError(5650) << "Couldn't connect to the IMAP resource backend\n"; + // TODO: You might want to show "error" (if not empty) here, + // using e.g. KMessageBox + return false; + } } mKMailIcalIfaceStub = new KMailICalIface_stub( kapp->dcopClient(), diff --git a/kresources/kolab/shared/kolabbase.cpp b/kresources/kolab/shared/kolabbase.cpp index 9a4a17f7c..b7f502576 100644 --- a/kresources/kolab/shared/kolabbase.cpp +++ b/kresources/kolab/shared/kolabbase.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -257,8 +258,16 @@ bool KolabBase::loadEmailAttribute( TQDomElement& element, Email& email ) TQDomElement e = n.toElement(); const TQString tagName = e.tagName(); - if ( tagName == "display-name" ) - email.displayName = e.text(); + if ( tagName == "display-name" ) { + // Quote the text in case it contains commas or other quotable chars. + TQString tusername = KPIM::quoteNameIfNecessary( e.text() ); + + TQString tname, temail; + // ignore the return value because it will always be false since + // tusername does not contain "@domain". + KPIM::getNameAndMail( tusername, tname, temail ); + email.displayName = tname; + } else if ( tagName == "smtp-address" ) email.smtpAddress = e.text(); else @@ -411,7 +420,11 @@ TQString KolabBase::dateToString( const TQDate& date ) TQDateTime KolabBase::stringToDateTime( const TQString& _date ) { TQString date( _date ); - if ( date.endsWith( "Z" ) ) + //Deal with data from some clients that always append a Z to dates. + if ( date.endsWith( "ZZ" ) ) + date.truncate( date.length() - 2 ); + //In TQt3, TQt::ISODate cannot handle a trailing Z for UTC, so remove if found. + else if ( date.endsWith( "Z" ) ) date.truncate( date.length() - 1 ); return TQDateTime::fromString( date, Qt::ISODate ); } diff --git a/kresources/kolab/shared/resourcekolabbase.cpp b/kresources/kolab/shared/resourcekolabbase.cpp index 291910fb9..2db2117db 100644 --- a/kresources/kolab/shared/resourcekolabbase.cpp +++ b/kresources/kolab/shared/resourcekolabbase.cpp @@ -210,9 +210,12 @@ bool ResourceKolabBase::kmailRemoveSubresource( const TQString& resource ) return mConnection->kmailRemoveSubresource( resource ); } -TQString ResourceKolabBase::findWritableResource( const ResourceMap& resources, +TQString ResourceKolabBase::findWritableResource( const ResourceType &type, + const ResourceMap& resources, const TQString& text ) { + mErrorCode = NoError; + // I have to use the label (shown in the dialog) as key here. But given how the // label is made up, it should be unique. If it's not, well the dialog would suck anyway... TQMap possible; @@ -227,7 +230,33 @@ TQString ResourceKolabBase::findWritableResource( const ResourceMap& resources, if ( possible.isEmpty() ) { // None found!! kdWarning(5650) << "No writable resource found!" << endl; - KMessageBox::error( 0, i18n( "No writable resource was found, saving will not be possible. Reconfigure KMail first." ) ); + + TQString errorText; + switch( type ) { + case Events: + errorText = i18n( "You have no writable event folders so saving will not be possible.\n" + "Please create or activate at least one writable event folder and try again." ); + break; + case Tasks: + errorText = i18n( "You have no writable task folders so saving will not be possible.\n" + "Please create or activate at least one writable task folder and try again." ); + break; + case Incidences: + errorText = i18n( "You have no writable calendar folder so saving will not be possible.\n" + "Please create or activate at least one writable calendar folder and try again." ); + break; + case Notes: + errorText = i18n( "You have no writable notes folders so saving will not be possible.\n" + "Please create or activate at least one writable notes folder and try again." ); + break; + case Contacts: + errorText = i18n( "You have no writable addressbook folder so saving will not be possible.\n" + "Please create or activate at least one writable addressbook folder and try again." ); + break; + } + + KMessageBox::error( 0, errorText ); + mErrorCode = NoWritableFound; return TQString::null; } if ( possible.count() == 1 ) @@ -242,8 +271,11 @@ TQString ResourceKolabBase::findWritableResource( const ResourceMap& resources, // Several found, ask the user TQString chosenLabel = KPIM::FolderSelectDialog::getItem( i18n( "Select Resource Folder" ), t, possible.keys() ); - if ( chosenLabel.isEmpty() ) // cancelled + if ( chosenLabel.isEmpty() ) { + // cancelled + mErrorCode = UserCancel; return TQString::null; + } return possible[chosenLabel]; } diff --git a/kresources/kolab/shared/resourcekolabbase.h b/kresources/kolab/shared/resourcekolabbase.h index b2ce0501f..1bd8b9515 100644 --- a/kresources/kolab/shared/resourcekolabbase.h +++ b/kresources/kolab/shared/resourcekolabbase.h @@ -46,6 +46,8 @@ class KURL; namespace Kolab { +enum ResourceType { Tasks, Events, Incidences, Contacts, Notes }; + class KMailConnection; /** @@ -168,9 +170,17 @@ protected: TQString configFile( const TQString& type ) const; /// If only one of these is writable, return that. Otherwise return null. - TQString findWritableResource( const ResourceMap& resources, + TQString findWritableResource( const ResourceType &type, + const ResourceMap& resources, const TQString& text = TQString::null ); + enum ErrorCode { + NoError, + NoWritableFound, /**< No writable resource is available */ + UserCancel /**< User canceled the operation */ + }; + ErrorCode mErrorCode; + bool mSilent; /** -- cgit v1.2.1