diff options
Diffstat (limited to 'kmail/newfolderdialog.cpp')
-rw-r--r-- | kmail/newfolderdialog.cpp | 102 |
1 files changed, 22 insertions, 80 deletions
diff --git a/kmail/newfolderdialog.cpp b/kmail/newfolderdialog.cpp index 78294e5f9..99051222e 100644 --- a/kmail/newfolderdialog.cpp +++ b/kmail/newfolderdialog.cpp @@ -40,6 +40,7 @@ #include <kdialogbase.h> #include <kmessagebox.h> +#include "folderutil.h" #include "newfolderdialog.h" #include "kmfolder.h" #include "folderstorage.h" @@ -58,6 +59,9 @@ NewFolderDialog::NewFolderDialog( TQWidget* parent, KMFolder *folder ) : KDialogBase( parent, "new_folder_dialog", false, i18n( "New Folder" ), KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ), + mFormatComboBox( 0 ), + mContentsComboBox( 0 ), + mNamespacesComboBox( 0 ), mFolder( folder ) { setWFlags( getWFlags() | WDestructiveClose ); @@ -112,7 +116,8 @@ NewFolderDialog::NewFolderDialog( TQWidget* parent, KMFolder *folder ) } // --- contents ----- - if ( kmkernel->iCalIface().isEnabled() ) { + if ( kmkernel->iCalIface().isEnabled() && + mFolder && mFolder->folderType() != KMFolderTypeImap ) { mContentsHBox = new TQHBoxLayout( 0, 0, 6, "mContentsHBox"); mContentsLabel = new TQLabel( privateLayoutWidget, "mContentsLabel" ); @@ -190,41 +195,12 @@ void NewFolderDialog::slotOk() return; } - // names of local folders must not contain a '/' - if ( fldName.find( '/' ) != -1 && - ( !mFolder || - ( mFolder->folderType() != KMFolderTypeImap && - mFolder->folderType() != KMFolderTypeCachedImap ) ) ) { - KMessageBox::error( this, i18n( "Folder names cannot contain the / (slash) character; please choose another folder name." ) ); + TQString msg; + if ( mFolder && !mFolder->isValidName( fldName, msg ) ) { + KMessageBox::error( this, msg ); return; } - // folder names must not start with a '.' - if ( fldName.startsWith( "." ) ) { - KMessageBox::error( this, i18n( "Folder names cannot start with a . (dot) character; please choose another folder name." ) ); - return; - } - - // names of IMAP folders must not contain the folder delimiter - if ( mFolder && - ( mFolder->folderType() == KMFolderTypeImap || - mFolder->folderType() == KMFolderTypeCachedImap ) ) { - TQString delimiter; - if ( mFolder->folderType() == KMFolderTypeImap ) { - KMAcctImap* ai = static_cast<KMFolderImap*>( mFolder->storage() )->account(); - if ( ai ) - delimiter = ai->delimiterForFolder( mFolder->storage() ); - } else { - KMAcctCachedImap* ai = static_cast<KMFolderCachedImap*>( mFolder->storage() )->account(); - if ( ai ) - delimiter = ai->delimiterForFolder( mFolder->storage() ); - } - if ( !delimiter.isEmpty() && fldName.find( delimiter ) != -1 ) { - KMessageBox::error( this, i18n( "Your IMAP server does not allow the character '%1'; please choose another folder name." ).arg( delimiter ) ); - return; - } - } - // default parent is Top Level local folders KMFolderDir * selectedFolderDir = &(kmkernel->folderMgr()->dir()); // we got a parent, let's use that @@ -245,55 +221,21 @@ void NewFolderDialog::slotOk() /* Ok, obvious errors caught, let's try creating it for real. */ const TQString message = i18n( "<qt>Failed to create folder <b>%1</b>." "</qt> " ).arg(fldName); - bool success = false; - KMFolder *newFolder = 0; - if ( mFolder && mFolder->folderType() == KMFolderTypeImap ) { - KMFolderImap* selectedStorage = static_cast<KMFolderImap*>( mFolder->storage() ); - KMAcctImap *anAccount = selectedStorage->account(); - // check if a connection is available BEFORE creating the folder - if (anAccount->makeConnection() == ImapAccountBase::Connected) { - newFolder = kmkernel->imapFolderMgr()->createFolder( fldName, false, KMFolderTypeImap, selectedFolderDir ); - if ( newFolder ) { - TQString imapPath, parent; - if ( mNamespacesComboBox ) { - // create folder with namespace - parent = anAccount->addPathToNamespace( mNamespacesComboBox->currentText() ); - imapPath = anAccount->createImapPath( parent, fldName ); - } else { - imapPath = anAccount->createImapPath( selectedStorage->imapPath(), fldName ); - } - KMFolderImap* newStorage = static_cast<KMFolderImap*>( newFolder->storage() ); - selectedStorage->createFolder(fldName, parent); // create it on the server - newStorage->initializeFrom( selectedStorage, imapPath, TQString::null ); - static_cast<KMFolderImap*>(mFolder->storage())->setAccount( selectedStorage->account() ); - success = true; - } - } - } else if ( mFolder && mFolder->folderType() == KMFolderTypeCachedImap ) { - newFolder = kmkernel->dimapFolderMgr()->createFolder( fldName, false, KMFolderTypeCachedImap, selectedFolderDir ); - if ( newFolder ) { - KMFolderCachedImap* selectedStorage = static_cast<KMFolderCachedImap*>( mFolder->storage() ); - KMFolderCachedImap* newStorage = static_cast<KMFolderCachedImap*>( newFolder->storage() ); - newStorage->initializeFrom( selectedStorage ); - if ( mNamespacesComboBox ) { - // create folder with namespace - TQString path = selectedStorage->account()->createImapPath( - mNamespacesComboBox->currentText(), fldName ); - newStorage->setImapPathForCreation( path ); - } - success = true; - } - } else { - // local folder - if (mFormatComboBox->currentItem() == 1) - newFolder = kmkernel->folderMgr()->createFolder(fldName, false, KMFolderTypeMaildir, selectedFolderDir ); - else - newFolder = kmkernel->folderMgr()->createFolder(fldName, false, KMFolderTypeMbox, selectedFolderDir ); - if ( newFolder ) - success = true; + TQString namespaceName; + if ( mNamespacesComboBox ) { + namespaceName = mNamespacesComboBox->currentText(); } - if ( !success ) { + + KMFolderType folderType = KMFolderTypeUnknown; + if ( mFormatComboBox && mFormatComboBox->currentItem() == 1 ) + folderType = KMFolderTypeMaildir; + else if ( mFormatComboBox ) + folderType = KMFolderTypeMbox; + + KMFolder *newFolder = KMail::FolderUtil::createSubFolder( mFolder, selectedFolderDir, fldName, + namespaceName, folderType ); + if ( !newFolder ) { KMessageBox::error( this, message ); return; } |