certmanager/lib

keyselectiondialog.h

00001 /*  -*- c++ -*-
00002     keyselectiondialog.h
00003 
00004     This file is part of libkleopatra, the KDE keymanagement library
00005     Copyright (c) 2004 Klarävdalens Datakonsult AB
00006 
00007     Based on kpgpui.h
00008     Copyright (C) 2001,2002 the KPGP authors
00009     See file libkdenetwork/AUTHORS.kpgp for details
00010 
00011     Libkleopatra is free software; you can redistribute it and/or
00012     modify it under the terms of the GNU General Public License as
00013     published by the Free Software Foundation; either version 2 of the
00014     License, or (at your option) any later version.
00015 
00016     Libkleopatra is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019     General Public License for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with this program; if not, write to the Free Software
00023     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00024 
00025     In addition, as a special exception, the copyright holders give
00026     permission to link the code of this program with any edition of
00027     the TQt library by Trolltech AS, Norway (or with modified versions
00028     of TQt that use the same license as TQt), and distribute linked
00029     combinations including the two.  You must obey the GNU General
00030     Public License in all respects for all of the code used other than
00031     TQt.  If you modify this file, you may extend this exception to
00032     your version of the file, but you are not obligated to do so.  If
00033     you do not wish to do so, delete this exception statement from
00034     your version.
00035 */
00036 
00037 #ifndef __KLEO_UI_KEYSELECTIONDIALOG_H__
00038 #define __KLEO_UI_KEYSELECTIONDIALOG_H__
00039 
00040 #include <kdialogbase.h>
00041 
00042 #include <kleo/cryptobackend.h>
00043 #include <gpgmepp/key.h>
00044 #include <kdepimmacros.h>
00045 #include <vector>
00046 
00047 class TQVBoxLayout;
00048 class TQCheckBox;
00049 class TQPixmap;
00050 class TQTimer;
00051 class TQListViewItem;
00052 class TQRegExp;
00053 class TQPoint;
00054 
00055 namespace Kleo {
00056   class KeyListView;
00057   class KeyListViewItem;
00058 }
00059 
00060 namespace GpgME {
00061   class KeyListResult;
00062 }
00063 
00064 namespace Kleo {
00065 
00066   class KDE_EXPORT KeySelectionDialog : public KDialogBase {
00067     Q_OBJECT
00068   TQ_OBJECT
00069   public:
00070 
00071     enum KeyUsage {
00072       PublicKeys = 1,
00073       SecretKeys = 2,
00074       EncryptionKeys = 4,
00075       SigningKeys = 8,
00076       ValidKeys = 16,
00077       TrustedKeys = 32,
00078       CertificationKeys = 64,
00079       AuthenticationKeys = 128,
00080       OpenPGPKeys = 256,
00081       SMIMEKeys = 512,
00082       AllKeys = PublicKeys | SecretKeys | OpenPGPKeys | SMIMEKeys,
00083       ValidEncryptionKeys = AllKeys | EncryptionKeys | ValidKeys,
00084       ValidTrustedEncryptionKeys = AllKeys | EncryptionKeys | ValidKeys | TrustedKeys
00085     };
00086 
00087     KeySelectionDialog( const TQString & title,
00088                         const TQString & text,
00089             const std::vector<GpgME::Key> & selectedKeys=std::vector<GpgME::Key>(),
00090                         unsigned int keyUsage=AllKeys,
00091                         bool extendedSelection=false,
00092             bool rememberChoice=false,
00093                         TQWidget * parent=0, const char * name=0,
00094                         bool modal=true );
00095     KeySelectionDialog( const TQString & title,
00096                         const TQString & text,
00097                         const TQString & initialPattern,
00098             const std::vector<GpgME::Key> & selectedKeys,
00099                         unsigned int keyUsage=AllKeys,
00100                         bool extendedSelection=false,
00101             bool rememberChoice=false,
00102                         TQWidget * parent=0, const char * name=0,
00103                         bool modal=true );
00104     KeySelectionDialog( const TQString & title,
00105                         const TQString & text,
00106             const TQString & initialPattern,
00107                         unsigned int keyUsage=AllKeys,
00108                         bool extendedSelection=false,
00109             bool rememberChoice=false,
00110                         TQWidget * parent=0, const char * name=0,
00111                         bool modal=true );
00112     ~KeySelectionDialog();
00113 
00116     const GpgME::Key & selectedKey() const;
00117 
00118     TQString fingerprint() const;
00119 
00121     const std::vector<GpgME::Key> & selectedKeys() const { return mSelectedKeys; }
00122 
00124     TQStringList fingerprints() const;
00125 
00127     TQStringList pgpKeyFingerprints() const;
00129     TQStringList smimeFingerprints() const;
00130 
00131     bool rememberSelection() const;
00132   protected slots:
00133     // reimplemented to avoid popping up the help, since we
00134     // override the button
00135     void slotHelp();
00136 
00137     // Could be used by derived classes to insert their own widget
00138     TQVBoxLayout* topLayout() const { return mTopLayout; }
00139 
00140   private slots:
00141     void slotRereadKeys();
00142     void slotStartCertificateManager( const TQString &query = TQString() );
00143     void slotStartSearchForExternalCertificates() {
00144       slotStartCertificateManager( mInitialQuery );
00145     }
00146     void slotKeyListResult( const GpgME::KeyListResult & );
00147     void slotSelectionChanged();
00148     void slotCheckSelection() { slotCheckSelection( 0 ); }
00149     void slotCheckSelection( Kleo::KeyListViewItem * );
00150     void slotRMB( Kleo::KeyListViewItem *, const TQPoint & );
00151     void slotRecheckKey();
00152     void slotTryOk();
00153     void slotOk();
00154     void slotCancel();
00155     void slotSearch( const TQString & text );
00156     void slotSearch();
00157     void slotFilter();
00158 
00159   private:
00160     void filterByKeyID( const TQString & keyID );
00161     void filterByKeyIDOrUID( const TQString & keyID );
00162     void filterByUID( const TQString & uid );
00163     void showAllItems();
00164     bool anyChildMatches( const Kleo::KeyListViewItem * item, TQRegExp & rx ) const;
00165 
00166     void connectSignals();
00167     void disconnectSignals();
00168 
00169     void startKeyListJobForBackend( const Kleo::CryptoBackend::Protocol *, const std::vector<GpgME::Key> &, bool );
00170     void startValidatingKeyListing();
00171 
00172     void init( bool, bool, const TQString &, const TQString & );
00173 
00174   private:
00175     TQVBoxLayout* mTopLayout;
00176     Kleo::KeyListView * mKeyListView;
00177     const Kleo::CryptoBackend::Protocol * mOpenPGPBackend;
00178     const Kleo::CryptoBackend::Protocol * mSMIMEBackend;
00179     TQCheckBox * mRememberCB;
00180     std::vector<GpgME::Key> mSelectedKeys, mKeysToCheck;
00181     unsigned int mKeyUsage;
00182     TQTimer * mCheckSelectionTimer;
00183     TQTimer * mStartSearchTimer;
00184     // cross-eventloop temporaries:
00185     TQString mSearchText;
00186     const TQString mInitialQuery;
00187     Kleo::KeyListViewItem * mCurrentContextMenuItem;
00188     int mTruncated, mListJobCount, mSavedOffsetY;
00189   };
00190 
00191 }
00192 
00193 #endif // __KLEO_UI_KEYSELECTIONDIALOG_H__