one entry for korganizer in khelpcenters navigation tree is enough
[kdepim.git] / libkpgp / kpgpui.h
blob94303d5e1efc36fcce62b2a00fd0d87f5f1a4029
1 /* -*- c++ -*-
2 kpgpui.h
4 Copyright (C) 2001,2002 the KPGP authors
5 See file AUTHORS.kpgp for details
7 This file is part of KPGP, the KDE PGP/GnuPG support library.
9 KPGP is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef KPGPUI_H
20 #define KPGPUI_H
22 #include "libkpgp_export.h"
23 #include "kpgp.h"
24 #include "kpgpkey.h"
26 #include <QtCore/QString> // is a member in KeyRequester
27 #include <QtCore/QVector> // used in KeyApprovalDialog
28 #include <QtGui/QWidget> // base class of Config
29 #include <QtGui/QCheckBox> // used in inlined methods
30 #include <QtGui/QPixmap>
31 #include <QtGui/QLabel>
33 #include <kdebug.h> // used in inlined methods
34 #include <kdialog.h> // base class of all dialogs here
35 #include <kpassworddialog.h>
37 class QString;
38 class QRegExp;
39 class QByteArray;
40 class QCheckBox; // needed by Config, KeySelectionDialog
41 class QTextEdit; // needed by CipherTextDialog
42 class QComboBox; // needed by Config
43 class QPixmap; // needed by KeySelectionDialog
44 class QPushButton; // needed by KeyRequester
45 class QTimer; // needed by KeySelectionDialog
46 class QGroupBox;
47 class QTreeWidgetItem;
49 class QTreeWidget; // needed by KeySelectionDialog
50 class KPasswordEdit; // needed by PassphraseDialog
52 namespace Kpgp {
54 class Module;
55 class Key; // needed by KeySelectionDialog
56 class KeyIDList; // needed by KeySelectionDialog
58 /** the passphrase dialog */
59 class KPGP_EXPORT PassphraseDialog : public KPasswordDialog
61 Q_OBJECT
63 public:
64 explicit PassphraseDialog( QWidget *parent=0,
65 const QString &caption=QString(),
66 const QString &keyID=QString());
67 virtual ~PassphraseDialog();
69 QString passphrase();
73 // -------------------------------------------------------------------------
74 /** A widget for configuring the pgp interface. Can be included into
75 a tabdialog. This widget by itself does not provide an apply/cancel
76 button mechanism. */
77 class KPGP_EXPORT Config : public QWidget
79 Q_OBJECT
81 public:
82 explicit Config( QWidget *parent = 0, bool encrypt = true );
83 virtual ~Config();
85 virtual void setValues();
86 virtual void applySettings();
87 QGroupBox* optionsGroupBox() { return mpOptionsGroupBox; }
88 Q_SIGNALS:
89 void changed();
91 protected:
92 Module *pgp;
93 QCheckBox *storePass;
94 QCheckBox *encToSelf;
95 QCheckBox *showCipherText;
96 QCheckBox *showKeyApprovalDlg;
97 QComboBox *toolCombo;
98 QGroupBox* mpOptionsGroupBox;
102 // -------------------------------------------------------------------------
103 #ifndef QT_NO_TREEWIDGET
104 #define KeySelectionDialogSuper KDialog
105 class KPGP_EXPORT KeySelectionDialog: public KeySelectionDialogSuper
107 Q_OBJECT
109 enum TrustCheckMode { NoExpensiveTrustCheck,
110 AllowExpensiveTrustCheck,
111 ForceTrustCheck
114 public:
115 /** allowedKeys: see kpgp.h
117 KeySelectionDialog( const KeyList& keyList,
118 const QString& title,
119 const QString& text = QString(),
120 const KeyIDList& keyIds = KeyIDList(),
121 const bool rememberChoice = false,
122 const unsigned int allowedKeys = AllKeys,
123 const bool extendedSelection = false,
124 QWidget *parent=0 );
125 virtual ~KeySelectionDialog();
127 /** Returns the key ID of the selected key in single selection mode.
128 Otherwise it returns a null string. */
129 virtual KeyID key() const;
131 /** Returns a list of selected key IDs. */
132 virtual KeyIDList keys() const
133 { return mKeyIds; }
135 virtual bool rememberSelection() const
136 { if( mRememberCB )
137 return mRememberCB->isChecked();
138 else
139 return false;
142 protected Q_SLOTS:
143 virtual void slotRereadKeys();
144 virtual void slotSelectionChanged();
145 virtual void slotCheckSelection( QTreeWidgetItem* = 0 );
146 virtual void slotRMB( const QPoint& pos );
147 virtual void slotRecheckKey();
148 virtual void slotOk();
149 virtual void slotCancel();
150 virtual void slotSearch( const QString & text );
151 virtual void slotFilter();
153 private:
154 void filterByKeyID( const QString & keyID );
155 void filterByKeyIDOrUID( const QString & keyID );
156 void filterByUID( const QString & uid );
157 void showAllItems();
158 bool anyChildMatches( const QTreeWidgetItem * item, QRegExp & rx ) const;
160 void initKeylist( const KeyList& keyList, const KeyIDList& keyIds );
162 QString keyInfo( const Kpgp::Key* ) const;
164 QString beautifyFingerprint( const QByteArray& ) const;
166 // Returns the key ID of the key the given QListViewItem belongs to
167 KeyID getKeyId( const QTreeWidgetItem* ) const;
169 // Returns: -1 = unusable, 0 = unknown, 1 = valid, but untrusted, 2 = trusted
170 int keyValidity( const Kpgp::Key* ) const;
172 // Updates the given QListViewItem with the data of the given key
173 void updateKeyInfo( const Kpgp::Key*, QTreeWidgetItem* ) const;
175 /** Checks if choosing the given key is allowed
176 Returns:
177 -1 = key must not be chosen,
178 0 = not enough information to decide whether the give key is allowed
179 or not,
180 1 = key can be chosen
182 int keyAdmissibility( QTreeWidgetItem*,
183 TrustCheckMode = NoExpensiveTrustCheck ) const;
185 // Perform expensive trust checks for the given keys
186 bool checkKeys( const QList<QTreeWidgetItem*>& ) const;
188 private:
189 QTreeWidget *mListView;
190 QCheckBox *mRememberCB;
191 QPixmap *mKeyGoodPix, *mKeyBadPix, *mKeyUnknownPix, *mKeyValidPix;
192 KeyIDList mKeyIds;
193 unsigned int mAllowedKeys;
194 QTimer* mCheckSelectionTimer;
195 QTimer* mStartSearchTimer;
196 QString mSearchText;
197 QTreeWidgetItem* mCurrentContextMenuItem;
199 static const int sCheckSelectionDelay;
201 #endif
203 class KPGP_EXPORT KeyRequester: public QWidget
205 Q_OBJECT
207 public:
208 explicit KeyRequester( QWidget * parent=0, bool multipleKeys=false,
209 unsigned int allowedKeys=AllKeys, const char * name=0 );
210 virtual ~KeyRequester();
212 KeyIDList keyIDs() const;
213 void setKeyIDs( const KeyIDList & keyIDs );
215 QPushButton * eraseButton() const { return mEraseButton; }
216 QPushButton * dialogButton() const { return mDialogButton; }
218 void setDialogCaption( const QString & caption );
219 void setDialogMessage( const QString & message );
221 bool isMultipleKeysEnabled() const;
222 void setMultipleKeysEnabled( bool enable );
224 int allowedKeys() const;
225 void setAllowedKeys( int allowed );
227 protected:
228 /** Reimplement this to return a list of selected keys. */
229 virtual KeyIDList keyRequestHook( Module * pgp ) const = 0;
231 protected:
232 QLabel * mLabel;
233 QPushButton * mEraseButton;
234 QPushButton * mDialogButton;
235 QString mDialogCaption, mDialogMessage;
236 bool mMulti;
237 int mAllowedKeys;
238 KeyIDList mKeys;
240 protected Q_SLOTS:
241 void slotDialogButtonClicked();
242 void slotEraseButtonClicked();
244 Q_SIGNALS:
245 void changed();
247 private:
248 class Private;
249 Private * d;
250 protected:
251 virtual void virtual_hook( int, void* );
255 class KPGP_EXPORT PublicKeyRequester : public KeyRequester {
256 Q_OBJECT
257 public:
258 explicit PublicKeyRequester( QWidget * parent=0, bool multipleKeys=false,
259 unsigned int allowedKeys=PublicKeys,
260 const char * name=0 );
261 virtual ~PublicKeyRequester();
263 protected:
264 KeyIDList keyRequestHook( Module * pgp ) const;
266 private:
267 typedef KeyRequester base;
268 class Private;
269 Private * d;
270 protected:
271 virtual void virtual_hook( int, void* );
275 class KPGP_EXPORT SecretKeyRequester : public KeyRequester {
276 Q_OBJECT
277 public:
278 explicit SecretKeyRequester( QWidget * parent=0, bool multipleKeys=false,
279 unsigned int allowedKeys=SecretKeys,
280 const char * name=0 );
281 virtual ~SecretKeyRequester();
283 protected:
284 KeyIDList keyRequestHook( Module * pgp ) const;
286 private:
287 typedef KeyRequester base;
288 class Private;
289 Private * d;
290 protected:
291 virtual void virtual_hook( int, void* );
295 // -------------------------------------------------------------------------
296 class KPGP_EXPORT KeyApprovalDialog: public KDialog
298 Q_OBJECT
300 public:
301 KeyApprovalDialog( const QStringList&,
302 const QVector<KeyIDList>&,
303 const int allowedKeys,
304 QWidget *parent = 0 );
305 virtual ~KeyApprovalDialog() {}
307 QVector<KeyIDList> keys() const { return mKeys; }
309 bool preferencesChanged() const { return mPrefsChanged; }
311 protected Q_SLOTS:
312 void slotPrefsChanged( int ) { mPrefsChanged = true; }
313 void slotChangeEncryptionKey( int );
314 virtual void slotOk();
315 virtual void slotCancel();
317 private:
318 QVector<KeyIDList> mKeys;
319 int mAllowedKeys;
320 int mEncryptToSelf;
321 bool mPrefsChanged;
322 QVector<QLabel*> mAddressLabels;
323 QVector<QLabel*> mKeyIdsLabels;
324 //QPtrVector<QListBox> mKeyIdListBoxes;
325 QVector<QComboBox*> mEncrPrefCombos;
329 // -------------------------------------------------------------------------
330 class KPGP_EXPORT CipherTextDialog: public KDialog
332 Q_OBJECT
334 public:
335 explicit CipherTextDialog( const QByteArray &text,
336 const QByteArray &charset=0,
337 QWidget *parent=0 );
338 virtual ~CipherTextDialog() {}
340 private:
341 void setMinimumSize();
342 QTextEdit *mEditBox;
345 } // namespace Kpgp
347 #endif