summaryrefslogtreecommitdiffstats
path: root/knode/knstringfilter.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /knode/knstringfilter.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'knode/knstringfilter.cpp')
-rw-r--r--knode/knstringfilter.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/knode/knstringfilter.cpp b/knode/knstringfilter.cpp
new file mode 100644
index 000000000..c41b723fe
--- /dev/null
+++ b/knode/knstringfilter.cpp
@@ -0,0 +1,165 @@
+/*
+ KNode, the KDE newsreader
+ Copyright (c) 1999-2005 the KNode authors.
+ See file AUTHORS for details
+
+ 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
+*/
+
+#include <qcombobox.h>
+#include <qlayout.h>
+#include <qcheckbox.h>
+
+#include <klocale.h>
+#include <ksimpleconfig.h>
+#include <klineedit.h>
+
+#include "kngroup.h"
+#include "knnntpaccount.h"
+#include "knglobals.h"
+#include "knconfigmanager.h"
+#include "knstringfilter.h"
+
+
+KNStringFilter& KNStringFilter::operator=(const KNStringFilter &sf)
+{
+ con=sf.con;
+ data=sf.data.copy();
+ regExp=sf.regExp;
+
+ return (*this);
+}
+
+
+
+bool KNStringFilter::doFilter(const QString &s)
+{
+ bool ret=true;
+
+ if(!expanded.isEmpty()) {
+ if(regExp) {
+ QRegExp matcher(expanded);
+ ret = ( matcher.search(s) >= 0 );
+ } else
+ ret=(s.find(expanded,0,false)!=-1);
+
+ if(!con) ret=!ret;
+ }
+
+ return ret;
+}
+
+
+
+// replace placeholders
+void KNStringFilter::expand(KNGroup *g)
+{
+ KNConfig::Identity *id = (g) ? g->identity() : 0;
+
+ if (!id) {
+ id = (g) ? g->account()->identity() : 0;
+ if (!id)
+ id = knGlobals.configManager()->identity();
+ }
+
+ expanded = data;
+ expanded.replace(QRegExp("%MYNAME"), id->name());
+ expanded.replace(QRegExp("%MYEMAIL"), id->email());
+}
+
+
+
+void KNStringFilter::load(KSimpleConfig *conf)
+{
+ con=conf->readBoolEntry("contains", true);
+ data=conf->readEntry("Data");
+ regExp=conf->readBoolEntry("regX", false);
+}
+
+
+
+void KNStringFilter::save(KSimpleConfig *conf)
+{
+ conf->writeEntry("contains", con);
+ conf->writeEntry("Data", data);
+ conf->writeEntry("regX", regExp);
+}
+
+
+//===============================================================================
+
+KNStringFilterWidget::KNStringFilterWidget(const QString& title, QWidget *parent)
+ : QGroupBox(title, parent)
+{
+ fType=new QComboBox(this);
+ fType->insertItem(i18n("Does Contain"));
+ fType->insertItem(i18n("Does NOT Contain"));
+
+ fString=new KLineEdit(this);
+
+ regExp=new QCheckBox(i18n("Regular expression"), this);
+
+ QGridLayout *topL=new QGridLayout(this, 3,3, 8,5 );
+ topL->addRowSpacing(0, fontMetrics().lineSpacing()-4);
+ topL->addWidget(fType, 1,0);
+ topL->addColSpacing(1, 10);
+ topL->addWidget(regExp, 1,1);
+ topL->addMultiCellWidget(fString, 2,2, 0,2);
+ topL->setColStretch(2,1);
+}
+
+
+
+KNStringFilterWidget::~KNStringFilterWidget()
+{
+}
+
+
+
+KNStringFilter KNStringFilterWidget::filter()
+{
+ KNStringFilter ret;
+ ret.con=(fType->currentItem()==0);
+ ret.data=fString->text();
+ ret.regExp=regExp->isChecked();
+
+ return ret;
+}
+
+
+
+void KNStringFilterWidget::setFilter(KNStringFilter &f)
+{
+ if(f.con) fType->setCurrentItem(0);
+ else fType->setCurrentItem(1);
+ fString->setText(f.data);
+ regExp->setChecked(f.regExp);
+}
+
+
+
+void KNStringFilterWidget::clear()
+{
+ fString->clear();
+ fType->setCurrentItem(0);
+ regExp->setChecked(false);
+}
+
+
+void KNStringFilterWidget::setStartFocus()
+{
+ fString->setFocus();
+}
+
+
+// -----------------------------------------------------------------------------+
+
+#include "knstringfilter.moc"
+
+// kate: space-indent on; indent-width 2;