29 #include "copyfolderjob.h" 30 #include "folderstorage.h" 31 #include "kmacctcachedimap.h" 32 #include "kmfoldercachedimap.h" 34 #include "kmfolderdir.h" 35 #include "kmfoldertype.h" 36 #include "kmfoldermgr.h" 37 #include "kmcommands.h" 38 #include "kmmsgbase.h" 39 #include "undostack.h" 42 #include <tdelocale.h> 45 using namespace KMail;
48 : FolderJob( 0, tOther, (storage ? storage->folder() : 0) ),
49 mStorage( storage ), mNewParent( newParent ),
50 mNewFolder( 0 ), mChildFolderNodeIterator( *mStorage->folder()->createChildFolder() ),
53 mStorage->open(
"copyfolder" );
56 CopyFolderJob::~CopyFolderJob()
58 kdDebug(5006) << k_funcinfo << endl;
60 mNewFolder->setMoveInProgress(
false );
63 mStorage->folder()->setMoveInProgress(
false );
64 mStorage->close(
"copyfolder" );
72 void CopyFolderJob::execute()
82 mStorage->blockSignals(
true );
84 TQPtrList<KMMsgBase> msgList;
85 for (
int i = 0; i < mStorage->count(); i++ )
87 const KMMsgBase* msgBase = mStorage->getMsgBase( i );
89 msgList.append( msgBase );
91 if ( msgList.count() == 0 ) {
92 mStorage->blockSignals(
false );
97 KMCommand *command =
new KMCopyCommand( mNewFolder, msgList );
98 connect( command, TQ_SIGNAL( completed( KMCommand * ) ),
106 kdDebug(5006) << k_funcinfo << (command?command->result():0) << endl;
107 disconnect( command, TQ_SIGNAL( completed( KMCommand * ) ),
110 mStorage->blockSignals(
false );
112 if ( command && command->result() != KMCommand::OK ) {
117 if ( mStorage->folder()->child() ) {
128 if ( mNextChildFolder )
129 mNextChildFolder->
close(
"copyfolder" );
132 kdDebug(5006) <<
"Failed to copy one subfolder, let's not continue: " << mNewFolder->prettyURL() << endl;
138 KMFolderNode* node = mChildFolderNodeIterator.current();
139 while ( node && node->isDir() ) {
140 ++mChildFolderNodeIterator;
141 node = mChildFolderNodeIterator.current();
144 mNextChildFolder =
static_cast<KMFolder*
>(node);
145 ++mChildFolderNodeIterator;
153 KMFolderDir *
const dir = mNewFolder->createChildFolder();
155 kdDebug(5006) <<
"Failed to create subfolders of: " << mNewFolder->prettyURL() << endl;
161 mNextChildFolder->
open(
"copyfolder" );
162 FolderJob* job =
new CopyFolderJob( mNextChildFolder->storage(), dir);
174 TDEConfig *
const config = KMKernel::config();
175 TDEConfigGroupSaver saver(config,
"General");
176 int deftype = config->readNumEntry(
"default-mailbox-format", 1);
177 if ( deftype < 0 || deftype > 1 ) deftype = 1;
180 KMFolderType typenew =
181 ( deftype == 0 ) ? KMFolderTypeMbox : KMFolderTypeMaildir;
182 if ( mNewParent->
owner() )
185 bool success =
false, waitForFolderCreation =
false;
188 KMFolderImap* selectedStorage =
static_cast<KMFolderImap*
>( mNewParent->
owner()->storage() );
189 KMAcctImap *anAccount = selectedStorage->account();
191 if (anAccount->makeConnection() == ImapAccountBase::Connected) {
192 mNewFolder = kmkernel->imapFolderMgr()->createFolder( mStorage->folder()->name(),
false, typenew, mNewParent );
195 imapPath = anAccount->createImapPath( selectedStorage->imapPath(), mStorage->folder()->name() );
196 KMFolderImap* newStorage =
static_cast<KMFolderImap*
>( mNewFolder->storage() );
197 connect( selectedStorage, TQ_SIGNAL(folderCreationResult(
const TQString&,
bool)),
199 selectedStorage->createFolder(mStorage->folder()->name(), TQString());
200 newStorage->initializeFrom( selectedStorage, imapPath, TQString() );
201 static_cast<KMFolderImap*
>(mNewParent->
owner()->storage())->setAccount( selectedStorage->account() );
202 waitForFolderCreation =
true;
206 }
else if ( mNewParent->
owner() && mNewParent->
owner()->
folderType() == KMFolderTypeCachedImap ) {
207 mNewFolder = kmkernel->dimapFolderMgr()->createFolder( mStorage->folder()->name(),
false, typenew, mNewParent );
209 KMFolderCachedImap* selectedStorage =
static_cast<KMFolderCachedImap*
>( mNewParent->
owner()->storage() );
210 KMFolderCachedImap* newStorage =
static_cast<KMFolderCachedImap*
>( mNewFolder->storage() );
211 newStorage->initializeFrom( selectedStorage );
216 mNewFolder = kmkernel->folderMgr()->createFolder(mStorage->folder()->name(),
false, typenew, mNewParent );
222 kdWarning(5006) << k_funcinfo <<
"could not create folder" << endl;
228 mNewFolder->setMoveInProgress(
true );
229 mStorage->folder()->setMoveInProgress(
true );
233 mNewFolder->storage()->setContentsType( mStorage->contentsType(),
true );
234 mNewFolder->storage()->writeConfig();
235 kdDebug(5006)<<
"CopyJob::createTargetDir - " << mStorage->folder()->idString()
236 <<
" |=> " << mNewFolder->idString() << endl;
237 return !waitForFolderCreation;
247 if ( mNewFolder->folderType() == KMFolderTypeImap )
249 kmkernel->imapFolderMgr()->remove( mNewFolder );
250 }
else if ( mNewFolder->folderType() == KMFolderTypeCachedImap )
253 KMFolderCachedImap* folder =
static_cast<KMFolderCachedImap*
>(mNewFolder->storage());
254 KMAcctCachedImap* acct = folder->account();
256 acct->addDeletedFolder( folder->imapPath() );
257 kmkernel->dimapFolderMgr()->remove( mNewFolder );
258 }
else if ( mNewFolder->folderType() == KMFolderTypeSearch )
261 kdWarning(5006) << k_funcinfo <<
"cannot remove a search folder" << endl;
263 kmkernel->folderMgr()->remove( mNewFolder );
273 if ( mStorage->folder()->name() != name )
275 kdDebug(5006) << k_funcinfo << success << endl;
283 #include "copyfolderjob.moc" void folderCopyComplete(bool success)
Emitted when the job is done, check the success bool.
void rollback()
Called when one of the operations of the foldre itself or one of it's child folders failed and the al...
KMail list that manages the contents of one directory that may contain folders and/or other directori...
bool createTargetDir()
Create the target directory under the new parent.
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
void close(const char *owner, bool force=false)
Close folder.
void slotCopyNextChild(bool success=true)
Called when the previous sibling's copy operation completed.
void copyMessagesToTargetDir()
Copy all messages from the original folder to mNewFolder.
KMFolderType folderType() const
Returns the type of this folder.
void folderCreationDone(const TQString &name, bool success)
Called when the online IMAP folder creation finished.
KMFolder * owner() const
Returns the folder whose children we are holding.
int open(const char *owner)
Open folder for access.
void slotCopyCompleted(KMCommand *command)
Called when the CopyCommand has either succesfully completed copying the contents of our folder to th...
CopyFolderJob(FolderStorage *const storage, KMFolderDir *const newParent=0)
Create a new job.