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 "core/widgets/searchlinecommand.h"
17#include "messagelist_export.h"
18#include "widgets/quicksearchline.h"
19#include <Akonadi/Collection>
20#include <Akonadi/MessageStatus>
21#include <KSharedConfig>
22
23namespace MessageList
24{
25namespace Core
26{
27class MessageItem;
28
29/**
30 * This class is responsible of matching messages that should be displayed
31 * in the View. It's used mainly by Model and Widget.
32 */
33class Filter : public QObject
34{
36
37public:
38 explicit Filter(QObject *parent = nullptr);
39
40public:
41 /**
42 * Returns true if the specified parameters match this filter and false otherwise.
43 * The msg pointer must not be null.
44 */
45 [[nodiscard]] bool match(const MessageItem *item) const;
46
47 /**
48 * Returns the currently set status mask
49 */
50 [[nodiscard]] QList<Akonadi::MessageStatus> status() const;
51
52 /**
53 * Sets the status mask for this filter.
54 */
55 void setStatus(const QList<Akonadi::MessageStatus> &lstStatus);
56
57 /**
58 * Sets the current folder of this filter.
59 */
60 void setCurrentFolder(const Akonadi::Collection &collection);
61
62 /**
63 * Returns the currently set search string.
64 */
65 [[nodiscard]] const QString &searchString() const;
66
67 /**
68 * Sets the search string for this filter.
69 */
71
72 /**
73 * Returns the currently set MessageItem::Tag id
74 */
75 [[nodiscard]] const QString &tagId() const;
76
77 /**
78 * Sets the id of a MessageItem::Tag that the matching messages must contain.
79 */
80 void setTagId(const QString &tagId);
81
82 /**
83 * Clears this filter (sets status to 0, search string and tag id to empty strings)
84 */
85 void clear();
86
87 /**
88 * Returns true if this filter is empty (0 status mask, empty search string and empty tag)
89 * and it's useless to call match() that will always return true.
90 */
91 [[nodiscard]] bool isEmpty() const;
92
93 [[nodiscard]] SearchMessageByButtons::SearchOptions currentOptions() const;
94
95 void save(const KSharedConfig::Ptr &config, const QString &filtername, const QString &iconName, int numFilter = -1);
96 [[nodiscard]] static Filter *load(const KSharedConfig::Ptr &config, int filternumber);
97 void generateRandomIdentifier();
98 [[nodiscard]] QString identifier() const;
99 void setIdentifier(const QString &newIdentifier);
100
101 [[nodiscard]] const QString &filterName() const;
102 void setFilterName(const QString &newFilterName);
103
104 void setOptions(SearchMessageByButtons::SearchOptions newOptions);
105
106 [[nodiscard]] static Filter *loadFromConfigGroup(const KConfigGroup &newGroup);
107 [[nodiscard]] const QString &iconName() const;
108 void setIconName(const QString &newIconName);
109
110 void setSearchString(const SearchLineCommand &command);
112 void finished();
113
114private:
115 [[nodiscard]] bool containString(const QString &searchInString) const;
116 QList<Akonadi::MessageStatus> mStatus; ///< Messages must match these statuses, if non 0
117 QString mSearchString; ///< Messages must match this search string, if not empty
118 QString mTagId; ///< Messages must have this tag, if not empty. Contains a tag url.
119 Akonadi::Collection mCurrentFolder;
120 QSet<qint64> mMatchingItemIds;
122 QStringList mSearchList;
123 QString mIdentifier;
124 QString mFilterName;
125 QString mIconName;
126};
127} // namespace Core
128} // namespace MessageList
129
130MESSAGELIST_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:34
const QString & tagId() const
Returns the currently set MessageItem::Tag id.
Definition filter.cpp:438
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:443
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
void setSearchString(const QString &search, SearchMessageByButtons::SearchOptions options)
Sets the search string for this filter.
Definition filter.cpp:372
The MessageItem class.
Definition messageitem.h:35
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.