From 90b666f740da90fdc443ef0dfdbff9fce8a4960c Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 24 May 2004 18:22:57 +0000 Subject: [PATCH] KMBroadcastStatus cleanup discussed with Till: move "abortRequested" to kmkernel, renaming it "mailCheckAborted", since it's now only used for this. Reimplemented the real "abort all" code (that used to be for the littleprogress' cross button) in ProgressManager, so that Key_Escape calls it, like it used to. It simply acts as if the 'abort' button of any running job had been clicked. svn path=/trunk/kdepim/; revision=314224 --- kmacctexppop.cpp | 2 +- kmacctlocal.cpp | 6 +++--- kmacctmaildir.cpp | 6 +++--- kmbroadcaststatus.cpp | 23 ----------------------- kmbroadcaststatus.h | 21 --------------------- kmfoldercachedimap.cpp | 2 +- kmkernel.cpp | 18 +++++++++++++++++- kmkernel.h | 25 +++++++++++++++++++++---- kmmainwidget.cpp | 9 ++++++--- kmmainwin.cpp | 5 ++--- progressmanager.cpp | 10 +++++++++- progressmanager.h | 5 +++++ 12 files changed, 68 insertions(+), 64 deletions(-) diff --git a/kmacctexppop.cpp b/kmacctexppop.cpp index 79ebde453..d1c8d7a3d 100644 --- a/kmacctexppop.cpp +++ b/kmacctexppop.cpp @@ -613,7 +613,7 @@ void KMAcctExpPop::slotJobFinished() { mSlave = 0; stage = Idle; if( mMailCheckProgressItem ) { // do this only once... - bool canceled = KMBroadcastStatus::instance()->abortRequested() || mMailCheckProgressItem->canceled(); + bool canceled = kmkernel->mailCheckAborted() || mMailCheckProgressItem->canceled(); int numMessages = canceled ? indexOfCurrentMsg : idsOfMsgs.count(); KMBroadcastStatus::instance()->setStatusMsgTransmissionCompleted( numMessages, numBytes, numBytesRead, numBytesToRead, mLeaveOnServer, mMailCheckProgressItem ); diff --git a/kmacctlocal.cpp b/kmacctlocal.cpp index cc6aae63c..3ac1c539f 100644 --- a/kmacctlocal.cpp +++ b/kmacctlocal.cpp @@ -95,7 +95,7 @@ void KMAcctLocal::processNewMail(bool) return; } - KMBroadcastStatus::instance()->reset(); + //KMBroadcastStatus::instance()->reset(); KMBroadcastStatus::instance()->setStatusMsg( i18n("Preparing transmission from \"%1\"...").arg(mName)); @@ -150,7 +150,7 @@ void KMAcctLocal::processNewMail(bool) if (!addedOk) break; /* This causes mail eating - if (KMBroadcastStatus::instance()->abortRequested()) break; */ + if (kmkernel->mailCheckAborted()) break; */ QString statusMsg = statusMsgStub.arg(i); KMBroadcastStatus::instance()->setStatusMsg( statusMsg ); @@ -193,7 +193,7 @@ void KMAcctLocal::processNewMail(bool) } KMBroadcastStatus::instance()->setStatusProgressEnable( "L" + mName, false ); - KMBroadcastStatus::instance()->reset(); + //KMBroadcastStatus::instance()->reset(); if (addedOk) { diff --git a/kmacctmaildir.cpp b/kmacctmaildir.cpp index 3e8f25768..db7c64e31 100644 --- a/kmacctmaildir.cpp +++ b/kmacctmaildir.cpp @@ -100,7 +100,7 @@ void KMAcctMaildir::processNewMail(bool) return; } - KMBroadcastStatus::instance()->reset(); + //KMBroadcastStatus::instance()->reset(); KMBroadcastStatus::instance()->setStatusMsg( i18n("Preparing transmission from \"%1\"...").arg(mName)); @@ -149,7 +149,7 @@ void KMAcctMaildir::processNewMail(bool) for (i=0; iabortRequested() ) { + if( kmkernel->mailCheckAborted() ) { KMBroadcastStatus::instance()->setStatusMsg( i18n("Transmission aborted.") ); num = i; addedOk = false; @@ -181,7 +181,7 @@ void KMAcctMaildir::processNewMail(bool) } KMBroadcastStatus::instance()->setStatusProgressEnable( "M" + mName, false ); - KMBroadcastStatus::instance()->reset(); + //KMBroadcastStatus::instance()->reset(); if (addedOk) { diff --git a/kmbroadcaststatus.cpp b/kmbroadcaststatus.cpp index 5b8280777..ebfd8667a 100644 --- a/kmbroadcaststatus.cpp +++ b/kmbroadcaststatus.cpp @@ -31,7 +31,6 @@ KMBroadcastStatus* KMBroadcastStatus::instance() KMBroadcastStatus::KMBroadcastStatus() { - reset(); } void KMBroadcastStatus::setStatusMsg( const QString& message ) @@ -159,26 +158,4 @@ void KMBroadcastStatus::setStatusProgressPercent( const QString &id, emit statusProgressPercent( count ? (sum / count) : sum ); } -void KMBroadcastStatus::reset() -{ - abortRequested_ = false; - if (ids.isEmpty()) - emit resetRequested(); -} - -bool KMBroadcastStatus::abortRequested() -{ - return abortRequested_; -} - -void KMBroadcastStatus::setAbortRequested() -{ - abortRequested_ = true; -} - -void KMBroadcastStatus::requestAbort() -{ - abortRequested_ = true; -} #include "kmbroadcaststatus.moc" - diff --git a/kmbroadcaststatus.h b/kmbroadcaststatus.h index 3e72c438a..dca03c297 100644 --- a/kmbroadcaststatus.h +++ b/kmbroadcaststatus.h @@ -56,19 +56,6 @@ public: /** Emit an update progress widget(s) percent completed signal */ void setStatusProgressPercent( const QString& id, unsigned long percent ); - /** Returns true IFF the user has requested the current operation - (the one whose progress is being shown) should be aborted. - Needs to be periodically polled in the implementation of the - operation. */ - bool abortRequested(); - /** Set the state of the abort requested variable to false */ - void reset(); - /** Set the state of the abort requested variable to true, - * without emitting the signal. - * (to let the current jobs run, but stop when possible). - * This is only for exiting gracefully, don't use. - */ - void setAbortRequested(); signals: /** Emitted when setStatusMsg is called. */ @@ -77,19 +64,11 @@ signals: void statusProgressEnable( bool ); /** Emitted when setStatusProgressPercent is called. */ void statusProgressPercent( unsigned long ); - /** Emitted when reset is called. */ - void resetRequested(); - -public slots: - - /** Set the state of the abort requested variable to return */ - void requestAbort(); protected: KMBroadcastStatus(); static KMBroadcastStatus* instance_; - bool abortRequested_; QMap ids; }; diff --git a/kmfoldercachedimap.cpp b/kmfoldercachedimap.cpp index 305cc64c9..83e137975 100644 --- a/kmfoldercachedimap.cpp +++ b/kmfoldercachedimap.cpp @@ -530,7 +530,7 @@ void KMFolderCachedImap::serverSyncInternal() // This is used to stop processing when we're about to exit // and the current job wasn't cancellable. // For user-requested abort, we'll use signalAbortRequested instead. - if( KMBroadcastStatus::instance()->abortRequested() ) { + if( kmkernel->mailCheckAborted() ) { resetSyncState(); emit folderComplete( this, false ); return; diff --git a/kmkernel.cpp b/kmkernel.cpp index 6727245b1..add2c0507 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -114,6 +114,7 @@ KMKernel::KMKernel (QObject *parent, const char *name) : the_filterActionDict = 0; the_msgSender = 0; mWin = 0; + mMailCheckAborted = false; // make sure that we check for config updates before doing anything else KMKernel::config(); @@ -175,7 +176,7 @@ KMKernel::~KMKernel () mMailService = 0; delete mKIMProxy; mKIMProxy = 0; - + GlobalSettings::writeConfig(); mySelf = 0; kdDebug(5006) << "KMKernel::~KMKernel" << endl; @@ -1798,4 +1799,19 @@ KMFolder* KMKernel::findFolderById( const QString& idString ) return mKIMProxy; } +void KMKernel::enableMailCheck() +{ + mMailCheckAborted = false; +} + +bool KMKernel::mailCheckAborted() const +{ + return mMailCheckAborted; +} + +void KMKernel::abortMailCheck() +{ + mMailCheckAborted = true; +} + #include "kmkernel.moc" diff --git a/kmkernel.h b/kmkernel.h index f492e1333..879d21317 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -220,16 +220,32 @@ public: // ### again. void setContextMenuShown( bool flag ) { mContextMenuShown = flag; } bool contextMenuShown() const { return mContextMenuShown; } - + /** * Get a reference to KMail's KIMProxy instance - * @return a pointer to a valid KIMProxy + * @return a pointer to a valid KIMProxy */ ::KIMProxy* imProxy(); + /** + * Returns true IFF the user has requested that the current mail checks + * should be aborted. Needs to be periodically polled. + */ + bool mailCheckAborted() const; + /** Set the state of the abort requested variable to false, + * i.e. enable mail checking again + */ + void enableMailCheck(); + /** + * Set the state of the abort requested variable to true, + * (to let the current jobs run, but stop when possible). + * This is used to cancel mail checks when closing the last mainwindow + */ + void abortMailCheck(); + public slots: - //Save contents of all open composer widnows to ~/dead.letter + /// Save contents of all open composer widnows to ~/dead.letter void dumpDeadLetters(); /** Call this slot instead of directly @ref KConfig::sync() to @@ -299,6 +315,7 @@ private: /** true unles kmail is closed by session management */ bool closed_by_user; bool the_firstInstance; + bool mMailCheckAborted; static KMKernel *mySelf; KSharedConfig::Ptr mConfig; QTextCodec *netCodec; @@ -316,7 +333,7 @@ private: // temporary mainwin KMMainWin *mWin; MailServiceImpl *mMailService; - + // KIMProxy provides access to up to date instant messaging presence data ::KIMProxy *mKIMProxy; // true if the context menu of KMFolderTree or KMHeaders is shown diff --git a/kmmainwidget.cpp b/kmmainwidget.cpp index 92b081fd5..0ca2be652 100644 --- a/kmmainwidget.cpp +++ b/kmmainwidget.cpp @@ -94,6 +94,9 @@ using KMail::HeaderListQuickSearch; using namespace KMime; using KMime::Types::AddrSpecList; +#include "progressmanager.h" +using KMail::ProgressManager; + #include "kmmainwidget.moc" QPtrList* KMMainWidget::s_mainWidgetList = 0; @@ -584,10 +587,10 @@ void KMMainWidget::createWidgets(void) mFolderTree, SLOT(incCurrentFolder())); new KAction( - i18n("Abort Current Operation"), Key_Escape, KMBroadcastStatus::instance(), - SLOT(requestAbort()), actionCollection(), "cancel" ); + i18n("Abort Current Operation"), Key_Escape, ProgressManager::instance(), + SLOT(slotAbortAll()), actionCollection(), "cancel" ); accel->connectItem(accel->insertItem(Key_Escape), - KMBroadcastStatus::instance(), SLOT(requestAbort())); + ProgressManager::instance(), SLOT(slotAbortAll())); new KAction( i18n("Focus on Previous Folder"), CTRL+Key_Left, mFolderTree, diff --git a/kmmainwin.cpp b/kmmainwin.cpp index 70bdf68f1..4e36c24fb 100644 --- a/kmmainwin.cpp +++ b/kmmainwin.cpp @@ -7,7 +7,6 @@ #include "kstatusbar.h" #include "kmkernel.h" #include "kmsender.h" -#include "kmbroadcaststatus.h" #include "statusbarprogresswidget.h" #include "kmglobal.h" #include "kmacctmgr.h" @@ -56,7 +55,7 @@ KMMainWin::KMMainWin(QWidget *) SLOT(slotUpdateToolbars()) ); // Enable mail checks again (see destructor) - KMBroadcastStatus::instance()->reset(); + kmkernel->enableMailCheck(); } KMMainWin::~KMMainWin() @@ -82,7 +81,7 @@ KMMainWin::~KMMainWin() kdDebug(5006) << "Closing last KMMainWin: stopping mail check" << endl; // Running KIO jobs prevent kapp from exiting, so we need to kill them // if they are only about checking mail (not important stuff like moving messages) - KMBroadcastStatus::instance()->setAbortRequested(); + kmkernel->abortMailCheck(); kmkernel->acctMgr()->cancelMailCheck(); } } diff --git a/progressmanager.cpp b/progressmanager.cpp index 0265499d9..4d16b5360 100644 --- a/progressmanager.cpp +++ b/progressmanager.cpp @@ -87,7 +87,7 @@ void ProgressItem::removeChild( ProgressItem *kiddo ) void ProgressItem::cancel() { - if ( mCanceled ) return; + if ( mCanceled || !mCanBeCanceled ) return; kdDebug(5006) << "ProgressItem::cancel() - " << label() << endl; mCanceled = true; // Cancel all children. @@ -206,6 +206,14 @@ ProgressItem* ProgressManager::singleItem() const return 0; } +void ProgressManager::slotAbortAll() +{ + QDictIterator< ProgressItem > it( mTransactions ); + for ( ; it.current(); ++it ) { + it.current()->cancel(); + } +} + } // namespace #include "progressmanager.moc" diff --git a/progressmanager.h b/progressmanager.h index 53f7e3254..5143b6b6e 100644 --- a/progressmanager.h +++ b/progressmanager.h @@ -352,6 +352,11 @@ class ProgressManager : public QObject */ void slotStandardCancelHandler( ProgressItem* item ); + /** + * Aborts all running jobs. Bound to "Esc" + */ + void slotAbortAll(); + private slots: void slotTransactionCompleted( ProgressItem *item );