00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __KLEO_KEYLISTVIEW_H__
00034 #define __KLEO_KEYLISTVIEW_H__
00035
00036 #include <klistview.h>
00037
00038 #include <gpgmepp/key.h>
00039 #include <kdepimmacros.h>
00040
00041 class QPainter;
00042 class QColorGroup;
00043 class QFont;
00044 class QColor;
00045
00046 namespace Kleo {
00047
00048
00049 #define TEMPLATE_TYPENAME(T) template <typename T>
00050 TEMPLATE_TYPENAME(T)
00051 inline T * lvi_cast( QListViewItem * item ) {
00052 return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
00053 ? static_cast<T*>( item ) : 0 ;
00054 }
00055
00056 TEMPLATE_TYPENAME(T)
00057 inline const T * lvi_cast( const QListViewItem * item ) {
00058 return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
00059 ? static_cast<const T*>( item ) : 0 ;
00060 }
00061 #undef TEMPLATE_TYPENAME
00062
00063 class KeyListView;
00064
00065 class KDE_EXPORT KeyListViewItem : public QListViewItem {
00066 public:
00067 KeyListViewItem( KeyListView * parent, const GpgME::Key & key );
00068 KeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Key & key );
00069 KeyListViewItem( KeyListViewItem * parent, const GpgME::Key & key );
00070 KeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Key & key );
00071 ~KeyListViewItem();
00072
00073 void setKey( const GpgME::Key & key );
00074 const GpgME::Key & key() const { return mKey; }
00075
00076 enum { RTTI_MASK = 0xFFFFFFF0, RTTI = 0x2C1362E0 };
00077
00078
00079
00080
00081 virtual QString toolTip( int column ) const;
00082
00084 KeyListView * listView() const;
00086 KeyListViewItem * nextSibling() const;
00088 int compare( QListViewItem * other, int col, bool ascending ) const;
00090 QString key( int col, bool ascending ) const { return QListViewItem::key( col, ascending ); }
00092 int rtti() const { return RTTI; }
00094 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00096 void insertItem( QListViewItem * item );
00098 void takeItem( QListViewItem * item );
00099
00100 private:
00101 GpgME::Key mKey;
00102 };
00103
00104 class KDE_EXPORT SubkeyKeyListViewItem : public KeyListViewItem {
00105 public:
00106 SubkeyKeyListViewItem( KeyListView * parent, const GpgME::Subkey & subkey );
00107 SubkeyKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
00108 SubkeyKeyListViewItem( KeyListViewItem * parent, const GpgME::Subkey & subkey );
00109 SubkeyKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
00110
00111 void setSubkey( const GpgME::Subkey & subkey );
00112 const GpgME::Subkey & subkey() const { return mSubkey; }
00113
00114 enum { RTTI = KeyListViewItem::RTTI + 1 };
00115
00116
00117
00118
00120 QString toolTip( int col ) const;
00122 QString text( int col ) const;
00124 const QPixmap * pixmap( int col ) const;
00126 int compare( QListViewItem * other, int col, bool ascending ) const;
00128 int rtti() const { return RTTI; }
00130 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00131
00132 private:
00133 GpgME::Subkey mSubkey;
00134 };
00135
00136 class KDE_EXPORT UserIDKeyListViewItem : public KeyListViewItem {
00137 public:
00138 UserIDKeyListViewItem( KeyListView * parent, const GpgME::UserID & userid );
00139 UserIDKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID & userid );
00140 UserIDKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID & userid );
00141 UserIDKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID & userid );
00142
00143 void setUserID( const GpgME::UserID & userid );
00144 const GpgME::UserID userID() const { return mUserID; }
00145
00146 enum { RTTI = KeyListViewItem::RTTI + 2 };
00147
00148
00149
00150
00152 QString toolTip( int col ) const;
00154 QString text( int col ) const;
00156 const QPixmap * pixmap( int col ) const;
00158 int compare( QListViewItem * other, int col, bool ascending ) const;
00160 int rtti() const { return RTTI; }
00162 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00163
00164 private:
00165 GpgME::UserID mUserID;
00166 };
00167
00168 class KDE_EXPORT SignatureKeyListViewItem : public KeyListViewItem {
00169 public:
00170 SignatureKeyListViewItem( KeyListView * parent, const GpgME::UserID::Signature & sig );
00171 SignatureKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
00172 SignatureKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID::Signature & sig );
00173 SignatureKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
00174
00175 void setSignature( const GpgME::UserID::Signature & sig );
00176 const GpgME::UserID::Signature & signature() const { return mSignature; }
00177
00178 enum { RTTI = KeyListViewItem::RTTI + 3 };
00179
00180
00181
00182
00184 QString toolTip( int col ) const;
00186 QString text( int col ) const;
00188 const QPixmap * pixmap( int col ) const;
00190 int compare( QListViewItem * other, int col, bool ascending ) const;
00192 int rtti() const { return RTTI; }
00194 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
00195
00196 private:
00197 GpgME::UserID::Signature mSignature;
00198 };
00199
00200
00201 class KDE_EXPORT KeyListView : public KListView {
00202 Q_OBJECT
00203 friend class KeyListViewItem;
00204 public:
00205
00206 class KDE_EXPORT ColumnStrategy {
00207 public:
00208 virtual ~ColumnStrategy();
00209 virtual QString title( int column ) const = 0;
00210 virtual int width( int column, const QFontMetrics & fm ) const;
00211 virtual QListView::WidthMode widthMode( int ) const { return QListView::Manual; }
00212
00213 virtual QString text( const GpgME::Key & key, int column ) const = 0;
00214 virtual QString toolTip( const GpgME::Key & key, int column ) const;
00215 virtual const QPixmap * pixmap( const GpgME::Key &, int ) const { return 0; }
00216 virtual int compare( const GpgME::Key & key1, const GpgME::Key & key2, const int column ) const;
00217
00218 virtual QString subkeyText( const GpgME::Subkey &, int ) const { return QString::null; }
00219 virtual QString subkeyToolTip( const GpgME::Subkey & subkey, int column ) const;
00220 virtual const QPixmap * subkeyPixmap( const GpgME::Subkey &, int ) const { return 0; }
00221 virtual int subkeyCompare( const GpgME::Subkey & subkey1, const GpgME::Subkey & subkey2, const int column ) const;
00222
00223 virtual QString userIDText( const GpgME::UserID &, int ) const { return QString::null; }
00224 virtual QString userIDToolTip( const GpgME::UserID & userID, int column ) const;
00225 virtual const QPixmap * userIDPixmap( const GpgME::UserID &, int ) const { return 0; }
00226 virtual int userIDCompare( const GpgME::UserID & userID1, const GpgME::UserID & userID2, const int column ) const;
00227
00228 virtual QString signatureText( const GpgME::UserID::Signature &, int ) const { return QString::null; }
00229 virtual QString signatureToolTip( const GpgME::UserID::Signature & sig, int column ) const;
00230 virtual const QPixmap * signaturePixmap( const GpgME::UserID::Signature &, int ) const { return 0; }
00231 virtual int signatureCompare( const GpgME::UserID::Signature & sig1, const GpgME::UserID::Signature & sig2, const int column ) const;
00232 };
00233
00234 class KDE_EXPORT DisplayStrategy {
00235 public:
00236 virtual ~DisplayStrategy();
00237
00238 virtual QFont keyFont( const GpgME::Key &, const QFont & ) const;
00239 virtual QFont subkeyFont( const GpgME::Subkey &, const QFont & ) const;
00240 virtual QFont useridFont( const GpgME::UserID &, const QFont & ) const;
00241 virtual QFont signatureFont( const GpgME::UserID::Signature & , const QFont & ) const;
00242
00243 virtual QColor keyForeground( const GpgME::Key & , const QColor & ) const;
00244 virtual QColor subkeyForeground( const GpgME::Subkey &, const QColor & ) const;
00245 virtual QColor useridForeground( const GpgME::UserID &, const QColor & ) const;
00246 virtual QColor signatureForeground( const GpgME::UserID::Signature &, const QColor & ) const;
00247
00248 virtual QColor keyBackground( const GpgME::Key &, const QColor & ) const;
00249 virtual QColor subkeyBackground( const GpgME::Subkey &, const QColor & ) const;
00250 virtual QColor useridBackground( const GpgME::UserID &, const QColor & ) const;
00251 virtual QColor signatureBackground( const GpgME::UserID::Signature &, const QColor & ) const;
00252 };
00253
00254 KeyListView( const ColumnStrategy * strategy,
00255 const DisplayStrategy * display=0,
00256 QWidget * parent=0, const char * name=0, WFlags f=0 );
00257
00258 ~KeyListView();
00259
00260 const ColumnStrategy * columnStrategy() const { return mColumnStrategy; }
00261 const DisplayStrategy * displayStrategy() const { return mDisplayStrategy; }
00262
00263 bool hierarchical() const { return mHierarchical; }
00264 virtual void setHierarchical( bool hier );
00265
00266 void flushKeys() { slotUpdateTimeout(); }
00267
00268 bool hasSelection() const;
00269
00270 KeyListViewItem * itemByFingerprint( const QCString & ) const;
00271
00272 signals:
00273 void doubleClicked( Kleo::KeyListViewItem*, const QPoint&, int );
00274 void returnPressed( Kleo::KeyListViewItem* );
00275 void selectionChanged( Kleo::KeyListViewItem* );
00276 void contextMenu( Kleo::KeyListViewItem*, const QPoint& );
00277
00278 public slots:
00279 virtual void slotAddKey( const GpgME::Key & key );
00280 virtual void slotRefreshKey( const GpgME::Key & key );
00281
00282
00283
00284
00285 private slots:
00286 void slotEmitDoubleClicked( QListViewItem*, const QPoint&, int );
00287 void slotEmitReturnPressed( QListViewItem* );
00288 void slotEmitSelectionChanged( QListViewItem* );
00289 void slotEmitContextMenu( KListView*, QListViewItem*, const QPoint& );
00290 void slotUpdateTimeout();
00291
00292 public:
00294 KeyListViewItem * selectedItem() const;
00296 QPtrList<KeyListViewItem> selectedItems() const;
00298 KeyListViewItem * firstChild() const;
00300 void clear();
00302 void insertItem( QListViewItem * );
00304 void takeItem( QListViewItem * );
00305
00306 private:
00307 void doHierarchicalInsert( const GpgME::Key & );
00308 void gatherScattered();
00309 void scatterGathered( QListViewItem * );
00310 void registerItem( KeyListViewItem * );
00311 void deregisterItem( const KeyListViewItem * );
00312
00313 private:
00314 const ColumnStrategy * mColumnStrategy;
00315 const DisplayStrategy * mDisplayStrategy;
00316 bool mHierarchical;
00317
00318 class Private;
00319 Private * d;
00320 };
00321 }
00322
00323 #endif // __KLEO_KEYLISTVIEW_H__