24 #include <KColorCombo>
26 #include <KIconLoader>
27 #include <KIntSpinBox>
30 #include <kregexpeditorinterface.h>
31 #include <KServiceTypeTrader>
32 #include <KPushButton>
35 #include <QPushButton>
38 #include <QRadioButton>
39 #include <QApplication>
41 #include <QButtonGroup>
43 #include <QGridLayout>
45 #include <QHBoxLayout>
47 #include <QVBoxLayout>
53 int cnt = box->count();
54 for (
int i=0; i<cnt; ++i ) {
55 if ( box->text( i ) == s ) {
56 box->setCurrentItem( i );
69 :
QFrame( p ), manager( m )
71 QBoxLayout *topL =
new QVBoxLayout(
this );
73 QBoxLayout *firstRow =
new QHBoxLayout();
74 topL->addItem( firstRow );
75 neg =
new QCheckBox( i18n(
"Not" ),
this );
76 neg->setToolTip( i18n(
"Negate this condition" ) );
77 firstRow->addWidget( neg );
80 headers->setEditable(
true );
81 headers->setToolTip( i18n(
"Select the header to match this condition against" ) );
82 firstRow->addWidget( headers, 1 );
85 matches->setToolTip( i18n(
"Select the type of match" ) );
86 firstRow->addWidget( matches, 1 );
88 QHBoxLayout *secondRow =
new QHBoxLayout();
89 secondRow->setSpacing( 1 );
90 topL->addItem( secondRow );
93 expr->setToolTip( i18n(
"The condition for the match" ) );
95 expr->setMinimumWidth( fontMetrics().maxWidth() * 20 );
96 secondRow->addWidget( expr );
97 regExpButton =
new QPushButton( i18n(
"Edit..." ),
this );
98 secondRow->addWidget( regExpButton );
101 regExpButton->setEnabled(!KServiceTypeTrader::self()->query(
"KRegExpEditor/KRegExpEditor" ).isEmpty());
104 setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
105 setFrameStyle( Box | Sunken );
114 neg->setChecked( e->
isNeg() );
115 headers->setItemText( headers->currentIndex(), e->
getHeader() );
123 QString head = headers->currentText();
124 QString match = matches->currentText();
127 QString cond = expr->text();
128 QString negs = ( neg->isChecked() ) ?
"1" :
"0";
134 neg->setChecked(
false );
142 !KServiceTypeTrader::self()->query(
"KRegExpEditor/KRegExpEditor" ).isEmpty();
143 regExpButton->setEnabled( isRegExp );
148 QDialog *editorDialog =
149 KServiceTypeTrader::createInstanceFromQuery<QDialog>(
150 "KRegExpEditor/KRegExpEditor", QString() );
151 if ( editorDialog ) {
152 KRegExpEditorInterface *editor = qobject_cast<KRegExpEditorInterface *>( editorDialog );
154 editor->setRegExp( expr->text() );
155 editorDialog->exec();
156 expr->setText( editor->regExp() );
195 if ( !rule || l.count() == 0 ) {
202 while ( e && it != widgetList.constEnd() ) {
219 kWarning(5100) <<
"there is a widget in ConditionEditWidget"
220 <<
"which isn't a KPIM::SingleConditionWidget";
231 :
QWidget( p ), notifyEditor( 0 ), scoreEditor( 0 ),
232 colorEditor( 0 ), manager( m )
235 QHBoxLayout *topL =
new QHBoxLayout(
this );
236 topL->setMargin( 0 );
237 topL->setSpacing( 5 );
240 types->setEditable(
false );
241 topL->addWidget( types );
242 stack =
new QStackedWidget(
this );
243 topL->addWidget( stack );
245 dummyLabel =
new QLabel( i18n(
"Select an action." ), stack );
246 stack->insertWidget( 0, dummyLabel );
250 types->addItem( QString() );
252 for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
256 types->addItem( name );
260 w = scoreEditor =
new KIntSpinBox( stack );
261 scoreEditor->setRange( -99999, 99999 );
262 scoreEditor->setValue( 30 );
265 w = notifyEditor =
new KLineEdit( stack );
268 w = colorEditor =
new KColorCombo( stack );
275 stack->insertWidget( index++, w );
280 connect( types, SIGNAL(activated(
int)), stack, SLOT(setCurrentIndex(
int)) );
283 types->setCurrentIndex( 0 );
284 stack->setCurrentWidget( dummyLabel );
293 kDebug(5100) <<
"SingleActionWidget::setAction()";
295 int index = types->findText( act->
userName() );
297 kWarning(5100) <<
"unknown action in SingleActionWidget::setAction()";
301 types->setCurrentIndex( index );
302 stack->setCurrentIndex( index );
317 kWarning(5100) <<
"unknown action type in SingleActionWidget::setAction()";
324 if ( types->currentText().isEmpty() ) {
335 return new ActionColor( colorEditor->color().name() );
339 kWarning(5100) <<
"unknown action type in SingleActionWidget::getValue()";
347 scoreEditor->setValue( 0 );
349 if ( notifyEditor ) {
350 notifyEditor->clear();
353 colorEditor->setCurrentIndex( 0 );
356 types->setCurrentIndex( 0 );
357 stack->setCurrentWidget( dummyLabel );
386 if ( !rule || l.count() == 0 ) {
393 while ( act && it != widgetList.constEnd() ) {
413 kWarning(5100) <<
"there is a widget in ActionEditWidget"
414 <<
"which isn't a KPIM::SingleActionWidget";
434 :
QWidget( p ), dirty( false ), manager( m ), oldRuleName( QString() )
436 kDebug(5100) <<
"RuleEditWidget::RuleEditWidget()";
438 setObjectName( n != 0 ? n :
"RuleEditWidget" );
440 QVBoxLayout *topLayout =
new QVBoxLayout(
this );
441 topLayout->setMargin( 5 );
442 topLayout->setSpacing( KDialog::spacingHint() );
446 topLayout->addWidget( groupB );
447 QGridLayout *groupL =
new QGridLayout( groupB );
448 groupL->setMargin( 8 );
449 groupL->setSpacing( 5 );
451 groupL->addItem(
new QSpacerItem( 0, fontMetrics().lineSpacing() - 4 ), 0, 0 );
455 groupL->addWidget( ruleNameEdit, 1, 1 );
456 QLabel *ruleNameLabel =
new QLabel( i18nc(
"@label rule name",
"&Name:" ), groupB );
457 ruleNameLabel->setBuddy( ruleNameEdit );
458 ruleNameLabel->setObjectName(
"ruleNameLabel" );
459 groupL->addWidget( ruleNameLabel, 1, 0 );
463 groupL->addWidget( groupsEdit, 2, 1 );
464 QLabel *groupsLabel =
new QLabel( i18n(
"&Groups:" ), groupB );
465 groupsLabel->setBuddy( groupsEdit );
466 groupsLabel->setObjectName(
"groupsLabel" );
467 groupL->addWidget( groupsLabel, 2, 0 );
469 QPushButton *groupsBtn =
new QPushButton( i18n(
"A&dd Group" ), groupB );
470 connect( groupsBtn, SIGNAL(clicked()), SLOT(
slotAddGroup()) );
471 groupL->addWidget( groupsBtn, 3, 0 );
473 groupsBox =
new KComboBox(
false, groupB );
474 groupsBox->setDuplicatesEnabled(
false );
475 groupsBox->addItems( manager->
getGroups() );
476 groupsBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
477 groupL->addWidget( groupsBox, 3, 1 );
480 expireCheck =
new QCheckBox( i18n(
"&Expire rule automatically" ), groupB );
481 groupL->addWidget( expireCheck, 4, 0, 1, 2 );
482 expireEdit =
new KIntSpinBox( groupB );
483 expireEdit->setRange( 1, 9999 );
484 expireEdit->setValue( 30 );
485 slotExpireEditChanged(30 );
486 connect( expireEdit, SIGNAL(valueChanged(
int)), SLOT(slotExpireEditChanged(
int)) );
487 groupL->addWidget( expireEdit, 5, 1 );
488 expireLabel =
new QLabel( i18n(
"&Rule is valid for:" ), groupB );
489 expireLabel->setBuddy( expireEdit );
490 expireLabel->setObjectName(
"expireLabel" );
491 groupL->addWidget( expireLabel, 5, 0 );
492 expireLabel->setEnabled(
false );
493 expireEdit->setEnabled(
false );
495 connect( expireCheck, SIGNAL(toggled(
bool)), expireLabel, SLOT(setEnabled(
bool)) );
496 connect( expireCheck, SIGNAL(toggled(
bool)), expireEdit, SLOT(setEnabled(
bool)) );
500 topLayout->addWidget( groupConds );
501 QGridLayout *condL =
new QGridLayout( groupConds );
502 condL->setMargin( 8 );
503 condL->setSpacing( 5 );
505 condL->addItem(
new QSpacerItem( 0, fontMetrics().lineSpacing() - 4 ), 0, 0 );
507 QButtonGroup *buttonGroup =
new QButtonGroup( groupConds );
509 linkModeAnd =
new QRadioButton( i18n(
"Match a&ll conditions" ), groupConds );
510 buttonGroup->addButton( linkModeAnd );
511 condL->addWidget( linkModeAnd, 1, 0 );
512 linkModeOr =
new QRadioButton( i18n(
"Matc&h any condition" ), groupConds );
513 buttonGroup->addButton( linkModeOr );
514 condL->addWidget( linkModeOr, 1, 1 );
515 linkModeAnd->setChecked(
true );
518 condL->addWidget( condEditor, 2, 0, 1, 2 );
519 connect( condEditor, SIGNAL(widgetRemoved()),
this, SLOT(
slotShrink()) );
523 topLayout->addWidget( groupActions );
524 QBoxLayout *actionL =
new QVBoxLayout( groupActions );
525 actionL->setMargin( 8 );
526 actionL->setSpacing( 5 );
527 actionL->addSpacing( fontMetrics().lineSpacing() - 4 );
529 actionL->addWidget( actionEditor );
530 connect( actionEditor, SIGNAL(widgetRemoved()),
this, SLOT(
slotShrink()) );
532 topLayout->addStretch( 1 );
534 kDebug(5100) <<
"constructed RuleEditWidget";
545 kDebug(5100) <<
"no rule for ruleName" << ruleName;
550 ruleNameEdit->setText( rule->
getName() );
551 groupsEdit->setText( rule->
getGroups().join(
";" ) );
554 expireCheck->setChecked( b );
555 expireEdit->setEnabled( b );
556 expireLabel->setEnabled( b );
558 expireEdit->setValue( QDate::currentDate().daysTo( rule->
getExpireDate() ) );
560 expireEdit->setValue( 30 );
563 linkModeAnd->setChecked(
true );
565 linkModeOr->setChecked(
true );
571 kDebug(5100) <<
"RuleEditWidget::slotEditRule() ready";
574 void RuleEditWidget::clearContents()
576 ruleNameEdit->setText(
"" );
577 groupsEdit->setText(
"" );
578 expireCheck->setChecked(
false );
579 expireEdit->setValue( 30 );
580 expireEdit->setEnabled(
false );
589 QString groups = groupsEdit->text();
590 if ( groups.isEmpty() ) {
593 rule->
setGroups( groups.split(
';', QString::SkipEmptyParts ) );
595 bool b = expireCheck->isChecked();
597 rule->
setExpireDate( QDate::currentDate().addDays( expireEdit->value() ) );
604 if ( rule->
getName() != ruleNameEdit->text() ) {
605 manager->
setRuleName( rule, ruleNameEdit->text() );
619 QString grp = groupsBox->currentText();
620 if ( grp.isEmpty() ) {
623 QString txt = groupsEdit->text().trimmed();
624 if ( txt ==
".*" || txt.isEmpty() ) {
625 groupsEdit->setText( grp );
627 groupsEdit->setText( txt +
';' + grp );
633 kDebug(5100) <<
"RuleEditWidget::setDirty()";
645 void RuleEditWidget::slotExpireEditChanged(
int value )
647 expireEdit->setSuffix( i18np(
" day",
" days", value ) );
656 :
QWidget( p ), alone( standalone ), manager( m )
658 kDebug(5100) <<
"RuleListWidget::RuleListWidget()";
659 setObjectName( n != 0 ? n :
"RuleListWidget" );
660 QVBoxLayout *topL =
new QVBoxLayout(
this );
661 topL->setMargin( standalone ? 0 : 5 );
662 topL->setSpacing( KDialog::spacingHint() );
664 ruleList =
new K3ListBox(
this );
666 connect( ruleList, SIGNAL(doubleClicked(Q3ListBoxItem*)),
668 connect( ruleList, SIGNAL(returnPressed(Q3ListBoxItem*)),
671 connect( ruleList, SIGNAL(currentChanged(Q3ListBoxItem*)),
673 topL->addWidget( ruleList );
675 QHBoxLayout *btnL =
new QHBoxLayout();
676 btnL->setSpacing( KDialog::spacingHint() );
678 topL->addItem( btnL );
680 mRuleUp =
new QPushButton(
this );
681 mRuleUp->setIcon( KIcon(
"go-up" ) );
682 mRuleUp->setToolTip( i18n(
"Move rule up" ) );
683 btnL->addWidget( mRuleUp );
684 connect( mRuleUp, SIGNAL(clicked()), SLOT(
slotRuleUp()) );
685 mRuleDown =
new QPushButton(
this );
686 mRuleDown->setIcon( KIcon(
"go-down" ) );
687 mRuleDown->setToolTip( i18n(
"Move rule down" ) );
688 btnL->addWidget( mRuleDown );
689 connect( mRuleDown, SIGNAL(clicked()), SLOT(
slotRuleDown()) );
691 btnL =
new QHBoxLayout();
692 btnL->setSpacing( KDialog::spacingHint() );
694 topL->addItem( btnL );
697 newRule =
new QPushButton(
this );
698 newRule->setIcon( KIcon(
"document-new" ) );
699 newRule->setToolTip( i18n(
"New rule" ) ),
700 btnL->addWidget( newRule );
701 connect( newRule, SIGNAL(clicked()),
this, SLOT(
slotNewRule()) );
704 editRule =
new QPushButton(
this );
705 editRule->setIcon( KIcon(
"document-properties" ) );
706 editRule->setToolTip( i18n(
"Edit rule" ) );
707 btnL->addWidget( editRule );
708 connect( editRule, SIGNAL(clicked()),
this, SLOT(
slotEditRule()) );
710 delRule =
new QPushButton(
this );
711 delRule->setIcon( KIcon(
"edit-delete" ) );
712 delRule->setToolTip( i18n(
"Remove rule" ) );
713 btnL->addWidget( delRule );
714 connect( delRule, SIGNAL(clicked()),
this, SLOT(
slotDelRule()) );
715 copyRule =
new QPushButton(
this );
716 copyRule->setIcon( KIcon(
"edit-copy" ) );
717 copyRule->setToolTip( i18n(
"Copy rule" ) );
718 btnL->addWidget( copyRule );
719 connect( copyRule, SIGNAL(clicked()),
this, SLOT(
slotCopyRule()) );
722 QBoxLayout *filterL =
new QVBoxLayout();
723 topL->addItem( filterL );
724 filterL->setSpacing( KDialog::spacingHint() );
728 filterBox->addItem( i18n(
"<placeholder>all groups</placeholder>" ) );
729 filterBox->addItems( l );
730 filterBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
731 connect( filterBox, SIGNAL(activated(QString)),
734 QLabel *lab =
new QLabel( i18n(
"Sho&w only rules for group:" ),
this );
735 lab->setBuddy( filterBox );
737 filterL->addWidget( lab );
738 filterL->addWidget( filterBox );
740 connect( manager, SIGNAL(changedRules()),
this, SLOT(
updateRuleList()) );
741 connect( manager, SIGNAL(changedRuleName(QString,QString)),
754 bool state = ruleList->count() > 0;
756 editRule->setEnabled( state );
758 delRule->setEnabled( state );
759 copyRule->setEnabled( state );
761 Q3ListBoxItem *item = ruleList->item( ruleList->currentItem() );
763 mRuleUp->setEnabled( item->prev() != 0 );
764 mRuleDown->setEnabled( item->next() != 0 );
771 kDebug(5100) <<
"RuleListWidget::updateRuleList()";
772 QString curr = ruleList->currentText();
774 if ( group == i18n(
"<placeholder>all groups</placeholder>" ) ) {
776 ruleList->insertStringList( l );
779 for (
KScoringRule *rule = l.first(); rule; rule = l.next() ) {
780 if ( rule->matchGroup( group ) ) {
781 ruleList->insertItem( rule->getName() );
787 ruleList->setCurrentItem( 0 );
796 kDebug(5100) <<
"RuleListWidget::updateRuleList(" << rule->
getName() <<
")";
797 QString name = rule->
getName();
804 int ind = ruleList->currentItem();
805 for ( uint i=0; i<ruleList->count(); ++i ) {
806 if ( ruleList->text(i) == oldName ) {
807 ruleList->changeItem( newName, i );
808 ruleList->setCurrentItem( ind );
821 if ( ruleList->currentItem() >= 0 ) {
823 }
else if ( ruleList->count() == 0 ) {
842 kDebug(5100) <<
"RuleListWidget::slotRuleSelected(" << ruleName <<
")";
843 if ( ruleName != ruleList->currentText() ) {
855 QString ruleName = item->text();
862 if ( idx >= ruleList->count() ) {
865 QString ruleName = ruleList->text( index );
896 QString ruleName = ruleList->currentText();
909 Q3ListBoxItem *item = ruleList->item( ruleList->currentItem() );
911 rule = manager->
findRule( item->text() );
914 below = manager->
findRule( item->text() );
917 if ( rule && below ) {
927 Q3ListBoxItem *item = ruleList->item( ruleList->currentItem() );
929 rule = manager->
findRule( item->text() );
932 above = manager->
findRule( item->text() );
935 if ( rule && above ) {
950 :
KDialog( parent ), manager( m )
952 setCaption( i18n(
"Rule Editor" ) );
953 setButtons( Ok|Apply|Cancel );
954 setDefaultButton( Ok );
956 showButtonSeparator(
true );
958 if ( !scoreEditor ) {
961 kDebug(5100) <<
"KScoringEditor::KScoringEditor()";
966 QHBoxLayout *hbl =
new QHBoxLayout( w );
968 hbl->setSpacing( spacingHint() );
971 hbl->addWidget( ruleLister );
973 hbl->addWidget( ruleEditor );
974 connect( ruleLister, SIGNAL(ruleSelected(QString)),
975 ruleEditor, SLOT(slotEditRule(QString)) );
976 connect( ruleLister, SIGNAL(leavingRule()), ruleEditor, SLOT(updateRule()) );
977 connect( ruleEditor, SIGNAL(shrink()), SLOT(
slotShrink()) );
978 connect(
this, SIGNAL(finished()), SLOT(
slotFinished()) );
979 connect(
this, SIGNAL(okClicked()), SLOT(
slotOk()) );
980 connect(
this, SIGNAL(cancelClicked()), SLOT(
slotCancel()) );
981 connect(
this, SIGNAL(applyClicked()), SLOT(
slotApply()) );
983 resize( 550, sizeHint().height() );
988 enableButton( Apply,
true );
1007 kDebug(5100) <<
"KScoringEditor::setRule(" << r->
getName() <<
")";
1008 QString ruleName = r->
getName();
1020 QApplication::sendPostedEvents();
1021 resize( width(), sizeHint().height() );
1062 :
KDialog( p ), manager( m ), ruleName( r )
1064 setCaption( i18n(
"Edit Rule" ) );
1065 setButtons( KDialog::Ok|KDialog::Apply|KDialog::Cancel );
1066 setDefaultButton( KDialog::Ok );
1068 showButtonSeparator(
true );
1071 QBoxLayout *topL =
new QVBoxLayout( f );
1073 connect( ruleEditor, SIGNAL(shrink()), SLOT(
slotShrink()) );
1074 connect(
this, SIGNAL(okClicked()), SLOT(
slotOk()) );
1075 topL->addWidget( ruleEditor );
1103 QApplication::sendPostedEvents();
1104 resize( width(), sizeHint().height() );
1116 QBoxLayout *topL =
new QVBoxLayout(
this );
1118 topL->addWidget( ruleLister );
1119 connect( ruleLister, SIGNAL(ruleEdited(QString)),
1135 #include "kscoringeditor.moc"
ActionList getActions() const
virtual QString getValueString() const
void setExpireDate(const QDate &d)
void setRule(KScoringRule *)
virtual bool hasFeature(int)
ScoreExprList getExpressions() const
void setLinkMode(const QString &link)
static QString userName(int type)
void moveRuleBelow(KScoringRule *below, KScoringRule *above)
QString getExpression() const
QString getTypeString() const
Q3PtrList< KScoringRule > ScoringRuleList
QString getHeader() const
Condition getCondition() const
LinkMode getLinkMode() const
void deleteRule(KScoringRule *)
Base class for other Action classes.
Q3PtrList< KScoringExpression > ScoreExprList
static int setCurrentItem(K3ListBox *box, const QString &s)
KScoringRule * findRule(const QString &)
void moveRuleAbove(KScoringRule *above, KScoringRule *below)
void addExpression(KScoringExpression *)
static int getTypeForUserName(const QString &name)
void addAction(int, const QString &)
virtual QStringList getGroups() const =0
KScoringRule * addRule(KScoringRule *)
void editorReady()
called from an editor whenever it finishes editing the rule base, causes the finishedEditing signal t...
void setGroups(const QStringList &l)
static QStringList conditionNames()
QStringList getGroups() const
virtual int getType() const =0
void setRuleName(KScoringRule *, const QString &)
QDate getExpireDate() const
static KScoringEditor * createEditor(KScoringManager *m, QWidget *parent=0)
QStringList getRuleNames()
static QString getNameForCondition(int)
ScoringRuleList getAllRules() const
static int getConditionForName(const QString &)
static QStringList userNames()
KScoringRule * copyRule(KScoringRule *)
KScoringEditor(KScoringManager *m, QWidget *parent=0)
virtual QStringList getDefaultHeaders() const
returns a list of common (or available) headers defaults to returning { Subject, From, Message-ID, Date }
Q3PtrList< ActionBase > ActionList