8 #include "kmfilterdlg.h"
11 #include "kmsearchpatternedit.h"
12 #include "kmfiltermgr.h"
13 #include "kmmainwidget.h"
14 #include "accountmanager.h"
16 #include "filterimporterexporter.h"
18 #include "foldersetselector.h"
19 #include "globalsettings.h"
22 #include <kmessagebox.h>
25 #include <kinputdialog.h>
26 #include <kiconloader.h>
27 #include <kapplication.h>
30 #include <kicondialog.h>
31 #include <kkeybutton.h>
32 #include <klistview.h>
33 #include <kpushbutton.h>
38 #include <tqcombobox.h>
39 #include <tqwidgetstack.h>
40 #include <tqtooltip.h>
41 #include <tqwhatsthis.h>
42 #include <tqcheckbox.h>
44 #include <tqvalidator.h>
45 #include <tqtabwidget.h>
50 using namespace KMail;
54 const char * _wt_filterlist =
55 I18N_NOOP(
"<qt><p>This is the list of defined filters. "
56 "They are processed top-to-bottom.</p>"
57 "<p>Click on any filter to edit it "
58 "using the controls in the right-hand half "
59 "of the dialog.</p></qt>" );
60 const char * _wt_filterlist_new =
61 I18N_NOOP(
"<qt><p>Click this button to create a new filter.</p>"
62 "<p>The filter will be inserted just before the currently-"
63 "selected one, but you can always change that "
65 "<p>If you have clicked this button accidentally, you can undo this "
66 "by clicking on the <em>Delete</em> button.</p></qt>" );
67 const char * _wt_filterlist_copy =
68 I18N_NOOP(
"<qt><p>Click this button to copy a filter.</p>"
69 "<p>If you have clicked this button accidentally, you can undo this "
70 "by clicking on the <em>Delete</em> button.</p></qt>" );
71 const char * _wt_filterlist_delete =
72 I18N_NOOP(
"<qt><p>Click this button to <em>delete</em> the currently-"
73 "selected filter from the list above.</p>"
74 "<p>There is no way to get the filter back once "
75 "it is deleted, but you can always leave the "
76 "dialog by clicking <em>Cancel</em> to discard the "
77 "changes made.</p></qt>" );
78 const char * _wt_filterlist_top =
79 I18N_NOOP(
"<qt><p>Click this button to move the currently-"
80 "selected filter to the <em>top</em> of the list above.</p>"
81 "<p>This is useful since the order of the filters in the list "
82 "determines the order in which they are tried on messages: "
83 "The topmost filter gets tried first.</p></qt>" );
84 const char * _wt_filterlist_up =
85 I18N_NOOP(
"<qt><p>Click this button to move the currently-"
86 "selected filter <em>up</em> one in the list above.</p>"
87 "<p>This is useful since the order of the filters in the list "
88 "determines the order in which they are tried on messages: "
89 "The topmost filter gets tried first.</p>"
90 "<p>If you have clicked this button accidentally, you can undo this "
91 "by clicking on the <em>Down</em> button.</p></qt>" );
92 const char * _wt_filterlist_down =
93 I18N_NOOP(
"<qt><p>Click this button to move the currently-"
94 "selected filter <em>down</em> one in the list above.</p>"
95 "<p>This is useful since the order of the filters in the list "
96 "determines the order in which they are tried on messages: "
97 "The topmost filter gets tried first.</p>"
98 "<p>If you have clicked this button accidentally, you can undo this "
99 "by clicking on the <em>Up</em> button.</p></qt>" );
100 const char * _wt_filterlist_bot =
101 I18N_NOOP(
"<qt><p>Click this button to move the currently-"
102 "selected filter to the <em>bottom</em> of the list above.</p>"
103 "<p>This is useful since the order of the filters in the list "
104 "determines the order in which they are tried on messages: "
105 "The topmost filter gets tried first.</p></qt>" );
106 const char * _wt_filterlist_rename =
107 I18N_NOOP(
"<qt><p>Click this button to rename the currently-selected filter.</p>"
108 "<p>Filters are named automatically, as long as they start with "
110 "<p>If you have renamed a filter accidentally and want automatic "
111 "naming back, click this button and select <em>Clear</em> followed "
112 "by <em>OK</em> in the appearing dialog.</p></qt>" );
113 const char * _wt_filterdlg_showLater =
114 I18N_NOOP(
"<qt><p>Check this button to force the confirmation dialog to be "
115 "displayed.</p><p>This is useful if you have defined a ruleset that tags "
116 "messages to be downloaded later. Without the possibility to force "
117 "the dialog popup, these messages could never be downloaded if no "
118 "other large messages were waiting on the server, or if you wanted to "
119 "change the ruleset to tag the messages differently.</p></qt>" );
122 const char * KMFilterDlgHelpAnchor =
"filters-id" ;
123 const char * KMPopFilterDlgHelpAnchor =
"popfilters-id" ;
132 : KDialogBase( parent, name, false ,
133 (popFilter)? i18n(
"POP3 Filter Rules"): i18n(
"Filter Rules") ,
134 Help|Ok|Apply|Cancel|User1|User2 ,
136 bPopFilter(popFilter)
138 KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
139 setHelp( (bPopFilter)? KMPopFilterDlgHelpAnchor: KMFilterDlgHelpAnchor );
140 setButtonText( User1, i18n(
"Import") );
141 setButtonText( User2, i18n(
"Export") );
142 connect(
this, TQT_SIGNAL(user1Clicked()),
144 connect(
this, TQT_SIGNAL(user2Clicked()),
147 TQWidget *w =
new TQWidget(
this );
149 TQHBoxLayout *topLayout =
new TQHBoxLayout( w, 0, spacingHint(),
"topLayout" );
150 TQHBoxLayout *hbl = topLayout;
151 TQVBoxLayout *vbl2 = 0;
159 TQTabWidget *tabWidget =
new TQTabWidget( w,
"kmfd_tab" );
160 tabWidget->setMargin( KDialog::marginHint() );
161 topLayout->addWidget( tabWidget );
163 page1 =
new TQWidget( tabWidget );
164 tabWidget->addTab( page1, i18n(
"&General") );
165 hbl =
new TQHBoxLayout( page1, 0, spacingHint(),
"kmfd_hbl" );
167 page2 =
new TQWidget( tabWidget );
168 tabWidget->addTab( page2, i18n(
"A&dvanced") );
169 vbl2 =
new TQVBoxLayout( page2, 0, spacingHint(),
"kmfd_vbl2" );
172 TQVBoxLayout *vbl =
new TQVBoxLayout( hbl, spacingHint(),
"kmfd_vbl" );
173 hbl->setStretchFactor( vbl, 2 );
179 mActionGroup =
new KMPopFilterActionWidget( i18n(
"Filter Action"), w );
182 mGlobalsBox =
new TQVGroupBox(i18n(
"Global Options"), w);
183 mShowLaterBtn =
new TQCheckBox(i18n(
"Always &show matched 'Download Later' messages in confirmation dialog"), mGlobalsBox);
184 TQWhatsThis::add( mShowLaterBtn, i18n(_wt_filterdlg_showLater) );
185 vbl->addWidget( mGlobalsBox, 0, TQt::AlignTop );
188 TQGroupBox *agb =
new TQGroupBox( 1 , Qt::Vertical, i18n(
"Filter Actions"), page1 );
190 vbl->addWidget( agb, 0, TQt::AlignTop );
192 mAdvOptsGroup =
new TQGroupBox ( 1 , Qt::Vertical,
193 i18n(
"Advanced Options"), page2);
195 TQWidget *adv_w =
new TQWidget( mAdvOptsGroup );
196 TQGridLayout *gl =
new TQGridLayout( adv_w, 8 , 3 ,
199 TQVBoxLayout *vbl3 =
new TQVBoxLayout( gl, spacingHint(),
"vbl3" );
200 vbl3->addStretch( 1 );
201 mApplyOnIn =
new TQCheckBox( i18n(
"Apply this filter to incoming messages:"), adv_w );
203 TQButtonGroup *bg =
new TQButtonGroup( 0,
"bg" );
204 bg->setExclusive(
true );
205 mApplyOnForAll =
new TQRadioButton( i18n(
"from all accounts"), adv_w );
208 mApplyOnForTraditional =
new TQRadioButton( i18n(
"from all but online IMAP accounts"), adv_w );
209 bg->insert( mApplyOnForTraditional );
210 vbl3->addWidget( mApplyOnForTraditional );
211 mApplyOnForChecked =
new TQRadioButton( i18n(
"from checked accounts only"), adv_w );
212 bg->insert( mApplyOnForChecked );
213 vbl3->addWidget( mApplyOnForChecked );
214 vbl3->addStretch( 2 );
220 mAccountList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
224 mApplyOnOut =
new TQCheckBox( i18n(
"Apply this filter to &sent messages"), adv_w );
225 gl->addMultiCellWidget( mApplyOnOut, 4, 4, 0, 3 );
227 mApplyOnCtrlJ =
new TQCheckBox( i18n(
"Apply this filter on manual &filtering"), adv_w );
228 gl->addMultiCellWidget( mApplyOnCtrlJ, 5, 5, 0, 3 );
230 mStopProcessingHere =
new TQCheckBox( i18n(
"If this filter &matches, stop processing here"), adv_w );
231 gl->addMultiCellWidget( mStopProcessingHere,
234 mConfigureShortcut =
new TQCheckBox( i18n(
"Add this filter to the Apply Filter menu"), adv_w );
235 gl->addMultiCellWidget( mConfigureShortcut, 7, 7, 0, 1 );
236 TQLabel *keyButtonLabel =
new TQLabel( i18n(
"Shortcut:" ), adv_w );
237 keyButtonLabel->setAlignment( AlignVCenter | AlignRight );
238 gl->addMultiCellWidget( keyButtonLabel, 7, 7, 2, 2 );
239 mKeyButton =
new KKeyButton( adv_w,
"FilterShortcutSelector" );
240 gl->addMultiCellWidget( mKeyButton, 7, 7, 3, 3 );
241 mKeyButton->setEnabled(
false );
242 mConfigureToolbar =
new TQCheckBox( i18n(
"Additionally add this filter to the toolbar"), adv_w );
243 gl->addMultiCellWidget( mConfigureToolbar, 8, 8, 0, 3 );
244 mConfigureToolbar->setEnabled(
false );
246 TQHBox *hbox =
new TQHBox( adv_w );
247 mFilterActionLabel =
new TQLabel( i18n(
"Icon for this filter:" ),
249 mFilterActionLabel->setEnabled(
false );
251 mFilterActionIconButton =
new KIconButton( hbox );
252 mFilterActionLabel->setBuddy( mFilterActionIconButton );
253 mFilterActionIconButton->setIconType( KIcon::NoGroup, KIcon::Any,
true );
254 mFilterActionIconButton->setIconSize( 16 );
255 mFilterActionIconButton->setIcon(
"gear" );
256 mFilterActionIconButton->setEnabled(
false );
258 gl->addMultiCellWidget( hbox, 9, 9, 0, 3 );
260 vbl2->addWidget( mAdvOptsGroup, 0, TQt::AlignTop );
263 vbl->addStretch( 1 );
266 connect(
mFilterList, TQT_SIGNAL(filterSelected(KMFilter*)),
271 connect( mShowLaterBtn, TQT_SIGNAL(toggled(
bool)),
272 mFilterList, TQT_SLOT(slotShowLaterToggled(
bool)));
275 connect(
mActionGroup, TQT_SIGNAL(actionChanged(
const KMPopFilterAction)),
281 this, TQT_SLOT(slotApplicabilityChanged()) );
283 this, TQT_SLOT(slotApplicabilityChanged()) );
284 connect( mApplyOnForTraditional, TQT_SIGNAL(clicked()),
285 this, TQT_SLOT(slotApplicabilityChanged()) );
286 connect( mApplyOnForChecked, TQT_SIGNAL(clicked()),
287 this, TQT_SLOT(slotApplicabilityChanged()) );
288 connect( mApplyOnOut, TQT_SIGNAL(clicked()),
289 this, TQT_SLOT(slotApplicabilityChanged()) );
290 connect( mApplyOnCtrlJ, TQT_SIGNAL(clicked()),
291 this, TQT_SLOT(slotApplicabilityChanged()) );
292 connect(
mAccountList, TQT_SIGNAL(clicked(TQListViewItem*)),
293 this, TQT_SLOT(slotApplicableAccountsChanged()) );
294 connect(
mAccountList, TQT_SIGNAL(spacePressed(TQListViewItem*)),
295 this, TQT_SLOT(slotApplicableAccountsChanged()) );
299 connect( mStopProcessingHere, TQT_SIGNAL(toggled(
bool)),
300 this, TQT_SLOT(slotStopProcessingButtonToggled(
bool)) );
302 connect( mConfigureShortcut, TQT_SIGNAL(toggled(
bool)),
303 this, TQT_SLOT(slotConfigureShortcutButtonToggled(
bool)) );
305 connect( mKeyButton, TQT_SIGNAL( capturedShortcut(
const KShortcut& ) ),
306 this, TQT_SLOT( slotCapturedShortcutChanged(
const KShortcut& ) ) );
308 connect( mConfigureToolbar, TQT_SIGNAL(toggled(
bool)),
309 this, TQT_SLOT(slotConfigureToolbarButtonToggled(
bool)) );
311 connect( mFilterActionIconButton, TQT_SIGNAL( iconChanged( TQString ) ),
312 this, TQT_SLOT( slotFilterActionIconChanged( TQString ) ) );
317 this, TQT_SLOT(slotReset()) );
319 connect(
mFilterList, TQT_SIGNAL( applyWidgets() ),
320 this, TQT_SLOT( slotUpdateFilter() ) );
327 connect(
this, TQT_SIGNAL(applyClicked()),
331 connect(
this, TQT_SIGNAL(okClicked()),
335 connect(
this, TQT_SIGNAL(okClicked()),
336 this, TQT_SLOT(slotSaveSize()) );
339 connect(
this, TQT_SIGNAL(finished()),
340 this, TQT_SLOT(slotFinished()) );
342 KConfigGroup geometry( KMKernel::config(),
"Geometry");
343 const char * configKey
344 = bPopFilter ?
"popFilterDialogSize" :
"filterDialogSize";
345 if ( geometry.hasKey( configKey ) )
346 resize( geometry.readSizeEntry( configKey ) );
354 void KMFilterDlg::slotFinished() {
358 void KMFilterDlg::slotSaveSize() {
359 KConfigGroup geometry( KMKernel::config(),
"Geometry" );
360 geometry.writeEntry( bPopFilter ?
"popFilterDialogSize" :
"filterDialogSize", size() );
366 mFilter->setAction(aAction);
375 mGlobalsBox->setEnabled(
true );
380 mAdvOptsGroup->setEnabled(
true );
387 kdDebug(5006) <<
"apply on inbound == "
388 << aFilter->applyOnInbound() << endl;
389 kdDebug(5006) <<
"apply on outbound == "
390 << aFilter->applyOnOutbound() << endl;
391 kdDebug(5006) <<
"apply on explicit == "
392 << aFilter->applyOnExplicit() << endl;
397 const bool applyOnIn = aFilter->applyOnInbound();
398 const bool applyOnForAll = aFilter->applicability() == KMFilter::All;
399 const bool applyOnTraditional = aFilter->applicability() == KMFilter::ButImap;
400 const bool applyOnOut = aFilter->applyOnOutbound();
401 const bool applyOnExplicit = aFilter->applyOnExplicit();
402 const bool stopHere = aFilter->stopProcessingHere();
403 const bool configureShortcut = aFilter->configureShortcut();
404 const bool configureToolbar = aFilter->configureToolbar();
405 const TQString icon = aFilter->icon();
406 const KShortcut shortcut( aFilter->shortcut() );
410 mApplyOnForTraditional->setEnabled( applyOnIn );
411 mApplyOnForChecked->setEnabled( applyOnIn );
413 mApplyOnForTraditional->setChecked( applyOnTraditional );
414 mApplyOnForChecked->setChecked( !applyOnForAll && !applyOnTraditional );
415 mAccountList->setEnabled( mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked() );
416 slotUpdateAccountList();
417 mApplyOnOut->setChecked( applyOnOut );
418 mApplyOnCtrlJ->setChecked( applyOnExplicit );
419 mStopProcessingHere->setChecked( stopHere );
420 mConfigureShortcut->setChecked( configureShortcut );
421 mKeyButton->setShortcut( shortcut,
false );
422 mConfigureToolbar->setChecked( configureToolbar );
423 mFilterActionIconButton->setIcon( icon );
427 void KMFilterDlg::slotReset()
434 mGlobalsBox->setEnabled(
false );
437 mAdvOptsGroup->setEnabled(
false );
438 slotUpdateAccountList();
442 void KMFilterDlg::slotUpdateFilter()
450 void KMFilterDlg::slotApplicabilityChanged()
453 mFilter->setApplyOnInbound(
mApplyOnIn->isChecked() );
454 mFilter->setApplyOnOutbound( mApplyOnOut->isChecked() );
455 mFilter->setApplyOnExplicit( mApplyOnCtrlJ->isChecked() );
457 mFilter->setApplicability( KMFilter::All );
458 else if ( mApplyOnForTraditional->isChecked() )
459 mFilter->setApplicability( KMFilter::ButImap );
460 else if ( mApplyOnForChecked->isChecked() )
461 mFilter->setApplicability( KMFilter::Checked );
464 mApplyOnForTraditional->setEnabled(
mApplyOnIn->isChecked() );
465 mApplyOnForChecked->setEnabled(
mApplyOnIn->isChecked() );
466 mAccountList->setEnabled( mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked() );
470 while ( it.current() ) {
471 TQCheckListItem *item =
dynamic_cast<TQCheckListItem*
>( it.current() );
473 int id = item->text( 2 ).toInt();
474 item->setOn( mFilter->applyOnAccount(
id ) );
479 kdDebug(5006) <<
"KMFilterDlg: setting filter to be applied at "
480 << ( mFilter->applyOnInbound() ?
"incoming " :
"" )
481 << ( mFilter->applyOnOutbound() ?
"outgoing " :
"" )
482 << ( mFilter->applyOnExplicit() ?
"explicit CTRL-J" :
"" )
487 void KMFilterDlg::slotApplicableAccountsChanged()
489 if ( mFilter && mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked() ) {
492 while ( it.current() ) {
493 TQCheckListItem *item =
dynamic_cast<TQCheckListItem*
>( it.current() );
495 int id = item->text( 2 ).toInt();
496 mFilter->setApplyOnAccount(
id, item->isOn() );
503 void KMFilterDlg::slotStopProcessingButtonToggled(
bool aChecked )
506 mFilter->setStopProcessingHere( aChecked );
509 void KMFilterDlg::slotConfigureShortcutButtonToggled(
bool aChecked )
512 mFilter->setConfigureShortcut( aChecked );
513 mKeyButton->setEnabled( aChecked );
514 mConfigureToolbar->setEnabled( aChecked );
515 mFilterActionIconButton->setEnabled( aChecked );
516 mFilterActionLabel->setEnabled( aChecked );
520 void KMFilterDlg::slotCapturedShortcutChanged(
const KShortcut& sc )
523 if ( mySc == mKeyButton->shortcut() )
return;
527 if ( mySc.isNull() || mySc.toString().isEmpty() )
529 if ( !mySc.isNull() && !( kmkernel->getKMMainWidget()->shortcutIsValid( mySc ) ) ) {
530 TQString msg( i18n(
"The selected shortcut is already used, "
531 "please select a different one." ) );
532 KMessageBox::sorry(
this, msg );
534 mKeyButton->setShortcut( mySc,
false );
536 mFilter->setShortcut( mKeyButton->shortcut() );
540 void KMFilterDlg::slotConfigureToolbarButtonToggled(
bool aChecked )
543 mFilter->setConfigureToolbar( aChecked );
546 void KMFilterDlg::slotFilterActionIconChanged( TQString icon )
549 mFilter->setIcon( icon );
552 void KMFilterDlg::slotUpdateAccountList()
555 TQListViewItem *top = 0;
556 for( KMAccount *a = kmkernel->acctMgr()->first(); a!=0;
557 a = kmkernel->acctMgr()->next() ) {
558 TQCheckListItem *listItem =
559 new TQCheckListItem(
mAccountList, top, a->name(), TQCheckListItem::CheckBox );
560 listItem->setText( 1, a->type() );
561 listItem->setText( 2, TQString(
"%1" ).arg( a->id() ) );
563 listItem->setOn( mFilter->applyOnAccount( a->id() ) );
581 : TQGroupBox( 1, Qt::Horizontal, title, parent, name ),
582 bPopFilter(popFilter)
590 TQWhatsThis::add(
mListBox, i18n(_wt_filterlist) );
593 TQHBox *hb =
new TQHBox(
this);
595 mBtnTop =
new KPushButton( TQString(), hb );
596 mBtnTop->setAutoRepeat(
true );
597 mBtnTop->setIconSet( BarIconSet(
"top", KIcon::SizeSmall ) );
598 mBtnTop->setMinimumSize( mBtnTop->sizeHint() * 1.2 );
599 mBtnUp =
new KPushButton( TQString(), hb );
600 mBtnUp->setAutoRepeat(
true );
601 mBtnUp->setIconSet( BarIconSet(
"up", KIcon::SizeSmall ) );
602 mBtnUp->setMinimumSize( mBtnUp->sizeHint() * 1.2 );
603 mBtnDown =
new KPushButton( TQString(), hb );
604 mBtnDown->setAutoRepeat(
true );
605 mBtnDown->setIconSet( BarIconSet(
"down", KIcon::SizeSmall ) );
606 mBtnDown->setMinimumSize( mBtnDown->sizeHint() * 1.2 );
607 mBtnBot =
new KPushButton( TQString(), hb );
608 mBtnBot->setAutoRepeat(
true );
609 mBtnBot->setIconSet( BarIconSet(
"bottom", KIcon::SizeSmall ) );
610 mBtnBot->setMinimumSize( mBtnBot->sizeHint() * 1.2 );
611 TQToolTip::add( mBtnTop, i18n(
"Top") );
612 TQToolTip::add( mBtnUp, i18n(
"Up") );
613 TQToolTip::add( mBtnDown, i18n(
"Down") );
614 TQToolTip::add( mBtnBot, i18n(
"Bottom") );
615 TQWhatsThis::add( mBtnTop, i18n(_wt_filterlist_top) );
616 TQWhatsThis::add( mBtnUp, i18n(_wt_filterlist_up) );
617 TQWhatsThis::add( mBtnDown, i18n(_wt_filterlist_down) );
618 TQWhatsThis::add( mBtnBot, i18n(_wt_filterlist_bot) );
621 hb =
new TQHBox(
this);
623 mBtnNew =
new TQPushButton( TQString(), hb );
624 mBtnNew->setPixmap( BarIcon(
"filenew", KIcon::SizeSmall ) );
626 mBtnCopy =
new TQPushButton( TQString(), hb );
627 mBtnCopy->setIconSet( BarIconSet(
"editcopy", KIcon::SizeSmall ) );
628 mBtnCopy->setMinimumSize( mBtnCopy->sizeHint() * 1.2 );
629 mBtnDelete =
new TQPushButton( TQString(), hb );
630 mBtnDelete->setIconSet( BarIconSet(
"editdelete", KIcon::SizeSmall ) );
631 mBtnDelete->setMinimumSize( mBtnDelete->sizeHint() * 1.2 );
632 mBtnRename =
new TQPushButton( i18n(
"Rename..."), hb );
633 TQToolTip::add(
mBtnNew, i18n(
"New") );
634 TQToolTip::add( mBtnCopy, i18n(
"Copy") );
635 TQToolTip::add( mBtnDelete, i18n(
"Delete"));
636 TQWhatsThis::add(
mBtnNew, i18n(_wt_filterlist_new) );
637 TQWhatsThis::add( mBtnCopy, i18n(_wt_filterlist_copy) );
638 TQWhatsThis::add( mBtnDelete, i18n(_wt_filterlist_delete) );
639 TQWhatsThis::add( mBtnRename, i18n(_wt_filterlist_rename) );
643 hb =
new TQHBox(
this );
645 TQPushButton *btn =
new TQPushButton( i18n(
"Select Source Folders"), hb );
646 connect( btn, TQT_SIGNAL(clicked()), TQT_SLOT(slotSelectSourceFolders()) );
651 connect(
mListBox, TQT_SIGNAL(highlighted(
int)),
653 connect(
mListBox, TQT_SIGNAL( doubleClicked ( TQListBoxItem * )),
655 connect( mBtnTop, TQT_SIGNAL(clicked()),
657 connect( mBtnUp, TQT_SIGNAL(clicked()),
658 this, TQT_SLOT(
slotUp()) );
659 connect( mBtnDown, TQT_SIGNAL(clicked()),
661 connect( mBtnBot, TQT_SIGNAL(clicked()),
663 connect(
mBtnNew, TQT_SIGNAL(clicked()),
665 connect( mBtnCopy, TQT_SIGNAL(clicked()),
667 connect( mBtnDelete, TQT_SIGNAL(clicked()),
669 connect( mBtnRename, TQT_SIGNAL(clicked()),
679 const TQString & value )
683 KMFilter *newFilter =
new KMFilter(0, bPopFilter);
684 newFilter->pattern()->append( newRule );
685 newFilter->pattern()->setName( TQString(
"<%1>:%2").arg( TQString(field) ).arg( TQString(value) ) );
689 newFilter->actions()->append( desc->create() );
691 insertFilter( newFilter );
705 TQString shouldBeName = p->
name();
708 if ( shouldBeName.stripWhiteSpace().isEmpty() ) {
714 if ( !p->isEmpty() && p->first() && !p->first()->field().stripWhiteSpace().isEmpty() )
715 shouldBeName = TQString(
"<%1>: %2" ).arg( TQString(p->first()->field()) ).arg( TQString(p->first()->contents()) );
717 shouldBeName =
"<" + i18n(
"unnamed") +
">";
721 if ( displayedName == shouldBeName )
return;
745 fm = kmkernel->popFilterMgr();
747 fm = kmkernel->filterMgr();
752 fm->setShowLaterMsgs(mShowLater);
754 fm->setFilters( newFilters );
755 if (fm->atLeastOneOnlineImapFolderTarget()) {
756 TQString str = i18n(
"At least one filter targets a folder on an online "
757 "IMAP account. Such filters will only be applied "
758 "when manually filtering and when filtering "
759 "incoming online IMAP mail.");
760 KMessageBox::information(
this, str, TQString(),
761 "filterDlgOnlineImapCheck" );
768 TQValueList<KMFilter*> filters;
769 TQStringList emptyFilters;
771 for ( it.toFirst() ; it.current() ; ++it ) {
772 KMFilter *f =
new KMFilter( **it );
779 emptyFilters << f->name();
785 if ( !emptyFilters.empty() ) {
786 TQString msg = i18n(
"The following filters have not been saved because they "
787 "were invalid (e.g. containing no actions or no search "
789 KMessageBox::informationList( 0, msg, emptyFilters, TQString(),
790 "ShowInvalidFilterWarning" );
810 insertFilter(
new KMFilter(0, bPopFilter) );
817 kdDebug(5006) <<
"KMFilterListBox::slotCopy called while no filter is selected, ignoring." << endl;
831 insertFilter(
new KMFilter( *filter ) );
838 kdDebug(5006) <<
"KMFilterListBox::slotDelete called while no filter is selected, ignoring." << endl;
853 mListBox->removeItem( oIdxSelItem );
857 if ( count > oIdxSelItem )
859 mListBox->setSelected( oIdxSelItem,
true );
863 mListBox->setSelected( count - 1,
true );
872 kdDebug(5006) <<
"KMFilterListBox::slotTop called while no filter is selected, ignoring." << endl;
876 kdDebug(5006) <<
"KMFilterListBox::slotTop called while the _topmost_ filter is selected, ignoring." << endl;
887 kdDebug(5006) <<
"KMFilterListBox::slotUp called while no filter is selected, ignoring." << endl;
891 kdDebug(5006) <<
"KMFilterListBox::slotUp called while the _topmost_ filter is selected, ignoring." << endl;
902 kdDebug(5006) <<
"KMFilterListBox::slotDown called while no filter is selected, ignoring." << endl;
906 kdDebug(5006) <<
"KMFilterListBox::slotDown called while the _last_ filter is selected, ignoring." << endl;
917 kdDebug(5006) <<
"KMFilterListBox::slotBottom called while no filter is selected, ignoring." << endl;
921 kdDebug(5006) <<
"KMFilterListBox::slotBottom called while the _last_ filter is selected, ignoring." << endl;
932 kdDebug(5006) <<
"KMFilterListBox::slotRename called while no filter is selected, ignoring." << endl;
936 bool okPressed = false ;
944 TQValidator *validator =
new TQRegExpValidator( TQRegExp(
".*" ), 0 );
945 TQString newName = KInputDialog::getText
947 i18n(
"Rename Filter"),
948 i18n(
"Rename filter \"%1\" to:\n(leave the field empty for automatic naming)")
949 .arg( filter->pattern()->name() ) ,
950 filter->pattern()->name() ,
951 &okPressed, topLevelWidget(), 0, validator
955 if ( !okPressed )
return;
957 if ( newName.isEmpty() ) {
960 filter->pattern()->setName(
"<>" );
961 filter->setAutoNaming(
true );
963 filter->pattern()->setName( newName );
964 filter->setAutoNaming(
false );
970 void KMFilterListBox::slotSelectSourceFolders()
972 FolderSetSelector dlg( kmkernel->getKMMainWidget()->folderTree(), this );
973 dlg.setCaption( i18n(
"Select Folders to Filter" ) );
974 if ( !GlobalSettings::filterSourceFolders().isEmpty() )
975 dlg.setSelectedFolders( GlobalSettings::filterSourceFolders() );
976 if ( dlg.exec() == TQDialog::Accepted ) {
977 GlobalSettings::setFilterSourceFolders( dlg.selectedFolders() );
981 void KMFilterListBox::enableControls()
987 mBtnTop->setEnabled( aFilterIsSelected && !theFirst );
988 mBtnUp->setEnabled( aFilterIsSelected && !theFirst );
989 mBtnDown->setEnabled( aFilterIsSelected && !theLast );
990 mBtnBot->setEnabled( aFilterIsSelected && !theLast );
991 mBtnCopy->setEnabled( aFilterIsSelected );
992 mBtnDelete->setEnabled( aFilterIsSelected );
993 mBtnRename->setEnabled( aFilterIsSelected );
995 if ( aFilterIsSelected )
1002 setEnabled(
false );
1006 blockSignals(
true );
1012 const KMFilterMgr *manager = 0;
1015 mShowLater = kmkernel->popFilterMgr()->showLaterMsgs();
1016 manager = kmkernel->popFilterMgr();
1020 manager = kmkernel->filterMgr();
1022 Q_ASSERT( manager );
1024 TQValueListConstIterator<KMFilter*> it;
1025 for ( it = manager->filters().constBegin() ; it != manager->filters().constEnd() ; ++it ) {
1027 mListBox->insertItem( (*it)->pattern()->name() );
1030 blockSignals(
false );
1036 if ( !
mListBox->count() && createDummyFilter )
1045 void KMFilterListBox::insertFilter( KMFilter* aFilter )
1066 void KMFilterListBox::appendFilter( KMFilter* aFilter )
1069 mListBox->insertItem( aFilter->pattern()->name(), -1 );
1072 void KMFilterListBox::swapNeighbouringFilters(
int untouchedOne,
int movedOne )
1075 assert( untouchedOne - movedOne == 1 || movedOne - untouchedOne == 1 );
1079 TQListBoxItem *item =
mListBox->item( movedOne );
1083 mListBox->insertItem( item, untouchedOne );
1091 void KMFilterListBox::swapFilters(
int from,
int to )
1093 TQListBoxItem *item =
mListBox->item( from );
1112 : TQHBox( parent, name )
1115 mActionList.setAutoDelete(
true );
1117 mComboBox =
new TQComboBox(
false ,
this );
1118 assert( mComboBox );
1119 mWidgetStack =
new TQWidgetStack(
this);
1120 assert( mWidgetStack );
1124 TQPtrListIterator<KMFilterActionDesc> it ( kmkernel->filterActionDict()->list() );
1125 for ( i=0, it.toFirst() ; it.current() ; ++it, ++i ) {
1129 mActionList.append( a );
1133 mComboBox->insertItem( (*it)->label );
1136 mWidgetStack->addWidget(
new TQLabel( i18n(
"Please select an action."), mWidgetStack ), i );
1137 mWidgetStack->raiseWidget(i);
1138 mComboBox->insertItem(
" " );
1139 mComboBox->setCurrentItem(i);
1142 mComboBox->setSizeLimit( mComboBox->count() );
1147 mComboBox->adjustSize();
1148 mComboBox->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
1149 setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ) );
1153 setFocusProxy( mComboBox );
1156 connect( mComboBox, TQT_SIGNAL(activated(
int)),
1157 mWidgetStack, TQT_SLOT(raiseWidget(
int)) );
1163 bool found = false ;
1164 int count = mComboBox->count() - 1 ;
1165 TQString label = ( aAction ) ? aAction->
label() : TQString() ;
1169 for ( ; i < count ; i++ )
1170 if ( aAction && mComboBox->text(i) == label ) {
1176 mComboBox->setCurrentItem(i);
1177 mWidgetStack->raiseWidget(i);
1180 mActionList.at(i)->clearParamWidget( mWidgetStack->widget(i) );
1181 if ( found )
return;
1184 mComboBox->setCurrentItem( count );
1185 mWidgetStack->raiseWidget( count) ;
1192 KMFilterActionDesc *desc = (*kmkernel->filterActionDict())[ mComboBox->currentText() ];
1212 KMFilterActionWidgetLister::KMFilterActionWidgetLister( TQWidget *parent,
const char* name )
1213 : KWidgetLister( 1, FILTER_MAX_ACTIONS, parent, name )
1218 KMFilterActionWidgetLister::~KMFilterActionWidgetLister()
1222 void KMFilterActionWidgetLister::setActionList( TQPtrList<KMFilterAction> *aList )
1227 regenerateActionListFromWidgets();
1229 mActionList = aList;
1231 ((TQWidget*)parent())->setEnabled(
true );
1233 if ( aList->count() == 0 ) {
1238 int superfluousItems = (int)mActionList->count() - mMaxWidgets ;
1239 if ( superfluousItems > 0 ) {
1240 kdDebug(5006) <<
"KMFilterActionWidgetLister: Clipping action list to "
1241 << mMaxWidgets <<
" items!" << endl;
1243 for ( ; superfluousItems ; superfluousItems-- )
1244 mActionList->removeLast();
1248 setNumberOfShownWidgetsTo( mActionList->count() );
1251 TQPtrListIterator<KMFilterAction> aIt( *mActionList );
1252 TQPtrListIterator<TQWidget> wIt( mWidgetList );
1253 for ( aIt.toFirst(), wIt.toFirst() ;
1254 aIt.current() && wIt.current() ; ++aIt, ++wIt )
1258 void KMFilterActionWidgetLister::reset()
1261 regenerateActionListFromWidgets();
1265 ((TQWidget*)parent())->setEnabled(
false );
1268 TQWidget* KMFilterActionWidgetLister::createWidget( TQWidget *parent )
1273 void KMFilterActionWidgetLister::clearWidget( TQWidget *aWidget )
1279 void KMFilterActionWidgetLister::regenerateActionListFromWidgets()
1281 if ( !mActionList )
return;
1283 mActionList->clear();
1285 TQPtrListIterator<TQWidget> it( mWidgetList );
1286 for ( it.toFirst() ; it.current() ; ++it ) {
1289 mActionList->append( a );
1300 KMPopFilterActionWidget::KMPopFilterActionWidget(
const TQString& title, TQWidget *parent,
const char* name )
1301 : TQVButtonGroup( title, parent, name )
1303 mActionMap[Down] =
new TQRadioButton( i18n(
"&Download mail"),
this );
1304 mActionMap[Later] =
new TQRadioButton( i18n(
"Download mail la&ter"),
this );
1305 mActionMap[Delete] =
new TQRadioButton( i18n(
"D&elete mail from server"),
this );
1306 mIdMap[id(mActionMap[Later])] = Later;
1307 mIdMap[id(mActionMap[Down])] = Down;
1308 mIdMap[id(mActionMap[Delete])] = Delete;
1310 connect(
this, TQT_SIGNAL(clicked(
int)),
1311 this, TQT_SLOT( slotActionClicked(
int)) );
1314 void KMPopFilterActionWidget::setAction( KMPopFilterAction aAction )
1316 if( aAction == NoAction)
1323 blockSignals(
true );
1324 if(!mActionMap[aAction]->isChecked())
1326 mActionMap[aAction]->setChecked(
true );
1328 blockSignals(
false );
1333 KMPopFilterAction KMPopFilterActionWidget::action()
1338 void KMPopFilterActionWidget::slotActionClicked(
int aId)
1340 emit actionChanged(mIdMap[aId]);
1341 setAction(mIdMap[aId]);
1344 void KMPopFilterActionWidget::reset()
1346 blockSignals(
true );
1347 mActionMap[Down]->setChecked(
true );
1348 blockSignals(
false );
1350 setEnabled(
false );
1358 if (filters.isEmpty())
return;
1360 TQValueListConstIterator<KMFilter*> it;
1362 for ( it = filters.constBegin() ; it != filters.constEnd() ; ++it ) {
1372 TQValueList<KMFilter*>::iterator it;
1373 for ( it = filters.begin(); it != filters.end(); ++it )
1377 #include "kmfilterdlg.moc"