diff --git a/kmailicalifaceimpl.cpp b/kmailicalifaceimpl.cpp index 8dd411aa9..6d2f5b81e 100644 --- a/kmailicalifaceimpl.cpp +++ b/kmailicalifaceimpl.cpp @@ -78,13 +78,14 @@ static const struct { const char* mimetype; KFolderTreeItem::Type treeItemType; const char* annotation; + const char* translatedName; } s_folderContentsType[] = { - { "Mail", "application/x-vnd.kolab.mail", KFolderTreeItem::Other, "mail"}, - { "Calendar", "application/x-vnd.kolab.event", KFolderTreeItem::Calendar, "event" }, - { "Contact", "application/x-vnd.kolab.contact", KFolderTreeItem::Contacts, "contact" }, - { "Note", "application/x-vnd.kolab.note", KFolderTreeItem::Notes, "note" }, - { "Task", "application/x-vnd.kolab.task", KFolderTreeItem::Tasks, "task" }, - { "Journal", "application/x-vnd.kolab.journal", KFolderTreeItem::Journals, "journal" } + { "Mail", "application/x-vnd.kolab.mail", KFolderTreeItem::Other, "mail", I18N_NOOP( "Mail" ) }, + { "Calendar", "application/x-vnd.kolab.event", KFolderTreeItem::Calendar, "event", I18N_NOOP( "Calendar" ) }, + { "Contact", "application/x-vnd.kolab.contact", KFolderTreeItem::Contacts, "contact", I18N_NOOP( "Contacts" ) }, + { "Note", "application/x-vnd.kolab.note", KFolderTreeItem::Notes, "note", I18N_NOOP( "Notes" ) }, + { "Task", "application/x-vnd.kolab.task", KFolderTreeItem::Tasks, "task", I18N_NOOP( "Tasks" ) }, + { "Journal", "application/x-vnd.kolab.journal", KFolderTreeItem::Journals, "journal", I18N_NOOP( "Journal" ) } }; static QString folderContentsType( KMail::FolderContentsType type ) @@ -128,8 +129,8 @@ const char* KMailICalIfaceImpl::annotationForContentsType( KMail::FolderContents KMailICalIfaceImpl::KMailICalIfaceImpl() : DCOPObject( "KMailICalIface" ), QObject( 0, "KMailICalIfaceImpl" ), mContacts( 0 ), mCalendar( 0 ), mNotes( 0 ), mTasks( 0 ), mJournals( 0 ), - mFolderLanguage( 0 ), mUseResourceIMAP( false ), mResourceQuiet( false ), - mHideFolders( true ) + mFolderLanguage( 0 ), mFolderParentDir( 0 ), mFolderType( KMFolderTypeUnknown ), + mUseResourceIMAP( false ), mResourceQuiet( false ), mHideFolders( true ) { // Listen to config changes connect( kmkernel, SIGNAL( configChanged() ), this, SLOT( readConfig() ) ); @@ -1339,7 +1340,7 @@ void KMailICalIfaceImpl::slotFolderRenamed() void KMailICalIfaceImpl::slotFolderLocationChanged( const QString &oldLocation, const QString &newLocation ) { - KMFolder *folder = findResourceFolder( oldLocation ); + KMFolder *folder = findResourceFolder( oldLocation ); ExtraFolder* ef = mExtraFolders.find( oldLocation ); if ( ef ) { // reuse the ExtraFolder entry, but adjust the key @@ -1349,7 +1350,7 @@ void KMailICalIfaceImpl::slotFolderLocationChanged( const QString &oldLocation, mExtraFolders.insert( newLocation, ef ); } if ( folder ) - subresourceDeleted( folderContentsType( folder->storage()->contentsType() ), oldLocation ); + subresourceDeleted( folderContentsType( folder->storage()->contentsType() ), oldLocation ); } @@ -1431,56 +1432,25 @@ void KMailICalIfaceImpl::readConfig() } // Make sure the folder parent has the subdirs - bool makeSubFolders = false; - KMFolder* folder; - folder = findStandardResourceFolder( folderParentDir, KMail::ContentsTypeCalendar ); - if( !folder ) { - kdDebug(5006) << "Calendar folder not found in " << parentName << endl; - makeSubFolders = true; - mCalendar = 0; - } - folder = findStandardResourceFolder( folderParentDir, KMail::ContentsTypeTask ); - if( !folder ) { - kdDebug(5006) << "Tasks folder not found in " << parentName << endl; - makeSubFolders = true; - mTasks = 0; - } - folder = findStandardResourceFolder( folderParentDir, KMail::ContentsTypeJournal ); - if( !folder ) { - kdDebug(5006) << "Journals folder not found in " << parentName << endl; - makeSubFolders = true; - mJournals = 0; - } - folder = findStandardResourceFolder( folderParentDir, KMail::ContentsTypeContact ); - if( !folder ) { - kdDebug(5006) << "Contacts folder not found in " << parentName << endl; - makeSubFolders = true; - mContacts = 0; - } - folder = findStandardResourceFolder( folderParentDir, KMail::ContentsTypeNote ); - if( !folder ) { - kdDebug(5006) << "Notes folder not found in " << parentName << endl; - makeSubFolders = true; - mNotes = 0; - } - if( makeSubFolders ) { - // Not all subfolders were there, so ask if we can make them - if( KMessageBox::questionYesNo( 0, i18n("KMail will now create the required folders for the IMAP resource" - " as subfolders of %1; if you do not want this, press \"No\"," - " and the IMAP resource will be disabled").arg(folderParent!=0?folderParent->name():folderParentDir->name()), - i18n("IMAP Resource Folders") ) == KMessageBox::No ) { - - GlobalSettings::self()->setTheIMAPResourceEnabled( false ); - mUseResourceIMAP = false; - mFolderParentDir = 0; - mFolderParent = 0; - reloadFolderTree(); - return; + // Globally there are 3 cases: nothing found, some stuff found by type/name heuristics, or everything found OK + bool noneFound = true; + bool mustWarn = false; // true when at least one was found by heuristics + QValueVector results( KMail::ContentsTypeLast + 1 ); + for ( int i = 0; i < KMail::ContentsTypeLast+1; ++i ) { + if ( i != KMail::ContentsTypeMail ) { + results[i] = findStandardResourceFolder( folderParentDir, static_cast(i) ); + if ( results[i].found == StandardFolderSearchResult::FoundAndStandard ) + noneFound = false; + else if ( results[i].found == StandardFolderSearchResult::FoundByType || + results[i].found == StandardFolderSearchResult::FoundByName ) { + mustWarn = true; + noneFound = false; + } } } // Check if something changed - if( mUseResourceIMAP && !makeSubFolders && mFolderParentDir == folderParentDir + if( mUseResourceIMAP && !noneFound && !mustWarn && mFolderParentDir == folderParentDir && mFolderType == folderType ) { // Nothing changed if ( hideFolders != mHideFolders ) { @@ -1491,6 +1461,47 @@ void KMailICalIfaceImpl::readConfig() return; } + if( noneFound || mustWarn ) { + QString msg; + QString parentFolderName = folderParent != 0 ? folderParent->name() : folderParentDir->name(); + if ( noneFound ) { + // No subfolder was found, so ask if we can make them + msg = i18n("KMail will now create the required groupware folders" + " as subfolders of %1; if you do not want this, press \"No\"," + " and the IMAP resource will be disabled").arg(parentFolderName); + } else { + // Some subfolders were found, be more precise + QString operations = ""; + + msg = i18n("KMail found the following groupware folders in %1 and needs to perform the following operations: %2" + "
If you do not want this, press \"No\"," + " and the IMAP resource will be disabled").arg(parentFolderName, operations); + + } + + if( KMessageBox::questionYesNo( 0, msg, + i18n("Standard Groupware Folders") ) == KMessageBox::No ) { + + GlobalSettings::self()->setTheIMAPResourceEnabled( false ); + mUseResourceIMAP = false; + mFolderParentDir = 0; + mFolderParent = 0; + reloadFolderTree(); + return; + } + } + // Make the new settings work mUseResourceIMAP = true; mFolderLanguage = GlobalSettings::self()->theIMAPResourceFolderLanguage(); @@ -1592,17 +1603,8 @@ KMFolder* KMailICalIfaceImpl::initFolder( KMail::FolderContentsType contentsType //kdDebug(5006) << "KMailICalIfaceImpl::initFolder " << folderName( itemType ) << endl; // Find the folder - KMFolder* folder = findStandardResourceFolder( mFolderParentDir, contentsType ); - if( !folder && globalStorageFormat() == StorageXML ) { - // Maybe there's a folder with the right name - well, change its type then - KMFolderNode* node = mFolderParentDir->hasNamedFolder( folderName( itemType ) ); - if ( node && !node->isDir() ) { - folder = static_cast( node ); - folder->storage()->setContentsType( contentsType ); - kdDebug(5006) << "Adjusted type of " << folder->location() << " to contentsType " << contentsType << endl; - folder->storage()->writeConfig(); - } - } + StandardFolderSearchResult result = findStandardResourceFolder( mFolderParentDir, contentsType ); + KMFolder* folder = result.folder; if ( !folder ) { // The folder isn't there yet - create it @@ -1743,24 +1745,44 @@ static void vPartMicroParser( const QString& str, QString& s ) s.truncate(0); } -KMFolder* KMailICalIfaceImpl::findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType ) +// Returns the first child folder having the given annotation +static KMFolder* findFolderByAnnotation( KMFolderDir* folderParentDir, const QString& annotation ) { - if ( GlobalSettings::self()->theIMAPResourceStorageFormat() == GlobalSettings::EnumTheIMAPResourceStorageFormat::XML ) - { - // Look for a folder with an annotation like "event.default" QPtrListIterator it( *folderParentDir ); for ( ; it.current(); ++it ) { if ( !it.current()->isDir() ) { KMFolder* folder = static_cast( it.current() ); if ( folder->folderType() == KMFolderTypeCachedImap ) { - QString annotation = static_cast( folder->storage() )->annotationFolderType(); - //kdDebug(5006) << "findStandardResourceFolder: " << folder->name() << " has annotation " << annotation << endl; - if ( annotation == QString( s_folderContentsType[contentsType].annotation ) + ".default" ) + QString folderAnnotation = static_cast( folder->storage() )->annotationFolderType(); + //kdDebug(5006) << "findStandardResourceFolder: " << folder->name() << " has annotation " << folderAnnotation << endl; + if ( folderAnnotation == annotation ) return folder; } } } - kdDebug(5006) << "findStandardResourceFolder: no standard resource folder for " << s_folderContentsType[contentsType].annotation << endl; + return 0; +} + +KMailICalIfaceImpl::StandardFolderSearchResult KMailICalIfaceImpl::findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType ) +{ + 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 ); + + // 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 ); + + // Fallback: look for the folder by name (we'll need to change its type) + KMFolderNode* node = folderParentDir->hasNamedFolder( s_folderContentsType[contentsType].contentsTypeStr ); + if ( node && !node->isDir() ) + return StandardFolderSearchResult( static_cast( node ), StandardFolderSearchResult::FoundByName ); + + kdDebug(5006) << "findStandardResourceFolder: found no resource folder for " << s_folderContentsType[contentsType].annotation << endl; return 0; } else // icalvcard: look up standard resource folders by name diff --git a/kmailicalifaceimpl.h b/kmailicalifaceimpl.h index 4c4152c6f..6c3f072bc 100644 --- a/kmailicalifaceimpl.h +++ b/kmailicalifaceimpl.h @@ -229,7 +229,15 @@ private: KMFolder* extraFolder( const QString& type, const QString& folder ); - KMFolder* findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType ); + struct StandardFolderSearchResult + { + enum FoundEnum { FoundAndStandard, NotFound, FoundByType, FoundByName }; + StandardFolderSearchResult( KMFolder* f = 0, FoundEnum e = NotFound ) : folder( f ), found( e ) {} + KMFolder* folder; // NotFound implies folder==0 of course. + FoundEnum found; + }; + + StandardFolderSearchResult findStandardResourceFolder( KMFolderDir* folderParentDir, KMail::FolderContentsType contentsType ); KMFolder* findResourceFolder( const QString& resource ); @@ -282,7 +290,7 @@ private: typedef QMap FolderInfoMap; // helper for reading the FolderInfo from the config file FolderInfo readFolderInfo( const KMFolder * const folder ) const; - + FolderInfoMap mFolderInfoMap; unsigned int mFolderLanguage;