summaryrefslogtreecommitdiffstats
path: root/kshowmail/kcmconfigs/filtersetupitem.h
blob: 1d1bf02e99ffb6072f7f88ac8e964781bda24c6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//
// C++ Interface: filtersetupitem
//
// Description:
//
//
// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef FILTERSETUPITEM_H
#define FILTERSETUPITEM_H

//KDE headers
#include <klistview.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>

//KShowmail headers
#include "../constants.h"
#include "../types.h"

using namespace Types;

/**
 * @brief This class is used in ConfigFilter to show the available filters in the list view and to store a filter setup.
 * @author Ulrich Weigelt <ulrich.weigelt@gmx.de>
 */
class FilterSetupItem : public KListViewItem
{

  public:

    /**
     * Column Numbers.
     */
    enum Column{ ColNumber = 0, ColName = 1, ColAction = 2 };

    /**
     * General Constructor
     * @param parent the list view
     */
    FilterSetupItem( KListView* parent );

    /**
     * Constructor
     * @param parent the list view
     * @param num filter number
     */
    FilterSetupItem( KListView* parent, uint num );

    /**
     * Destructor
     */
    ~FilterSetupItem();

    /**
     * Sets the filter name.
     * @param name filter name
     * @see name
     * @see getName
     */
    void setName( QString name );

    /**
     * Returns the name of this filter.
     * @return filter name
     * @see name
     * @see setName
     */
    QString getName() const;

    /**
     * Sets the filter number.
     * @param number filter number.
     * @see number
     * @see getNumber
     */
    void setNumber( uint number );

    /**
     * Returns the filter number.
     * @return filter number
     * @see number
     * @see setNumber
     */
    uint getNumber() const;

    /**
     * Sets the action. See constants.h for valid values (CONFIG_VALUE_FILTER_ACTION...).
     * @param action
     * @see getAction
     * @see action
     */
    void setAction( int action );

    /**
     * Returns the action of this filter.
     * See constants.h for possible values (CONFIG_VALUE_FILTER_ACTION...).
     * @return action code
     * @see setAction
     * @see action
     */
    int getAction() const;

    /**
     * Sets the mailbox of a move action.
     * @param mailbox name of the mailbox
     * @see setMailBox
     * @see mailbox
     */
    void setMailBox( QString mailbox );

    /**
     * Returns the mailbox name of a move action if this action is selected. Otherwise it returns an empty string.
     * @return mailbox name
     * @see setMailBox
     * @see mailbox
     */
    QString getMailBox() const;

    /**
     * Sets the criteria linkage.
     * Valid values are CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL (all criterias have to satisy) or CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY (at least one criteria has to satisy ).
     * @param linkage criteria linkage
     * @see linkage
     */
    void setCriteriaLinkage( int linkage );

    /**
     * Returns the criteria linkage.
     * Possible values are CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL (all criterias have to satisy) or CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY (at least one criteria has to satisy ).
     * @return criteria linkage
     * @see setCriteriaLinkage
     * @see linkage
     */
    int getCriteriaLinkage() const;

    /**
     * Sets the criteria list.
     * @param list criteria list
     * @see criteriaList
     * @see getCriteriaList
     * @see Types::FilterCriteriaList_Type
     */
    void setCriteriaList( FilterCriteriaList_Type list );

    /**
     * Returns the criteria list.
     * @return criteria list
     * @see criteriaList
     * @see setCriteriaList
     * @see Types::FilterCriteriaList_Type
     */
    FilterCriteriaList_Type getCriteriaList() const;

    /**
     * Saves the settings to the configuration file.
     * The group is named CONFIG_GROUP_FILTER + filter number, e.g. Filter12.
     */
    void save();

    /**
     * Reimplemantation of QListViewItem::compare.
     * Compares this list view item to i using the column col in ascending order. Reutrns <0 if this item is less than i,
     * 0 if they are equal and >0 if this item is greater than i. The parameter ascneding will be ignored.
     * @param i pointer to the second view item
     * @param col number of the sorted column
     * @param ascending ignored
     */
    virtual int compare( QListViewItem* i, int col, bool ascending ) const;

    /**
     * Reads the settings from the config file.
     * The group is named CONFIG_GROUP_FILTER + filter number, e.g. Filter12.
     */
    void load();


  private:

    /**
     * filter name
     */
    QString name;

    /**
     * Connector to the configuration file
     */
    KConfig* config;

    /**
     * List of filter criterias.
     */
    FilterCriteriaList_Type criteriaList;

    /**
     * Filter Action
     * See constants.h for valid values (CONFIG_VALUE_FILTER_ACTION...).
     */
    int action;

    /**
     * Contains the mailbox name if the move action is selected.
     */
    QString mailbox;

    /**
     * Filter Number.
     * The filters will be showed and run through in ascending order. The first number is "0".
     */
    uint number;

    /**
     * Criteria Linkage.
     * Valid values are CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL (all criterias have to satisy) or CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY (at least one criteria has to satisy ).
     */
    int linkage;

  protected:

    /**
     * Initializes the object.
     */
    void init();

    /**
     * Updates the text of the rule column.
     */
    void updateActionColumn();




};

#endif