[kde-doc-english] [trojita] src/Gui: GUI: Inhibit auto-mark-read after toggling the state manually
Jan Kundrát
jkt at flaska.net
Wed Nov 6 10:13:50 UTC 2013
Git commit dd6c93767ac941480e30a41d9a9ced59520dc2d3 by Jan Kundrát.
Committed on 04/11/2013 at 20:27.
Pushed by jkt into branch 'master'.
GUI: Inhibit auto-mark-read after toggling the state manually
The point of this patch is to make sure that a quick press of "M" immediately
after hitting the up/down arrow key will abort the delayed "let's make current
message as read" feature.
This stuff has to be done in a slightly complicated way due to way how shortcuts
are implemented in Qt. The shortcut receives the key information *prior* to the
target widget's keyReleaseEvent; the keyPressEvent is actually eaten by the
QAction's shortcut handler.
However, we can still listen to the QEvent::ShortcutOverride which is processed
prior to QAction. This patch therefore configures the widget so that if it
detects that any other key than those in the "delay any action for these" group
has been pressed, the delay is immediately cut and the action is performed.
On top of that, the actual inhibition of the auto-mark-as-read timer can be
trivially implemented. The ihibiting is only active when the "current message"
as defined by the listing matches the "current message" as defined by the
message viewer.
REVIEW: 113669
M +11 -0 src/Gui/MessageView.cpp
M +1 -0 src/Gui/MessageView.h
M +12 -0 src/Gui/MsgListView.cpp
M +2 -2 src/Gui/MsgListView.h
M +7 -0 src/Gui/Window.cpp
http://commits.kde.org/trojita/dd6c93767ac941480e30a41d9a9ced59520dc2d3
diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index b26cddc..f3361d3 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -263,6 +263,17 @@ void MessageView::markAsRead()
model->markMessagesRead(QModelIndexList() << message, Imap::Mailbox::FLAG_ADD);
}
+/** @short Inhibit the automatic marking of the current message as already read
+
+The user might have e.g. explicitly marked a previously read message as unread again immediately after navigating back to it
+in the message listing. In that situation, the message viewer shall respect this decision and inhibit the helper which would
+otherwise mark the current message as read after a short timeout.
+*/
+void MessageView::stopAutoMarkAsRead()
+{
+ markAsReadTimer->stop();
+}
+
bool MessageView::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::Wheel) {
diff --git a/src/Gui/MessageView.h b/src/Gui/MessageView.h
index 9e0ff53..b5ee2ed 100644
--- a/src/Gui/MessageView.h
+++ b/src/Gui/MessageView.h
@@ -76,6 +76,7 @@ public slots:
void setMessage(const QModelIndex &index);
void setEmpty();
void setHomepageUrl(const QUrl &homepage);
+ void stopAutoMarkAsRead();
protected:
void showEvent(QShowEvent *se);
private slots:
diff --git a/src/Gui/MsgListView.cpp b/src/Gui/MsgListView.cpp
index 049084d..0c3074d 100644
--- a/src/Gui/MsgListView.cpp
+++ b/src/Gui/MsgListView.cpp
@@ -91,6 +91,18 @@ void MsgListView::keyReleaseEvent(QKeyEvent *ke)
QTreeView::keyReleaseEvent(ke);
}
+bool MsgListView::event(QEvent *event)
+{
+ if (event->type() == QEvent::ShortcutOverride
+ && !gs_naviActivationBlockers.contains(static_cast<QKeyEvent*>(event)->key())
+ && m_naviActivationTimer->isActive()) {
+ // Make sure that the delayed timer is broken ASAP when the key looks like something which might possibly be a shortcut
+ m_naviActivationTimer->stop();
+ slotCurrentActivated();
+ }
+ return QTreeView::event(event);
+}
+
void MsgListView::slotCurrentActivated()
{
if (currentIndex().isValid() && m_autoActivateAfterKeyNavigation) {
diff --git a/src/Gui/MsgListView.h b/src/Gui/MsgListView.h
index b875374..1305039 100644
--- a/src/Gui/MsgListView.h
+++ b/src/Gui/MsgListView.h
@@ -33,8 +33,7 @@ class PrettyMsgListModel;
}
}
-namespace Gui
-{
+namespace Gui {
/** @short A slightly tweaked QTreeView optimized for showing a list of messages in one mailbox
@@ -57,6 +56,7 @@ protected:
void keyPressEvent(QKeyEvent *ke);
void keyReleaseEvent(QKeyEvent *ke);
virtual void startDrag(Qt::DropActions supportedActions);
+ bool event(QEvent *event);
private slots:
void slotFixSize();
/** @short Expand all items below current root index */
diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp
index 2021501..d04677c 100644
--- a/src/Gui/Window.cpp
+++ b/src/Gui/Window.cpp
@@ -942,6 +942,10 @@ void MainWindow::msgListClicked(const QModelIndex &index)
Imap::Mailbox::FlagsOperation flagOp = translated.data(Imap::Mailbox::RoleMessageIsMarkedRead).toBool() ?
Imap::Mailbox::FLAG_REMOVE : Imap::Mailbox::FLAG_ADD;
model->markMessagesRead(QModelIndexList() << translated, flagOp);
+
+ if (translated == m_messageWidget->messageView->currentMessage()) {
+ m_messageWidget->messageView->stopAutoMarkAsRead();
+ }
} else {
if (m_messageWidget->isVisible() && !m_messageWidget->size().isEmpty()) {
// isVisible() won't work, the splitter manipulates width, not the visibility state
@@ -1263,6 +1267,9 @@ void MainWindow::handleMarkAsRead(bool value)
model->markMessagesRead(translatedIndexes, Imap::Mailbox::FLAG_ADD);
else
model->markMessagesRead(translatedIndexes, Imap::Mailbox::FLAG_REMOVE);
+ if (translatedIndexes.contains(m_messageWidget->messageView->currentMessage())) {
+ m_messageWidget->messageView->stopAutoMarkAsRead();
+ }
}
}
More information about the kde-doc-english
mailing list