filter.h 3.63 KB
Newer Older
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
 *
 *******************************************************************************/

Laurent Montel's avatar
Laurent Montel committed
9
#pragma once
10

Laurent Montel's avatar
Laurent Montel committed
11
#include <QDebug>
12
13
14
15
#include <QObject>
#include <QSet>
#include <QString>

Laurent Montel's avatar
Laurent Montel committed
16
#include "messagelist_export.h"
Laurent Montel's avatar
Laurent Montel committed
17
#include "widgets/quicksearchline.h"
18
19
#include <Akonadi/KMime/MessageStatus>
#include <Collection>
Laurent Montel's avatar
Laurent Montel committed
20
#include <KSharedConfig>
21

Laurent Montel's avatar
Laurent Montel committed
22
23
24
25
namespace MessageList
{
namespace Core
{
26
27
28
29
30
31
32
33
34
35
36
class MessageItem;

/**
 * This class is responsable of matching messages that should be displayed
 * in the View. It's used mainly by Model and Widget.
 */
class Filter : public QObject
{
    Q_OBJECT

public:
Laurent Montel's avatar
Laurent Montel committed
37
    explicit Filter(QObject *parent = nullptr);
38
39
40

public:
    /**
Laurent Montel's avatar
Laurent Montel committed
41
42
43
     * Returns true if the specified parameters match this filter and false otherwise.
     * The msg pointer must not be null.
     */
Laurent Montel's avatar
Laurent Montel committed
44
    Q_REQUIRED_RESULT bool match(const MessageItem *item) const;
45
46

    /**
Laurent Montel's avatar
Laurent Montel committed
47
48
     * Returns the currently set status mask
     */
Laurent Montel's avatar
Laurent Montel committed
49
    Q_REQUIRED_RESULT QVector<Akonadi::MessageStatus> status() const;
50
51

    /**
Laurent Montel's avatar
Laurent Montel committed
52
53
     * Sets the status mask for this filter.
     */
Laurent Montel's avatar
Laurent Montel committed
54
    void setStatus(const QVector<Akonadi::MessageStatus> &lstStatus);
55
56

    /**
Laurent Montel's avatar
Laurent Montel committed
57
58
     * Sets the current folder of this filter.
     */
59
60
61
    void setCurrentFolder(const Akonadi::Collection &collection);

    /**
Laurent Montel's avatar
Laurent Montel committed
62
63
     * Returns the currently set search string.
     */
Laurent Montel's avatar
Laurent Montel committed
64
    Q_REQUIRED_RESULT const QString &searchString() const;
65
66

    /**
Laurent Montel's avatar
Laurent Montel committed
67
68
     * Sets the search string for this filter.
     */
69
70
71
    void setSearchString(const QString &search, QuickSearchLine::SearchOptions options);

    /**
Laurent Montel's avatar
Laurent Montel committed
72
73
     * Returns the currently set MessageItem::Tag id
     */
Laurent Montel's avatar
Laurent Montel committed
74
    Q_REQUIRED_RESULT const QString &tagId() const;
75
76

    /**
Laurent Montel's avatar
Laurent Montel committed
77
78
     * Sets the id of a MessageItem::Tag that the matching messages must contain.
     */
Laurent Montel's avatar
Laurent Montel committed
79
    void setTagId(const QString &tagId);
80
81

    /**
Laurent Montel's avatar
Laurent Montel committed
82
83
     * Clears this filter (sets status to 0, search string and tag id to empty strings)
     */
84
85
86
    void clear();

    /**
Laurent Montel's avatar
Laurent Montel committed
87
88
89
     * Returns true if this filter is empty (0 status mask, empty search string and empty tag)
     * and it's useless to call match() that will always return true.
     */
Laurent Montel's avatar
Laurent Montel committed
90
    Q_REQUIRED_RESULT bool isEmpty() const;
91

Laurent Montel's avatar
Laurent Montel committed
92
    Q_REQUIRED_RESULT QuickSearchLine::SearchOptions currentOptions() const;
Laurent Montel's avatar
Laurent Montel committed
93
94

    void save(const KSharedConfig::Ptr &config, const QString &filtername);
Laurent Montel's avatar
Laurent Montel committed
95
    static Q_REQUIRED_RESULT Filter *load(const KSharedConfig::Ptr &config, int filternumber);
96
97
98
99
100
101
102
    void generateRandomIdentifier();
    Q_REQUIRED_RESULT QString identifier() const;
    void setIdentifier(const QString &newIdentifier);

    Q_REQUIRED_RESULT const QString &filterName() const;
    void setFilterName(const QString &newFilterName);

Laurent Montel's avatar
Laurent Montel committed
103
    void setOptions(QuickSearchLine::SearchOptions newOptions);
Laurent Montel's avatar
Laurent Montel committed
104

105
    static Q_REQUIRED_RESULT Filter *loadFromConfigGroup(const KConfigGroup &newGroup);
106
107
108
109
Q_SIGNALS:
    void finished();

private:
Laurent Montel's avatar
Laurent Montel committed
110
    Q_REQUIRED_RESULT bool containString(const QString &searchInString) const;
Laurent Montel's avatar
Laurent Montel committed
111
112
113
    QVector<Akonadi::MessageStatus> mStatus; ///< Messages must match these statuses, if non 0
    QString mSearchString; ///< Messages must match this search string, if not empty
    QString mTagId; ///< Messages must have this tag, if not empty. Contains a tag url.
114
115
116
117
    Akonadi::Collection mCurrentFolder;
    QSet<qint64> mMatchingItemIds;
    QuickSearchLine::SearchOptions mOptions;
    QStringList mSearchList;
118
119
    QString mIdentifier;
    QString mFilterName;
120
121
122
123
};
} // namespace Core
} // namespace MessageList

Laurent Montel's avatar
Laurent Montel committed
124
MESSAGELIST_EXPORT QDebug operator<<(QDebug d, const MessageList::Core::Filter &t);