aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp17
-rw-r--r--src/config.h15
-rw-r--r--src/mainwindow.cpp39
3 files changed, 65 insertions, 6 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 8ca7910..9bed74a 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -191,6 +191,11 @@ void Config::load(const QString &path)
m_startupQueryWasSet = true;
}
+ // Stored raw here and validated once the accounts are parsed, below: the
+ // account sections have not been read yet at this point.
+ m_startupAccount =
+ settings.value(QStringLiteral("startup_account")).toString().trimmed();
+
const QVariant zoom = settings.value(QStringLiteral("message_zoom"));
if (zoom.isValid()) {
bool ok = false;
@@ -442,6 +447,18 @@ void Config::load(const QString &path)
// are not parsed until now. Only a name the user actually wrote is worth a
// problem; the built-in default naming a query they never created is not
// something they got wrong.
+ // Same shape as the startup_query check below: a name the user wrote that
+ // matches nothing is a problem, because they asked for something and are
+ // not getting it. Cleared rather than passed on, since the dropdown has no
+ // entry for an account that does not exist and would sit on "All accounts"
+ // without saying why.
+ if (!m_startupAccount.isEmpty() && !account(m_startupAccount).isValid()) {
+ addProblem(QStringLiteral("Startup account '%1' is not a configured "
+ "account; starting on all accounts.")
+ .arg(m_startupAccount));
+ m_startupAccount.clear();
+ }
+
if (m_startupQueryWasSet && !m_savedQueries.isEmpty()
&& startupSavedQuery().name.compare(m_startupQuery,
Qt::CaseInsensitive) != 0) {
diff --git a/src/config.h b/src/config.h
index 3946b40..d1f8e65 100644
--- a/src/config.h
+++ b/src/config.h
@@ -299,6 +299,17 @@ public:
/// sort first rather than anything the user chose.
QString startupQuery() const { return m_startupQuery; }
+ /// Account key the dropdown starts on, or empty for "All accounts".
+ ///
+ /// Scoping happens because the built-in filters COMPOSE with the dropdown,
+ /// so setting it before the startup query runs is the whole mechanism: this
+ /// key does not need to reach the query builders at all.
+ ///
+ /// Validated on load. A name matching no account is reported and left
+ /// empty, rather than passed on to a dropdown that has no such entry and
+ /// would silently stay on "All accounts".
+ QString startupAccount() const { return m_startupAccount; }
+
/// The saved query startupQuery() names, or the first one when it names
/// nothing that exists. A default-constructed SavedQuery when there are
/// none at all.
@@ -401,6 +412,10 @@ private:
QList<CompletionEntry> m_extraMimetypes;
QString m_startupQuery = QStringLiteral("Unread");
+ /// Empty means "All accounts", which is the same convention every other
+ /// account key here follows.
+ QString m_startupAccount;
+
/// Whether startup_query came from the config rather than being the
/// built-in default. Only a name the user wrote is worth reporting when
/// it matches no saved query.
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3ebcbc4..3d7add2 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -404,19 +404,46 @@ MainWindow::MainWindow(const Config &config, QWidget *parent)
// Not savedQueries().first(): [queries] is read through childKeys(), which
// sorts alphabetically, so "first" means whatever happens to sort first
// rather than anything the user chose. Config resolves the name.
+ // BEFORE the startup query runs, so the query below is composed in this
+ // scope. That is the whole of `startup_account`: a built-in filter composes
+ // with the dropdown, so setting the dropdown is all that is needed and the
+ // key never reaches a query builder.
+ //
+ // Config has already checked the key names a real account and cleared it if
+ // not, so findData either matches or this is "All accounts" anyway.
+ const QString startupAccount = m_config.startupAccount();
+ if (!startupAccount.isEmpty()) {
+ const int index = m_accountBox->findData(startupAccount);
+ if (index >= 0)
+ m_accountBox->setCurrentIndex(index);
+ }
+
// resolvedQuery(), not startup.query: a generated entry stores no query at
// all, since its text is composed from the accounts at run time. Reading
// the field directly meant a startup_query naming a built-in filter opened
// an empty bar and ran nothing.
- //
- // No account scope here. The dropdown starts on "All accounts", which is
- // the empty key, so this is the unscoped form either way; passing the
- // selection would be reading a widget the user has not touched yet.
const SavedQuery startup = m_config.startupSavedQuery();
- const QString startupQuery = m_config.resolvedQuery(startup, QString());
+ const QString startupQuery =
+ m_config.resolvedQuery(startup, startupAccount);
if (!startupQuery.isEmpty()) {
m_queryEdit->setText(startupQuery);
- runCurrentQuery();
+
+ // Which of the two applies the scope depends on what the startup entry
+ // IS, and getting this wrong is silent in both directions.
+ //
+ // A generated filter came back from resolvedQuery() already scoped to
+ // the startup account, so applying the dropdown again gives
+ // path:"work/**" and (path:"work/**" and (tag:inbox))
+ // which returns exactly the right rows while being the double scope
+ // this item exists to avoid.
+ //
+ // A saved query did NOT: resolvedQuery() ignores the account key for
+ // one, because a saved query states its own scope. Claiming it was
+ // already scoped leaves it unscoped for good, with the dropdown sitting
+ // on Work and the list showing every account.
+ runQuery(FlatResult::No,
+ startup.isGenerated() ? AccountScope::AlreadyScoped
+ : AccountScope::Apply);
}
}