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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • widgets
kstringvalidator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2001 Marc Mutz <mutz@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; version 2.0
7  of the License.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public
15  License along with this library; if not, write to the Free
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301 USA
18 */
19 
20 #include "kstringvalidator.h"
21 
22 #include <kdebug.h>
23 
24 class KStringListValidator::Private
25 {
26  public:
27  QStringList mStringList;
28  bool mRejecting : 1;
29  bool mFixupEnabled : 1;
30 };
31 
32 //
33 // KStringListValidator
34 //
35 KStringListValidator::KStringListValidator( const QStringList &list, bool rejecting,
36  bool fixupEnabled, QObject *parent )
37  : QValidator( parent ),
38  d( new Private )
39 {
40  d->mStringList = list;
41  d->mRejecting = rejecting;
42  d->mFixupEnabled = fixupEnabled;
43 }
44 
45 KStringListValidator::~KStringListValidator()
46 {
47  delete d;
48 }
49 
50 QValidator::State KStringListValidator::validate( QString & input, int& ) const
51 {
52  if ( input.isEmpty() )
53  return Intermediate;
54 
55  if ( isRejecting() ) // anything not in mStringList is acceptable:
56  if ( !d->mStringList.contains( input ) )
57  return Acceptable;
58  else
59  return Intermediate;
60  else // only what is in mStringList is acceptable:
61  if ( d->mStringList.contains( input ) )
62  return Acceptable;
63  else
64  for ( QStringList::ConstIterator it = d->mStringList.constBegin(); it != d->mStringList.constEnd() ; ++it )
65  if ( (*it).startsWith( input ) || input.startsWith( *it ) )
66  return Intermediate;
67 
68  return Invalid;
69 }
70 
71 void KStringListValidator::fixup( QString& ) const
72 {
73  if ( !isFixupEnabled() )
74  return;
75 
76  // warn (but only once!) about non-implemented fixup():
77  static bool warn = true;
78  if ( warn ) {
79  kDebug() << "KStringListValidator::fixup() isn't yet implemented!";
80  warn = false;
81  }
82 }
83 
84 void KStringListValidator::setRejecting( bool rejecting )
85 {
86  d->mRejecting = rejecting;
87 }
88 
89 bool KStringListValidator::isRejecting() const
90 {
91  return d->mRejecting;
92 }
93 
94 void KStringListValidator::setFixupEnabled( bool fixupEnabled )
95 {
96  d->mFixupEnabled = fixupEnabled;
97 }
98 
99 bool KStringListValidator::isFixupEnabled() const
100 {
101  return d->mFixupEnabled;
102 }
103 
104 void KStringListValidator::setStringList( const QStringList &list )
105 {
106  d->mStringList = list;
107 }
108 
109 QStringList KStringListValidator::stringList() const
110 {
111  return d->mStringList;
112 }
113 
114 //
115 // KMimeTypeValidator
116 //
117 
118 #define ALLOWED_CHARS "!#-'*+.0-9^-~+-"
119 
120 class KMimeTypeValidator::Private
121 {
122 };
123 
124 KMimeTypeValidator::KMimeTypeValidator( QObject* parent )
125  : QValidator( parent ),
126  d( 0 )
127 {
128 }
129 
130 KMimeTypeValidator::~KMimeTypeValidator()
131 {
132  delete d;
133 }
134 
135 QValidator::State KMimeTypeValidator::validate( QString &input, int& ) const
136 {
137  if ( input.isEmpty() )
138  return Intermediate;
139 
140  QRegExp acceptable( "[" ALLOWED_CHARS "]+/[" ALLOWED_CHARS "]+", Qt::CaseInsensitive );
141  if ( acceptable.exactMatch( input ) )
142  return Acceptable;
143 
144  QRegExp intermediate( "[" ALLOWED_CHARS "]*/?[" ALLOWED_CHARS "]*", Qt::CaseInsensitive );
145  if ( intermediate.exactMatch( input ) )
146  return Intermediate;
147 
148  return Invalid;
149 }
150 
151 void KMimeTypeValidator::fixup( QString &input ) const
152 {
153  QRegExp invalidChars("[^/" ALLOWED_CHARS "]+");
154  input.remove( invalidChars );
155 }
156 
157 #include "kstringvalidator.moc"
KStringListValidator::rejecting
bool rejecting
Definition: kstringvalidator.h:64
KStringListValidator::fixupEnabled
bool fixupEnabled
Definition: kstringvalidator.h:65
kdebug.h
KStringListValidator::fixup
virtual void fixup(QString &input) const
Reimplemented from.
Definition: kstringvalidator.cpp:71
KMimeTypeValidator::KMimeTypeValidator
KMimeTypeValidator(QObject *parent=0)
Creates a new mime type validator.
Definition: kstringvalidator.cpp:124
KStringListValidator::KStringListValidator
KStringListValidator(const QStringList &list=QStringList(), bool rejecting=true, bool fixupEnabled=false, QObject *parent=0)
Creates a new string validator.
Definition: kstringvalidator.cpp:35
QString
QObject
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KStringListValidator::stringList
QStringList stringList() const
Returns the string list of the validator.
QValidator
QStringList
KStringListValidator::validate
virtual State validate(QString &input, int &pos) const
Reimplemented from.
Definition: kstringvalidator.cpp:50
KMimeTypeValidator::validate
virtual State validate(QString &input, int &pos) const
Checks for well-formed mimetype.
Definition: kstringvalidator.cpp:135
ALLOWED_CHARS
#define ALLOWED_CHARS
Definition: kstringvalidator.cpp:118
KStringListValidator::setRejecting
void setRejecting(bool rejecting)
Sets whether the string validator is in rejecting mode or not.
Definition: kstringvalidator.cpp:84
KStringListValidator::~KStringListValidator
~KStringListValidator()
Destroys the string validator.
Definition: kstringvalidator.cpp:45
KStringListValidator::setStringList
void setStringList(const QStringList &list)
Sets the.
Definition: kstringvalidator.cpp:104
KStringListValidator::setFixupEnabled
void setFixupEnabled(bool fixupEnabled)
Sets the fixup flag.
Definition: kstringvalidator.cpp:94
KMimeTypeValidator::~KMimeTypeValidator
~KMimeTypeValidator()
Destroys the mime type validator.
Definition: kstringvalidator.cpp:130
KStringListValidator::isRejecting
bool isRejecting() const
Returns whether the string validator is in rejecting mode.
Definition: kstringvalidator.cpp:89
KMimeTypeValidator::fixup
virtual void fixup(QString &input) const
Removes all characters that are forbidden in mimetypes.
Definition: kstringvalidator.cpp:151
kstringvalidator.h
KStringListValidator::isFixupEnabled
bool isFixupEnabled() const
Returns whether the fixup flag is set.
Definition: kstringvalidator.cpp:99
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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