summaryrefslogtreecommitdiffstats
path: root/kshowmail/filteritemcriteria.h
blob: 0546c2f25ce5a4eca69dedda0842987f3697638c (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
//
// C++ Interface: filteritemcriteria
//
// Description:
//
//
// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef FILTERITEMCRITERIA_H
#define FILTERITEMCRITERIA_H

//TQt headers
#include <ntqstring.h>
#include <ntqregexp.h>

//KDE headers
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kdebug.h>

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

/**
 * @brief This is a criteria of a filter item.
 * For using create an object and call check().
 * It gets its configuration itself from the config file at creation time. You can't reload the setup.
 * @author Ulrich Weigelt <ulrich.weigelt@gmx.de>
 */
class FilterItemCriteria{

  public:

    /**
     * Constructor
     * @param FilterNr number of the filter item
     * @param CritNr number of this criteria
     */
    FilterItemCriteria( uint FilterNr, uint CritNr );

    /**
     * Destructor
     */
    ~FilterItemCriteria();

    /**
     * Checks for match.
     * @param from Sender
     * @param to Addressee
     * @param size Size
     * @param subject Subject
     * @param header Header
     * @param account Account
     * @return TRUE - the criteria matches; FALSE - the criteria doesn't match
     */
    bool check( TQString from, TQString to, uint size, TQString subject, TQString header, TQString account ) const;

    /**
     * Prints the settings.
     */
    void print() const;

  private:

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

    /**
     * Types of source.
     */
    enum Source_Type{ SrcFrom, SrcTo, SrcSize, SrcSubject, SrcHeader, SrcAccount };

    /**
     * Source of the criteria.
     */
    Source_Type source;

    /**
     * Text Condition Types
     */
    enum TextCondition_Type{ TxtCondContains, TxtCondNotContains, TxtCondEqual, TxtCondNotEqual, TxtCondRegExpr, TxtCondNotRegExpr };

    /**
     * Numeric Condition Types
     */
    enum NumCondition_Type{ NumCondEqual, NumCondNotEqual, NumCondGreater, NumCondGreaterEqual, NumCondLess, NumCondLessEqual };

    /**
     * Text Condition
     */
    TextCondition_Type txtCondition;

    /**
     * Numeric Condition
     */
    NumCondition_Type numCondition;

    /**
     * Text Value
     */
    TQString txtValue;

    /**
     * Numeric Value
     */
    uint numValue;

    /**
     * Case Sensitive; used by text condition
     */
    bool cs;

    /**
     * Filter number. Just for error messages.
     */
    uint FilterNumber;

    /**
     * Criteria number. Just for error messages.
     */
    uint CriteriaNumber;

  protected:

    /**
     * Compares a text value.
     * @param value Value to compare
     * @return TRUE - value matches; FALSE - value doesn't match
     */
    bool checkText( TQString value ) const;

    /**
     * Compares a numeric value.
     * @param value Value to compare
     * @return TRUE - value matches; FALSE - value doesn't match
     */
    bool checkNum( uint value ) const;
};

#endif