diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-13 16:07:18 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-13 16:07:18 +0200 |
| commit | a52e4e41c2bc8fc8eb23c4bc99f9b8724212bd23 (patch) | |
| tree | 96baca838f24de8dabfa95391eaf9cd1d0c6d20f /src/mainwindow.cpp | |
| parent | e7cdd7fd3ae960572976cb4a053ecf192baa17c2 (diff) | |
| download | qtmaildir-a52e4e41c2bc8fc8eb23c4bc99f9b8724212bd23.tar.gz qtmaildir-a52e4e41c2bc8fc8eb23c4bc99f9b8724212bd23.zip | |
feat(rules): every Maildir folder in the Folder dropdown
The dropdown was built from config, which names one subtree per account
and nothing below it, so it offered five entries and no way to say
Drafts or Sent. A rule wants to target those as often as a whole
account.
NotmuchWorker gains requestFolders/foldersReady, walking the tree from
notmuch_database_get_path() and listing every directory holding cur/.
It belongs there because the database root is notmuch's database.path
and the worker owns the only handle that can answer for it; putting the
root in config would be the second source of truth the design refuses.
From the disk rather than from the index: a folder mbsync created and
nothing has landed in yet is still a folder a rule may target, and a
list derived from indexed message paths would not offer it.
The two tests build their own fixture rather than extending the shared
one, which needs a nested folder and would otherwise move seven count
assertions in unrelated tests. Mutation-checked: flattening the walk to
non-recursive fails the listing test.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f622036..e8b4dda 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1314,18 +1314,16 @@ void MainWindow::showTagRulesDialog() auto *dialog = new TagRulesDialog(this); dialog->setAttribute(Qt::WA_DeleteOnClose); - // The Folder row's dropdown. Config holds the account subdirectories and - // the dialog holds no Config, so they are handed over here. Account::maildir - // is the subtree name the Folder term compiles a path: against; the account - // key is a config section name and would match nothing. - QStringList folders; - for (const Account &account : m_config.accounts()) { - if (!account.maildir.isEmpty() && !folders.contains(account.maildir)) - folders.append(account.maildir); - } - dialog->setFolders(folders); m_tagRulesDialog = dialog; + // The Folder row's dropdown, filled from the Maildir tree on disk rather + // than from config. Config names one subtree per account and nothing + // below it, so the dropdown offered five entries and no way to say Drafts + // or Sent, which is a folder a rule wants to target as often as a whole + // account. The answer comes back queued, after the dialog is already up; + // setFolders refills the rows that exist by then. + QMetaObject::invokeMethod(m_worker, "requestFolders", Qt::QueuedConnection); + connect(dialog, &TagRulesDialog::countsRequested, this, [this, dialog]() { QMetaObject::invokeMethod( m_worker, "requestMessageCounts", Qt::QueuedConnection, @@ -1425,6 +1423,15 @@ void MainWindow::wireWorker() connect(m_worker, &NotmuchWorker::messageCountsReady, this, &MainWindow::onRuleCountsReady); + // The rules dialog is the only consumer, and it may have been closed while + // the scan was in flight. No generation counter: the tree on disk does not + // change under a query, so a late answer is still the right one. + connect(m_worker, &NotmuchWorker::foldersReady, this, + [this](const QStringList &folders) { + if (m_tagRulesDialog) + m_tagRulesDialog->setFolders(folders); + }); + // A confirmed write clears the pending revert: without this, a later // unrelated error would roll back a change that actually succeeded. connect(m_worker, &NotmuchWorker::tagsApplied, |
