kmail

filterlog.h
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 TQt library by Trolltech AS, Norway (or with modified versions
00021     of TQt that use the same license as TQt), 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     TQt.  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 <tqobject.h>
00033 #include <tqstringlist.h>
00034 #include <tqstylesheet.h>
00035 
00036 namespace KMail {
00037 
00053   class FilterLog : public TQObject
00054   {
00055     Q_OBJECT
00056   
00057 
00058     public:
00060       static FilterLog * instance();
00061       
00063       enum ContentType 
00064       { 
00065         meta          = 1, 
00066         patternDesc   = 2, 
00067         ruleResult    = 4, 
00068         patternResult = 8, 
00069         appliedAction = 16
00070       };
00071       
00072       
00074       bool isLogging() { return mLogging; };
00076       void setLogging( bool active )
00077       {
00078         mLogging = active; 
00079         emit logStateChanged();
00080       };
00081       
00082       
00084       void setMaxLogSize( long size = -1 );
00085       long getMaxLogSize() { return mMaxLogSize; };
00086       
00087       
00089       void setContentTypeEnabled( ContentType contentType, bool b )
00090       { 
00091         if ( b )
00092           mAllowedTypes |= contentType;
00093         else
00094           mAllowedTypes &= ~contentType;
00095         emit logStateChanged();
00096       };
00097 
00099       bool isContentTypeEnabled( ContentType contentType )
00100       { 
00101         return mAllowedTypes & contentType; 
00102       };
00103 
00104       
00106       void add( TQString logEntry, ContentType contentType );
00108       void addSeparator() { add( "------------------------------", meta ); };
00110       void clear() 
00111       {
00112         mLogEntries.clear(); 
00113         mCurrentLogSize = 0;
00114         emit logShrinked();
00115       };
00116       
00117       
00119       const TQStringList & getLogEntries() { return mLogEntries; };
00121       void dump();
00123       bool saveToFile( TQString fileName );
00124       
00126       virtual ~FilterLog();
00127       
00128       static TQString recode( const TQString & plain ) { return TQStyleSheet::escape(plain); };
00129       
00130     signals:
00131       void logEntryAdded( TQString );
00132       void logShrinked();
00133       void logStateChanged();
00134 
00135     protected:
00137       FilterLog();
00138       
00140       TQStringList mLogEntries;
00141       
00143       bool mLogging;
00144       
00148       long mMaxLogSize;
00149       long mCurrentLogSize;
00150       
00152       int mAllowedTypes;
00153       
00154       void checkLogSize();
00155       
00156     private:
00157       static FilterLog * mSelf;
00158   };
00159 
00160 } // namespace KMail
00161 
00162 #endif // KMAIL_FILTERLOG_H