29 #include "renamejob.h"
30 #include "copyfolderjob.h"
31 #include "kmfolderimap.h"
32 #include "kmfoldercachedimap.h"
33 #include "folderstorage.h"
35 #include "kmfolderdir.h"
36 #include "kmfoldermgr.h"
37 #include "imapaccountbase.h"
38 #include "kmacctimap.h"
39 #include "kmacctcachedimap.h"
40 #include "kmmsgbase.h"
44 #include <tdeio/scheduler.h>
45 #include <tdeio/job.h>
46 #include <tdeio/global.h>
47 #include <tdelocale.h>
52 using namespace KMail;
54 template <
typename T>
static TQStringList imapPaths(
FolderStorage* storage )
57 rv.append(
static_cast<T
>( storage )->imapPath() );
60 KMFolderNode *node = dir->first();
62 if ( !node->isDir() ) {
63 rv += imapPaths<T>(
static_cast<KMFolder*
>( node )->storage() );
73 : FolderJob( 0, tOther, (storage ? storage->folder() : 0) ),
74 mStorage( storage ), mNewParent( newParent ),
75 mNewName( newName ), mNewFolder( 0 ), mCopyFolderJob( 0 )
77 mStorageTempOpened = 0;
79 mOldName = storage->name();
80 if ( storage->
folderType() == KMFolderTypeImap ) {
81 mOldImapPath =
static_cast<KMFolderImap*
>(storage)->imapPath();
83 }
else if ( storage->
folderType() == KMFolderTypeCachedImap ) {
84 mOldImapPath =
static_cast<KMFolderCachedImap*
>(storage)->imapPath();
85 mOldImapPaths = imapPaths<KMFolderCachedImap*>( storage );
90 RenameJob::~RenameJob()
95 void RenameJob::execute()
101 if ( ( type == KMFolderTypeMbox || type == KMFolderTypeMaildir ) &&
102 mNewParent->type() == KMStandardDir &&
103 mStorage->
folderType() != KMFolderTypeCachedImap )
106 mStorage->
rename( mNewName, mNewParent );
114 mCopyFolderJob->execute();
119 if ( mStorage->
folderType() != KMFolderTypeImap )
122 mStorage->
rename( mNewName );
127 if ( mOldImapPath.isEmpty() )
133 }
else if ( mOldName == mNewName || mOldImapPath ==
"/INBOX/" ) {
138 ImapAccountBase* account =
static_cast<KMFolderImap*
>(mStorage)->account();
140 mNewImapPath = mOldImapPath;
141 mNewImapPath = mNewImapPath.replace( mOldName, mNewName );
142 KURL src( account->getUrl() );
143 src.setPath( mOldImapPath );
144 KURL dst( account->getUrl() );
145 dst.setPath( mNewImapPath );
146 TDEIO::SimpleJob *job = TDEIO::rename( src, dst,
true );
147 kdDebug(5006)<<
"RenameJob::rename - " << src.prettyURL()
148 <<
" |=> " << dst.prettyURL() << endl;
150 account->insertJob( job, jd );
151 TDEIO::Scheduler::assignJobToSlave( account->slave(), job );
152 connect( job, TQ_SIGNAL(result(TDEIO::Job*)),
159 ImapAccountBase* account =
static_cast<KMFolderImap*
>(mStorage)->account();
160 ImapAccountBase::JobIterator it = account->findJob(job);
161 if ( it == account->jobsEnd() )
169 account->handleJobError( job, i18n(
"Error while renaming a folder.") );
174 account->removeJob(it);
176 if ( mStorage->
folderType() == KMFolderTypeImap )
177 static_cast<KMFolderImap*
>(mStorage)->setImapPath( mNewImapPath );
179 account->changeSubscription(
false, mOldImapPath );
181 account->changeSubscription(
true, mNewImapPath );
184 mStorage->
rename( mNewName );
192 kdDebug(5006) << k_funcinfo << success << endl;
194 kdWarning(5006) << k_funcinfo <<
"could not copy folder" << endl;
202 if ( mStorageTempOpened ) {
203 mStorageTempOpened->
close(
"renamejob" );
204 mStorageTempOpened = 0;
207 kdDebug(5006) <<
"deleting old folder" << endl;
210 TQString oldconfig =
"Folder-" + mStorage->folder()->
idString();
211 TDEConfig* config = KMKernel::config();
212 TQMap<TQString, TQString> entries = config->entryMap( oldconfig );
213 TDEConfigGroupSaver saver(config,
"Folder-" + mNewFolder->
idString());
214 for ( TQMap<TQString, TQString>::Iterator it = entries.begin();
215 it != entries.end(); ++it )
217 if ( it.key() ==
"Id" || it.key() ==
"ImapPath" ||
218 it.key() ==
"UidValidity" )
220 config->writeEntry( it.key(), it.data() );
224 if ( mNewFolder->
child() &&
225 ( mNewFolder->storage()->
hasChildren() == FolderStorage::HasNoChildren ) )
229 mStorage->blockSignals(
false );
230 if ( mStorage->
folderType() == KMFolderTypeImap )
232 kmkernel->imapFolderMgr()->remove( mStorage->folder() );
233 }
else if ( mStorage->
folderType() == KMFolderTypeCachedImap )
236 KMAcctCachedImap* acct =
static_cast<KMFolderCachedImap*
>(mStorage)->account();
238 for ( TQStringList::ConstIterator it = mOldImapPaths.constBegin(); it != mOldImapPaths.constEnd(); ++it )
239 acct->addDeletedFolder( *it );
241 kmkernel->dimapFolderMgr()->remove( mStorage->folder() );
242 }
else if ( mStorage->
folderType() == KMFolderTypeSearch )
245 kdWarning(5006) << k_funcinfo <<
"cannot remove a search folder" << endl;
247 kmkernel->folderMgr()->remove( mStorage->folder() );
253 #include "renamejob.moc"
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
virtual int rename(const TQString &newName, KMFolderDir *aParent=0)
Physically rename the folder.
virtual KMFolderType folderType() const
Returns the type of this folder.
virtual void updateChildrenState()
Updates the hasChildren() state.
void close(const char *owner, bool force=false)
Close folder.
virtual ChildrenState hasChildren() const
Returns if the folder has children, has no children or we don't know.
KMail list that manages the contents of one directory that may contain folders and/or other directori...
TQString idString() const
Returns a string that can be used to identify this folder.
KMFolderDir * child() const
Returns the folder directory associated with this node or 0 if no such directory exists.
void readConfig(TDEConfig *config)
This is used by the storage to read the folder specific configuration.
Copy a hierarchy of folders somewhere else in the folder tree.
KMFolder * targetFolder() const
Returns the newly created target folder.
void folderCopyComplete(bool success)
All messages are copied so remove the original folder.
RenameJob(FolderStorage *storage, const TQString &newName, KMFolderDir *newParent=0)
Create a new job.
void renameDone(TQString newName, bool success)
Emitted when the job is done, check the success bool.
void slotRenameResult(TDEIO::Job *job)
Rename the folder.