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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • models
predicates.h
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  models/predicates.h
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 Klarälvdalens Datakonsult AB
6 
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.
11 
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.
16 
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
20 
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.
31 */
32 
33 #ifndef __KLEOPATRA_MODELS_PREDICATES_H__
34 #define __KLEOPATRA_MODELS_PREDICATES_H__
35 
36 #include <kleo/stl_util.h>
37 
38 #include <QByteArray>
39 #include <string>
40 
41 #include <gpgme++/key.h>
42 
43 #include <boost/bind.hpp>
44 
45 #include <cstring>
46 #include <algorithm>
47 #include <iterator>
48 
49 namespace Kleo {
50 namespace _detail {
51 
52  inline int mystrcmp( const char * s1, const char * s2 ) {
53  using namespace std;
54  return s1 ? s2 ? strcmp( s1, s2 ) : 1 : s2 ? -1 : 0 ;
55  }
56 
57 #define make_comparator_str_impl( Name, expr, cmp ) \
58  template <template <typename U> class Op> \
59  struct Name { \
60  typedef bool result_type; \
61  \
62  bool operator()( const char * lhs, const char * rhs ) const { \
63  return Op<int>()( cmp, 0 ); \
64  } \
65  \
66  bool operator()( const std::string & lhs, const std::string & rhs ) const { \
67  return operator()( lhs.c_str(), rhs.c_str() ); \
68  } \
69  bool operator()( const char * lhs, const std::string & rhs ) const { \
70  return operator()( lhs, rhs.c_str() ); \
71  } \
72  bool operator()( const std::string & lhs, const char * rhs ) const { \
73  return operator()( lhs.c_str(), rhs ); \
74  } \
75  \
76  template <typename T> \
77  bool operator()( const T & lhs, const T & rhs ) const { \
78  return operator()( (lhs expr), (rhs expr) ); \
79  } \
80  template <typename T> \
81  bool operator()( const T & lhs, const char * rhs ) const { \
82  return operator()( (lhs expr), rhs ); \
83  } \
84  template <typename T> \
85  bool operator()( const char * lhs, const T & rhs ) const { \
86  return operator()( lhs, (rhs expr) ); \
87  } \
88  template <typename T> \
89  bool operator()( const T & lhs, const std::string & rhs ) const { \
90  return operator()( (lhs expr), rhs ); \
91  } \
92  template <typename T> \
93  bool operator()( const std::string & lhs, const T & rhs ) const { \
94  return operator()( lhs, (rhs expr) ); \
95  } \
96  }
97 
98 #define make_comparator_str_fast( Name, expr ) \
99  make_comparator_str_impl( Name, expr, _detail::mystrcmp( lhs, rhs ) )
100 #define make_comparator_str( Name, expr ) \
101  make_comparator_str_impl( Name, expr, qstricmp( lhs, rhs ) )
102 
103  make_comparator_str_fast( ByFingerprint, .primaryFingerprint() );
104  make_comparator_str_fast( ByKeyID, .keyID() );
105  make_comparator_str_fast( ByShortKeyID, .shortKeyID() );
106  make_comparator_str_fast( ByChainID, .chainID() );
107 
108  template <typename T>
109  void sort_by_fpr( T & t ) {
110  std::sort( t.begin(), t.end(), ByFingerprint<std::less>() );
111  }
112 
113  template <typename T>
114  void remove_duplicates_by_fpr( T & t ) {
115  t.erase( std::unique( t.begin(), t.end(), ByFingerprint<std::equal_to>() ), t.end() );
116  }
117 
118  template <typename T>
119  T union_by_fpr( const T & t1, const T & t2 ) {
120  T result;
121  result.reserve( t1.size() + t2.size() );
122  std::set_union( t1.begin(), t1.end(),
123  t2.begin(), t2.end(),
124  std::back_inserter( result ),
125  ByFingerprint<std::less>() );
126  return result;
127  }
128 
129  template <typename T>
130  T union_by_fpr_dirty( const T & t1, const T & t2 ) {
131  T cleaned( t1 );
132  sort_by_fpr( cleaned );
133  remove_duplicates_by_fpr( cleaned );
134  return union_by_fpr( cleaned, t2 );
135  }
136 
137  template <typename T>
138  void grep_protocol( T & t, GpgME::Protocol proto ) {
139  t.erase( std::remove_if( t.begin(), t.end(), boost::bind( &GpgME::Key::protocol, _1 ) != proto ), t.end() );
140  }
141 
142  template <typename T>
143  bool any_protocol( const T & t, GpgME::Protocol proto ) {
144  return kdtools::any( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
145  }
146 
147  template <typename T>
148  bool all_protocol( const T & t, GpgME::Protocol proto ) {
149  return kdtools::all( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
150  }
151 
152  template <typename T>
153  bool none_of_protocol( const T & t, GpgME::Protocol proto ) {
154  return kdtools::none_of( t, boost::bind( &GpgME::Key::protocol, _1 ) == proto );
155  }
156 
157  template <typename T>
158  void grep_secret( T & t ) {
159  t.erase( std::remove_if( t.begin(), t.end(), boost::mem_fn( &GpgME::Key::hasSecret ) ), t.end() );
160  }
161 
162  template <typename T>
163  bool any_secret( const T & t ) {
164  return kdtools::any( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
165  }
166 
167  template <typename T>
168  bool all_secret( const T & t ) {
169  return kdtools::all( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
170  }
171 
172  template <typename T>
173  bool none_of_secret( const T & t ) {
174  return kdtools::none_of( t, boost::mem_fn( &GpgME::Key::hasSecret ) );
175  }
176 
177 
178  template <typename T>
179  void grep_can_encrypt( T & t ) {
180  t.erase( std::remove_if( t.begin(), t.end(), !boost::bind( &GpgME::Key::canEncrypt, _1 ) ), t.end() );
181  }
182 
183 
184 }
185 }
186 
187 #endif /* __KLEOPATRA_MODELS_PREDICATES_H__ */
Kleo::_detail::any_protocol
bool any_protocol(const T &t, GpgME::Protocol proto)
Definition: predicates.h:143
Kleo::_detail::grep_secret
void grep_secret(T &t)
Definition: predicates.h:158
Kleo::_detail::grep_can_encrypt
void grep_can_encrypt(T &t)
Definition: predicates.h:179
Kleo::_detail::make_comparator_str_fast
make_comparator_str_fast(ByFingerprint,.primaryFingerprint())
Kleo::_detail::any_secret
bool any_secret(const T &t)
Definition: predicates.h:163
Kleo::_detail::union_by_fpr
T union_by_fpr(const T &t1, const T &t2)
Definition: predicates.h:119
Kleo::_detail::grep_protocol
void grep_protocol(T &t, GpgME::Protocol proto)
Definition: predicates.h:138
Kleo::_detail::all_secret
bool all_secret(const T &t)
Definition: predicates.h:168
Kleo::_detail::all_protocol
bool all_protocol(const T &t, GpgME::Protocol proto)
Definition: predicates.h:148
Kleo::_detail::none_of_secret
bool none_of_secret(const T &t)
Definition: predicates.h:173
Kleo::_detail::none_of_protocol
bool none_of_protocol(const T &t, GpgME::Protocol proto)
Definition: predicates.h:153
Kleo::_detail::sort_by_fpr
void sort_by_fpr(T &t)
Definition: predicates.h:109
Kleo::_detail::remove_duplicates_by_fpr
void remove_duplicates_by_fpr(T &t)
Definition: predicates.h:114
Kleo::_detail::union_by_fpr_dirty
T union_by_fpr_dirty(const T &t1, const T &t2)
Definition: predicates.h:130
Kleo::_detail::mystrcmp
int mystrcmp(const char *s1, const char *s2)
Definition: predicates.h:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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