Messagelib

filter.h
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 *
7 *******************************************************************************/
8
9#pragma once
10
11#include <QDebug>
12#include <QObject>
13#include <QSet>
14#include <QString>
15
16#include "messagelist_export.h"
17#include "widgets/quicksearchline.h"
18#include <Akonadi/Collection>
19#include <Akonadi/MessageStatus>
20#include <KSharedConfig>
21
22namespace MessageList
23{
24namespace Core
25{
26class MessageItem;
27
28/**
29 * This class is responsible of matching messages that should be displayed
30 * in the View. It's used mainly by Model and Widget.
31 */
32class Filter : public QObject
33{
35
36public:
37 explicit Filter(QObject *parent = nullptr);
38
39public:
40 /**
41 * Returns true if the specified parameters match this filter and false otherwise.
42 * The msg pointer must not be null.
43 */
44 [[nodiscard]] bool match(const MessageItem *item) const;
45
46 /**
47 * Returns the currently set status mask
48 */
50
51 /**
52 * Sets the status mask for this filter.
53 */
55
56 /**
57 * Sets the current folder of this filter.
58 */
59 void setCurrentFolder(const Akonadi::Collection &collection);
60
61 /**
62 * Returns the currently set search string.
63 */
64 [[nodiscard]] const QString &searchString() const;
65
66 /**
67 * Sets the search string for this filter.
68 */
69 void setSearchString(const QString &search, QuickSearchLine::SearchOptions options);
70
71 /**
72 * Returns the currently set MessageItem::Tag id
73 */
74 [[nodiscard]] const QString &tagId() const;
75
76 /**
77 * Sets the id of a MessageItem::Tag that the matching messages must contain.
78 */
79 void setTagId(const QString &tagId);
80
81 /**
82 * Clears this filter (sets status to 0, search string and tag id to empty strings)
83 */
84 void clear();
85
86 /**
87 * Returns true if this filter is empty (0 status mask, empty search string and empty tag)
88 * and it's useless to call match() that will always return true.
89 */
90 [[nodiscard]] bool isEmpty() const;
91
92 [[nodiscard]] QuickSearchLine::SearchOptions currentOptions() const;
93
94 void save(const KSharedConfig::Ptr &config, const QString &filtername, const QString &iconName, int numFilter = -1);
95 [[nodiscard]] static Filter *load(const KSharedConfig::Ptr &config, int filternumber);
96 void generateRandomIdentifier();
97 [[nodiscard]] QString identifier() const;
98 void setIdentifier(const QString &newIdentifier);
99
100 [[nodiscard]] const QString &filterName() const;
101 void setFilterName(const QString &newFilterName);
102
104
105 [[nodiscard]] static Filter *loadFromConfigGroup(const KConfigGroup &newGroup);
106 [[nodiscard]] const QString &iconName() const;
107 void setIconName(const QString &newIconName);
108
110 void finished();
111
112private:
113 [[nodiscard]] bool containString(const QString &searchInString) const;
114 QList<Akonadi::MessageStatus> mStatus; ///< Messages must match these statuses, if non 0
115 QString mSearchString; ///< Messages must match this search string, if not empty
116 QString mTagId; ///< Messages must have this tag, if not empty. Contains a tag url.
117 Akonadi::Collection mCurrentFolder;
118 QSet<qint64> mMatchingItemIds;
120 QStringList mSearchList;
121 QString mIdentifier;
122 QString mFilterName;
123 QString mIconName;
124};
125} // namespace Core
126} // namespace MessageList
127
128MESSAGELIST_EXPORT QDebug operator<<(QDebug d, const MessageList::Core::Filter &t);
This class is responsible of matching messages that should be displayed in the View.
Definition filter.h:33
const QString & tagId() const
Returns the currently set MessageItem::Tag id.
Definition filter.cpp:282
bool isEmpty() const
Returns true if this filter is empty (0 status mask, empty search string and empty tag) and it's usel...
Definition filter.cpp:120
void setTagId(const QString &tagId)
Sets the id of a MessageItem::Tag that the matching messages must contain.
Definition filter.cpp:287
void setSearchString(const QString &search, QuickSearchLine::SearchOptions options)
Sets the search string for this filter.
Definition filter.cpp:218
QList< Akonadi::MessageStatus > status() const
Returns the currently set status mask.
Definition filter.cpp:110
void clear()
Clears this filter (sets status to 0, search string and tag id to empty strings)
Definition filter.cpp:137
const QString & searchString() const
Returns the currently set search string.
Definition filter.cpp:151
bool match(const MessageItem *item) const
Returns true if the specified parameters match this filter and false otherwise.
Definition filter.cpp:70
void setStatus(const QList< Akonadi::MessageStatus > &lstStatus)
Sets the status mask for this filter.
Definition filter.cpp:115
void setCurrentFolder(const Akonadi::Collection &collection)
Sets the current folder of this filter.
Definition filter.cpp:146
The MessageItem class.
Definition messageitem.h:35
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.