kmail Library API Documentation

filterlogdlg.cpp

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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 00030 #include "filterlogdlg.h" 00031 #include "filterlog.h" 00032 00033 #include <kdebug.h> 00034 #include <kdeversion.h> 00035 #include <kfiledialog.h> 00036 #include <klocale.h> 00037 #include <kmessagebox.h> 00038 00039 #include <qcheckbox.h> 00040 #include <qlabel.h> 00041 #include <qspinbox.h> 00042 #include <qstringlist.h> 00043 #include <qtextedit.h> 00044 #include <qvbox.h> 00045 #include <qwhatsthis.h> 00046 #include <qvgroupbox.h> 00047 00048 #include <errno.h> 00049 #include <X11/Xlib.h> 00050 #include <X11/Xatom.h> 00051 00052 using namespace KMail; 00053 00054 00055 FilterLogDialog::FilterLogDialog( QWidget * parent ) 00056 : KDialogBase( parent, "FilterLogDlg", false, i18n( "Filter Log Viewer" ), 00057 User1|User2|Close, Close, true, KStdGuiItem::clear(), KStdGuiItem::saveAs() ) 00058 { 00059 setWFlags( WDestructiveClose ); 00060 QVBox *page = makeVBoxMainWidget(); 00061 00062 mTextEdit = new QTextEdit( page ); 00063 mTextEdit->setReadOnly( true ); 00064 mTextEdit->setWordWrap( QTextEdit::NoWrap ); 00065 mTextEdit->setTextFormat( QTextEdit::LogText ); 00066 00067 QStringList logEntries = FilterLog::instance()->getLogEntries(); 00068 for ( QStringList::Iterator it = logEntries.begin(); 00069 it != logEntries.end(); ++it ) 00070 { 00071 mTextEdit->append( *it ); 00072 } 00073 00074 mLogActiveBox = new QCheckBox( i18n("&Log filter activities"), page ); 00075 mLogActiveBox->setChecked( FilterLog::instance()->isLogging() ); 00076 connect( mLogActiveBox, SIGNAL(clicked()), 00077 this, SLOT(slotSwitchLogState(void)) ); 00078 QWhatsThis::add( mLogActiveBox, 00079 i18n( "You can turn logging of filter activities on and off here. " 00080 "Of course, log data is collected and shown only when logging " 00081 "is turned on. " ) ); 00082 00083 mLogDetailsBox = new QVGroupBox( i18n( "Logging Details" ), page ); 00084 mLogDetailsBox->setEnabled( mLogActiveBox->isChecked() ); 00085 connect( mLogActiveBox, SIGNAL( toggled( bool ) ), 00086 mLogDetailsBox, SLOT( setEnabled( bool ) ) ); 00087 00088 mLogPatternDescBox = new QCheckBox( i18n("Log pattern description"), 00089 mLogDetailsBox ); 00090 mLogPatternDescBox->setChecked( 00091 FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) ); 00092 connect( mLogPatternDescBox, SIGNAL(clicked()), 00093 this, SLOT(slotChangeLogDetail(void)) ); 00094 // TODO 00095 //QWhatsThis::add( mLogPatternDescBox, 00096 // i18n( "" ) ); 00097 00098 mLogRuleEvaluationBox = new QCheckBox( i18n("Log filter &rule evaluation"), 00099 mLogDetailsBox ); 00100 mLogRuleEvaluationBox->setChecked( 00101 FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) ); 00102 connect( mLogRuleEvaluationBox, SIGNAL(clicked()), 00103 this, SLOT(slotChangeLogDetail(void)) ); 00104 QWhatsThis::add( mLogRuleEvaluationBox, 00105 i18n( "You can control the feedback in the log concerning the " 00106 "evaluation of the filter rules of applied filters: " 00107 "having this option checked will give detailed feedback " 00108 "for each single filter rule; alternatively, only " 00109 "feedback about the result of the evaluation of all rules " 00110 "of a single filter will be given." ) ); 00111 00112 mLogPatternResultBox = new QCheckBox( i18n("Log filter pattern evaluation"), 00113 mLogDetailsBox ); 00114 mLogPatternResultBox->setChecked( 00115 FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) ); 00116 connect( mLogPatternResultBox, SIGNAL(clicked()), 00117 this, SLOT(slotChangeLogDetail(void)) ); 00118 // TODO 00119 //QWhatsThis::add( mLogPatternResultBox, 00120 // i18n( "" ) ); 00121 00122 mLogFilterActionBox = new QCheckBox( i18n("Log filter actions"), 00123 mLogDetailsBox ); 00124 mLogFilterActionBox->setChecked( 00125 FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) ); 00126 connect( mLogFilterActionBox, SIGNAL(clicked()), 00127 this, SLOT(slotChangeLogDetail(void)) ); 00128 // TODO 00129 //QWhatsThis::add( mLogFilterActionBox, 00130 // i18n( "" ) ); 00131 00132 QHBox * hbox = new QHBox( page ); 00133 new QLabel( i18n("Log size limit:"), hbox ); 00134 mLogMemLimitSpin = new QSpinBox( hbox ); 00135 mLogMemLimitSpin->setMinValue( 1 ); 00136 mLogMemLimitSpin->setMaxValue( 1024 * 256 ); // 256 MB 00137 // value in the QSpinBox is in KB while it's in Byte in the FilterLog 00138 mLogMemLimitSpin->setValue( FilterLog::instance()->getMaxLogSize() / 1024 ); 00139 mLogMemLimitSpin->setSuffix( " KB" ); 00140 mLogMemLimitSpin->setSpecialValueText( i18n("unlimited") ); 00141 connect( mLogMemLimitSpin, SIGNAL(valueChanged(int)), 00142 this, SLOT(slotChangeLogMemLimit(int)) ); 00143 QWhatsThis::add( mLogMemLimitSpin, 00144 i18n( "Collecting log data uses memory to temporarily store the " 00145 "log data; here you can limit the maximum amount of memory " 00146 "to be used: if the size of the collected log data exceeds " 00147 "this limit then the oldest data will be discarded until " 00148 "the limit is no longer exceeded. " ) ); 00149 00150 connect(FilterLog::instance(), SIGNAL(logEntryAdded(QString)), 00151 this, SLOT(slotLogEntryAdded(QString))); 00152 connect(FilterLog::instance(), SIGNAL(logShrinked(void)), 00153 this, SLOT(slotLogShrinked(void))); 00154 connect(FilterLog::instance(), SIGNAL(logStateChanged(void)), 00155 this, SLOT(slotLogStateChanged(void))); 00156 00157 setInitialSize( QSize( 500, 500 ) ); 00158 #if !KDE_IS_VERSION( 3, 2, 91 ) 00159 // HACK - KWin keeps all dialogs on top of their mainwindows, but that's probably 00160 // wrong (#76026), and should be done only for modals. CVS HEAD should get 00161 // proper fix in KWin (see also kmfldsearch.cpp) 00162 XDeleteProperty( qt_xdisplay(), winId(), XA_WM_TRANSIENT_FOR ); 00163 #endif 00164 } 00165 00166 00167 void FilterLogDialog::slotLogEntryAdded( QString logEntry ) 00168 { 00169 mTextEdit->append( logEntry ); 00170 } 00171 00172 00173 void FilterLogDialog::slotLogShrinked() 00174 { 00175 // limit the size of the shown log lines as soon as 00176 // the log has reached it's memory limit 00177 if ( mTextEdit->maxLogLines() == -1 ) 00178 mTextEdit->setMaxLogLines( mTextEdit->lines() ); 00179 } 00180 00181 00182 void FilterLogDialog::slotLogStateChanged() 00183 { 00184 mLogActiveBox->setChecked( FilterLog::instance()->isLogging() ); 00185 mLogPatternDescBox->setChecked( 00186 FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) ); 00187 mLogRuleEvaluationBox->setChecked( 00188 FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) ); 00189 mLogPatternResultBox->setChecked( 00190 FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) ); 00191 mLogFilterActionBox->setChecked( 00192 FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) ); 00193 00194 // value in the QSpinBox is in KB while it's in Byte in the FilterLog 00195 int newLogSize = FilterLog::instance()->getMaxLogSize() / 1024; 00196 if ( mLogMemLimitSpin->value() != newLogSize ) 00197 mLogMemLimitSpin->setValue( newLogSize ); 00198 } 00199 00200 00201 void FilterLogDialog::slotChangeLogDetail() 00202 { 00203 if ( mLogPatternDescBox->isChecked() != 00204 FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) ) 00205 FilterLog::instance()->setContentTypeEnabled( FilterLog::patternDesc, 00206 mLogPatternDescBox->isChecked() ); 00207 00208 if ( mLogRuleEvaluationBox->isChecked() != 00209 FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) ) 00210 FilterLog::instance()->setContentTypeEnabled( FilterLog::ruleResult, 00211 mLogRuleEvaluationBox->isChecked() ); 00212 00213 if ( mLogPatternResultBox->isChecked() != 00214 FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) ) 00215 FilterLog::instance()->setContentTypeEnabled( FilterLog::patternResult, 00216 mLogPatternResultBox->isChecked() ); 00217 00218 if ( mLogFilterActionBox->isChecked() != 00219 FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) ) 00220 FilterLog::instance()->setContentTypeEnabled( FilterLog::appliedAction, 00221 mLogFilterActionBox->isChecked() ); 00222 } 00223 00224 00225 void FilterLogDialog::slotSwitchLogState() 00226 { 00227 FilterLog::instance()->setLogging( mLogActiveBox->isChecked() ); 00228 } 00229 00230 00231 void FilterLogDialog::slotChangeLogMemLimit( int value ) 00232 { 00233 FilterLog::instance()->setMaxLogSize( value * 1024 ); 00234 } 00235 00236 00237 void FilterLogDialog::slotUser1() 00238 { 00239 FilterLog::instance()->clear(); 00240 mTextEdit->clear(); 00241 } 00242 00243 00244 void FilterLogDialog::slotUser2() 00245 { 00246 QString fileName; 00247 KFileDialog fdlg( QString::null, QString::null, this, 0, true ); 00248 00249 fdlg.setMode( KFile::File ); 00250 fdlg.setSelection( "kmail-filter.log" ); 00251 fdlg.setOperationMode( KFileDialog::Saving ); 00252 if ( fdlg.exec() ) 00253 { 00254 fileName = fdlg.selectedFile(); 00255 if ( !FilterLog::instance()->saveToFile( fileName ) ) 00256 { 00257 KMessageBox::error( this, 00258 i18n( "Could not write the file %1:\n" 00259 "\"%2\" is the detailed error description." ) 00260 .arg( fileName, 00261 QString::fromLocal8Bit( strerror( errno ) ) ), 00262 i18n( "KMail Error" ) ); 00263 } 00264 } 00265 } 00266 00267 00268 #include "filterlogdlg.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:45 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003