diff --git a/folderjob.h b/folderjob.h index 19bfa3408..160e59086 100644 --- a/folderjob.h +++ b/folderjob.h @@ -134,6 +134,7 @@ protected: QPtrList mMsgList; JobType mType; QString mSets; + KMFolder* mSrcFolder; KMFolder* mDestFolder; QString mPartSpecifier; diff --git a/imapaccountbase.cpp b/imapaccountbase.cpp index bd12ccca6..674a91a39 100644 --- a/imapaccountbase.cpp +++ b/imapaccountbase.cpp @@ -272,13 +272,6 @@ namespace KMail { mProgressEnabled = !mapJobData.isEmpty(); KMBroadcastStatus::instance()->setStatusProgressEnable( "I" + mName, mProgressEnabled ); - if (!mProgressEnabled) - { - QPtrListIterator > it(mOpenFolders); - for ( it.toFirst() ; it.current() ; ++it ) - if ( it.current() ) (*(it.current()))->close(); - mOpenFolders.clear(); - } } mIdle = FALSE; if (mapJobData.isEmpty()) diff --git a/imapjob.cpp b/imapjob.cpp index bc64debbd..805619499 100644 --- a/imapjob.cpp +++ b/imapjob.cpp @@ -64,8 +64,31 @@ void ImapJob::init( JobType jt, QString sets, KMFolderImap* folder, KMMessage* msg = msgList.first(); mType = jt; mDestFolder = folder; - KMFolderImap *msg_parent = static_cast( msg->parent() ); - KMAcctImap *account = (folder) ? folder->account() : msg_parent->account(); + // refcount++ + if (folder) { + folder->open(); + } + KMFolder *msg_parent = msg->parent(); + if (msg_parent) { + if (!folder || folder!= msg_parent) { + msg_parent->open(); + } + } + mSrcFolder = msg_parent; + // If there is a destination folder, this is a copy, move or put to an + // imap folder, use its account for keeping track of the job. Otherwise, + // this is a get job and the src folder is an imap one. Use its account + // then. + KMAcctImap *account; + if (folder) { + account = folder->account(); + } else { + account = static_cast(msg_parent)->account(); + } + if (!account) { + deleteLater(); + return; + } account->mJobList.append( this ); if ( jt == tPutMessage ) { @@ -118,7 +141,8 @@ void ImapJob::init( JobType jt, QString sets, KMFolderImap* folder, KURL url = account->getUrl(); KURL destUrl = account->getUrl(); destUrl.setPath(folder->imapPath()); - url.setPath( msg_parent->imapPath() + ";UID=" + sets ); + KMFolderImap *imapDestFolder = static_cast(msg_parent); + url.setPath( imapDestFolder->imapPath() + ";UID=" + sets ); ImapAccountBase::jobData jd; jd.parent = 0; mOffset = 0; jd.total = 1; jd.done = 0; @@ -155,6 +179,7 @@ void ImapJob::init( JobType jt, QString sets, KMFolderImap* folder, //----------------------------------------------------------------------------- ImapJob::~ImapJob() { + if ( mDestFolder ) { KMAcctImap *account = static_cast(mDestFolder)->account(); @@ -169,6 +194,28 @@ ImapJob::~ImapJob() mit.current()->setTransferInProgress(false); } } + + mDestFolder->close(); + } + + if (mSrcFolder) { + if (!mDestFolder || mDestFolder != mSrcFolder) { + if (! (mSrcFolder->folderType() == KMFolderTypeImap) ) return; + KMAcctImap *account = static_cast(mSrcFolder)->account(); + if ( account ) // just to be sure this job is removed from the list + account->mJobList.remove(this); + if ( account && mJob ) + { + ImapAccountBase::JobIterator it = account->findJob( mJob ); + if ( it != account->jobsEnd() && !(*it).msgList.isEmpty() ) + { + for ( QPtrListIterator mit( (*it).msgList ); mit.current(); ++mit ) + mit.current()->setTransferInProgress(false); + } + } + } + + mSrcFolder->close(); } } @@ -178,7 +225,6 @@ void ImapJob::slotGetNextMessage() { KMMessage *msg = mMsgList.first(); KMFolderImap *msgParent = static_cast(msg->parent()); - if (msgParent) msgParent->open(); KMAcctImap *account = msgParent->account(); if ( msg->headerField("X-UID").isEmpty() ) { @@ -241,20 +287,15 @@ void ImapJob::slotGetMessageResult( KIO::Job * job ) msg->setTransferInProgress( false ); KMAcctImap *account = parent->account(); if ( !account ) { - if (parent) parent->close(); deleteLater(); return; } ImapAccountBase::JobIterator it = account->findJob( job ); - if ( it == account->jobsEnd() ) { - if (parent) parent->close(); - return; - } + if ( it == account->jobsEnd() ) return; if (job->error()) { account->slotSlaveError( account->slave(), job->error(), job->errorText() ); - if (parent) parent->close(); return; } else { if ((*it).data.size() > 0) @@ -288,7 +329,6 @@ void ImapJob::slotGetMessageResult( KIO::Job * job ) emit messageUpdated(msg, mPartSpecifier); } deleteLater(); - if (parent) parent->close(); } //----------------------------------------------------------------------------- @@ -297,7 +337,6 @@ void ImapJob::slotGetBodyStructureResult( KIO::Job * job ) KMMessage *msg = mMsgList.first(); if (!msg || !msg->parent() || !job) { deleteLater(); - if (msg->parent()) msg->parent()->close(); return; } KMFolderImap* parent = static_cast(msg->parent()); @@ -305,21 +344,17 @@ void ImapJob::slotGetBodyStructureResult( KIO::Job * job ) msg->setTransferInProgress( false ); KMAcctImap *account = parent->account(); if ( !account ) { - if (parent) parent->close(); deleteLater(); return; } ImapAccountBase::JobIterator it = account->findJob( job ); - if ( it == account->jobsEnd() ) { - if (parent) parent->close(); - return; - } + if ( it == account->jobsEnd() ) return; + if (job->error()) { account->slotSlaveError( account->slave(), job->error(), job->errorText() ); - if (parent) parent->close(); return; } else { if ((*it).data.size() > 0) @@ -333,7 +368,6 @@ void ImapJob::slotGetBodyStructureResult( KIO::Job * job ) account->mJobList.remove(this); } deleteLater(); - if (parent) parent->close(); } //----------------------------------------------------------------------------- diff --git a/kmacctimap.cpp b/kmacctimap.cpp index 46020469f..b8cd7f7ab 100644 --- a/kmacctimap.cpp +++ b/kmacctimap.cpp @@ -90,16 +90,6 @@ void KMAcctImap::setImapFolder(KMFolderImap *aFolder) } -//----------------------------------------------------------------------------- -int KMAcctImap::tempOpenFolder(KMFolder *folder) -{ - int rc = folder->open(); - if (rc) return rc; - mOpenFolders.append(new QGuardedPtr(folder)); - return 0; -} - - //----------------------------------------------------------------------------- void KMAcctImap::slotSlaveError(KIO::Slave *aSlave, int errorCode, const QString &errorMsg) @@ -205,11 +195,10 @@ void KMAcctImap::ignoreJobsForMessage( KMMessage* msg ) QPtrListIterator it( mJobList ); while ( it.current() ) { - if ( it.current()->msgList().findRef( msg ) != -1 ) + ImapJob *job = it.current(); + ++it; + if ( job->msgList().findRef( msg ) != -1 ) { - // decrement the ref count of the folder for each job - if (msg->parent()) msg->parent()->close(); - ImapJob *job = it.current(); if ( job->mJob ) { job->mJob->disconnect(); @@ -217,8 +206,7 @@ void KMAcctImap::ignoreJobsForMessage( KMMessage* msg ) } mJobList.remove( job ); delete job; - } else - ++it; + } } } @@ -228,9 +216,10 @@ void KMAcctImap::ignoreJobsForFolder( KMFolder* folder ) QPtrListIterator it( mJobList ); while ( it.current() ) { - if ( it.current()->msgList().first()->parent() == folder ) + ImapJob *job = it.current(); + ++it; + if ( job->msgList().first()->parent() == folder ) { - ImapJob *job = it.current(); if ( job->mJob ) { job->mJob->disconnect(); @@ -238,8 +227,7 @@ void KMAcctImap::ignoreJobsForFolder( KMFolder* folder ) } mJobList.remove( job ); delete job; - } else - ++it; + } } } diff --git a/kmacctimap.h b/kmacctimap.h index c348b2e38..7da14f693 100644 --- a/kmacctimap.h +++ b/kmacctimap.h @@ -77,11 +77,6 @@ public: */ virtual void setImapFolder(KMFolderImap *); - /** - * Open a folder and close it again when the network transfer is finished - */ - int tempOpenFolder(KMFolder *folder); - public slots: void processNewMail() { processNewMail(TRUE); } diff --git a/kmcommands.cpp b/kmcommands.cpp index 5ee8bdffd..940653f4a 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -1264,7 +1264,6 @@ void KMCopyCommand::execute() QPtrList list; KCursorSaver busy(KBusyPtr::busy()); - mDestFolder->open(); for (msgBase = mMsgList.first(); msgBase; msgBase = mMsgList.next() ) { @@ -1293,8 +1292,6 @@ void KMCopyCommand::execute() if (srcFolder && !newMsg->isComplete()) { - // will be closed in reallyAddCopyOfMsg - mDestFolder->open(); newMsg->setParent(msg->parent()); FolderJob *job = srcFolder->createJob(newMsg); connect(job, SIGNAL(messageRetrieved(KMMessage*)), @@ -1329,7 +1326,6 @@ void KMCopyCommand::execute() imapDestFolder->getFolder(); } - mDestFolder->close(); } @@ -1426,7 +1422,6 @@ void KMMoveCommand::execute() FolderToMessageListMap::Iterator it; for ( it = folderDeleteList.begin(); it != folderDeleteList.end(); ++it ) { it.key()->removeMsg(*it.data()); - it.key()->close(); delete it.data(); } @@ -1435,7 +1430,6 @@ void KMMoveCommand::execute() if (mDestFolder) { mDestFolder->sync(); - mDestFolder->close(); } } diff --git a/kmfolder.cpp b/kmfolder.cpp index d45839052..dd4d16b6f 100644 --- a/kmfolder.cpp +++ b/kmfolder.cpp @@ -345,8 +345,6 @@ bool KMFolder::canAddMsgNow(KMMessage* aMsg, int* aIndex_ret) SLOT(reallyAddMsg(KMMessage*))); job->start(); aMsg->setTransferInProgress(TRUE); - //FIXME: remove that. Maybe extract tempOpenFolder to some base class - static_cast(msgParent)->account()->tempOpenFolder(msgParent); return FALSE; } return TRUE; @@ -380,8 +378,6 @@ void KMFolder::reallyAddCopyOfMsg(KMMessage* aMsg) aMsg->setTransferInProgress( false ); addMsg( aMsg ); unGetMsg( count() - 1 ); - // We have been opened before the transfer was started. - close( ); } int KMFolder::find( const KMMessage * msg ) const { diff --git a/kmfolderimap.cpp b/kmfolderimap.cpp index 35d6ad93f..f8ad820d4 100644 --- a/kmfolderimap.cpp +++ b/kmfolderimap.cpp @@ -79,6 +79,7 @@ void KMFolderImap::close(bool aForced) if (mOpenCount <= 0 ) return; if (mOpenCount > 0) mOpenCount--; if (mOpenCount > 0 && !aForced) return; + // FIXME is this still needed? if (mAccount) mAccount->ignoreJobsForFolder( this ); int idx = count(); @@ -283,14 +284,12 @@ int KMFolderImap::addMsg(KMMessage* aMsg, int* aIndex_ret) int KMFolderImap::addMsg(QPtrList& msgList, int* aIndex_ret) { - mAccount->tempOpenFolder(this); KMMessage *aMsg = msgList.getFirst(); KMFolder *msgParent = aMsg->parent(); ImapJob *imapJob = 0; if (msgParent) { - mAccount->tempOpenFolder(msgParent); if (msgParent->folderType() == KMFolderTypeImap) { if (static_cast(msgParent)->account() == account()) @@ -382,13 +381,6 @@ int KMFolderImap::addMsg(QPtrList& msgList, int* aIndex_ret) //----------------------------------------------------------------------------- void KMFolderImap::copyMsg(QPtrList& msgList) { - mAccount->tempOpenFolder(this); - KMMessage *aMsg = msgList.getFirst(); - if (aMsg) - { - KMFolder* parent = aMsg->parent(); - if (parent) mAccount->tempOpenFolder(parent); - } for (KMMessage *msg = msgList.first(); msg; msg = msgList.next()) { // Remember the status, so it can be transfered to the new message. mMetaDataMap.insert(msg->msgIdMD5(), new KMMsgMetaData(msg->status())); @@ -592,7 +584,6 @@ void KMFolderImap::checkValidity() } // Only check once at a time. if (mCheckingValidity) return; - mAccount->tempOpenFolder(this); ImapAccountBase::jobData jd( url.url(), this ); KIO::SimpleJob *job = KIO::get(url, FALSE, FALSE); KIO::Scheduler::assignJobToSlave(mAccount->slave(), job); @@ -603,6 +594,7 @@ void KMFolderImap::checkValidity() SLOT(slotSimpleData(KIO::Job *, const QByteArray &))); // Only check once at a time. mCheckingValidity = true; + } @@ -1130,13 +1122,6 @@ void KMFolderImap::deleteMessage(KMMessage * msg) void KMFolderImap::deleteMessage(QPtrList msgList) { - mAccount->tempOpenFolder(this); - KMMessage *aMsg = msgList.getFirst(); - if (aMsg) - { - KMFolder* parent = aMsg->parent(); - if (parent) mAccount->tempOpenFolder(parent); - } QValueList uids; getUids(msgList, uids); QStringList sets = makeSets(uids);