00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "senderlistdialog.h"
00019 #include <qlistview.h>
00020
00021 SenderListDialog::SenderListDialog(QWidget *parent, ListType list )
00022 : KDialog( parent )
00023 {
00024
00025 this->list = list;
00026
00027
00028 config = KGlobal::config();
00029
00030
00031 if( list == White )
00032 setCaption( "Whitelist" );
00033 else
00034 setCaption( "Blacklist" );
00035
00036
00037
00038
00039
00040 QWidget* wdgMain = new QWidget( this );
00041 setMainWidget( wdgMain );
00042 QVBoxLayout* layMain = new QVBoxLayout( wdgMain );
00043
00044
00045 editFrame = new KEditListBox( wdgMain, "editFrame", true, KEditListBox::Add | KEditListBox::Remove );
00046 editFrame->setTitle( i18nc( "@title:window dialog to edit the black- or whitelist", "List" ) );
00047 if( list == White )
00048 editFrame->listView()->setToolTip( i18nc( "@info/rich", "A mail whose sender is listed here will pass the filter.<nl/>A mail will be accepted, if its From line incloses a list entry.<nl/>E.g. a line of<nl/>"Ulrich Weigelt" <ulrich.weigelt@gmx.de> is accepted by the entries<nl/>Ulrich Weigelt<nl/>ulrich.weigelt@gmx.de<nl/>"Ulrich Weigelt" <ulrich.weigelt@gmx.de>" ) );
00049 else
00050 editFrame->listView()->setToolTip( i18nc( "@info:tooltip", "A mail whose sender is listed here will be hold up by the filter.<nl/>A mail will be stopped, if its From line incloses a list entry.<nl/>E.g. a line of<nl/>"Ulrich Weigelt" <ulrich.weigelt@gmx.de> is filtered by the entries<nl/>Ulrich Weigelt<nl/>ulrich.weigelt@gmx.de<nl/>"Ulrich Weigelt" <ulrich.weigelt@gmx.de>" ) );
00051
00052 layMain->addWidget( editFrame );
00053
00054 connect( editFrame->addButton(), SIGNAL( clicked() ), this, SLOT( slotSort() ) );
00055 connect( editFrame->lineEdit(), SIGNAL( returnPressed( const QString & ) ), this, SLOT( slotSort() ) );
00056
00057
00058 if( list == Black )
00059 {
00060 QGroupBox* gboxAction = new QGroupBox( i18nc( "@title:group action to execute if a blacklisted mail comes in", "Action" ), wdgMain );
00061 QHBoxLayout* layAction = new QHBoxLayout();
00062 gboxAction->setLayout( layAction );
00063 layMain->addWidget( gboxAction );
00064
00065 grpAction = new QButtonGroup( NULL );
00066 btnDelete = new QRadioButton( i18nc( "@option:radio delete a blacklisted mail", "Delete"), gboxAction );
00067 btnMark = new QRadioButton( i18nc( "@option:radio mark a blacklisted mail", "Mark" ), gboxAction );
00068
00069 grpAction->addButton( btnDelete, ID_BUTTON_FILTER_SENDERLIST_DELETE );
00070 grpAction->addButton( btnMark, ID_BUTTON_FILTER_SENDERLIST_MARK );
00071
00072 btnDelete->setToolTip( i18nc( "@info:tooltip", "The mails will be deleted." ) );
00073 btnMark->setToolTip( i18nc( "@info:tooltip", "The mails will be marked." ) );
00074
00075 layAction->addWidget( btnDelete );
00076 layAction->addWidget( btnMark );
00077
00078
00079 switch( DEFAULT_FILTER_BLACKLIST_ACTION )
00080 {
00081 case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE : btnDelete->setChecked( true ); break;
00082 case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK : btnMark->setChecked( true ); break;
00083 default : btnDelete->setChecked( true ); break;
00084 }
00085 }
00086
00087 setGeometry( 50, 50, (int)( this->width() / 2 ), this->height() );
00088
00089
00090 fillDialog();
00091 }
00092
00093
00094 SenderListDialog::~SenderListDialog()
00095 {
00096 }
00097
00098 void SenderListDialog::slotSort( )
00099 {
00100 editFrame->listView()->model()->sort( 0 );
00101 }
00102
00103 void SenderListDialog::slotButtonClicked( int button )
00104 {
00105 if( button == KDialog::Ok )
00106 {
00107
00108 KConfigGroup* configList = new KConfigGroup( config, CONFIG_GROUP_FILTER );
00109
00110
00111 if( list == Black )
00112 configList->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST, editFrame->items() );
00113 else
00114 configList->writeEntry( CONFIG_ENTRY_FILTER_WHITELIST, editFrame->items() );
00115
00116
00117 if( list == Black )
00118 {
00119 int action = grpAction->checkedId();
00120 if( action != ID_BUTTON_FILTER_SENDERLIST_DELETE && action != ID_BUTTON_FILTER_SENDERLIST_MARK )
00121 action = DEFAULT_FILTER_BLACKLIST_ACTION;
00122
00123 switch( action )
00124 {
00125 case ID_BUTTON_FILTER_SENDERLIST_DELETE : configList->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE ); break;
00126 case ID_BUTTON_FILTER_SENDERLIST_MARK : configList->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK ); break;
00127 default : configList->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE ); break;
00128 }
00129 }
00130
00131 config->sync();
00132
00133 delete configList;
00134 }
00135
00136
00137 KDialog::slotButtonClicked( button );
00138
00139 }
00140
00141 void SenderListDialog::fillDialog( )
00142 {
00143
00144 KConfigGroup* configList = new KConfigGroup( config, CONFIG_GROUP_FILTER );
00145
00146
00147 if( list == Black )
00148 editFrame->setItems( configList->readEntry( CONFIG_ENTRY_FILTER_BLACKLIST, QStringList() ) );
00149 else
00150 editFrame->setItems( configList->readEntry( CONFIG_ENTRY_FILTER_WHITELIST, QStringList() ) );
00151
00152
00153 if( list == Black )
00154 {
00155 switch( configList->readEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, DEFAULT_FILTER_BLACKLIST_ACTION ) )
00156 {
00157 case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE : btnDelete->setChecked( true ); break;
00158 case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK : btnMark->setChecked( true ); break;
00159 default : btnDelete->setChecked( true ); break;
00160 }
00161 }
00162
00163 delete configList;
00164 }
00165
00166
00167 #include "senderlistdialog.moc"