certmanager/lib Library API Documentation

keylistview.h

00001 /*
00002     keylistview.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), 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     Qt.  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 #ifndef __KLEO_KEYLISTVIEW_H__
00034 #define __KLEO_KEYLISTVIEW_H__
00035 
00036 #include <klistview.h>
00037 
00038 #include <gpgmepp/key.h>
00039 
00040 class QPainter;
00041 class QColorGroup;
00042 class QFont;
00043 class QColor;
00044 
00045 namespace Kleo {
00046 
00047   // work around moc parser bug...
00048 #define TEMPLATE_TYPENAME(T) template <typename T>
00049   TEMPLATE_TYPENAME(T)
00050   inline T * lvi_cast( QListViewItem * item ) {
00051     return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
00052       ? static_cast<T*>( item ) : 0 ;
00053   }
00054 
00055   TEMPLATE_TYPENAME(T)
00056   inline const T * lvi_cast( const QListViewItem * item ) {
00057     return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
00058       ? static_cast<const T*>( item ) : 0 ;
00059   }
00060 #undef TEMPLATE_TYPENAME
00061 
00062   class KeyListView;
00063 
00064   class KeyListViewItem : public QListViewItem {
00065   public:
00066     KeyListViewItem( KeyListView * parent, const GpgME::Key & key );
00067     KeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Key & key );
00068     KeyListViewItem( KeyListViewItem * parent, const GpgME::Key & key );
00069     KeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Key & key );
00070     ~KeyListViewItem();
00071 
00072     void setKey( const GpgME::Key & key );
00073     const GpgME::Key & key() const { return mKey; }
00074 
00075     enum { RTTI_MASK = 0xFFFFFFF0, RTTI = 0x2C1362E0 };
00076 
00077     //
00078     // only boring stuff below:
00079     //
00080     virtual QString toolTip( int column ) const;
00081 
00083     KeyListView * listView() const;
00085     KeyListViewItem * nextSibling() const;
00087     int compare( QListViewItem * other, int col, bool ascending ) const;
00089     QString key( int col, bool ascending ) const { return QListViewItem::key( col, ascending ); }
00091     int rtti() const { return RTTI; }
00093     void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00095     void insertItem( QListViewItem * item );
00097     void takeItem( QListViewItem * item );
00098 
00099   private:
00100     GpgME::Key mKey;
00101   };
00102 
00103   class SubkeyKeyListViewItem : public KeyListViewItem {
00104   public:
00105     SubkeyKeyListViewItem( KeyListView * parent, const GpgME::Subkey & subkey );
00106     SubkeyKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
00107     SubkeyKeyListViewItem( KeyListViewItem * parent, const GpgME::Subkey & subkey );
00108     SubkeyKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
00109 
00110     void setSubkey( const GpgME::Subkey & subkey );
00111     const GpgME::Subkey & subkey() const { return mSubkey; }
00112 
00113     enum { RTTI = KeyListViewItem::RTTI + 1 };
00114 
00115     //
00116     // only boring stuff below:
00117     //
00119     QString toolTip( int col ) const;
00121     QString text( int col ) const;
00123     const QPixmap * pixmap( int col ) const;
00125     int compare( QListViewItem * other, int col, bool ascending ) const;
00127     int rtti() const { return RTTI; }
00129     void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00130 
00131   private:
00132     GpgME::Subkey mSubkey;
00133   };
00134 
00135   class UserIDKeyListViewItem : public KeyListViewItem {
00136   public:
00137     UserIDKeyListViewItem( KeyListView * parent, const GpgME::UserID & userid );
00138     UserIDKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID & userid );
00139     UserIDKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID & userid );
00140     UserIDKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID & userid );
00141 
00142     void setUserID( const GpgME::UserID & userid );
00143     const GpgME::UserID userID() const { return mUserID; }
00144 
00145     enum { RTTI = KeyListViewItem::RTTI + 2 };
00146 
00147     //
00148     // only boring stuff below:
00149     //
00151     QString toolTip( int col ) const;
00153     QString text( int col ) const;
00155     const QPixmap * pixmap( int col ) const;
00157     int compare( QListViewItem * other, int col, bool ascending ) const;
00159     int rtti() const { return RTTI; }
00161     void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00162 
00163   private:
00164     GpgME::UserID mUserID;
00165   };
00166 
00167   class SignatureKeyListViewItem : public KeyListViewItem {
00168   public:
00169     SignatureKeyListViewItem( KeyListView * parent, const GpgME::UserID::Signature & sig );
00170     SignatureKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
00171     SignatureKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID::Signature & sig );
00172     SignatureKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
00173 
00174     void setSignature( const GpgME::UserID::Signature & sig );
00175     const GpgME::UserID::Signature & signature() const { return mSignature; }
00176 
00177     enum { RTTI = KeyListViewItem::RTTI + 3 };
00178 
00179     //
00180     // only boring stuff below:
00181     //
00183     QString toolTip( int col ) const;
00185     QString text( int col ) const;
00187     const QPixmap * pixmap( int col ) const;
00189     int compare( QListViewItem * other, int col, bool ascending ) const;
00191     int rtti() const { return RTTI; }
00193     void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00194 
00195   private:
00196     GpgME::UserID::Signature mSignature;
00197   };
00198 
00199 
00200   class KeyListView : public KListView {
00201     Q_OBJECT
00202     friend class KeyListViewItem;
00203   public:
00204     class ColumnStrategy;
00205     class DisplayStrategy;
00206 
00207 
00208     KeyListView( const ColumnStrategy * strategy,
00209          const DisplayStrategy * display=0,
00210          QWidget * parent=0, const char * name=0, WFlags f=0 );
00211 
00212     ~KeyListView();
00213 
00214     const ColumnStrategy * columnStrategy() const { return mColumnStrategy; }
00215     const DisplayStrategy * displayStrategy() const { return mDisplayStrategy; }
00216 
00217     bool hierarchical() const { return mHierarchical; }
00218     virtual void setHierarchical( bool hier );
00219 
00220     void flushKeys() { slotUpdateTimeout(); }
00221 
00222     bool hasSelection() const;
00223 
00224     KeyListViewItem * itemByFingerprint( const QCString & ) const;
00225 
00226   signals:
00227     void doubleClicked( Kleo::KeyListViewItem*, const QPoint&, int );
00228     void returnPressed( Kleo::KeyListViewItem* );
00229     void selectionChanged( Kleo::KeyListViewItem* );
00230     void contextMenu( Kleo::KeyListViewItem*, const QPoint& );
00231 
00232   public slots:
00233     virtual void slotAddKey( const GpgME::Key & key );
00234     virtual void slotRefreshKey( const GpgME::Key & key );
00235 
00236     //
00237     // Only boring stuff below:
00238     //
00239   private slots:
00240     void slotEmitDoubleClicked( QListViewItem*, const QPoint&, int );
00241     void slotEmitReturnPressed( QListViewItem* );
00242     void slotEmitSelectionChanged( QListViewItem* );
00243     void slotEmitContextMenu( KListView*, QListViewItem*, const QPoint& );
00244     void slotUpdateTimeout();
00245 
00246   public:
00248     KeyListViewItem * selectedItem() const;
00250     QPtrList<KeyListViewItem> selectedItems() const;
00252     KeyListViewItem * firstChild() const;
00254     void clear();
00256     void insertItem( QListViewItem * );
00258     void takeItem( QListViewItem * );
00259 
00260   private:
00261     void doHierarchicalInsert( const GpgME::Key & );
00262     void gatherScattered();
00263     void scatterGathered( QListViewItem * );
00264     void registerItem( KeyListViewItem * );
00265     void deregisterItem( const KeyListViewItem * );
00266 
00267   private:
00268     const ColumnStrategy * mColumnStrategy;
00269     const DisplayStrategy * mDisplayStrategy;
00270     bool mHierarchical;
00271 
00272     class Private;
00273     Private * d;
00274   };
00275 
00276   class KeyListView::ColumnStrategy {
00277   public:
00278     virtual ~ColumnStrategy();
00279     virtual QString title( int column ) const = 0;
00280     virtual int width( int column, const QFontMetrics & fm ) const;
00281     virtual QListView::WidthMode widthMode( int ) const { return QListView::Manual; }
00282 
00283     virtual QString text( const GpgME::Key & key, int column ) const = 0;
00284     virtual QString toolTip( const GpgME::Key & key, int column ) const;
00285     virtual const QPixmap * pixmap( const GpgME::Key &, int ) const { return 0; }
00286     virtual int compare( const GpgME::Key & key1, const GpgME::Key & key2, const int column ) const;
00287 
00288     virtual QString subkeyText( const GpgME::Subkey &, int ) const { return QString::null; }
00289     virtual QString subkeyToolTip( const GpgME::Subkey & subkey, int column ) const;
00290     virtual const QPixmap * subkeyPixmap( const GpgME::Subkey &, int ) const { return 0; }
00291     virtual int subkeyCompare( const GpgME::Subkey & subkey1, const GpgME::Subkey & subkey2, const int column ) const;
00292 
00293     virtual QString userIDText( const GpgME::UserID &, int ) const { return QString::null; }
00294     virtual QString userIDToolTip( const GpgME::UserID & userID, int column ) const;
00295     virtual const QPixmap * userIDPixmap( const GpgME::UserID &, int ) const { return 0; }
00296     virtual int userIDCompare( const GpgME::UserID & userID1, const GpgME::UserID & userID2, const int column ) const;
00297 
00298     virtual QString signatureText( const GpgME::UserID::Signature &, int ) const { return QString::null; }
00299     virtual QString signatureToolTip( const GpgME::UserID::Signature & sig, int column ) const;
00300     virtual const QPixmap * signaturePixmap( const GpgME::UserID::Signature &, int ) const { return 0; }
00301     virtual int signatureCompare( const GpgME::UserID::Signature & sig1, const GpgME::UserID::Signature & sig2, const int column ) const;
00302   };
00303 
00304   class KeyListView::DisplayStrategy {
00305   public:
00306     virtual ~DisplayStrategy();
00307     //font
00308     virtual QFont keyFont( const GpgME::Key &, const QFont & ) const;
00309     virtual QFont subkeyFont( const GpgME::Subkey &, const QFont & ) const;
00310     virtual QFont useridFont( const GpgME::UserID &, const QFont &  ) const;
00311     virtual QFont signatureFont( const GpgME::UserID::Signature & , const QFont & ) const;
00312     //foreground
00313     virtual QColor keyForeground( const GpgME::Key & , const QColor & ) const;
00314     virtual QColor subkeyForeground( const GpgME::Subkey &, const QColor &  ) const;
00315     virtual QColor useridForeground( const GpgME::UserID &, const QColor &  ) const;
00316     virtual QColor signatureForeground( const GpgME::UserID::Signature &, const QColor &  ) const;
00317     //background
00318     virtual QColor keyBackground( const GpgME::Key &, const QColor &  ) const;
00319     virtual QColor subkeyBackground( const GpgME::Subkey &, const QColor &  ) const;
00320     virtual QColor useridBackground( const GpgME::UserID &, const QColor & ) const;
00321     virtual QColor signatureBackground( const GpgME::UserID::Signature &, const QColor &  ) const;
00322   };
00323 
00324 }
00325 
00326 #endif // __KLEO_KEYLISTVIEW_H__
KDE Logo
This file is part of the documentation for certmanager/lib Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:40:26 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003