KMAccountImap::tempOpenFolder() is no more. h00t

o make imapjobs refcount the folders they operate on via open/close instead
  of relying on the account to keep track of open folders and close them
  in displayProgress()
o keep not only the destination but also the source folder in each imapjob
  so they can be closed if need be
o remove tempOpenFolder() itself and all its uses

svn path=/trunk/kdepim/; revision=244918
wilder-work
Till Adam 23 years ago
parent c6f730a460
commit ac52a82abe
  1. 1
      folderjob.h
  2. 7
      imapaccountbase.cpp
  3. 72
      imapjob.cpp
  4. 28
      kmacctimap.cpp
  5. 5
      kmacctimap.h
  6. 6
      kmcommands.cpp
  7. 4
      kmfolder.cpp
  8. 19
      kmfolderimap.cpp

@ -134,6 +134,7 @@ protected:
QPtrList<KMMessage> mMsgList;
JobType mType;
QString mSets;
KMFolder* mSrcFolder;
KMFolder* mDestFolder;
QString mPartSpecifier;

@ -272,13 +272,6 @@ namespace KMail {
mProgressEnabled = !mapJobData.isEmpty();
KMBroadcastStatus::instance()->setStatusProgressEnable( "I" + mName,
mProgressEnabled );
if (!mProgressEnabled)
{
QPtrListIterator<QGuardedPtr<KMFolder> > it(mOpenFolders);
for ( it.toFirst() ; it.current() ; ++it )
if ( it.current() ) (*(it.current()))->close();
mOpenFolders.clear();
}
}
mIdle = FALSE;
if (mapJobData.isEmpty())

@ -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<KMFolderImap*>( 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<KMFolderImap*>(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<KMFolderImap*>(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<KMFolderImap*>(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<KMFolderImap*>(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<KMMessage> 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<KMFolderImap*>(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<KMFolderImap*>(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();
}
//-----------------------------------------------------------------------------

@ -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<KMFolder>(folder));
return 0;
}
//-----------------------------------------------------------------------------
void KMAcctImap::slotSlaveError(KIO::Slave *aSlave, int errorCode,
const QString &errorMsg)
@ -205,11 +195,10 @@ void KMAcctImap::ignoreJobsForMessage( KMMessage* msg )
QPtrListIterator<ImapJob> 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<ImapJob> 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;
}
}
}

@ -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); }

@ -1264,7 +1264,6 @@ void KMCopyCommand::execute()
QPtrList<KMMessage> 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();
}
}

@ -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<KMFolderImap*>(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 {

@ -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<KMMessage>& 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<KMFolderImap*>(msgParent)->account() == account())
@ -382,13 +381,6 @@ int KMFolderImap::addMsg(QPtrList<KMMessage>& msgList, int* aIndex_ret)
//-----------------------------------------------------------------------------
void KMFolderImap::copyMsg(QPtrList<KMMessage>& 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<KMMessage> msgList)
{
mAccount->tempOpenFolder(this);
KMMessage *aMsg = msgList.getFirst();
if (aMsg)
{
KMFolder* parent = aMsg->parent();
if (parent) mAccount->tempOpenFolder(parent);
}
QValueList<int> uids;
getUids(msgList, uids);
QStringList sets = makeSets(uids);

Loading…
Cancel
Save