Mailcommon

filteractionstatus.cpp
1 /*
2 
3  SPDX-FileCopyrightText: 2012-2022 Laurent Montel <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "filteractionstatus.h"
9 #include <KLocalizedString>
10 using namespace MailCommon;
11 
12 const Akonadi::MessageStatus MailCommon::FilterActionStatus::statuses[] = {Akonadi::MessageStatus::statusImportant(),
22 
23 const int MailCommon::FilterActionStatus::StatiCount = sizeof(MailCommon::FilterActionStatus::statuses) / sizeof(Akonadi::MessageStatus);
24 
25 FilterActionStatus::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 
45 SearchRule::RequiredPart FilterActionStatus::requiredPart() const
46 {
47  return SearchRule::Envelope;
48 }
49 
50 bool FilterActionStatus::isEmpty() const
51 {
52  return mParameter.isEmpty();
53 }
54 
55 QString 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 
66 void 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()) == QLatin1String(argsStr.toLatin1())) {
74  mParameter = mParameterList.at(i + 1);
75  return;
76  }
77  }
78  }
79 
80  mParameter = mParameterList.at(0);
81 }
82 
83 QString 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 
93 QString FilterActionStatus::displayString() const
94 {
95  return label() + QLatin1String(" \"") + mParameter + QLatin1String("\"");
96 }
97 
98 QString FilterActionStatus::informationAboutNotValidAction() const
99 {
100  return i18n("Status is missing.");
101 }
static const MessageStatus statusImportant()
static const MessageStatus statusToAct()
Abstract base class for filter actions with a fixed set of string parameters.
static const MessageStatus statusWatched()
static const MessageStatus statusSpam()
static const MessageStatus statusUnread()
QByteArray toLatin1() const const
static const MessageStatus statusForwarded()
QString i18n(const char *text, const TYPE &arg...)
RequiredPart
Possible required parts.
Definition: searchrule.h:68
NETWORKMANAGERQT_EXPORT NetworkManager::Status status()
int length() const const
static const MessageStatus statusIgnored()
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QString label(StandardShortcut id)
QString name(StandardShortcut id)
static const MessageStatus statusReplied()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
static const MessageStatus statusRead()
static const MessageStatus statusHam()
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.