kmail

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