diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 179 | ||||
| -rw-r--r-- | src/mainwindow.h | 44 | ||||
| -rw-r--r-- | src/messageview.cpp | 86 | ||||
| -rw-r--r-- | src/messageview.h | 37 | ||||
| -rw-r--r-- | src/threaddashboard.cpp | 3 |
5 files changed, 348 insertions, 1 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4cce042..321c608 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -69,6 +69,7 @@ #include "pendingchangesdialog.h" #include "savequerydialog.h" #include "tagrulesdialog.h" +#include "threaddashboard.h" #include "threadlistmodel.h" #include "threadlistview.h" #include "version.h" @@ -960,6 +961,44 @@ void MainWindow::buildUi() connect(m_messageView, &MessageView::searchRequested, this, &MainWindow::runSearchFromPane); + // The conversation dashboard (item 177). Its colours are the application's + // own, so the strip it holds reads the same table every other chip does. + ThreadDashboard *dashboard = m_messageView->dashboard(); + dashboard->setTagColors(&m_tagColors); + + // An unread entry is a way INTO the conversation: expand the thread and + // select that message, which is the ordinary gesture rather than a second + // way to open a message. + connect(dashboard, &ThreadDashboard::messageActivated, + this, &MainWindow::selectMessageInCurrentThread); + + // The "+N more" link. The full list already lives in the left pane, so + // this expands the thread there and leaves the selection alone. + connect(dashboard, &ThreadDashboard::expandRequested, this, [this]() { + const QModelIndex current = m_threadView->currentIndex(); + if (current.isValid() && !m_model->isMessageRow(current)) + m_threadView->expand(current); + }); + + // The three buttons TRIGGER the existing actions rather than reimplement + // them. Those actions already resolve their scope from the selection, and + // a conversation row resolves to the whole conversation, which is exactly + // what a button on this pane means. A second path to the same write is the + // mistake the deleted "Whole thread" submenu made. + // + // Looked up at emit time: registerActions() runs after buildUi(), so the + // map is empty here. + const auto triggerAction = [this](const QString &name) { + if (QAction *action = m_actions.value(name)) + action->trigger(); + }; + connect(dashboard, &ThreadDashboard::markAllReadRequested, this, + [triggerAction]() { triggerAction(QStringLiteral("mark_all_read")); }); + connect(dashboard, &ThreadDashboard::archiveRequested, this, + [triggerAction]() { triggerAction(QStringLiteral("archive")); }); + connect(dashboard, &ThreadDashboard::deleteRequested, this, + [triggerAction]() { triggerAction(QStringLiteral("delete")); }); + m_splitter = new QSplitter(Qt::Horizontal, central); m_splitter->addWidget(m_threadView); m_splitter->addWidget(m_messageView); @@ -2558,6 +2597,8 @@ void MainWindow::wireWorker() this, &MainWindow::onThreadTreeLoaded); connect(m_worker, &NotmuchWorker::messageLoaded, this, &MainWindow::onMessageLoaded); + connect(m_worker, &NotmuchWorker::threadDigestLoaded, + this, &MainWindow::onThreadDigestLoaded); connect(m_worker, &NotmuchWorker::errorOccurred, this, &MainWindow::onWorkerError); connect(m_worker, &NotmuchWorker::allTagsReady, @@ -4063,6 +4104,52 @@ void MainWindow::onThreadSelected(const QModelIndex ¤t, m_currentThreadId = thread.threadId; m_messageView->setTags(thread.tags); + // A CONVERSATION row stands for the whole thread, so there is no single + // message to render and the pane shows the conversation instead (item + // 177). A thread of one message is not a conversation and falls through to + // the message path below, which is the case the whole split protects: it + // must still open on one click. + if (m_model->isConversationRow(current)) { + // No mark-read, deliberately: the row displays nothing, so there is no + // message the user can be said to have read. Any timer armed for the + // row they came from is still cancelled. + m_markReadTimer->stop(); + m_markReadMessageId.clear(); + + m_currentMessageId.clear(); + m_currentMessageThreadId.clear(); + + m_dashboardThreadId = thread.threadId; + + // The heading before the round trip, not after it: the subject, the + // account and the tags are already on the summary, and the digest + // carries none of them. Waiting would show an empty heading for as + // long as the worker takes. + m_messageView->setDashboardThread( + thread.subject, + m_model->data(current, ThreadListModel::AccountLabelRole).toString(), + thread.tags); + + // Empty for now, so the pane switches at once rather than staying on + // the previous message until the digest lands. + ThreadDigest pending; + pending.threadId = thread.threadId; + pending.totalCount = thread.totalCount; + m_messageView->showDashboard(pending); + + // Its OWN generation. m_generation is the query's, and bumping that + // discards any thread load in flight and blanks the pane, which is the + // opposite of what selecting a row should do. + ++m_digestGeneration; + QMetaObject::invokeMethod(m_worker, "loadThreadDigest", + Qt::QueuedConnection, + Q_ARG(QString, thread.threadId), + Q_ARG(quint64, m_digestGeneration)); + return; + } + + m_dashboardThreadId.clear(); + // The message the card displays, not the thread. The summary's `unread` is // a union over the conversation, so this can arm for a thread whose first // message is already read; the write is scoped to that message either way, @@ -4100,6 +4187,32 @@ void MainWindow::onThreadSelected(const QModelIndex ¤t, Q_ARG(quint64, m_generation)); } +void MainWindow::onThreadDigestLoaded(const ThreadDigest &digest, + quint64 generation) +{ + // Three guards, and each one covers a different way the answer can outlive + // the selection that asked for it. loadThreadDigest crosses on a queued + // connection, so all of them are reachable by moving the selection while + // one is in flight. + // + // Superseded by a later request: the user moved to another conversation. + if (generation != m_digestGeneration) + return; + + // The pane is no longer showing a dashboard at all: it was blanked, or a + // message row was selected. Every route that renders a message switches + // the stack back, so this is the question rather than a flag of our own. + if (!m_messageView->showingDashboard()) + return; + + // And it is showing a DIFFERENT conversation. The generation guard alone + // would let this through if a request were ever made without bumping it. + if (digest.threadId != m_dashboardThreadId) + return; + + m_messageView->showDashboard(digest); +} + void MainWindow::onMessageLoaded(const QVector<MessageRef> &messages, quint64 generation) { @@ -4217,6 +4330,9 @@ void MainWindow::onThreadTreeLoaded(const QVector<MessageNode> &nodes, // A stale-thread recovery waits for exactly this: the message it wants to // select does not exist as a row until the replies land. applyPendingRecovery(); + + // And so does a dashboard entry, for the same reason. + applyPendingDashboardSelection(); } void MainWindow::renderMessages(const QVector<MessageRef> &messages) @@ -4761,6 +4877,69 @@ void MainWindow::onRowDoubleClicked(const QModelIndex &index) recoverStaleThread(threadId, messageId); } +void MainWindow::selectMessageInCurrentThread(const QString &messageId) +{ + if (messageId.isEmpty()) + return; + + const QModelIndex current = m_threadView->currentIndex(); + if (!current.isValid() || m_model->isMessageRow(current)) + return; + + // Expanded FIRST, and unconditionally: this is also what asks the worker + // for the replies, so a collapsed thread has no row to select yet. + m_threadView->expand(current); + + m_dashboardSelectThreadId = m_model->threadFor(current).threadId; + m_dashboardSelectMessageId = messageId; + applyPendingDashboardSelection(); +} + +void MainWindow::applyPendingDashboardSelection() +{ + if (m_dashboardSelectMessageId.isEmpty()) + return; + + for (int row = 0; row < m_model->rowCount(QModelIndex()); ++row) { + const QModelIndex thread = m_model->index(row, 0, QModelIndex()); + if (m_model->threadAt(row).threadId != m_dashboardSelectThreadId) + continue; + + // The thread's first message is the ROOT row, not a child: + // setThreadMessages drops depth 0 because the root stands for it, so + // looking for it among the children finds nothing. + if (m_model->data(thread, ThreadListModel::MessageIdRole).toString() + == m_dashboardSelectMessageId) { + selectRowAt(thread); + m_dashboardSelectMessageId.clear(); + m_dashboardSelectThreadId.clear(); + return; + } + + for (int child = 0; child < m_model->rowCount(thread); ++child) { + const QModelIndex reply = m_model->index(child, 0, thread); + if (m_model->messageAt(reply).messageId + != m_dashboardSelectMessageId) + continue; + selectRowAt(reply); + m_dashboardSelectMessageId.clear(); + m_dashboardSelectThreadId.clear(); + return; + } + + // The replies have not arrived. The target stays remembered and + // onThreadTreeLoaded() runs this again when they do; the selection is + // deliberately left where it is until then, so the dashboard the user + // clicked from stays on screen rather than flashing to something else. + return; + } + + // The thread is not in the list at all, which the query having moved on + // would produce. Nothing to select, and nothing to keep waiting for. + m_dashboardSelectMessageId.clear(); + m_dashboardSelectThreadId.clear(); +} + void MainWindow::applyPendingRecovery() { if (m_recoverThreadId.isEmpty()) diff --git a/src/mainwindow.h b/src/mainwindow.h index 11f35e7..16bf8c4 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -41,6 +41,7 @@ #include "tagrules.h" #include "syncmonitor.h" #include "tagcolors.h" +#include "threaddigest.h" #include "types.h" // Held by value: the parsed business-senders list is a member, and the load is @@ -585,6 +586,22 @@ private slots: /// Selects the remembered message once its thread's rows have loaded. void applyPendingRecovery(); + + /// Selects \p messageId inside the currently selected conversation, + /// expanding it first (item 177). + /// + /// For the dashboard's unread entries. Deliberately NOT recoverStaleThread(), + /// which runs thread:<id> as a new query: the thread is already in the list + /// the user is looking at, and replacing that list to reach a row it + /// already holds would throw away the view they came from. + /// + /// A reply row does not exist until the expansion's replies arrive, so the + /// target is remembered and applied again when they do. + void selectMessageInCurrentThread(const QString &messageId); + + /// Applies a pending selectMessageInCurrentThread() target, if any. + void applyPendingDashboardSelection(); + void onThreadsReady(const QVector<ThreadSummary> &threads, quint64 generation); void onQueryFinished(int total, quint64 generation); void onThreadSelected(const QModelIndex ¤t, const QModelIndex &previous); @@ -609,6 +626,15 @@ private slots: /// Renders the single message a message row asked for. void onMessageLoaded(const QVector<MessageRef> &messages, quint64 generation); + + /// Fills the conversation dashboard once the worker has read the digest. + /// + /// Guarded the way onMessageLoaded() is, and for the same reason: the + /// request crosses on a queued connection, so the answer arrives after + /// whatever the user did in the meantime. A digest for a thread the pane + /// has moved off, or one that arrives once the pane is showing a message, + /// must not repaint anything. + void onThreadDigestLoaded(const ThreadDigest &digest, quint64 generation); void onWorkerError(const QString &message); void onSyncFinished(bool success, int exitCode); @@ -1601,6 +1627,24 @@ private: QString m_lastQuery; QString m_currentThreadId; + /// The digest request's own generation, bumped per request. + /// + /// Separate from m_generation, which is the QUERY generation: bumping that + /// one discards any thread load in flight and blanks the pane, so a + /// selection asking for a digest would cancel the work the selection + /// itself started. + quint64 m_digestGeneration = 0; + + /// The thread the dashboard is showing, empty whenever it is not showing. + /// A late digest is matched against this, not against m_currentThreadId, + /// which is also set for a thread of one message that renders normally. + QString m_dashboardThreadId; + + /// The message a dashboard entry asked for and the thread it is in, both + /// empty when nothing is waiting. See selectMessageInCurrentThread(). + QString m_dashboardSelectMessageId; + QString m_dashboardSelectThreadId; + /// The message a MESSAGE row is showing, empty whenever the pane holds a /// whole thread. The two are mutually exclusive and each clears the other, /// so a late reply can tell which kind of selection it belongs to. diff --git a/src/messageview.cpp b/src/messageview.cpp index eb0dccd..7106ab5 100644 --- a/src/messageview.cpp +++ b/src/messageview.cpp @@ -31,6 +31,7 @@ #include <QMenu> #include <QMouseEvent> #include <QPushButton> +#include <QStackedWidget> #include <QStandardPaths> #include <QtNumeric> #include <QResizeEvent> @@ -57,6 +58,7 @@ #include "searchterm.h" #include "tagstrip.h" #include "threadcidmap.h" +#include "threaddashboard.h" #include "version.h" namespace { @@ -444,6 +446,11 @@ MessageView::MessageView(QWidget *parent) // Tags live under the message rather than in the thread list, where // spelling them out cost most of the list's width. m_tagStrip = new TagStrip(this); + // Named because the pane now holds TWO strips: this one, under the + // message, and the dashboard's, under the conversation heading. An + // unqualified findChild<TagStrip *>() cannot tell them apart, and which + // one it happens to return is an ordering accident. + m_tagStrip->setObjectName(QStringLiteral("messageTagStrip")); m_tagStrip->hide(); // Item 85: a tag chip is searchable. The strip reports which chip was hit @@ -475,7 +482,12 @@ MessageView::MessageView(QWidget *parent) // Left at the style's own default until then, which is what a MessageView // built on its own in a test gets. - auto *layout = new QVBoxLayout(this); + // Everything above belongs to ONE of the pane's two faces. The message + // page carries it; the dashboard is the other page of the stack. + m_messagePage = new QWidget(this); + m_messagePage->setObjectName(QStringLiteral("messagePage")); + auto *layout = new QVBoxLayout(m_messagePage); + layout->setContentsMargins(0, 0, 0, 0); layout->addLayout(headerRow); layout->addWidget(m_blockedBar); layout->addWidget(m_receiveOnlyRibbon); @@ -489,6 +501,27 @@ MessageView::MessageView(QWidget *parent) layout->addWidget(m_attachmentBar); layout->addWidget(m_tagStrip); + m_dashboard = new ThreadDashboard(this); + + // A QStackedWidget takes the LARGEST minimum of its pages, so the hidden + // dashboard would set the floor for the whole pane: its three action + // buttons side by side measured 395px, against the 300px MainWindow asks + // for, and a floor the pane cannot go under is a floor that squeezes the + // thread list instead. The dashboard already scrolls, so letting it be + // narrower than its natural width costs nothing it does not already + // handle. + m_dashboard->setMinimumWidth(0); + m_dashboard->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); + + m_stack = new QStackedWidget(this); + m_stack->addWidget(m_messagePage); + m_stack->addWidget(m_dashboard); + m_stack->setCurrentWidget(m_messagePage); + + auto *outer = new QVBoxLayout(this); + outer->setContentsMargins(0, 0, 0, 0); + outer->addWidget(m_stack); + applyNoticeBarStyles(); clear(); @@ -519,9 +552,57 @@ void MessageView::setDocument(const QString &html) m_view->setHtml(html, documentUrl()); } +bool MessageView::showingDashboard() const +{ + return m_stack && m_stack->currentWidget() == m_dashboard; +} + +void MessageView::showMessagePage() +{ + if (m_stack) + m_stack->setCurrentWidget(m_messagePage); +} + +void MessageView::setDashboardThread(const QString &subject, + const QString &accountLabel, + const QStringList &tags) +{ + m_dashboard->setThreadHeading(subject, accountLabel); + m_dashboard->setTags(tags); +} + +void MessageView::showDashboard(const ThreadDigest &digest) +{ + // Everything the message page was serving is dropped, exactly as + // showPlaceholder() drops it: the pane is no longer displaying that + // message, so none of its parts may stay reachable behind the dashboard. + m_items.clear(); + m_tagStrip->setTags({}); + m_cidHandler->setParts({}); + m_interceptor->setAllowedCids({}); + m_interceptor->resetForNewMessage(); + + m_headerLabel->clear(); + m_detailsButton->hide(); + m_blockedBar->hide(); + m_messageBar->hide(); + rebuildAttachmentBar(); + setStaleThread(QString(), QString()); + + // Not the placeholder: a helper link is honoured only while THAT is on + // screen, and this is a different pane. + m_showingPlaceholder = false; + setDocument(QString()); + + m_dashboard->setDigest(digest); + m_stack->setCurrentWidget(m_dashboard); +} + void MessageView::showPlaceholder( const QList<HtmlBuilder::PlaceholderHelper> &helpers) { + showMessagePage(); + // Everything clear() drops, dropped again: this is reachable directly and // must not leave a previous thread's parts serveable behind the logo. m_items.clear(); @@ -633,6 +714,7 @@ void MessageView::setBarActions(const QList<QAction *> &messageActions, void MessageView::clear() { + showMessagePage(); m_items.clear(); m_showingPlaceholder = false; m_tagStrip->setTags({}); @@ -668,6 +750,7 @@ void MessageView::clear() void MessageView::showThread(const QList<ThreadRenderItem> &items) { + showMessagePage(); m_items = items; m_preferHtml = true; m_showingPlaceholder = false; @@ -707,6 +790,7 @@ void MessageView::showThread(const QList<ThreadRenderItem> &items) void MessageView::showError(const QString &text, const QString &filePath) { + showMessagePage(); m_items.clear(); m_showingPlaceholder = false; diff --git a/src/messageview.h b/src/messageview.h index c81a4f6..10b9430 100644 --- a/src/messageview.h +++ b/src/messageview.h @@ -29,10 +29,13 @@ #include "marks.h" #include "mimeparser.h" #include "searchterm.h" +#include "threaddigest.h" class QLabel; class QMenu; +class QStackedWidget; class QToolBar; +class ThreadDashboard; class QWebEnginePage; class QPushButton; class QWebEngineView; @@ -123,6 +126,29 @@ public: /// re-render it with fresh counts without guessing what is on screen. bool showingPlaceholder() const { return m_showingPlaceholder; } + /// Shows the conversation dashboard instead of a message (item 177). + /// + /// A thread row stands for the conversation, so there is no single message + /// to render. The heading, account and tags come from the summary and are + /// set separately: the digest is built from the index by the worker and + /// carries none of them. + void showDashboard(const ThreadDigest &digest); + + /// The heading the dashboard displays. Separate from showDashboard() + /// because the summary is known at selection time and the digest arrives + /// afterwards, so the pane can be right before the round trip returns. + void setDashboardThread(const QString &subject, const QString &accountLabel, + const QStringList &tags); + + /// True while the dashboard is what the pane is showing. + /// + /// The pane's content is asserted through this and through the dashboard's + /// own accessors, never by rendering: see "Rendering probes lie". + bool showingDashboard() const; + + /// The dashboard itself, so the window can connect its signals. Never null. + ThreadDashboard *dashboard() const { return m_dashboard; } + /// Supplies the tag strip's colours. Not owned; must outlive the view. void setTagColors(const TagColors *colours); @@ -410,6 +436,17 @@ private: /// Gates queryRequested(), so a link in a message body cannot run a query. bool m_showingPlaceholder = false; + /// The two things this pane can be: a message, or the conversation it + /// belongs to. A stack rather than show/hide over eight widgets, so + /// switching cannot leave half of one pane visible behind the other. + QStackedWidget *m_stack = nullptr; + QWidget *m_messagePage = nullptr; + ThreadDashboard *m_dashboard = nullptr; + + /// Puts the message page back on top. Every route that renders a message + /// passes through it, so the dashboard cannot survive into a message. + void showMessagePage(); + QWebEngineProfile *m_profile = nullptr; QWebEngineView *m_view = nullptr; RequestInterceptor *m_interceptor = nullptr; diff --git a/src/threaddashboard.cpp b/src/threaddashboard.cpp index 8583379..56b587f 100644 --- a/src/threaddashboard.cpp +++ b/src/threaddashboard.cpp @@ -197,6 +197,9 @@ ThreadDashboard::ThreadDashboard(QWidget *parent) : QWidget(parent) // Block 2: the tag chips. One tier, no muting, drawn by the same strip the // message pane uses so the two cannot drift. m_tags = new TagStrip; + // Named for the same reason the message pane's is: the two sit in one + // widget tree and an unqualified findChild cannot tell them apart. + m_tags->setObjectName(QStringLiteral("dashboardTagStrip")); layout->addWidget(m_tags); // Block 3: the counts, with the read-progress bar beneath. |
