libkpgp

kpgpui.h

00001 /*  -*- c++ -*-
00002     kpgpui.h
00003 
00004     Copyright (C) 2001,2002 the KPGP authors
00005     See file AUTHORS.kpgp for details
00006 
00007     This file is part of KPGP, the KDE PGP/GnuPG support library.
00008 
00009     KPGP is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software Foundation,
00016     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #ifndef KPGPUI_H
00020 #define KPGPUI_H
00021 
00022 #include <kdialogbase.h>  // base class of all dialogs here
00023 #include <qwidget.h>      // base class of Config
00024 #include <qcheckbox.h>    // used in inlined methods
00025 #include <kdebug.h>       // used in inlined methods
00026 #include <qcstring.h>     // used in return-by-value
00027 #include <qstring.h>      // is a member in KeyRequester
00028 #include <qvaluevector.h> // used in KeyApprovalDialog
00029 
00030 #include "kpgp.h"
00031 
00032 #include <kdepimmacros.h>
00033 
00034 class QString;
00035 class QRegExp;
00036 class QCString;
00037 class QCheckBox;            // needed by Config, KeySelectionDialog
00038 class QMultiLineEdit;       // needed by CipherTextDialog
00039 class QComboBox;            // needed by Config
00040 class QPixmap;              // needed by KeySelectionDialog
00041 class QPushButton;          // needed by KeyRequester
00042 class QTimer;               // needed by KeySelectionDialog
00043 
00044 class KListView;            // needed by KeySelectionDialog
00045 class KPasswordEdit;        // needed by PassphraseDialog
00046 
00047 namespace Kpgp {
00048 
00049 class Module;
00050 class KeyList;              // needed by KeySelectionDialog
00051 class Key;                  // needed by KeySelectionDialog
00052 class KeyIDList;            // needed by KeySelectionDialog
00053 
00055 class KDE_EXPORT PassphraseDialog : public KDialogBase
00056 {
00057   Q_OBJECT
00058 
00059   public:
00060     PassphraseDialog( QWidget *parent=0, const QString &caption=QString::null,
00061                       bool modal=true, const QString &keyID=QString::null);
00062     virtual ~PassphraseDialog();
00063 
00064     const char * passphrase();
00065 
00066   private:
00067     KPasswordEdit *lineedit;
00068 };
00069 
00070 
00071 // -------------------------------------------------------------------------
00075 class KDE_EXPORT Config : public QWidget
00076 {
00077   Q_OBJECT
00078 
00079   public:
00080     Config(QWidget *parent = 0, const char *name = 0, bool encrypt =true);
00081     virtual ~Config();
00082 
00083     virtual void setValues();
00084     virtual void applySettings();
00085     QGroupBox* optionsGroupBox() { return mpOptionsGroupBox; };
00086   signals:
00087     void changed();
00088 
00089   protected:
00090     Module *pgp;
00091     QCheckBox *storePass;
00092     QCheckBox *encToSelf;
00093     QCheckBox *showCipherText;
00094     QCheckBox *showKeyApprovalDlg;
00095     QComboBox *toolCombo;
00096     QGroupBox* mpOptionsGroupBox;
00097 };
00098 
00099 
00100 // -------------------------------------------------------------------------
00101 #define KeySelectionDialogSuper KDialogBase
00102 class KDE_EXPORT KeySelectionDialog: public KeySelectionDialogSuper
00103 {
00104   Q_OBJECT
00105 
00106   enum TrustCheckMode { NoExpensiveTrustCheck,
00107                         AllowExpensiveTrustCheck,
00108                         ForceTrustCheck
00109                       };
00110 
00111   public:
00114     KeySelectionDialog( const KeyList& keyList,
00115                         const QString& title,
00116                         const QString& text = QString::null,
00117                         const KeyIDList& keyIds = KeyIDList(),
00118                         const bool rememberChoice = false,
00119                         const unsigned int allowedKeys = AllKeys,
00120                         const bool extendedSelection = false,
00121                         QWidget *parent=0, const char *name=0,
00122                         bool modal=true );
00123     virtual ~KeySelectionDialog();
00124 
00127     virtual KeyID key() const;
00128  
00130     virtual KeyIDList keys() const
00131       { return mKeyIds; };
00132 
00133     virtual bool rememberSelection() const
00134       { if( mRememberCB )
00135           return mRememberCB->isChecked();
00136         else
00137           return false;
00138       };
00139 
00140   protected slots:
00141     virtual void slotRereadKeys();
00142     virtual void slotSelectionChanged( QListViewItem* );
00143     virtual void slotSelectionChanged();
00144     virtual void slotCheckSelection( QListViewItem* = 0 );
00145     virtual void slotRMB( QListViewItem*, const QPoint&, int );
00146     virtual void slotRecheckKey();
00147     virtual void slotOk();
00148     virtual void slotCancel();
00149     virtual void slotSearch( const QString & text );
00150     virtual void slotFilter();
00151 
00152   private:
00153     void filterByKeyID( const QString & keyID );
00154     void filterByKeyIDOrUID( const QString & keyID );
00155     void filterByUID( const QString & uid );
00156     void showAllItems();
00157     bool anyChildMatches( const QListViewItem * item, QRegExp & rx ) const;
00158 
00159     void initKeylist( const KeyList& keyList, const KeyIDList& keyIds );
00160 
00161     QString keyInfo( const Kpgp::Key* ) const;
00162 
00163     QString beautifyFingerprint( const QCString& ) const;
00164 
00165     // Returns the key ID of the key the given QListViewItem belongs to
00166     KeyID getKeyId( const QListViewItem* ) const;
00167 
00168     // Returns: -1 = unusable, 0 = unknown, 1 = valid, but untrusted, 2 = trusted
00169     int keyValidity( const Kpgp::Key* ) const;
00170 
00171     // Updates the given QListViewItem with the data of the given key
00172     void updateKeyInfo( const Kpgp::Key*, QListViewItem* ) const;
00173 
00181     int keyAdmissibility( QListViewItem*,
00182                           TrustCheckMode = NoExpensiveTrustCheck ) const;
00183 
00184     // Perform expensive trust checks for the given keys
00185     bool checkKeys( const QValueList<QListViewItem*>& ) const;
00186 
00187   private:
00188     KListView *mListView;
00189     QCheckBox *mRememberCB;
00190     QPixmap *mKeyGoodPix, *mKeyBadPix, *mKeyUnknownPix, *mKeyValidPix;
00191     KeyIDList mKeyIds;
00192     unsigned int mAllowedKeys;
00193     QTimer* mCheckSelectionTimer;
00194     QTimer* mStartSearchTimer;
00195     QString mSearchText;
00196     QListViewItem* mCurrentContextMenuItem;
00197 
00198   static const int sCheckSelectionDelay;
00199 };
00200 
00201 class KDE_EXPORT KeyRequester: public QWidget
00202 {
00203   Q_OBJECT
00204 
00205 public:
00206   KeyRequester( QWidget * parent=0, bool multipleKeys=false,
00207         unsigned int allowedKeys=AllKeys, const char * name=0 );
00208   virtual ~KeyRequester();
00209 
00210   KeyIDList keyIDs() const;
00211   void setKeyIDs( const KeyIDList & keyIDs );
00212 
00213   QPushButton * eraseButton() const { return mEraseButton; }
00214   QPushButton * dialogButton() const { return mDialogButton; }
00215 
00216   void setDialogCaption( const QString & caption );
00217   void setDialogMessage( const QString & message );
00218 
00219   bool isMultipleKeysEnabled() const;
00220   void setMultipleKeysEnabled( bool enable );
00221 
00222   int allowedKeys() const;
00223   void setAllowedKeys( int allowed );
00224 
00225 protected:
00227   virtual KeyIDList keyRequestHook( Module * pgp ) const = 0;
00228 
00229 protected:
00230   QLabel * mLabel;
00231   QPushButton * mEraseButton;
00232   QPushButton * mDialogButton;
00233   QString mDialogCaption, mDialogMessage;
00234   bool mMulti;
00235   int mAllowedKeys;
00236   KeyIDList mKeys;
00237 
00238 protected slots:
00239   void slotDialogButtonClicked();
00240   void slotEraseButtonClicked();
00241 
00242 signals:
00243   void changed();
00244 
00245 private:
00246   class Private;
00247   Private * d;
00248 protected:
00249   virtual void virtual_hook( int, void* );
00250 };
00251 
00252 
00253 class KDE_EXPORT PublicKeyRequester : public KeyRequester {
00254   Q_OBJECT
00255 public:
00256   PublicKeyRequester( QWidget * parent=0, bool multipleKeys=false,
00257               unsigned int allowedKeys=PublicKeys, const char * name=0 );
00258   virtual ~PublicKeyRequester();
00259 
00260 protected:
00261   KeyIDList keyRequestHook( Module * pgp ) const;
00262 
00263 private:
00264   typedef KeyRequester base;
00265   class Private;
00266   Private * d;
00267 protected:
00268   virtual void virtual_hook( int, void* );
00269 };
00270 
00271 
00272 class KDE_EXPORT SecretKeyRequester : public KeyRequester {
00273   Q_OBJECT
00274 public:
00275   SecretKeyRequester( QWidget * parent=0, bool multipleKeys=false,
00276               unsigned int allowedKeys=SecretKeys, const char * name=0 );
00277   virtual ~SecretKeyRequester();
00278 
00279 protected:
00280   KeyIDList keyRequestHook( Module * pgp ) const;
00281 
00282 private:
00283   typedef KeyRequester base;
00284   class Private;
00285   Private * d;
00286 protected:
00287   virtual void virtual_hook( int, void* );
00288 };
00289 
00290 
00291 // -------------------------------------------------------------------------
00292 class KDE_EXPORT KeyApprovalDialog: public KDialogBase
00293 {
00294   Q_OBJECT
00295 
00296   public:
00297     KeyApprovalDialog( const QStringList&,
00298                        const QValueVector<KeyIDList>&,
00299                        const int allowedKeys,
00300                        QWidget *parent = 0, const char *name = 0,
00301                        bool modal = true );
00302     virtual ~KeyApprovalDialog() {};
00303 
00304     QValueVector<KeyIDList> keys() const { return mKeys; };
00305 
00306     bool preferencesChanged() const { return mPrefsChanged; }
00307 
00308   protected slots:
00309     void slotPrefsChanged( int ) { mPrefsChanged = true; };
00310     void slotChangeEncryptionKey( int );
00311     virtual void slotOk();
00312     virtual void slotCancel();
00313 
00314   private:
00315     QValueVector<KeyIDList> mKeys;
00316     int mAllowedKeys;
00317     int mEncryptToSelf;
00318     bool mPrefsChanged;
00319     QPtrVector<QLabel> mAddressLabels;
00320     QPtrVector<QLabel> mKeyIdsLabels;
00321     //QPtrVector<QListBox> mKeyIdListBoxes;
00322     QPtrVector<QComboBox> mEncrPrefCombos;
00323 };
00324 
00325 
00326 // -------------------------------------------------------------------------
00327 class KDE_EXPORT CipherTextDialog: public KDialogBase
00328 {
00329   Q_OBJECT
00330 
00331   public:
00332     CipherTextDialog( const QCString & text, const QCString & charset=0,
00333                       QWidget *parent=0, const char *name=0, bool modal=true );
00334     virtual ~CipherTextDialog() {};
00335 
00336   private:
00337     void setMinimumSize();
00338     QMultiLineEdit *mEditBox;
00339 };
00340 
00341 } // namespace Kpgp
00342 
00343 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys