From c3aaa41f25b23c26b7d05f33ad8d3ad6691cddbb Mon Sep 17 00:00:00 2001 From: Carsten Burghardt Date: Sun, 14 Apr 2002 13:22:32 +0000 Subject: [PATCH] Activated the new-mail-notification for imap. The last count is cached so that a notification is only emitted when the unread-count has increased. Fixes Bug#39606 svn path=/trunk/kdenetwork/kmail/; revision=149385 --- kmacctimap.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++--- kmacctimap.h | 8 +++++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/kmacctimap.cpp b/kmacctimap.cpp index 9c2bc798b..6b09f8750 100644 --- a/kmacctimap.cpp +++ b/kmacctimap.cpp @@ -50,6 +50,8 @@ KMAcctImap::KMAcctImap(KMAcctMgr* aOwner, const QString& aAccountName): mSlave = NULL; mTotal = 0; mFolder = 0; + mCountUnread = 0; + mCountLastUnread = 0; connect(KMBroadcastStatus::instance(), SIGNAL(signalAbortRequested()), this, SLOT(slotAbortRequested())); connect(&mIdleTimer, SIGNAL(timeout()), SLOT(slotIdleTimeout())); @@ -502,6 +504,18 @@ void KMAcctImap::processNewMail(bool interactive) kernel->imapFolderMgr()->createFolderList(&strList, &folderList, mFolder->child(), QString::null, false); QValueList >::Iterator it; + // first get the current count of unread-messages + mCountRemainChecks = 0; + mCountLastUnread = 0; + for (it = folderList.begin(); it != folderList.end(); it++) + { + KMFolder *folder = *it; + if (folder && !folder->noContent()) + { + mCountLastUnread += folder->countUnread(); + } + } + // then check for new mails for (it = folderList.begin(); it != folderList.end(); it++) { KMFolder *folder = *it; @@ -510,11 +524,49 @@ void KMAcctImap::processNewMail(bool interactive) KMFolderImap *imapFolder = static_cast(folder); if (imapFolder->getContentState() != KMFolderImap::imapInProgress) { - if (imapFolder->isSelected()) + // connect the result-signals for new-mail-notification + mCountRemainChecks++; + if (imapFolder->isSelected()) { + connect(imapFolder, SIGNAL(folderComplete(KMFolderImap*, bool)), + this, SLOT(postProcessNewMail(KMFolderImap*, bool))); imapFolder->getFolder(); - else imapFolder->processNewMail(interactive); + } + else { + connect(imapFolder, SIGNAL(numUnreadMsgsChanged(KMFolder*)), + this, SLOT(postProcessNewMail(KMFolder*))); + imapFolder->processNewMail(interactive); + } } } } - emit finishedCheck(false); +} + +void KMAcctImap::postProcessNewMail(KMFolderImap* folder, bool) +{ + disconnect(folder, SIGNAL(folderComplete(KMFolderImap*, bool)), + this, SLOT(postProcessNewMail(KMFolderImap*, bool))); + postProcessNewMail(static_cast(folder)); +} + +void KMAcctImap::postProcessNewMail(KMFolder* folder) +{ + disconnect(folder, SIGNAL(numUnreadMsgsChanged(KMFolder*)), + this, SLOT(postProcessNewMail(KMFolder*))); + + mCountRemainChecks--; + + // count the unread messages + mCountUnread += folder->countUnread(); + if (mCountRemainChecks == 0) + { + // all checks are done + if (mCountUnread > 0 && mCountUnread > mCountLastUnread) + { + emit finishedCheck(true); + mCountLastUnread = mCountUnread; + } else { + emit finishedCheck(false); + } + mCountUnread = 0; + } } diff --git a/kmacctimap.h b/kmacctimap.h index cc1f9fdd1..64ef9de3f 100644 --- a/kmacctimap.h +++ b/kmacctimap.h @@ -226,6 +226,8 @@ protected: KIO::MetaData mSlaveConfig; QPtrList mJobList; KMFolderImap *mFolder; + int mCountUnread, mCountLastUnread; + int mCountRemainChecks; protected slots: /** @@ -247,6 +249,12 @@ protected slots: * Display an error message, that connecting failed */ void slotSlaveError(KIO::Slave *aSlave, int, const QString &errorMsg); + + /** new-mail-notification for the current folder (is called via folderComplete) */ + void postProcessNewMail(KMFolderImap*, bool); + + /** new-mail-notification for not-selected folders (is called via numUnreadMsgsChanged) */ + void postProcessNewMail(KMFolder*); }; #endif /*KMAcctImap_h*/