filter.h 3.42 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
11
12
13
14

#include <QObject>
#include <QSet>
#include <QString>

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

Laurent Montel's avatar
Laurent Montel committed
20
21
22
23
namespace MessageList
{
namespace Core
{
24
25
26
27
28
29
30
31
32
33
34
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
35
    explicit Filter(QObject *parent = nullptr);
36
37
38

public:
    /**
Laurent Montel's avatar
Laurent Montel committed
39
40
41
     * 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
42
    Q_REQUIRED_RESULT bool match(const MessageItem *item) const;
43
44

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

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

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

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

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

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

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

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

    /**
Laurent Montel's avatar
Laurent Montel committed
85
86
87
     * 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
88
    Q_REQUIRED_RESULT bool isEmpty() const;
89

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

    void save(const KSharedConfig::Ptr &config, const QString &filtername);
Laurent Montel's avatar
Laurent Montel committed
93
    static Q_REQUIRED_RESULT Filter *load(const KSharedConfig::Ptr &config, int filternumber);
94
95
96
97
98
99
100
    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
101
102
    void setOptions(const QuickSearchLine::SearchOptions &newOptions);

103
104
105
106
Q_SIGNALS:
    void finished();

private:
Laurent Montel's avatar
Laurent Montel committed
107
    Q_REQUIRED_RESULT bool containString(const QString &searchInString) const;
Laurent Montel's avatar
Laurent Montel committed
108
109
110
    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.
111
112
113
114
    Akonadi::Collection mCurrentFolder;
    QSet<qint64> mMatchingItemIds;
    QuickSearchLine::SearchOptions mOptions;
    QStringList mSearchList;
115
116
    QString mIdentifier;
    QString mFilterName;
117
118
119
120
};
} // namespace Core
} // namespace MessageList