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

List:       kmail-devel
Subject:    PATCH: mark any message
From:       Stephan Kulow <coolo () kde ! org>
Date:       2001-04-27 15:56:58
[Download RAW message or body]

Hi!

I have some folders where I want to be sure they are empty if I end my day.
But currently kmail only marks folders with unread messages. So I added a 
property to the folder that any message should be marked. One important 
folder that uses this property is the outbox.

I attach the patch, so you can comment on it (like in any other patch of mine 
it changes things that are not related to it :), but I won't commit it anyway 
before Don commited his major change and I merged my changes into it
(I need to open the folders on start to read the count of messages and Don 
said this count is going to be in the index soon)

Greetings, Stephan

-- 
People in cars cause accidents. Accidents in cars cause people.
["kmail-patch1" (text/x-c++)]

Index: kmfolder.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfolder.cpp,v
retrieving revision 1.152
diff -u -u -r1.152 kmfolder.cpp
--- kmfolder.cpp	2001/04/24 11:22:28	1.152
+++ kmfolder.cpp	2001/04/27 15:51:19
@@ -89,6 +89,9 @@
   mConvertToUtf8  = FALSE;
   mAccount        = NULL;
   mMailingListEnabled = FALSE;
+  mMarkAnyMessage = false;
+
+  readConfig();
 }
 
 
@@ -1013,7 +1016,7 @@
   needsCompact=true; // message is taken from here - needs to be compacted
 
   if (mb->status()==KMMsgStatusUnread ||
-      mb->status()==KMMsgStatusNew) {
+      mb->status()==KMMsgStatusNew || isAnyMessageMarked()) {
     --mUnreadMsgs;
     emit numUnreadMsgsChanged( this );
   }
@@ -1047,7 +1050,7 @@
   QString msgIdMD5 = mMsgList[idx]->msgIdMD5();
   msg = (KMMessage*)mMsgList.take(idx);
   if (msg->status()==KMMsgStatusUnread ||
-      msg->status()==KMMsgStatusNew) {
+      msg->status()==KMMsgStatusNew || isAnyMessageMarked()) {
     --mUnreadMsgs;
     emit numUnreadMsgsChanged( this );
   }
@@ -1372,7 +1375,7 @@
 //  if (mAccount) aMsg->removeHeaderField("X-UID");
 
   if (aMsg->status()==KMMsgStatusUnread ||
-      aMsg->status()==KMMsgStatusNew) {
+      aMsg->status()==KMMsgStatusNew || isAnyMessageMarked()) {
     if (mUnreadMsgs == -1) mUnreadMsgs = 1;
     else ++mUnreadMsgs;
     emit numUnreadMsgsChanged( this );
@@ -1783,6 +1786,7 @@
   mMailingListPostingAddress = config->readEntry("MailingListPostingAddress");
   mMailingListAdminAddress = config->readEntry("MailingListAdminAddress");
   mMailingListIdentity = config->readEntry("MailingListIdentity");
+  mMarkAnyMessage = config->readBoolEntry( "MarkAnyMessage" );
 }
 
 //-----------------------------------------------------------------------------
@@ -1795,14 +1799,15 @@
   config->writeEntry("MailingListPostingAddress", mMailingListPostingAddress);
   config->writeEntry("MailingListAdminAddress", mMailingListAdminAddress);
   config->writeEntry("MailingListIdentity", mMailingListIdentity);
+  config->writeEntry( "MarkAnyMessage", mMarkAnyMessage );
 }
 
 //-----------------------------------------------------------------------------
 void KMFolder::correctUnreadMsgsCount()
 {
-  open();
-  close();
-  emit numUnreadMsgsChanged( this );
+    open();
+    close();
+    emit numUnreadMsgsChanged( this );
 }
 
 //-----------------------------------------------------------------------------
Index: kmfolder.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfolder.h,v
retrieving revision 1.47
diff -u -u -r1.47 kmfolder.h
--- kmfolder.h	2001/04/24 11:22:28	1.47
+++ kmfolder.h	2001/04/27 15:51:19
@@ -150,6 +150,8 @@
       contained by this folder */
   virtual int countUnreadRecursive();
 
+  virtual bool isAnyMessageMarked() const { return mMarkAnyMessage; }
+
   // Called by KMMsgBase::setStatus when status of a message has changed
   // required to keep the number unread messages variable current.
   virtual void msgStatusChanged( KMMsgStatus oldStatus,
@@ -248,19 +250,23 @@
 
   void setMailingListPostAddress(const QString &address)
   { mMailingListPostingAddress = address; writeConfig(); }
-  const QString& mailingListPostAddress() const
+  QString mailingListPostAddress() const
   { return mMailingListPostingAddress; }
 
   void setMailingListAdminAddress(const QString &address)
   { mMailingListAdminAddress = address; writeConfig(); }
-  const QString& mailingListAdminAddress() const
+  QString mailingListAdminAddress() const
   { return mMailingListAdminAddress; }
 
   void setMailingListIdentity(const QString &identity)
   { mMailingListIdentity = identity; writeConfig(); }
-  const QString& mailingListIdentity() const
+  QString mailingListIdentity() const
   { return mMailingListIdentity; }
 
+  void setMarkAnyMessage( bool mark ) {
+      mMarkAnyMessage = mark;
+  }
+
   /** Tell the folder that a header field that is usually used for
     the index (subject, from, ...) has changed of given message.
     This method is usually called from within KMMessage::setSubject/set... */
@@ -397,6 +403,8 @@
   LockType mLockType;
   QString mProcmailLockFileName;
   bool mConvertToUtf8;
+
+  bool mMarkAnyMessage;
 };
 
 #endif /*kmfolder_h*/
Index: kmfolderdia.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfolderdia.cpp,v
retrieving revision 1.38
diff -u -u -r1.38 kmfolderdia.cpp
--- kmfolderdia.cpp	2001/04/25 11:39:05	1.38
+++ kmfolderdia.cpp	2001/04/27 15:51:20
@@ -110,10 +110,13 @@
 
   holdsMailingList = new QCheckBox( i18n("folder holds a mailing-list"), page);
   QObject::connect( holdsMailingList, SIGNAL(toggled(bool)),
-                    this, SLOT(slotHoldsML(bool)) );
+                    SLOT(slotHoldsML(bool)) );
 
   topLayout->addWidget(holdsMailingList);
 
+  markAnyMessage = new QCheckBox( i18n( "Mark Any Message in this folder" ), page );
+  topLayout->addWidget( markAnyMessage );
+
   QGridLayout *grid = new QGridLayout(page, 2, 2, 0, 8);
   grid->setColStretch(0, 1);
   grid->setColStretch(1, 100);
@@ -152,6 +155,7 @@
 //     mailingListAdminAddress->setEnabled(folder->isMailingList());
     mailingListIdentity->setEnabled(folder->isMailingList());
     holdsMailingList->setChecked(folder->isMailingList());
+    markAnyMessage->setChecked( folder->isAnyMessageMarked() );
 
     for (int i=0; i < mailingListIdentity->count(); ++i)
       if (mailingListIdentity->text(i) == folder->mailingListIdentity()) {
@@ -238,6 +242,7 @@
 //   folder->setMailingListAdminAddress( mailingListAdminAddress->text() );
     folder->setMailingListAdminAddress( QString::null );
     folder->setMailingListIdentity( mailingListIdentity->currentText() );
+    folder->setMarkAnyMessage( markAnyMessage->isChecked() );
   }
 
   KMFolderDialogInherited::slotOk();
Index: kmfolderdia.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfolderdia.h,v
retrieving revision 1.10
diff -u -u -r1.10 kmfolderdia.h
--- kmfolderdia.h	2001/04/24 11:22:28	1.10
+++ kmfolderdia.h	2001/04/27 15:51:20
@@ -36,7 +36,7 @@
   KMFolderDir* mFolderDir;
   QValueList<QGuardedPtr<KMFolder> > mFolders;
 
-  QCheckBox *holdsMailingList;
+  QCheckBox *holdsMailingList, *markAnyMessage;
   QLineEdit *mailingListPostAddress;
   QComboBox *mailingListIdentity;
 //   QLineEdit *mailingListAdminAddress;
Index: kmfoldertree.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfoldertree.cpp,v
retrieving revision 1.113
diff -u -u -r1.113 kmfoldertree.cpp
--- kmfoldertree.cpp	2001/04/24 11:22:28	1.113
+++ kmfoldertree.cpp	2001/04/27 15:51:21
@@ -42,6 +42,53 @@
 QPixmap* KMFolderTree::pixTr = 0;
 QPixmap* KMFolderTree::pixSent = 0;
 
+/* Construct the root item */
+KMFolderTreeItem::KMFolderTreeItem( QListView *parent,
+                    KMPaintInfo *aPaintInfo )
+    : QListViewItem( parent, i18n("Mail") ),
+      folder( 0 ),
+      mPaintInfo( aPaintInfo )
+{
+    init();
+}
+
+KMFolderTreeItem::KMFolderTreeItem( QListView *parent,
+                                    KMFolder* folder,
+                                    KMPaintInfo *aPaintInfo )
+    : QListViewItem( parent, i18n("Mail") ),
+      folder( folder ),
+      mPaintInfo( aPaintInfo )
+{
+    init();
+}
+
+/* Construct a child item */
+KMFolderTreeItem::KMFolderTreeItem( QListViewItem* parent,
+                                    KMFolder* _folder,
+                                    KMPaintInfo *aPaintInfo )
+    : QListViewItem( parent, (_folder) ? _folder->label() : QString::null ),
+      folder( _folder ),
+      mPaintInfo( aPaintInfo )
+{
+    init();
+}
+
+void KMFolderTreeItem::init()
+{
+    mImapState = imapNoInformation;
+    mCount = 0;
+    if ( !folder )
+        return;
+
+    // coolo - we need to keep the count here as long as it's not present
+    // if unopened
+    if ( folder->isAnyMessageMarked() ) {
+        folder->open();
+        mCount = folder->count();
+        folder->close();
+    }
+}
+
 //-----------------------------------------------------------------------------
 
 KMFolderTreeItem::~KMFolderTreeItem()
@@ -87,16 +134,21 @@
 
   QString t = text( column );
   if ( !t.isEmpty() ) {
-    if( folder && (folder->countUnreadRecursive() > 0) ) {
-      QFont f = p->font();
-      f.setWeight(QFont::Bold);
-      p->setFont(f);
+      if( folder ) {
+          int count = folder->isAnyMessageMarked() ?
+                      mCount :
+                      folder->countUnreadRecursive();
+          if ( count > 0 ) {
+              QFont f = p->font();
+              f.setWeight(QFont::Bold);
+              p->setFont(f);
+          }
     }
     QRect br;
     p->drawText( r, 0, width-marg-r, height(),
 		 align | AlignVCenter, t, -1, &br );
     if (!isSelected())
-      p->setPen( mPaintInfo->colUnread );
+        p->setPen( mPaintInfo->colUnread );
     if (column == 0)
       p->drawText( br.right(), 0, width-marg-br.right(), height(),
 		   align | AlignVCenter, unread );
@@ -190,7 +242,6 @@
   // Espen 2000-05-14: Getting rid of thick ugly frames
   setLineWidth(0);
 
-  mUpdateTimer = NULL;
   setSelectionMode( Extended );
 
   connect(this, SIGNAL(currentChanged(QListViewItem*)),
@@ -355,8 +406,7 @@
 //-----------------------------------------------------------------------------
 KMFolderTree::~KMFolderTree()
 {
-  disconnect(kernel->folderMgr(), SIGNAL(changed()), this, SLOT(doFolderListChanged()));
-  delete mUpdateTimer;
+    disconnect(kernel->folderMgr(), SIGNAL(changed()), this, SLOT(doFolderListChanged()));
 }
 
 //-----------------------------------------------------------------------------
@@ -516,14 +566,9 @@
 // Not really need anymore as count is cached in config file. But causes
 // a nice blink in the foldertree, that indicates kmail did something
 // when the user manually checks for mail and none was found.
-void KMFolderTree::refresh(KMFolder* )
+void KMFolderTree::refresh(KMFolder* f)
 {
-  if (!mUpdateTimer)
-  {
-    mUpdateTimer = new QTimer(this);
-    connect(mUpdateTimer, SIGNAL(timeout()), this, SLOT(delayedUpdate()));
-  }
-  mUpdateTimer->changeInterval(200);
+    QTimer::singleShot( 200, this, SLOT( delayedUpdate() ) );
 }
 
 //-----------------------------------------------------------------------------
@@ -543,18 +588,26 @@
       continue;
     }
 
+    if ( fti->folder->isAnyMessageMarked() ) { // update count too
+        fti->folder->open();
+        fti->mCount = fti->folder->count();
+        fti->folder->close();
+    }
     QString extendedName;
-    if (fti->folder->countUnread() > 0) {
-      QString num;
-	num.setNum(fti->folder->countUnread());
-      extendedName = " (" + num + ")";
-      if (!fti->folder->isSystemFolder())
-	fti->setPixmap( 0, *pixFull );
-    }
-    else {
-      extendedName = "";
-      if (!fti->folder->isSystemFolder())
-	fti->setPixmap( 0, *pixPlain );
+    int count =
+        fti->folder->isAnyMessageMarked() ?
+        fti->mCount :
+        fti->folder->countUnread();
+    if (count > 0) {
+        QString num;
+        num.setNum(count );
+        extendedName = " (" + num + ")";
+        if (!fti->folder->isSystemFolder())
+            fti->setPixmap( 0, *pixFull );
+    } else {
+        extendedName = "";
+        if (!fti->folder->isSystemFolder())
+            fti->setPixmap( 0, *pixPlain );
     }
 
     if (extendedName != fti->unread) {
@@ -563,11 +616,10 @@
     }
 
     if (upd && repaintRequired)
-      for (QListViewItem *p = fti; p; p = p->parent()) p->repaint();
+        for (QListViewItem *p = fti; p; p = p->parent()) p->repaint();
     ++it;
   }
   setUpdatesEnabled(upd);
-  mUpdateTimer->stop();
 }
 
 //-----------------------------------------------------------------------------
@@ -757,10 +809,15 @@
     if (fti->folder->account() && fti->mImapState
       != KMFolderTreeItem::imapInProgress)
         fti->folder->account()->getFolder(fti);
-    if (folder && (folder->countUnread() > 0) ) {
-      QString num;
-      num.setNum(folder->countUnread());
-      extendedName = " (" + num + ")";
+    if ( folder ) {
+        int count = folder->isAnyMessageMarked() ?
+                    fti->mCount :
+                    folder->countUnread();
+        if ( count > 0) {
+            QString num;
+            num.setNum(count);
+            extendedName = " (" + num + ")";
+        }
     }
     if (extendedName != fti->unread) {
       fti->unread = extendedName;
@@ -830,7 +887,7 @@
      if (!fti->folder->account())  // protect from imap folders
          folderMenu->insertItem(i18n("&Create Child Folder..."), this,
                                        SLOT(addChildFolder()));
-         folderMenu->insertItem(i18n("&Modify..."), topLevelWidget(),
+         folderMenu->insertItem(i18n("&Properties..."), topLevelWidget(),
                                       SLOT(slotModifyFolder()));
      }
   folderMenu->insertItem(i18n("C&ompact"), topLevelWidget(),
@@ -891,7 +948,7 @@
   if (fti->folder)
     if (!fti->folder->createChildFolder())
       return;
-  
+
   KMFolderDir *dir = &(kernel->folderMgr()->dir());
   if (fti->folder)
     dir = fti->folder->child();
Index: kmfoldertree.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfoldertree.h,v
retrieving revision 1.35
diff -u -u -r1.35 kmfoldertree.h
--- kmfoldertree.h	2001/04/16 21:31:03	1.35
+++ kmfoldertree.h	2001/04/27 15:51:21
@@ -15,53 +15,38 @@
 
 class KMFolderTreeItem : public QListViewItem
 {
- 
+
 public:
   KMFolder* folder;
   QString unread;
+  int mCount;
   KMPaintInfo *mPaintInfo;
   enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
   imapState mImapState;
- 
+
   /* Construct the root item */
   KMFolderTreeItem( QListView *parent,
-                    KMPaintInfo *aPaintInfo )
-    : QListViewItem( parent, i18n("Mail") ),
-      folder( 0 ),
-      unread( QString::null ),
-      mPaintInfo( aPaintInfo ),
-      mImapState( imapNoInformation )
-    {}
+                    KMPaintInfo *aPaintInfo );
   KMFolderTreeItem( QListView *parent,
                     KMFolder* folder,
-                    KMPaintInfo *aPaintInfo )
-    : QListViewItem( parent, i18n("Mail") ),
-      folder( folder ),
-      unread( QString::null ),
-      mPaintInfo( aPaintInfo ),
-      mImapState( imapNoInformation )
-    {}
- 
+                    KMPaintInfo *aPaintInfo );
   /* Construct a child item */
   KMFolderTreeItem( QListViewItem* parent,
                     KMFolder* folder,
-                    KMPaintInfo *aPaintInfo )
-    : QListViewItem( parent, (folder) ? folder->label() : QString::null ),
-      folder( folder ),
-      unread( QString::null ),
-      mPaintInfo( aPaintInfo ),
-      mImapState( imapNoInformation )
-    {}
- 
+                    KMPaintInfo *aPaintInfo );
+
+  // common to all constructors
+  void init();
+
   virtual ~KMFolderTreeItem();
-  void paintBranches( QPainter * p, const QColorGroup & cg,
+  virtual void paintBranches( QPainter * p, const QColorGroup & cg,
                       int w, int y, int h, GUIStyle s )
   {
     QListViewItem::paintBranches( p, cg, w, y, h, s);
   }
 
-  void paintCell( QPainter * p, const QColorGroup & cg,
-                  int column, int width, int align ); 
+  virtual void paintCell( QPainter * p, const QColorGroup & cg,
+                  int column, int width, int align );
   virtual QString key( int, bool ) const;
 };
 
@@ -192,7 +177,6 @@
   void writeIsListViewItemOpen(KMFolderTreeItem *fti);
 
   KMFolderNodeList mList;
-  QTimer* mUpdateTimer;
   static QPixmap *pixDir, *pixNode, *pixPlain, *pixFld, *pixFull, *pixIn,
     *pixOut, *pixTr, *pixSent;
 
Index: kmkernel.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmkernel.cpp,v
retrieving revision 1.44
diff -u -u -r1.44 kmkernel.cpp
--- kmkernel.cpp	2001/04/22 12:36:25	1.44
+++ kmkernel.cpp	2001/04/27 15:51:22
@@ -403,6 +403,7 @@
   the_outboxFolder->setType("Out");
   the_outboxFolder->setWhoField("To");
   the_outboxFolder->setSystemFolder(TRUE);
+  the_outboxFolder->setMarkAnyMessage( TRUE );
   the_outboxFolder->open();
 
   the_sentFolder = the_folderMgr->findOrCreate(cfg->readEntry("sentFolder", "sent-mail"));

_______________________________________________
Kmail Developers mailing list
Kmail@master.kde.org
http://master.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