File indexing completed on 2024-11-10 04:50:04
0001 /* 0002 0003 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "filteractionstatus.h" 0009 #include <KLocalizedString> 0010 using namespace MailCommon; 0011 0012 const Akonadi::MessageStatus MailCommon::FilterActionStatus::statuses[] = {Akonadi::MessageStatus::statusImportant(), 0013 Akonadi::MessageStatus::statusRead(), 0014 Akonadi::MessageStatus::statusUnread(), 0015 Akonadi::MessageStatus::statusReplied(), 0016 Akonadi::MessageStatus::statusForwarded(), 0017 Akonadi::MessageStatus::statusWatched(), 0018 Akonadi::MessageStatus::statusIgnored(), 0019 Akonadi::MessageStatus::statusSpam(), 0020 Akonadi::MessageStatus::statusHam(), 0021 Akonadi::MessageStatus::statusToAct()}; 0022 0023 const int MailCommon::FilterActionStatus::StatiCount = sizeof(MailCommon::FilterActionStatus::statuses) / sizeof(Akonadi::MessageStatus); 0024 0025 FilterActionStatus::FilterActionStatus(const QString &name, const QString &label, QObject *parent) 0026 : FilterActionWithStringList(name, label, parent) 0027 { 0028 // if you change this list, also update 0029 // FilterActionSetStatus::statuses above 0030 mParameterList.append(QString()); 0031 mParameterList.append(i18nc("msg status", "Important")); 0032 mParameterList.append(i18nc("msg status", "Read")); 0033 mParameterList.append(i18nc("msg status", "Unread")); 0034 mParameterList.append(i18nc("msg status", "Replied")); 0035 mParameterList.append(i18nc("msg status", "Forwarded")); 0036 mParameterList.append(i18nc("msg status", "Watched")); 0037 mParameterList.append(i18nc("msg status", "Ignored")); 0038 mParameterList.append(i18nc("msg status", "Spam")); 0039 mParameterList.append(i18nc("msg status", "Ham")); 0040 mParameterList.append(i18nc("msg status", "Action Item")); 0041 0042 mParameter = mParameterList.at(0); 0043 } 0044 0045 SearchRule::RequiredPart FilterActionStatus::requiredPart() const 0046 { 0047 return SearchRule::Envelope; 0048 } 0049 0050 bool FilterActionStatus::isEmpty() const 0051 { 0052 return mParameter.isEmpty(); 0053 } 0054 0055 QString FilterActionStatus::realStatusString(const QString &statusStr) 0056 { 0057 QString result(statusStr); 0058 0059 if (result.size() == 2) { 0060 result.remove(QLatin1Char('U')); 0061 } 0062 0063 return result; 0064 } 0065 0066 void FilterActionStatus::argsFromString(const QString &argsStr) 0067 { 0068 if (argsStr.length() == 1) { 0069 Akonadi::MessageStatus status; 0070 0071 for (int i = 0; i < FilterActionStatus::StatiCount; ++i) { 0072 status = statuses[i]; 0073 if (realStatusString(status.statusStr()) == QLatin1StringView(argsStr.toLatin1())) { 0074 mParameter = mParameterList.at(i + 1); 0075 return; 0076 } 0077 } 0078 } 0079 0080 mParameter = mParameterList.at(0); 0081 } 0082 0083 QString FilterActionStatus::argsAsString() const 0084 { 0085 const int index = mParameterList.indexOf(mParameter); 0086 if (index < 1) { 0087 return {}; 0088 } 0089 0090 return realStatusString(FilterActionStatus::statuses[index - 1].statusStr()); 0091 } 0092 0093 QString FilterActionStatus::displayString() const 0094 { 0095 return label() + QLatin1StringView(" \"") + mParameter + QLatin1StringView("\""); 0096 } 0097 0098 QString FilterActionStatus::informationAboutNotValidAction() const 0099 { 0100 return i18n("Status is missing."); 0101 } 0102 0103 #include "moc_filteractionstatus.cpp"