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 <tdeversion.h>
35 #include <tdefiledialog.h>
36 #include <tdelocale.h>
37 #include <tdemessagebox.h>
38 
39 #include <tqcheckbox.h>
40 #include <tqlabel.h>
41 #include <tqspinbox.h>
42 #include <tqstringlist.h>
43 #include <tqtextedit.h>
44 #include <tqvbox.h>
45 #include <tqwhatsthis.h>
46 #include <tqvgroupbox.h>
47 
48 #include <errno.h>
49 #include <X11/Xlib.h>
50 #include <X11/Xatom.h>
51 
52 using namespace KMail;
53 
54 
56 : KDialogBase( parent, "FilterLogDlg", false, i18n( "Filter Log Viewer" ),
57  User1|User2|Close, Close, true, KStdGuiItem::clear(), KStdGuiItem::saveAs() )
58 {
59  setWFlags( WDestructiveClose );
60  TQVBox *page = makeVBoxMainWidget();
61 
62  mTextEdit = new TQTextEdit( page );
63  mTextEdit->setReadOnly( true );
64  mTextEdit->setWordWrap( TQTextEdit::NoWrap );
65  mTextEdit->setTextFormat( TQTextEdit::LogText );
66 
67  TQStringList logEntries = FilterLog::instance()->getLogEntries();
68  for ( TQStringList::Iterator it = logEntries.begin();
69  it != logEntries.end(); ++it )
70  {
71  mTextEdit->append( *it );
72  }
73 
74  mLogActiveBox = new TQCheckBox( i18n("&Log filter activities"), page );
75  mLogActiveBox->setChecked( FilterLog::instance()->isLogging() );
76  connect( mLogActiveBox, TQ_SIGNAL(clicked()),
77  this, TQ_SLOT(slotSwitchLogState(void)) );
78  TQWhatsThis::add( mLogActiveBox,
79  i18n( "You can turn logging of filter activities on and off here. "
80  "Of course, log data is collected and shown only when logging "
81  "is turned on. " ) );
82 
83  mLogDetailsBox = new TQVGroupBox( i18n( "Logging Details" ), page );
84  mLogDetailsBox->setEnabled( mLogActiveBox->isChecked() );
85  connect( mLogActiveBox, TQ_SIGNAL( toggled( bool ) ),
86  mLogDetailsBox, TQ_SLOT( setEnabled( bool ) ) );
87 
88  mLogPatternDescBox = new TQCheckBox( i18n("Log pattern description"),
89  mLogDetailsBox );
90  mLogPatternDescBox->setChecked(
91  FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) );
92  connect( mLogPatternDescBox, TQ_SIGNAL(clicked()),
93  this, TQ_SLOT(slotChangeLogDetail(void)) );
94  // TODO
95  //TQWhatsThis::add( mLogPatternDescBox,
96  // i18n( "" ) );
97 
98  mLogRuleEvaluationBox = new TQCheckBox( i18n("Log filter &rule evaluation"),
99  mLogDetailsBox );
100  mLogRuleEvaluationBox->setChecked(
101  FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) );
102  connect( mLogRuleEvaluationBox, TQ_SIGNAL(clicked()),
103  this, TQ_SLOT(slotChangeLogDetail(void)) );
104  TQWhatsThis::add( mLogRuleEvaluationBox,
105  i18n( "You can control the feedback in the log concerning the "
106  "evaluation of the filter rules of applied filters: "
107  "having this option checked will give detailed feedback "
108  "for each single filter rule; alternatively, only "
109  "feedback about the result of the evaluation of all rules "
110  "of a single filter will be given." ) );
111 
112  mLogPatternResultBox = new TQCheckBox( i18n("Log filter pattern evaluation"),
113  mLogDetailsBox );
114  mLogPatternResultBox->setChecked(
115  FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) );
116  connect( mLogPatternResultBox, TQ_SIGNAL(clicked()),
117  this, TQ_SLOT(slotChangeLogDetail(void)) );
118  // TODO
119  //TQWhatsThis::add( mLogPatternResultBox,
120  // i18n( "" ) );
121 
122  mLogFilterActionBox = new TQCheckBox( i18n("Log filter actions"),
123  mLogDetailsBox );
124  mLogFilterActionBox->setChecked(
125  FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) );
126  connect( mLogFilterActionBox, TQ_SIGNAL(clicked()),
127  this, TQ_SLOT(slotChangeLogDetail(void)) );
128  // TODO
129  //TQWhatsThis::add( mLogFilterActionBox,
130  // i18n( "" ) );
131 
132  TQHBox * hbox = new TQHBox( page );
133  new TQLabel( i18n("Log size limit:"), hbox );
134  mLogMemLimitSpin = new TQSpinBox( hbox );
135  mLogMemLimitSpin->setMinValue( 1 );
136  mLogMemLimitSpin->setMaxValue( 1024 * 256 ); // 256 MB
137  // value in the TQSpinBox is in KB while it's in Byte in the FilterLog
138  mLogMemLimitSpin->setValue( FilterLog::instance()->getMaxLogSize() / 1024 );
139  mLogMemLimitSpin->setSuffix( " KB" );
140  mLogMemLimitSpin->setSpecialValueText( i18n("unlimited") );
141  connect( mLogMemLimitSpin, TQ_SIGNAL(valueChanged(int)),
142  this, TQ_SLOT(slotChangeLogMemLimit(int)) );
143  TQWhatsThis::add( mLogMemLimitSpin,
144  i18n( "Collecting log data uses memory to temporarily store the "
145  "log data; here you can limit the maximum amount of memory "
146  "to be used: if the size of the collected log data exceeds "
147  "this limit then the oldest data will be discarded until "
148  "the limit is no longer exceeded. " ) );
149 
150  connect(FilterLog::instance(), TQ_SIGNAL(logEntryAdded(TQString)),
151  this, TQ_SLOT(slotLogEntryAdded(TQString)));
152  connect(FilterLog::instance(), TQ_SIGNAL(logShrinked(void)),
153  this, TQ_SLOT(slotLogShrinked(void)));
154  connect(FilterLog::instance(), TQ_SIGNAL(logStateChanged(void)),
155  this, TQ_SLOT(slotLogStateChanged(void)));
156 
157  setInitialSize( TQSize( 500, 500 ) );
158 #if !KDE_IS_VERSION( 3, 2, 91 )
159  // HACK - KWin keeps all dialogs on top of their mainwindows, but that's probably
160  // wrong (#76026), and should be done only for modals. CVS HEAD should get
161  // proper fix in KWin (see also searchwindow.cpp)
162  XDeleteProperty( tqt_xdisplay(), winId(), XA_WM_TRANSIENT_FOR );
163 #endif
164 }
165 
166 
167 void FilterLogDialog::slotLogEntryAdded( TQString logEntry )
168 {
169  mTextEdit->append( logEntry );
170 }
171 
172 
173 void FilterLogDialog::slotLogShrinked()
174 {
175  // limit the size of the shown log lines as soon as
176  // the log has reached it's memory limit
177  if ( mTextEdit->maxLogLines() == -1 )
178  mTextEdit->setMaxLogLines( mTextEdit->lines() );
179 }
180 
181 
182 void FilterLogDialog::slotLogStateChanged()
183 {
184  mLogActiveBox->setChecked( FilterLog::instance()->isLogging() );
185  mLogPatternDescBox->setChecked(
186  FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) );
187  mLogRuleEvaluationBox->setChecked(
188  FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) );
189  mLogPatternResultBox->setChecked(
190  FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) );
191  mLogFilterActionBox->setChecked(
192  FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) );
193 
194  // value in the TQSpinBox is in KB while it's in Byte in the FilterLog
195  int newLogSize = FilterLog::instance()->getMaxLogSize() / 1024;
196  if ( mLogMemLimitSpin->value() != newLogSize )
197  mLogMemLimitSpin->setValue( newLogSize );
198 }
199 
200 
201 void FilterLogDialog::slotChangeLogDetail()
202 {
203  if ( mLogPatternDescBox->isChecked() !=
204  FilterLog::instance()->isContentTypeEnabled( FilterLog::patternDesc ) )
205  FilterLog::instance()->setContentTypeEnabled( FilterLog::patternDesc,
206  mLogPatternDescBox->isChecked() );
207 
208  if ( mLogRuleEvaluationBox->isChecked() !=
209  FilterLog::instance()->isContentTypeEnabled( FilterLog::ruleResult ) )
210  FilterLog::instance()->setContentTypeEnabled( FilterLog::ruleResult,
211  mLogRuleEvaluationBox->isChecked() );
212 
213  if ( mLogPatternResultBox->isChecked() !=
214  FilterLog::instance()->isContentTypeEnabled( FilterLog::patternResult ) )
215  FilterLog::instance()->setContentTypeEnabled( FilterLog::patternResult,
216  mLogPatternResultBox->isChecked() );
217 
218  if ( mLogFilterActionBox->isChecked() !=
219  FilterLog::instance()->isContentTypeEnabled( FilterLog::appliedAction ) )
220  FilterLog::instance()->setContentTypeEnabled( FilterLog::appliedAction,
221  mLogFilterActionBox->isChecked() );
222 }
223 
224 
225 void FilterLogDialog::slotSwitchLogState()
226 {
227  FilterLog::instance()->setLogging( mLogActiveBox->isChecked() );
228 }
229 
230 
231 void FilterLogDialog::slotChangeLogMemLimit( int value )
232 {
233  FilterLog::instance()->setMaxLogSize( value * 1024 );
234 }
235 
236 
237 void FilterLogDialog::slotUser1()
238 {
240  mTextEdit->clear();
241 }
242 
243 
244 void FilterLogDialog::slotUser2()
245 {
246  TQString fileName;
247  KFileDialog fdlg( TQString(), TQString(), this, 0, true );
248 
249  fdlg.setMode( KFile::File );
250  fdlg.setSelection( "kmail-filter.log" );
251  fdlg.setOperationMode( KFileDialog::Saving );
252  if ( fdlg.exec() )
253  {
254  fileName = fdlg.selectedFile();
255  if ( !FilterLog::instance()->saveToFile( fileName ) )
256  {
257  KMessageBox::error( this,
258  i18n( "Could not write the file %1:\n"
259  "\"%2\" is the detailed error description." )
260  .arg( fileName,
261  TQString::fromLocal8Bit( strerror( errno ) ) ),
262  i18n( "KMail Error" ) );
263  }
264  }
265 }
266 
267 
268 #include "filterlogdlg.moc"
FilterLogDialog(TQWidget *parent)
constructor
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