certmanager/lib

keyrequester.h

00001 /*  -*- c++ -*-
00002     keyrequester.h
00003 
00004     This file is part of libkleopatra, the KDE keymanagement library
00005     Copyright (c) 2004 Klarälvdalens Datakonsult AB
00006 
00007     Libkleopatra is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License as
00009     published by the Free Software Foundation; either version 2 of the
00010     License, or (at your option) any later version.
00011 
00012     Libkleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the TQt library by Trolltech AS, Norway (or with modified versions
00024     of TQt that use the same license as TQt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     TQt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 
00032 
00033     Based on kpgpui.h
00034     Copyright (C) 2001,2002 the KPGP authors
00035     See file libkdenetwork/AUTHORS.kpgp for details
00036 
00037     This file is part of KPGP, the KDE PGP/GnuPG support library.
00038 
00039     KPGP is free software; you can redistribute it and/or modify
00040     it under the terms of the GNU General Public License as published by
00041     the Free Software Foundation; either version 2 of the License, or
00042     (at your option) any later version.
00043 
00044     You should have received a copy of the GNU General Public License
00045     along with this program; if not, write to the Free Software Foundation,
00046     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00047  */
00048 
00049 #ifndef __KLEO_UI_KEYREQUESTER_H__
00050 #define __KLEO_UI_KEYREQUESTER_H__
00051 
00052 #include <tqwidget.h>
00053 #include <kleo/cryptobackend.h>
00054 
00055 #include <vector>
00056 #include <kdepimmacros.h>
00057 
00058 namespace Kleo {
00059   class KeyListView;
00060   class KeyListViewItem;
00061 }
00062 
00063 namespace GpgME {
00064   class Key;
00065   class KeyListResult;
00066 }
00067 
00068 class TQStringList;
00069 class TQString;
00070 class TQPushButton;
00071 class TQLabel;
00072 
00073 namespace Kleo {
00074 
00076   class KDE_EXPORT KeyRequester : public TQWidget {
00077     Q_OBJECT
00078   TQ_OBJECT
00079   public:
00080     KeyRequester( unsigned int allowedKeys, bool multipleKeys=false,
00081           TQWidget * parent=0, const char * name=0 );
00082     // Constructor for TQt Designer
00083     KeyRequester( TQWidget * parent=0, const char * name=0 );
00084     ~KeyRequester();
00085 
00086     const GpgME::Key & key() const;
00091     void setKey( const GpgME::Key & key );
00092 
00093     const std::vector<GpgME::Key> & keys() const;
00097     void setKeys( const std::vector<GpgME::Key> & keys );
00098 
00099     TQString fingerprint() const;
00103     void setFingerprint( const TQString & fingerprint );
00104 
00105     TQStringList fingerprints() const;
00109     void setFingerprints( const TQStringList & fingerprints );
00110 
00111 
00112     TQPushButton * eraseButton();
00113     TQPushButton * dialogButton();
00114 
00115     void setDialogCaption( const TQString & caption );
00116     void setDialogMessage( const TQString & message );
00117 
00118     bool isMultipleKeysEnabled() const;
00119     void setMultipleKeysEnabled( bool enable );
00120 
00121     unsigned int allowedKeys() const;
00122     void setAllowedKeys( unsigned int allowed );
00123 
00124     void setInitialQuery( const TQString & s ) { mInitialQuery = s; }
00125     const TQString & initialQuery() const { return mInitialQuery; }
00126 
00127   signals:
00128     void changed();
00129 
00130   private:
00131     void init();
00132     void startKeyListJob( const TQStringList & fingerprints );
00133     void updateKeys();
00134 
00135   private slots:
00136     void slotNextKey( const GpgME::Key & key );
00137     void slotKeyListResult( const GpgME::KeyListResult & result );
00138     void slotDialogButtonClicked();
00139     void slotEraseButtonClicked();
00140 
00141   private:
00142     const CryptoBackend::Protocol * mOpenPGPBackend;
00143     const CryptoBackend::Protocol * mSMIMEBackend;
00144     TQLabel * mLabel;
00145     TQPushButton * mEraseButton;
00146     TQPushButton * mDialogButton;
00147     TQString mDialogCaption, mDialogMessage, mInitialQuery;
00148     bool mMulti;
00149     unsigned int mKeyUsage;
00150     int mJobs;
00151     std::vector<GpgME::Key> mKeys;
00152     std::vector<GpgME::Key> mTmpKeys;
00153 
00154   private:
00155     class Private;
00156     Private * d;
00157   protected:
00158     virtual void virtual_hook( int, void* );
00159   };
00160 
00161 
00162   class KDE_EXPORT EncryptionKeyRequester : public KeyRequester {
00163     Q_OBJECT
00164   TQ_OBJECT
00165   public:
00166     enum { OpenPGP = 1, SMIME = 2, AllProtocols = OpenPGP|SMIME };
00167 
00171     EncryptionKeyRequester( bool multipleKeys=false, unsigned int proto=AllProtocols,
00172                 TQWidget * parent=0, const char * name=0,
00173                 bool onlyTrusted=true, bool onlyValid=true );
00177     EncryptionKeyRequester( TQWidget * parent=0, const char * name=0 );
00178     ~EncryptionKeyRequester();
00179 
00180     void setAllowedKeys( unsigned int proto, bool onlyTrusted=true, bool onlyValid=true );
00181 
00182   private:
00183     class Private;
00184     Private * d;
00185   protected:
00186     virtual void virtual_hook( int, void* );
00187   };
00188 
00189 
00190   class KDE_EXPORT SigningKeyRequester : public KeyRequester {
00191     Q_OBJECT
00192   TQ_OBJECT
00193   public:
00194     enum { OpenPGP = 1, SMIME = 2, AllProtocols = OpenPGP|SMIME };
00195 
00204     SigningKeyRequester( bool multipleKeys=false, unsigned int proto=AllProtocols,
00205              TQWidget * parent=0, const char * name=0,
00206              bool onlyTrusted=true, bool onlyValid=true );
00210     SigningKeyRequester( TQWidget * parent=0, const char * name=0 );
00211     ~SigningKeyRequester();
00212 
00213     /*
00214      * Those parameters affect the parameters given to the key selection dialog.
00215      * @param proto the allowed protocols, OpenPGP and/or SMIME
00216      * @param onlyTrusted only show trusted keys
00217      * @param onlyValid only show valid keys
00218      */
00219     void setAllowedKeys( unsigned int proto, bool onlyTrusted=true, bool onlyValid=true );
00220 
00221   private:
00222     class Private;
00223     Private * d;
00224   protected:
00225     virtual void virtual_hook( int, void* );
00226   };
00227 
00228 }
00229 
00230 #endif // __KLEO_UI_KEYREQUESTER_H__