docs update, needs proofreading
[kdepim.git] / libkleo / ui / keylistview.h
blobd3a2d9dbfc62662e52a8d416958fda34084008e6
1 /*
2 keylistview.h
4 This file is part of libkleopatra, the KDE keymanagement library
5 Copyright (c) 2004 Klar�vdalens Datakonsult AB
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.
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.
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
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 Qt library by Trolltech AS, Norway (or with modified versions
24 of Qt that use the same license as Qt), 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 Qt. 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.
33 #ifndef __KLEO_KEYLISTVIEW_H__
34 #define __KLEO_KEYLISTVIEW_H__
36 #include "kleo/kleo_export.h"
38 #include <gpgme++/key.h>
40 #include <k3listview.h>
42 #include <QtGui/QPixmap>
43 #include <QtCore/QByteArray>
44 #include <Qt3Support/Q3PtrList>
46 class QPainter;
47 class QColorGroup;
48 class QFont;
49 class QColor;
50 class QEvent;
52 namespace Kleo {
54 // work around moc parser bug...
55 #define TEMPLATE_TYPENAME(T) template <typename T>
56 TEMPLATE_TYPENAME(T)
57 inline T * lvi_cast( Q3ListViewItem * item ) {
58 return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
59 ? static_cast<T*>( item ) : 0 ;
62 TEMPLATE_TYPENAME(T)
63 inline const T * lvi_cast( const Q3ListViewItem * item ) {
64 return item && (item->rtti() & T::RTTI_MASK) == T::RTTI
65 ? static_cast<const T*>( item ) : 0 ;
67 #undef TEMPLATE_TYPENAME
69 class KeyListView;
71 class KLEO_EXPORT KeyListViewItem : public Q3ListViewItem {
72 public:
73 KeyListViewItem( KeyListView * parent, const GpgME::Key & key );
74 KeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Key & key );
75 KeyListViewItem( KeyListViewItem * parent, const GpgME::Key & key );
76 KeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Key & key );
77 ~KeyListViewItem();
79 void setKey( const GpgME::Key & key );
80 const GpgME::Key & key() const { return mKey; }
82 enum { RTTI_MASK = 0xFFFFFFF0, RTTI = 0x2C1362E0 };
85 // only boring stuff below:
87 virtual QString toolTip( int column ) const;
89 /*! \reimp for covariant return */
90 KeyListView * listView() const;
91 /*! \reimp for covariant return */
92 KeyListViewItem * nextSibling() const;
93 /*! \reimp */
94 int compare( Q3ListViewItem * other, int col, bool ascending ) const;
95 /*! \reimp to allow for key() overload above */
96 QString key( int col, bool ascending ) const { return Q3ListViewItem::key( col, ascending ); }
97 /*! \reimp */
98 int rtti() const { return RTTI; }
99 /*! \reimp */
100 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
101 /*! \reimp */
102 void insertItem( Q3ListViewItem * item );
103 /*! \reimp */
104 void takeItem( Q3ListViewItem * item );
106 private:
107 GpgME::Key mKey;
110 class KLEO_EXPORT SubkeyKeyListViewItem : public KeyListViewItem {
111 public:
112 SubkeyKeyListViewItem( KeyListView * parent, const GpgME::Subkey & subkey );
113 SubkeyKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
114 SubkeyKeyListViewItem( KeyListViewItem * parent, const GpgME::Subkey & subkey );
115 SubkeyKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Subkey & subkey );
117 void setSubkey( const GpgME::Subkey & subkey );
118 const GpgME::Subkey & subkey() const { return mSubkey; }
120 enum { RTTI = KeyListViewItem::RTTI + 1 };
123 // only boring stuff below:
125 /*! \reimp */
126 QString toolTip( int col ) const;
127 /*! \reimp */
128 QString text( int col ) const;
129 /*! \reimp */
130 const QPixmap * pixmap( int col ) const;
131 /*! \reimp */
132 int compare( Q3ListViewItem * other, int col, bool ascending ) const;
133 /*! \reimp */
134 int rtti() const { return RTTI; }
135 /*! \reimp */
136 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
138 private:
139 GpgME::Subkey mSubkey;
142 class KLEO_EXPORT UserIDKeyListViewItem : public KeyListViewItem {
143 public:
144 UserIDKeyListViewItem( KeyListView * parent, const GpgME::UserID & userid );
145 UserIDKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID & userid );
146 UserIDKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID & userid );
147 UserIDKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID & userid );
149 void setUserID( const GpgME::UserID & userid );
150 const GpgME::UserID userID() const { return mUserID; }
152 enum { RTTI = KeyListViewItem::RTTI + 2 };
155 // only boring stuff below:
157 /*! \reimp */
158 QString toolTip( int col ) const;
159 /*! \reimp */
160 QString text( int col ) const;
161 /*! \reimp */
162 const QPixmap * pixmap( int col ) const;
163 /*! \reimp */
164 int compare( Q3ListViewItem * other, int col, bool ascending ) const;
165 /*! \reimp */
166 int rtti() const { return RTTI; }
167 /*! \reimp */
168 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
170 private:
171 GpgME::UserID mUserID;
174 class KLEO_EXPORT SignatureKeyListViewItem : public KeyListViewItem {
175 public:
176 SignatureKeyListViewItem( KeyListView * parent, const GpgME::UserID::Signature & sig );
177 SignatureKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
178 SignatureKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID::Signature & sig );
179 SignatureKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID::Signature & sig );
181 void setSignature( const GpgME::UserID::Signature & sig );
182 const GpgME::UserID::Signature & signature() const { return mSignature; }
184 enum { RTTI = KeyListViewItem::RTTI + 3 };
187 // only boring stuff below:
189 /*! \reimp */
190 QString toolTip( int col ) const;
191 /*! \reimp */
192 QString text( int col ) const;
193 /*! \reimp */
194 const QPixmap * pixmap( int col ) const;
195 /*! \reimp */
196 int compare( Q3ListViewItem * other, int col, bool ascending ) const;
197 /*! \reimp */
198 int rtti() const { return RTTI; }
199 /*! \reimp */
200 void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment );
202 private:
203 GpgME::UserID::Signature mSignature;
207 class KLEO_EXPORT KeyListView : public K3ListView {
208 Q_OBJECT
209 friend class KeyListViewItem;
210 public:
212 class KLEO_EXPORT ColumnStrategy {
213 public:
214 virtual ~ColumnStrategy();
215 virtual QString title( int column ) const = 0;
216 virtual int width( int column, const QFontMetrics & fm ) const;
217 virtual Q3ListView::WidthMode widthMode( int ) const { return Q3ListView::Manual; }
219 virtual QString text( const GpgME::Key & key, int column ) const = 0;
220 virtual QString toolTip( const GpgME::Key & key, int column ) const;
221 virtual const QPixmap * pixmap( const GpgME::Key &, int ) const { return 0; }
222 virtual int compare( const GpgME::Key & key1, const GpgME::Key & key2, const int column ) const;
224 virtual QString subkeyText( const GpgME::Subkey &, int ) const { return QString(); }
225 virtual QString subkeyToolTip( const GpgME::Subkey & subkey, int column ) const;
226 virtual const QPixmap * subkeyPixmap( const GpgME::Subkey &, int ) const { return 0; }
227 virtual int subkeyCompare( const GpgME::Subkey & subkey1, const GpgME::Subkey & subkey2, const int column ) const;
229 virtual QString userIDText( const GpgME::UserID &, int ) const { return QString(); }
230 virtual QString userIDToolTip( const GpgME::UserID & userID, int column ) const;
231 virtual const QPixmap * userIDPixmap( const GpgME::UserID &, int ) const { return 0; }
232 virtual int userIDCompare( const GpgME::UserID & userID1, const GpgME::UserID & userID2, const int column ) const;
234 virtual QString signatureText( const GpgME::UserID::Signature &, int ) const { return QString(); }
235 virtual QString signatureToolTip( const GpgME::UserID::Signature & sig, int column ) const;
236 virtual const QPixmap * signaturePixmap( const GpgME::UserID::Signature &, int ) const { return 0; }
237 virtual int signatureCompare( const GpgME::UserID::Signature & sig1, const GpgME::UserID::Signature & sig2, const int column ) const;
240 class KLEO_EXPORT DisplayStrategy {
241 public:
242 virtual ~DisplayStrategy();
243 //font
244 virtual QFont keyFont( const GpgME::Key &, const QFont & ) const;
245 virtual QFont subkeyFont( const GpgME::Subkey &, const QFont & ) const;
246 virtual QFont useridFont( const GpgME::UserID &, const QFont & ) const;
247 virtual QFont signatureFont( const GpgME::UserID::Signature & , const QFont & ) const;
248 //foreground
249 virtual QColor keyForeground( const GpgME::Key & , const QColor & ) const;
250 virtual QColor subkeyForeground( const GpgME::Subkey &, const QColor & ) const;
251 virtual QColor useridForeground( const GpgME::UserID &, const QColor & ) const;
252 virtual QColor signatureForeground( const GpgME::UserID::Signature &, const QColor & ) const;
253 //background
254 virtual QColor keyBackground( const GpgME::Key &, const QColor & ) const;
255 virtual QColor subkeyBackground( const GpgME::Subkey &, const QColor & ) const;
256 virtual QColor useridBackground( const GpgME::UserID &, const QColor & ) const;
257 virtual QColor signatureBackground( const GpgME::UserID::Signature &, const QColor & ) const;
260 KeyListView( const ColumnStrategy * strategy,
261 const DisplayStrategy * display=0,
262 QWidget * parent=0, Qt::WFlags f=0 );
264 ~KeyListView();
266 const ColumnStrategy * columnStrategy() const { return mColumnStrategy; }
267 const DisplayStrategy * displayStrategy() const { return mDisplayStrategy; }
269 bool hierarchical() const { return mHierarchical; }
270 virtual void setHierarchical( bool hier );
272 void flushKeys() { slotUpdateTimeout(); }
274 bool hasSelection() const;
276 KeyListViewItem * itemByFingerprint( const QByteArray & ) const;
278 Q_SIGNALS:
279 void doubleClicked( Kleo::KeyListViewItem*, const QPoint&, int );
280 void returnPressed( Kleo::KeyListViewItem* );
281 void selectionChanged( Kleo::KeyListViewItem* );
282 void contextMenu( Kleo::KeyListViewItem*, const QPoint& );
284 public Q_SLOTS:
285 virtual void slotAddKey( const GpgME::Key & key );
286 virtual void slotRefreshKey( const GpgME::Key & key );
289 // Only boring stuff below:
291 private Q_SLOTS:
292 void slotEmitDoubleClicked( Q3ListViewItem*, const QPoint&, int );
293 void slotEmitReturnPressed( Q3ListViewItem* );
294 void slotEmitSelectionChanged( Q3ListViewItem* );
295 void slotEmitContextMenu( K3ListView*, Q3ListViewItem*, const QPoint& );
296 void slotUpdateTimeout();
298 public:
299 /*! \reimp for covariant return */
300 KeyListViewItem * selectedItem() const;
301 /*! \reimp */
302 Q3PtrList<KeyListViewItem> selectedItems() const;
303 /*! \reimp for covariant return */
304 KeyListViewItem * firstChild() const;
305 /*! \reimp */
306 void clear();
307 /*! \reimp */
308 void insertItem( Q3ListViewItem * );
309 /*! \reimp */
310 void takeItem( Q3ListViewItem * );
312 protected:
313 virtual bool event(QEvent *e );
314 private:
315 bool showToolTip( const QPoint& p );
316 void doHierarchicalInsert( const GpgME::Key & );
317 void gatherScattered();
318 void scatterGathered( Q3ListViewItem * );
319 void registerItem( KeyListViewItem * );
320 void deregisterItem( const KeyListViewItem * );
322 private:
323 const ColumnStrategy * mColumnStrategy;
324 const DisplayStrategy * mDisplayStrategy;
325 bool mHierarchical;
327 class Private;
328 Private *const d;
332 #endif // __KLEO_KEYLISTVIEW_H__