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

List:       kmail-devel
Subject:    Re: New action: move to next unread message or folder
From:       David Smith <dsmih () algonet ! se>
Date:       2003-07-17 23:59:13
[Download RAW message or body]

On Thursday 17 July 2003 00.20, Ingo Klöcker wrote:
> On Wednesday 16 July 2003 21:09, David Smith wrote:
> > I just started to use KMail and this is a feature I was missing. An
> > action that sort of combines "Next unread message" and "Next unread
> > text", that is, goes to the next unread message but continues to the
> > next folder.
> >
> Instead of adding another action we should simply make the strategy for
> "Next unread message" configurable. We already have the option
> [ ] Loop in the current folder when trying to find unread messages
>
> This could be replaced with a combo box with the options:
>
> When trying to find unread messages:
> - Don't loop
> - Loop in the current folder
> - Loop over all folders
>

Hmm, ok, how about this patch then? It's a bit more intrusive, but it does 
exactly that. It applies to previous and next unread message and also to 
"next unread text" (i.e. if you anything but loop over all folders, "next 
unread text" will be different. I wasn't sure about that one, but it seemed 
right to me.)

/David

["loop_on_goto_unread.diff" (text/x-diff)]

Index: configuredialog.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/configuredialog.cpp,v
retrieving revision 1.376
diff -u -r1.376 configuredialog.cpp
--- configuredialog.cpp	12 Jul 2003 16:05:59 -0000	1.376
+++ configuredialog.cpp	17 Jul 2003 23:37:21 -0000
@@ -3574,10 +3574,22 @@
   mWarnBeforeExpire =
     new QCheckBox( i18n("&Warn before expiring messages"), this );
   vlay->addWidget( mWarnBeforeExpire );
-  mLoopOnGotoUnread =
-    new QCheckBox( i18n("&Loop in the current folder when trying to find "
-			"unread messages"), this );
-  vlay->addWidget( mLoopOnGotoUnread );
+  // "when trying to find unread messages" combo + label: stretch 0
+  hlay = new QHBoxLayout( vlay ); // inherits spacing
+  mLoopOnGotoUnread = new QComboBox( false, this );
+  label = new QLabel( mLoopOnGotoUnread,
+           i18n("to be continued with \"don't loop\", \"loop in current folder\", "
+                "and \"loop in all folders\".",
+                "When trying to find unread messages:"), this );
+  mLoopOnGotoUnread->insertStringList( QStringList()
+      << i18n("continuation of \"When trying to find unread messages:\"",
+              "Don't loop")
+      << i18n("continuation of \"When trying to find unread messages:\"",
+              "Loop in current folder")
+      << i18n("continuation of \"When trying to find unread messages:\"",
+              "Loop in all folders"));
+  hlay->addWidget( label );
+  hlay->addWidget( mLoopOnGotoUnread, 1 );
   mJumpToUnread =
     new QCheckBox( i18n("&Jump to first unread message when entering a "
 			"folder"), this );
@@ -3654,13 +3666,18 @@
   QWhatsThis::add( label, msg );
 
   msg = i18n( "what's this help",
-	      "<qt><p>When jumping to the next unread message, it may occur "
-	      "that no more unread messages are below the current message.</p>"
-	      "<p>When this option is checked, the search will start at the "
-	      "top of the message list. Otherwise, it will do nothing.</p>"
-	      "<p>Similarly, when searching for the previous unread message, "
-	      "the search will start from the bottom of the message list if "
-	      "this option is checked.</p></qt>" );
+	    "<qt><p>When jumping to the next unread message, it may occur "
+	    "that no more unread messages are below the current message.</p>"
+	    "<p><b>Don't loop:</b> The search will stop at the last message in "
+	    "the current folder.</p>"
+	    "<p><b>Loop in current folder:</b> The search will continue at the "
+	    "top of the message list, but not go to another folder.</p>"
+	    "<p><b>Loop in all folders:</b> The search will continue at the top of "
+	    "the message list. If no unread messages are found it will then continue "
+	    "to the next folder.</p>"
+	    "<p>Similarly, when searching for the previous unread message, "
+	    "the search will start from the bottom of the message list and continue to "
+	    "the previous folder depeding on which option is selected.</p></qt>" );
   QWhatsThis::add( mLoopOnGotoUnread, msg );
 }
 
@@ -3675,7 +3692,8 @@
 						  kernel->inboxFolder()->idString() ) );
   mCompactOnExitCheck->setChecked( general.readBoolEntry( "compact-all-on-exit", \
true ) );  mEmptyFolderConfirmCheck->setChecked( general.readBoolEntry( \
                "confirm-before-empty", true ) );
-  mLoopOnGotoUnread->setChecked( behaviour.readBoolEntry( "LoopOnGotoUnread", true ) \
); +  // default = "Loop in current folder"
+  mLoopOnGotoUnread->setCurrentItem( behaviour.readNumEntry( "LoopOnGotoUnread", 1 ) \
);  mJumpToUnread->setChecked( behaviour.readBoolEntry( "JumpToUnread", false ) );
   mDelayedMarkAsRead->setChecked( behaviour.readBoolEntry( "DelayedMarkAsRead", true \
) );  mDelayedMarkTime->setValue( behaviour.readNumEntry( "DelayedMarkTime", 0 ) );
@@ -3697,7 +3715,7 @@
   general.writeEntry( "warn-before-expire", mWarnBeforeExpire->isChecked() );
   general.writeEntry( "startupFolder", mOnStartupOpenFolder->getFolder() ?
 				  mOnStartupOpenFolder->getFolder()->idString() : QString::null );
-  behaviour.writeEntry( "LoopOnGotoUnread", mLoopOnGotoUnread->isChecked() );
+  behaviour.writeEntry( "LoopOnGotoUnread", mLoopOnGotoUnread->currentItem() );
   behaviour.writeEntry( "JumpToUnread", mJumpToUnread->isChecked() );
   behaviour.writeEntry( "DelayedMarkAsRead", mDelayedMarkAsRead->isChecked() );
   behaviour.writeEntry( "DelayedMarkTime", mDelayedMarkTime->value() );
Index: configuredialog_p.h
===================================================================
RCS file: /home/kde/kdepim/kmail/configuredialog_p.h,v
retrieving revision 1.62
diff -u -r1.62 configuredialog_p.h
--- configuredialog_p.h	27 May 2003 13:58:58 -0000	1.62
+++ configuredialog_p.h	17 Jul 2003 23:37:21 -0000
@@ -858,7 +858,7 @@
 protected:
   QCheckBox    *mEmptyFolderConfirmCheck;
   QCheckBox    *mWarnBeforeExpire;
-  QCheckBox    *mLoopOnGotoUnread;
+  QComboBox    *mLoopOnGotoUnread;
   QCheckBox    *mJumpToUnread;
   QComboBox    *mMailboxPrefCombo;
   QCheckBox    *mCompactOnExitCheck;
Index: kmheaders.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmheaders.cpp,v
retrieving revision 1.521
diff -u -r1.521 kmheaders.cpp
--- kmheaders.cpp	17 Jul 2003 22:13:12 -0000	1.521
+++ kmheaders.cpp	17 Jul 2003 23:37:21 -0000
@@ -681,7 +681,8 @@
   // Behavior
   {
     KConfigGroupSaver saver(config, "Behaviour");
-    mLoopOnGotoUnread = config->readBoolEntry( "LoopOnGotoUnread", true );
+    mLoopOnGotoUnread = (LoopOnGotoUnreadValue)config->readNumEntry(
+            "LoopOnGotoUnread", LoopInCurrentFolder );
     mJumpToUnread = config->readBoolEntry( "JumpToUnread", false );
   }
 }
@@ -1876,18 +1877,21 @@
 }
 
 //-----------------------------------------------------------------------------
-void KMHeaders::nextUnreadMessage(bool acceptCurrent)
+bool KMHeaders::nextUnreadMessage(bool acceptCurrent)
 {
-  if ( !mFolder->countUnread() ) return;
+  if ( !mFolder || !mFolder->countUnread() ) return false;
   int i = findUnread(TRUE, -1, false, acceptCurrent);
-  if ( i < 0 && mLoopOnGotoUnread )
+  if ( i < 0 && mLoopOnGotoUnread != DontLoop )
   {
     KMHeaderItem * first = static_cast<KMHeaderItem*>(firstChild());
     if ( first )
       i = findUnread(TRUE, first->msgId(), false, acceptCurrent); // from top
   }
+  if ( i < 0 )
+    return false;
   setCurrentMsg(i);
   ensureCurrentItemVisible();
+  return true;
 }
 
 void KMHeaders::ensureCurrentItemVisible()
@@ -1898,17 +1902,20 @@
 }
 
 //-----------------------------------------------------------------------------
-void KMHeaders::prevUnreadMessage()
+bool KMHeaders::prevUnreadMessage()
 {
-  if ( !mFolder->countUnread() ) return;
+  if ( !mFolder || !mFolder->countUnread() ) return false;
   int i = findUnread(FALSE);
-  if ( i < 0 && mLoopOnGotoUnread ) {
+  if ( i < 0 && mLoopOnGotoUnread != DontLoop ) {
     KMHeaderItem * last = static_cast<KMHeaderItem*>(lastItem());
     if ( last )
       i = findUnread(FALSE, last->msgId() ); // from bottom
   }
+  if ( i < 0 )
+    return false;
   setCurrentMsg(i);
   ensureCurrentItemVisible();
+  return true;
 }
 
 
Index: kmheaders.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmheaders.h,v
retrieving revision 1.127
diff -u -r1.127 kmheaders.h
--- kmheaders.h	6 Jul 2003 19:16:06 -0000	1.127
+++ kmheaders.h	17 Jul 2003 23:37:21 -0000
@@ -27,6 +27,7 @@
 typedef QValueList<Q_UINT32> SerNumList;
 typedef QMap<int,KMFolder*> KMMenuToFolder;
 enum NestingPolicy { AlwaysOpen = 0, DefaultOpen, DefaultClosed, OpenUnread };
+enum LoopOnGotoUnreadValue { DontLoop = 0, LoopInCurrentFolder, LoopInAllFolders };
 
 /** The widget that shows the contents of folders */
 #define KMHeadersInherited KListView
@@ -134,8 +135,11 @@
     is unset. */
   virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool \
acceptCurrent = false);  
-  void highlightMessage(QListViewItem*, bool markitread);
+  /** Return the config option LoopOnGotoUnread */
+  LoopOnGotoUnreadValue loopOnGotoUnread() { return mLoopOnGotoUnread; }
 
+  void highlightMessage(QListViewItem*, bool markitread);
+  
   /** return a string relativ to the current time */
   static QString fancyDate( time_t otime );
 
@@ -183,10 +187,12 @@
   void prevMessage();
   /** Same as prevMessage() but don't clear the current selection */
   void selectPrevMessage();
-  /** Make the nextUnread message header visible scrolling if necessary */
-  void nextUnreadMessage(bool acceptCurrent = false);
-  /** Make the previous message header visible scrolling if necessary */
-  void prevUnreadMessage();
+  /** Make the nextUnread message header visible scrolling if necessary, returning 
+    true if an unread message is found */
+  bool nextUnreadMessage(bool acceptCurrent = false);
+  /** Make the previous message header visible scrolling if necessary, returning
+    true if an unread message is found */
+  bool prevUnreadMessage();
   /** Don't show a drag cursor */
   void slotNoDrag();
   /** timer function to set the current time regularly */
@@ -350,7 +356,7 @@
 
   KMime::DateFormatter mDate;
   /** value of config key Behaviour/LoopOnGotoUnread */
-  bool mLoopOnGotoUnread;
+  LoopOnGotoUnreadValue mLoopOnGotoUnread;
   bool mJumpToUnread;
 
   /** popup to switch columns */
Index: kmmainwidget.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmmainwidget.cpp,v
retrieving revision 1.64
diff -u -r1.64 kmmainwidget.cpp
--- kmmainwidget.cpp	17 Jul 2003 22:13:13 -0000	1.64
+++ kmmainwidget.cpp	17 Jul 2003 23:37:21 -0000
@@ -1715,12 +1715,22 @@
 
 //-----------------------------------------------------------------------------
 void KMMainWidget::slotNextMessage()       { mHeaders->nextMessage(); }
-void KMMainWidget::slotNextUnreadMessage() { mHeaders->nextUnreadMessage(); }
+void KMMainWidget::slotNextUnreadMessage()
+{
+  if ( !mHeaders->nextUnreadMessage() )
+    if ( mHeaders->loopOnGotoUnread() == LoopInAllFolders )
+      mFolderTree->nextUnreadFolder(true);
+}
 void KMMainWidget::slotNextImportantMessage() {
   //mHeaders->nextImportantMessage();
 }
 void KMMainWidget::slotPrevMessage()       { mHeaders->prevMessage(); }
-void KMMainWidget::slotPrevUnreadMessage() { mHeaders->prevUnreadMessage(); }
+void KMMainWidget::slotPrevUnreadMessage()
+{ 
+  if ( !mHeaders->prevUnreadMessage() )
+    if ( mHeaders->loopOnGotoUnread() == LoopInAllFolders )
+      mFolderTree->prevUnreadFolder();
+}
 void KMMainWidget::slotPrevImportantMessage() {
   //mHeaders->prevImportantMessage();
 }
@@ -2463,15 +2473,7 @@
         mMsgView->slotJumpDown();
         return;
     }
-    int i = mHeaders->findUnread(true, -1, false, false);
-    if ( i < 0 ) // let's try from start, what gives?
-        i = mHeaders->findUnread(true, 0, false, true);
-    if ( i >= 0 ) {
-         mHeaders->setCurrentMsg(i);
-         mHeaders->ensureCurrentItemVisible();
-         return;
-    }
-    mFolderTree->nextUnreadFolder( true );
+    slotNextUnreadMessage();
 }
 
 void KMMainWidget::slotNextUnreadFolder() {
@@ -2611,10 +2613,11 @@
     viewSourceAction()->setEnabled( single_actions );
 
     bool mails = mFolder && mFolder->count();
+    bool enable_goto_unread = mails || (mHeaders->loopOnGotoUnread() == \
LoopInAllFolders);  actionCollection()->action( "go_next_message" )->setEnabled( \
                mails );
-    actionCollection()->action( "go_next_unread_message" )->setEnabled( mails );
+    actionCollection()->action( "go_next_unread_message" )->setEnabled( \
enable_goto_unread );  actionCollection()->action( "go_prev_message" )->setEnabled( \
                mails );
-    actionCollection()->action( "go_prev_unread_message" )->setEnabled( mails );
+    actionCollection()->action( "go_prev_unread_message" )->setEnabled( \
                enable_goto_unread );
     actionCollection()->action( "send_queued" )->setEnabled( \
kernel->outboxFolder()->count() > 0 );  if (action( "edit_undo" ))
       action( "edit_undo" )->setEnabled( mHeaders->canUndo() );



_______________________________________________
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