00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00095
00096
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
00119
00120
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
00129
00130
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 );
00137
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
00160
00161
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
00176
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
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"