Add warning about missing Nepomuk in the KMail composer.
[kdepim.git] / kleopatra / utils / multivalidator.cpp
blob76a7c8cccf0cb65a8f3b6b1f0ff5168c7c5ab870
1 /* -*- mode: c++; c-basic-offset:4 -*-
2 utils/multivalidator.cpp
4 This file is part of Kleopatra, the KDE keymanager
5 Copyright (c) 2008 Klarälvdalens Datakonsult AB
7 Kleopatra is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Kleopatra is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the Qt library by Trolltech AS, Norway (or with modified versions
24 of Qt that use the same license as Qt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 Qt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
30 your version.
33 #include <config-kleopatra.h>
35 #include "multivalidator.h"
37 #include <kleo/stl_util.h>
39 #include <boost/lambda/lambda.hpp>
40 #include <boost/lambda/bind.hpp>
42 #include <vector>
43 #include <iterator>
45 using namespace Kleo;
46 using namespace boost;
47 using namespace boost::lambda;
49 MultiValidator::~MultiValidator() {}
51 void MultiValidator::addValidator( QValidator * vali ) {
52 if ( !vali )
53 return;
54 if ( !vali->parent() )
55 vali->setParent( this );
56 connect( vali, SIGNAL(destroyed(QObject*)), this, SLOT(_kdmv_slotDestroyed(QObject*)) );
57 m_validators.push_back( vali );
60 void MultiValidator::addValidators( const QList<QValidator*> & valis ) {
61 kdtools::for_each( valis, bind( &MultiValidator::addValidator, this, _1 ) );
64 void MultiValidator::removeValidator( QValidator * vali ) {
65 if ( !vali )
66 return;
67 _kdmv_slotDestroyed( vali );
68 if ( vali->parent() == this )
69 delete vali;
70 else
71 disconnect( vali, SIGNAL(destroyed(QObject*)), this, SLOT(_kdmv_slotDestroyed(QObject*)) );
74 void MultiValidator::removeValidators( const QList<QValidator*> & valis ) {
75 kdtools::for_each( valis, bind( &MultiValidator::removeValidator, this, _1 ) );
78 void MultiValidator::fixup( QString & str ) const {
79 kdtools::for_each( m_validators, bind( &QValidator::fixup, _1, ref( str ) ) );
82 QValidator::State MultiValidator::validate( QString & str, int & pos ) const {
83 std::vector<State> states;
84 states.reserve( m_validators.size() );
85 std::transform( m_validators.begin(), m_validators.end(),
86 std::back_inserter( states ),
87 bind( &QValidator::validate, _1, ref( str ), ref( pos ) ) );
88 if ( kdtools::any( states, _1 == Invalid ) )
89 return Invalid;
90 if ( kdtools::all( states, _1 == Acceptable ) )
91 return Acceptable;
92 return Intermediate;
95 void MultiValidator::_kdmv_slotDestroyed( QObject * o ) {
96 m_validators.erase( std::remove( m_validators.begin(), m_validators.end(), o ),
97 m_validators.end() );
100 #include "moc_multivalidator.cpp"