aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.h
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-15 10:50:59 +0200
committerDanilo M. <danix@danix.xyz>2026-08-15 10:50:59 +0200
commitde0d3aaa63be2867d127304d55d34259eb6e30d6 (patch)
tree3911cb7563d36aad65de8e6afb6c845555c023c9 /src/config.h
parente6e18849bd5aa49dbdd299982d39a92e7360d0aa (diff)
downloadqtmaildir-de0d3aaa63be2867d127304d55d34259eb6e30d6.tar.gz
qtmaildir-de0d3aaa63be2867d127304d55d34259eb6e30d6.zip
feat(filters): resolve built-in filters per account
Item 93, the Config half. Four built-in filters, Unread, Inbox, Flagged and Sent, as generated entries in kQueryGenerators, which was already a closed set validated on load for Sent alone. resolvedQuery() gains an overload taking an account key, and that is what makes a filter compose with the account dropdown instead of fighting it. A generator is asked for the account's OWN query rather than having its all-accounts query wrapped in a scope: wrapping gives path:"a/**" and (path:"a/Sent/**" or path:"b/Sent/**") which returns the right rows only because path: is hierarchical, so a row-count test passes against it. The tests assert on the query string for that reason, and the mutation putting the wrap back fails two of them. An ordinary saved query ignores the account key and keeps resolving through its own stored account, which is the behaviour item 90 leaves alone. matchNothingQuery() exists because an empty query means "match everything" to notmuch: an account configuring no sent folder would otherwise give a button labelled Sent that shows the entire Maildir. Config gains Q_DECLARE_TR_FUNCTIONS for the filter names, which are button labels. The generator names are not translated: they are matched against the closed set and stored in queries.json, so translating them would make a file written in one locale unreadable in another. No UI yet, and no migration: the query row still builds from pinned saved queries.
Diffstat (limited to 'src/config.h')
-rw-r--r--src/config.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h
index b9ee9d6..3946b40 100644
--- a/src/config.h
+++ b/src/config.h
@@ -19,6 +19,7 @@
#pragma once
#include <QColor>
+#include <QCoreApplication>
#include <QJsonObject>
#include <QList>
#include <QString>
@@ -155,6 +156,11 @@ struct SavedQuery
/// allow the GUI to index a different tree than the CLI.
class Config
{
+ // Not a QObject: this class is a value holder read from every thread. The
+ // macro gives it tr() for the built-in filters' NAMES, which are the labels
+ // on the query row's buttons and therefore user-facing.
+ Q_DECLARE_TR_FUNCTIONS(Config)
+
public:
/// Path used when load() is called with no argument.
static QString defaultPath();
@@ -190,6 +196,46 @@ public:
/// than a scope built from an empty maildir, which would be path:"/**".
QString resolvedQuery(const SavedQuery &query) const;
+ /// The query as it should be run in one account's scope, or across all of
+ /// them when `accountKey` is empty.
+ ///
+ /// This is what makes a built-in filter COMPOSE with the account dropdown
+ /// rather than fight it (item 93). A generator is asked for the account's
+ /// own query, never handed its all-accounts query to wrap: wrapping gives
+ /// path:"a/**" and (path:"a/Sent/**" or path:"b/Sent/**")
+ /// which returns the right rows only because path: is hierarchical, and
+ /// says something other than what is meant.
+ ///
+ /// An ordinary saved query ignores `accountKey` and keeps resolving through
+ /// its OWN stored account, which is the behaviour item 90 leaves alone: a
+ /// saved query is a destination and states its own scope.
+ QString resolvedQuery(const SavedQuery &query,
+ const QString &accountKey) const;
+
+ /// The built-in filters, in the order they appear on the query row.
+ ///
+ /// Shipped rather than stored: these are not the user's saved queries and
+ /// are not in queries.json at all. The row used to be whatever the user had
+ /// pinned, which is how it drifted (item 93).
+ static QList<SavedQuery> builtinFilters();
+
+ /// One built-in filter by generator name, or a default-constructed
+ /// SavedQuery when the name is not one.
+ static SavedQuery builtinFilter(const QString &generator);
+
+ /// Whether `generator` is one this build knows how to resolve.
+ ///
+ /// A closed set, so a typo is reported on load rather than producing a
+ /// button that silently finds nothing.
+ static bool isKnownGenerator(const QString &generator);
+
+ /// A query that deliberately matches no message.
+ ///
+ /// Needed because an EMPTY query means "match everything" to notmuch, so a
+ /// generator with nothing to match cannot simply return one: Sent under an
+ /// account that configures no sent folder would show the entire Maildir.
+ static QString matchNothingQuery();
+
/// Empty when unset; the caller disables the Sync button in that case.
QString syncCommand() const { return m_syncCommand; }