certmanager/lib

keyselectiondialog.h
1 /*
2  keyselectiondialog.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarävdalens Datakonsult AB
6 
7  Based on kpgpui.h
8  Copyright (C) 2001,2002 the KPGP authors
9  See file libtdenetwork/AUTHORS.kpgp for details
10 
11  Libkleopatra is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15 
16  Libkleopatra is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 
25  In addition, as a special exception, the copyright holders give
26  permission to link the code of this program with any edition of
27  the TQt library by Trolltech AS, Norway (or with modified versions
28  of TQt that use the same license as TQt), and distribute linked
29  combinations including the two. You must obey the GNU General
30  Public License in all respects for all of the code used other than
31  TQt. If you modify this file, you may extend this exception to
32  your version of the file, but you are not obligated to do so. If
33  you do not wish to do so, delete this exception statement from
34  your version.
35 */
36 
37 #ifndef __KLEO_UI_KEYSELECTIONDIALOG_H__
38 #define __KLEO_UI_KEYSELECTIONDIALOG_H__
39 
40 #include <kdialogbase.h>
41 
42 #include <kleo/cryptobackend.h>
43 #include <gpgmepp/key.h>
44 #include <tdemacros.h>
45 #include <vector>
46 
47 class TQVBoxLayout;
48 class TQCheckBox;
49 class TQPixmap;
50 class TQTimer;
51 class TQListViewItem;
52 class TQRegExp;
53 class TQPoint;
54 
55 namespace Kleo {
56  class KeyListView;
57  class KeyListViewItem;
58 }
59 
60 namespace GpgME {
61  class KeyListResult;
62 }
63 
64 namespace Kleo {
65 
66  class TDE_EXPORT KeySelectionDialog : public KDialogBase {
67  TQ_OBJECT
68 
69  public:
70 
71  enum KeyUsage {
72  PublicKeys = 1,
73  SecretKeys = 2,
74  EncryptionKeys = 4,
75  SigningKeys = 8,
76  ValidKeys = 16,
77  TrustedKeys = 32,
78  CertificationKeys = 64,
79  AuthenticationKeys = 128,
80  OpenPGPKeys = 256,
81  SMIMEKeys = 512,
82  AllKeys = PublicKeys | SecretKeys | OpenPGPKeys | SMIMEKeys,
83  ValidEncryptionKeys = AllKeys | EncryptionKeys | ValidKeys,
84  ValidTrustedEncryptionKeys = AllKeys | EncryptionKeys | ValidKeys | TrustedKeys
85  };
86 
87  KeySelectionDialog( const TQString & title,
88  const TQString & text,
89  const std::vector<GpgME::Key> & selectedKeys=std::vector<GpgME::Key>(),
90  unsigned int keyUsage=AllKeys,
91  bool extendedSelection=false,
92  bool rememberChoice=false,
93  TQWidget * parent=0, const char * name=0,
94  bool modal=true );
95  KeySelectionDialog( const TQString & title,
96  const TQString & text,
97  const TQString & initialPattern,
98  const std::vector<GpgME::Key> & selectedKeys,
99  unsigned int keyUsage=AllKeys,
100  bool extendedSelection=false,
101  bool rememberChoice=false,
102  TQWidget * parent=0, const char * name=0,
103  bool modal=true );
104  KeySelectionDialog( const TQString & title,
105  const TQString & text,
106  const TQString & initialPattern,
107  unsigned int keyUsage=AllKeys,
108  bool extendedSelection=false,
109  bool rememberChoice=false,
110  TQWidget * parent=0, const char * name=0,
111  bool modal=true );
112  ~KeySelectionDialog();
113 
116  const GpgME::Key & selectedKey() const;
117 
118  TQString fingerprint() const;
119 
121  const std::vector<GpgME::Key> & selectedKeys() const { return mSelectedKeys; }
122 
124  TQStringList fingerprints() const;
125 
127  TQStringList pgpKeyFingerprints() const;
129  TQStringList smimeFingerprints() const;
130 
131  bool rememberSelection() const;
132  protected slots:
133  // reimplemented to avoid popping up the help, since we
134  // override the button
135  void slotHelp();
136 
137  // Could be used by derived classes to insert their own widget
138  TQVBoxLayout* topLayout() const { return mTopLayout; }
139 
140  private slots:
141  void slotRereadKeys();
142  void slotStartCertificateManager( const TQString &query = TQString() );
143  void slotStartSearchForExternalCertificates() {
144  slotStartCertificateManager( mInitialQuery );
145  }
146  void slotKeyListResult( const GpgME::KeyListResult & );
147  void slotSelectionChanged();
148  void slotCheckSelection() { slotCheckSelection( 0 ); }
149  void slotCheckSelection( Kleo::KeyListViewItem * );
150  void slotRMB( Kleo::KeyListViewItem *, const TQPoint & );
151  void slotRecheckKey();
152  void slotTryOk();
153  void slotOk();
154  void slotCancel();
155  void slotSearch( const TQString & text );
156  void slotSearch();
157  void slotFilter();
158 
159  private:
160  void filterByKeyID( const TQString & keyID );
161  void filterByKeyIDOrUID( const TQString & keyID );
162  void filterByUID( const TQString & uid );
163  void showAllItems();
164  bool anyChildMatches( const Kleo::KeyListViewItem * item, TQRegExp & rx ) const;
165 
166  void connectSignals();
167  void disconnectSignals();
168 
169  void startKeyListJobForBackend( const Kleo::CryptoBackend::Protocol *, const std::vector<GpgME::Key> &, bool );
170  void startValidatingKeyListing();
171 
172  void init( bool, bool, const TQString &, const TQString & );
173 
174  private:
175  TQVBoxLayout* mTopLayout;
176  Kleo::KeyListView * mKeyListView;
177  const Kleo::CryptoBackend::Protocol * mOpenPGPBackend;
178  const Kleo::CryptoBackend::Protocol * mSMIMEBackend;
179  TQCheckBox * mRememberCB;
180  std::vector<GpgME::Key> mSelectedKeys, mKeysToCheck;
181  unsigned int mKeyUsage;
182  TQTimer * mCheckSelectionTimer;
183  TQTimer * mStartSearchTimer;
184  // cross-eventloop temporaries:
185  TQString mSearchText;
186  const TQString mInitialQuery;
187  Kleo::KeyListViewItem * mCurrentContextMenuItem;
188  int mTruncated, mListJobCount, mSavedOffsetY;
189  };
190 
191 }
192 
193 #endif // __KLEO_UI_KEYSELECTIONDIALOG_H__