From 7a3d0a8a82002b484be84c105c591d2d59e0a11e Mon Sep 17 00:00:00 2001 From: Bruno Virlet Date: Mon, 27 Aug 2007 14:05:44 +0000 Subject: [PATCH] Port r705221 to enterprise. See: https://bugzilla.novell.com/show_bug.cgi?id=273550 svn path=/branches/kdepim/enterprise/kdepim/; revision=705225 --- accountmanager.cpp | 5 ----- accountmanager.h | 2 -- kmaccount.cpp | 19 ++++--------------- kmaccount.h | 16 ++++++++++------ kmacctlocal.cpp | 47 +++++++++++++++++++++++++++++----------------- kmacctlocal.h | 14 +++++++++++++- kmacctmaildir.cpp | 28 ++++++++++++++++----------- kmacctmaildir.h | 3 +++ popaccount.cpp | 22 ++++++++++++++-------- popaccount.h | 7 ++++++- 10 files changed, 97 insertions(+), 66 deletions(-) diff --git a/accountmanager.cpp b/accountmanager.cpp index 7ca9ed1df..35e2e8f3b 100644 --- a/accountmanager.cpp +++ b/accountmanager.cpp @@ -122,11 +122,6 @@ void AccountManager::singleCheckMail(KMAccount *account, bool interactive) return; } - QTimer::singleShot(0, this, SLOT(slotProcessNextCheck())); -} -//----------------------------------------------------------------------------- -void AccountManager::slotProcessNextCheck() -{ processNextCheck( false ); } //----------------------------------------------------------------------------- diff --git a/accountmanager.h b/accountmanager.h index e46b26eb3..fda0591f7 100644 --- a/accountmanager.h +++ b/accountmanager.h @@ -97,8 +97,6 @@ public slots: void singleInvalidateIMAPFolders( KMAccount * ); void intCheckMail( int, bool interactive = true ); - /** Call processNextCheck with the false argument. **/ - void slotProcessNextCheck(); void processNextCheck( bool newMail ); /** this slot increases the count of new mails to show a total number diff --git a/kmaccount.cpp b/kmaccount.cpp index 863906062..0f3f994ce 100644 --- a/kmaccount.cpp +++ b/kmaccount.cpp @@ -88,7 +88,6 @@ KMAccount::KMAccount(AccountManager* aOwner, const QString& aName, uint id) mInterval(0), mExclude(false), mCheckingMail(false), - mPrecommandSuccess(true), mHasInbox(false), mMailCheckProgressItem(0) { @@ -350,11 +349,11 @@ void KMAccount::deinstallTimer() } //----------------------------------------------------------------------------- -bool KMAccount::runPrecommand(const QString &precommand) +void KMAccount::startPrecommand(const QString &precommand) { // Run the pre command if there is one if ( precommand.isEmpty() ) - return true; + emit precommandExited( true ); KMPrecommand precommandProcess(precommand, this); @@ -365,18 +364,8 @@ bool KMAccount::runPrecommand(const QString &precommand) SLOT(precommandExited(bool))); kdDebug(5006) << "Running precommand " << precommand << endl; - if (!precommandProcess.start()) return false; - - kapp->eventLoop()->enterLoop(); - - return mPrecommandSuccess; -} - -//----------------------------------------------------------------------------- -void KMAccount::precommandExited(bool success) -{ - mPrecommandSuccess = success; - kapp->eventLoop()->exitLoop(); + if (!precommandProcess.start()) + emit precommandExited( false ); } //----------------------------------------------------------------------------- diff --git a/kmaccount.h b/kmaccount.h index 0f712df69..4147062eb 100644 --- a/kmaccount.h +++ b/kmaccount.h @@ -184,12 +184,12 @@ public: virtual void setPrecommand(const QString &cmd) { mPrecommand = cmd; } /** - * Runs the precommand. If the precommand is empty, the method + * Start the precommand. If the precommand is empty, the method * will just return success and not actually do anything * - * @return True if successful, false otherwise + * @return True if successful start, false otherwise */ - bool runPrecommand(const QString &precommand); + void startPrecommand(const QString &precommand); /** * Very primitive en/de-cryption so that the password is not @@ -216,7 +216,7 @@ public: * @return whether mail checks can proceed */ virtual bool mailCheckCanProceed() const { return true; } - + /** * Set/Get if this account is currently checking mail */ @@ -246,6 +246,12 @@ public: } signals: + /** + * Emitted after the precommand exited, successfully or not + * @param success true if the command execution was successful. + */ + virtual void precommandExited( bool success ); + /** * Emitted after the mail check is finished. * @param newMail true if there was new mail @@ -262,7 +268,6 @@ signals: protected slots: virtual void mailCheck(); virtual void sendReceipts(); - virtual void precommandExited(bool); protected: KMAccount( AccountManager* owner, const QString& accountName, uint id); @@ -305,7 +310,6 @@ protected: int mInterval; bool mExclude; bool mCheckingMail : 1; - bool mPrecommandSuccess; QValueList mReceipts; QPtrList mJobList; bool mHasInbox : 1; diff --git a/kmacctlocal.cpp b/kmacctlocal.cpp index c168b654a..3f46a0a9d 100644 --- a/kmacctlocal.cpp +++ b/kmacctlocal.cpp @@ -32,7 +32,8 @@ using KPIM::ProgressManager; KMAcctLocal::KMAcctLocal(AccountManager* aOwner, const QString& aAccountName, uint id): KMAccount(aOwner, aAccountName, id), mHasNewMail( false ), mAddedOk( true ), mNumMsgs( 0 ), - mMsgsFetched( 0 ), mMailFolder( 0 ) + mMsgsFetched( 0 ), mMailFolder( 0 ), + mMboxStorage( 0 ) { mLock = procmail_lockfile; } @@ -75,9 +76,14 @@ void KMAcctLocal::processNewMail(bool) { mHasNewMail = false; - if ( !preProcess() ) { + connect( this, SIGNAL(preProcessExited(bool)), SLOT(continueProcess()) ); + preProcess(); +} + +void KMAcctLocal::continueProcess( bool preProcessSuccess ) +{ + if ( !preProcessSuccess ) return; - } QTime t; t.start(); @@ -98,29 +104,29 @@ void KMAcctLocal::processNewMail(bool) //----------------------------------------------------------------------------- -bool KMAcctLocal::preProcess() +void KMAcctLocal::preProcess() { if ( precommand().isEmpty() ) { QFileInfo fi( location() ); if ( fi.size() == 0 ) { BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, 0 ); checkDone( mHasNewMail, CheckOK ); - return false; + emit preProcessExited( false ); } } mMailFolder = new KMFolder( 0, location(), KMFolderTypeMbox, false /* no index */, false /* don't export sernums */ ); - KMFolderMbox* mboxStorage = + mMboxStorage = static_cast(mMailFolder->storage()); - mboxStorage->setLockType( mLock ); + mMboxStorage->setLockType( mLock ); if ( mLock == procmail_lockfile) - mboxStorage->setProcmailLockFileName( mProcmailLockFileName ); + mMboxStorage->setProcmailLockFileName( mProcmailLockFileName ); if (!mFolder) { checkDone( mHasNewMail, CheckError ); BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." )); - return false; + emit preProcessExited( false ); } //BroadcastStatus::instance()->reset(); @@ -137,15 +143,20 @@ bool KMAcctLocal::preProcess() false, // cannot be canceled false ); // no tls/ssl - // run the precommand - if (!runPrecommand(precommand())) + connect( this, SIGNAL(precommandExited(bool)), SLOT(continuePreProcess(bool)) ); + startPrecommand(precommand()); +} + +void KMAcctLocal::continuePreProcess( bool precommandSuccess ) +{ + if ( !precommandSuccess ) { kdDebug(5006) << "cannot run precommand " << precommand() << endl; checkDone( mHasNewMail, CheckError ); BroadcastStatus::instance()->setStatusMsg( i18n( "Running precommand failed." )); - return false; + emit preProcessExited( false ); } - + const int rc = mMailFolder->open(); if ( rc != 0 ) { QString aStr; @@ -156,17 +167,17 @@ bool KMAcctLocal::preProcess() << mMailFolder->name() << endl; checkDone( mHasNewMail, CheckError ); BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." )); - return false; + emit preProcessExited( false ); } - if (!mboxStorage->isLocked()) { + if (!mMBoxStorage->isLocked()) { kdDebug(5006) << "mailFolder could not be locked" << endl; mMailFolder->close(); checkDone( mHasNewMail, CheckError ); QString errMsg = i18n( "Transmission failed: Could not lock %1." ) .arg( mMailFolder->location() ); BroadcastStatus::instance()->setStatusMsg( errMsg ); - return false; + emit preProcessExited( false ); } mFolder->open(); @@ -180,7 +191,7 @@ bool KMAcctLocal::preProcess() .arg(mMailFolder->location()).arg( mNumMsgs ); //BroadcastStatus::instance()->setStatusProgressEnable( "L" + mName, true ); - return true; + emit preProcessExited( true ); } @@ -320,3 +331,5 @@ void KMAcctLocal::setProcmailLockFileName(const QString& s) { mProcmailLockFileName = s; } + +#include "kmacctlocal.moc" diff --git a/kmacctlocal.h b/kmacctlocal.h index 5e1b6284d..66f703aeb 100644 --- a/kmacctlocal.h +++ b/kmacctlocal.h @@ -7,8 +7,12 @@ #include "kmaccount.h" #include "kmglobal.h" +class KMFolderMbox; + class KMAcctLocal: public KMAccount { + Q_OBJECT + protected: friend class ::AccountManager; @@ -37,8 +41,14 @@ public: virtual void readConfig(KConfig&); virtual void writeConfig(KConfig&); +signals: + virtual void preProcessExited( bool preProcessSuccess ); + private slots: - bool preProcess(); + void preProcess(); + void continuePreProcess( bool preCommandSuccess ); + void continueProcess( bool preProcessSuccess ); + bool fetchMsg(); void postProcess(); @@ -52,6 +62,8 @@ private: int mMsgsFetched; KMFolder *mMailFolder; QString mStatusMsgStub; + + KMFolderMbox* mMboxStorage; // used during preprocess }; #endif /*kmacctlocal_h*/ diff --git a/kmacctmaildir.cpp b/kmacctmaildir.cpp index 1f417e9b0..19d55c3bb 100644 --- a/kmacctmaildir.cpp +++ b/kmacctmaildir.cpp @@ -79,7 +79,6 @@ void KMAcctMaildir::pseudoAssign( const KMAccount * a ) //----------------------------------------------------------------------------- void KMAcctMaildir::processNewMail(bool) { - QTime t; hasNewMail = false; if ( precommand().isEmpty() ) { @@ -91,15 +90,6 @@ void KMAcctMaildir::processNewMail(bool) } } - KMFolder mailFolder(0, location(), KMFolderTypeMaildir, - false /* no index */, false /* don't export sernums */); - - long num = 0; - long i; - int rc; - KMMessage* msg; - bool addedOk; - if (!mFolder) { checkDone( hasNewMail, CheckError ); BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." )); @@ -119,7 +109,23 @@ void KMAcctMaildir::processNewMail(bool) false ); // no tls/ssl // run the precommand - if (!runPrecommand(precommand())) + connect( this, SIGNAL(precommandExited(bool)), SLOT(continueProcessNewMail(bool)) ); + startPrecommand( precommand() ); +} + +void KMAcctMaildir::continueProcessNewMail( bool precommandSuccess ) +{ + QTime t; + long num = 0; + long i; + int rc; + KMMessage* msg; + bool addedOk; + + KMFolder mailFolder(0, location(), KMFolderTypeMaildir, + false /* no index */, false /* don't export sernums */); + + if ( !precommandSuccess ) { kdDebug(5006) << "cannot run precommand " << precommand() << endl; checkDone( hasNewMail, CheckError ); diff --git a/kmacctmaildir.h b/kmacctmaildir.h index 05b90833c..ef13fdb72 100644 --- a/kmacctmaildir.h +++ b/kmacctmaildir.h @@ -29,6 +29,9 @@ public: virtual void readConfig(KConfig&); virtual void writeConfig(KConfig&); +private slots: + void continueProcessNewMail( bool precommandSuccess ); + protected: QString mLocation; bool hasNewMail; diff --git a/popaccount.cpp b/popaccount.cpp index 2f0b26cf2..a5916151f 100644 --- a/popaccount.cpp +++ b/popaccount.cpp @@ -367,14 +367,20 @@ void PopAccount::slotAbortRequested() void PopAccount::startJob() { // Run the precommand - if (!runPrecommand(precommand())) - { - KMessageBox::sorry(0, - i18n("Could not execute precommand: %1").arg(precommand()), - i18n("KMail Error Message")); - checkDone( false, CheckError ); - return; - } + connect( this, SIGNAL(precommandExited(bool)), SLOT(continueJob(bool)) ); + startPrecommand(precommand()); +} + +void PopAccount::continueJob( bool precommandSuccess ) +{ + if ( !precommandSuccess ) + { + KMessageBox::sorry(0, + i18n("Could not execute precommand: %1").arg(precommand()), + i18n("KMail Error Message")); + checkDone( false, CheckError ); + return; + } // end precommand code KURL url = getUrl(); diff --git a/popaccount.h b/popaccount.h index 887436a2f..0f52f2963 100644 --- a/popaccount.h +++ b/popaccount.h @@ -45,7 +45,7 @@ public: */ bool usePipelining(void) const { return mUsePipelining; } virtual void setUsePipelining(bool); - + /** * Shall messages be left on the server upon retreival (TRUE) * or deleted (FALSE). @@ -170,6 +170,11 @@ protected: int dataCounter; protected slots: + /** + * Continue the job after precommand was executed + */ + void continueJob( bool precommandSuccess ); + /** * Messages are downloaded in the background and then once every x seconds * a batch of messages are processed. Messages are processed in batches to