Mailcommon

filtermanager.h
1/*
2 SPDX-FileCopyrightText: 2011 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "mailcommon_export.h"
10#include "mailfilter.h"
11
12#include <Akonadi/Item>
13#include <Akonadi/ServerManager>
14
15#include <QObject>
16
17namespace MailCommon
18{
19class FilterActionDict;
20
21/**
22 * @short A wrapper class that allows easy access to the mail filters
23 *
24 * This class communicates with the mailfilter agent via DBus.
25 */
26class MAILCOMMON_EXPORT FilterManager : public QObject
27{
28 Q_OBJECT
29
30public:
31 ~FilterManager() override;
32 /**
33 * Describes the list of filters.
34 */
35 enum FilterSet {
36 NoSet = 0x0,
37 Inbound = 0x1,
38 Outbound = 0x2,
39 Explicit = 0x4,
40 BeforeOutbound = 0x8,
41 AllFolders = 0x16, ///< Apply the filter on all folders, not just inbox
42 All = Inbound | BeforeOutbound | Outbound | Explicit | AllFolders
43 };
44
45 /**
46 * Returns the global filter manager object.
47 */
48 static FilterManager *instance();
49
50 /**
51 * Returns whether the filter manager is in a usable state.
52 */
53 [[nodiscard]] bool isValid() const;
54
55 /**
56 * Checks for existing filters with the @p name and extend the
57 * "name" to "name (i)" until no match is found for i=1..n
58 */
59 [[nodiscard]] QString createUniqueFilterName(const QString &name) const;
60
61 /**
62 * Returns the global filter action dictionary.
63 */
64 static FilterActionDict *filterActionDict();
65
66 /**
67 * Shows the filter log dialog.
68 *
69 * This is used to debug problems with filters.
70 */
71 void showFilterLogDialog(qlonglong windowId);
72
73 /// Apply filters interface
74
75 /**
76 * Applies filter with the given @p identifier on the message @p item.
77 * @return @c true on success, @c false otherwise.
78 */
79 void filter(const Akonadi::Item &item, const QString &identifier, const QString &resourceId) const;
80
81 /**
82 * Process given message item by applying the filter rules one by
83 * one. You can select which set of filters (incoming or outgoing)
84 * should be used.
85 *
86 * @param item The message item to process.
87 * @param set Select the filter set to use.
88 * @param account @c true if an account id is specified else @c false
89 * @param accountId The id of the resource that the message was retrieved from
90 */
91 void filter(const Akonadi::Item &item, FilterSet set = Inbound, bool account = false, const QString &resourceId = QString()) const;
92
93 /**
94 * Process all messages in given collection by applying the filters rules one
95 * by one. You can select which set of filters (incoming or outgoing)
96 * should be used.
97 */
98 void filter(const Akonadi::Collection &collection, FilterSet set = Explicit) const;
99
100 /**
101 * Apply specified filters on all messages in given collection
102 */
103 void filter(const Akonadi::Collection &collection, const QStringList &listFilters) const;
104
105 /**
106 * Process all messages in given collections by applying the filters rules one
107 * by one. You can select which set of filters (incoming or outgoing)
108 * should be used.
109 */
110 void filter(const Akonadi::Collection::List &collections, FilterSet set = Explicit) const;
111
112 /**
113 * Apply specified filters on all messages in given collection
114 */
115 void filter(const Akonadi::Collection::List &collections, const QStringList &listFilters, FilterSet set = Explicit) const;
116
117 /**
118 * Process given @p messages by applying the filter rules one by
119 * one. You can select which set of filters (incoming or outgoing)
120 * should be used.
121 *
122 * @param item The message item to process.
123 * @param set Select the filter set to use.
124 */
125 void filter(const Akonadi::Item::List &messages, FilterSet set = Explicit) const;
126
127 void filter(const Akonadi::Item::List &messages, SearchRule::RequiredPart requiredPart, const QStringList &listFilters) const;
128
129 /// Manage filters interface
130
131 /**
132 * Appends the list of @p filters to the current list of filters and
133 * write everything back into the configuration. The filter manager
134 * takes ownership of the filters in the list.
135 */
136 void appendFilters(const QList<MailCommon::MailFilter *> &filters, bool replaceIfNameExists = false);
137
138 /**
139 * Removes the given @p filter from the list.
140 * The filter object is not deleted.
141 */
142 void removeFilter(MailCommon::MailFilter *filter);
143
144 /**
145 * Replace the list of filters of the filter manager with the given list of @p filters.
146 * The manager takes ownership of the filters.
147 */
148 void setFilters(const QList<MailCommon::MailFilter *> &filters);
149
150 /**
151 * Returns the filter list of the manager.
152 */
153 [[nodiscard]] QList<MailCommon::MailFilter *> filters() const;
154
155 /**
156 * Should be called at the beginning of an filter list update.
157 */
158 void beginUpdate();
159
160 /**
161 * Should be called at the end of an filter list update.
162 */
163 void endUpdate();
164
165 [[nodiscard]] QMap<QUrl, QString> tagList() const;
166
167 [[nodiscard]] bool initialized() const;
168
169 void cleanup();
170private Q_SLOTS:
171 MAILCOMMON_NO_EXPORT void slotServerStateChanged(Akonadi::ServerManager::State);
172 MAILCOMMON_NO_EXPORT void slotFinishedTagListing(KJob *);
173 MAILCOMMON_NO_EXPORT void slotReadConfig();
174 MAILCOMMON_NO_EXPORT void updateTagList();
175
176 MAILCOMMON_NO_EXPORT void slotTagAdded(const Akonadi::Tag &);
177 MAILCOMMON_NO_EXPORT void slotTagChanged(const Akonadi::Tag &);
178 MAILCOMMON_NO_EXPORT void slotTagRemoved(const Akonadi::Tag &);
179
180Q_SIGNALS:
181 /**
182 * This signal is emitted whenever the filter list has been updated.
183 */
185
186 void tagListingFinished();
187
188 void loadingFiltersDone();
189
190private:
191 MAILCOMMON_NO_EXPORT FilterManager();
192
193 class FilterManagerPrivate;
194 FilterManagerPrivate *const d;
195};
196}
List of known FilterAction-types.
A wrapper class that allows easy access to the mail filters.
void filtersChanged()
This signal is emitted whenever the filter list has been updated.
FilterSet
Describes the list of filters.
The MailFilter class.
Definition mailfilter.h:29
RequiredPart
Possible required parts.
Definition searchrule.h:70
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:49:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.