[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Patch to show a total number of new msgs
From:       Antonio Larrosa =?iso-8859-1?q?Jim=E9nez?= <larrosa () kde ! org>
Date:       2002-02-28 18:36:52
[Download RAW message or body]

Hello,

Currently, when using Ctrl-L to get your new mail. It may be possible to 
have many new mails and still get a status mail which says "no new 
messages" because the last account didn't have any new mail.

The attached patch increases an internal counter and shows the total after 
checking all the accounts. The display of this total is disabled in case 
of error (so that the user can see it in the status bar).

Note that I couldn't find a nice way to know the number of new mails in 
IMAP mode (KMacctImap), so I just disable the display of the total number 
of mails so that when you have an imap account, the behaviour is as 
currently.

Can somebody review it ?
Please Cc: me any answer, as I'm not in this list.

Greetings,
--
Antonio Larrosa Jimenez
KDE Core developer  - larrosa@kde.org
http://perso.wanadoo.es/antlarr
KDE - The development framework of the future, today.
["kmail.diff" (text/x-diff)]

Index: kmaccount.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmaccount.h,v
retrieving revision 1.43
diff -u -p -r1.43 kmaccount.h
--- kmaccount.h	2002/02/24 14:36:22	1.43
+++ kmaccount.h	2002/02/28 18:25:37
@@ -148,6 +148,7 @@ public:
 
 signals:
   virtual void finishedCheck(bool newMail);
+  virtual void newMailsProcessed(int numberOfNewMails);
 
 protected slots:
   virtual void mailCheck();
Index: kmacctexppop.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmacctexppop.cpp,v
retrieving revision 1.110
diff -u -p -r1.110 kmacctexppop.cpp
--- kmacctexppop.cpp	2002/02/24 14:36:22	1.110
+++ kmacctexppop.cpp	2002/02/28 18:25:37
@@ -141,6 +141,7 @@ void KMAcctExpPop::processNewMail(bool _
         != QDialog::Accepted)
       {
 	emit finishedCheck(false);
+	emit newMailsProcessed(0);
 	return;
       } else {
         mPasswd = encryptStr(passwd);
@@ -161,6 +162,7 @@ void KMAcctExpPop::processNewMail(bool _
   }
   else {
     emit finishedCheck(false);
+    emit newMailsProcessed(-1);
     return;
   }
 }
@@ -417,6 +419,7 @@ void KMAcctExpPop::startJob() {
                          i18n("Couldn't execute precommand: %1").arg(precommand()),
                          i18n("Kmail Error Message"));
       emit finishedCheck(idsOfMsgs.count() > 0);
+      emit newMailsProcessed(-1);
       return;
     }
   // end precommand code
@@ -750,6 +753,7 @@ void KMAcctExpPop::slotJobFinished() {
     KMBroadcastStatus::instance()->reset();
 
     emit finishedCheck(numMessages > 0);
+    emit newMailsProcessed(numMessages);
   }
 }
 
Index: kmacctimap.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmacctimap.cpp,v
retrieving revision 1.93
diff -u -p -r1.93 kmacctimap.cpp
--- kmacctimap.cpp	2002/02/24 14:36:22	1.93
+++ kmacctimap.cpp	2002/02/28 18:25:37
@@ -491,6 +491,7 @@ void KMAcctImap::slotSimpleResult(KIO::J
 //-----------------------------------------------------------------------------
 void KMAcctImap::processNewMail(bool interactive)
 {
+  emit newMailsProcessed(-1);
   if (!mFolder || !mFolder->child())
   {
     emit finishedCheck(false);
Index: kmacctlocal.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmacctlocal.cpp,v
retrieving revision 1.73
diff -u -p -r1.73 kmacctlocal.cpp
--- kmacctlocal.cpp	2002/01/16 12:43:31	1.73
+++ kmacctlocal.cpp	2002/02/28 18:25:37
@@ -94,6 +94,7 @@ void KMAcctLocal::processNewMail(bool)
       QString statusMsg = i18n("Transmission completed, no new messages.");
       KMBroadcastStatus::instance()->setStatusMsg( statusMsg );
       emit finishedCheck(hasNewMail);
+      emit newMailsProcessed(0);
       return;
     }
   }
@@ -111,6 +112,7 @@ void KMAcctLocal::processNewMail(bool)
 
   if (!mFolder) {
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
     KMBroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
     return;
   }
@@ -124,6 +126,7 @@ void KMAcctLocal::processNewMail(bool)
   {
     kdDebug(5006) << "cannot run precommand " << precommand() << endl;
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
   }
 
   mailFolder.setAutoCreateIndex(FALSE);
@@ -138,6 +141,7 @@ void KMAcctLocal::processNewMail(bool)
     kdDebug(5006) << "cannot open file " << mailFolder.path() << "/"
       << mailFolder.name() << endl;
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
     KMBroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
     return;
   }
@@ -146,6 +150,7 @@ void KMAcctLocal::processNewMail(bool)
     kdDebug(5006) << "mailFolder could not be locked" << endl;
     mailFolder.close();
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
     QString errMsg = i18n( "Transmission failed: Could not lock %1." )
       .arg( mailFolder.location() );
     KMBroadcastStatus::instance()->setStatusMsg( errMsg );
@@ -218,6 +223,7 @@ void KMAcctLocal::processNewMail(bool)
   mFolder->quiet(FALSE);
 
   emit finishedCheck(hasNewMail);
+  emit newMailsProcessed(num);
 
   return;
 }
Index: kmacctmaildir.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmacctmaildir.cpp,v
retrieving revision 1.6
diff -u -p -r1.6 kmacctmaildir.cpp
--- kmacctmaildir.cpp	2002/01/16 12:43:31	1.6
+++ kmacctmaildir.cpp	2002/02/28 18:25:37
@@ -82,6 +82,7 @@ void KMAcctMaildir::processNewMail(bool)
     QFileInfo fi( location() );
     if ( !fi.exists() ) {
       emit finishedCheck(hasNewMail);
+      emit newMailsProcessed(0);
       QString statusMsg = i18n("Transmission completed, no new messages");
       KMBroadcastStatus::instance()->setStatusMsg( statusMsg );
       return;
@@ -98,6 +99,7 @@ void KMAcctMaildir::processNewMail(bool)
 
   if (!mFolder) {
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
     KMBroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
     return;
   }
@@ -111,6 +113,7 @@ void KMAcctMaildir::processNewMail(bool)
   {
     kdDebug(5006) << "cannot run precommand " << precommand() << endl;
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
   }
 
   mailFolder.setAutoCreateIndex(FALSE);
@@ -125,6 +128,7 @@ void KMAcctMaildir::processNewMail(bool)
     kdDebug(5006) << "cannot open file " << mailFolder.path() << "/"
       << mailFolder.name() << endl;
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
     KMBroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
     return;
   }
@@ -132,6 +136,7 @@ void KMAcctMaildir::processNewMail(bool)
   if (mailFolder.isReadOnly()) { // mailFolder is locked
     mailFolder.close();
     emit finishedCheck(hasNewMail);
+    emit newMailsProcessed(-1);
     QString errMsg = i18n( "Transmission failed: Could not lock %1." )
       .arg( mailFolder.location() );
     KMBroadcastStatus::instance()->setStatusMsg( errMsg );
@@ -201,6 +206,7 @@ void KMAcctMaildir::processNewMail(bool)
   mFolder->quiet(FALSE);
 
   emit finishedCheck(hasNewMail);
+  emit newMailsProcessed(num);
 
   return;
 }
Index: kmacctmgr.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmacctmgr.cpp,v
retrieving revision 1.72
diff -u -p -r1.72 kmacctmgr.cpp
--- kmacctmgr.cpp	2002/01/19 07:48:36	1.72
+++ kmacctmgr.cpp	2002/02/28 18:25:37
@@ -5,6 +5,7 @@
 #include "kmacctlocal.h"
 #include "kmacctexppop.h"
 #include "kmacctimap.h"
+#include "kmbroadcaststatus.h"
 
 
 #include <assert.h>
@@ -191,7 +192,11 @@ KMAccount* KMAcctMgr::create(const QStri
     act = new KMAcctImap(this, aName);
 
   if (act)
+  {
     act->setFolder(kernel->inboxFolder());
+    connect( act, SIGNAL(newMailsProcessed(int)),
+	this, SLOT(addToTotalNewMailCount(int)) );
+  }
 
   return act;
 }
@@ -261,6 +266,8 @@ void KMAcctMgr::checkMail(bool _interact
     return;
   }
 
+  mTotalNewMailsArrived=0;
+
   mAccountIt->toFirst();
   while (TRUE)
   {
@@ -269,6 +276,12 @@ void KMAcctMgr::checkMail(bool _interact
     if (mAccountIt->atLast()) break;
     ++(*mAccountIt);
   }
+
+  if (mTotalNewMailsArrived!=-1)
+    KMBroadcastStatus::instance()->setStatusMsg(
+	i18n("Transmission completed, %n new message.",
+	  "Transmission completed, %n new messages.", mTotalNewMailsArrived) );
+
 }
 
 
@@ -326,5 +339,12 @@ void KMAcctMgr::intCheckMail(int item, b
 }
 
 
+//-----------------------------------------------------------------------------
+void KMAcctMgr::addToTotalNewMailCount(int newmails)
+{
+  if ( newmails==-1 ) mTotalNewMailsArrived=-1;
+  if ( mTotalNewMailsArrived==-1 ) return;
+  mTotalNewMailsArrived+=newmails;
+}
 //-----------------------------------------------------------------------------
 #include "kmacctmgr.moc"
Index: kmacctmgr.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmacctmgr.h,v
retrieving revision 1.24
diff -u -p -r1.24 kmacctmgr.h
--- kmacctmgr.h	2002/01/05 11:18:11	1.24
+++ kmacctmgr.h	2002/02/28 18:25:37
@@ -64,6 +64,12 @@ public slots:
   virtual void intCheckMail(int, bool _interactive = true);
   virtual void processNextCheck(bool _newMail);
 
+  /** this slot increases the count of new mails to show a total number
+  after checking in multiple accounts. You can disable the display of
+  the total (for example, to show an error in the status bar) by
+  calling it with numNewMails = -1  */
+  virtual void addToTotalNewMailCount(int numNewMails);
+  
 signals:
   /** emitted if new mail has been collected */
   void checkedMail(bool, bool);
@@ -76,6 +82,7 @@ private:
   bool checking;
   bool newMailArrived;
   bool interactive;
+  int  mTotalNewMailsArrived;
 };
 
 #endif /*kmacctmgr_h*/

_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic