From b5b410950e04d28b929d52316f5af266a8ea6d32 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 21 Aug 2008 20:07:25 +0000 Subject: [PATCH] Merged revisions 850360 via svnmerge from svn+ssh://tmcguire@svn.kde.org/home/kde/branches/kdepim/enterprise4/kdepim ................ r850360 | ervin | 2008-08-21 12:32:05 +0200 (Thu, 21 Aug 2008) | 12 lines Merged revisions 787716 via svnmerge from svn+ssh://ervin@svn.kde.org/home/kde/branches/kdepim/enterprise/kdepim ........ r787716 | vkrause | 2008-03-19 18:41:52 +0100 (Wed, 19 Mar 2008) | 5 lines Recover from situations where multiple folders are marked as default groupware folder. Kolab issue 2290 ........ ................ svn path=/trunk/KDE/kdepim/; revision=850591 --- kmailicalifaceimpl.cpp | 58 +++++++++++++++++++++++++++--------------- kmailicalifaceimpl.h | 3 +++ kmfoldercachedimap.cpp | 7 +++-- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/kmailicalifaceimpl.cpp b/kmailicalifaceimpl.cpp index 914f01391..59b043779 100644 --- a/kmailicalifaceimpl.cpp +++ b/kmailicalifaceimpl.cpp @@ -66,6 +66,7 @@ using KMail::AccountManager; #include #include +#include #include #include #include @@ -1783,8 +1784,9 @@ void KMailICalIfaceImpl::readConfig() for(QList >::iterator it = folderList.begin(); it != folderList.end(); ++it) { - FolderStorage* storage = (*it)->storage(); - if ( storage->contentsType() != 0 ) { + KMFolderCachedImap* storage = dynamic_cast( (*it)->storage() ); + if ( storage && storage->contentsType() != 0 ) { + storage->updateAnnotationFolderType(); folderContentsTypeChanged( *it, storage->contentsType() ); } } @@ -1928,6 +1930,19 @@ KMFolder* KMailICalIfaceImpl::initFolder( KMail::FolderContentsType contentsType // Find the folder StandardFolderSearchResult result = findStandardResourceFolder( mFolderParentDir, contentsType ); + + // deal with multiple default groupware folders + if ( result.folders.count() > 1 && result.found == StandardFolderSearchResult::FoundAndStandard ) { + QStringList labels; + for ( QList::ConstIterator it = result.folders.begin(); it != result.folders.end(); ++it ) + labels << (*it)->prettyUrl(); + const QString selected = KInputDialog::getItem( i18n("Default folder"), + i18n("There are multiple %1 default folders, please choose one:", + localizedDefaultFolderName( contentsType ) ), labels ); + if ( !selected.isEmpty() ) + result.folder = result.folders[ labels.findIndex( selected ) ]; + } + KMFolder* folder = result.folder; if ( !folder ) { @@ -2127,21 +2142,22 @@ static void vPartMicroParser( const QString& str, QString& s ) } // Returns the first child folder having the given annotation -static KMFolder* findFolderByAnnotation( KMFolderDir* folderParentDir, const QString& annotation ) -{ - QList::const_iterator it; - for ( it = folderParentDir->begin(); it != folderParentDir->end(); ++it ) { - if ( !(*it)->isDir() ) { - KMFolder* folder = static_cast( *it ); - if ( folder->folderType() == KMFolderTypeCachedImap ) { - QString folderAnnotation = static_cast( folder->storage() )->annotationFolderType(); - //kDebug() <<"findStandardResourceFolder:" << folder->name() <<" has annotation" << folderAnnotation; - if ( folderAnnotation == annotation ) - return folder; - } +static QList findFolderByAnnotation( KMFolderDir* folderParentDir, const QString& annotation ) +{ + QList rv; + QList::const_iterator it; + for ( it = folderParentDir->begin(); it != folderParentDir->end(); ++it ) { + if ( !(*it)->isDir() ) { + KMFolder* folder = static_cast( *it ); + if ( folder->folderType() == KMFolderTypeCachedImap ) { + QString folderAnnotation = static_cast( folder->storage() )->annotationFolderType(); + //kDebug() <<"findStandardResourceFolder:" << folder->name() <<" has annotation" << folderAnnotation; + if ( folderAnnotation == annotation ) + rv.append( folder ); } } - return 0; + } + return rv; } KMailICalIfaceImpl::StandardFolderSearchResult KMailICalIfaceImpl::findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType ) @@ -2149,14 +2165,14 @@ KMailICalIfaceImpl::StandardFolderSearchResult KMailICalIfaceImpl::findStandardR if ( GlobalSettings::self()->theIMAPResourceStorageFormat() == GlobalSettings::EnumTheIMAPResourceStorageFormat::XML ) { // Look for a folder with an annotation like "event.default" - KMFolder* folder = findFolderByAnnotation( folderParentDir, QString( s_folderContentsType[contentsType].annotation ) + ".default" ); - if ( folder ) - return StandardFolderSearchResult( folder, StandardFolderSearchResult::FoundAndStandard ); + QList folders = findFolderByAnnotation( folderParentDir, QString( s_folderContentsType[contentsType].annotation ) + ".default" ); + if ( !folders.isEmpty() ) + return StandardFolderSearchResult( folders, StandardFolderSearchResult::FoundAndStandard ); // Fallback: look for a folder with an annotation like "event" - folder = findFolderByAnnotation( folderParentDir, QString( s_folderContentsType[contentsType].annotation ) ); - if ( folder ) - return StandardFolderSearchResult( folder, StandardFolderSearchResult::FoundByType ); + folders = findFolderByAnnotation( folderParentDir, QString( s_folderContentsType[contentsType].annotation ) ); + if ( !folders.isEmpty() ) + return StandardFolderSearchResult( folders, StandardFolderSearchResult::FoundByType ); // Fallback: look for the folder by name (we'll need to change its type) KMFolderNode* node = folderParentDir->hasNamedFolder( localizedDefaultFolderName( contentsType ) ); diff --git a/kmailicalifaceimpl.h b/kmailicalifaceimpl.h index 84f09dccd..ed1604f14 100644 --- a/kmailicalifaceimpl.h +++ b/kmailicalifaceimpl.h @@ -281,7 +281,10 @@ private: enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName }; StandardFolderSearchResult() : folder( 0 ) {} StandardFolderSearchResult( KMFolder* f, FoundEnum e ) : folder( f ), found( e ) {} + StandardFolderSearchResult( const QList &f, FoundEnum e ) : + folder( f.first() ), folders( f ), found( e ) {} KMFolder* folder; // NotFound implies folder==0 of course. + QList folders; // in case we found multiple default folders (which should not happen) FoundEnum found; }; diff --git a/kmfoldercachedimap.cpp b/kmfoldercachedimap.cpp index cacc9400f..4dc5528e7 100644 --- a/kmfoldercachedimap.cpp +++ b/kmfoldercachedimap.cpp @@ -2498,9 +2498,8 @@ void KMFolderCachedImap::updateAnnotationFolderType() newType = KMailICalIfaceImpl::annotationForContentsType( mContentsType ); if ( kmkernel->iCalIface().isStandardResourceFolder( folder() ) ) { newSubType = "default"; - } else { - // preserve unknown subtypes, like drafts etc. And preserve ".default" too. - newSubType = oldSubType; + } else if ( oldSubType != "default" ) { + newSubType = oldSubType; // preserve unknown subtypes, like drafts etc. } } @@ -2806,7 +2805,7 @@ void KMFolderCachedImap::slotSetAnnotationResult( KJob *job ) contentsType() == ContentsTypeMail ) { if ( mAccount->slave() ) { mAccount->removeJob( static_cast( job ) ); - } + } } else { cont = mAccount->handleJobError( static_cast( job ),