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 --- kmail/kmfolderdir.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'kmail/kmfolderdir.cpp') diff --git a/kmail/kmfolderdir.cpp b/kmail/kmfolderdir.cpp index 46aba345..1ecab637 100644 --- a/kmail/kmfolderdir.cpp +++ b/kmail/kmfolderdir.cpp @@ -163,6 +163,31 @@ TQString KMFolderDir::prettyURL() const return label(); } +//----------------------------------------------------------------------------- +void KMFolderDir::addDirToParent( const TQString &dirName, KMFolder *parentFolder ) +{ + KMFolderDir* folderDir = new KMFolderDir( parentFolder, this, dirName, mDirType); + folderDir->reload(); + append( folderDir ); + parentFolder->setChild( folderDir ); +} + +// Get the default folder type of the given dir type. This function should only be used when +// needing to find out what the folder type of a missing folder is. +KMFolderType dirTypeToFolderType( KMFolderDirType dirType ) +{ + switch( dirType ) { + + // Use maildir for normal folder dirs, as this function is only called when finding a dir + // without a parent folder, which can only happen with maildir-like folders + case KMStandardDir: return KMFolderTypeMaildir; + + case KMImapDir: return KMFolderTypeImap; + case KMDImapDir: return KMFolderTypeCachedImap; + case KMSearchDir: return KMFolderTypeSearch; + default: Q_ASSERT( false ); return KMFolderTypeMaildir; + } +} //----------------------------------------------------------------------------- bool KMFolderDir::reload(void) @@ -272,6 +297,7 @@ bool KMFolderDir::reload(void) } } + TQStringList dirsWithoutFolder = diList; for (folder=folderList.first(); folder; folder=folderList.next()) { for(TQStringList::Iterator it = diList.begin(); @@ -279,13 +305,36 @@ bool KMFolderDir::reload(void) ++it) if (*it == "." + folder->fileName() + ".directory") { - KMFolderDir* folderDir = new KMFolderDir( folder, this, *it, mDirType); - folderDir->reload(); - append(folderDir); - folder->setChild(folderDir); + dirsWithoutFolder.remove( *it ); + addDirToParent( *it, folder ); break; } } + + // Check if the are any dirs without an associated folder. This can happen if the user messes + // with the on-disk folder structure, see kolab issue 2972. In that case, we don't want to loose + // the subfolders as well, so we recreate the folder so the folder/dir hierachy is OK again. + if ( type() == KMDImapDir ) { + for ( TQStringList::Iterator it = dirsWithoutFolder.begin(); + it != dirsWithoutFolder.end(); ++it ) { + + // .foo.directory => foo + TQString folderName = *it; + int right = folderName.find( ".directory" ); + int left = folderName.find( "." ); + Q_ASSERT( left != -1 && right != -1 ); + folderName = folderName.mid( left + 1, right - 1 ); + + kdDebug(5006) << "Found dir without associated folder: " << ( *it ) << ", recreating the folder " << folderName << "." << endl; + + // Recreate the missing folder + KMFolder *folder = new KMFolder( this, folderName, KMFolderTypeCachedImap ); + append( folder ); + folderList.append( folder ); + + addDirToParent( *it, folder ); + } + } return TRUE; } -- cgit v1.2.3