1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
/*
This file is part of KMail.
Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
KMail is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
KMail is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the TQt library by Trolltech AS, Norway (or with modified versions
of TQt that use the same license as TQt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
TQt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include "filterlogdlg.h"
#include "filterlog.h"
#include <kdebug.h>
#include <kdeversion.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqspinbox.h>
#include <tqstringlist.h>
#include <tqtextedit.h>
#include <tqvbox.h>
#include <tqwhatsthis.h>
#include <tqvgroupbox.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
using namespace KMail;
FilterLogDialog::FilterLogDialog( TQWidget * parent )
: KDialogBase( parent, "FilterLogDlg", false, i18n( "Filter Log Viewer" ),
User1|User2|Close, Close, true, KStdGuiItem::clear(), KStdGuiItem::saveAs() )
{
setWFlags( WDestructiveClose );
TQVBox *page = makeVBoxMainWidget();
mTextEdit = new TQTextEdit( page );
mTextEdit->setReadOnly( true );
mTextEdit->setWordWrap( TQTextEdit::NoWrap );
mTextEdit->setTextFormat( TQTextEdit::LogText );
TQStringList logEntries = FilterLog::instance()->getLogEntries();
for ( TQStringList::Iterator it = logEntries.begin();
it != logEntries.end(); ++it )
{
mTextEdit->append( *it );
}
mLogActiveBox = new TQCheckBox( i18n("&Log filter activities"), page );
mLogActiveBox->setChecked( FilterLog::instance()->isLogging() );
connect( mLogActiveBox, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotSwitchLogState(void)) );
TQWhatsThis::add( mLogActiveBox,
i18n( "You can turn logging of filter activities on and off here. "
"Of course, log data is collected and shown only when logging "
"is turned on. " ) );
mLogDetailsBox = new TQVGroupBox( i18n( "Logging Details" ), page );
mLogDetailsBox->setEnabled( mLogActiveBox->isChecked() );
connect( mLogActiveBox, TQT_SIGNAL( toggled( bool ) ),
mLogDetailsBox, TQT_SLOT( setEnabled( bool ) ) );
mLogPatternDescBox = new TQCheckBox( i18n("Log pattern description"),
mLogDetailsBox );
mLogPatternDescBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) );
connect( mLogPatternDescBox, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotChangeLogDetail(void)) );
// TODO
//TQWhatsThis::add( mLogPatternDescBox,
// i18n( "" ) );
mLogRuleEvaluationBox = new TQCheckBox( i18n("Log filter &rule evaluation"),
mLogDetailsBox );
mLogRuleEvaluationBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) );
connect( mLogRuleEvaluationBox, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotChangeLogDetail(void)) );
TQWhatsThis::add( mLogRuleEvaluationBox,
i18n( "You can control the feedback in the log concerning the "
"evaluation of the filter rules of applied filters: "
"having this option checked will give detailed feedback "
"for each single filter rule; alternatively, only "
"feedback about the result of the evaluation of all rules "
"of a single filter will be given." ) );
mLogPatternResultBox = new TQCheckBox( i18n("Log filter pattern evaluation"),
mLogDetailsBox );
mLogPatternResultBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) );
connect( mLogPatternResultBox, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotChangeLogDetail(void)) );
// TODO
//TQWhatsThis::add( mLogPatternResultBox,
// i18n( "" ) );
mLogFilterActionBox = new TQCheckBox( i18n("Log filter actions"),
mLogDetailsBox );
mLogFilterActionBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) );
connect( mLogFilterActionBox, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotChangeLogDetail(void)) );
// TODO
//TQWhatsThis::add( mLogFilterActionBox,
// i18n( "" ) );
TQHBox * hbox = new TQHBox( page );
new TQLabel( i18n("Log size limit:"), hbox );
mLogMemLimitSpin = new TQSpinBox( hbox );
mLogMemLimitSpin->setMinValue( 1 );
mLogMemLimitSpin->setMaxValue( 1024 * 256 ); // 256 MB
// value in the TQSpinBox is in KB while it's in Byte in the FilterLog
mLogMemLimitSpin->setValue( FilterLog::instance()->getMaxLogSize() / 1024 );
mLogMemLimitSpin->setSuffix( " KB" );
mLogMemLimitSpin->setSpecialValueText( i18n("unlimited") );
connect( mLogMemLimitSpin, TQT_SIGNAL(valueChanged(int)),
this, TQT_SLOT(slotChangeLogMemLimit(int)) );
TQWhatsThis::add( mLogMemLimitSpin,
i18n( "Collecting log data uses memory to temporarily store the "
"log data; here you can limit the maximum amount of memory "
"to be used: if the size of the collected log data exceeds "
"this limit then the oldest data will be discarded until "
"the limit is no longer exceeded. " ) );
connect(FilterLog::instance(), TQT_SIGNAL(logEntryAdded(TQString)),
this, TQT_SLOT(slotLogEntryAdded(TQString)));
connect(FilterLog::instance(), TQT_SIGNAL(logShrinked(void)),
this, TQT_SLOT(slotLogShrinked(void)));
connect(FilterLog::instance(), TQT_SIGNAL(logStateChanged(void)),
this, TQT_SLOT(slotLogStateChanged(void)));
setInitialSize( TQSize( 500, 500 ) );
#if !KDE_IS_VERSION( 3, 2, 91 )
// HACK - KWin keeps all dialogs on top of their mainwindows, but that's probably
// wrong (#76026), and should be done only for modals. CVS HEAD should get
// proper fix in KWin (see also searchwindow.cpp)
XDeleteProperty( qt_xdisplay(), winId(), XA_WM_TRANSIENT_FOR );
#endif
}
void FilterLogDialog::slotLogEntryAdded( TQString logEntry )
{
mTextEdit->append( logEntry );
}
void FilterLogDialog::slotLogShrinked()
{
// limit the size of the shown log lines as soon as
// the log has reached it's memory limit
if ( mTextEdit->maxLogLines() == -1 )
mTextEdit->setMaxLogLines( mTextEdit->lines() );
}
void FilterLogDialog::slotLogStateChanged()
{
mLogActiveBox->setChecked( FilterLog::instance()->isLogging() );
mLogPatternDescBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) );
mLogRuleEvaluationBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) );
mLogPatternResultBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) );
mLogFilterActionBox->setChecked(
FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) );
// value in the TQSpinBox is in KB while it's in Byte in the FilterLog
int newLogSize = FilterLog::instance()->getMaxLogSize() / 1024;
if ( mLogMemLimitSpin->value() != newLogSize )
mLogMemLimitSpin->setValue( newLogSize );
}
void FilterLogDialog::slotChangeLogDetail()
{
if ( mLogPatternDescBox->isChecked() !=
FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) )
FilterLog::instance()->setContentTypeEnabled( FilterLog::patternDesc,
mLogPatternDescBox->isChecked() );
if ( mLogRuleEvaluationBox->isChecked() !=
FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) )
FilterLog::instance()->setContentTypeEnabled( FilterLog::ruleResult,
mLogRuleEvaluationBox->isChecked() );
if ( mLogPatternResultBox->isChecked() !=
FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) )
FilterLog::instance()->setContentTypeEnabled( FilterLog::patternResult,
mLogPatternResultBox->isChecked() );
if ( mLogFilterActionBox->isChecked() !=
FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) )
FilterLog::instance()->setContentTypeEnabled( FilterLog::appliedAction,
mLogFilterActionBox->isChecked() );
}
void FilterLogDialog::slotSwitchLogState()
{
FilterLog::instance()->setLogging( mLogActiveBox->isChecked() );
}
void FilterLogDialog::slotChangeLogMemLimit( int value )
{
FilterLog::instance()->setMaxLogSize( value * 1024 );
}
void FilterLogDialog::slotUser1()
{
FilterLog::instance()->clear();
mTextEdit->clear();
}
void FilterLogDialog::slotUser2()
{
TQString fileName;
KFileDialog fdlg( TQString(), TQString(), this, 0, true );
fdlg.setMode( KFile::File );
fdlg.setSelection( "kmail-filter.log" );
fdlg.setOperationMode( KFileDialog::Saving );
if ( fdlg.exec() )
{
fileName = fdlg.selectedFile();
if ( !FilterLog::instance()->saveToFile( fileName ) )
{
KMessageBox::error( this,
i18n( "Could not write the file %1:\n"
"\"%2\" is the detailed error description." )
.tqarg( fileName,
TQString::fromLocal8Bit( strerror( errno ) ) ),
i18n( "KMail Error" ) );
}
}
}
#include "filterlogdlg.moc"
|