~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to kmail/filterlogdlg.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 Qt library by Trolltech AS, Norway (or with modified versions
21
 
    of Qt that use the same license as Qt), 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
 
    Qt.  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
 
 
31
 
#include "filterlogdlg.h"
32
 
#include "mailcommon/filterlog.h"
33
 
#include "messageviewer/autoqpointer.h"
34
 
 
35
 
#include <kdebug.h>
36
 
#include <kfiledialog.h>
37
 
#include <klocale.h>
38
 
#include <kmessagebox.h>
39
 
#include <ktextedit.h>
40
 
#include <kvbox.h>
41
 
 
42
 
#include <QCheckBox>
43
 
#include <QLabel>
44
 
#include <QSpinBox>
45
 
#include <QStringList>
46
 
#include <QGroupBox>
47
 
#include <QVBoxLayout>
48
 
 
49
 
#include <errno.h>
50
 
 
51
 
using namespace KMail;
52
 
using namespace MailCommon;
53
 
 
54
 
 
55
 
FilterLogDialog::FilterLogDialog( QWidget * parent )
56
 
: KDialog( parent )
57
 
{
58
 
  setCaption( i18n( "Filter Log Viewer" ) );
59
 
  setButtons( User1|User2|Close );
60
 
  setObjectName( "FilterLogDlg" );
61
 
  setModal( false );
62
 
  setDefaultButton( Close );
63
 
  setButtonGuiItem( User1, KStandardGuiItem::clear() );
64
 
  setButtonGuiItem( User2, KStandardGuiItem::saveAs() );
65
 
  setAttribute( Qt::WA_DeleteOnClose );
66
 
  QFrame *page = new KVBox( this );
67
 
  setMainWidget( page );
68
 
 
69
 
  mTextEdit = new KTextEdit( page );
70
 
  mTextEdit->setReadOnly( true );
71
 
  mTextEdit->setLineWrapMode ( KTextEdit::NoWrap );
72
 
 
73
 
  QString text;
74
 
  const QStringList logEntries = FilterLog::instance()->logEntries();
75
 
  for ( QStringList::ConstIterator it = logEntries.constBegin();
76
 
        it != logEntries.constEnd(); ++it )
77
 
  {
78
 
    mTextEdit->append(*it);
79
 
  }
80
 
 
81
 
  mLogActiveBox = new QCheckBox( i18n("&Log filter activities"), page );
82
 
  mLogActiveBox->setChecked( FilterLog::instance()->isLogging() );
83
 
  connect( mLogActiveBox, SIGNAL(clicked()),
84
 
           this, SLOT(slotSwitchLogState(void)) );
85
 
  mLogActiveBox->setWhatsThis(
86
 
      i18n( "You can turn logging of filter activities on and off here. "
87
 
            "Of course, log data is collected and shown only when logging "
88
 
            "is turned on. " ) );
89
 
 
90
 
  mLogDetailsBox = new QGroupBox(i18n( "Logging Details" ), page );
91
 
  QVBoxLayout *layout = new QVBoxLayout;
92
 
  mLogDetailsBox->setLayout( layout );
93
 
  mLogDetailsBox->setEnabled( mLogActiveBox->isChecked() );
94
 
  connect( mLogActiveBox, SIGNAL( toggled( bool ) ),
95
 
           mLogDetailsBox, SLOT( setEnabled( bool ) ) );
96
 
 
97
 
  mLogPatternDescBox = new QCheckBox( i18n("Log pattern description") );
98
 
  layout->addWidget( mLogPatternDescBox );
99
 
  mLogPatternDescBox->setChecked(
100
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::PatternDescription ) );
101
 
  connect( mLogPatternDescBox, SIGNAL(clicked()),
102
 
           this, SLOT(slotChangeLogDetail(void)) );
103
 
  // TODO
104
 
  //QWhatsThis::add( mLogPatternDescBox,
105
 
  //    i18n( "" ) );
106
 
 
107
 
  mLogRuleEvaluationBox = new QCheckBox( i18n("Log filter &rule evaluation") );
108
 
  layout->addWidget( mLogRuleEvaluationBox );
109
 
  mLogRuleEvaluationBox->setChecked(
110
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::RuleResult ) );
111
 
  connect( mLogRuleEvaluationBox, SIGNAL(clicked()),
112
 
           this, SLOT(slotChangeLogDetail(void)) );
113
 
  mLogRuleEvaluationBox->setWhatsThis(
114
 
      i18n( "You can control the feedback in the log concerning the "
115
 
            "evaluation of the filter rules of applied filters: "
116
 
            "having this option checked will give detailed feedback "
117
 
            "for each single filter rule; alternatively, only "
118
 
            "feedback about the result of the evaluation of all rules "
119
 
            "of a single filter will be given." ) );
120
 
 
121
 
  mLogPatternResultBox = new QCheckBox( i18n("Log filter pattern evaluation") );
122
 
  layout->addWidget( mLogPatternResultBox );
123
 
  mLogPatternResultBox->setChecked(
124
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::PatternResult ) );
125
 
  connect( mLogPatternResultBox, SIGNAL(clicked()),
126
 
           this, SLOT(slotChangeLogDetail(void)) );
127
 
  // TODO
128
 
  //QWhatsThis::add( mLogPatternResultBox,
129
 
  //    i18n( "" ) );
130
 
 
131
 
  mLogFilterActionBox = new QCheckBox( i18n("Log filter actions") );
132
 
  layout->addWidget( mLogFilterActionBox );
133
 
  mLogFilterActionBox->setChecked(
134
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::AppliedAction ) );
135
 
  connect( mLogFilterActionBox, SIGNAL(clicked()),
136
 
           this, SLOT(slotChangeLogDetail(void)) );
137
 
  // TODO
138
 
  //QWhatsThis::add( mLogFilterActionBox,
139
 
  //    i18n( "" ) );
140
 
 
141
 
  KHBox * hbox = new KHBox( page );
142
 
  new QLabel( i18n("Log size limit:"), hbox );
143
 
  mLogMemLimitSpin = new QSpinBox( hbox );
144
 
  mLogMemLimitSpin->setMinimum( 1 );
145
 
  mLogMemLimitSpin->setMaximum( 1024 * 256 ); // 256 MB
146
 
  // value in the QSpinBox is in KB while it's in Byte in the FilterLog
147
 
  mLogMemLimitSpin->setValue( FilterLog::instance()->maxLogSize() / 1024 );
148
 
  mLogMemLimitSpin->setSuffix( " KB" );
149
 
  mLogMemLimitSpin->setSpecialValueText(
150
 
    i18nc("@label:spinbox Set the size of the logfile to unlimited.", "unlimited") );
151
 
  connect( mLogMemLimitSpin, SIGNAL(valueChanged(int)),
152
 
           this, SLOT(slotChangeLogMemLimit(int)) );
153
 
  mLogMemLimitSpin->setWhatsThis(
154
 
      i18n( "Collecting log data uses memory to temporarily store the "
155
 
            "log data; here you can limit the maximum amount of memory "
156
 
            "to be used: if the size of the collected log data exceeds "
157
 
            "this limit then the oldest data will be discarded until "
158
 
            "the limit is no longer exceeded. " ) );
159
 
 
160
 
  connect(FilterLog::instance(), SIGNAL(logEntryAdded(const QString&)),
161
 
          this, SLOT(slotLogEntryAdded(const QString&)));
162
 
  connect(FilterLog::instance(), SIGNAL(logShrinked(void)),
163
 
          this, SLOT(slotLogShrinked(void)));
164
 
  connect(FilterLog::instance(), SIGNAL(logStateChanged(void)),
165
 
          this, SLOT(slotLogStateChanged(void)));
166
 
 
167
 
  setInitialSize( QSize( 500, 500 ) );
168
 
  connect( this, SIGNAL( user1Clicked() ), SLOT( slotUser1() ) );
169
 
  connect( this, SIGNAL( user2Clicked() ), SLOT( slotUser2() ) );
170
 
}
171
 
 
172
 
 
173
 
void FilterLogDialog::slotLogEntryAdded(const QString& logEntry )
174
 
{
175
 
  mTextEdit->append( logEntry );
176
 
}
177
 
 
178
 
 
179
 
void FilterLogDialog::slotLogShrinked()
180
 
{
181
 
  // limit the size of the shown log lines as soon as
182
 
  // the log has reached it's memory limit
183
 
  if ( mTextEdit->document()->maximumBlockCount () <= 0 )
184
 
    mTextEdit->document()->setMaximumBlockCount( mTextEdit->document()->blockCount() );
185
 
}
186
 
 
187
 
 
188
 
void FilterLogDialog::slotLogStateChanged()
189
 
{
190
 
  mLogActiveBox->setChecked( FilterLog::instance()->isLogging() );
191
 
  mLogPatternDescBox->setChecked(
192
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::PatternDescription ) );
193
 
  mLogRuleEvaluationBox->setChecked(
194
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::RuleResult ) );
195
 
  mLogPatternResultBox->setChecked(
196
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::PatternResult ) );
197
 
  mLogFilterActionBox->setChecked(
198
 
      FilterLog::instance()->isContentTypeEnabled( FilterLog::AppliedAction ) );
199
 
 
200
 
  // value in the QSpinBox is in KB while it's in Byte in the FilterLog
201
 
  int newLogSize = FilterLog::instance()->maxLogSize() / 1024;
202
 
  if ( mLogMemLimitSpin->value() != newLogSize )
203
 
    mLogMemLimitSpin->setValue( newLogSize );
204
 
}
205
 
 
206
 
 
207
 
void FilterLogDialog::slotChangeLogDetail()
208
 
{
209
 
  if ( mLogPatternDescBox->isChecked() !=
210
 
       FilterLog::instance()->isContentTypeEnabled( FilterLog::PatternDescription ) )
211
 
    FilterLog::instance()->setContentTypeEnabled( FilterLog::PatternDescription,
212
 
                                                  mLogPatternDescBox->isChecked() );
213
 
 
214
 
  if ( mLogRuleEvaluationBox->isChecked() !=
215
 
       FilterLog::instance()->isContentTypeEnabled( FilterLog::RuleResult ) )
216
 
    FilterLog::instance()->setContentTypeEnabled( FilterLog::RuleResult,
217
 
                                                  mLogRuleEvaluationBox->isChecked() );
218
 
 
219
 
  if ( mLogPatternResultBox->isChecked() !=
220
 
       FilterLog::instance()->isContentTypeEnabled( FilterLog::PatternResult ) )
221
 
    FilterLog::instance()->setContentTypeEnabled( FilterLog::PatternResult,
222
 
                                                  mLogPatternResultBox->isChecked() );
223
 
 
224
 
  if ( mLogFilterActionBox->isChecked() !=
225
 
       FilterLog::instance()->isContentTypeEnabled( FilterLog::AppliedAction ) )
226
 
    FilterLog::instance()->setContentTypeEnabled( FilterLog::AppliedAction,
227
 
                                                  mLogFilterActionBox->isChecked() );
228
 
}
229
 
 
230
 
 
231
 
void FilterLogDialog::slotSwitchLogState()
232
 
{
233
 
  FilterLog::instance()->setLogging( mLogActiveBox->isChecked() );
234
 
}
235
 
 
236
 
 
237
 
void FilterLogDialog::slotChangeLogMemLimit( int value )
238
 
{
239
 
  FilterLog::instance()->setMaxLogSize( value * 1024 );
240
 
}
241
 
 
242
 
 
243
 
void FilterLogDialog::slotUser1()
244
 
{
245
 
  FilterLog::instance()->clear();
246
 
  mTextEdit->clear();
247
 
}
248
 
 
249
 
 
250
 
void FilterLogDialog::slotUser2()
251
 
{
252
 
  QString fileName;
253
 
  KUrl url;
254
 
  MessageViewer::AutoQPointer<KFileDialog> fdlg( new KFileDialog( url, QString(), this) );
255
 
 
256
 
  fdlg->setMode( KFile::File );
257
 
  fdlg->setSelection( "kmail-filter.log" );
258
 
  fdlg->setOperationMode( KFileDialog::Saving );
259
 
  if ( fdlg->exec() == QDialog::Accepted && fdlg )
260
 
  {
261
 
    fileName = fdlg->selectedFile();
262
 
    if ( !FilterLog::instance()->saveToFile( fileName ) )
263
 
    {
264
 
      KMessageBox::error( this,
265
 
                          i18n( "Could not write the file %1:\n"
266
 
                                "\"%2\" is the detailed error description.",
267
 
                                fileName,
268
 
                                QString::fromLocal8Bit( strerror( errno ) ) ),
269
 
                          i18n( "KMail Error" ) );
270
 
    }
271
 
  }
272
 
}
273
 
 
274
 
 
275
 
#include "filterlogdlg.moc"