diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 76 | ||||
| -rw-r--r-- | src/mainwindow.h | 18 | ||||
| -rw-r--r-- | src/pendingchangesdialog.cpp | 121 | ||||
| -rw-r--r-- | src/pendingchangesdialog.h | 86 |
5 files changed, 302 insertions, 0 deletions
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 <QApplication> #include <QCloseEvent> #include <QKeyEvent> +#include <QMouseEvent> #include <QComboBox> #include <QDialog> #include <QDialogButtonBox> @@ -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<QMouseEvent *>(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<PendingChange> 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<bool> 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<bool>, areThreads)); +} + +void MainWindow::onPendingSubjectsResolved(const QStringList &subjects, + const QList<int> &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<PendingChange> 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<PendingChange> 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<int> &messageCounts); void onAllTagsReady(const QStringList &tags); /// The Maildir root, answered once at startup. Enables nothing on its own: @@ -1575,6 +1586,13 @@ private: }; QHash<QString, PendingEdit> 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<PendingChange> 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. <danix@danix.xyz> + * + * 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 <QDialogButtonBox> +#include <QGridLayout> +#include <QLabel> +#include <QScrollArea> +#include <QVBoxLayout> + +QVector<PendingChangeRow> PendingChangesDialog::rowsFor( + const QVector<PendingChange> &changes) +{ + QVector<PendingChangeRow> 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<PendingChange> &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. <danix@danix.xyz> + * + * 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 <QDialog> +#include <QVector> + +#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<PendingChange> &changes, + QWidget *parent = nullptr); + + /// The lines on display, in order. Exposed for testing without rendering. + QVector<PendingChangeRow> 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<PendingChangeRow> rowsFor( + const QVector<PendingChange> &changes); + +private: + QVector<PendingChangeRow> m_rows; +}; |
