diff --git a/kmailicalifaceimpl.cpp b/kmailicalifaceimpl.cpp index 686649872..b38438628 100644 --- a/kmailicalifaceimpl.cpp +++ b/kmailicalifaceimpl.cpp @@ -66,6 +66,7 @@ using KMail::AccountManager; #include #include +#include #include #include #include @@ -1812,8 +1813,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() ); } } @@ -1957,6 +1959,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 ) { @@ -2156,21 +2171,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 ) @@ -2178,14 +2194,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 3f8a09e6f..c16a2288b 100644 --- a/kmailicalifaceimpl.h +++ b/kmailicalifaceimpl.h @@ -285,7 +285,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 ),