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
22 #include "libkpgp_export.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>
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
47 class QTreeWidgetItem
;
49 class QTreeWidget
; // needed by KeySelectionDialog
50 class KPasswordEdit
; // needed by PassphraseDialog
55 class Key
; // needed by KeySelectionDialog
56 class KeyIDList
; // needed by KeySelectionDialog
58 /** the passphrase dialog */
59 class KPGP_EXPORT PassphraseDialog
: public KPasswordDialog
64 explicit PassphraseDialog( QWidget
*parent
=0,
65 const QString
&caption
=QString(),
66 const QString
&keyID
=QString());
67 virtual ~PassphraseDialog();
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
77 class KPGP_EXPORT Config
: public QWidget
82 explicit Config( QWidget
*parent
= 0, bool encrypt
= true );
85 virtual void setValues();
86 virtual void applySettings();
87 QGroupBox
* optionsGroupBox() { return mpOptionsGroupBox
; }
95 QCheckBox
*showCipherText
;
96 QCheckBox
*showKeyApprovalDlg
;
98 QGroupBox
* mpOptionsGroupBox
;
102 // -------------------------------------------------------------------------
103 #ifndef QT_NO_TREEWIDGET
104 #define KeySelectionDialogSuper KDialog
105 class KPGP_EXPORT KeySelectionDialog
: public KeySelectionDialogSuper
109 enum TrustCheckMode
{ NoExpensiveTrustCheck
,
110 AllowExpensiveTrustCheck
,
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,
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
135 virtual bool rememberSelection() const
137 return mRememberCB
->isChecked();
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();
154 void filterByKeyID( const QString
& keyID
);
155 void filterByKeyIDOrUID( const QString
& keyID
);
156 void filterByUID( const QString
& uid
);
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
177 -1 = key must not be chosen,
178 0 = not enough information to decide whether the give key is allowed
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;
189 QTreeWidget
*mListView
;
190 QCheckBox
*mRememberCB
;
191 QPixmap
*mKeyGoodPix
, *mKeyBadPix
, *mKeyUnknownPix
, *mKeyValidPix
;
193 unsigned int mAllowedKeys
;
194 QTimer
* mCheckSelectionTimer
;
195 QTimer
* mStartSearchTimer
;
197 QTreeWidgetItem
* mCurrentContextMenuItem
;
199 static const int sCheckSelectionDelay
;
203 class KPGP_EXPORT KeyRequester
: public QWidget
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
);
228 /** Reimplement this to return a list of selected keys. */
229 virtual KeyIDList
keyRequestHook( Module
* pgp
) const = 0;
233 QPushButton
* mEraseButton
;
234 QPushButton
* mDialogButton
;
235 QString mDialogCaption
, mDialogMessage
;
241 void slotDialogButtonClicked();
242 void slotEraseButtonClicked();
251 virtual void virtual_hook( int, void* );
255 class KPGP_EXPORT PublicKeyRequester
: public KeyRequester
{
258 explicit PublicKeyRequester( QWidget
* parent
=0, bool multipleKeys
=false,
259 unsigned int allowedKeys
=PublicKeys
,
260 const char * name
=0 );
261 virtual ~PublicKeyRequester();
264 KeyIDList
keyRequestHook( Module
* pgp
) const;
267 typedef KeyRequester base
;
271 virtual void virtual_hook( int, void* );
275 class KPGP_EXPORT SecretKeyRequester
: public KeyRequester
{
278 explicit SecretKeyRequester( QWidget
* parent
=0, bool multipleKeys
=false,
279 unsigned int allowedKeys
=SecretKeys
,
280 const char * name
=0 );
281 virtual ~SecretKeyRequester();
284 KeyIDList
keyRequestHook( Module
* pgp
) const;
287 typedef KeyRequester base
;
291 virtual void virtual_hook( int, void* );
295 // -------------------------------------------------------------------------
296 class KPGP_EXPORT KeyApprovalDialog
: public KDialog
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
; }
312 void slotPrefsChanged( int ) { mPrefsChanged
= true; }
313 void slotChangeEncryptionKey( int );
314 virtual void slotOk();
315 virtual void slotCancel();
318 QVector
<KeyIDList
> mKeys
;
322 QVector
<QLabel
*> mAddressLabels
;
323 QVector
<QLabel
*> mKeyIdsLabels
;
324 //QPtrVector<QListBox> mKeyIdListBoxes;
325 QVector
<QComboBox
*> mEncrPrefCombos
;
329 // -------------------------------------------------------------------------
330 class KPGP_EXPORT CipherTextDialog
: public KDialog
335 explicit CipherTextDialog( const QByteArray
&text
,
336 const QByteArray
&charset
=0,
338 virtual ~CipherTextDialog() {}
341 void setMinimumSize();