From 59a196ea849c64c51311f56bf62130e74d90b784 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 26 Aug 2026 19:31:45 +0200 Subject: feat: open the unsynced-changes count to see what it counts Item 119, and item 146 which is the same request recorded again. The status bar's count answers "is my work safe to quit on" and could not say what the work was. The label opens a read-only list on a click. A QLabel has no clicked signal, so the press is taken by MainWindow's existing event filter rather than by replacing the label with a flat QToolButton, which would have brought the style's button metrics into a status bar the label already sits correctly in. The pointing-hand cursor is the affordance, since a status-bar label has room for nothing else. The layout is the user's own: a message appears once with its actions beneath it. PendingChangesDialog::rowsFor() does the grouping over a run of rows sharing an id, which the snapshot has already ordered, so the actions under one message keep the order they were made in. Read-only, deliberately. Retrying or discarding a change from here would be a new mutation path with its own undo question, and the count exists to be understood rather than edited. Three rules the tests pin, each of which is a way the list could disagree with the count it was opened from: - Grouping must not collapse: two actions on one message are two rows. - A thread row stays thread-scoped and reports how many messages it covered. - An id the index no longer holds still opens a run of its own, showing that its subject is unknown rather than folding its actions under the message above it. This is why the row carries startsMessage rather than inferring it from a non-empty subject. The queued call carrying QStringList, QList and QList is covered by a test that drives it across a real thread, since a container whose metatype does not resolve is dropped at runtime and the slot runs with a default. Both survive on Qt 6.11; the test is what says so, and what would fail if that changed. Italian ships with it: five new strings, lupdate clean, lrelease 522 finished and 0 unfinished. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01P88Q3MCSCSQxKDy7pmXh9F --- src/CMakeLists.txt | 1 + src/mainwindow.cpp | 76 +++++++++++++++++++++++++++ src/mainwindow.h | 18 +++++++ src/pendingchangesdialog.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++ src/pendingchangesdialog.h | 86 ++++++++++++++++++++++++++++++ 5 files changed, 302 insertions(+) create mode 100644 src/pendingchangesdialog.cpp create mode 100644 src/pendingchangesdialog.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7cec9b3..591e95f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(qtmaildir_lib STATIC threadcidmap.cpp messageview.cpp messagedetailsdialog.cpp + pendingchangesdialog.cpp mainwindow.cpp querycompleter.cpp rulequery.cpp diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0c6092e..231a9a5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ #include "searchterm.h" #include "tagchip.h" #include "tagdialog.h" +#include "pendingchangesdialog.h" #include "savequerydialog.h" #include "tagrulesdialog.h" #include "threadlistmodel.h" @@ -490,6 +492,20 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) // cannot fail. } + // The unsynced-changes indicator opens its list on a click (item 119). A + // QLabel has no clicked signal, so the press is taken here rather than + // replacing the label with a flat QToolButton: a button would inherit the + // style's button metrics inside a status bar, and the label already sits + // correctly. + if (watched == m_pendingLabel + && event->type() == QEvent::MouseButtonRelease) { + auto *mouse = static_cast(event); + if (mouse->button() == Qt::LeftButton) { + showPendingChanges(); + return true; + } + } + return QMainWindow::eventFilter(watched, event); } @@ -682,6 +698,11 @@ void MainWindow::buildUi() // them together. m_pendingLabel = new QLabel(this); m_pendingLabel->setObjectName(QStringLiteral("pendingEdits")); + // Clickable, opening the list of what it counts (item 119). The cursor is + // the only affordance a status-bar label can carry, so it is what says + // this one can be opened. + m_pendingLabel->setCursor(Qt::PointingHandCursor); + m_pendingLabel->installEventFilter(this); m_pendingLabel->hide(); statusBar()->addPermanentWidget(m_pendingLabel); @@ -2618,6 +2639,8 @@ void MainWindow::wireWorker() // unrelated error would roll back a change that actually succeeded. connect(m_worker, &NotmuchWorker::tagsApplied, this, &MainWindow::onTagsApplied); + connect(m_worker, &NotmuchWorker::pendingSubjectsResolved, + this, &MainWindow::onPendingSubjectsResolved); // messagesMovedFrom rather than messagesMoved: the tags a move carries can // only be resolved once the origins are known, and that signal is the one @@ -5108,6 +5131,59 @@ QVector MainWindow::pendingChangeSnapshot() const return rows; } +void MainWindow::showPendingChanges() +{ + // The snapshot is taken HERE, at the click, and is what the dialog shows + // however long it stays open. Nothing refreshes it: the count the user + // clicked is the list they get. + m_pendingChangeRequest = pendingChangeSnapshot(); + + if (m_pendingChangeRequest.isEmpty() || !m_worker) { + // Nothing to resolve. Shown anyway rather than silently ignoring the + // click, since a window saying "nothing is waiting" is an answer and a + // dead click is not. + PendingChangesDialog(m_pendingChangeRequest, this).exec(); + m_pendingChangeRequest.clear(); + return; + } + + QStringList ids; + QList areThreads; + ids.reserve(m_pendingChangeRequest.size()); + areThreads.reserve(m_pendingChangeRequest.size()); + for (const PendingChange &change : m_pendingChangeRequest) { + ids.append(change.id); + areThreads.append(change.isThread); + } + + QMetaObject::invokeMethod(m_worker, "resolvePendingSubjects", + Qt::QueuedConnection, + Q_ARG(QStringList, ids), + Q_ARG(QList, areThreads)); +} + +void MainWindow::onPendingSubjectsResolved(const QStringList &subjects, + const QList &messageCounts) +{ + // Positional, so the two must line up. A mismatch means the answer is not + // this request's, which is not something to render half of. + if (m_pendingChangeRequest.isEmpty() + || subjects.size() != m_pendingChangeRequest.size() + || messageCounts.size() != m_pendingChangeRequest.size()) { + m_pendingChangeRequest.clear(); + return; + } + + QVector changes = m_pendingChangeRequest; + m_pendingChangeRequest.clear(); + for (int i = 0; i < changes.size(); ++i) { + changes[i].subject = subjects.at(i); + changes[i].messageCount = messageCounts.at(i); + } + + PendingChangesDialog(changes, this).exec(); +} + void MainWindow::updatePendingIndicator() { const int pending = pendingEditCount(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 532a5ea..6321573 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -123,6 +123,13 @@ public: QVector pendingChangeSnapshot() const; + /// Opens the list behind the unsynced-changes count. + /// + /// Takes the snapshot, asks the worker to resolve its subjects, and shows + /// the dialog when they arrive. Q_INVOKABLE so a test can open it without + /// synthesising a click on a status-bar label. + Q_INVOKABLE void showPendingChanges(); + /// Whether the undo stack still holds anything. Exposed so a test can show /// that a rejected write did not take unrelated history down with it. bool canUndo() const { return m_undoStack.canUndo(); } @@ -618,6 +625,10 @@ private slots: /// A tag mutation the worker has confirmed reached the database. Counts it /// as unsynced, since reaching the index is not reaching the mail store. void onTagsApplied(const TagChange &change); + + /// The subjects for the pending-changes list arrived; show the dialog. + void onPendingSubjectsResolved(const QStringList &subjects, + const QList &messageCounts); void onAllTagsReady(const QStringList &tags); /// The Maildir root, answered once at startup. Enables nothing on its own: @@ -1575,6 +1586,13 @@ private: }; QHash m_pendingTagEdits; + /// The snapshot taken when the user clicked the indicator, held while the + /// worker resolves its subjects. Empty when no such request is in flight. + /// + /// One request at a time: a second click before the first answers replaces + /// it, which is right because both would show the same thing. + QVector m_pendingChangeRequest; + /// Marks the open thread read once it has been on screen long enough. /// /// Single-shot and RESTARTED on every selection change, never stacked: diff --git a/src/pendingchangesdialog.cpp b/src/pendingchangesdialog.cpp new file mode 100644 index 0000000..71e3bb0 --- /dev/null +++ b/src/pendingchangesdialog.cpp @@ -0,0 +1,121 @@ +/* + * qtmaildir - a Qt6 mail client for notmuch-indexed Maildirs + * Copyright (C) 2026 Danilo M. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pendingchangesdialog.h" + +#include +#include +#include +#include +#include + +QVector PendingChangesDialog::rowsFor( + const QVector &changes) +{ + QVector rows; + rows.reserve(changes.size()); + + // A run is a stretch of changes sharing one id, which the snapshot has + // already grouped. Only the first row of a run carries a subject, so the + // actions read as belonging to the message above them. + // + // Compared against the PREVIOUS id rather than collected into a map: the + // snapshot's order is deliberate (the actions under one message keep the + // order they were made in), and a map would discard it. + QString previousId; + bool first = true; + for (const PendingChange &change : changes) { + const bool startsMessage = first || change.id != previousId; + rows.append(PendingChangeRow{ + startsMessage ? change.subject : QString(), + change.action, + startsMessage, + startsMessage ? change.messageCount : -1 }); + previousId = change.id; + first = false; + } + return rows; +} + +PendingChangesDialog::PendingChangesDialog( + const QVector &changes, QWidget *parent) + : QDialog(parent), m_rows(rowsFor(changes)) +{ + setWindowTitle(tr("Unsynced changes")); + + auto *layout = new QVBoxLayout(this); + + auto *intro = new QLabel( + tr("Changes made here that a sync has not yet carried to the mail " + "store. This list is a snapshot taken when it was opened."), + this); + intro->setWordWrap(true); + layout->addWidget(intro); + + auto *content = new QWidget; + auto *grid = new QGridLayout(content); + grid->setColumnStretch(0, 1); + + int line = 0; + for (const PendingChangeRow &row : m_rows) { + if (row.startsMessage) { + // PlainText stated rather than left to Qt, for the reason + // MessageDetailsDialog states it on every value: a subject comes + // from a stranger, and a QLabel guesses under Qt::AutoText. Plain + // text cannot interpret markup, so there is nothing to escape. + QString text = row.subject; + if (text.isEmpty()) { + // The id no longer resolves. The row stays, because the count + // the user clicked has to equal the list they are shown. + text = tr("(no longer in the index)"); + } + if (row.messageCount >= 0) { + text = tr("%1 (whole thread, %n message(s))", "", + row.messageCount).arg(text); + } + auto *subject = new QLabel(text, content); + subject->setTextFormat(Qt::PlainText); + subject->setWordWrap(true); + grid->addWidget(subject, line, 0); + } + + auto *action = new QLabel(row.action, content); + action->setTextFormat(Qt::PlainText); + grid->addWidget(action, line, 1, Qt::AlignTop | Qt::AlignRight); + ++line; + } + + if (m_rows.isEmpty()) { + grid->addWidget(new QLabel(tr("Nothing is waiting to be synced."), + content), + 0, 0); + } + + grid->setRowStretch(line, 1); + + auto *scroll = new QScrollArea(this); + scroll->setWidget(content); + scroll->setWidgetResizable(true); + layout->addWidget(scroll); + + auto *buttons = new QDialogButtonBox(QDialogButtonBox::Close, this); + connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); + layout->addWidget(buttons); + + resize(600, 380); +} diff --git a/src/pendingchangesdialog.h b/src/pendingchangesdialog.h new file mode 100644 index 0000000..5e47cbd --- /dev/null +++ b/src/pendingchangesdialog.h @@ -0,0 +1,86 @@ +/* + * qtmaildir - a Qt6 mail client for notmuch-indexed Maildirs + * Copyright (C) 2026 Danilo M. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include +#include + +#include "types.h" + +/// What one line of the dialog shows. +/// +/// Separate from PendingChange because the two answer different questions. +/// PendingChange is what is outstanding; this is what is drawn, and the +/// difference is the grouping: a message with several actions contributes +/// several rows here, only the first of which carries a subject. +struct PendingChangeRow +{ + /// The subject, drawn only on the first row of a run sharing one id. + /// Empty on the rows beneath it, which is what puts the actions under + /// their message rather than beside a repeated subject. + QString subject; + + /// What the user did. Every row has one; this is the point of the list. + QString action; + + /// True when this row opens a new message, i.e. when `subject` is drawn. + /// Carried explicitly rather than inferred from a non-empty subject: a + /// message whose id no longer resolves has an EMPTY subject and still + /// opens a run of its own. + bool startsMessage = false; + + /// How many messages a thread row covered, or -1 for a message row. + int messageCount = -1; +}; + +/// The list behind the unsynced-changes count (item 119). +/// +/// Read-only, deliberately. This is an information window, not a place to +/// retry or discard a change: either would be a new mutation path with its own +/// undo question, and the count exists to answer "is my work safe to quit on" +/// rather than to be edited. +/// +/// A SNAPSHOT. The rows are built once, when the user opens it, and never +/// refreshed underneath them: a dialog left open for twenty minutes shows what +/// was true when it was opened, which is what the user clicked on. +/// +/// Rows are exposed so the grouping can be asserted without rendering +/// anything, which is how MessageDetailsDialog is tested and for the same +/// reason: a pixel probe cannot tell a correct layout from a plausible one. +class PendingChangesDialog : public QDialog +{ + Q_OBJECT +public: + explicit PendingChangesDialog(const QVector &changes, + QWidget *parent = nullptr); + + /// The lines on display, in order. Exposed for testing without rendering. + QVector rows() const { return m_rows; } + + /// Groups the changes into display rows: a subject on the first row of + /// each run sharing an id, the actions beneath it. + /// + /// Static and value-in, value-out so the grouping is testable with no + /// widget at all. + static QVector rowsFor( + const QVector &changes); + +private: + QVector m_rows; +}; -- cgit v1.2.3