certmanager/lib

keylistview.h
1 /*
2  keylistview.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the TQt library by Trolltech AS, Norway (or with modified versions
24  of TQt that use the same license as TQt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  TQt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #ifndef __KLEO_KEYLISTVIEW_H__
34 #define __KLEO_KEYLISTVIEW_H__
35 
36 #include <tdelistview.h>
37 
38 #include <gpgmepp/key.h>
39 #include <tdemacros.h>
40 
41 class TQPainter;
42 class TQColorGroup;
43 class TQFont;
44 class TQColor;
45 
46 namespace Kleo {
47 
48  // work around moc parser bug...
49 #define TEMPLATE_TYPENAME(T) template <typename T>
50  TEMPLATE_TYPENAME(T)
51  inline T * lvi_cast( TQListViewItem * item ) {
52  return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
53  ? static_cast<T*>( item ) : 0 ;
54  }
55 
56  TEMPLATE_TYPENAME(T)
57  inline const T * lvi_cast( const TQListViewItem * item ) {
58  return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
59  ? static_cast<const T*>( item ) : 0 ;
60  }
61 #undef TEMPLATE_TYPENAME
62 
63  class KeyListView;
64 
65  class TDE_EXPORT KeyListViewItem : public TQListViewItem {
66  public:
67  KeyListViewItem( KeyListView * parent, const GpgME::Key & key );
68  KeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Key & key );
69  KeyListViewItem( KeyListViewItem * parent, const GpgME::Key & key );
70  KeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Key & key );
71  ~KeyListViewItem();
72 
73  void setKey( const GpgME::Key & key );
74  const GpgME::Key & key() const { return mKey; }
75 
76  enum { RTTI_MASK = 0xFFFFFFF0, RTTI = 0x2C1362E0 };
77 
78  //
79  // only boring stuff below:
80  //
81  virtual TQString toolTip( int column ) const;
82 
84  KeyListView * listView() const;
86  KeyListViewItem * nextSibling() const;
88  int compare( TQListViewItem * other, int col, bool ascending ) const;
90  TQString key( int col, bool ascending ) const { return TQListViewItem::key( col, ascending ); }
92  int rtti() const { return RTTI; }
94  void paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int alignment );
96  void insertItem( TQListViewItem * item );
98  void takeItem( TQListViewItem * item );
99 
100  private:
101  GpgME::Key mKey;
102  };
103 
104  class TDE_EXPORT SubkeyKeyListViewItem : public KeyListViewItem {
105  public:
106  SubkeyKeyListViewItem( KeyListView * parent, const GpgME::Subkey & subkey );
107  SubkeyKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
108  SubkeyKeyListViewItem( KeyListViewItem * parent, const GpgME::Subkey & subkey );
109  SubkeyKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
110 
111  void setSubkey( const GpgME::Subkey & subkey );
112  const GpgME::Subkey & subkey() const { return mSubkey; }
113 
114  enum { RTTI = KeyListViewItem::RTTI + 1 };
115 
116  //
117  // only boring stuff below:
118  //
120  TQString toolTip( int col ) const;
122  TQString text( int col ) const;
124  const TQPixmap * pixmap( int col ) const;
126  int compare( TQListViewItem * other, int col, bool ascending ) const;
128  int rtti() const { return RTTI; }
130  void paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int alignment );
131 
132  private:
133  GpgME::Subkey mSubkey;
134  };
135 
136  class TDE_EXPORT UserIDKeyListViewItem : public KeyListViewItem {
137  public:
138  UserIDKeyListViewItem( KeyListView * parent, const GpgME::UserID & userid );
139  UserIDKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID & userid );
140  UserIDKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID & userid );
141  UserIDKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID & userid );
142 
143  void setUserID( const GpgME::UserID & userid );
144  const GpgME::UserID userID() const { return mUserID; }
145 
146  enum { RTTI = KeyListViewItem::RTTI + 2 };
147 
148  //
149  // only boring stuff below:
150  //
152  TQString toolTip( int col ) const;
154  TQString text( int col ) const;
156  const TQPixmap * pixmap( int col ) const;
158  int compare( TQListViewItem * other, int col, bool ascending ) const;
160  int rtti() const { return RTTI; }
162  void paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int alignment );
163 
164  private:
165  GpgME::UserID mUserID;
166  };
167 
168  class TDE_EXPORT SignatureKeyListViewItem : public KeyListViewItem {
169  public:
170  SignatureKeyListViewItem( KeyListView * parent, const GpgME::UserID::Signature & sig );
171  SignatureKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
172  SignatureKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID::Signature & sig );
173  SignatureKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
174 
175  void setSignature( const GpgME::UserID::Signature & sig );
176  const GpgME::UserID::Signature & signature() const { return mSignature; }
177 
178  enum { RTTI = KeyListViewItem::RTTI + 3 };
179 
180  //
181  // only boring stuff below:
182  //
184  TQString toolTip( int col ) const;
186  TQString text( int col ) const;
188  const TQPixmap * pixmap( int col ) const;
190  int compare( TQListViewItem * other, int col, bool ascending ) const;
192  int rtti() const { return RTTI; }
194  void paintCell( TQPainter * p, const TQColorGroup & cg, int column, int width, int alignment );
195 
196  private:
197  GpgME::UserID::Signature mSignature;
198  };
199 
200 
201  class TDE_EXPORT KeyListView : public TDEListView {
202  TQ_OBJECT
203 
204  friend class KeyListViewItem;
205  public:
206 
207  class TDE_EXPORT ColumnStrategy {
208  public:
209  virtual ~ColumnStrategy();
210  virtual TQString title( int column ) const = 0;
211  virtual int width( int column, const TQFontMetrics & fm ) const;
212  virtual TQListView::WidthMode widthMode( int ) const { return TQListView::Manual; }
213 
214  virtual TQString text( const GpgME::Key & key, int column ) const = 0;
215  virtual TQString toolTip( const GpgME::Key & key, int column ) const;
216  virtual const TQPixmap * pixmap( const GpgME::Key &, int ) const { return 0; }
217  virtual int compare( const GpgME::Key & key1, const GpgME::Key & key2, const int column ) const;
218 
219  virtual TQString subkeyText( const GpgME::Subkey &, int ) const { return TQString(); }
220  virtual TQString subkeyToolTip( const GpgME::Subkey & subkey, int column ) const;
221  virtual const TQPixmap * subkeyPixmap( const GpgME::Subkey &, int ) const { return 0; }
222  virtual int subkeyCompare( const GpgME::Subkey & subkey1, const GpgME::Subkey & subkey2, const int column ) const;
223 
224  virtual TQString userIDText( const GpgME::UserID &, int ) const { return TQString(); }
225  virtual TQString userIDToolTip( const GpgME::UserID & userID, int column ) const;
226  virtual const TQPixmap * userIDPixmap( const GpgME::UserID &, int ) const { return 0; }
227  virtual int userIDCompare( const GpgME::UserID & userID1, const GpgME::UserID & userID2, const int column ) const;
228 
229  virtual TQString signatureText( const GpgME::UserID::Signature &, int ) const { return TQString(); }
230  virtual TQString signatureToolTip( const GpgME::UserID::Signature & sig, int column ) const;
231  virtual const TQPixmap * signaturePixmap( const GpgME::UserID::Signature &, int ) const { return 0; }
232  virtual int signatureCompare( const GpgME::UserID::Signature & sig1, const GpgME::UserID::Signature & sig2, const int column ) const;
233  };
234 
235  class TDE_EXPORT DisplayStrategy {
236  public:
237  virtual ~DisplayStrategy();
238  //font
239  virtual TQFont keyFont( const GpgME::Key &, const TQFont & ) const;
240  virtual TQFont subkeyFont( const GpgME::Subkey &, const TQFont & ) const;
241  virtual TQFont useridFont( const GpgME::UserID &, const TQFont & ) const;
242  virtual TQFont signatureFont( const GpgME::UserID::Signature & , const TQFont & ) const;
243  //foreground
244  virtual TQColor keyForeground( const GpgME::Key & , const TQColor & ) const;
245  virtual TQColor subkeyForeground( const GpgME::Subkey &, const TQColor & ) const;
246  virtual TQColor useridForeground( const GpgME::UserID &, const TQColor & ) const;
247  virtual TQColor signatureForeground( const GpgME::UserID::Signature &, const TQColor & ) const;
248  //background
249  virtual TQColor keyBackground( const GpgME::Key &, const TQColor & ) const;
250  virtual TQColor subkeyBackground( const GpgME::Subkey &, const TQColor & ) const;
251  virtual TQColor useridBackground( const GpgME::UserID &, const TQColor & ) const;
252  virtual TQColor signatureBackground( const GpgME::UserID::Signature &, const TQColor & ) const;
253  };
254 
255  KeyListView( const ColumnStrategy * strategy,
256  const DisplayStrategy * display=0,
257  TQWidget * parent=0, const char * name=0, WFlags f=0 );
258 
259  ~KeyListView();
260 
261  const ColumnStrategy * columnStrategy() const { return mColumnStrategy; }
262  const DisplayStrategy * displayStrategy() const { return mDisplayStrategy; }
263 
264  bool hierarchical() const { return mHierarchical; }
265  virtual void setHierarchical( bool hier );
266 
267  void flushKeys() { slotUpdateTimeout(); }
268 
269  bool hasSelection() const;
270 
271  KeyListViewItem * itemByFingerprint( const TQCString & ) const;
272 
273  signals:
274  void doubleClicked( Kleo::KeyListViewItem*, const TQPoint&, int );
275  void returnPressed( Kleo::KeyListViewItem* );
276  void selectionChanged( Kleo::KeyListViewItem* );
277  void contextMenu( Kleo::KeyListViewItem*, const TQPoint& );
278 
279  public slots:
280  virtual void slotAddKey( const GpgME::Key & key );
281  virtual void slotRefreshKey( const GpgME::Key & key );
282 
283  //
284  // Only boring stuff below:
285  //
286  private slots:
287  void slotEmitDoubleClicked( TQListViewItem*, const TQPoint&, int );
288  void slotEmitReturnPressed( TQListViewItem* );
289  void slotEmitSelectionChanged( TQListViewItem* );
290  void slotEmitContextMenu( TDEListView*, TQListViewItem*, const TQPoint& );
291  void slotUpdateTimeout();
292 
293  public:
295  KeyListViewItem * selectedItem() const;
297  TQPtrList<KeyListViewItem> selectedItems() const;
299  KeyListViewItem * firstChild() const;
301  void clear();
303  void insertItem( TQListViewItem * );
305  void takeItem( TQListViewItem * );
306 
307  private:
308  void doHierarchicalInsert( const GpgME::Key & );
309  void gatherScattered();
310  void scatterGathered( TQListViewItem * );
311  void registerItem( KeyListViewItem * );
312  void deregisterItem( const KeyListViewItem * );
313 
314  private:
315  const ColumnStrategy * mColumnStrategy;
316  const DisplayStrategy * mDisplayStrategy;
317  bool mHierarchical;
318 
319  class Private;
320  Private * d;
321  };
322 }
323 
324 #endif // __KLEO_KEYLISTVIEW_H__