summaryrefslogtreecommitdiffstats
path: root/src/config.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-18 15:09:09 +0200
committerDanilo M. <danix@danix.xyz>2026-09-18 15:09:09 +0200
commit729fd1465718ef1da5f61452bcb7eb23d02c9c9a (patch)
tree49df1e831e90d012685e829b8eb52c5d5fd1a3dc /src/config.cpp
parent3303c7855cb22a6bb4f36aa1a17707187320f5d2 (diff)
downloadqtmaildir-729fd1465718ef1da5f61452bcb7eb23d02c9c9a.tar.gz
qtmaildir-729fd1465718ef1da5f61452bcb7eb23d02c9c9a.zip
feat: add the contacts_dir config key
Adds Config::contactsDir(), the [general] key Task 5 will read to locate the ContactStore. Empty means the feature is off. The key is read WITHOUT the general/ prefix, like notmuch_config, because QSettings' INI backend strips a section literally named [general]. Absent or empty is silent; a set path that does not exist is reported through addProblem(). A leading ~ is expanded by a local helper, since config.cpp expands no other path and this is the first one to need it.
Diffstat (limited to 'src/config.cpp')
-rw-r--r--src/config.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 184c756..3cd842b 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -94,6 +94,21 @@ bool generatorIsFlat(const QString &generator)
|| generator == QStringLiteral("drafts");
}
+/// Expands a leading "~" to the home directory.
+///
+/// No other key in config.cpp expands one; contacts_dir is the first, and only
+/// because the README documents its usual value as
+/// "~/.local/share/vdirsyncer/contacts/". A shared helper would serve one
+/// caller, so this stays local until a second one exists.
+QString expandTilde(const QString &path)
+{
+ if (path == QLatin1String("~"))
+ return QDir::homePath();
+ if (path.startsWith(QLatin1String("~/")))
+ return QDir::homePath() + path.mid(1);
+ return path;
+}
+
} // namespace
QString Account::scopedQuery(const QString &query) const
@@ -236,6 +251,27 @@ void Config::load(const QString &path)
m_notmuchConfig =
settings.value(QStringLiteral("notmuch_config")).toString();
+ // [general], so no prefix, per the note above. Tilde is expanded for the
+ // README's documented value, "~/.local/share/vdirsyncer/contacts/", which
+ // would otherwise name a literal "~" directory that does not exist.
+ //
+ // Absent or empty is silent: the feature is simply off, which is an
+ // ordinary machine rather than a misconfiguration. A path that is set and
+ // missing is reported, because there the user asked for something and is
+ // not getting it. The value is KEPT rather than cleared: a vdirsyncer
+ // target may not exist until its first run, and ContactStore's walk treats
+ // a missing directory as empty anyway, so the warning is the whole report.
+ const QString contactsDir =
+ settings.value(QStringLiteral("contacts_dir")).toString().trimmed();
+ if (!contactsDir.isEmpty()) {
+ m_contactsDir = expandTilde(contactsDir);
+ if (!QFileInfo::exists(m_contactsDir)) {
+ addProblem(tr("Contacts directory '%1' does not exist; contact "
+ "completion will find no contacts.")
+ .arg(m_contactsDir));
+ }
+ }
+
// Absent is fine and silent: the default is 1.0. Present but unparseable
// is a problem, since the user asked for something and is not getting it.
// The range is enforced by MessageView::clampZoom(), the one place that