filter.h 3.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/******************************************************************************
 *
 *  Copyright 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *******************************************************************************/

Laurent Montel's avatar
Laurent Montel committed
21
22
#ifndef MESSAGELIST_CORE_FILTER_H
#define MESSAGELIST_CORE_FILTER_H
23
24
25
26
27
28
29
30
31

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

#include <Akonadi/KMime/MessageStatus>
#include <Collection>
#include "widgets/quicksearchline.h"

Laurent Montel's avatar
Laurent Montel committed
32
33
namespace MessageList {
namespace Core {
34
35
36
37
38
39
40
41
42
43
44
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
45
    explicit Filter(QObject *parent = nullptr);
46
47
48
49
50
51

public:
    /**
    * 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
52
    Q_REQUIRED_RESULT bool match(const MessageItem *item) const;
53
54
55
56

    /**
    * Returns the currently set status mask
    */
Laurent Montel's avatar
Laurent Montel committed
57
    Q_REQUIRED_RESULT QVector<Akonadi::MessageStatus> status() const
58
59
60
61
62
63
64
    {
        return mStatus;
    }

    /**
    * Sets the status mask for this filter.
    */
Laurent Montel's avatar
Laurent Montel committed
65
    void setStatus(const QVector<Akonadi::MessageStatus> &lstStatus)
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    {
        mStatus = lstStatus;
    }

    /**
    * Sets the current folder of this filter.
    */
    void setCurrentFolder(const Akonadi::Collection &collection);

    /**
    * Returns the currently set search string.
    */
    const QString &searchString() const
    {
        return mSearchString;
    }

    /**
    * Sets the search string for this filter.
    */
    void setSearchString(const QString &search, QuickSearchLine::SearchOptions options);

    /**
    * Returns the currently set MessageItem::Tag id
    */
    const QString &tagId() const
    {
        return mTagId;
    }

    /**
    * Sets the id of a MessageItem::Tag that the matching messages must contain.
    */
    void setTagId(const QString &tagId)
    {
        mTagId = tagId;
    }

    /**
    * Clears this filter (sets status to 0, search string and tag id to empty strings)
    */
    void clear();

    /**
    * 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
113
    Q_REQUIRED_RESULT bool isEmpty() const;
114

Laurent Montel's avatar
Laurent Montel committed
115
    Q_REQUIRED_RESULT QuickSearchLine::SearchOptions currentOptions() const;
116
117
118
119
120
Q_SIGNALS:
    void finished();

private:
    bool containString(const QString &searchInString) const;
Laurent Montel's avatar
Laurent Montel committed
121
    QVector<Akonadi::MessageStatus> mStatus;    ///< Messages must match these statuses, if non 0
122
123
124
125
126
127
128
129
130
131
    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.
    Akonadi::Collection mCurrentFolder;
    QSet<qint64> mMatchingItemIds;
    QuickSearchLine::SearchOptions mOptions;
    QStringList mSearchList;
};
} // namespace Core
} // namespace MessageList

Laurent Montel's avatar
Laurent Montel committed
132
#endif //!__MESSAGELIST_CORE_FILTER_H