Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 11eef2f6 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Introduce 'Apply to inbound emails in all folders' filter option

Differential Revision: https://phabricator.kde.org/D7134
parent 438182f2
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.6.40")
set(PIM_VERSION "5.6.41")
project(mailcommon VERSION ${PIM_VERSION})
......
......@@ -51,7 +51,8 @@ public:
Outbound = 0x2,
Explicit = 0x4,
BeforeOutbound = 0x8,
All = Inbound | BeforeOutbound | Outbound | Explicit
AllFolders = 0x16, ///< Apply the filter on all folders, not just inbox
All = Inbound | BeforeOutbound | Outbound | Explicit | AllFolders
};
/**
......
......@@ -264,28 +264,35 @@ KMFilterDialog::KMFilterDialog(const QList<KActionCollection *> &actionCollectio
= new QCheckBox(i18n("Apply this filter on manual &filtering"), mAdvOptsGroup);
gl->addWidget(mApplyOnCtrlJ, 6, 0, 1, 4);
mApplyOnAllFolders = new QCheckBox(i18n("Apply this filter on inbound emails in all folders"), mAdvOptsGroup);
mApplyOnAllFolders->setToolTip(i18n("<p>The filter will be applied on inbound emails from all folders "
"belonging to all accounts selected above. This is useful when using local filters "
"with IMAP accounts where new emails may have already been moved to different folders "
"by server-side filters.</p>"));
gl->addWidget(mApplyOnAllFolders, 7, 0, 1, 4);
mStopProcessingHere
= new QCheckBox(i18n("If this filter &matches, stop processing here"), mAdvOptsGroup);
gl->addWidget(mStopProcessingHere, 7, 0, 1, 4);
gl->addWidget(mStopProcessingHere, 8, 0, 1, 4);
mConfigureShortcut
= new QCheckBox(i18n("Add this filter to the Apply Filter menu"), mAdvOptsGroup);
gl->addWidget(mConfigureShortcut, 8, 0, 1, 2);
gl->addWidget(mConfigureShortcut, 9, 0, 1, 2);
QLabel *keyButtonLabel = new QLabel(i18n("Shortcut:"), mAdvOptsGroup);
keyButtonLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
gl->addWidget(keyButtonLabel, 8, 2, 1, 1);
gl->addWidget(keyButtonLabel, 9, 2, 1, 1);
mKeySeqWidget = new KKeySequenceWidget(mAdvOptsGroup);
mKeySeqWidget->setObjectName(QStringLiteral("FilterShortcutSelector"));
gl->addWidget(mKeySeqWidget, 8, 3, 1, 1);
gl->addWidget(mKeySeqWidget, 9, 3, 1, 1);
mKeySeqWidget->setEnabled(false);
mKeySeqWidget->setModifierlessAllowed(true);
mKeySeqWidget->setCheckActionCollections(actionCollection);
mConfigureToolbar
= new QCheckBox(i18n("Additionally add this filter to the toolbar"), mAdvOptsGroup);
gl->addWidget(mConfigureToolbar, 9, 0, 1, 4);
gl->addWidget(mConfigureToolbar, 10, 0, 1, 4);
mConfigureToolbar->setEnabled(false);
QWidget *hbox = new QWidget(mAdvOptsGroup);
......@@ -303,7 +310,7 @@ KMFilterDialog::KMFilterDialog(const QList<KActionCollection *> &actionCollectio
mFilterActionIconButton->setIcon(QIcon::fromTheme(QStringLiteral("system-run")));
mFilterActionIconButton->setEnabled(false);
gl->addWidget(hbox, 10, 0, 1, 4);
gl->addWidget(hbox, 11, 0, 1, 4);
mAdvOptsGroup->setLayout(gl);
}
......@@ -335,6 +342,7 @@ KMFilterDialog::KMFilterDialog(const QList<KActionCollection *> &actionCollectio
connect(mApplyOnForTraditional, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged);
connect(mApplyOnForChecked, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged);
connect(mApplyBeforeOut, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged);
connect(mApplyOnAllFolders, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged);
connect(mApplyOnOut, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged);
connect(mApplyOnCtrlJ, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged);
connect(mAccountList, &KMFilterAccountList::itemChanged, this, &KMFilterDialog::slotApplicableAccountsChanged);
......@@ -529,6 +537,7 @@ void KMFilterDialog::slotFilterSelected(MailFilter *aFilter)
qCDebug(MAILCOMMON_LOG) << "apply on outbound ==" << aFilter->applyOnOutbound();
qCDebug(MAILCOMMON_LOG) << "apply before outbound == " << aFilter->applyBeforeOutbound();
qCDebug(MAILCOMMON_LOG) << "apply on explicit ==" << aFilter->applyOnExplicit();
qCDebug(MAILCOMMON_LOG) << "apply on all folders inboud == " << aFilter->applyOnAllFoldersInbound();
// NOTE: setting these values activates the slot that sets them in
// the filter! So make sure we have the correct values _before_ we
......@@ -538,6 +547,7 @@ void KMFilterDialog::slotFilterSelected(MailFilter *aFilter)
const bool applyOnTraditional = aFilter->applicability() == MailFilter::ButImap;
const bool applyBeforeOut = aFilter->applyBeforeOutbound();
const bool applyOnOut = aFilter->applyOnOutbound();
const bool applyOnAllFolders = aFilter->applyOnAllFoldersInbound();
const bool applyOnExplicit = aFilter->applyOnExplicit();
const bool stopHere = aFilter->stopProcessingHere();
const bool configureShortcut = aFilter->configureShortcut();
......@@ -550,6 +560,7 @@ void KMFilterDialog::slotFilterSelected(MailFilter *aFilter)
mApplyOnForTraditional->setEnabled(applyOnIn);
mApplyOnForChecked->setEnabled(applyOnIn);
mApplyOnForAll->setChecked(applyOnForAll);
mApplyOnAllFolders->setChecked(applyOnAllFolders);
mApplyOnForTraditional->setChecked(applyOnTraditional);
mApplyOnForChecked->setChecked(!applyOnForAll && !applyOnTraditional);
mAccountList->setEnabled(mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked());
......@@ -589,6 +600,7 @@ void KMFilterDialog::slotApplicabilityChanged()
mFilter->setApplyBeforeOutbound(mApplyBeforeOut->isChecked());
mFilter->setApplyOnOutbound(mApplyOnOut->isChecked());
mFilter->setApplyOnExplicit(mApplyOnCtrlJ->isChecked());
mFilter->setApplyOnAllFoldersInbound(mApplyOnAllFolders->isChecked());
if (mApplyOnForAll->isChecked()) {
mFilter->setApplicability(MailFilter::All);
mFilter->clearApplyOnAccount();
......@@ -615,6 +627,7 @@ void KMFilterDialog::slotApplicabilityChanged()
<< (mFilter->applyOnInbound() ? "incoming " : "")
<< (mFilter->applyOnOutbound() ? "outgoing " : "")
<< (mFilter->applyBeforeOutbound() ? "before_outgoing " : "")
<< (mFilter->applyOnAllFoldersInbound() ? "all folders inboud " : "")
<< (mFilter->applyOnExplicit() ? "explicit CTRL-J" : "");
}
}
......
......@@ -224,7 +224,7 @@ protected:
/** Lets the user select whether to apply this filter on
inbound/outbound messages, both, or only on explicit CTRL-J. */
QCheckBox *mApplyOnIn, *mApplyOnOut, *mApplyBeforeOut, *mApplyOnCtrlJ;
QCheckBox *mApplyOnIn, *mApplyOnOut, *mApplyBeforeOut, *mApplyOnCtrlJ, *mApplyOnAllFolders;
/** For a filter applied to inbound messages selects whether to apply
this filter to all accounts or to selected accounts only. */
......
......@@ -54,6 +54,7 @@ MailFilter::MailFilter()
bApplyBeforeOutbound = false;
bApplyOnOutbound = false;
bApplyOnExplicit = true;
bApplyOnAllFolders = false;
bStopProcessingHere = true;
bConfigureShortcut = false;
bConfigureToolbar = false;
......@@ -76,6 +77,7 @@ MailFilter::MailFilter(const MailFilter &aFilter)
bApplyBeforeOutbound = aFilter.applyBeforeOutbound();
bApplyOnOutbound = aFilter.applyOnOutbound();
bApplyOnExplicit = aFilter.applyOnExplicit();
bApplyOnAllFolders = aFilter.applyOnAllFoldersInbound();
bStopProcessingHere = aFilter.stopProcessingHere();
bConfigureShortcut = aFilter.configureShortcut();
bConfigureToolbar = aFilter.configureToolbar();
......@@ -236,6 +238,16 @@ bool MailFilter::applyOnExplicit() const
return bApplyOnExplicit;
}
void MailFilter::setApplyOnAllFoldersInbound(bool aApply)
{
bApplyOnAllFolders = aApply;
}
bool MailFilter::applyOnAllFoldersInbound() const
{
return bApplyOnAllFolders;
}
void MailFilter::setApplicability(AccountType aApply)
{
mApplicability = aApply;
......@@ -402,12 +414,14 @@ bool MailFilter::readConfig(const KConfigGroup &config, bool interactive)
bApplyOnOutbound = false;
bApplyOnInbound = true;
bApplyOnExplicit = true;
bApplyOnAllFolders = false;
mApplicability = ButImap;
} else {
bApplyBeforeOutbound = bool(sets.contains(QStringLiteral("before-send-mail")));
bApplyOnInbound = bool(sets.contains(QStringLiteral("check-mail")));
bApplyOnOutbound = bool(sets.contains(QStringLiteral("send-mail")));
bApplyOnExplicit = bool(sets.contains(QStringLiteral("manual-filtering")));
bApplyOnAllFolders = bool(sets.contains(QStringLiteral("all-folders")));
mApplicability = (AccountType)config.readEntry(
"Applicability", (int)ButImap);
}
......@@ -530,6 +544,9 @@ void MailFilter::writeConfig(KConfigGroup &config, bool exportFilter) const
if (bApplyOnExplicit) {
sets.append(QStringLiteral("manual-filtering"));
}
if (bApplyOnAllFolders) {
sets.append(QStringLiteral("all-folders"));
}
config.writeEntry("apply-on", sets);
config.writeEntry("StopProcessingHere", bStopProcessingHere);
......@@ -642,6 +659,9 @@ const QString MailFilter::asString() const
if (bApplyOnExplicit) {
result += " Explicit";
}
if (bApplyOnAllFolders) {
result += " All Folders";
}
result += '\n';
if (bApplyOnInbound && mApplicability == All) {
result += "This filter applies to all accounts.\n";
......@@ -689,6 +709,7 @@ QDataStream &MailCommon::operator<<(QDataStream &stream, const MailCommon::MailF
stream << filter.bApplyBeforeOutbound;
stream << filter.bApplyOnOutbound;
stream << filter.bApplyOnExplicit;
stream << filter.bApplyOnAllFolders;
stream << filter.bStopProcessingHere;
stream << filter.bConfigureShortcut;
stream << filter.bConfigureToolbar;
......@@ -708,6 +729,7 @@ QDataStream &MailCommon::operator>>(QDataStream &stream, MailCommon::MailFilter
bool bApplyBeforeOutbound;
bool bApplyOnOutbound;
bool bApplyOnExplicit;
bool bApplyOnAllFolders;
bool bStopProcessingHere;
bool bConfigureShortcut;
bool bConfigureToolbar;
......@@ -747,6 +769,7 @@ QDataStream &MailCommon::operator>>(QDataStream &stream, MailCommon::MailFilter
stream >> bApplyBeforeOutbound;
stream >> bApplyOnOutbound;
stream >> bApplyOnExplicit;
stream >> bApplyOnAllFolders;
stream >> bStopProcessingHere;
stream >> bConfigureShortcut;
stream >> bConfigureToolbar;
......@@ -760,6 +783,7 @@ QDataStream &MailCommon::operator>>(QDataStream &stream, MailCommon::MailFilter
filter.bApplyBeforeOutbound = bApplyBeforeOutbound;
filter.bApplyOnOutbound = bApplyOnOutbound;
filter.bApplyOnExplicit = bApplyOnExplicit;
filter.bApplyOnAllFolders = bApplyOnAllFolders;
filter.bStopProcessingHere = bStopProcessingHere;
filter.bConfigureShortcut = bConfigureShortcut;
filter.bConfigureToolbar = bConfigureToolbar;
......
......@@ -199,6 +199,16 @@ public:
*/
void setApplicability(AccountType aApply = All);
/** Sets whether the filter should be applied on inbound emails in all
folders, not just Inbox.
*/
void setApplyOnAllFoldersInbound(bool aApply = true);
/** Returns whether the filter should be applied on inbound emails in all
folders, not just Inbox.
*/
bool applyOnAllFoldersInbound() const;
/** @return true if this filter should be applied on
inbound messages for all accounts, or false if this filter
is to be applied on a specified set of accounts only.
......@@ -327,6 +337,7 @@ private:
bool bApplyBeforeOutbound : 1;
bool bApplyOnOutbound : 1;
bool bApplyOnExplicit : 1;
bool bApplyOnAllFolders : 1;
bool bStopProcessingHere : 1;
bool bConfigureShortcut : 1;
bool bConfigureToolbar : 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment