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 friend class KeyListViewItem;
00204 public:
00205
00206 class KDE_EXPORT ColumnStrategy {
00207 public:
00208 virtual ~ColumnStrategy();
00209 virtual TQString title( int column ) const = 0;
00210 virtual int width( int column, const TQFontMetrics & fm ) const;
00211 virtual TQListView::WidthMode widthMode( int ) const { return TQListView::Manual; }
00212
00213 virtual TQString text( const GpgME::Key & key, int column ) const = 0;
00214 virtual TQString toolTip( const GpgME::Key & key, int column ) const;
00215 virtual const TQPixmap * 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 TQString subkeyText( const GpgME::Subkey &, int ) const { return TQString::null; }
00219 virtual TQString subkeyToolTip( const GpgME::Subkey & subkey, int column ) const;
00220 virtual const TQPixmap * 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 TQString userIDText( const GpgME::UserID &, int ) const { return TQString::null; }
00224 virtual TQString userIDToolTip( const GpgME::UserID & userID, int column ) const;
00225 virtual const TQPixmap * 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 TQString signatureText( const GpgME::UserID::Signature &, int ) const { return TQString::null; }
00229 virtual TQString signatureToolTip( const GpgME::UserID::Signature & sig, int column ) const;
00230 virtual const TQPixmap * 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 TQFont keyFont( const GpgME::Key &, const TQFont & ) const;
00239 virtual TQFont subkeyFont( const GpgME::Subkey &, const TQFont & ) const;
00240 virtual TQFont useridFont( const GpgME::UserID &, const TQFont & ) const;
00241 virtual TQFont signatureFont( const GpgME::UserID::Signature & , const TQFont & ) const;
00242
00243 virtual TQColor keyForeground( const GpgME::Key & , const TQColor & ) const;
00244 virtual TQColor subkeyForeground( const GpgME::Subkey &, const TQColor & ) const;
00245 virtual TQColor useridForeground( const GpgME::UserID &, const TQColor & ) const;
00246 virtual TQColor signatureForeground( const GpgME::UserID::Signature &, const TQColor & ) const;
00247
00248 virtual TQColor keyBackground( const GpgME::Key &, const TQColor & ) const;
00249 virtual TQColor subkeyBackground( const GpgME::Subkey &, const TQColor & ) const;
00250 virtual TQColor useridBackground( const GpgME::UserID &, const TQColor & ) const;
00251 virtual TQColor signatureBackground( const GpgME::UserID::Signature &, const TQColor & ) const;
00252 };
00253
00254 KeyListView( const ColumnStrategy * strategy,
00255 const DisplayStrategy * display=0,
00256 TQWidget * 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 TQCString & ) const;
00271
00272 signals:
00273 void doubleClicked( Kleo::KeyListViewItem*, const TQPoint&, int );
00274 void returnPressed( Kleo::KeyListViewItem* );
00275 void selectionChanged( Kleo::KeyListViewItem* );
00276 void contextMenu( Kleo::KeyListViewItem*, const TQPoint& );
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( TQListViewItem*, const TQPoint&, int );
00287 void slotEmitReturnPressed( TQListViewItem* );
00288 void slotEmitSelectionChanged( TQListViewItem* );
00289 void slotEmitContextMenu( KListView*, TQListViewItem*, const TQPoint& );
00290 void slotUpdateTimeout();
00291
00292 public:
00294 KeyListViewItem * selectedItem() const;
00296 TQPtrList<KeyListViewItem> selectedItems() const;
00298 KeyListViewItem * firstChild() const;
00300 void clear();
00302 void insertItem( TQListViewItem * );
00304 void takeItem( TQListViewItem * );
00305
00306 private:
00307 void doHierarchicalInsert( const GpgME::Key & );
00308 void gatherScattered();
00309 void scatterGathered( TQListViewItem * );
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__