Mailcommon

filteractionstatus.cpp
1/*
2
3 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "filteractionstatus.h"
9#include <KLocalizedString>
10using namespace MailCommon;
11
12const Akonadi::MessageStatus MailCommon::FilterActionStatus::statuses[] = {Akonadi::MessageStatus::statusImportant(),
22
23const int MailCommon::FilterActionStatus::StatiCount = sizeof(MailCommon::FilterActionStatus::statuses) / sizeof(Akonadi::MessageStatus);
24
25FilterActionStatus::FilterActionStatus(const QString &name, const QString &label, QObject *parent)
27{
28 // if you change this list, also update
29 // FilterActionSetStatus::statuses above
30 mParameterList.append(QString());
31 mParameterList.append(i18nc("msg status", "Important"));
32 mParameterList.append(i18nc("msg status", "Read"));
33 mParameterList.append(i18nc("msg status", "Unread"));
34 mParameterList.append(i18nc("msg status", "Replied"));
35 mParameterList.append(i18nc("msg status", "Forwarded"));
36 mParameterList.append(i18nc("msg status", "Watched"));
37 mParameterList.append(i18nc("msg status", "Ignored"));
38 mParameterList.append(i18nc("msg status", "Spam"));
39 mParameterList.append(i18nc("msg status", "Ham"));
40 mParameterList.append(i18nc("msg status", "Action Item"));
41
42 mParameter = mParameterList.at(0);
43}
44
45SearchRule::RequiredPart FilterActionStatus::requiredPart() const
46{
48}
49
50bool FilterActionStatus::isEmpty() const
51{
52 return mParameter.isEmpty();
53}
54
55QString FilterActionStatus::realStatusString(const QString &statusStr)
56{
57 QString result(statusStr);
58
59 if (result.size() == 2) {
60 result.remove(QLatin1Char('U'));
61 }
62
63 return result;
64}
65
66void FilterActionStatus::argsFromString(const QString &argsStr)
67{
68 if (argsStr.length() == 1) {
70
71 for (int i = 0; i < FilterActionStatus::StatiCount; ++i) {
72 status = statuses[i];
73 if (realStatusString(status.statusStr()) == QLatin1StringView(argsStr.toLatin1())) {
74 mParameter = mParameterList.at(i + 1);
75 return;
76 }
77 }
78 }
79
80 mParameter = mParameterList.at(0);
81}
82
83QString FilterActionStatus::argsAsString() const
84{
85 const int index = mParameterList.indexOf(mParameter);
86 if (index < 1) {
87 return {};
88 }
89
90 return realStatusString(FilterActionStatus::statuses[index - 1].statusStr());
91}
92
93QString FilterActionStatus::displayString() const
94{
95 return label() + QLatin1StringView(" \"") + mParameter + QLatin1StringView("\"");
96}
97
98QString FilterActionStatus::informationAboutNotValidAction() const
99{
100 return i18n("Status is missing.");
101}
102
103#include "moc_filteractionstatus.cpp"
static const MessageStatus statusRead()
static const MessageStatus statusUnread()
static const MessageStatus statusSpam()
static const MessageStatus statusReplied()
static const MessageStatus statusImportant()
static const MessageStatus statusWatched()
static const MessageStatus statusForwarded()
static const MessageStatus statusToAct()
static const MessageStatus statusIgnored()
static const MessageStatus statusHam()
Abstract base class for filter actions with a fixed set of string parameters.
QString label() const
Returns i18n'd label, ie.
RequiredPart
Possible required parts.
Definition searchrule.h:70
Q_SCRIPTABLE CaptureState status()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString name(StandardAction id)
QString label(StandardShortcut id)
The filter dialog.
const_reference at(qsizetype i) const const
bool isEmpty() const const
qsizetype length() const const
QByteArray toLatin1() const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.