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 <tqwidget.h>      // base class of Config
00024 #include <tqcheckbox.h>    // used in inlined methods
00025 #include <kdebug.h>       // used in inlined methods
00026 #include <tqcstring.h>     // used in return-by-value
00027 #include <tqstring.h>      // is a member in KeyRequester
00028 #include <tqvaluevector.h> // used in KeyApprovalDialog
00029 
00030 #include "kpgp.h"
00031 
00032 #include <tdepimmacros.h>
00033 
00034 class TQString;
00035 class TQRegExp;
00036 class TQCString;
00037 class TQCheckBox;            // needed by Config, KeySelectionDialog
00038 class TQMultiLineEdit;       // needed by CipherTextDialog
00039 class TQComboBox;            // needed by Config
00040 class TQPixmap;              // needed by KeySelectionDialog
00041 class TQPushButton;          // needed by KeyRequester
00042 class TQTimer;               // needed by KeySelectionDialog
00043 
00044 class TDEListView;            // 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 
00060   public:
00061     PassphraseDialog( TQWidget *parent=0, const TQString &caption=TQString(),
00062                       bool modal=true, const TQString &keyID=TQString());
00063     virtual ~PassphraseDialog();
00064 
00065     const char * passphrase();
00066 
00067   private:
00068     KPasswordEdit *lineedit;
00069 };
00070 
00071 
00072 // -------------------------------------------------------------------------
00076 class KDE_EXPORT Config : public TQWidget
00077 {
00078   Q_OBJECT
00079   
00080 
00081   public:
00082     Config(TQWidget *parent = 0, const char *name = 0, bool encrypt =true);
00083     virtual ~Config();
00084 
00085     virtual void setValues();
00086     virtual void applySettings();
00087     TQGroupBox* optionsGroupBox() { return mpOptionsGroupBox; };
00088   signals:
00089     void changed();
00090 
00091   protected:
00092     Module *pgp;
00093     TQCheckBox *storePass;
00094     TQCheckBox *encToSelf;
00095     TQCheckBox *showCipherText;
00096     TQCheckBox *showKeyApprovalDlg;
00097     TQComboBox *toolCombo;
00098     TQGroupBox* mpOptionsGroupBox;
00099 };
00100 
00101 
00102 // -------------------------------------------------------------------------
00103 #define KeySelectionDialogSuper KDialogBase
00104 class KDE_EXPORT KeySelectionDialog: public KeySelectionDialogSuper
00105 {
00106   Q_OBJECT
00107   
00108 
00109   enum TrustCheckMode { NoExpensiveTrustCheck,
00110                         AllowExpensiveTrustCheck,
00111                         ForceTrustCheck
00112                       };
00113 
00114   public:
00117     KeySelectionDialog( const KeyList& keyList,
00118                         const TQString& title,
00119                         const TQString& text = TQString(),
00120                         const KeyIDList& keyIds = KeyIDList(),
00121                         const bool rememberChoice = false,
00122                         const unsigned int allowedKeys = AllKeys,
00123                         const bool extendedSelection = false,
00124                         TQWidget *parent=0, const char *name=0,
00125                         bool modal=true );
00126     virtual ~KeySelectionDialog();
00127 
00130     virtual KeyID key() const;
00131  
00133     virtual KeyIDList keys() const
00134       { return mKeyIds; };
00135 
00136     virtual bool rememberSelection() const
00137       { if( mRememberCB )
00138           return mRememberCB->isChecked();
00139         else
00140           return false;
00141       };
00142 
00143   protected slots:
00144     virtual void slotRereadKeys();
00145     virtual void slotSelectionChanged( TQListViewItem* );
00146     virtual void slotSelectionChanged();
00147     virtual void slotCheckSelection( TQListViewItem* = 0 );
00148     virtual void slotRMB( TQListViewItem*, const TQPoint&, int );
00149     virtual void slotRecheckKey();
00150     virtual void slotOk();
00151     virtual void slotCancel();
00152     virtual void slotSearch( const TQString & text );
00153     virtual void slotFilter();
00154 
00155   private:
00156     void filterByKeyID( const TQString & keyID );
00157     void filterByKeyIDOrUID( const TQString & keyID );
00158     void filterByUID( const TQString & uid );
00159     void showAllItems();
00160     bool anyChildMatches( const TQListViewItem * item, TQRegExp & rx ) const;
00161 
00162     void initKeylist( const KeyList& keyList, const KeyIDList& keyIds );
00163 
00164     TQString keyInfo( const Kpgp::Key* ) const;
00165 
00166     TQString beautifyFingerprint( const TQCString& ) const;
00167 
00168     // Returns the key ID of the key the given TQListViewItem belongs to
00169     KeyID getKeyId( const TQListViewItem* ) const;
00170 
00171     // Returns: -1 = unusable, 0 = unknown, 1 = valid, but untrusted, 2 = trusted
00172     int keyValidity( const Kpgp::Key* ) const;
00173 
00174     // Updates the given TQListViewItem with the data of the given key
00175     void updateKeyInfo( const Kpgp::Key*, TQListViewItem* ) const;
00176 
00184     int keyAdmissibility( TQListViewItem*,
00185                           TrustCheckMode = NoExpensiveTrustCheck ) const;
00186 
00187     // Perform expensive trust checks for the given keys
00188     bool checkKeys( const TQValueList<TQListViewItem*>& ) const;
00189 
00190   private:
00191     TDEListView *mListView;
00192     TQCheckBox *mRememberCB;
00193     TQPixmap *mKeyGoodPix, *mKeyBadPix, *mKeyUnknownPix, *mKeyValidPix;
00194     KeyIDList mKeyIds;
00195     unsigned int mAllowedKeys;
00196     TQTimer* mCheckSelectionTimer;
00197     TQTimer* mStartSearchTimer;
00198     TQString mSearchText;
00199     TQListViewItem* mCurrentContextMenuItem;
00200 
00201   static const int sCheckSelectionDelay;
00202 };
00203 
00204 class KDE_EXPORT KeyRequester: public TQWidget
00205 {
00206   Q_OBJECT
00207   
00208 
00209 public:
00210   KeyRequester( TQWidget * parent=0, bool multipleKeys=false,
00211         unsigned int allowedKeys=AllKeys, const char * name=0 );
00212   virtual ~KeyRequester();
00213 
00214   KeyIDList keyIDs() const;
00215   void setKeyIDs( const KeyIDList & keyIDs );
00216 
00217   TQPushButton * eraseButton() const { return mEraseButton; }
00218   TQPushButton * dialogButton() const { return mDialogButton; }
00219 
00220   void setDialogCaption( const TQString & caption );
00221   void setDialogMessage( const TQString & message );
00222 
00223   bool isMultipleKeysEnabled() const;
00224   void setMultipleKeysEnabled( bool enable );
00225 
00226   int allowedKeys() const;
00227   void setAllowedKeys( int allowed );
00228 
00229 protected:
00231   virtual KeyIDList keyRequestHook( Module * pgp ) const = 0;
00232 
00233 protected:
00234   TQLabel * mLabel;
00235   TQPushButton * mEraseButton;
00236   TQPushButton * mDialogButton;
00237   TQString mDialogCaption, mDialogMessage;
00238   bool mMulti;
00239   int mAllowedKeys;
00240   KeyIDList mKeys;
00241 
00242 protected slots:
00243   void slotDialogButtonClicked();
00244   void slotEraseButtonClicked();
00245 
00246 signals:
00247   void changed();
00248 
00249 private:
00250   class Private;
00251   Private * d;
00252 protected:
00253   virtual void virtual_hook( int, void* );
00254 };
00255 
00256 
00257 class KDE_EXPORT PublicKeyRequester : public KeyRequester {
00258   Q_OBJECT
00259   
00260 public:
00261   PublicKeyRequester( TQWidget * parent=0, bool multipleKeys=false,
00262               unsigned int allowedKeys=PublicKeys, const char * name=0 );
00263   virtual ~PublicKeyRequester();
00264 
00265 protected:
00266   KeyIDList keyRequestHook( Module * pgp ) const;
00267 
00268 private:
00269   typedef KeyRequester base;
00270   class Private;
00271   Private * d;
00272 protected:
00273   virtual void virtual_hook( int, void* );
00274 };
00275 
00276 
00277 class KDE_EXPORT SecretKeyRequester : public KeyRequester {
00278   Q_OBJECT
00279   
00280 public:
00281   SecretKeyRequester( TQWidget * parent=0, bool multipleKeys=false,
00282               unsigned int allowedKeys=SecretKeys, const char * name=0 );
00283   virtual ~SecretKeyRequester();
00284 
00285 protected:
00286   KeyIDList keyRequestHook( Module * pgp ) const;
00287 
00288 private:
00289   typedef KeyRequester base;
00290   class Private;
00291   Private * d;
00292 protected:
00293   virtual void virtual_hook( int, void* );
00294 };
00295 
00296 
00297 // -------------------------------------------------------------------------
00298 class KDE_EXPORT KeyApprovalDialog: public KDialogBase
00299 {
00300   Q_OBJECT
00301   
00302 
00303   public:
00304     KeyApprovalDialog( const TQStringList&,
00305                        const TQValueVector<KeyIDList>&,
00306                        const int allowedKeys,
00307                        TQWidget *parent = 0, const char *name = 0,
00308                        bool modal = true );
00309     virtual ~KeyApprovalDialog() {};
00310 
00311     TQValueVector<KeyIDList> keys() const { return mKeys; };
00312 
00313     bool preferencesChanged() const { return mPrefsChanged; }
00314 
00315   protected slots:
00316     void slotPrefsChanged( int ) { mPrefsChanged = true; };
00317     void slotChangeEncryptionKey( int );
00318     virtual void slotOk();
00319     virtual void slotCancel();
00320 
00321   private:
00322     TQValueVector<KeyIDList> mKeys;
00323     int mAllowedKeys;
00324     int mEncryptToSelf;
00325     bool mPrefsChanged;
00326     TQPtrVector<TQLabel> mAddressLabels;
00327     TQPtrVector<TQLabel> mKeyIdsLabels;
00328     //TQPtrVector<TQListBox> mKeyIdListBoxes;
00329     TQPtrVector<TQComboBox> mEncrPrefCombos;
00330 };
00331 
00332 
00333 // -------------------------------------------------------------------------
00334 class KDE_EXPORT CipherTextDialog: public KDialogBase
00335 {
00336   Q_OBJECT
00337   
00338 
00339   public:
00340     CipherTextDialog( const TQCString & text, const TQCString & charset=0,
00341                       TQWidget *parent=0, const char *name=0, bool modal=true );
00342     virtual ~CipherTextDialog() {};
00343 
00344   private:
00345     void setMinimumSize();
00346     TQMultiLineEdit *mEditBox;
00347 };
00348 
00349 } // namespace Kpgp
00350 
00351 #endif