37 #include "rulewidgethandlermanager.h"
39 #include "interfaces/rulewidgethandler.h"
43 #include <kiconloader.h>
45 #include <tqwidgetstack.h>
47 #include <tqcstring.h>
49 #include <tqobjectlist.h>
62 TextRuleWidgetHandler() :
KMail::RuleWidgetHandler() {}
63 ~TextRuleWidgetHandler() {}
65 TQWidget * createFunctionWidget(
int number,
66 TQWidgetStack *functionStack,
67 const TQObject *receiver )
const;
68 TQWidget * createValueWidget(
int number,
69 TQWidgetStack *valueStack,
70 const TQObject *receiver )
const;
72 const TQWidgetStack *functionStack )
const;
73 TQString value(
const TQCString & field,
74 const TQWidgetStack *functionStack,
75 const TQWidgetStack *valueStack )
const;
76 TQString prettyValue(
const TQCString & field,
77 const TQWidgetStack *functionStack,
78 const TQWidgetStack *valueStack )
const;
79 bool handlesField(
const TQCString & field )
const;
80 void reset( TQWidgetStack *functionStack,
81 TQWidgetStack *valueStack )
const;
82 bool setRule( TQWidgetStack *functionStack,
83 TQWidgetStack *valueStack,
85 bool update(
const TQCString & field,
86 TQWidgetStack *functionStack,
87 TQWidgetStack *valueStack )
const;
91 TQString currentValue(
const TQWidgetStack *valueStack,
97 MessageRuleWidgetHandler() :
KMail::RuleWidgetHandler() {}
98 ~MessageRuleWidgetHandler() {}
100 TQWidget * createFunctionWidget(
int number,
101 TQWidgetStack *functionStack,
102 const TQObject *receiver )
const;
103 TQWidget * createValueWidget(
int number,
104 TQWidgetStack *valueStack,
105 const TQObject *receiver )
const;
107 const TQWidgetStack *functionStack )
const;
108 TQString value(
const TQCString & field,
109 const TQWidgetStack *functionStack,
110 const TQWidgetStack *valueStack )
const;
111 TQString prettyValue(
const TQCString & field,
112 const TQWidgetStack *functionStack,
113 const TQWidgetStack *valueStack )
const;
114 bool handlesField(
const TQCString & field )
const;
115 void reset( TQWidgetStack *functionStack,
116 TQWidgetStack *valueStack )
const;
117 bool setRule( TQWidgetStack *functionStack,
118 TQWidgetStack *valueStack,
120 bool update(
const TQCString & field,
121 TQWidgetStack *functionStack,
122 TQWidgetStack *valueStack )
const;
126 TQString currentValue(
const TQWidgetStack *valueStack,
133 StatusRuleWidgetHandler() :
KMail::RuleWidgetHandler() {}
134 ~StatusRuleWidgetHandler() {}
136 TQWidget * createFunctionWidget(
int number,
137 TQWidgetStack *functionStack,
138 const TQObject *receiver )
const;
139 TQWidget * createValueWidget(
int number,
140 TQWidgetStack *valueStack,
141 const TQObject *receiver )
const;
143 const TQWidgetStack *functionStack )
const;
144 TQString value(
const TQCString & field,
145 const TQWidgetStack *functionStack,
146 const TQWidgetStack *valueStack )
const;
147 TQString prettyValue(
const TQCString & field,
148 const TQWidgetStack *functionStack,
149 const TQWidgetStack *valueStack )
const;
150 bool handlesField(
const TQCString & field )
const;
151 void reset( TQWidgetStack *functionStack,
152 TQWidgetStack *valueStack )
const;
153 bool setRule( TQWidgetStack *functionStack,
154 TQWidgetStack *valueStack,
156 bool update(
const TQCString & field,
157 TQWidgetStack *functionStack,
158 TQWidgetStack *valueStack )
const;
162 int currenStatusValue(
const TQWidgetStack *valueStack )
const;
167 NumericRuleWidgetHandler() :
KMail::RuleWidgetHandler() {}
168 ~NumericRuleWidgetHandler() {}
170 TQWidget * createFunctionWidget(
int number,
171 TQWidgetStack *functionStack,
172 const TQObject *receiver )
const;
173 TQWidget * createValueWidget(
int number,
174 TQWidgetStack *valueStack,
175 const TQObject *receiver )
const;
177 const TQWidgetStack *functionStack )
const;
178 TQString value(
const TQCString & field,
179 const TQWidgetStack *functionStack,
180 const TQWidgetStack *valueStack )
const;
181 TQString prettyValue(
const TQCString & field,
182 const TQWidgetStack *functionStack,
183 const TQWidgetStack *valueStack )
const;
184 bool handlesField(
const TQCString & field )
const;
185 void reset( TQWidgetStack *functionStack,
186 TQWidgetStack *valueStack )
const;
187 bool setRule( TQWidgetStack *functionStack,
188 TQWidgetStack *valueStack,
190 bool update(
const TQCString & field,
191 TQWidgetStack *functionStack,
192 TQWidgetStack *valueStack )
const;
196 TQString currentValue(
const TQWidgetStack *valueStack )
const;
200 KMail::RuleWidgetHandlerManager::RuleWidgetHandlerManager()
202 registerHandler(
new NumericRuleWidgetHandler() );
203 registerHandler(
new StatusRuleWidgetHandler() );
204 registerHandler(
new MessageRuleWidgetHandler() );
207 registerHandler(
new TextRuleWidgetHandler() );
210 KMail::RuleWidgetHandlerManager::~RuleWidgetHandlerManager()
212 for_each( mHandlers.begin(), mHandlers.end(),
213 DeleteAndSetToZero<RuleWidgetHandler>() );
216 void KMail::RuleWidgetHandlerManager::registerHandler(
const RuleWidgetHandler * handler )
220 unregisterHandler( handler );
221 mHandlers.push_back( handler );
224 void KMail::RuleWidgetHandlerManager::unregisterHandler(
const RuleWidgetHandler * handler )
227 mHandlers.erase( remove( mHandlers.begin(), mHandlers.end(), handler ), mHandlers.end() );
234 int childCount(
const TQObject *parent,
const char *objName )
236 TQObjectList *list = parent->queryList( 0, objName,
false,
false );
239 const int count = list->count();
240 delete list; list = 0;
245 void KMail::RuleWidgetHandlerManager::createWidgets( TQWidgetStack *functionStack,
246 TQWidgetStack *valueStack,
247 const TQObject *receiver )
const
249 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
252 ( w = (*it)->createFunctionWidget( i, functionStack, receiver ) );
254 if ( childCount( functionStack, w->name() ) < 2 ) {
256 functionStack->addWidget( w );
260 kdDebug(5006) <<
"RuleWidgetHandlerManager::createWidgets: "
261 << w->name() <<
" already exists in functionStack"
267 ( w = (*it)->createValueWidget( i, valueStack, receiver ) );
269 if ( childCount( valueStack, w->name() ) < 2 ) {
271 valueStack->addWidget( w );
275 kdDebug(5006) <<
"RuleWidgetHandlerManager::createWidgets: "
276 << w->name() <<
" already exists in valueStack"
285 const TQWidgetStack *functionStack )
const
287 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
290 if ( func != KMSearchRule::FuncNone )
293 return KMSearchRule::FuncNone;
296 TQString KMail::RuleWidgetHandlerManager::value(
const TQCString& field,
297 const TQWidgetStack *functionStack,
298 const TQWidgetStack *valueStack )
const
300 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
301 const TQString val = (*it)->value( field, functionStack, valueStack );
302 if ( !val.isEmpty() )
308 TQString KMail::RuleWidgetHandlerManager::prettyValue(
const TQCString& field,
309 const TQWidgetStack *functionStack,
310 const TQWidgetStack *valueStack )
const
312 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
313 const TQString val = (*it)->prettyValue( field, functionStack, valueStack );
314 if ( !val.isEmpty() )
320 void KMail::RuleWidgetHandlerManager::reset( TQWidgetStack *functionStack,
321 TQWidgetStack *valueStack )
const
323 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
324 (*it)->reset( functionStack, valueStack );
326 update(
"", functionStack, valueStack );
329 void KMail::RuleWidgetHandlerManager::setRule( TQWidgetStack *functionStack,
330 TQWidgetStack *valueStack,
334 reset( functionStack, valueStack );
335 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
336 if ( (*it)->setRule( functionStack, valueStack, rule ) )
341 void KMail::RuleWidgetHandlerManager::update(
const TQCString &field,
342 TQWidgetStack *functionStack,
343 TQWidgetStack *valueStack )
const
347 for ( const_iterator it = mHandlers.begin(); it != mHandlers.end(); ++it ) {
348 if ( (*it)->update( field, functionStack, valueStack ) )
360 TQObject* TQObject_child_const(
const TQObject *parent,
361 const char *objName )
363 const TQObjectList list = parent->childrenListObject();
364 if ( list.isEmpty() )
367 TQObjectListIterator it( list );
369 while ( ( obj = it.current() ) ) {
371 if ( !objName || qstrcmp( objName, obj->name() ) == 0 )
382 #include "kmaddrbook.h"
383 #include "kmsearchpattern.h"
384 #include "regexplineedit.h"
385 using KMail::RegExpLineEdit;
387 #include <tdelocale.h>
388 #include <knuminput.h>
390 #include <tqcombobox.h>
402 static const struct {
404 const char *displayName;
405 } TextFunctions[] = {
406 { KMSearchRule::FuncContains, I18N_NOOP(
"contains" ) },
407 { KMSearchRule::FuncContainsNot, I18N_NOOP(
"does not contain" ) },
408 { KMSearchRule::FuncEquals, I18N_NOOP(
"equals" ) },
409 { KMSearchRule::FuncNotEqual, I18N_NOOP(
"does not equal" ) },
410 { KMSearchRule::FuncRegExp, I18N_NOOP(
"matches regular expr." ) },
411 { KMSearchRule::FuncNotRegExp, I18N_NOOP(
"does not match reg. expr." ) },
412 { KMSearchRule::FuncIsInAddressbook, I18N_NOOP(
"is in address book" ) },
413 { KMSearchRule::FuncIsNotInAddressbook, I18N_NOOP(
"is not in address book" ) },
414 { KMSearchRule::FuncIsInCategory, I18N_NOOP(
"is in category" ) },
415 { KMSearchRule::FuncIsNotInCategory, I18N_NOOP(
"is not in category" ) }
417 static const int TextFunctionCount =
418 sizeof( TextFunctions ) /
sizeof( *TextFunctions );
422 TQWidget * TextRuleWidgetHandler::createFunctionWidget(
int number,
423 TQWidgetStack *functionStack,
424 const TQObject *receiver )
const
429 TQComboBox *funcCombo =
new TQComboBox( functionStack,
"textRuleFuncCombo" );
430 for (
int i = 0; i < TextFunctionCount; ++i ) {
431 funcCombo->insertItem( i18n( TextFunctions[i].displayName ) );
433 funcCombo->adjustSize();
434 TQObject::connect( funcCombo, TQ_SIGNAL( activated(
int ) ),
435 receiver, TQ_SLOT( slotFunctionChanged() ) );
441 TQWidget * TextRuleWidgetHandler::createValueWidget(
int number,
442 TQWidgetStack *valueStack,
443 const TQObject *receiver )
const
446 RegExpLineEdit *lineEdit =
447 new RegExpLineEdit( valueStack,
"regExpLineEdit" );
448 TQObject::connect( lineEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
449 receiver, TQ_SLOT( slotValueChanged() ) );
455 return new TQLabel( valueStack,
"textRuleValueHider" );
459 TQComboBox *combo =
new TQComboBox( valueStack,
"categoryCombo" );
460 TQStringList categories = KabcBridge::categories();
461 combo->insertStringList( categories );
462 TQObject::connect( combo, TQ_SIGNAL( activated(
int ) ),
463 receiver, TQ_SLOT( slotValueChanged() ) );
474 const TQComboBox *funcCombo =
475 dynamic_cast<TQComboBox*
>( TQObject_child_const( functionStack,
476 "textRuleFuncCombo" ) );
481 return TextFunctions[funcCombo->currentItem()].id;
484 kdDebug(5006) <<
"TextRuleWidgetHandler::currentFunction: "
485 "textRuleFuncCombo not found." << endl;
486 return KMSearchRule::FuncNone;
492 const TQWidgetStack *functionStack )
const
494 return currentFunction( functionStack );
499 TQString TextRuleWidgetHandler::currentValue(
const TQWidgetStack *valueStack,
503 if ( func == KMSearchRule::FuncIsInCategory ||
504 func == KMSearchRule::FuncIsNotInCategory ) {
505 const TQComboBox *combo=
506 dynamic_cast<TQComboBox*
>( TQObject_child_const( valueStack,
512 return combo->currentText();
515 kdDebug(5006) <<
"TextRuleWidgetHandler::currentValue: "
516 "categoryCombo not found." << endl;
522 const RegExpLineEdit *lineEdit =
523 dynamic_cast<RegExpLineEdit*
>( TQObject_child_const( valueStack,
524 "regExpLineEdit" ) );
529 return lineEdit->text();
532 kdDebug(5006) <<
"TextRuleWidgetHandler::currentValue: "
533 "regExpLineEdit not found." << endl;
541 TQString TextRuleWidgetHandler::value(
const TQCString &,
542 const TQWidgetStack *functionStack,
543 const TQWidgetStack *valueStack )
const
546 if ( func == KMSearchRule::FuncIsInAddressbook )
547 return "is in address book";
548 else if ( func == KMSearchRule::FuncIsNotInAddressbook )
549 return "is not in address book";
551 return currentValue( valueStack, func );
556 TQString TextRuleWidgetHandler::prettyValue(
const TQCString &,
557 const TQWidgetStack *functionStack,
558 const TQWidgetStack *valueStack )
const
561 if ( func == KMSearchRule::FuncIsInAddressbook )
562 return i18n(
"is in address book" );
563 else if ( func == KMSearchRule::FuncIsNotInAddressbook )
564 return i18n(
"is not in address book" );
566 return currentValue( valueStack, func );
571 bool TextRuleWidgetHandler::handlesField(
const TQCString & )
const
578 void TextRuleWidgetHandler::reset( TQWidgetStack *functionStack,
579 TQWidgetStack *valueStack )
const
582 TQComboBox *funcCombo =
583 dynamic_cast<TQComboBox*
>( functionStack->child(
"textRuleFuncCombo",
586 funcCombo->blockSignals(
true );
587 funcCombo->setCurrentItem( 0 );
588 funcCombo->blockSignals(
false );
592 RegExpLineEdit *lineEdit =
593 dynamic_cast<RegExpLineEdit*
>( valueStack->child(
"regExpLineEdit",
596 lineEdit->blockSignals(
true );
598 lineEdit->blockSignals(
false );
599 lineEdit->showEditButton(
false );
600 valueStack->raiseWidget( lineEdit );
604 dynamic_cast<TQComboBox*
>( valueStack->child(
"categoryCombo",
607 combo->blockSignals(
true );
608 combo->setCurrentItem( 0 );
609 combo->blockSignals(
false );
615 bool TextRuleWidgetHandler::setRule( TQWidgetStack *functionStack,
616 TQWidgetStack *valueStack,
620 reset( functionStack, valueStack );
626 for ( ; i < TextFunctionCount; ++i )
627 if ( func == TextFunctions[i].
id )
629 TQComboBox *funcCombo =
630 dynamic_cast<TQComboBox*
>( functionStack->child(
"textRuleFuncCombo",
633 funcCombo->blockSignals(
true );
634 if ( i < TextFunctionCount )
635 funcCombo->setCurrentItem( i );
637 kdDebug(5006) <<
"TextRuleWidgetHandler::setRule( "
639 <<
" ): unhandled function" << endl;
640 funcCombo->setCurrentItem( 0 );
642 funcCombo->blockSignals(
false );
643 functionStack->raiseWidget( funcCombo );
646 if ( func == KMSearchRule::FuncIsInAddressbook ||
647 func == KMSearchRule::FuncIsNotInAddressbook ) {
649 static_cast<TQWidget*
>( valueStack->child(
"textRuleValueHider",
651 valueStack->raiseWidget( w );
653 else if ( func == KMSearchRule::FuncIsInCategory ||
654 func == KMSearchRule::FuncIsNotInCategory) {
656 static_cast<TQComboBox*
>(
static_cast<TQWidget*
>(valueStack->child(
"categoryCombo",
658 combo->blockSignals(
true );
659 for ( i = 0; i < combo->count(); ++i )
660 if ( rule->
contents() == combo->text( i ) ) {
661 combo->setCurrentItem( i );
664 if ( i == combo->count() )
665 combo->setCurrentItem( 0 );
667 combo->blockSignals(
false );
668 valueStack->raiseWidget( combo );
671 RegExpLineEdit *lineEdit =
672 dynamic_cast<RegExpLineEdit*
>( valueStack->child(
"regExpLineEdit",
675 lineEdit->blockSignals(
true );
676 lineEdit->setText( rule->
contents() );
677 lineEdit->blockSignals(
false );
678 lineEdit->showEditButton( func == KMSearchRule::FuncRegExp ||
679 func == KMSearchRule::FuncNotRegExp );
680 valueStack->raiseWidget( lineEdit );
689 bool TextRuleWidgetHandler::update(
const TQCString &,
690 TQWidgetStack *functionStack,
691 TQWidgetStack *valueStack )
const
694 functionStack->raiseWidget(
695 static_cast<TQWidget*
>( functionStack->child(
"textRuleFuncCombo",
700 if ( func == KMSearchRule::FuncIsInAddressbook ||
701 func == KMSearchRule::FuncIsNotInAddressbook ) {
702 valueStack->raiseWidget(
703 static_cast<TQWidget*
>( valueStack->child(
"textRuleValueHider",
706 else if ( func == KMSearchRule::FuncIsInCategory ||
707 func == KMSearchRule::FuncIsNotInCategory) {
708 valueStack->raiseWidget(
709 static_cast<TQWidget*
>( valueStack->child(
"categoryCombo",
713 RegExpLineEdit *lineEdit =
714 dynamic_cast<RegExpLineEdit*
>( valueStack->child(
"regExpLineEdit",
717 lineEdit->showEditButton( func == KMSearchRule::FuncRegExp ||
718 func == KMSearchRule::FuncNotRegExp );
719 valueStack->raiseWidget( lineEdit );
737 static const struct {
739 const char *displayName;
740 } MessageFunctions[] = {
741 { KMSearchRule::FuncContains, I18N_NOOP(
"contains" ) },
742 { KMSearchRule::FuncContainsNot, I18N_NOOP(
"does not contain" ) },
743 { KMSearchRule::FuncRegExp, I18N_NOOP(
"matches regular expr." ) },
744 { KMSearchRule::FuncNotRegExp, I18N_NOOP(
"does not match reg. expr." ) },
745 { KMSearchRule::FuncHasAttachment, I18N_NOOP(
"has an attachment" ) },
746 { KMSearchRule::FuncHasNoAttachment, I18N_NOOP(
"has no attachment" ) },
748 static const int MessageFunctionCount =
749 sizeof( MessageFunctions ) /
sizeof( *MessageFunctions );
753 TQWidget * MessageRuleWidgetHandler::createFunctionWidget(
int number,
754 TQWidgetStack *functionStack,
755 const TQObject *receiver )
const
760 TQComboBox *funcCombo =
new TQComboBox( functionStack,
"messageRuleFuncCombo" );
761 for (
int i = 0; i < MessageFunctionCount; ++i ) {
762 funcCombo->insertItem( i18n( MessageFunctions[i].displayName ) );
764 funcCombo->adjustSize();
765 TQObject::connect( funcCombo, TQ_SIGNAL( activated(
int ) ),
766 receiver, TQ_SLOT( slotFunctionChanged() ) );
772 TQWidget * MessageRuleWidgetHandler::createValueWidget(
int number,
773 TQWidgetStack *valueStack,
774 const TQObject *receiver )
const
777 RegExpLineEdit *lineEdit =
778 new RegExpLineEdit( valueStack,
"regExpLineEdit" );
779 TQObject::connect( lineEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
780 receiver, TQ_SLOT( slotValueChanged() ) );
786 return new TQLabel( valueStack,
"textRuleValueHider" );
794 KMSearchRule::Function MessageRuleWidgetHandler::currentFunction(
const TQWidgetStack *functionStack )
const
796 const TQComboBox *funcCombo =
797 dynamic_cast<TQComboBox*
>( TQObject_child_const( functionStack,
798 "messageRuleFuncCombo" ) );
803 return MessageFunctions[funcCombo->currentItem()].id;
806 kdDebug(5006) <<
"MessageRuleWidgetHandler::currentFunction: "
807 "messageRuleFuncCombo not found." << endl;
808 return KMSearchRule::FuncNone;
814 const TQWidgetStack *functionStack )
const
816 if ( !handlesField( field ) )
817 return KMSearchRule::FuncNone;
819 return currentFunction( functionStack );
824 TQString MessageRuleWidgetHandler::currentValue(
const TQWidgetStack *valueStack,
827 const RegExpLineEdit *lineEdit =
828 dynamic_cast<RegExpLineEdit*
>( TQObject_child_const( valueStack,
829 "regExpLineEdit" ) );
834 return lineEdit->text();
837 kdDebug(5006) <<
"MessageRuleWidgetHandler::currentValue: "
838 "regExpLineEdit not found." << endl;
845 TQString MessageRuleWidgetHandler::value(
const TQCString & field,
846 const TQWidgetStack *functionStack,
847 const TQWidgetStack *valueStack )
const
849 if ( !handlesField( field ) )
853 if ( func == KMSearchRule::FuncHasAttachment )
854 return "has an attachment";
855 else if ( func == KMSearchRule::FuncHasNoAttachment )
856 return "has no attachment";
858 return currentValue( valueStack, func );
863 TQString MessageRuleWidgetHandler::prettyValue(
const TQCString & field,
864 const TQWidgetStack *functionStack,
865 const TQWidgetStack *valueStack )
const
867 if ( !handlesField( field ) )
871 if ( func == KMSearchRule::FuncHasAttachment )
872 return i18n(
"has an attachment" );
873 else if ( func == KMSearchRule::FuncHasNoAttachment )
874 return i18n(
"has no attachment" );
876 return currentValue( valueStack, func );
881 bool MessageRuleWidgetHandler::handlesField(
const TQCString & field )
const
883 return ( field ==
"<message>" );
888 void MessageRuleWidgetHandler::reset( TQWidgetStack *functionStack,
889 TQWidgetStack *valueStack )
const
892 TQComboBox *funcCombo =
893 dynamic_cast<TQComboBox*
>( functionStack->child(
"messageRuleFuncCombo",
896 funcCombo->blockSignals(
true );
897 funcCombo->setCurrentItem( 0 );
898 funcCombo->blockSignals(
false );
902 RegExpLineEdit *lineEdit =
903 dynamic_cast<RegExpLineEdit*
>( valueStack->child(
"regExpLineEdit",
906 lineEdit->blockSignals(
true );
908 lineEdit->blockSignals(
false );
909 lineEdit->showEditButton(
false );
910 valueStack->raiseWidget( lineEdit );
916 bool MessageRuleWidgetHandler::setRule( TQWidgetStack *functionStack,
917 TQWidgetStack *valueStack,
920 if ( !rule || !handlesField( rule->
field() ) ) {
921 reset( functionStack, valueStack );
927 for ( ; i < MessageFunctionCount; ++i )
928 if ( func == MessageFunctions[i].
id )
930 TQComboBox *funcCombo =
931 dynamic_cast<TQComboBox*
>( functionStack->child(
"messageRuleFuncCombo",
934 funcCombo->blockSignals(
true );
935 if ( i < MessageFunctionCount )
936 funcCombo->setCurrentItem( i );
938 kdDebug(5006) <<
"MessageRuleWidgetHandler::setRule( "
940 <<
" ): unhandled function" << endl;
941 funcCombo->setCurrentItem( 0 );
943 funcCombo->blockSignals(
false );
944 functionStack->raiseWidget( funcCombo );
947 if ( func == KMSearchRule::FuncHasAttachment ||
948 func == KMSearchRule::FuncHasNoAttachment ) {
950 static_cast<TQWidget*
>( valueStack->child(
"textRuleValueHider",
952 valueStack->raiseWidget( w );
955 RegExpLineEdit *lineEdit =
956 dynamic_cast<RegExpLineEdit*
>( valueStack->child(
"regExpLineEdit",
959 lineEdit->blockSignals(
true );
960 lineEdit->setText( rule->
contents() );
961 lineEdit->blockSignals(
false );
962 lineEdit->showEditButton( func == KMSearchRule::FuncRegExp ||
963 func == KMSearchRule::FuncNotRegExp );
964 valueStack->raiseWidget( lineEdit );
973 bool MessageRuleWidgetHandler::update(
const TQCString & field,
974 TQWidgetStack *functionStack,
975 TQWidgetStack *valueStack )
const
977 if ( !handlesField( field ) )
980 functionStack->raiseWidget(
981 static_cast<TQWidget*
>( functionStack->child(
"messageRuleFuncCombo",
986 if ( func == KMSearchRule::FuncHasAttachment ||
987 func == KMSearchRule::FuncHasNoAttachment ) {
989 static_cast<TQWidget*
>( valueStack->child(
"textRuleValueHider",
991 valueStack->raiseWidget( w );
994 RegExpLineEdit *lineEdit =
995 dynamic_cast<RegExpLineEdit*
>( valueStack->child(
"regExpLineEdit",
998 lineEdit->showEditButton( func == KMSearchRule::FuncRegExp ||
999 func == KMSearchRule::FuncNotRegExp );
1000 valueStack->raiseWidget( lineEdit );
1016 static const struct {
1018 const char *displayName;
1019 } StatusFunctions[] = {
1020 { KMSearchRule::FuncContains, I18N_NOOP(
"is" ) },
1021 { KMSearchRule::FuncContainsNot, I18N_NOOP(
"is not" ) }
1023 static const int StatusFunctionCount =
1024 sizeof( StatusFunctions ) /
sizeof( *StatusFunctions );
1028 TQWidget * StatusRuleWidgetHandler::createFunctionWidget(
int number,
1029 TQWidgetStack *functionStack,
1030 const TQObject *receiver )
const
1035 TQComboBox *funcCombo =
new TQComboBox( functionStack,
1036 "statusRuleFuncCombo" );
1037 for (
int i = 0; i < StatusFunctionCount; ++i ) {
1038 funcCombo->insertItem( i18n( StatusFunctions[i].displayName ) );
1040 funcCombo->adjustSize();
1041 TQObject::connect( funcCombo, TQ_SIGNAL( activated(
int ) ),
1042 receiver, TQ_SLOT( slotFunctionChanged() ) );
1048 TQWidget * StatusRuleWidgetHandler::createValueWidget(
int number,
1049 TQWidgetStack *valueStack,
1050 const TQObject *receiver )
const
1055 TQComboBox *statusCombo =
new TQComboBox( valueStack,
1056 "statusRuleValueCombo" );
1057 for (
int i = 0; i < KMail::StatusValueCountWithoutHidden; ++i ) {
1058 statusCombo->insertItem( UserIcon( KMail::StatusValues[ i ].icon ), i18n( KMail::StatusValues[ i ].text ) );
1060 statusCombo->adjustSize();
1061 TQObject::connect( statusCombo, TQ_SIGNAL( activated(
int ) ),
1062 receiver, TQ_SLOT( slotValueChanged() ) );
1068 KMSearchRule::Function StatusRuleWidgetHandler::currentFunction(
const TQWidgetStack *functionStack )
const
1070 const TQComboBox *funcCombo =
1071 dynamic_cast<TQComboBox*
>( TQObject_child_const( functionStack,
1072 "statusRuleFuncCombo" ) );
1077 return StatusFunctions[funcCombo->currentItem()].id;
1080 kdDebug(5006) <<
"StatusRuleWidgetHandler::currentFunction: "
1081 "statusRuleFuncCombo not found." << endl;
1082 return KMSearchRule::FuncNone;
1088 const TQWidgetStack *functionStack )
const
1090 if ( !handlesField( field ) )
1091 return KMSearchRule::FuncNone;
1093 return currentFunction( functionStack );
1098 int StatusRuleWidgetHandler::currenStatusValue(
const TQWidgetStack *valueStack )
const
1100 const TQComboBox *statusCombo =
1101 dynamic_cast<TQComboBox*
>( TQObject_child_const( valueStack,
1102 "statusRuleValueCombo" ) );
1106 if ( statusCombo ) {
1107 return statusCombo->currentItem();
1110 kdDebug(5006) <<
"StatusRuleWidgetHandler::currenStatusValue: "
1111 "statusRuleValueCombo not found." << endl;
1117 TQString StatusRuleWidgetHandler::value(
const TQCString & field,
1118 const TQWidgetStack *,
1119 const TQWidgetStack *valueStack )
const
1121 if ( !handlesField( field ) )
1124 const int status = currenStatusValue( valueStack );
1126 return TQString::fromLatin1( KMail::StatusValues[ status ].text );
1133 TQString StatusRuleWidgetHandler::prettyValue(
const TQCString & field,
1134 const TQWidgetStack *,
1135 const TQWidgetStack *valueStack )
const
1137 if ( !handlesField( field ) )
1140 const int status = currenStatusValue( valueStack );
1142 return i18n( KMail::StatusValues[ status ].text );
1149 bool StatusRuleWidgetHandler::handlesField(
const TQCString & field )
const
1151 return ( field ==
"<status>" );
1156 void StatusRuleWidgetHandler::reset( TQWidgetStack *functionStack,
1157 TQWidgetStack *valueStack )
const
1160 TQComboBox *funcCombo =
1161 dynamic_cast<TQComboBox*
>( functionStack->child(
"statusRuleFuncCombo",
1164 funcCombo->blockSignals(
true );
1165 funcCombo->setCurrentItem( 0 );
1166 funcCombo->blockSignals(
false );
1170 TQComboBox *statusCombo =
1171 dynamic_cast<TQComboBox*
>( valueStack->child(
"statusRuleValueCombo",
1173 if ( statusCombo ) {
1174 statusCombo->blockSignals(
true );
1175 statusCombo->setCurrentItem( 0 );
1176 statusCombo->blockSignals(
false );
1182 bool StatusRuleWidgetHandler::setRule( TQWidgetStack *functionStack,
1183 TQWidgetStack *valueStack,
1186 if ( !rule || !handlesField( rule->
field() ) ) {
1187 reset( functionStack, valueStack );
1194 for ( ; funcIndex < StatusFunctionCount; ++funcIndex )
1195 if ( func == StatusFunctions[funcIndex].
id )
1197 TQComboBox *funcCombo =
1198 dynamic_cast<TQComboBox*
>( functionStack->child(
"statusRuleFuncCombo",
1201 funcCombo->blockSignals(
true );
1202 if ( funcIndex < StatusFunctionCount )
1203 funcCombo->setCurrentItem( funcIndex );
1205 kdDebug(5006) <<
"StatusRuleWidgetHandler::setRule( "
1207 <<
" ): unhandled function" << endl;
1208 funcCombo->setCurrentItem( 0 );
1210 funcCombo->blockSignals(
false );
1211 functionStack->raiseWidget( funcCombo );
1215 const TQString value = rule->
contents();
1217 for ( ; valueIndex < KMail::StatusValueCountWithoutHidden; ++valueIndex )
1218 if ( value == TQString::fromLatin1(
1219 KMail::StatusValues[ valueIndex ].text ) )
1221 TQComboBox *statusCombo =
1222 dynamic_cast<TQComboBox*
>( valueStack->child(
"statusRuleValueCombo",
1224 if ( statusCombo ) {
1225 statusCombo->blockSignals(
true );
1226 if ( valueIndex < KMail::StatusValueCountWithoutHidden )
1227 statusCombo->setCurrentItem( valueIndex );
1229 kdDebug(5006) <<
"StatusRuleWidgetHandler::setRule( "
1231 <<
" ): unhandled value" << endl;
1232 statusCombo->setCurrentItem( 0 );
1234 statusCombo->blockSignals(
false );
1235 valueStack->raiseWidget( statusCombo );
1243 bool StatusRuleWidgetHandler::update(
const TQCString &field,
1244 TQWidgetStack *functionStack,
1245 TQWidgetStack *valueStack )
const
1247 if ( !handlesField( field ) )
1251 functionStack->raiseWidget(
1252 static_cast<TQWidget*
>( functionStack->child(
"statusRuleFuncCombo",
1256 valueStack->raiseWidget(
1257 static_cast<TQWidget*
>( valueStack->child(
"statusRuleValueCombo",
1272 static const struct {
1274 const char *displayName;
1275 } NumericFunctions[] = {
1276 { KMSearchRule::FuncEquals, I18N_NOOP(
"is equal to" ) },
1277 { KMSearchRule::FuncNotEqual, I18N_NOOP(
"is not equal to" ) },
1278 { KMSearchRule::FuncIsGreater, I18N_NOOP(
"is greater than" ) },
1279 { KMSearchRule::FuncIsLessOrEqual, I18N_NOOP(
"is less than or equal to" ) },
1280 { KMSearchRule::FuncIsLess, I18N_NOOP(
"is less than" ) },
1281 { KMSearchRule::FuncIsGreaterOrEqual, I18N_NOOP(
"is greater than or equal to" ) }
1283 static const int NumericFunctionCount =
1284 sizeof( NumericFunctions ) /
sizeof( *NumericFunctions );
1288 TQWidget * NumericRuleWidgetHandler::createFunctionWidget(
int number,
1289 TQWidgetStack *functionStack,
1290 const TQObject *receiver )
const
1295 TQComboBox *funcCombo =
new TQComboBox( functionStack,
1296 "numericRuleFuncCombo" );
1297 for (
int i = 0; i < NumericFunctionCount; ++i ) {
1298 funcCombo->insertItem( i18n( NumericFunctions[i].displayName ) );
1300 funcCombo->adjustSize();
1301 TQObject::connect( funcCombo, TQ_SIGNAL( activated(
int ) ),
1302 receiver, TQ_SLOT( slotFunctionChanged() ) );
1308 TQWidget * NumericRuleWidgetHandler::createValueWidget(
int number,
1309 TQWidgetStack *valueStack,
1310 const TQObject *receiver )
const
1315 KIntNumInput *numInput =
new KIntNumInput( valueStack,
"KIntNumInput" );
1316 TQObject::connect( numInput, TQ_SIGNAL( valueChanged(
int ) ),
1317 receiver, TQ_SLOT( slotValueChanged() ) );
1323 KMSearchRule::Function NumericRuleWidgetHandler::currentFunction(
const TQWidgetStack *functionStack )
const
1325 const TQComboBox *funcCombo =
1326 dynamic_cast<TQComboBox*
>( TQObject_child_const( functionStack,
1327 "numericRuleFuncCombo" ) );
1332 return NumericFunctions[funcCombo->currentItem()].id;
1335 kdDebug(5006) <<
"NumericRuleWidgetHandler::currentFunction: "
1336 "numericRuleFuncCombo not found." << endl;
1337 return KMSearchRule::FuncNone;
1343 const TQWidgetStack *functionStack )
const
1345 if ( !handlesField( field ) )
1346 return KMSearchRule::FuncNone;
1348 return currentFunction( functionStack );
1353 TQString NumericRuleWidgetHandler::currentValue(
const TQWidgetStack *valueStack )
const
1355 const KIntNumInput *numInput =
1356 dynamic_cast<KIntNumInput*
>( TQObject_child_const( valueStack,
1362 return TQString::number( numInput->value() );
1365 kdDebug(5006) <<
"NumericRuleWidgetHandler::currentValue: "
1366 "KIntNumInput not found." << endl;
1372 TQString NumericRuleWidgetHandler::value(
const TQCString & field,
1373 const TQWidgetStack *,
1374 const TQWidgetStack *valueStack )
const
1376 if ( !handlesField( field ) )
1379 return currentValue( valueStack );
1384 TQString NumericRuleWidgetHandler::prettyValue(
const TQCString & field,
1385 const TQWidgetStack *,
1386 const TQWidgetStack *valueStack )
const
1388 if ( !handlesField( field ) )
1391 return currentValue( valueStack );
1396 bool NumericRuleWidgetHandler::handlesField(
const TQCString & field )
const
1398 return ( field ==
"<size>" || field ==
"<age in days>" );
1403 void NumericRuleWidgetHandler::reset( TQWidgetStack *functionStack,
1404 TQWidgetStack *valueStack )
const
1407 TQComboBox *funcCombo =
1408 dynamic_cast<TQComboBox*
>( functionStack->child(
"numericRuleFuncCombo",
1411 funcCombo->blockSignals(
true );
1412 funcCombo->setCurrentItem( 0 );
1413 funcCombo->blockSignals(
false );
1417 KIntNumInput *numInput =
1418 dynamic_cast<KIntNumInput*
>( valueStack->child(
"KIntNumInput",
1421 numInput->blockSignals(
true );
1422 numInput->setValue( 0 );
1423 numInput->blockSignals(
false );
1429 void initNumInput( KIntNumInput *numInput,
const TQCString &field )
1431 if ( field ==
"<size>" ) {
1432 numInput->setMinValue( 0 );
1433 numInput->setSuffix( i18n(
" bytes" ) );
1436 numInput->setMinValue( -10000 );
1437 numInput->setSuffix( i18n(
" days" ) );
1443 bool NumericRuleWidgetHandler::setRule( TQWidgetStack *functionStack,
1444 TQWidgetStack *valueStack,
1447 if ( !rule || !handlesField( rule->
field() ) ) {
1448 reset( functionStack, valueStack );
1455 for ( ; funcIndex < NumericFunctionCount; ++funcIndex )
1456 if ( func == NumericFunctions[funcIndex].
id )
1458 TQComboBox *funcCombo =
1459 dynamic_cast<TQComboBox*
>( functionStack->child(
"numericRuleFuncCombo",
1462 funcCombo->blockSignals(
true );
1463 if ( funcIndex < NumericFunctionCount )
1464 funcCombo->setCurrentItem( funcIndex );
1466 kdDebug(5006) <<
"NumericRuleWidgetHandler::setRule( "
1468 <<
" ): unhandled function" << endl;
1469 funcCombo->setCurrentItem( 0 );
1471 funcCombo->blockSignals(
false );
1472 functionStack->raiseWidget( funcCombo );
1477 int value = rule->
contents().toInt( &ok );
1480 KIntNumInput *numInput =
1481 dynamic_cast<KIntNumInput*
>( valueStack->child(
"KIntNumInput",
1484 initNumInput( numInput, rule->
field() );
1485 numInput->blockSignals(
true );
1486 numInput->setValue( value );
1487 numInput->blockSignals(
false );
1488 valueStack->raiseWidget( numInput );
1496 bool NumericRuleWidgetHandler::update(
const TQCString &field,
1497 TQWidgetStack *functionStack,
1498 TQWidgetStack *valueStack )
const
1500 if ( !handlesField( field ) )
1504 functionStack->raiseWidget(
1505 static_cast<TQWidget*
>( functionStack->child(
"numericRuleFuncCombo",
1509 KIntNumInput *numInput =
1510 dynamic_cast<KIntNumInput*
>( valueStack->child(
"KIntNumInput",
1513 initNumInput( numInput, field );
1514 valueStack->raiseWidget( numInput );
Incoming mail is sent through the list of mail filter rules before it is placed in the associated mai...
TQCString field() const
Return message header field name (without the trailing ':').
Function function() const
Return filter function.
const TQString asString() const
Returns the rule as string.
TQString contents() const
Return the value.
Function
Operators for comparison of field and contents.