From 58a8cbdd937dd74786a72bc5cf2d62b08828a2e1 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 21 May 2004 07:57:31 +0000 Subject: [PATCH] Support for cancelling dimap checks. Fixed bugs related to cancelling. svn path=/trunk/kdepim/; revision=313148 --- imapaccountbase.cpp | 5 +++- kmacctcachedimap.cpp | 53 +++++------------------------------------- kmacctcachedimap.h | 4 ++-- kmacctexppop.h | 5 ++-- kmfoldercachedimap.cpp | 10 ++++---- progressdialog.cpp | 6 ++--- progressmanager.cpp | 7 ++++-- progressmanager.h | 2 ++ 8 files changed, 29 insertions(+), 63 deletions(-) diff --git a/imapaccountbase.cpp b/imapaccountbase.cpp index cb06f6e48..cc4e76685 100644 --- a/imapaccountbase.cpp +++ b/imapaccountbase.cpp @@ -691,6 +691,9 @@ namespace KMail { // These mean that we'll have to reconnect on the next attempt, so set mSlave to 0. killAllJobs( true ); break; + case KIO::ERR_USER_CANCELED: + killAllJobs( false ); + break; default: if ( abortSync ) killAllJobs( false ); @@ -700,7 +703,7 @@ namespace KMail { } // check if we still display an error - if ( !mErrorDialogIsActive ) + if ( !mErrorDialogIsActive && errorCode != KIO::ERR_USER_CANCELED ) { mErrorDialogIsActive = true; QString msg; diff --git a/kmacctcachedimap.cpp b/kmacctcachedimap.cpp index 2962ece32..acea0c4e2 100644 --- a/kmacctcachedimap.cpp +++ b/kmacctcachedimap.cpp @@ -88,7 +88,6 @@ void KMAcctCachedImap::init() { //----------------------------------------------------------------------------- void KMAcctCachedImap::pseudoAssign( const KMAccount * a ) { - mIdleTimer.stop(); killAllJobs( true ); if (mFolder) { @@ -121,50 +120,6 @@ void KMAcctCachedImap::setAutoExpunge( bool /*aAutoExpunge*/ ) mAutoExpunge = false; } -//----------------------------------------------------------------------------- -void KMAcctCachedImap::displayProgress() -{ - mIdle = false; - mIdleTimer.start( 15000 ); - /* - if (mProgressEnabled == mapJobData.isEmpty()) - { - mProgressEnabled = !mapJobData.isEmpty(); - KMBroadcastStatus::instance()->setStatusProgressEnable( "I" + mName, - mProgressEnabled ); - if (!mProgressEnabled) kmkernel->filterMgr()->deref(true); - } - mIdle = FALSE; - if( mapJobData.isEmpty() ) - mIdleTimer.start(0); - else - mIdleTimer.stop(); - int total = 0, done = 0; - // This is a loop, but it seems that we can currently have only one job at a time in this map. - for (QMap::Iterator it = mapJobData.begin(); - it != mapJobData.end(); ++it) - { - total += (*it).total; // always ==1 (in kmfoldercachedimap.cpp) - if( (*it).parent ) - done += static_cast((*it).parent)->progress(); - else - done += (*it).done; - } - if (total == 0) // can't happen - { - mTotal = 0; - return; - } - //if (total > mTotal) mTotal = total; - //done += mTotal - total; - - KMBroadcastStatus::instance()->setStatusProgressPercent( "I" + mName, - done / total ); - - //100*done / mTotal ); - */ -} - //----------------------------------------------------------------------------- void KMAcctCachedImap::killAllJobs( bool disconnectSlave ) { @@ -176,6 +131,11 @@ void KMAcctCachedImap::killAllJobs( bool disconnectSlave ) for (; it != mapJobData.end(); ++it) { if ((*it).parent) folderList << static_cast((*it).parent->storage()); + // Kill the job - except if it's the one that already died and is calling us + if ( !it.key()->error() && mSlave ) { + it.key()->kill(); + mSlave = 0; // killing a job, kills the slave + } } mapJobData.clear(); @@ -183,7 +143,6 @@ void KMAcctCachedImap::killAllJobs( bool disconnectSlave ) for( QPtrListIterator it( mJobList ); it.current(); ++it ) it.current()->setPassiveDestructor( true ); KMAccount::deleteFolderJobs(); - displayProgress(); if ( disconnectSlave && slave() ) { KIO::Scheduler::disconnectSlave( slave() ); @@ -287,7 +246,7 @@ void KMAcctCachedImap::processNewMail( KMFolderCachedImap* folder, mMailCheckProgressItem = KMail::ProgressManager::createProgressItem( "MailCheck" + QString::number( id() ), folder->label(), // will be changed immediately in serverSync anyway - QString::null, false); + QString::null, true); connect( mMailCheckProgressItem, SIGNAL( progressItemCanceled( ProgressItem* ) ), this, SLOT( slotProgressItemCanceled( ProgressItem* ) ) ); diff --git a/kmacctcachedimap.h b/kmacctcachedimap.h index ae765286d..4399d21dd 100644 --- a/kmacctcachedimap.h +++ b/kmacctcachedimap.h @@ -78,9 +78,9 @@ public: virtual void processNewMail( bool interactive ); /** - * Update the progress bar + * Does nothing for cached imap */ - virtual void displayProgress(); + virtual void displayProgress() {} /** * Kill all jobs related the the specified folder diff --git a/kmacctexppop.h b/kmacctexppop.h index a608f1f8c..dd10807a3 100644 --- a/kmacctexppop.h +++ b/kmacctexppop.h @@ -19,8 +19,9 @@ namespace KIO { class Job; } -/** KMail account for experimental pop mail account - * +/** + * KMail account for pop mail account + * The Exp in the name used to mean Experimental, but it's the stable one now :) */ class KMAcctExpPop: public KMail::NetworkAccount { Q_OBJECT diff --git a/kmfoldercachedimap.cpp b/kmfoldercachedimap.cpp index 37f76c79f..d12d49ef7 100644 --- a/kmfoldercachedimap.cpp +++ b/kmfoldercachedimap.cpp @@ -463,7 +463,6 @@ void KMFolderCachedImap::serverSync( bool recurse ) account()->mailCheckProgressItem()->setProgress( 100 ); mProgress = 100; // all done newState( mProgress, i18n("Synchronization skipped")); - mAccount->displayProgress(); mSyncState = SYNC_STATE_INITIAL; emit folderComplete( this, true ); return; @@ -782,7 +781,6 @@ void KMFolderCachedImap::serverSyncInternal() mProgress = 100; // all done newState( mProgress, i18n("Synchronization done")); emit syncRunning( folder(), false ); - mAccount->displayProgress(); if ( !mRecurse ) // "check mail for this folder" only mSubfoldersForSync.clear(); @@ -1150,7 +1148,6 @@ void KMFolderCachedImap::slotGetMessagesData(KIO::Job * job, const QByteArray & (*it).cdata.remove(0, pos); (*it).done++; pos = (*it).cdata.find("\r\n--IMAPDIGEST", 1); - mAccount->displayProgress(); } } @@ -1289,7 +1286,6 @@ void KMFolderCachedImap::slotListResult( QStringList folderNames, kmkernel->dimapFolderMgr()->remove( doomed ); mProgress += 5; - mAccount->displayProgress(); serverSyncInternal(); } @@ -1522,7 +1518,11 @@ void KMFolderCachedImap::resetSyncState() mSubfoldersForSync.clear(); mSyncState = SYNC_STATE_INITIAL; close(); - newState( mProgress, i18n("Aborted") ); + // Don't use newState here, it would revert to mProgress (which is < current value when listing messages) + ProgressItem *progressItem = mAccount->mailCheckProgressItem(); + QString str = i18n("Aborted"); + progressItem->setStatus( str ); + emit statusMsg( str ); } void KMFolderCachedImap::slotIncreaseProgress() diff --git a/progressdialog.cpp b/progressdialog.cpp index 10cb34768..9eb4bc760 100644 --- a/progressdialog.cpp +++ b/progressdialog.cpp @@ -160,8 +160,7 @@ void TransactionItem::setStatus( const QString& status ) void TransactionItem::slotItemCanceled() { - item()->setStatus( i18n("cancelling ... ") ); - item()->cancel(); + mItem->cancel(); } @@ -244,7 +243,6 @@ void ProgressDialog::slotTransactionCompleted( ProgressItem *item ) { if ( mTransactionsToListviewItems.contains( item ) ) { TransactionItem *ti = mTransactionsToListviewItems[ item ]; - ti->setStatus(i18n("Completed")); mTransactionsToListviewItems.remove( item ); QTimer::singleShot( 5000, ti, SLOT( deleteLater() ) ); } @@ -253,7 +251,7 @@ void ProgressDialog::slotTransactionCompleted( ProgressItem *item ) QTimer::singleShot( 6000, this, SLOT( slotHide() ) ); } -void ProgressDialog::slotTransactionCanceled( ProgressItem* /* item */ ) +void ProgressDialog::slotTransactionCanceled( ProgressItem* ) { } diff --git a/progressmanager.cpp b/progressmanager.cpp index 7090c3563..45ef0d4c1 100644 --- a/progressmanager.cpp +++ b/progressmanager.cpp @@ -34,6 +34,7 @@ #include #include "progressmanager.h" +#include namespace KMail { @@ -55,8 +56,9 @@ ProgressItem::~ProgressItem() void ProgressItem::setComplete() { kdDebug(5006) << "ProgressItem::setComplete - " << label() << endl; - setProgress( 100 ); - if ( mChildren.count() == 0 ) { + if ( !mCanceled ) + setProgress( 100 ); + if ( mChildren.isEmpty() ) { emit progressItemCompleted( this ); if ( parent() ) parent()->removeChild( this ); @@ -95,6 +97,7 @@ void ProgressItem::cancel() if ( kid->canBeCanceled() ) kid->cancel(); } + setStatus( i18n( "Aborting..." ) ); emit progressItemCanceled( this ); } diff --git a/progressmanager.h b/progressmanager.h index f6b0483c0..df4eaec0a 100644 --- a/progressmanager.h +++ b/progressmanager.h @@ -130,6 +130,8 @@ class ProgressItem : public QObject void addChild( ProgressItem *kiddo ); void removeChild( ProgressItem *kiddo ); + bool canceled() const { return mCanceled; } + signals: /** * Emitted when a new ProgressItem is added.