diff --git a/kmaccount.cpp b/kmaccount.cpp index 350dc2625..d937649f4 100644 --- a/kmaccount.cpp +++ b/kmaccount.cpp @@ -29,6 +29,7 @@ KMAccount::KMAccount(KMAcctMgr* aOwner, const char* aName) mOwner = aOwner; mName = aName; mFolder = NULL; + } @@ -85,3 +86,47 @@ void KMAccount::writeConfig(KConfig& config) config.writeEntry("Folder", mFolder ? (const char*)mFolder->name() : ""); } +void KMAccount::installTimer() +{ + if(!mTimer) { + mTimer = new QTimer(); + connect(mTimer,SIGNAL(timeout()),SLOT(mailCheck())); + connect(this,SIGNAL(requestCheck(KMAccount *)), + acctMgr,SLOT(singleCheckMail(KMAccount *))); + printf("Starting new Timer with interval: %ld\n",mInterval*1000*60); + mTimer->start(mInterval*1000*60); + } + else { + mTimer->stop(); + printf("Starting old Timer with interval: %ld\n",mInterval*1000*60); + mTimer->start(mInterval*1000*60); + } + +} + +void KMAccount::deinstallTimer() +{ + printf("Calling deinstallTimer()\n"); + if(mTimer) { + mTimer->stop(); + disconnect(mTimer); + disconnect(this); + delete mTimer; + mTimer = 0L; + } +} + +void KMAccount::mailCheck() +{ + printf("Emitting signal\n"); + emit requestCheck(this); +} + +void KMAccount::stateChanged() +{ + printf("stateChanged called\n"); + if(timerRequested()) + installTimer(); + else + deinstallTimer(); +} diff --git a/kmaccount.h b/kmaccount.h index b06fe61aa..b84f3fe25 100644 --- a/kmaccount.h +++ b/kmaccount.h @@ -7,6 +7,8 @@ #include #include +#include +#include #include class KMAcctMgr; @@ -50,6 +52,14 @@ public: is already properly set by the caller. */ virtual void writeConfig(KConfig& config); + virtual bool timerRequested() {return mRTimer;} + virtual void setTimerRequested(bool _timer) { mRTimer = _timer;} + + virtual void installTimer(); + + virtual void deinstallTimer(); + + virtual void stateChanged(); protected: KMAccount(KMAcctMgr* owner, const char* accountName); @@ -57,6 +67,18 @@ protected: QString mName; KMAcctMgr* mOwner; KMAcctFolder* mFolder; + QTimer *mTimer; + bool mRTimer; + int mInterval; + + + +private slots: + void mailCheck(); + +signals: + void requestCheck(KMAccount *); + }; diff --git a/kmacctlocal.cpp b/kmacctlocal.cpp index 545832cdf..0a0ab6d17 100644 --- a/kmacctlocal.cpp +++ b/kmacctlocal.cpp @@ -110,6 +110,8 @@ void KMAcctLocal::readConfig(KConfig& config) KMAcctLocalInherited::readConfig(config); mLocation = config.readEntry("Location", defaultPath); + mRTimer = config.readNumEntry("timer",FALSE); + mInterval = config.readNumEntry("interval",0); } @@ -119,6 +121,8 @@ void KMAcctLocal::writeConfig(KConfig& config) KMAcctLocalInherited::writeConfig(config); config.writeEntry("Location", mLocation); + config.writeEntry("timer",mRTimer); + config.writeEntry("interval",mInterval); } diff --git a/kmacctmgr.cpp b/kmacctmgr.cpp index bbbc1c400..d1910999b 100644 --- a/kmacctmgr.cpp +++ b/kmacctmgr.cpp @@ -4,6 +4,7 @@ #include "kmacctlocal.h" #include "kmacctpop.h" #include "kmglobal.h" +#include "kbusyptr.h" #include #include @@ -14,6 +15,7 @@ #include #include +extern KBusyPtr *kbp; //----------------------------------------------------------------------------- KMAcctMgr::KMAcctMgr(const char* aBasePath): KMAcctMgrInherited() { @@ -51,6 +53,7 @@ void KMAcctMgr::setBasePath(const char* aBasePath) //----------------------------------------------------------------------------- void KMAcctMgr::writeConfig(bool withSync) { + printf("writing config\n"); KConfig* config = app->getConfig(); KMAccount* acct; QString groupName(256); @@ -72,6 +75,7 @@ void KMAcctMgr::writeConfig(bool withSync) //----------------------------------------------------------------------------- void KMAcctMgr::readConfig(void) { + printf("Read config called\n"); KConfig* config = app->getConfig(); KMAccount* acct; QString groupName(256), acctType, acctName; @@ -91,9 +95,26 @@ void KMAcctMgr::readConfig(void) acct = create(acctType, acctName); if (!acct) continue; acct->readConfig(*config); + if(acct->timerRequested()) + acct->installTimer(); + else + acct->deinstallTimer(); } } +bool KMAcctMgr::singleCheckMail(KMAccount *account) +{ + bool hasNewMail = FALSE; + printf("singleCheckMail called!\n"); + kbp->busy(); + if (account->processNewMail()) + { + hasNewMail = TRUE; + emit newMail(account); + } + kbp->idle(); + return hasNewMail; +} //----------------------------------------------------------------------------- KMAccount* KMAcctMgr::create(const QString& aType, const QString& aName) diff --git a/kmacctmgr.h b/kmacctmgr.h index 46e62fa2a..8e17c05f8 100644 --- a/kmacctmgr.h +++ b/kmacctmgr.h @@ -61,6 +61,9 @@ public: is new mail in at least one account. */ virtual bool checkMail(void); +public slots: + virtual bool singleCheckMail(KMAccount *); + signals: /** emitted if new mail arrived in the account */ void newMail(KMAccount* inAccount); diff --git a/kmacctpop.cpp b/kmacctpop.cpp index d04d22af5..ba1fe5c62 100644 --- a/kmacctpop.cpp +++ b/kmacctpop.cpp @@ -87,7 +87,6 @@ bool KMAcctPop::processNewMail(void) result = doProcessNewMail(); signal(SIGALRM, oldHandler); signal(SIGPIPE, pipeHandler); - return result; } @@ -288,6 +287,8 @@ void KMAcctPop::readConfig(KConfig& config) mProtocol = config.readNumEntry("protocol"); mLeaveOnServer = config.readNumEntry("leave-on-server", FALSE); mRetrieveAll = config.readNumEntry("retrieve-all", TRUE); + mRTimer = config.readNumEntry("timer",FALSE); + mInterval = config.readNumEntry("interval",0); } @@ -310,6 +311,8 @@ void KMAcctPop::writeConfig(KConfig& config) config.writeEntry("protocol", mProtocol); config.writeEntry("leave-on-server",mLeaveOnServer); config.writeEntry("retrieve-all",mRetrieveAll); + config.writeEntry("timer",mRTimer); + config.writeEntry("interval",mInterval); } diff --git a/kmsettings.cpp b/kmsettings.cpp index cee1f3a67..fb1ab4042 100644 --- a/kmsettings.cpp +++ b/kmsettings.cpp @@ -450,6 +450,7 @@ void KMSettings::modifyAccount(int index,int) d->exec(); delete d; + acct->stateChanged(); accountList->changeItem(tabNetworkAcctStr(acct), index); accountList->setCurrentItem(index); } @@ -709,6 +710,9 @@ void KMAccountSettings::accept() if (acctType == "local") { ((KMAcctLocal*)mAcct)->setLocation(mEdtLocation->text()); + + // Wainting for GUI + //((KMAcctLocal*)mAcct)->setTimerRequested(false); } else if (acctType == "pop") @@ -718,6 +722,9 @@ void KMAccountSettings::accept() ((KMAcctPop*)mAcct)->setLogin(mEdtLogin->text()); ((KMAcctPop*)mAcct)->setPasswd(mEdtPasswd->text(), true); ((KMAcctPop*)mAcct)->setLeaveOnServer(!chk->isChecked()); + + // Waiting for GUI + //((KMAcctPop*)mAcct)->setTimerRequested(false); } acctMgr->writeConfig(TRUE);