18 #undef TQT_NO_ASCII_CAST
27 #include <tqcheckbox.h>
28 #include <tqtextview.h>
30 #include <tdelocale.h>
31 #include <kstandarddirs.h>
33 #include <kinputdialog.h>
36 #include "kscoringeditor.h"
41 static TQString toXml(
const TQString& str)
44 uint len = tmp.length();
47 if (tmp[(
int)i] ==
'<') {
48 tmp.replace(i, 1,
"<");
51 }
else if (tmp[(
int)i] ==
'"') {
52 tmp.replace(i, 1,
""");
55 }
else if (tmp[(
int)i] ==
'&') {
56 tmp.replace(i, 1,
"&");
59 }
else if (tmp[(
int)i] ==
'>') {
60 tmp.replace(i, 1,
">");
73 NotifyDialog* NotifyDialog::me = 0;
74 NotifyDialog::NotesMap NotifyDialog::dict;
76 NotifyDialog::NotifyDialog(TQWidget* p)
77 : KDialogBase(p,
"notify action dialog",true,
"Notify Message",Close,Close,true)
79 TQFrame *f = makeMainWidget();
80 TQVBoxLayout *topL =
new TQVBoxLayout(f);
81 note =
new TQLabel(f);
82 note->setTextFormat(RichText);
83 topL->addWidget(note);
84 TQCheckBox *check =
new TQCheckBox(i18n(
"Do not show this message again"),f);
85 check->setChecked(
true);
86 topL->addWidget(check);
87 connect(check,TQ_SIGNAL(toggled(
bool)),TQ_SLOT(slotShowAgainToggled(
bool)));
90 void NotifyDialog::slotShowAgainToggled(
bool flag)
92 dict.replace(msg,!flag);
93 kdDebug(5100) <<
"note \"" << note <<
"\" will popup again: " << flag << endl;
96 void NotifyDialog::display(ScorableArticle& a,
const TQString& s)
98 kdDebug(5100) <<
"displaying message" << endl;
99 if (!me) me =
new NotifyDialog();
102 NotesMap::Iterator i = dict.find(s);
103 if (i == dict.end() || i.data()) {
104 TQString msg = i18n(
"Article\n<b>%1</b><br><b>%2</b><br>caused the following"
105 " note to appear:<br>%3").
109 me->note->setText(msg);
110 if ( i == dict.end() ) i = dict.replace(s,
false);
118 ScorableArticle::~ScorableArticle()
122 void ScorableArticle::displayMessage(
const TQString& note)
124 NotifyDialog::display(*
this,note);
128 ScorableGroup::~ScorableGroup()
133 ActionBase::ActionBase()
135 kdDebug(5100) <<
"new Action " <<
this << endl;
138 ActionBase::~ActionBase()
140 kdDebug(5100) <<
"delete Action " <<
this << endl;
144 TQStringList ActionBase::userNames()
147 l << userName(SETSCORE);
148 l << userName(NOTIFY);
149 l << userName(COLOR);
150 l << userName(MARKASREAD);
154 ActionBase* ActionBase::factory(
int type,
const TQString &value)
157 case SETSCORE:
return new ActionSetScore(value);
158 case NOTIFY:
return new ActionNotify(value);
159 case COLOR:
return new ActionColor(value);
160 case MARKASREAD:
return new ActionMarkAsRead();
162 kdWarning(5100) <<
"unknown type " << type <<
" in ActionBase::factory()" << endl;
167 TQString ActionBase::userName(
int type)
170 case SETSCORE:
return i18n(
"Adjust Score");
171 case NOTIFY:
return i18n(
"Display Message");
172 case COLOR:
return i18n(
"Colorize Header");
173 case MARKASREAD:
return i18n(
"Mark As Read");
175 kdWarning(5100) <<
"unknown type " << type <<
" in ActionBase::userName()" << endl;
180 int ActionBase::getTypeForName(
const TQString& name)
182 if (name ==
"SETSCORE")
return SETSCORE;
183 else if (name ==
"NOTIFY")
return NOTIFY;
184 else if (name ==
"COLOR")
return COLOR;
185 else if (name ==
"MARKASREAD")
return MARKASREAD;
187 kdWarning(5100) <<
"unknown type string " << name
188 <<
" in ActionBase::getTypeForName()" << endl;
193 int ActionBase::getTypeForUserName(
const TQString& name)
195 if (name == userName(SETSCORE))
return SETSCORE;
196 else if (name == userName(NOTIFY))
return NOTIFY;
197 else if (name == userName(COLOR))
return COLOR;
198 else if ( name == userName(MARKASREAD) )
return MARKASREAD;
200 kdWarning(5100) <<
"unknown type string " << name
201 <<
" in ActionBase::getTypeForUserName()" << endl;
207 ActionSetScore::ActionSetScore(
short v)
212 ActionSetScore::ActionSetScore(
const TQString& s)
217 ActionSetScore::ActionSetScore(
const ActionSetScore& as)
223 ActionSetScore::~ActionSetScore()
227 TQString ActionSetScore::toString()
const
230 a +=
"<Action type=\"SETSCORE\" value=\"" + TQString::number(val) +
"\" />";
234 void ActionSetScore::apply(ScorableArticle& a)
const
239 ActionSetScore* ActionSetScore::clone()
const
241 return new ActionSetScore(*
this);
245 ActionColor::ActionColor(
const TQColor& c)
250 ActionColor::ActionColor(
const TQString& s)
256 ActionColor::ActionColor(
const ActionColor& a)
261 ActionColor::~ActionColor()
264 TQString ActionColor::toString()
const
267 a +=
"<Action type=\"COLOR\" value=\"" + toXml(color.name()) +
"\" />";
271 void ActionColor::apply(ScorableArticle& a)
const
273 a.changeColor(color);
276 ActionColor* ActionColor::clone()
const
278 return new ActionColor(*
this);
283 ActionNotify::ActionNotify(
const TQString& s)
288 ActionNotify::ActionNotify(
const ActionNotify& an)
294 TQString ActionNotify::toString()
const
296 return "<Action type=\"NOTIFY\" value=\"" + toXml(note) +
"\" />";
299 void ActionNotify::apply(ScorableArticle& a)
const
301 a.displayMessage(note);
304 ActionNotify* ActionNotify::clone()
const
306 return new ActionNotify(*
this);
311 ActionMarkAsRead::ActionMarkAsRead() :
316 ActionMarkAsRead::ActionMarkAsRead(
const ActionMarkAsRead &action ) :
322 TQString ActionMarkAsRead::toString()
const
324 return "<Action type=\"MARKASREAD\"/>";
327 void ActionMarkAsRead::apply( ScorableArticle &article )
const
329 article.markAsRead();
332 ActionMarkAsRead* ActionMarkAsRead::clone()
const
334 return new ActionMarkAsRead(*
this);
338 NotifyCollection::NotifyCollection()
340 notifyList.setAutoDelete(
true);
343 NotifyCollection::~NotifyCollection()
347 void NotifyCollection::addNote(
const ScorableArticle& a,
const TQString& note)
349 article_list *l = notifyList.find(note);
351 notifyList.insert(note,
new article_list);
352 l = notifyList.find(note);
356 i.subject = a.subject();
360 TQString NotifyCollection::collection()
const
362 TQString notifyCollection = i18n(
"<h1>List of collected notes</h1>");
363 notifyCollection +=
"<p><ul>";
365 TQDictIterator<article_list> it(notifyList);
366 for(;it.current();++it) {
367 const TQString& note = it.currentKey();
368 notifyCollection +=
"<li>" + note +
"<ul>";
369 article_list* alist = it.current();
370 article_list::Iterator ait;
371 for(ait = alist->begin(); ait != alist->end(); ++ait) {
372 notifyCollection +=
"<li><b>From: </b>" + (*ait).from +
"<br>";
373 notifyCollection +=
"<b>Subject: </b>" + (*ait).subject;
375 notifyCollection +=
"</ul>";
377 notifyCollection +=
"</ul>";
379 return notifyCollection;
382 void NotifyCollection::displayCollection(TQWidget *p)
const
385 KDialogBase *dlg =
new KDialogBase( p, 0,
false, i18n(
"Collected Notes"),
386 KDialogBase::Close, KDialogBase::Close );
387 TQTextView *text =
new TQTextView(dlg);
388 text->setText(collection());
389 dlg->setMainWidget(text);
390 dlg->setMinimumWidth(300);
391 dlg->setMinimumHeight(300);
396 KScoringExpression::KScoringExpression(
const TQString& h,
const TQString& t,
const TQString& n,
const TQString& ng)
397 : header(h), expr_str(n)
401 expr.setPattern(expr_str);
402 expr.setCaseSensitive(
false);
404 else if ( t ==
"MATCHCS" ) {
406 expr.setPattern( expr_str );
407 expr.setCaseSensitive(
true );
409 else if (t ==
"CONTAINS" ) cond = CONTAINS;
410 else if (t ==
"EQUALS" ) cond = EQUALS;
411 else if (t ==
"GREATER") {
413 expr_int = expr_str.toInt();
415 else if (t ==
"SMALLER") {
417 expr_int = expr_str.toInt();
420 kdDebug(5100) <<
"unknown match type in new expression" << endl;
424 c_header = header.latin1();
426 kdDebug(5100) <<
"new expr: " << c_header <<
" " << t <<
" "
427 << expr_str <<
" " << neg << endl;
431 int KScoringExpression::getConditionForName(
const TQString& s)
433 if (s == getNameForCondition(CONTAINS))
return CONTAINS;
434 else if (s == getNameForCondition(MATCH))
return MATCH;
435 else if (s == getNameForCondition(MATCHCS))
return MATCHCS;
436 else if (s == getNameForCondition(EQUALS))
return EQUALS;
437 else if (s == getNameForCondition(SMALLER))
return SMALLER;
438 else if (s == getNameForCondition(GREATER))
return GREATER;
440 kdWarning(5100) <<
"unknown condition name " << s
441 <<
" in KScoringExpression::getConditionForName()" << endl;
447 TQString KScoringExpression::getNameForCondition(
int cond)
450 case CONTAINS:
return i18n(
"Contains Substring");
451 case MATCH:
return i18n(
"Matches Regular Expression");
452 case MATCHCS:
return i18n(
"Matches Regular Expression (Case Sensitive)");
453 case EQUALS:
return i18n(
"Is Exactly the Same As");
454 case SMALLER:
return i18n(
"Less Than");
455 case GREATER:
return i18n(
"Greater Than");
457 kdWarning(5100) <<
"unknown condition " << cond
458 <<
" in KScoringExpression::getNameForCondition()" << endl;
464 TQStringList KScoringExpression::conditionNames()
467 l << getNameForCondition(CONTAINS);
468 l << getNameForCondition(MATCH);
469 l << getNameForCondition(MATCHCS);
470 l << getNameForCondition(EQUALS);
471 l << getNameForCondition(SMALLER);
472 l << getNameForCondition(GREATER);
477 TQStringList KScoringExpression::headerNames()
481 l.append(
"Message-ID");
484 l.append(
"References");
485 l.append(
"NNTP-Posting-Host");
492 KScoringExpression::~KScoringExpression()
496 bool KScoringExpression::match(ScorableArticle& a)
const
502 if (header ==
"From")
504 else if (header ==
"Subject")
507 head = a.getHeaderByType(c_header);
509 if (!head.isEmpty()) {
512 res = (head.lower() == expr_str.lower());
515 res = (head.lower().find(expr_str.lower()) >= 0);
519 res = (expr.search(head)!=-1);
522 res = (head.toInt() > expr_int);
525 res = (head.toInt() < expr_int);
528 kdDebug(5100) <<
"unknown match" << endl;
534 return (neg)?!res:res;
537 void KScoringExpression::write(TQTextStream& st)
const
542 TQString KScoringExpression::toString()
const
550 e +=
"<Expression neg=\"" + TQString::number(neg?1:0)
551 +
"\" header=\"" + header
552 +
"\" type=\"" + getTypeString()
553 +
"\" expr=\"" + toXml(expr_str)
559 TQString KScoringExpression::getTypeString()
const
561 return KScoringExpression::getTypeString(cond);
564 TQString KScoringExpression::getTypeString(
int cond)
567 case CONTAINS:
return "CONTAINS";
568 case MATCH:
return "MATCH";
569 case MATCHCS:
return "MATCHCS";
570 case EQUALS:
return "EQUALS";
571 case SMALLER:
return "SMALLER";
572 case GREATER:
return "GREATER";
574 kdWarning(5100) <<
"unknown cond " << cond <<
" in KScoringExpression::getTypeString()" << endl;
579 int KScoringExpression::getType()
const
585 KScoringRule::KScoringRule(
const TQString& n )
588 expressions.setAutoDelete(
true);
589 actions.setAutoDelete(
true);
592 KScoringRule::KScoringRule(
const KScoringRule& r)
594 kdDebug(5100) <<
"copying rule " << r.getName() << endl;
596 expressions.setAutoDelete(
true);
597 actions.setAutoDelete(
true);
600 const ScoreExprList& rexpr = r.expressions;
601 TQPtrListIterator<KScoringExpression> it(rexpr);
602 for ( ; it.current(); ++it ) {
603 KScoringExpression *t =
new KScoringExpression(**it);
604 expressions.append(t);
608 const ActionList& ract = r.actions;
609 TQPtrListIterator<ActionBase> ait(ract);
610 for ( ; ait.current(); ++ait ) {
612 actions.append(t->clone());
620 KScoringRule::~KScoringRule()
626 void KScoringRule::cleanExpressions()
632 void KScoringRule::cleanActions()
638 void KScoringRule::addExpression( KScoringExpression* expr)
640 kdDebug(5100) <<
"KScoringRule::addExpression" << endl;
641 expressions.append(expr);
644 void KScoringRule::addAction(
int type,
const TQString& val)
646 ActionBase *action = ActionBase::factory(type,val);
652 kdDebug(5100) <<
"KScoringRule::addAction() " << a->toString() << endl;
656 void KScoringRule::setLinkMode(
const TQString& l)
658 if (l ==
"OR") link = OR;
662 void KScoringRule::setExpire(
const TQString& e)
665 TQStringList l = TQStringList::split(
"-",e);
666 Q_ASSERT( l.count() == 3 );
667 expires.setYMD( (*(l.at(0))).toInt(),
668 (*(l.at(1))).toInt(),
669 (*(l.at(2))).toInt());
671 kdDebug(5100) <<
"Rule " << getName() <<
" expires at " << getExpireDateString() << endl;
674 bool KScoringRule::matchGroup(
const TQString& group)
const
676 for(GroupList::ConstIterator i=groups.begin(); i!=groups.end();++i) {
678 if (e.search(group, 0) != -1 &&
679 (uint)e.matchedLength() == group.length())
685 void KScoringRule::applyAction(ScorableArticle& a)
const
687 TQPtrListIterator<ActionBase> it(actions);
688 for(; it.current(); ++it) {
689 it.current()->apply(a);
693 void KScoringRule::applyRule(ScorableArticle& a)
const
699 bool oper_and = (link == AND);
701 TQPtrListIterator<KScoringExpression> it(expressions);
703 for (; it.current(); ++it) {
704 Q_ASSERT( it.current() );
705 res = it.current()->match(a);
706 if (!res && oper_and)
return;
707 else if (res && !oper_and)
break;
709 if (res) applyAction(a);
712 void KScoringRule::applyRule(ScorableArticle& a ,
const TQString& g)
const
715 for (TQStringList::ConstIterator i = groups.begin(); i != groups.end(); ++i) {
716 if (TQRegExp(*i).search(g) != -1) {
723 void KScoringRule::write(TQTextStream& s)
const
728 TQString KScoringRule::toString()
const
732 r +=
"<Rule name=\"" + toXml(name) +
"\" linkmode=\"" + getLinkModeName();
733 r +=
"\" expires=\"" + getExpireDateString() +
"\">";
735 for(GroupList::ConstIterator i=groups.begin();i!=groups.end();++i) {
736 r +=
"<Group name=\"" + toXml(*i) +
"\" />";
739 TQPtrListIterator<KScoringExpression> eit(expressions);
740 for (; eit.current(); ++eit) {
741 r += eit.current()->toString();
744 TQPtrListIterator<ActionBase> ait(actions);
745 for (; ait.current(); ++ait) {
746 r += ait.current()->toString();
753 TQString KScoringRule::getLinkModeName()
const
756 case AND:
return "AND";
757 case OR:
return "OR";
758 default:
return "AND";
762 TQString KScoringRule::getExpireDateString()
const
764 if (expires.isNull())
return "never";
766 return TQString::number(expires.year()) + TQString(
"-")
767 + TQString::number(expires.month()) + TQString(
"-")
768 + TQString::number(expires.day());
772 bool KScoringRule::isExpired()
const
774 return (expires.isValid() && (expires < TQDate::currentDate()));
780 KScoringManager::KScoringManager(
const TQString& appName)
783 allRules.setAutoDelete(
true);
785 if(appName.isEmpty())
786 mFilename = TDEGlobal::dirs()->saveLocation(
"appdata") +
"/scorefile";
788 mFilename = TDEGlobal::dirs()->saveLocation(
"data") +
"/" + appName +
"/scorefile";
794 KScoringManager::~KScoringManager()
798 void KScoringManager::load()
800 TQDomDocument sdoc(
"Scorefile");
801 TQFile f( mFilename );
802 if ( !f.open( IO_ReadOnly ) )
804 if ( !sdoc.setContent( &f ) ) {
806 kdDebug(5100) <<
"loading the scorefile failed" << endl;
810 kdDebug(5100) <<
"loaded the scorefile, creating internal representation" << endl;
812 createInternalFromXML(sdoc);
814 kdDebug(5100) <<
"ready, got " << allRules.count() <<
" rules" << endl;
817 void KScoringManager::save()
819 kdDebug(5100) <<
"KScoringManager::save() starts" << endl;
820 TQFile f( mFilename );
821 if ( !f.open( IO_WriteOnly ) )
823 TQTextStream stream(&f);
824 stream.setEncoding(TQTextStream::Unicode);
825 kdDebug(5100) <<
"KScoringManager::save() creating xml" << endl;
826 createXMLfromInternal().save(stream,2);
827 kdDebug(5100) <<
"KScoringManager::save() finished" << endl;
830 TQDomDocument KScoringManager::createXMLfromInternal()
834 TQDomDocument sdoc(
"Scorefile");
836 ss +=
"<?xml version = '1.0'?><!DOCTYPE Scorefile >";
838 ss +=
"</Scorefile>\n";
839 kdDebug(5100) <<
"KScoringManager::createXMLfromInternal():" << endl << ss << endl;
844 TQString KScoringManager::toString()
const
847 s +=
"<Scorefile>\n";
848 TQPtrListIterator<KScoringRule> it(allRules);
849 for( ; it.current(); ++it) {
850 s += it.current()->toString();
855 void KScoringManager::expireRules()
857 for ( KScoringRule *cR = allRules.first(); cR; cR=allRules.next()) {
858 if (cR->isExpired()) {
859 kdDebug(5100) <<
"Rule " << cR->getName() <<
" is expired, deleting it" << endl;
865 void KScoringManager::createInternalFromXML(TQDomNode n)
867 static KScoringRule *cR = 0;
870 kdDebug(5100) <<
"inspecting node of type " << n.nodeType()
871 <<
" named " << n.toElement().tagName() << endl;
873 switch (n.nodeType()) {
874 case TQDomNode::DocumentNode: {
878 case TQDomNode::ElementNode: {
880 TQDomElement e = n.toElement();
883 TQString s = e.tagName();
885 cR =
new KScoringRule(e.attribute(
"name"));
886 cR->setLinkMode(e.attribute(
"linkmode"));
887 cR->setExpire(e.attribute(
"expires"));
890 else if (s ==
"Group") {
892 cR->addGroup( e.attribute(
"name") );
894 else if (s ==
"Expression") {
895 cR->addExpression(
new KScoringExpression(e.attribute(
"header"),
898 e.attribute(
"neg")));
900 else if (s ==
"Action") {
902 cR->addAction(ActionBase::getTypeForName(e.attribute(
"type")),
903 e.attribute(
"value"));
910 TQDomNodeList nodelist = n.childNodes();
911 unsigned cnt = nodelist.count();
913 for (
unsigned i=0;i<cnt;++i)
914 createInternalFromXML(nodelist.item(i));
918 KScoringRule* KScoringManager::addRule(
const ScorableArticle& a, TQString group,
short score)
920 KScoringRule *rule =
new KScoringRule(findUniqueName());
921 rule->addGroup( group );
923 new KScoringExpression(
"From",
"CONTAINS",
925 if (score) rule->addAction(
new ActionSetScore(score));
926 rule->setExpireDate(TQDate::currentDate().addDays(30));
928 KScoringEditor *edit = KScoringEditor::createEditor(
this);
931 setCacheValid(
false);
935 KScoringRule* KScoringManager::addRule(KScoringRule* expr)
937 int i = allRules.findRef(expr);
940 addRuleInternal(expr);
948 KScoringRule* KScoringManager::addRule()
950 KScoringRule *rule =
new KScoringRule(findUniqueName());
955 void KScoringManager::addRuleInternal(KScoringRule *e)
958 setCacheValid(
false);
960 kdDebug(5100) <<
"KScoringManager::addRuleInternal " << e->getName() << endl;
963 void KScoringManager::cancelNewRule(KScoringRule *r)
966 int i = allRules.findRef(r);
968 kdDebug(5100) <<
"deleting rule " << r->getName() << endl;
972 kdDebug(5100) <<
"rule " << r->getName() <<
" not deleted" << endl;
976 void KScoringManager::setRuleName(KScoringRule *r,
const TQString& s)
980 TQString oldName = r->getName();
983 TQPtrListIterator<KScoringRule> it(allRules);
984 for (; it.current(); ++it) {
985 if ( it.current() != r && it.current()->getName() == text ) {
986 kdDebug(5100) <<
"rule name " << text <<
" is not unique" << endl;
987 text = KInputDialog::getText(i18n(
"Choose Another Rule Name"),
988 i18n(
"The rule name is already assigned, please choose another name:"),
995 if (text != oldName) {
997 emit changedRuleName(oldName,text);
1001 void KScoringManager::deleteRule(KScoringRule *r)
1003 int i = allRules.findRef(r);
1006 emit changedRules();
1010 void KScoringManager::editRule(KScoringRule *e, TQWidget *w)
1012 KScoringEditor *edit = KScoringEditor::createEditor(
this, w);
1018 void KScoringManager::moveRuleAbove( KScoringRule *above, KScoringRule *below )
1020 int aindex = allRules.findRef( above );
1021 int bindex = allRules.findRef( below );
1022 if ( aindex <= 0 || bindex < 0 )
1024 if ( aindex < bindex )
1026 allRules.take( aindex );
1027 allRules.insert( bindex, above );
1030 void KScoringManager::moveRuleBelow( KScoringRule *below, KScoringRule *above )
1032 int bindex = allRules.findRef( below );
1033 int aindex = allRules.findRef( above );
1034 if ( bindex < 0 || bindex >= (
int)allRules.count() - 1 || aindex < 0 )
1036 if ( bindex < aindex )
1038 allRules.take( bindex );
1039 allRules.insert( aindex + 1, below );
1042 void KScoringManager::editorReady()
1044 kdDebug(5100) <<
"emitting signal finishedEditing" << endl;
1046 emit finishedEditing();
1049 KScoringRule* KScoringManager::copyRule(KScoringRule *r)
1051 KScoringRule *rule =
new KScoringRule(*r);
1052 rule->setName(findUniqueName());
1053 addRuleInternal(rule);
1059 kdWarning(5100) <<
"KScoringManager::applyRules(ScorableGroup* ) isn't implemented" << endl;
1062 void KScoringManager::applyRules(ScorableArticle& article,
const TQString& group)
1065 applyRules(article);
1068 void KScoringManager::applyRules(ScorableArticle& a)
1070 TQPtrListIterator<KScoringRule> it(isCacheValid()? ruleList : allRules);
1071 for( ; it.current(); ++it) {
1072 it.current()->applyRule(a);
1076 void KScoringManager::initCache(
const TQString& g)
1080 TQPtrListIterator<KScoringRule> it(allRules);
1081 for (; it.current(); ++it) {
1082 if ( it.current()->matchGroup(group) ) {
1083 ruleList.append(it.current());
1086 kdDebug(5100) <<
"created cache for group " << group
1087 <<
" with " << ruleList.count() <<
" rules" << endl;
1088 setCacheValid(
true);
1091 void KScoringManager::setGroup(
const TQString& g)
1093 if (group != g) initCache(g);
1096 bool KScoringManager::hasRulesForCurrentGroup()
1098 return ruleList.count() != 0;
1102 TQStringList KScoringManager::getRuleNames()
1105 TQPtrListIterator<KScoringRule> it(allRules);
1106 for( ; it.current(); ++it) {
1107 l << it.current()->getName();
1112 KScoringRule* KScoringManager::findRule(
const TQString& ruleName)
1114 TQPtrListIterator<KScoringRule> it(allRules);
1115 for (; it.current(); ++it) {
1116 if ( it.current()->getName() == ruleName ) {
1123 bool KScoringManager::setCacheValid(
bool v)
1125 bool res = cacheValid;
1130 TQString KScoringManager::findUniqueName()
const
1134 bool duplicated=
false;
1136 while (nr < 99999999) {
1138 ret = i18n(
"rule %1").arg(nr);
1141 TQPtrListIterator<KScoringRule> it(allRules);
1142 for( ; it.current(); ++it) {
1143 if (it.current()->getName() == ret) {
1156 bool KScoringManager::hasFeature(
int p)
1159 case ActionBase::SETSCORE:
return canScores();
1160 case ActionBase::NOTIFY:
return canNotes();
1161 case ActionBase::COLOR:
return canColors();
1162 case ActionBase::MARKASREAD:
return canMarkAsRead();
1163 default:
return false;
1167 TQStringList KScoringManager::getDefaultHeaders()
const
1170 l.append(
"Subject");
1173 l.append(
"Message-ID");
1177 void KScoringManager::pushRuleList()
1179 stack.push(allRules);
1182 void KScoringManager::popRuleList()
1184 stack.pop(allRules);
1187 void KScoringManager::removeTOS()
1192 RuleStack::RuleStack()
1196 RuleStack::~RuleStack()
1201 kdDebug(5100) <<
"RuleStack::push pushing list with " << l.count() <<
" rules" << endl;
1202 KScoringManager::ScoringRuleList *l1 =
new KScoringManager::ScoringRuleList;
1203 for ( KScoringRule *r=l.first(); r != 0; r=l.next() ) {
1204 l1->append(
new KScoringRule(*r));
1207 kdDebug(5100) <<
"now there are " << stack.count() <<
" lists on the stack" << endl;
1214 kdDebug(5100) <<
"RuleStack::pop pops list with " << l.count() <<
" rules" << endl;
1215 kdDebug(5100) <<
"now there are " << stack.count() <<
" lists on the stack" << endl;
1221 KScoringManager::ScoringRuleList *l1 = stack.top();
1227 kdDebug(5100) <<
"drop: now there are " << stack.count() <<
" lists on the stack" << endl;
1232 #include "kscoring.moc"
Base class for other Action classes.
void pop(TQPtrList< KScoringRule > &)
clears the argument list and copy the content of the TOS into it after that the TOS gets dropped
void push(TQPtrList< KScoringRule > &)
puts the list on the stack, doesn't change the list
void top(TQPtrList< KScoringRule > &)
like pop but without dropping the TOS
The following classes ScorableArticle, ScorableGroup define the interface for the scoring.