Libkleo

keyfilter.h
1 /*
2  keyfilter.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6 
7  SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include "kleo_export.h"
13 
14 #include <QFlags>
15 
16 #include <algorithm>
17 #include <memory>
18 
19 namespace GpgME
20 {
21 class Key;
22 class UserID;
23 }
24 
25 class QFont;
26 class QColor;
27 class QString;
28 
29 namespace Kleo
30 {
31 
32 /**
33  @short An abstract base class key filters
34 
35 */
36 class KLEO_EXPORT KeyFilter
37 {
38 public:
39  virtual ~KeyFilter()
40  {
41  }
42 
43  enum MatchContext {
44  // clang-format off
45  NoMatchContext = 0x0,
46  Appearance = 0x1,
47  Filtering = 0x2,
48 
49  AnyMatchContext = Appearance | Filtering
50  // clang-format on
51  };
52  Q_DECLARE_FLAGS(MatchContexts, MatchContext)
53 
54  virtual bool matches(const GpgME::Key &key, MatchContexts ctx) const = 0;
55  virtual bool matches(const GpgME::UserID &userID, MatchContexts ctx) const = 0;
56 
57  virtual unsigned int specificity() const = 0;
58  virtual QString id() const = 0;
59  virtual MatchContexts availableMatchContexts() const = 0;
60 
61  // not sure if we want these here, but for the time being, it's
62  // the easiest way:
63  virtual QColor fgColor() const = 0;
64  virtual QColor bgColor() const = 0;
65  virtual QString name() const = 0;
66  virtual QString icon() const = 0;
67 
68  class FontDescription
69  {
70  public:
71  FontDescription();
72  FontDescription(const FontDescription &other);
73  FontDescription &operator=(const FontDescription &other)
74  {
75  FontDescription copy(other);
76  swap(copy);
77  return *this;
78  }
79  ~FontDescription();
80 
81  static FontDescription create(bool bold, bool italic, bool strikeOut);
82  static FontDescription create(const QFont &font, bool bold, bool italic, bool strikeOut);
83 
84  QFont font(const QFont &base) const;
85 
86  FontDescription resolve(const FontDescription &other) const;
87 
88  void swap(FontDescription &other)
89  {
90  std::swap(this->d, other.d);
91  }
92  struct Private;
93 
94  private:
95  std::unique_ptr<Private> d;
96  };
97 
98  virtual FontDescription fontDescription() const = 0;
99 };
100 
101 Q_DECLARE_OPERATORS_FOR_FLAGS(KeyFilter::MatchContexts)
102 
103 }
104 
105 #include <QObject>
106 
107 Q_DECLARE_METATYPE(Kleo::KeyFilter::MatchContexts)
An abstract base class key filters.
Definition: keyfilter.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:56:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.