kmail

filterlog.h
1 /*
2  This file is part of KMail.
3  Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
4 
5  KMail is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  KMail is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 
18  In addition, as a special exception, the copyright holders give
19  permission to link the code of this program with any edition of
20  the TQt library by Trolltech AS, Norway (or with modified versions
21  of TQt that use the same license as TQt), and distribute linked
22  combinations including the two. You must obey the GNU General
23  Public License in all respects for all of the code used other than
24  TQt. If you modify this file, you may extend this exception to
25  your version of the file, but you are not obligated to do so. If
26  you do not wish to do so, delete this exception statement from
27  your version.
28 */
29 #ifndef KMAIL_FILTERLOG_H
30 #define KMAIL_FILTERLOG_H
31 
32 #include <tqobject.h>
33 #include <tqstringlist.h>
34 #include <tqstylesheet.h>
35 
36 namespace KMail {
37 
53  class FilterLog : public TQObject
54  {
55  Q_OBJECT
56  TQ_OBJECT
57 
58  public:
60  static FilterLog * instance();
61 
64  {
65  meta = 1,
66  patternDesc = 2,
67  ruleResult = 4,
68  patternResult = 8,
69  appliedAction = 16
70  };
71 
72 
74  bool isLogging() { return mLogging; };
76  void setLogging( bool active )
77  {
78  mLogging = active;
79  emit logStateChanged();
80  };
81 
82 
84  void setMaxLogSize( long size = -1 );
85  long getMaxLogSize() { return mMaxLogSize; };
86 
87 
89  void setContentTypeEnabled( ContentType contentType, bool b )
90  {
91  if ( b )
92  mAllowedTypes |= contentType;
93  else
94  mAllowedTypes &= ~contentType;
95  emit logStateChanged();
96  };
97 
99  bool isContentTypeEnabled( ContentType contentType )
100  {
101  return mAllowedTypes & contentType;
102  };
103 
104 
106  void add( TQString logEntry, ContentType contentType );
108  void addSeparator() { add( "------------------------------", meta ); };
110  void clear()
111  {
112  mLogEntries.clear();
113  mCurrentLogSize = 0;
114  emit logShrinked();
115  };
116 
117 
119  const TQStringList & getLogEntries() { return mLogEntries; };
121  void dump();
123  bool saveToFile( TQString fileName );
124 
126  virtual ~FilterLog();
127 
128  static TQString recode( const TQString & plain ) { return TQStyleSheet::escape(plain); };
129 
130  signals:
131  void logEntryAdded( TQString );
132  void logShrinked();
133  void logStateChanged();
134 
135  protected:
137  FilterLog();
138 
140  TQStringList mLogEntries;
141 
143  bool mLogging;
144 
149  long mCurrentLogSize;
150 
153 
154  void checkLogSize();
155 
156  private:
157  static FilterLog * mSelf;
158  };
159 
160 } // namespace KMail
161 
162 #endif // KMAIL_FILTERLOG_H