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
wilder-work
Carsten Burghardt 24 years ago
parent 1ebeeaab0a
commit c3aaa41f25
  1. 58
      kmacctimap.cpp
  2. 8
      kmacctimap.h

@ -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<QGuardedPtr<KMFolder> >::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<KMFolderImap*>(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<KMFolder*>(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;
}
}

@ -226,6 +226,8 @@ protected:
KIO::MetaData mSlaveConfig;
QPtrList<KMImapJob> 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*/

Loading…
Cancel
Save