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 TQPainter;
00042 class TQColorGroup;
00043 class TQFont;
00044 class TQColor;
00045
00046 namespace Kleo {
00047
00048
00049 #define TEMPLATE_TYPENAME(T) template <typename T>
00050 TEMPLATE_TYPENAME(T)
00051 inline T * lvi_cast( TQListViewItem * 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 TQListViewItem * 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 TQListViewItem {
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 TQString toolTip( int column ) const;
00082
00084 KeyListView * listView() const;
00086 KeyListViewItem * nextSibling() const;
00088 int compare( TQListViewItem * other, int col, bool ascending ) const;
00090 TQString key( int col, bool ascending ) const { return TQListViewItem::key( col, ascending ); }
00092 int rtti() const { return RTTI; }
00094 void paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int alignment );
00096 void insertItem( TQListViewItem * item );
00098 void takeItem( TQListViewItem * 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 TQString toolTip( int col ) const;
00122 TQString text( int col ) const;
00124 const TQPixmap * pixmap( int col ) const;
00126 int compare( TQListViewItem * other, int col, bool ascending ) const;
00128 int rtti() const { return RTTI; }
00130 void paintCell( TQPainter * p, const TQColorGroup & 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 TQString toolTip( int col ) const;
00154 TQString text( int col ) const;
00156 const TQPixmap * pixmap( int col ) const;
00158 int compare( TQListViewItem * other, int col, bool ascending ) const;
00160 int rtti() const { return RTTI; }
00162 void paintCell( TQPainter * p, const TQColorGroup & 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 TQString toolTip( int col ) const;
00186 TQString text( int col ) const;
00188 const TQPixmap * pixmap( int col ) const;
00190 int compare( TQListViewItem * other, int col, bool ascending ) const;
00192 int rtti() const { return RTTI; }
00194 void paintCell( TQPainter * p, const TQColorGroup & 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 TQ_OBJECT
00204 friend class KeyListViewItem;
00205 public:
00206
00207 class KDE_EXPORT ColumnStrategy {
00208 public:
00209 virtual ~ColumnStrategy();
00210 virtual TQString title( int column ) const = 0;
00211 virtual int width( int column, const TQFontMetrics & fm ) const;
00212 virtual TQListView::WidthMode widthMode( int ) const { return TQListView::Manual; }
00213
00214 virtual TQString text( const GpgME::Key & key, int column ) const = 0;
00215 virtual TQString toolTip( const GpgME::Key & key, int column ) const;
00216 virtual const TQPixmap * pixmap( const GpgME::Key &, int ) const { return 0; }
00217 virtual int compare( const GpgME::Key & key1, const GpgME::Key & key2, const int column ) const;
00218
00219 virtual TQString subkeyText( const GpgME::Subkey &, int ) const { return TQString(); }
00220 virtual TQString subkeyToolTip( const GpgME::Subkey & subkey, int column ) const;
00221 virtual const TQPixmap * subkeyPixmap( const GpgME::Subkey &, int ) const { return 0; }
00222 virtual int subkeyCompare( const GpgME::Subkey & subkey1, const GpgME::Subkey & subkey2, const int column ) const;
00223
00224 virtual TQString userIDText( const GpgME::UserID &, int ) const { return TQString(); }
00225 virtual TQString userIDToolTip( const GpgME::UserID & userID, int column ) const;
00226 virtual const TQPixmap * userIDPixmap( const GpgME::UserID &, int ) const { return 0; }
00227 virtual int userIDCompare( const GpgME::UserID & userID1, const GpgME::UserID & userID2, const int column ) const;
00228
00229 virtual TQString signatureText( const GpgME::UserID::Signature &, int ) const { return TQString(); }
00230 virtual TQString signatureToolTip( const GpgME::UserID::Signature & sig, int column ) const;
00231 virtual const TQPixmap * signaturePixmap( const GpgME::UserID::Signature &, int ) const { return 0; }
00232 virtual int signatureCompare( const GpgME::UserID::Signature & sig1, const GpgME::UserID::Signature & sig2, const int column ) const;
00233 };
00234
00235 class KDE_EXPORT DisplayStrategy {
00236 public:
00237 virtual ~DisplayStrategy();
00238
00239 virtual TQFont keyFont( const GpgME::Key &, const TQFont & ) const;
00240 virtual TQFont subkeyFont( const GpgME::Subkey &, const TQFont & ) const;
00241 virtual TQFont useridFont( const GpgME::UserID &, const TQFont & ) const;
00242 virtual TQFont signatureFont( const GpgME::UserID::Signature & , const TQFont & ) const;
00243
00244 virtual TQColor keyForeground( const GpgME::Key & , const TQColor & ) const;
00245 virtual TQColor subkeyForeground( const GpgME::Subkey &, const TQColor & ) const;
00246 virtual TQColor useridForeground( const GpgME::UserID &, const TQColor & ) const;
00247 virtual TQColor signatureForeground( const GpgME::UserID::Signature &, const TQColor & ) const;
00248
00249 virtual TQColor keyBackground( const GpgME::Key &, const TQColor & ) const;
00250 virtual TQColor subkeyBackground( const GpgME::Subkey &, const TQColor & ) const;
00251 virtual TQColor useridBackground( const GpgME::UserID &, const TQColor & ) const;
00252 virtual TQColor signatureBackground( const GpgME::UserID::Signature &, const TQColor & ) const;
00253 };
00254
00255 KeyListView( const ColumnStrategy * strategy,
00256 const DisplayStrategy * display=0,
00257 TQWidget * parent=0, const char * name=0, WFlags f=0 );
00258
00259 ~KeyListView();
00260
00261 const ColumnStrategy * columnStrategy() const { return mColumnStrategy; }
00262 const DisplayStrategy * displayStrategy() const { return mDisplayStrategy; }
00263
00264 bool hierarchical() const { return mHierarchical; }
00265 virtual void setHierarchical( bool hier );
00266
00267 void flushKeys() { slotUpdateTimeout(); }
00268
00269 bool hasSelection() const;
00270
00271 KeyListViewItem * itemByFingerprint( const TQCString & ) const;
00272
00273 signals:
00274 void doubleClicked( Kleo::KeyListViewItem*, const TQPoint&, int );
00275 void returnPressed( Kleo::KeyListViewItem* );
00276 void selectionChanged( Kleo::KeyListViewItem* );
00277 void contextMenu( Kleo::KeyListViewItem*, const TQPoint& );
00278
00279 public slots:
00280 virtual void slotAddKey( const GpgME::Key & key );
00281 virtual void slotRefreshKey( const GpgME::Key & key );
00282
00283
00284
00285
00286 private slots:
00287 void slotEmitDoubleClicked( TQListViewItem*, const TQPoint&, int );
00288 void slotEmitReturnPressed( TQListViewItem* );
00289 void slotEmitSelectionChanged( TQListViewItem* );
00290 void slotEmitContextMenu( KListView*, TQListViewItem*, const TQPoint& );
00291 void slotUpdateTimeout();
00292
00293 public:
00295 KeyListViewItem * selectedItem() const;
00297 TQPtrList<KeyListViewItem> selectedItems() const;
00299 KeyListViewItem * firstChild() const;
00301 void clear();
00303 void insertItem( TQListViewItem * );
00305 void takeItem( TQListViewItem * );
00306
00307 private:
00308 void doHierarchicalInsert( const GpgME::Key & );
00309 void gatherScattered();
00310 void scatterGathered( TQListViewItem * );
00311 void registerItem( KeyListViewItem * );
00312 void deregisterItem( const KeyListViewItem * );
00313
00314 private:
00315 const ColumnStrategy * mColumnStrategy;
00316 const DisplayStrategy * mDisplayStrategy;
00317 bool mHierarchical;
00318
00319 class Private;
00320 Private * d;
00321 };
00322 }
00323
00324 #endif // __KLEO_KEYLISTVIEW_H__