Mailcommon

kmfilterdialog.h
1/*
2 Filter Dialog
3
4 SPDX-FileCopyrightText: Marc Mutz <mutz@kde.org>
5 SPDX-FileCopyrightText: 2011-2024 Laurent Montel <montel@kde.org>
6
7 based upon work by Stefan Taferner <taferner@kde.org>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11
12#pragma once
13
14#include "filterimporterexporter.h"
15#include "mailcommon/filteraction.h"
16#include "mailcommon/searchpattern.h"
17#include "mailcommon_export.h"
18#include "mailfilter.h"
19
20#include <QDialog>
21
22#include <QList>
23
25class KIconButton;
27
28class QCheckBox;
29class QPushButton;
30class QRadioButton;
31class QPushButton;
32class QGroupBox;
33namespace MailCommon
34{
35class SearchPatternEdit;
36class FilterActionWidgetLister;
37class FolderRequester;
38class KMFilterAccountList;
39class KMFilterListBox;
40}
41
42class KJob;
43
44/**
45 * The filter dialog. This is a non-modal dialog used to manage the filters.
46 * It should only be called through KMFilterMgr::openDialog. The dialog
47 * consists of three main parts:
48 *
49 * @li The KMFilterListBox in the left half allows the user to
50 * select a filter to be displayed using the widgets on the right
51 * half. It also has buttons to delete filters, add new ones, to
52 * rename them and to change their order (maybe you will be able to
53 * move the filters around by dragging later, and to optimize the
54 * filters by trying to apply them to all locally available
55 * KMMessage in turn and thus profiling which filters (and which
56 * rules of the search patterns) matches most often and sorting the
57 * filter/rules list according to the results, but I first want the
58 * basic functionality in place).
59 *
60 * @li The SearchPatternEdit in the upper-right quarter allows
61 * the user to modify the filter criteria.
62 *
63 * @li The KMFilterActionEdit in the lower-right quarter allows
64 * the user to select the actions that will be executed for any
65 * message that matches the search pattern.
66 *
67 * @li (tbi) There will be another widget that will allow the user to
68 * select to which folders the filter may be applied and whether it
69 * should be applied on outbound or inbound message transfers or both
70 * or none (meaning the filter is only applied when the user
71 * explicitly hits CTRL-J). I'm not sure whether there should be a
72 * per-folder filter list or a single list where you can select the
73 * names of folders this rule will be applied to.
74 *
75 * Upon creating the dialog, a (deep) copy of the current filter list
76 * is made by KMFilterListBox. The changed filters are local to
77 * KMFilterListBox until the user clicks the 'Apply' button.
78 *
79 * NOTE: Though this dialog is non-modal, it completely ignores all
80 * the stuff that goes on behind the scenes with folders esp. folder
81 * creation, move and create. The widgets that depend on the filter
82 * list and the filters that use folders as parameters are not
83 * updated as you expect. I hope this will change sometime soon.
84 *
85 * KMFilterDialog supports the creation of new filters through context
86 * menus, dubbed "rapid filters". Call KMFilterMgr::createFilter
87 * to use this. That call will be delivered to this dialog, which in
88 * turn delivers it to the KMFilterListBox.
89 *
90 * If you change the (DocBook) anchor for the filter dialog help,
91 * make sure to change @p const @p QString @p KMFilterDialogHelpAnchor
92 * in kmfilterdlg.cpp accordingly.
93 *
94 * @short The filter dialog.
95 * @author Marc Mutz <mutz@kde.org>, based upon work by Stefan Taferner <taferner@kde.org>.
96 * @see MailCommon::MailFilter KMFilterActionEdit SearchPatternEdit KMFilterListBox
97 */
98namespace MailCommon
99{
100class MAILCOMMON_EXPORT KMFilterDialog : public QDialog
101{
102 Q_OBJECT
103
104public:
105 /**
106 * Creates the filter dialog. The only class which should be able
107 * to do this is KMFilterMgr. This ensures that there is only a
108 * single filter dialog.
109 */
110 explicit KMFilterDialog(const QList<KActionCollection *> &actionCollection, QWidget *parent = nullptr, bool createDummyFilter = true);
111
112 /**
113 * Called from KMFilterMgr. Creates a new filter and presets
114 * the first rule with "field equals value". Internally forwarded to
115 * KMFilterListBox::createFilter. You should instead call
116 * KMFilterMgr::createFilter.
117 */
118 void createFilter(const QByteArray &field, const QString &value);
119
120public Q_SLOTS:
121 /**
122 * Internally connected to KMFilterListBox::filterSelected.
123 * Just does a simple check and then calls
124 * SearchPatternEdit::setSearchPattern and
125 * KMFilterActionEdit::setActionList.
126 */
127 void slotFilterSelected(MailCommon::MailFilter *aFilter);
128
129 /** Override QDialog::accept to allow disabling close */
130 void accept() override;
131
132protected Q_SLOTS:
133 void slotApplicabilityChanged();
134 void slotApplicableAccountsChanged();
135 void slotStopProcessingButtonToggled(bool aChecked);
136 void slotShortcutChanged(const QKeySequence &newSeq);
137 void slotConfigureToolbarButtonToggled(bool aChecked);
138 void slotFilterActionIconChanged(const QString &icon);
139 void slotReset();
140 void slotUpdateFilter();
141 void slotSaveSize();
142
143 /**
144 * Called when the dialog is closed (finished).
145 */
146 void slotFinished();
147
148 /**
149 * Update the list of accounts shown in the advanced tab.
150 */
151 void slotUpdateAccountList();
152
153 /**
154 * Called when a user clicks the import filters button. Pops up
155 * a dialog asking the user which file to import from and which
156 * of the filters in that file to import.
157 */
158 void slotImportFilter(QAction *);
159
160 /**
161 * Called when a user clicks the export filters button. Pops up
162 * a dialog asking the user which filters to export and which
163 * file to export to.
164 */
165 void slotExportFilters();
166
167 /**
168 * Called when a user decides to continue editing invalid filters
169 */
170 void slotDisableAccept();
171
172 /**
173 * Called whenever a change in the filters configuration is detected,
174 * to enable the Apply button.
175 */
176 void slotDialogUpdated();
177
178 /**
179 * Called wherenever the apply button is pressed.
180 */
181 void slotApply();
182
183 void slotRunFilters();
184
185 void slotFetchItemsForFolderDone(KJob *job);
186
187 void slotFolderChanged(const Akonadi::Collection &);
188
189private:
190 MAILCOMMON_NO_EXPORT void slotExportAsSieveScript();
191 MAILCOMMON_NO_EXPORT void slotHelp();
192 MAILCOMMON_NO_EXPORT void importFilters(MailCommon::FilterImporterExporter::FilterType type);
193
194protected:
195 bool event(QEvent *e) override;
196
197 /** The widget that contains the ListBox showing the filters, and the
198 controls to remove filters, add new ones and to change their order. */
199 KMFilterListBox *mFilterList = nullptr;
200
201 /** The widget that allows editing of the filter pattern. */
202 MailCommon::SearchPatternEdit *mPatternEdit = nullptr;
203
204 /** The widget that allows editing of the filter actions. */
205 MailCommon::FilterActionWidgetLister *mActionLister = nullptr;
206
207 /** Lets the user select whether to apply this filter on
208 inbound/outbound messages, both, or only on explicit CTRL-J. */
209 QCheckBox *mApplyOnIn = nullptr;
210 QCheckBox *mApplyOnOut = nullptr;
211 QCheckBox *mApplyBeforeOut = nullptr;
212 QCheckBox *mApplyOnCtrlJ = nullptr;
213 QCheckBox *mApplyOnAllFolders = nullptr;
214
215 /** For a filter applied to inbound messages selects whether to apply
216 this filter to all accounts or to selected accounts only. */
217 QRadioButton *mApplyOnForAll = nullptr;
218 QRadioButton *mApplyOnForTraditional = nullptr;
219 QRadioButton *mApplyOnForChecked = nullptr;
220
221 /** ListView that shows the accounts in the advanced tab */
222 KMFilterAccountList *mAccountList = nullptr;
223
224 QCheckBox *mStopProcessingHere = nullptr;
225 QCheckBox *mConfigureShortcut = nullptr;
226 QCheckBox *mConfigureToolbar = nullptr;
227 KIconButton *mFilterActionIconButton = nullptr;
228 KKeySequenceWidget *mKeySeqWidget = nullptr;
229 QGroupBox *mAdvOptsGroup = nullptr;
230
231 MailCommon::MailFilter *mFilter = nullptr;
232 MailCommon::FolderRequester *mFolderRequester = nullptr;
233 QPushButton *mRunNow = nullptr;
234 QPushButton *mApplyButton = nullptr;
235 bool mDoNotClose = false;
236 bool mIgnoreFilterUpdates = true;
237 QWidget *mInMenuWidget = nullptr;
238};
239}
A container widget for a list of FilterActionWidgets.
The MailFilter class.
Definition mailfilter.h:29
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.