You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1235 lines
30 KiB
1235 lines
30 KiB
15 years ago
|
/*
|
||
|
kscoring.cpp
|
||
|
|
||
|
Copyright (c) 2001 Mathias Waack
|
||
|
Copyright (C) 2005 by Volker Krause <volker.krause@rwth-aachen.de>
|
||
|
|
||
|
Author: Mathias Waack <mathias@atoll-net.de>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software Foundation,
|
||
|
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
|
||
|
*/
|
||
|
#ifdef KDE_USE_FINAL
|
||
14 years ago
|
#undef TQT_NO_ASCII_CAST
|
||
15 years ago
|
#endif
|
||
|
|
||
14 years ago
|
#undef TQT_NO_COMPAT
|
||
15 years ago
|
|
||
|
#include <iostream>
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqdom.h>
|
||
|
#include <tqlayout.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqtextview.h>
|
||
15 years ago
|
|
||
|
#include <klocale.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kinputdialog.h>
|
||
|
|
||
|
#include "kscoring.h"
|
||
|
#include "kscoringeditor.h"
|
||
|
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
14 years ago
|
// a small function to encode attribute values, code stolen from TQDom
|
||
15 years ago
|
static TQString toXml(const TQString& str)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString tmp(str);
|
||
15 years ago
|
uint len = tmp.length();
|
||
|
uint i = 0;
|
||
|
while ( i < len ) {
|
||
|
if (tmp[(int)i] == '<') {
|
||
14 years ago
|
tmp.replace(i, 1, "<");
|
||
15 years ago
|
len += 3;
|
||
|
i += 4;
|
||
|
} else if (tmp[(int)i] == '"') {
|
||
14 years ago
|
tmp.replace(i, 1, """);
|
||
15 years ago
|
len += 5;
|
||
|
i += 6;
|
||
|
} else if (tmp[(int)i] == '&') {
|
||
14 years ago
|
tmp.replace(i, 1, "&");
|
||
15 years ago
|
len += 4;
|
||
|
i += 5;
|
||
|
} else if (tmp[(int)i] == '>') {
|
||
14 years ago
|
tmp.replace(i, 1, ">");
|
||
15 years ago
|
len += 3;
|
||
|
i += 4;
|
||
|
} else {
|
||
|
++i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return tmp;
|
||
|
}
|
||
|
|
||
|
|
||
|
// small dialog to display the messages from NotifyAction
|
||
|
NotifyDialog* NotifyDialog::me = 0;
|
||
|
NotifyDialog::NotesMap NotifyDialog::dict;
|
||
|
|
||
15 years ago
|
NotifyDialog::NotifyDialog(TQWidget* p)
|
||
15 years ago
|
: KDialogBase(p,"notify action dialog",true,"Notify Message",Close,Close,true)
|
||
|
{
|
||
15 years ago
|
TQFrame *f = makeMainWidget();
|
||
|
TQVBoxLayout *topL = new TQVBoxLayout(f);
|
||
|
note = new TQLabel(f);
|
||
15 years ago
|
note->setTextFormat(RichText);
|
||
|
topL->addWidget(note);
|
||
15 years ago
|
TQCheckBox *check = new TQCheckBox(i18n("Do not show this message again"),f);
|
||
15 years ago
|
check->setChecked(true);
|
||
|
topL->addWidget(check);
|
||
15 years ago
|
connect(check,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotShowAgainToggled(bool)));
|
||
15 years ago
|
}
|
||
|
|
||
|
void NotifyDialog::slotShowAgainToggled(bool flag)
|
||
|
{
|
||
14 years ago
|
dict.replace(msg,!flag);
|
||
15 years ago
|
kdDebug(5100) << "note \"" << note << "\" will popup again: " << flag << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void NotifyDialog::display(ScorableArticle& a, const TQString& s)
|
||
15 years ago
|
{
|
||
|
kdDebug(5100) << "displaying message" << endl;
|
||
|
if (!me) me = new NotifyDialog();
|
||
|
me->msg = s;
|
||
|
|
||
14 years ago
|
NotesMap::Iterator i = dict.find(s);
|
||
15 years ago
|
if (i == dict.end() || i.data()) {
|
||
15 years ago
|
TQString msg = i18n("Article\n<b>%1</b><br><b>%2</b><br>caused the following"
|
||
15 years ago
|
" note to appear:<br>%3").
|
||
|
arg(a.from()).
|
||
|
arg(a.subject()).
|
||
|
arg(s);
|
||
|
me->note->setText(msg);
|
||
14 years ago
|
if ( i == dict.end() ) i = dict.replace(s,false);
|
||
15 years ago
|
me->adjustSize();
|
||
|
me->exec();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
|
ScorableArticle::~ScorableArticle()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void ScorableArticle::displayMessage(const TQString& note)
|
||
15 years ago
|
{
|
||
|
NotifyDialog::display(*this,note);
|
||
|
}
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
|
ScorableGroup::~ScorableGroup()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// the base class for all actions
|
||
|
ActionBase::ActionBase()
|
||
|
{
|
||
|
kdDebug(5100) << "new Action " << this << endl;
|
||
|
}
|
||
|
|
||
|
ActionBase::~ActionBase()
|
||
|
{
|
||
|
kdDebug(5100) << "delete Action " << this << endl;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQStringList ActionBase::userNames()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList l;
|
||
15 years ago
|
l << userName(SETSCORE);
|
||
|
l << userName(NOTIFY);
|
||
|
l << userName(COLOR);
|
||
|
l << userName(MARKASREAD);
|
||
|
return l;
|
||
|
}
|
||
|
|
||
15 years ago
|
ActionBase* ActionBase::factory(int type, const TQString &value)
|
||
15 years ago
|
{
|
||
|
switch (type) {
|
||
|
case SETSCORE: return new ActionSetScore(value);
|
||
|
case NOTIFY: return new ActionNotify(value);
|
||
|
case COLOR: return new ActionColor(value);
|
||
|
case MARKASREAD: return new ActionMarkAsRead();
|
||
|
default:
|
||
|
kdWarning(5100) << "unknown type " << type << " in ActionBase::factory()" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ActionBase::userName(int type)
|
||
15 years ago
|
{
|
||
|
switch (type) {
|
||
|
case SETSCORE: return i18n("Adjust Score");
|
||
|
case NOTIFY: return i18n("Display Message");
|
||
|
case COLOR: return i18n("Colorize Header");
|
||
|
case MARKASREAD: return i18n("Mark As Read");
|
||
|
default:
|
||
|
kdWarning(5100) << "unknown type " << type << " in ActionBase::userName()" << endl;
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int ActionBase::getTypeForName(const TQString& name)
|
||
15 years ago
|
{
|
||
|
if (name == "SETSCORE") return SETSCORE;
|
||
|
else if (name == "NOTIFY") return NOTIFY;
|
||
|
else if (name == "COLOR") return COLOR;
|
||
|
else if (name == "MARKASREAD") return MARKASREAD;
|
||
|
else {
|
||
|
kdWarning(5100) << "unknown type string " << name
|
||
|
<< " in ActionBase::getTypeForName()" << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int ActionBase::getTypeForUserName(const TQString& name)
|
||
15 years ago
|
{
|
||
|
if (name == userName(SETSCORE)) return SETSCORE;
|
||
|
else if (name == userName(NOTIFY)) return NOTIFY;
|
||
|
else if (name == userName(COLOR)) return COLOR;
|
||
|
else if ( name == userName(MARKASREAD) ) return MARKASREAD;
|
||
|
else {
|
||
|
kdWarning(5100) << "unknown type string " << name
|
||
|
<< " in ActionBase::getTypeForUserName()" << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// the set score action
|
||
|
ActionSetScore::ActionSetScore(short v)
|
||
|
: val(v)
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
ActionSetScore::ActionSetScore(const TQString& s)
|
||
15 years ago
|
{
|
||
|
val = s.toShort();
|
||
|
}
|
||
|
|
||
|
ActionSetScore::ActionSetScore(const ActionSetScore& as)
|
||
|
: ActionBase(),
|
||
|
val(as.val)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
ActionSetScore::~ActionSetScore()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ActionSetScore::toString() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString a;
|
||
|
a += "<Action type=\"SETSCORE\" value=\"" + TQString::number(val) + "\" />";
|
||
15 years ago
|
return a;
|
||
|
}
|
||
|
|
||
|
void ActionSetScore::apply(ScorableArticle& a) const
|
||
|
{
|
||
|
a.addScore(val);
|
||
|
}
|
||
|
|
||
|
ActionSetScore* ActionSetScore::clone() const
|
||
|
{
|
||
|
return new ActionSetScore(*this);
|
||
|
}
|
||
|
|
||
|
// the color action
|
||
15 years ago
|
ActionColor::ActionColor(const TQColor& c)
|
||
15 years ago
|
: ActionBase(), color(c)
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
ActionColor::ActionColor(const TQString& s)
|
||
15 years ago
|
: ActionBase()
|
||
|
{
|
||
|
setValue(s);
|
||
|
}
|
||
|
|
||
|
ActionColor::ActionColor(const ActionColor& a)
|
||
|
: ActionBase(), color(a.color)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
ActionColor::~ActionColor()
|
||
|
{}
|
||
|
|
||
15 years ago
|
TQString ActionColor::toString() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString a;
|
||
15 years ago
|
a += "<Action type=\"COLOR\" value=\"" + toXml(color.name()) + "\" />";
|
||
|
return a;
|
||
|
}
|
||
|
|
||
|
void ActionColor::apply(ScorableArticle& a) const
|
||
|
{
|
||
|
a.changeColor(color);
|
||
|
}
|
||
|
|
||
|
ActionColor* ActionColor::clone() const
|
||
|
{
|
||
|
return new ActionColor(*this);
|
||
|
}
|
||
|
|
||
|
|
||
|
// the notify action
|
||
15 years ago
|
ActionNotify::ActionNotify(const TQString& s)
|
||
15 years ago
|
{
|
||
|
note = s;
|
||
|
}
|
||
|
|
||
|
ActionNotify::ActionNotify(const ActionNotify& an)
|
||
|
: ActionBase()
|
||
|
{
|
||
|
note = an.note;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ActionNotify::toString() const
|
||
15 years ago
|
{
|
||
|
return "<Action type=\"NOTIFY\" value=\"" + toXml(note) + "\" />";
|
||
|
}
|
||
|
|
||
|
void ActionNotify::apply(ScorableArticle& a) const
|
||
|
{
|
||
|
a.displayMessage(note);
|
||
|
}
|
||
|
|
||
|
ActionNotify* ActionNotify::clone() const
|
||
|
{
|
||
|
return new ActionNotify(*this);
|
||
|
}
|
||
|
|
||
|
|
||
|
// mark as read action
|
||
|
ActionMarkAsRead::ActionMarkAsRead() :
|
||
|
ActionBase()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
ActionMarkAsRead::ActionMarkAsRead( const ActionMarkAsRead &action ) :
|
||
|
ActionBase()
|
||
|
{
|
||
|
Q_UNUSED( action );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ActionMarkAsRead::toString() const
|
||
15 years ago
|
{
|
||
|
return "<Action type=\"MARKASREAD\"/>";
|
||
|
}
|
||
|
|
||
|
void ActionMarkAsRead::apply( ScorableArticle &article ) const
|
||
|
{
|
||
|
article.markAsRead();
|
||
|
}
|
||
|
|
||
|
ActionMarkAsRead* ActionMarkAsRead::clone() const
|
||
|
{
|
||
|
return new ActionMarkAsRead(*this);
|
||
|
}
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
|
NotifyCollection::NotifyCollection()
|
||
|
{
|
||
|
notifyList.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
|
NotifyCollection::~NotifyCollection()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void NotifyCollection::addNote(const ScorableArticle& a, const TQString& note)
|
||
15 years ago
|
{
|
||
14 years ago
|
article_list *l = notifyList.find(note);
|
||
15 years ago
|
if (!l) {
|
||
|
notifyList.insert(note,new article_list);
|
||
14 years ago
|
l = notifyList.find(note);
|
||
15 years ago
|
}
|
||
|
article_info i;
|
||
|
i.from = a.from();
|
||
|
i.subject = a.subject();
|
||
|
l->append(i);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString NotifyCollection::collection() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString notifyCollection = i18n("<h1>List of collected notes</h1>");
|
||
15 years ago
|
notifyCollection += "<p><ul>";
|
||
|
// first look thru the notes and create one string
|
||
15 years ago
|
TQDictIterator<article_list> it(notifyList);
|
||
15 years ago
|
for(;it.current();++it) {
|
||
15 years ago
|
const TQString& note = it.currentKey();
|
||
15 years ago
|
notifyCollection += "<li>" + note + "<ul>";
|
||
|
article_list* alist = it.current();
|
||
|
article_list::Iterator ait;
|
||
|
for(ait = alist->begin(); ait != alist->end(); ++ait) {
|
||
|
notifyCollection += "<li><b>From: </b>" + (*ait).from + "<br>";
|
||
|
notifyCollection += "<b>Subject: </b>" + (*ait).subject;
|
||
|
}
|
||
|
notifyCollection += "</ul>";
|
||
|
}
|
||
|
notifyCollection += "</ul>";
|
||
|
|
||
|
return notifyCollection;
|
||
|
}
|
||
|
|
||
15 years ago
|
void NotifyCollection::displayCollection(TQWidget *p) const
|
||
15 years ago
|
{
|
||
|
//KMessageBox::information(p,collection(),i18n("Collected Notes"));
|
||
|
KDialogBase *dlg = new KDialogBase( p, 0, false, i18n("Collected Notes"),
|
||
|
KDialogBase::Close, KDialogBase::Close );
|
||
15 years ago
|
TQTextView *text = new TQTextView(dlg);
|
||
15 years ago
|
text->setText(collection());
|
||
|
dlg->setMainWidget(text);
|
||
|
dlg->setMinimumWidth(300);
|
||
|
dlg->setMinimumHeight(300);
|
||
|
dlg->show();
|
||
|
}
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
15 years ago
|
KScoringExpression::KScoringExpression(const TQString& h, const TQString& t, const TQString& n, const TQString& ng)
|
||
15 years ago
|
: header(h), expr_str(n)
|
||
|
{
|
||
|
if (t == "MATCH" ) {
|
||
|
cond = MATCH;
|
||
|
expr.setPattern(expr_str);
|
||
|
expr.setCaseSensitive(false);
|
||
|
}
|
||
|
else if ( t == "MATCHCS" ) {
|
||
|
cond = MATCHCS;
|
||
|
expr.setPattern( expr_str );
|
||
|
expr.setCaseSensitive( true );
|
||
|
}
|
||
|
else if (t == "CONTAINS" ) cond = CONTAINS;
|
||
14 years ago
|
else if (t == "ETQUALS" ) cond = ETQUALS;
|
||
15 years ago
|
else if (t == "GREATER") {
|
||
|
cond = GREATER;
|
||
|
expr_int = expr_str.toInt();
|
||
|
}
|
||
|
else if (t == "SMALLER") {
|
||
|
cond = SMALLER;
|
||
|
expr_int = expr_str.toInt();
|
||
|
}
|
||
|
else {
|
||
|
kdDebug(5100) << "unknown match type in new expression" << endl;
|
||
|
}
|
||
|
|
||
|
neg = ng.toInt();
|
||
|
c_header = header.latin1();
|
||
|
|
||
|
kdDebug(5100) << "new expr: " << c_header << " " << t << " "
|
||
|
<< expr_str << " " << neg << endl;
|
||
|
}
|
||
|
|
||
|
// static
|
||
15 years ago
|
int KScoringExpression::getConditionForName(const TQString& s)
|
||
15 years ago
|
{
|
||
|
if (s == getNameForCondition(CONTAINS)) return CONTAINS;
|
||
|
else if (s == getNameForCondition(MATCH)) return MATCH;
|
||
|
else if (s == getNameForCondition(MATCHCS)) return MATCHCS;
|
||
14 years ago
|
else if (s == getNameForCondition(ETQUALS)) return ETQUALS;
|
||
15 years ago
|
else if (s == getNameForCondition(SMALLER)) return SMALLER;
|
||
|
else if (s == getNameForCondition(GREATER)) return GREATER;
|
||
|
else {
|
||
|
kdWarning(5100) << "unknown condition name " << s
|
||
|
<< " in KScoringExpression::getConditionForName()" << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// static
|
||
15 years ago
|
TQString KScoringExpression::getNameForCondition(int cond)
|
||
15 years ago
|
{
|
||
|
switch (cond) {
|
||
|
case CONTAINS: return i18n("Contains Substring");
|
||
|
case MATCH: return i18n("Matches Regular Expression");
|
||
|
case MATCHCS: return i18n("Matches Regular Expression (Case Sensitive)");
|
||
14 years ago
|
case ETQUALS: return i18n("Is Exactly the Same As");
|
||
15 years ago
|
case SMALLER: return i18n("Less Than");
|
||
|
case GREATER: return i18n("Greater Than");
|
||
|
default:
|
||
|
kdWarning(5100) << "unknown condition " << cond
|
||
|
<< " in KScoringExpression::getNameForCondition()" << endl;
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// static
|
||
15 years ago
|
TQStringList KScoringExpression::conditionNames()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList l;
|
||
15 years ago
|
l << getNameForCondition(CONTAINS);
|
||
|
l << getNameForCondition(MATCH);
|
||
|
l << getNameForCondition(MATCHCS);
|
||
14 years ago
|
l << getNameForCondition(ETQUALS);
|
||
15 years ago
|
l << getNameForCondition(SMALLER);
|
||
|
l << getNameForCondition(GREATER);
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
// static
|
||
15 years ago
|
TQStringList KScoringExpression::headerNames()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList l;
|
||
15 years ago
|
l.append("From");
|
||
|
l.append("Message-ID");
|
||
|
l.append("Subject");
|
||
|
l.append("Date");
|
||
|
l.append("References");
|
||
|
l.append("NNTP-Posting-Host");
|
||
|
l.append("Bytes");
|
||
|
l.append("Lines");
|
||
|
l.append("Xref");
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
KScoringExpression::~KScoringExpression()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool KScoringExpression::match(ScorableArticle& a) const
|
||
|
{
|
||
|
//kdDebug(5100) << "matching against header " << c_header << endl;
|
||
|
bool res = true;
|
||
15 years ago
|
TQString head;
|
||
15 years ago
|
|
||
|
if (header == "From")
|
||
|
head = a.from();
|
||
|
else if (header == "Subject")
|
||
|
head = a.subject();
|
||
|
else
|
||
|
head = a.getHeaderByType(c_header);
|
||
|
|
||
|
if (!head.isEmpty()) {
|
||
|
switch (cond) {
|
||
14 years ago
|
case ETQUALS:
|
||
15 years ago
|
res = (head.lower() == expr_str.lower());
|
||
|
break;
|
||
|
case CONTAINS:
|
||
14 years ago
|
res = (head.lower().find(expr_str.lower()) >= 0);
|
||
15 years ago
|
break;
|
||
|
case MATCH:
|
||
|
case MATCHCS:
|
||
|
res = (expr.search(head)!=-1);
|
||
|
break;
|
||
|
case GREATER:
|
||
|
res = (head.toInt() > expr_int);
|
||
|
break;
|
||
|
case SMALLER:
|
||
|
res = (head.toInt() < expr_int);
|
||
|
break;
|
||
|
default:
|
||
|
kdDebug(5100) << "unknown match" << endl;
|
||
|
res = false;
|
||
|
}
|
||
|
}
|
||
|
else res = false;
|
||
|
// kdDebug(5100) << "matching returns " << res << endl;
|
||
|
return (neg)?!res:res;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringExpression::write(TQTextStream& st) const
|
||
15 years ago
|
{
|
||
|
st << toString();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringExpression::toString() const
|
||
15 years ago
|
{
|
||
|
// kdDebug(5100) << "KScoringExpression::toString() starts" << endl;
|
||
|
// kdDebug(5100) << "header is " << header << endl;
|
||
|
// kdDebug(5100) << "expr is " << expr_str << endl;
|
||
|
// kdDebug(5100) << "neg is " << neg << endl;
|
||
|
// kdDebug(5100) << "type is " << getType() << endl;
|
||
15 years ago
|
TQString e;
|
||
|
e += "<Expression neg=\"" + TQString::number(neg?1:0)
|
||
15 years ago
|
+ "\" header=\"" + header
|
||
|
+ "\" type=\"" + getTypeString()
|
||
|
+ "\" expr=\"" + toXml(expr_str)
|
||
|
+ "\" />";
|
||
|
// kdDebug(5100) << "KScoringExpression::toString() finished" << endl;
|
||
|
return e;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringExpression::getTypeString() const
|
||
15 years ago
|
{
|
||
|
return KScoringExpression::getTypeString(cond);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringExpression::getTypeString(int cond)
|
||
15 years ago
|
{
|
||
|
switch (cond) {
|
||
|
case CONTAINS: return "CONTAINS";
|
||
|
case MATCH: return "MATCH";
|
||
|
case MATCHCS: return "MATCHCS";
|
||
14 years ago
|
case ETQUALS: return "ETQUALS";
|
||
15 years ago
|
case SMALLER: return "SMALLER";
|
||
|
case GREATER: return "GREATER";
|
||
|
default:
|
||
|
kdWarning(5100) << "unknown cond " << cond << " in KScoringExpression::getTypeString()" << endl;
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int KScoringExpression::getType() const
|
||
|
{
|
||
|
return cond;
|
||
|
}
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
15 years ago
|
KScoringRule::KScoringRule(const TQString& n )
|
||
15 years ago
|
: name(n), link(AND)
|
||
|
{
|
||
|
expressions.setAutoDelete(true);
|
||
|
actions.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
|
KScoringRule::KScoringRule(const KScoringRule& r)
|
||
|
{
|
||
|
kdDebug(5100) << "copying rule " << r.getName() << endl;
|
||
|
name = r.getName();
|
||
|
expressions.setAutoDelete(true);
|
||
|
actions.setAutoDelete(true);
|
||
|
// copy expressions
|
||
|
expressions.clear();
|
||
|
const ScoreExprList& rexpr = r.expressions;
|
||
15 years ago
|
TQPtrListIterator<KScoringExpression> it(rexpr);
|
||
15 years ago
|
for ( ; it.current(); ++it ) {
|
||
|
KScoringExpression *t = new KScoringExpression(**it);
|
||
|
expressions.append(t);
|
||
|
}
|
||
|
// copy actions
|
||
|
actions.clear();
|
||
|
const ActionList& ract = r.actions;
|
||
15 years ago
|
TQPtrListIterator<ActionBase> ait(ract);
|
||
15 years ago
|
for ( ; ait.current(); ++ait ) {
|
||
|
ActionBase *t = *ait;
|
||
|
actions.append(t->clone());
|
||
|
}
|
||
|
// copy groups, servers, linkmode and expires
|
||
|
groups = r.groups;
|
||
|
expires = r.expires;
|
||
|
link = r.link;
|
||
|
}
|
||
|
|
||
|
KScoringRule::~KScoringRule()
|
||
|
{
|
||
|
cleanExpressions();
|
||
|
cleanActions();
|
||
|
}
|
||
|
|
||
|
void KScoringRule::cleanExpressions()
|
||
|
{
|
||
|
// the expressions is setAutoDelete(true)
|
||
|
expressions.clear();
|
||
|
}
|
||
|
|
||
|
void KScoringRule::cleanActions()
|
||
|
{
|
||
|
// the actions is setAutoDelete(true)
|
||
|
actions.clear();
|
||
|
}
|
||
|
|
||
|
void KScoringRule::addExpression( KScoringExpression* expr)
|
||
|
{
|
||
|
kdDebug(5100) << "KScoringRule::addExpression" << endl;
|
||
|
expressions.append(expr);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringRule::addAction(int type, const TQString& val)
|
||
15 years ago
|
{
|
||
|
ActionBase *action = ActionBase::factory(type,val);
|
||
|
addAction(action);
|
||
|
}
|
||
|
|
||
|
void KScoringRule::addAction(ActionBase* a)
|
||
|
{
|
||
|
kdDebug(5100) << "KScoringRule::addAction() " << a->toString() << endl;
|
||
|
actions.append(a);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringRule::setLinkMode(const TQString& l)
|
||
15 years ago
|
{
|
||
|
if (l == "OR") link = OR;
|
||
|
else link = AND;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringRule::setExpire(const TQString& e)
|
||
15 years ago
|
{
|
||
|
if (e != "never") {
|
||
15 years ago
|
TQStringList l = TQStringList::split("-",e);
|
||
15 years ago
|
Q_ASSERT( l.count() == 3 );
|
||
|
expires.setYMD( (*(l.at(0))).toInt(),
|
||
|
(*(l.at(1))).toInt(),
|
||
|
(*(l.at(2))).toInt());
|
||
|
}
|
||
|
kdDebug(5100) << "Rule " << getName() << " expires at " << getExpireDateString() << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KScoringRule::matchGroup(const TQString& group) const
|
||
15 years ago
|
{
|
||
|
for(GroupList::ConstIterator i=groups.begin(); i!=groups.end();++i) {
|
||
15 years ago
|
TQRegExp e(*i);
|
||
15 years ago
|
if (e.search(group, 0) != -1 &&
|
||
|
(uint)e.matchedLength() == group.length())
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
void KScoringRule::applyAction(ScorableArticle& a) const
|
||
|
{
|
||
15 years ago
|
TQPtrListIterator<ActionBase> it(actions);
|
||
15 years ago
|
for(; it.current(); ++it) {
|
||
|
it.current()->apply(a);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KScoringRule::applyRule(ScorableArticle& a) const
|
||
|
{
|
||
|
// kdDebug(5100) << "checking rule " << name << endl;
|
||
|
// kdDebug(5100) << " for article from "
|
||
|
// << a->from()->asUnicodeString()
|
||
|
// << endl;
|
||
|
bool oper_and = (link == AND);
|
||
|
bool res = true;
|
||
15 years ago
|
TQPtrListIterator<KScoringExpression> it(expressions);
|
||
15 years ago
|
//kdDebug(5100) << "checking " << expressions.count() << " expressions" << endl;
|
||
|
for (; it.current(); ++it) {
|
||
|
Q_ASSERT( it.current() );
|
||
|
res = it.current()->match(a);
|
||
|
if (!res && oper_and) return;
|
||
|
else if (res && !oper_and) break;
|
||
|
}
|
||
|
if (res) applyAction(a);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringRule::applyRule(ScorableArticle& a /*, const TQString& s*/, const TQString& g) const
|
||
15 years ago
|
{
|
||
|
// check if one of the groups match
|
||
15 years ago
|
for (TQStringList::ConstIterator i = groups.begin(); i != groups.end(); ++i) {
|
||
|
if (TQRegExp(*i).search(g) != -1) {
|
||
15 years ago
|
applyRule(a);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringRule::write(TQTextStream& s) const
|
||
15 years ago
|
{
|
||
|
s << toString();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringRule::toString() const
|
||
15 years ago
|
{
|
||
|
//kdDebug(5100) << "KScoringRule::toString() starts" << endl;
|
||
15 years ago
|
TQString r;
|
||
15 years ago
|
r += "<Rule name=\"" + toXml(name) + "\" linkmode=\"" + getLinkModeName();
|
||
|
r += "\" expires=\"" + getExpireDateString() + "\">";
|
||
|
//kdDebug(5100) << "building grouplist..." << endl;
|
||
|
for(GroupList::ConstIterator i=groups.begin();i!=groups.end();++i) {
|
||
|
r += "<Group name=\"" + toXml(*i) + "\" />";
|
||
|
}
|
||
|
//kdDebug(5100) << "building expressionlist..." << endl;
|
||
15 years ago
|
TQPtrListIterator<KScoringExpression> eit(expressions);
|
||
15 years ago
|
for (; eit.current(); ++eit) {
|
||
|
r += eit.current()->toString();
|
||
|
}
|
||
|
//kdDebug(5100) << "building actionlist..." << endl;
|
||
15 years ago
|
TQPtrListIterator<ActionBase> ait(actions);
|
||
15 years ago
|
for (; ait.current(); ++ait) {
|
||
|
r += ait.current()->toString();
|
||
|
}
|
||
|
r += "</Rule>";
|
||
|
//kdDebug(5100) << "KScoringRule::toString() finished" << endl;
|
||
|
return r;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringRule::getLinkModeName() const
|
||
15 years ago
|
{
|
||
|
switch (link) {
|
||
|
case AND: return "AND";
|
||
|
case OR: return "OR";
|
||
|
default: return "AND";
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringRule::getExpireDateString() const
|
||
15 years ago
|
{
|
||
|
if (expires.isNull()) return "never";
|
||
|
else {
|
||
15 years ago
|
return TQString::number(expires.year()) + TQString("-")
|
||
|
+ TQString::number(expires.month()) + TQString("-")
|
||
|
+ TQString::number(expires.day());
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
bool KScoringRule::isExpired() const
|
||
|
{
|
||
14 years ago
|
return (expires.isValid() && (expires < TQDate::tqcurrentDate()));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//----------------------------------------------------------------------------
|
||
15 years ago
|
KScoringManager::KScoringManager(const TQString& appName)
|
||
15 years ago
|
: cacheValid(false)//, _s(0)
|
||
|
{
|
||
|
allRules.setAutoDelete(true);
|
||
|
// determine filename of the scorefile
|
||
|
if(appName.isEmpty())
|
||
|
mFilename = KGlobal::dirs()->saveLocation("appdata") + "/scorefile";
|
||
|
else
|
||
|
mFilename = KGlobal::dirs()->saveLocation("data") + "/" + appName + "/scorefile";
|
||
|
// open the score file
|
||
|
load();
|
||
|
}
|
||
|
|
||
|
|
||
|
KScoringManager::~KScoringManager()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KScoringManager::load()
|
||
|
{
|
||
15 years ago
|
TQDomDocument sdoc("Scorefile");
|
||
|
TQFile f( mFilename );
|
||
15 years ago
|
if ( !f.open( IO_ReadOnly ) )
|
||
|
return;
|
||
|
if ( !sdoc.setContent( &f ) ) {
|
||
|
f.close();
|
||
|
kdDebug(5100) << "loading the scorefile failed" << endl;
|
||
|
return;
|
||
|
}
|
||
|
f.close();
|
||
|
kdDebug(5100) << "loaded the scorefile, creating internal representation" << endl;
|
||
|
allRules.clear();
|
||
|
createInternalFromXML(sdoc);
|
||
|
expireRules();
|
||
|
kdDebug(5100) << "ready, got " << allRules.count() << " rules" << endl;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::save()
|
||
|
{
|
||
|
kdDebug(5100) << "KScoringManager::save() starts" << endl;
|
||
15 years ago
|
TQFile f( mFilename );
|
||
15 years ago
|
if ( !f.open( IO_WriteOnly ) )
|
||
|
return;
|
||
15 years ago
|
TQTextStream stream(&f);
|
||
|
stream.setEncoding(TQTextStream::Unicode);
|
||
15 years ago
|
kdDebug(5100) << "KScoringManager::save() creating xml" << endl;
|
||
|
createXMLfromInternal().save(stream,2);
|
||
|
kdDebug(5100) << "KScoringManager::save() finished" << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomDocument KScoringManager::createXMLfromInternal()
|
||
15 years ago
|
{
|
||
15 years ago
|
// I was'nt able to create a TQDomDocument in memory:(
|
||
15 years ago
|
// so I write the content into a string, which is really stupid
|
||
15 years ago
|
TQDomDocument sdoc("Scorefile");
|
||
|
TQString ss; // scorestring
|
||
15 years ago
|
ss += "<?xml version = '1.0'?><!DOCTYPE Scorefile >";
|
||
|
ss += toString();
|
||
|
ss += "</Scorefile>\n";
|
||
|
kdDebug(5100) << "KScoringManager::createXMLfromInternal():" << endl << ss << endl;
|
||
|
sdoc.setContent(ss);
|
||
|
return sdoc;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringManager::toString() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString s;
|
||
15 years ago
|
s += "<Scorefile>\n";
|
||
15 years ago
|
TQPtrListIterator<KScoringRule> it(allRules);
|
||
15 years ago
|
for( ; it.current(); ++it) {
|
||
|
s += it.current()->toString();
|
||
|
}
|
||
|
return s;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::expireRules()
|
||
|
{
|
||
|
for ( KScoringRule *cR = allRules.first(); cR; cR=allRules.next()) {
|
||
|
if (cR->isExpired()) {
|
||
|
kdDebug(5100) << "Rule " << cR->getName() << " is expired, deleting it" << endl;
|
||
|
allRules.remove();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringManager::createInternalFromXML(TQDomNode n)
|
||
15 years ago
|
{
|
||
|
static KScoringRule *cR = 0; // the currentRule
|
||
|
// the XML file was parsed and now we simply traverse the resulting tree
|
||
|
if ( !n.isNull() ) {
|
||
|
kdDebug(5100) << "inspecting node of type " << n.nodeType()
|
||
|
<< " named " << n.toElement().tagName() << endl;
|
||
|
|
||
|
switch (n.nodeType()) {
|
||
15 years ago
|
case TQDomNode::DocumentNode: {
|
||
15 years ago
|
// the document itself
|
||
|
break;
|
||
|
}
|
||
15 years ago
|
case TQDomNode::ElementNode: {
|
||
15 years ago
|
// Server, Newsgroup, Rule, Expression, Action
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
//kdDebug(5100) << "The name of the element is "
|
||
|
//<< e.tagName().latin1() << endl;
|
||
15 years ago
|
TQString s = e.tagName();
|
||
15 years ago
|
if (s == "Rule") {
|
||
|
cR = new KScoringRule(e.attribute("name"));
|
||
|
cR->setLinkMode(e.attribute("linkmode"));
|
||
|
cR->setExpire(e.attribute("expires"));
|
||
|
addRuleInternal(cR);
|
||
|
}
|
||
|
else if (s == "Group") {
|
||
|
Q_CHECK_PTR(cR);
|
||
|
cR->addGroup( e.attribute("name") );
|
||
|
}
|
||
|
else if (s == "Expression") {
|
||
|
cR->addExpression(new KScoringExpression(e.attribute("header"),
|
||
|
e.attribute("type"),
|
||
|
e.attribute("expr"),
|
||
|
e.attribute("neg")));
|
||
|
}
|
||
|
else if (s == "Action") {
|
||
|
Q_CHECK_PTR(cR);
|
||
|
cR->addAction(ActionBase::getTypeForName(e.attribute("type")),
|
||
|
e.attribute("value"));
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
default: // kdDebug(5100) << "unknown DomNode::type" << endl;
|
||
|
;
|
||
|
}
|
||
15 years ago
|
TQDomNodeList nodelist = n.childNodes();
|
||
15 years ago
|
unsigned cnt = nodelist.count();
|
||
|
//kdDebug(5100) << "recursive checking " << cnt << " nodes" << endl;
|
||
|
for (unsigned i=0;i<cnt;++i)
|
||
|
createInternalFromXML(nodelist.item(i));
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
KScoringRule* KScoringManager::addRule(const ScorableArticle& a, TQString group, short score)
|
||
15 years ago
|
{
|
||
|
KScoringRule *rule = new KScoringRule(findUniqueName());
|
||
|
rule->addGroup( group );
|
||
|
rule->addExpression(
|
||
|
new KScoringExpression("From","CONTAINS",
|
||
|
a.from(),"0"));
|
||
|
if (score) rule->addAction(new ActionSetScore(score));
|
||
14 years ago
|
rule->setExpireDate(TQDate::tqcurrentDate().addDays(30));
|
||
15 years ago
|
addRule(rule);
|
||
|
KScoringEditor *edit = KScoringEditor::createEditor(this);
|
||
|
edit->setRule(rule);
|
||
|
edit->show();
|
||
|
setCacheValid(false);
|
||
|
return rule;
|
||
|
}
|
||
|
|
||
|
KScoringRule* KScoringManager::addRule(KScoringRule* expr)
|
||
|
{
|
||
14 years ago
|
int i = allRules.findRef(expr);
|
||
15 years ago
|
if (i == -1) {
|
||
|
// only add a rule we don't know
|
||
|
addRuleInternal(expr);
|
||
|
}
|
||
|
else {
|
||
|
emit changedRules();
|
||
|
}
|
||
|
return expr;
|
||
|
}
|
||
|
|
||
|
KScoringRule* KScoringManager::addRule()
|
||
|
{
|
||
|
KScoringRule *rule = new KScoringRule(findUniqueName());
|
||
|
addRule(rule);
|
||
|
return rule;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::addRuleInternal(KScoringRule *e)
|
||
|
{
|
||
|
allRules.append(e);
|
||
|
setCacheValid(false);
|
||
|
emit changedRules();
|
||
|
kdDebug(5100) << "KScoringManager::addRuleInternal " << e->getName() << endl;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::cancelNewRule(KScoringRule *r)
|
||
|
{
|
||
|
// if e was'nt previously added to the list of rules, we delete it
|
||
14 years ago
|
int i = allRules.findRef(r);
|
||
15 years ago
|
if (i == -1) {
|
||
|
kdDebug(5100) << "deleting rule " << r->getName() << endl;
|
||
|
deleteRule(r);
|
||
|
}
|
||
|
else {
|
||
|
kdDebug(5100) << "rule " << r->getName() << " not deleted" << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringManager::setRuleName(KScoringRule *r, const TQString& s)
|
||
15 years ago
|
{
|
||
|
bool cont = true;
|
||
15 years ago
|
TQString text = s;
|
||
|
TQString oldName = r->getName();
|
||
15 years ago
|
while (cont) {
|
||
|
cont = false;
|
||
15 years ago
|
TQPtrListIterator<KScoringRule> it(allRules);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
if ( it.current() != r && it.current()->getName() == text ) {
|
||
|
kdDebug(5100) << "rule name " << text << " is not unique" << endl;
|
||
|
text = KInputDialog::getText(i18n("Choose Another Rule Name"),
|
||
|
i18n("The rule name is already assigned, please choose another name:"),
|
||
|
text);
|
||
|
cont = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (text != oldName) {
|
||
|
r->setName(text);
|
||
|
emit changedRuleName(oldName,text);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KScoringManager::deleteRule(KScoringRule *r)
|
||
|
{
|
||
14 years ago
|
int i = allRules.findRef(r);
|
||
15 years ago
|
if (i != -1) {
|
||
|
allRules.remove();
|
||
|
emit changedRules();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringManager::editRule(KScoringRule *e, TQWidget *w)
|
||
15 years ago
|
{
|
||
|
KScoringEditor *edit = KScoringEditor::createEditor(this, w);
|
||
|
edit->setRule(e);
|
||
|
edit->show();
|
||
|
delete edit;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::moveRuleAbove( KScoringRule *above, KScoringRule *below )
|
||
|
{
|
||
14 years ago
|
int aindex = allRules.findRef( above );
|
||
|
int bindex = allRules.findRef( below );
|
||
15 years ago
|
if ( aindex <= 0 || bindex < 0 )
|
||
|
return;
|
||
|
if ( aindex < bindex )
|
||
|
--bindex;
|
||
|
allRules.take( aindex );
|
||
|
allRules.insert( bindex, above );
|
||
|
}
|
||
|
|
||
|
void KScoringManager::moveRuleBelow( KScoringRule *below, KScoringRule *above )
|
||
|
{
|
||
14 years ago
|
int bindex = allRules.findRef( below );
|
||
|
int aindex = allRules.findRef( above );
|
||
15 years ago
|
if ( bindex < 0 || bindex >= (int)allRules.count() - 1 || aindex < 0 )
|
||
|
return;
|
||
|
if ( bindex < aindex )
|
||
|
--aindex;
|
||
|
allRules.take( bindex );
|
||
|
allRules.insert( aindex + 1, below );
|
||
|
}
|
||
|
|
||
|
void KScoringManager::editorReady()
|
||
|
{
|
||
|
kdDebug(5100) << "emitting signal finishedEditing" << endl;
|
||
|
save();
|
||
|
emit finishedEditing();
|
||
|
}
|
||
|
|
||
|
KScoringRule* KScoringManager::copyRule(KScoringRule *r)
|
||
|
{
|
||
|
KScoringRule *rule = new KScoringRule(*r);
|
||
|
rule->setName(findUniqueName());
|
||
|
addRuleInternal(rule);
|
||
|
return rule;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::applyRules(ScorableGroup* )
|
||
|
{
|
||
|
kdWarning(5100) << "KScoringManager::applyRules(ScorableGroup* ) isn't implemented" << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringManager::applyRules(ScorableArticle& article, const TQString& group)
|
||
15 years ago
|
{
|
||
|
setGroup(group);
|
||
|
applyRules(article);
|
||
|
}
|
||
|
|
||
|
void KScoringManager::applyRules(ScorableArticle& a)
|
||
|
{
|
||
15 years ago
|
TQPtrListIterator<KScoringRule> it(isCacheValid()? ruleList : allRules);
|
||
15 years ago
|
for( ; it.current(); ++it) {
|
||
|
it.current()->applyRule(a);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringManager::initCache(const TQString& g)
|
||
15 years ago
|
{
|
||
|
group = g;
|
||
|
ruleList.clear();
|
||
15 years ago
|
TQPtrListIterator<KScoringRule> it(allRules);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
if ( it.current()->matchGroup(group) ) {
|
||
|
ruleList.append(it.current());
|
||
|
}
|
||
|
}
|
||
|
kdDebug(5100) << "created cache for group " << group
|
||
|
<< " with " << ruleList.count() << " rules" << endl;
|
||
|
setCacheValid(true);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KScoringManager::setGroup(const TQString& g)
|
||
15 years ago
|
{
|
||
|
if (group != g) initCache(g);
|
||
|
}
|
||
|
|
||
|
bool KScoringManager::hasRulesForCurrentGroup()
|
||
|
{
|
||
|
return ruleList.count() != 0;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQStringList KScoringManager::getRuleNames()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList l;
|
||
|
TQPtrListIterator<KScoringRule> it(allRules);
|
||
15 years ago
|
for( ; it.current(); ++it) {
|
||
|
l << it.current()->getName();
|
||
|
}
|
||
|
return l;
|
||
|
}
|
||
|
|
||
15 years ago
|
KScoringRule* KScoringManager::findRule(const TQString& ruleName)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPtrListIterator<KScoringRule> it(allRules);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
if ( it.current()->getName() == ruleName ) {
|
||
|
return it;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
bool KScoringManager::setCacheValid(bool v)
|
||
|
{
|
||
|
bool res = cacheValid;
|
||
|
cacheValid = v;
|
||
|
return res;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KScoringManager::findUniqueName() const
|
||
15 years ago
|
{
|
||
|
int nr = 0;
|
||
15 years ago
|
TQString ret;
|
||
15 years ago
|
bool duplicated=false;
|
||
|
|
||
|
while (nr < 99999999) {
|
||
|
nr++;
|
||
14 years ago
|
ret = i18n("rule %1").tqarg(nr);
|
||
15 years ago
|
|
||
|
duplicated=false;
|
||
15 years ago
|
TQPtrListIterator<KScoringRule> it(allRules);
|
||
15 years ago
|
for( ; it.current(); ++it) {
|
||
|
if (it.current()->getName() == ret) {
|
||
|
duplicated = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!duplicated)
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
bool KScoringManager::hasFeature(int p)
|
||
|
{
|
||
|
switch (p) {
|
||
|
case ActionBase::SETSCORE: return canScores();
|
||
|
case ActionBase::NOTIFY: return canNotes();
|
||
|
case ActionBase::COLOR: return canColors();
|
||
|
case ActionBase::MARKASREAD: return canMarkAsRead();
|
||
|
default: return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KScoringManager::getDefaultHeaders() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList l;
|
||
15 years ago
|
l.append("Subject");
|
||
|
l.append("From");
|
||
|
l.append("Date");
|
||
|
l.append("Message-ID");
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
void KScoringManager::pushRuleList()
|
||
|
{
|
||
|
stack.push(allRules);
|
||
|
}
|
||
|
|
||
|
void KScoringManager::popRuleList()
|
||
|
{
|
||
|
stack.pop(allRules);
|
||
|
}
|
||
|
|
||
|
void KScoringManager::removeTOS()
|
||
|
{
|
||
|
stack.drop();
|
||
|
}
|
||
|
|
||
|
RuleStack::RuleStack()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
RuleStack::~RuleStack()
|
||
|
{}
|
||
|
|
||
15 years ago
|
void RuleStack::push(TQPtrList<KScoringRule>& l)
|
||
15 years ago
|
{
|
||
|
kdDebug(5100) << "RuleStack::push pushing list with " << l.count() << " rules" << endl;
|
||
|
KScoringManager::ScoringRuleList *l1 = new KScoringManager::ScoringRuleList;
|
||
|
for ( KScoringRule *r=l.first(); r != 0; r=l.next() ) {
|
||
|
l1->append(new KScoringRule(*r));
|
||
|
}
|
||
|
stack.push(l1);
|
||
|
kdDebug(5100) << "now there are " << stack.count() << " lists on the stack" << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void RuleStack::pop(TQPtrList<KScoringRule>& l)
|
||
15 years ago
|
{
|
||
|
top(l);
|
||
|
drop();
|
||
|
kdDebug(5100) << "RuleStack::pop pops list with " << l.count() << " rules" << endl;
|
||
|
kdDebug(5100) << "now there are " << stack.count() << " lists on the stack" << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void RuleStack::top(TQPtrList<KScoringRule>& l)
|
||
15 years ago
|
{
|
||
|
l.clear();
|
||
|
KScoringManager::ScoringRuleList *l1 = stack.top();
|
||
|
l = *l1;
|
||
|
}
|
||
|
|
||
|
void RuleStack::drop()
|
||
|
{
|
||
|
kdDebug(5100) << "drop: now there are " << stack.count() << " lists on the stack" << endl;
|
||
|
stack.remove();
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "kscoring.moc"
|