diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-03 20:51:18 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-04 12:54:14 +0200 |
| commit | ed5f795869b2f63b8f7e164239e4afcf9f13bb77 (patch) | |
| tree | b18130e7915884d11da876ff68ba161589c3a3cf /src/querycompleter.cpp | |
| parent | 8e65d8f5eba78acc9558e26f9b728521f323b1a6 (diff) | |
| download | qtmaildir-ed5f795869b2f63b8f7e164239e4afcf9f13bb77.tar.gz qtmaildir-ed5f795869b2f63b8f7e164239e4afcf9f13bb77.zip | |
feat(completion): add the prefix, date and mimetype vocabularies
Keywords are syntax and stay untranslated; the descriptions beside them are
prose and go through tr().
The tables are free functions with no QObject to inherit tr() from, so the
file declares a VocabularyStrings context with Q_DECLARE_TR_FUNCTIONS rather
than borrowing QObject::tr, which would file every string under the QObject
context.
Diffstat (limited to 'src/querycompleter.cpp')
| -rw-r--r-- | src/querycompleter.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/querycompleter.cpp b/src/querycompleter.cpp index 6bdd494..77c62c1 100644 --- a/src/querycompleter.cpp +++ b/src/querycompleter.cpp @@ -18,8 +18,20 @@ #include "querycompleter.h" +#include <QCoreApplication> + namespace { +// The vocabulary lives in free functions, not in a QObject, so there is no +// inherited tr(). Q_DECLARE_TR_FUNCTIONS gives this namespace its own tr() +// bound to an explicit context, which is what lupdate scans for. Calling +// QObject::tr() here would compile but file every string under the "QObject" +// context, mixing the vocabulary in with unrelated strings. +class VocabularyStrings +{ + Q_DECLARE_TR_FUNCTIONS(VocabularyStrings) +}; + /// Whether the cursor sits inside a double-quoted literal. Counts quotes from /// the start: an odd count before the cursor means the quote is still open. bool insideQuotes(const QString &text, int cursor) @@ -64,6 +76,54 @@ int tokenEnd(const QString &text, int cursor) } // namespace +QList<CompletionEntry> prefixVocabulary() +{ + return { + { QStringLiteral("tag:"), VocabularyStrings::tr("messages with a tag") }, + { QStringLiteral("is:"), VocabularyStrings::tr("same as tag:") }, + { QStringLiteral("from:"), VocabularyStrings::tr("sender address or name") }, + { QStringLiteral("to:"), VocabularyStrings::tr("recipient, including Cc") }, + { QStringLiteral("subject:"), VocabularyStrings::tr("words in the subject") }, + { QStringLiteral("date:"), VocabularyStrings::tr("a date or a range") }, + { QStringLiteral("attachment:"), VocabularyStrings::tr("attachment filename") }, + { QStringLiteral("mimetype:"), VocabularyStrings::tr("attachment content type") }, + { QStringLiteral("folder:"), VocabularyStrings::tr("Maildir folder name") }, + { QStringLiteral("path:"), VocabularyStrings::tr("directory below the Maildir root") }, + { QStringLiteral("thread:"), VocabularyStrings::tr("a thread id") }, + { QStringLiteral("id:"), VocabularyStrings::tr("a single message id") }, + { QStringLiteral("and"), VocabularyStrings::tr("both conditions") }, + { QStringLiteral("or"), VocabularyStrings::tr("either condition") }, + { QStringLiteral("not"), VocabularyStrings::tr("exclude what follows") }, + }; +} + +QList<CompletionEntry> dateVocabulary() +{ + return { + { QStringLiteral("today"), VocabularyStrings::tr("since midnight") }, + { QStringLiteral("yesterday"), VocabularyStrings::tr("the previous day") }, + { QStringLiteral("this_week"), VocabularyStrings::tr("the current week") }, + { QStringLiteral("last_week"), VocabularyStrings::tr("the week before this one") }, + { QStringLiteral("this_month"), VocabularyStrings::tr("the current month") }, + { QStringLiteral("last_month"), VocabularyStrings::tr("the month before this one") }, + { QStringLiteral("this_year"), VocabularyStrings::tr("the current year") }, + // These two are complete open-ended ranges, hence the trailing "..". + { QStringLiteral("1week.."), VocabularyStrings::tr("the last seven days") }, + { QStringLiteral("1month.."), VocabularyStrings::tr("the last month") }, + }; +} + +QList<CompletionEntry> mimetypeVocabulary() +{ + return { + { QStringLiteral("application/pdf"), VocabularyStrings::tr("PDF document") }, + { QStringLiteral("image/jpeg"), VocabularyStrings::tr("JPEG image") }, + { QStringLiteral("image/png"), VocabularyStrings::tr("PNG image") }, + { QStringLiteral("text/html"), VocabularyStrings::tr("HTML document") }, + { QStringLiteral("application/zip"), VocabularyStrings::tr("ZIP archive") }, + }; +} + CompletionContext completionContext(const QString &text, int cursor) { CompletionContext ctx; |
