Messagelib

filter.h
1 /******************************************************************************
2  *
3  * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <[email protected]>
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 
22 namespace MessageList
23 {
24 namespace Core
25 {
26 class 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  */
32 class Filter : public QObject
33 {
34  Q_OBJECT
35 
36 public:
37  explicit Filter(QObject *parent = nullptr);
38 
39 public:
40  /**
41  * Returns true if the specified parameters match this filter and false otherwise.
42  * The msg pointer must not be null.
43  */
44  Q_REQUIRED_RESULT bool match(const MessageItem *item) const;
45 
46  /**
47  * Returns the currently set status mask
48  */
49  Q_REQUIRED_RESULT QVector<Akonadi::MessageStatus> status() const;
50 
51  /**
52  * Sets the status mask for this filter.
53  */
54  void setStatus(const QVector<Akonadi::MessageStatus> &lstStatus);
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  Q_REQUIRED_RESULT 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  Q_REQUIRED_RESULT 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  Q_REQUIRED_RESULT bool isEmpty() const;
91 
92  Q_REQUIRED_RESULT QuickSearchLine::SearchOptions currentOptions() const;
93 
94  void save(const KSharedConfig::Ptr &config, const QString &filtername, const QString &iconName, int numFilter = -1);
95  Q_REQUIRED_RESULT static Filter *load(const KSharedConfig::Ptr &config, int filternumber);
96  void generateRandomIdentifier();
97  Q_REQUIRED_RESULT QString identifier() const;
98  void setIdentifier(const QString &newIdentifier);
99 
100  Q_REQUIRED_RESULT const QString &filterName() const;
101  void setFilterName(const QString &newFilterName);
102 
103  void setOptions(QuickSearchLine::SearchOptions newOptions);
104 
105  Q_REQUIRED_RESULT static Filter *loadFromConfigGroup(const KConfigGroup &newGroup);
106  Q_REQUIRED_RESULT const QString &iconName() const;
107  void setIconName(const QString &newIconName);
108 
109 Q_SIGNALS:
110  void finished();
111 
112 private:
113  Q_REQUIRED_RESULT bool containString(const QString &searchInString) const;
114  QVector<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 
128 MESSAGELIST_EXPORT QDebug operator<<(QDebug d, const MessageList::Core::Filter &t);
Q_OBJECTQ_OBJECT
The MessageItem class.
Definition: messageitem.h:34
void setTagId(const QString &tagId)
Sets the id of a MessageItem::Tag that the matching messages must contain.
Definition: filter.cpp:286
const QString & searchString() const
Returns the currently set search string.
Definition: filter.cpp:150
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
void setCurrentFolder(const Akonadi::Collection &collection)
Sets the current folder of this filter.
Definition: filter.cpp:145
void clear()
Clears this filter (sets status to 0, search string and tag id to empty strings)
Definition: filter.cpp:136
void setSearchString(const QString &search, QuickSearchLine::SearchOptions options)
Sets the search string for this filter.
Definition: filter.cpp:217
const QString & tagId() const
Returns the currently set MessageItem::Tag id.
Definition: filter.cpp:281
void setStatus(const QVector< Akonadi::MessageStatus > &lstStatus)
Sets the status mask for this filter.
Definition: filter.cpp:114
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:119
Q_SIGNALSQ_SIGNALS
QVector< Akonadi::MessageStatus > status() const
Returns the currently set status mask.
Definition: filter.cpp:109
This class is responsible of matching messages that should be displayed in the View.
Definition: filter.h:44
QObject * parent() const const
bool match(const MessageItem *item) const
Returns true if the specified parameters match this filter and false otherwise.
Definition: filter.cpp:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:02:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.