• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
knstringfilter.cpp
Go to the documentation of this file.
1 /*
2  KNode, the KDE newsreader
3  Copyright (c) 1999-2005 the KNode authors.
4  See file AUTHORS for details
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  You should have received a copy of the GNU General Public License
11  along with this program; if not, write to the Free Software Foundation,
12  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
13 */
14 
15 #include "knstringfilter.h"
16 
17 #include "knglobals.h"
18 #include "kngroup.h"
19 #include "knnntpaccount.h"
20 #include "settings.h"
21 
22 #include <QCheckBox>
23 #include <QComboBox>
24 #include <QGridLayout>
25 #include <kconfig.h>
26 #include <kdialog.h>
27 #include <klineedit.h>
28 #include <klocale.h>
29 #include <KPIMIdentities/Identity>
30 
31 
32 using namespace KNode;
33 
34 StringFilter& KNode::StringFilter::operator=( const StringFilter &sf )
35 {
36  con=sf.con;
37  data=sf.data;
38  regExp=sf.regExp;
39 
40  return (*this);
41 }
42 
43 
44 
45 bool KNode::StringFilter::doFilter( const QString &s )
46 {
47  bool ret=true;
48 
49  if(!expanded.isEmpty()) {
50  if(regExp) {
51  QRegExp matcher(expanded);
52  ret = ( matcher.indexIn(s) >= 0 );
53  } else
54  ret = ( s.indexOf( expanded, 0, Qt::CaseInsensitive ) != -1 );
55 
56  if(!con) ret=!ret;
57  }
58 
59  return ret;
60 }
61 
62 
63 
64 // replace placeholders
65 void KNode::StringFilter::expand( KNGroup *g )
66 {
67  KPIMIdentities::Identity id;
68  if ( g ) {
69  if ( !g->identity().isNull() ) {
70  id = g->identity();
71  } else if ( !g->account()->identity().isNull() ) {
72  id = g->account()->identity();
73  }
74  }
75  if ( id.isNull() ) {
76  id = KNGlobals::self()->settings()->identity();
77  }
78 
79  expanded = data;
80  expanded.replace( QRegExp("%MYNAME"), id.fullName() );
81  expanded.replace( QRegExp("%MYEMAIL"), id.primaryEmailAddress() );
82 }
83 
84 
85 
86 void KNode::StringFilter::load( const KConfigGroup &group )
87 {
88  con=group.readEntry("contains", true);
89  data=group.readEntry("Data");
90  regExp=group.readEntry("regX", false);
91 }
92 
93 
94 
95 void KNode::StringFilter::save( KConfigGroup &group )
96 {
97  group.writeEntry("contains", con);
98  group.writeEntry("Data", data);
99  group.writeEntry("regX", regExp);
100 }
101 
102 
103 //===============================================================================
104 
105 KNode::StringFilterWidget::StringFilterWidget( const QString& title, QWidget *parent )
106  : QGroupBox( title, parent )
107 {
108  fType=new QComboBox(this);
109  fType->addItem(i18n("Does Contain"));
110  fType->addItem(i18n("Does NOT Contain"));
111 
112  fString=new KLineEdit(this);
113 
114  regExp=new QCheckBox(i18n("Regular expression"), this);
115 
116  QGridLayout *topL = new QGridLayout( this );
117  topL->setSpacing( KDialog::spacingHint() );
118  topL->addWidget( fType, 0, 0 );
119  topL->addWidget( regExp, 0, 1 );
120  topL->addWidget( fString, 1, 0, 1, 2 );
121  topL->setColumnStretch( 2, 1 );
122 }
123 
124 
125 
126 KNode::StringFilterWidget::~StringFilterWidget()
127 {
128 }
129 
130 
131 
132 KNode::StringFilter StringFilterWidget::filter()
133 {
134  StringFilter ret;
135  ret.con=(fType->currentIndex()==0);
136  ret.data=fString->text();
137  ret.regExp=regExp->isChecked();
138 
139  return ret;
140 }
141 
142 
143 
144 void KNode::StringFilterWidget::setFilter( StringFilter &f )
145 {
146  if(f.con) fType->setCurrentIndex(0);
147  else fType->setCurrentIndex(1);
148  fString->setText(f.data);
149  regExp->setChecked(f.regExp);
150 }
151 
152 
153 
154 void KNode::StringFilterWidget::clear()
155 {
156  fString->clear();
157  fType->setCurrentIndex(0);
158  regExp->setChecked(false);
159 }
160 
161 
162 void KNode::StringFilterWidget::setStartFocus()
163 {
164  fString->setFocus();
165 }
166 
167 
168 // -----------------------------------------------------------------------------+
169 
170 #include "knstringfilter.moc"
KNode::StringFilter
Filter for string values.
Definition: knstringfilter.h:31
KNode::StringFilterWidget::clear
void clear()
Definition: knstringfilter.cpp:154
KNode::StringFilterWidget::StringFilterWidget
StringFilterWidget(const QString &title, QWidget *parent)
Create a new configuration widget for StringFilter.
Definition: knstringfilter.cpp:105
KNode::StringFilter::data
QString data
Definition: knstringfilter.h:49
QWidget
KNode::StringFilterWidget::fType
QComboBox * fType
Definition: knstringfilter.h:80
KNGlobals::self
static KNGlobals * self()
Return the KNGlobals instance.
Definition: knglobals.cpp:72
KNode::StringFilterWidget::filter
StringFilter filter()
Definition: knstringfilter.cpp:132
KNode::StringFilterWidget::setFilter
void setFilter(StringFilter &f)
Definition: knstringfilter.cpp:144
KNGroup
Representation of a news group.
Definition: kngroup.h:41
kngroup.h
knnntpaccount.h
KNode::StringFilter::load
void load(const KConfigGroup &group)
Definition: knstringfilter.cpp:86
QComboBox
KNode::StringFilterWidget::setStartFocus
void setStartFocus()
usablity hack for the search dialog
Definition: knstringfilter.cpp:162
KNode::StringFilter::expand
void expand(KNGroup *g)
replace placeholders
Definition: knstringfilter.cpp:65
KNode::Settings::identity
virtual const KPIMIdentities::Identity & identity() const
Returns the global identity (or the default one when none is set yet).
Definition: settings.cpp:91
QGroupBox
KNGlobals::settings
KNode::Settings * settings()
Returns the KConfigXT generated settings object.
Definition: knglobals.cpp:182
KNode::StringFilter::doFilter
bool doFilter(const QString &s)
Definition: knstringfilter.cpp:45
KNode::StringFilter::regExp
bool regExp
Definition: knstringfilter.h:50
knglobals.h
KNode::StringFilter::operator=
StringFilter & operator=(const StringFilter &sf)
Definition: knstringfilter.cpp:34
KLineEdit
settings.h
KNode::StringFilter::con
bool con
Definition: knstringfilter.h:50
knstringfilter.h
KNode::StringFilter::save
void save(KConfigGroup &conf)
Definition: knstringfilter.cpp:95
KNGroup::account
KNNntpAccount::Ptr account()
Returns the account this group belongs to.
Definition: kngroup.cpp:161
KNode::StringFilterWidget::regExp
QCheckBox * regExp
Definition: knstringfilter.h:79
KNGroup::identity
virtual const KPIMIdentities::Identity & identity() const
Returns the identity configured for this group.
Definition: kngroup.cpp:169
KNode::StringFilterWidget::fString
KLineEdit * fString
Definition: knstringfilter.h:81
KNode::StringFilterWidget::~StringFilterWidget
~StringFilterWidget()
Definition: knstringfilter.cpp:126
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal