7#include "searchlinecommand.h"
8#include <KLocalizedString>
16 {
"subject"_L1, SearchLineCommand::SearchLineType::Subject},
17 {
"body"_L1, SearchLineCommand::SearchLineType::Body},
18 {
"to"_L1, SearchLineCommand::SearchLineType::To},
19 {
"cc"_L1, SearchLineCommand::SearchLineType::Cc},
20 {
"bcc"_L1, SearchLineCommand::SearchLineType::Bcc},
21 {
"from"_L1, SearchLineCommand::SearchLineType::From},
22 {
"has:attachment"_L1, SearchLineCommand::SearchLineType::HasAttachment},
23 {
"has:invitation"_L1, SearchLineCommand::SearchLineType::HasInvitation},
24 {
"is:unread"_L1, SearchLineCommand::SearchLineType::IsUnRead},
25 {
"is:read"_L1, SearchLineCommand::SearchLineType::IsRead},
26 {
"is:important"_L1, SearchLineCommand::SearchLineType::IsImportant},
27 {
"is:ignored"_L1, SearchLineCommand::SearchLineType::IsIgnored},
28 {
"is:ham"_L1, SearchLineCommand::SearchLineType::IsHam},
29 {
"is:spam"_L1, SearchLineCommand::SearchLineType::IsSpam},
30 {
"is:watched"_L1, SearchLineCommand::SearchLineType::IsWatched},
31 {
"is:replied"_L1, SearchLineCommand::SearchLineType::IsReplied},
32 {
"is:forwarded"_L1, SearchLineCommand::SearchLineType::IsForwarded},
33 {
"size"_L1, SearchLineCommand::SearchLineType::Size},
34 {
"smaller"_L1, SearchLineCommand::SearchLineType::Larger},
35 {
"larger"_L1, SearchLineCommand::SearchLineType::Smaller},
36 {
"older_than"_L1, SearchLineCommand::SearchLineType::OlderThan},
37 {
"newer_than"_L1, SearchLineCommand::SearchLineType::NewerThan},
38 {
"category"_L1, SearchLineCommand::SearchLineType::Category},
43SearchLineCommand::SearchLineCommand() =
default;
45SearchLineCommand::~SearchLineCommand() =
default;
47bool SearchLineCommand::hasSubType(
const QString &v)
52bool SearchLineCommand::hasSubType(SearchLineCommand::SearchLineType type)
54 return type == Date || type == Size || type == To || type == Bcc || type == Cc || type == From || type == Subject || type == Smaller || type == Larger
55 || type == OlderThan || type == NewerThan || type == Body || type == Category;
58bool SearchLineCommand::isEmpty()
const
60 return mSearchLineInfo.
isEmpty();
63QString SearchLineCommand::convertSearchLinetypeToTranslatedString(SearchLineCommand::SearchLineType type)
const
67 case HasStateOrAttachment:
75 return i18n(
"Literal string");
77 return i18n(
"Size is smaller than");
79 return i18n(
"Size is larger than");
81 return i18n(
"Size is");
83 return i18n(
"To contains");
85 return i18n(
"BCC contains");
87 return i18n(
"CC contains");
89 return i18n(
"From contains");
91 return i18n(
"Subject contains");
93 return i18n(
"Body contains");
95 return i18n(
"Mail has tag");
97 return i18n(
"Mail has attachment");
99 return i18n(
"Mail has invitation");
101 return i18n(
"Mail is important");
103 return i18n(
"Mail is read");
105 return i18n(
"Mail is Unread");
107 return i18n(
"Mail is Ignored");
109 return i18n(
"Mail is Ham");
111 return i18n(
"Mail is Spam");
113 return i18n(
"Mail is watched");
115 return i18n(
"Mail is replied");
117 return i18n(
"Mail is forwarded");
122QString SearchLineCommand::generateCommadLineStr()
const
125 for (
const auto &info : mSearchLineInfo) {
129 const QString translatedType = convertSearchLinetypeToTranslatedString(info.type);
130 if (!translatedType.
isEmpty()) {
131 result += translatedType;
133 if (!info.argument.isEmpty()) {
134 if (!translatedType.
isEmpty()) {
137 result += info.argument;
143SearchLineCommand::SearchLineInfo SearchLineCommand::isAnotherInfo(
QString tmp, SearchLineInfo searchLineInfo)
149#ifdef DEBUG_COMMAND_PARSER
150 qDebug() <<
" found has subtype " << tmp;
155 for (
const QString &key : keys) {
157#ifdef DEBUG_COMMAND_PARSER
158 qDebug() <<
" found element !!!!!! " << tmp;
162 searchLineInfo.argument = tmp;
163 if (!searchLineInfo.argument.isEmpty() && searchLineInfo.type == Unknown) {
164 searchLineInfo.type = Literal;
167 if (searchLineInfo.isValid()) {
168 appendSearchLineInfo(searchLineInfo);
170#ifdef DEBUG_COMMAND_PARSER
171 qDebug() <<
" Add searchLineInfo" << searchLineInfo << mSearchLineInfo;
175 info.type = mKeyList.
value(key);
182void SearchLineCommand::parseSearchLineCommand(
const QString &str)
184 mSearchLineInfo.clear();
188 SearchLineInfo searchLineInfo;
191 for (
int i = 0, total = str.
length(); i < total; ++i) {
194#ifdef DEBUG_COMMAND_PARSER
195 qDebug() <<
" tmp ! " << tmp;
197 const SearchLineCommand::SearchLineInfo newInfo = isAnotherInfo(tmp, searchLineInfo);
198 if (newInfo.type != Unknown) {
200 searchLineInfo = newInfo;
203#ifdef DEBUG_COMMAND_PARSER
204 qDebug() <<
" contains " << tmp;
208 }
else if (hasSubType(tmp)) {
209 searchLineInfo.type = HasStateOrAttachment;
216 const SearchLineCommand::SearchLineInfo newInfo = isAnotherInfo(tmp, searchLineInfo);
217 if (newInfo.type != Unknown) {
219 searchLineInfo = newInfo;
221 }
else if (mKeyList.
contains(tmp)) {
222 searchLineInfo.type = mKeyList.
value(tmp);
225#ifdef DEBUG_COMMAND_PARSER
226 qDebug() <<
" is space " <<
"pare" << parentheses <<
" tmp " << tmp <<
"searchLineInfo.type " << searchLineInfo.type
227 <<
" searchLineInfo.argument.isEmpty() " << searchLineInfo.argument.
isEmpty();
229 if (tmp.
isEmpty() && hasSubType(searchLineInfo.type) && parentheses == 0) {
230#ifdef DEBUG_COMMAND_PARSER
231 qDebug() <<
"clear invalid type" << searchLineInfo;
233 searchLineInfo.type = Unknown;
235 }
else if (hasSubType(searchLineInfo.type)) {
237 }
else if (searchLineInfo.type != Unknown && parentheses == 0) {
238 searchLineInfo.argument = tmp;
240#ifdef DEBUG_COMMAND_PARSER
241 qDebug() <<
"clear tmp argument " << searchLineInfo;
246 if (searchLineInfo.isValid() && parentheses == 0) {
247 appendSearchLineInfo(searchLineInfo);
248 searchLineInfo.clear();
253 if (parentheses > 1) {
256#ifdef DEBUG_COMMAND_PARSER
257 qDebug() <<
" parenthese ( equal " << parentheses;
261 if (parentheses > 0) {
264#ifdef DEBUG_COMMAND_PARSER
265 qDebug() <<
" parenthese ) equal " << parentheses;
267 if (parentheses == 0) {
268 searchLineInfo.argument = tmp;
270#ifdef DEBUG_COMMAND_PARSER
271 qDebug() <<
" new values " << searchLineInfo;
273 appendSearchLineInfo(searchLineInfo);
274 searchLineInfo.clear();
278#ifdef DEBUG_COMMAND_PARSER
279 qDebug() <<
" tmp " << tmp <<
" ch " << ch <<
"end";
283 if (searchLineInfo.type != Unknown) {
284 if (searchLineInfo.type == HasStateOrAttachment) {
285#ifdef DEBUG_COMMAND_PARSER
286 qDebug() <<
" type is HasStateOrAttachment";
289 searchLineInfo.type = mKeyList.
value(tmp);
290 appendSearchLineInfo(searchLineInfo);
294#ifdef DEBUG_COMMAND_PARSER
295 qDebug() <<
" add as original searchLineInfo" << searchLineInfo;
297 const SearchLineCommand::SearchLineInfo newInfo = isAnotherInfo(tmp, searchLineInfo);
298 if (newInfo.type != Unknown) {
299 searchLineInfo = newInfo;
301 searchLineInfo.argument = tmp;
303 appendSearchLineInfo(searchLineInfo);
308 searchLineInfo.type = Literal;
309 searchLineInfo.argument = tmp;
310 appendSearchLineInfo(searchLineInfo);
313#ifdef DEBUG_COMMAND_PARSER
314 qDebug() <<
" END " << mSearchLineInfo;
321void SearchLineCommand::appendSearchLineInfo(SearchLineInfo searchLineInfo)
323 if (searchLineInfo.mustBeUnique()) {
324 if (mSearchLineInfo.contains(searchLineInfo)) {
325#ifdef DEBUG_COMMAND_PARSER
326 qDebug() <<
" Already exist " << searchLineInfo;
331 mSearchLineInfo.
append(std::move(searchLineInfo));
336 return mSearchLineInfo;
341 mSearchLineInfo = newSearchLineInfo;
344void SearchLineCommand::SearchLineInfo::clear()
346 type = SearchLineCommand::SearchLineType::Unknown;
350bool SearchLineCommand::SearchLineInfo::isValid()
const
352 if (type == SearchLineType::Unknown || type == SearchLineCommand::HasStateOrAttachment) {
355 if (type == SearchLineType::Literal && !argument.isEmpty()) {
358 if (hasSubType(type) && !argument.isEmpty()) {
361 if (!hasSubType(type) && argument.isEmpty()) {
367bool SearchLineCommand::SearchLineInfo::operator==(
const SearchLineInfo &other)
const
369 return type == other.type && argument == other.argument;
372bool SearchLineCommand::SearchLineInfo::isValidDate()
const
374 if (argument.isEmpty()) {
380bool SearchLineCommand::SearchLineInfo::mustBeUnique()
const
382 return type == HasAttachment || type == IsImportant || type == IsRead || type == IsUnRead || type == IsIgnored || type == IsHam || type == IsSpam
383 || type == IsWatched || type == IsReplied || type == IsForwarded;
386qint64 SearchLineCommand::SearchLineInfo::convertArgumentAsSize()
const
394 d <<
" type " << info.type;
395 d <<
" argument " << info.argument;
399#include "moc_searchlinecommand.cpp"
QString i18n(const char *text, const TYPE &arg...)
The implementation independent part of the MessageList library.
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
bool isSpace(char32_t ucs4)
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid() const const
bool isEmpty() const const
bool contains(const Key &key) const const
QList< Key > keys() const const
T value(const Key &key, const T &defaultValue) const const
QString & append(QChar ch)
const QChar at(qsizetype position) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString trimmed() const const