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

SenderListDialog::SenderListDialog(TQWidget *parent, ListType list, const char *name)
  : KDialogBase( parent, name, true, TQString::null, Ok|Cancel, Ok, true )
{
  //save list type
  this->list = list;

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

  //set caption
  if( list == White )
    setCaption( "Whitelist" );
  else
    setCaption( "Blacklist" );

  //build GUI
  //---------

  //main widget and layout
  TQWidget* wdgMain = new TQWidget( this );
  setMainWidget( wdgMain );
  TQVBoxLayout* layMain = new TQVBoxLayout( wdgMain, 0, spacingHint() );

  //edit frame
  editFrame = new KEditListBox( wdgMain, "editFrame", true, KEditListBox::Add | KEditListBox::Remove );
  editFrame->setTitle( i18n( "List" ) );
  if( list == White )
    TQToolTip::add( editFrame->listBox(), i18n( "A mail whose sender is listed here will pass the filter.\nA mail will be accepted, if its From line incloses a list entry.\nE.g. a line of\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de> is accepted by the entries\nUlrich Weigelt\nulrich.weigelt@gmx.de\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de>" ) );
  else
    TQToolTip::add( editFrame->listBox(), i18n( "A mail whose sender is listed here will be hold up by the filter.\nA mail will be stopped, if its From line incloses a list entry.\nE.g. a line of\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de> is filtered by the entries\nUlrich Weigelt\nulrich.weigelt@gmx.de\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de>" ) );

  layMain->addWidget( editFrame );

  connect( editFrame->addButton(), SIGNAL( clicked() ), this, SLOT( slotSort() ) );
  connect( editFrame->lineEdit(), SIGNAL( returnPressed( const TQString & ) ), this, SLOT( slotSort() ) );

  //this radio buttons we just need in the blacklist
  if( list == Black )
  {
    TQGroupBox* gboxAction = new TQGroupBox( 0, TQt::Horizontal, i18n( "Action" ), wdgMain, "gboxAction" );
    TQHBoxLayout* layAction = new TQHBoxLayout( gboxAction->layout(), 10 );
    layMain->addWidget( gboxAction );

    grpAction = new TQButtonGroup( NULL, "grpAction" );
    TQRadioButton* btnDelete = new TQRadioButton( i18n( "Delete"), gboxAction, "btnDelete" );
    TQRadioButton* btnMark = new TQRadioButton( i18n( "Mark" ), gboxAction, "btnMark" );

    grpAction->insert( btnDelete, ID_BUTTON_FILTER_SENDERLIST_DELETE );
    grpAction->insert( btnMark, ID_BUTTON_FILTER_SENDERLIST_MARK );

    TQToolTip::add( btnDelete, i18n( "The mails will be deleted." ) );
    TQToolTip::add( btnMark, i18n( "The mails will be marked." ) );

    layAction->addWidget( btnDelete );
    layAction->addWidget( btnMark );

    //set default
    switch( DEFAULT_FILTER_BLACKLIST_ACTION )
    {
      case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE  : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break;
      case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK    : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_MARK ); break;
      default                                           : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break;
    }
  }
  //set size
  setGeometry( 50, 50, (int)( this->width() / 2 ), this->height() );

  //get values
  fillDialog();
}


SenderListDialog::~SenderListDialog()
{
}

void SenderListDialog::slotSort( )
{
  editFrame->listBox()->sort();
}

void SenderListDialog::slotOk( )
{
  //set config group
  config->setGroup( CONFIG_GROUP_FILTER );

  //save the list of senders
  if( list == Black )
    config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST, editFrame->items() );
  else
    config->writeEntry( CONFIG_ENTRY_FILTER_WHITELIST, editFrame->items() );

  //save blacklist action
  if( list == Black )
  {
   int action = grpAction->selectedId();
   if( action != ID_BUTTON_FILTER_SENDERLIST_DELETE && action != ID_BUTTON_FILTER_SENDERLIST_MARK )
     action = DEFAULT_FILTER_BLACKLIST_ACTION;

    switch( action )
    {
      case ID_BUTTON_FILTER_SENDERLIST_DELETE   : config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE ); break;
      case ID_BUTTON_FILTER_SENDERLIST_MARK     : config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK ); break;
      default                                   : config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE ); break;
    }
  }

  config->sync();

  //call slot of super class to close the dialog
  KDialogBase::slotOk();
}

void SenderListDialog::fillDialog( )
{
  //set config group
  config->setGroup( CONFIG_GROUP_FILTER );

  //get list of senders
  if( list == Black )
    editFrame->setItems( config->readListEntry( CONFIG_ENTRY_FILTER_BLACKLIST ) );
  else
    editFrame->setItems( config->readListEntry( CONFIG_ENTRY_FILTER_WHITELIST ) );

  //get blacklist action
  if( list == Black )
  {
    switch( config->readNumEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, DEFAULT_FILTER_BLACKLIST_ACTION ) )
    {
      case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE    : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break;
      case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK      : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_MARK ); break;
      default                                             : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break;
    }
  }
}


#include "senderlistdialog.moc"