kmail

filterlog.h

Go to the documentation of this file.
00001 /*
00002     This file is part of KMail.
00003     Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018     In addition, as a special exception, the copyright holders give
00019     permission to link the code of this program with any edition of
00020     the Qt library by Trolltech AS, Norway (or with modified versions
00021     of Qt that use the same license as Qt), and distribute linked
00022     combinations including the two.  You must obey the GNU General
00023     Public License in all respects for all of the code used other than
00024     Qt.  If you modify this file, you may extend this exception to
00025     your version of the file, but you are not obligated to do so.  If
00026     you do not wish to do so, delete this exception statement from
00027     your version.
00028 */
00029 #ifndef KMAIL_FILTERLOG_H
00030 #define KMAIL_FILTERLOG_H
00031 
00032 #include <qobject.h>
00033 #include <qstringlist.h>
00034 #include <qstylesheet.h>
00035 
00036 namespace KMail {
00037 
00053   class FilterLog : public QObject
00054   {
00055     Q_OBJECT
00056 
00057     public:
00059       static FilterLog * instance();
00060       
00062       enum ContentType 
00063       { 
00064         meta          = 1, 
00065         patternDesc   = 2, 
00066         ruleResult    = 4, 
00067         patternResult = 8, 
00068         appliedAction = 16
00069       };
00070       
00071       
00073       bool isLogging() { return mLogging; };
00075       void setLogging( bool active )
00076       {
00077         mLogging = active; 
00078         emit logStateChanged();
00079       };
00080       
00081       
00083       void setMaxLogSize( long size = -1 );
00084       long getMaxLogSize() { return mMaxLogSize; };
00085       
00086       
00088       void setContentTypeEnabled( ContentType contentType, bool b )
00089       { 
00090         if ( b )
00091           mAllowedTypes |= contentType;
00092         else
00093           mAllowedTypes &= ~contentType;
00094         emit logStateChanged();
00095       };
00096 
00098       bool isContentTypeEnabled( ContentType contentType )
00099       { 
00100         return mAllowedTypes & contentType; 
00101       };
00102 
00103       
00105       void add( QString logEntry, ContentType contentType );
00107       void addSeparator() { add( "------------------------------", meta ); };
00109       void clear() 
00110       {
00111         mLogEntries.clear(); 
00112         mCurrentLogSize = 0;
00113         emit logShrinked();
00114       };
00115       
00116       
00118       const QStringList & getLogEntries() { return mLogEntries; };
00120       void dump();
00122       bool saveToFile( QString fileName );
00123       
00125       virtual ~FilterLog();
00126       
00127       static QString recode( const QString & plain ) { return QStyleSheet::escape(plain); };
00128       
00129     signals:
00130       void logEntryAdded( QString );
00131       void logShrinked();
00132       void logStateChanged();
00133 
00134     protected:
00136       FilterLog();
00137       
00139       QStringList mLogEntries;
00140       
00142       bool mLogging;
00143       
00147       long mMaxLogSize;
00148       long mCurrentLogSize;
00149       
00151       int mAllowedTypes;
00152       
00153       void checkLogSize();
00154       
00155     private:
00156       static FilterLog * mSelf;
00157   };
00158 
00159 } // namespace KMail
00160 
00161 #endif // KMAIL_FILTERLOG_H