summaryrefslogtreecommitdiffstats
path: root/kshowmail/kcmconfigs/configlog.cpp
blob: e7eb51d1abf3e5190467c22a38921a0ef658a371 (plain)
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
//
// C++ Implementation: configlog
//
// Description:
//
//
// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "configlog.h"

typedef KGenericFactory<ConfigLog, QWidget> ConfigLogFactory;

K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfiglog, ConfigLogFactory(
    "kcm_kshowmailconfiglog" ) );

ConfigLog::ConfigLog( QWidget * parent, const char * name, const QStringList & args )
  : KCModule( ConfigLogFactory::instance(), parent, args )
{
  //set the module name
  if ( !name )
    setName( "configlog" );

  //build GUI
  //---------
  //main layout
  QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 );

  //widgets for deleted mails log
  QVBoxLayout* layDelMails = new QVBoxLayout( layMain, 10, "layDelMails" );

  chkLogDeletedMails = new QCheckBox( i18n( "Log mails deleted by filter" ), this, "chkLogDeletedMails" );
  layDelMails->addWidget( chkLogDeletedMails );
  QToolTip::add( chkLogDeletedMails, i18n( "Check to activate the log of mails deleted by filter." ) );
  connect( chkLogDeletedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
  connect( chkLogDeletedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChangeItems() ) );

  QVBoxLayout* layDelMailsConfig = new QVBoxLayout( layDelMails, 10, "layDelMailsConfig" );
  layDelMailsConfig->setMargin( 10 );

  grpDelMailsRemove = new QButtonGroup( NULL, "grpDelMailsRemove" );
  connect( grpDelMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChanged() ) );
  connect( grpDelMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChangeItems() ) );
  btnDelMailsRemoveExit = new QRadioButton( i18n( "Remove log entries at exit" ), this, "btnDelMailsRemoveExit" );
  grpDelMailsRemove->insert( btnDelMailsRemoveExit, ID_BUTTON_REMOVE_AT_EXIT );
  layDelMailsConfig->addWidget( btnDelMailsRemoveExit );

  QHBoxLayout* layDelMailsConfigDays = new QHBoxLayout( layDelMailsConfig, 0, "layDelMailsConfigDays" );
  layDelMailsConfigDays->setAlignment( Qt::AlignLeft );
  btnDelMailsRemoveDays = new QRadioButton( i18n( "Remove log entries after" ), this, "btnDelMailsRemoveDays" );
  grpDelMailsRemove->insert( btnDelMailsRemoveDays, ID_BUTTON_REMOVE_AFTER_DAYS );
  layDelMailsConfigDays->addWidget( btnDelMailsRemoveDays );
  spbDelDays = new QSpinBox( 1, 999999, 1, this, "spbDelDays" );
  connect( spbDelDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) );
  connect( spbDelDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChangeItems() ) );
  spbDelDays->setSuffix( i18n( " Days" ) );
  spbDelDays->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum );
  layDelMailsConfigDays->addWidget( spbDelDays );


  //widgets for moved mails log
  QVBoxLayout* layMovMails = new QVBoxLayout( layMain, 10, "layMovMails" );

  chkLogMovedMails = new QCheckBox( i18n( "Log mails moved by filter" ), this, "chkLogMovedMails" );
  layMovMails->addWidget( chkLogMovedMails );
  QToolTip::add( chkLogMovedMails, i18n( "Check to activate the log of mails moved by filter." ) );
  connect( chkLogMovedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
  connect( chkLogMovedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChangeItems() ) );

  QVBoxLayout* layMovMailsConfig = new QVBoxLayout( layMovMails, 10, "layMovMailsConfig" );
  layMovMailsConfig->setMargin( 10 );

  grpMovMailsRemove = new QButtonGroup( NULL, "grpMovMailsRemove" );
  connect( grpMovMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChanged() ) );
  connect( grpMovMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChangeItems() ) );
  btnMovMailsRemoveExit = new QRadioButton( i18n( "Remove log entries at exit" ), this, "btnMovMailsRemoveExit" );
  grpMovMailsRemove->insert( btnMovMailsRemoveExit, ID_BUTTON_REMOVE_AT_EXIT );
  layMovMailsConfig->addWidget( btnMovMailsRemoveExit );

  QHBoxLayout* layMovMailsConfigDays = new QHBoxLayout( layMovMailsConfig, 0, "layMovMailsConfigDays" );
  layMovMailsConfigDays->setAlignment( Qt::AlignLeft );
  btnMovMailsRemoveDays = new QRadioButton( i18n( "Remove log entries after" ), this, "btnMovMailsRemoveDays" );
  grpMovMailsRemove->insert( btnMovMailsRemoveDays, ID_BUTTON_REMOVE_AFTER_DAYS );
  layMovMailsConfigDays->addWidget( btnMovMailsRemoveDays );
  spbMovDays = new QSpinBox( 1, 999999, 1, this, "spbMovDays" );
  connect( spbMovDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) );
  connect( spbMovDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChangeItems() ) );
  spbMovDays->setSuffix( i18n( " Days" ) );
  spbMovDays->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum );
  layMovMailsConfigDays->addWidget( spbMovDays );

  //the log of moved mails is not saved yet, maybe later...
  btnMovMailsRemoveExit->setHidden( true );
  btnMovMailsRemoveDays->setHidden( true );
  spbMovDays->setHidden( true );

  //get application config object (kshowmailrc)
  config = KApplication::kApplication()->config();

  //load configured values
  load();
}

ConfigLog::~ConfigLog()
{
}

void ConfigLog::load()
{
  //set group
  config->setGroup( CONFIG_GROUP_LOG );

  //load settings
  chkLogDeletedMails->setChecked( config->readBoolEntry( CONFIG_ENTRY_LOG_LOG_DELETED_MAILS, DEFAULT_LOG_LOG_DELETED_MAILS ) );
  chkLogMovedMails->setChecked( config->readBoolEntry( CONFIG_ENTRY_LOG_LOG_MOVED_MAILS, DEFAULT_LOG_LOG_MOVED_MAILS ) );

  if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, DEFAULT_LOG_REMOVE_DELETED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT )
    grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT );
  else if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, DEFAULT_LOG_REMOVE_DELETED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS )
    grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );
  else
    if( DEFAULT_LOG_REMOVE_DELETED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT )
      grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT );
    else
      grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );

  if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, DEFAULT_LOG_REMOVE_MOVED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT )
    grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT );
  else if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, DEFAULT_LOG_REMOVE_MOVED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS )
    grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );
  else
    if( DEFAULT_LOG_REMOVE_MOVED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT )
      grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT );
  else
    grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );

  spbDelDays->setValue( config->readNumEntry( CONFIG_ENTRY_LOG_HOLDDAYS_DELETED_MAILS, DEFAULT_LOG_HOLDDAYS_DELETED_MAILS ) );
  spbMovDays->setValue( config->readNumEntry( CONFIG_ENTRY_LOG_HOLDDAYS_MOVED_MAILS, DEFAULT_LOG_HOLDDAYS_MOVED_MAILS ) );

  //enable or disable Items
  slotChangeItems();
}

void ConfigLog::defaults()
{
  if( DEFAULT_LOG_LOG_DELETED_MAILS )
    chkLogDeletedMails->setChecked( true );
  else
    chkLogMovedMails->setChecked( false );

  if( DEFAULT_LOG_LOG_MOVED_MAILS )
    chkLogMovedMails->setChecked( true );
  else
    chkLogMovedMails->setChecked( false );

  if( DEFAULT_LOG_REMOVE_DELETED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT )
    grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT );
  else if( DEFAULT_LOG_REMOVE_DELETED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS )
    grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );
  else
    grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );

  if( DEFAULT_LOG_REMOVE_MOVED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT )
    grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT );
  else if( DEFAULT_LOG_REMOVE_MOVED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS )
    grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );
  else
    grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS );

  spbDelDays->setValue( DEFAULT_LOG_HOLDDAYS_DELETED_MAILS );
  spbMovDays->setValue( DEFAULT_LOG_HOLDDAYS_MOVED_MAILS );

  //enable or disable Items
  slotChangeItems();

  slotChanged();
}

void ConfigLog::save()
{
  //set group
  config->setGroup( CONFIG_GROUP_LOG );

  //write settings
  config->writeEntry( CONFIG_ENTRY_LOG_LOG_DELETED_MAILS, chkLogDeletedMails->isOn() );
  config->writeEntry( CONFIG_ENTRY_LOG_LOG_MOVED_MAILS, chkLogMovedMails->isOn() );

  switch( grpDelMailsRemove->selectedId() )
  {
    case ID_BUTTON_REMOVE_AT_EXIT     : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ); break;
    case ID_BUTTON_REMOVE_AFTER_DAYS  : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ); break;
    default                           : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ); break;
  }

  switch( grpMovMailsRemove->selectedId() )
  {
    case ID_BUTTON_REMOVE_AT_EXIT     : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ); break;
    case ID_BUTTON_REMOVE_AFTER_DAYS  : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ); break;
    default                           : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ); break;
  }

  config->writeEntry( CONFIG_ENTRY_LOG_HOLDDAYS_DELETED_MAILS, spbDelDays->value() );
  config->writeEntry( CONFIG_ENTRY_LOG_HOLDDAYS_MOVED_MAILS, spbMovDays->value() );
}

void ConfigLog::slotChanged()
{
  KCModule::changed();
}

void ConfigLog::slotChangeItems()
{
  if( chkLogDeletedMails->isChecked() )
  {
    btnDelMailsRemoveExit->setEnabled( true );
    btnDelMailsRemoveDays->setEnabled( true );
    spbDelDays->setEnabled( true );
    switch( grpDelMailsRemove->selectedId() )
    {
      case ID_BUTTON_REMOVE_AFTER_DAYS      : spbDelDays->setEnabled( true ); break;
      case ID_BUTTON_REMOVE_AT_EXIT         : spbDelDays->setEnabled( false ); break;
      default                               : spbDelDays->setEnabled( true ); break;
    }
  }
  else
  {
    btnDelMailsRemoveExit->setEnabled( false );
    btnDelMailsRemoveDays->setEnabled( false );
    spbDelDays->setEnabled( false );
  }

  if( chkLogMovedMails->isChecked() )
  {
    btnMovMailsRemoveExit->setEnabled( true );
    btnMovMailsRemoveDays->setEnabled( true );
    spbMovDays->setEnabled( true );
    switch( grpMovMailsRemove->selectedId() )
    {
      case ID_BUTTON_REMOVE_AFTER_DAYS      : spbMovDays->setEnabled( true ); break;
      case ID_BUTTON_REMOVE_AT_EXIT         : spbMovDays->setEnabled( false ); break;
      default                               : spbMovDays->setEnabled( true ); break;
    }
  }
  else
  {
    btnMovMailsRemoveExit->setEnabled( false );
    btnMovMailsRemoveDays->setEnabled( false );
    spbMovDays->setEnabled( false );
  }
}


#include "configlog.moc"