From 72b56d0beca6d640c724eabc73a3ee45cf04bfea Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 2 Aug 2026 17:21:47 +0200 Subject: feat: add Config with account, query, and sync parsing Accounts use [account.work] rather than [account/work]: QSettings' INI backend treats "/" as its own hierarchical group separator, so a literal slash in a section header parses as a nested group and trips QSettings::FormatError, silently breaking childGroups() enumeration. A dot carries no such meaning and keeps the format flat. Saved-query order is alphabetical (QSettings::childKeys() sorts), not file order; documented in code and tests rather than left to a false assumption. --- src/config.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/config.h (limited to 'src/config.h') diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..f037db5 --- /dev/null +++ b/src/config.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include +#include + +/// One mail account. notmuch has no concept of accounts; it sees a single flat +/// tree. An account is therefore a path prefix within that tree plus an +/// identity. +struct Account +{ + QString key; ///< INI group suffix, e.g. "work" from [account/work]. + QString name; + QString address; + QString maildir; ///< Relative to notmuch's database.path. + QString drafts; ///< Unused in v1; send is v2. + + bool isValid() const { return !key.isEmpty() && !maildir.isEmpty(); } + + /// Restricts a notmuch query to this account's subtree. + QString scopedQuery(const QString &query) const; +}; + +struct SavedQuery +{ + QString name; + QString query; +}; + +/// Reads ~/.config/qtmaildir/qtmaildir.conf. +/// +/// The Maildir path is deliberately NOT configurable here: notmuch already +/// stores it as database.path and libnotmuch reads it. Duplicating it would +/// allow the GUI to index a different tree than the CLI. +class Config +{ +public: + /// Path used when load() is called with no argument. + static QString defaultPath(); + + void load(const QString &path); + + QList accounts() const { return m_accounts; } + Account account(const QString &key) const; + QList savedQueries() const { return m_savedQueries; } + + /// Empty when unset; the caller disables the Sync button in that case. + QString syncCommand() const { return m_syncCommand; } + + /// Optional alternate notmuch config file. Empty means "let notmuch decide". + QString notmuchConfig() const { return m_notmuchConfig; } + + /// Non-fatal problems, shown once in a startup banner. + QStringList warnings() const { return m_warnings; } + +private: + QList m_accounts; + QList m_savedQueries; + QString m_syncCommand; + QString m_notmuchConfig; + QStringList m_warnings; +}; -- cgit v1.2.3