certmanager Library API Documentation

keylistview.cpp

00001 /* 00002 keylistview.cpp 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 00031 */ 00032 00033 #ifdef HAVE_CONFIG_H 00034 #include <config.h> 00035 #endif 00036 00037 #include "keylistview.h" 00038 00039 #include <kdebug.h> 00040 00041 #include <qfontmetrics.h> 00042 #include <qtooltip.h> 00043 #include <qrect.h> 00044 #include <qheader.h> 00045 #include <qpoint.h> 00046 #include <qptrlist.h> 00047 #include <qpainter.h> 00048 #include <qfont.h> 00049 #include <qcolor.h> 00050 #include <qtimer.h> 00051 #include <qcstring.h> 00052 00053 #include <gpgmepp/key.h> 00054 00055 #include <vector> 00056 #include <map> 00057 00058 #include <assert.h> 00059 00060 static const int updateDelayMilliSecs = 500; 00061 00062 namespace { 00063 00064 class ItemToolTip : public QToolTip { 00065 public: 00066 ItemToolTip( Kleo::KeyListView * parent ); 00067 protected: 00068 void maybeTip( const QPoint & p ); 00069 private: 00070 Kleo::KeyListView * mKeyListView; 00071 }; 00072 00073 ItemToolTip::ItemToolTip( Kleo::KeyListView * parent ) 00074 : QToolTip( parent->viewport() ), mKeyListView( parent ) {} 00075 00076 void ItemToolTip::maybeTip( const QPoint & p ) { 00077 if ( !mKeyListView ) 00078 return; 00079 00080 const QListViewItem * item = mKeyListView->itemAt( p ); 00081 if ( !item ) 00082 return; 00083 00084 const QRect itemRect = mKeyListView->itemRect( item ); 00085 if ( !itemRect.isValid() ) 00086 return; 00087 00088 const int col = mKeyListView->header()->sectionAt( p.x() ); 00089 if ( col == -1 ) 00090 return; 00091 00092 const QRect headerRect = mKeyListView->header()->sectionRect( col ); 00093 if ( !headerRect.isValid() ) 00094 return; 00095 00096 const QRect cellRect( headerRect.left(), itemRect.top(), 00097 headerRect.width(), itemRect.height() ); 00098 00099 QString tipStr; 00100 if ( ( item->rtti() & Kleo::KeyListViewItem::RTTI_MASK ) == Kleo::KeyListViewItem::RTTI ) 00101 tipStr = static_cast<const Kleo::KeyListViewItem*>( item )->toolTip( col ); 00102 else 00103 tipStr = item->text( col ) ; 00104 00105 if ( !tipStr.isEmpty() ) 00106 tip( cellRect, tipStr ); 00107 } 00108 00109 } // anon namespace 00110 00111 struct Kleo::KeyListView::Private { 00112 Private() : updateTimer( 0 ), itemToolTip( 0 ) {} 00113 00114 std::vector<GpgME::Key> keyBuffer; 00115 QTimer * updateTimer; 00116 QToolTip * itemToolTip; 00117 std::map<QCString,KeyListViewItem*> itemMap; 00118 }; 00119 00120 // a list of signals where we want to replace QListViewItem with 00121 // Kleo:KeyListViewItem: 00122 static const struct { 00123 const char * source; 00124 const char * target; 00125 } signalReplacements[] = { 00126 { SIGNAL(doubleClicked(QListViewItem*,const QPoint&,int)), 00127 SLOT(slotEmitDoubleClicked(QListViewItem*,const QPoint&,int)) }, 00128 { SIGNAL(returnPressed(QListViewItem*)), 00129 SLOT(slotEmitReturnPressed(QListViewItem*)) }, 00130 { SIGNAL(selectionChanged(QListViewItem*)), 00131 SLOT(slotEmitSelectionChanged(QListViewItem*)) }, 00132 { SIGNAL(contextMenu(KListView*, QListViewItem*,const QPoint&)), 00133 SLOT(slotEmitContextMenu(KListView*, QListViewItem*,const QPoint&)) }, 00134 }; 00135 static const int numSignalReplacements = sizeof signalReplacements / sizeof *signalReplacements; 00136 00137 00138 Kleo::KeyListView::KeyListView( const ColumnStrategy * columnStrategy, const DisplayStrategy * displayStrategy, QWidget * parent, const char * name, WFlags f ) 00139 : KListView( parent, name ), 00140 mColumnStrategy( columnStrategy ), 00141 mDisplayStrategy ( displayStrategy ), 00142 mHierarchical( false ) 00143 { 00144 setWFlags( f ); 00145 00146 d = new Private(); 00147 00148 d->updateTimer = new QTimer( this ); 00149 connect( d->updateTimer, SIGNAL(timeout()), SLOT(slotUpdateTimeout()) ); 00150 00151 if ( !columnStrategy ) { 00152 kdWarning(5150) << "Kleo::KeyListView: need a column strategy to work with!" << endl; 00153 return; 00154 } 00155 00156 const QFontMetrics fm = fontMetrics(); 00157 00158 for ( int col = 0 ; !columnStrategy->title( col ).isEmpty() ; ++col ) { 00159 addColumn( columnStrategy->title( col ), columnStrategy->width( col, fm ) ); 00160 setColumnWidthMode( col, columnStrategy->widthMode( col ) ); 00161 } 00162 00163 setAllColumnsShowFocus( true ); 00164 setShowToolTips( false ); // we do it instead... 00165 00166 for ( int i = 0 ; i < numSignalReplacements ; ++i ) 00167 connect( this, signalReplacements[i].source, signalReplacements[i].target ); 00168 00169 QToolTip::remove( this ); 00170 QToolTip::remove( viewport() ); // make double sure :) 00171 d->itemToolTip = new ItemToolTip( this ); 00172 } 00173 00174 Kleo::KeyListView::~KeyListView() { 00175 d->updateTimer->stop(); 00176 delete d->itemToolTip; d->itemToolTip = 0; 00177 delete d; d = 0; 00178 delete mColumnStrategy; mColumnStrategy = 0; 00179 delete mDisplayStrategy; mDisplayStrategy = 0; 00180 } 00181 00182 void Kleo::KeyListView::setHierarchical( bool hier ) { 00183 if ( hier == mHierarchical ) 00184 return; 00185 mHierarchical = hier; 00186 if ( hier ) { 00187 refillFingerprintDictionary(); 00188 gatherScattered(); 00189 } else 00190 scatterGathered( firstChild() ); 00191 } 00192 00193 void Kleo::KeyListView::slotAddKey( const GpgME::Key & key ) { 00194 if ( key.isNull() ) 00195 return; 00196 00197 d->keyBuffer.push_back( key ); 00198 if ( !d->updateTimer->isActive() ) 00199 d->updateTimer->start( updateDelayMilliSecs, true /* single-shot */ ); 00200 } 00201 00202 void Kleo::KeyListView::slotUpdateTimeout() { 00203 if ( d->keyBuffer.empty() ) 00204 return; 00205 00206 const bool wasUpdatesEnabled = viewport()->isUpdatesEnabled(); 00207 if ( wasUpdatesEnabled ) 00208 viewport()->setUpdatesEnabled( false ); 00209 kdDebug( 5150 ) << "Kleo::KeyListView::slotUpdateTimeout(): processing " 00210 << d->keyBuffer.size() << " items en block" << endl; 00211 if ( hierarchical() ) { 00212 for ( std::vector<GpgME::Key>::const_iterator it = d->keyBuffer.begin() ; it != d->keyBuffer.end() ; ++it ) 00213 doHierarchicalInsert( *it ); 00214 gatherScattered(); 00215 } else { 00216 for ( std::vector<GpgME::Key>::const_iterator it = d->keyBuffer.begin() ; it != d->keyBuffer.end() ; ++it ) 00217 (void)new KeyListViewItem( this, *it ); 00218 } 00219 if ( wasUpdatesEnabled ) 00220 viewport()->setUpdatesEnabled( true ); 00221 d->keyBuffer.clear(); 00222 } 00223 00224 void Kleo::KeyListView::clear() { 00225 d->updateTimer->stop(); 00226 d->itemMap.clear(); 00227 d->keyBuffer.clear(); 00228 KListView::clear(); 00229 } 00230 00231 void Kleo::KeyListView::deregisterItem( const KeyListViewItem * item ) { 00232 if ( !item ) 00233 return; 00234 std::map<QCString,KeyListViewItem*>::iterator it 00235 = d->itemMap.find( item->key().subkey(0).fingerprint() ); 00236 if ( it == d->itemMap.end() ) 00237 return; 00238 Q_ASSERT( it->second != item ); 00239 if ( it->second != item ) 00240 return; 00241 d->itemMap.erase( it ); 00242 } 00243 00244 void Kleo::KeyListView::doHierarchicalInsert( const GpgME::Key & key ) { 00245 const QCString fpr = key.subkey(0).fingerprint(); 00246 if ( fpr.isEmpty() ) 00247 return; 00248 KeyListViewItem * item = 0; 00249 if ( !key.isRoot() ) 00250 if ( KeyListViewItem * parent = parentFor( key.chainID() ) ) { 00251 item = new KeyListViewItem( parent, key ); 00252 parent->setOpen( true ); 00253 } 00254 if ( !item ) 00255 item = new KeyListViewItem( this, key ); // top-level (for now) 00256 00257 d->itemMap.insert( std::make_pair( fpr, item ) ); 00258 } 00259 00260 void Kleo::KeyListView::gatherScattered() { 00261 KeyListViewItem * item = firstChild(); 00262 while ( item ) { 00263 KeyListViewItem * cur = item; 00264 item = item->nextSibling(); 00265 if ( cur->key().isRoot() ) 00266 continue; 00267 if ( KeyListViewItem * parent = parentFor( cur->key().chainID() ) ) { 00268 // found a new parent... 00269 takeItem( cur ); 00270 parent->insertItem( cur ); 00271 parent->setOpen( true ); 00272 } 00273 } 00274 } 00275 00276 void Kleo::KeyListView::scatterGathered( QListViewItem * start ) { 00277 QListViewItem * item = start; 00278 while ( item ) { 00279 QListViewItem * cur = item; 00280 item = item->nextSibling(); 00281 00282 scatterGathered( cur->firstChild() ); 00283 assert( cur->childCount() == 0 ); 00284 00285 if ( cur->parent() ) 00286 cur->parent()->takeItem( cur ); 00287 else 00288 takeItem( cur ); 00289 insertItem( cur ); 00290 } 00291 } 00292 00293 void Kleo::KeyListView::refillFingerprintDictionary() { 00294 d->itemMap.clear(); 00295 for ( QListViewItemIterator it( this ) ; it.current() ; ++it ) 00296 if ( ( it.current()->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) { 00297 KeyListViewItem * item = static_cast<KeyListViewItem*>( it.current() ); 00298 if ( const char * fpr = item->key().subkey(0).fingerprint() ) 00299 d->itemMap.insert( std::make_pair( QCString( fpr ), item ) ); 00300 } 00301 } 00302 00303 Kleo::KeyListViewItem * Kleo::KeyListView::parentFor( const QCString & s ) const { 00304 if ( s.isEmpty() ) 00305 return 0; 00306 const std::map<QCString,KeyListViewItem*>::const_iterator it = d->itemMap.find( s ); 00307 if ( it == d->itemMap.end() ) 00308 return 0; 00309 return it->second; 00310 } 00311 00312 00313 void Kleo::KeyListView::slotRefreshKey( const GpgME::Key & key ) { 00314 const char * fpr = key.subkey(0).fingerprint(); 00315 if ( !fpr ) 00316 return; 00317 for ( QListViewItemIterator it( this ) ; it.current() ; ++it ) 00318 if ( ( it.current()->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) { 00319 KeyListViewItem * item = static_cast<KeyListViewItem*>( it.current() ); 00320 if ( qstrcmp( fpr, item->key().subkey(0).fingerprint() ) == 0 ) { 00321 item->setKey ( key ); 00322 return; 00323 } 00324 } 00325 // none found -> add it 00326 slotAddKey( key ); 00327 } 00328 00329 // slots for the emission of covariant signals: 00330 00331 void Kleo::KeyListView::slotEmitDoubleClicked( QListViewItem * item, const QPoint & p, int col ) { 00332 if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) 00333 emit doubleClicked( static_cast<KeyListViewItem*>( item ), p, col ); 00334 } 00335 00336 void Kleo::KeyListView::slotEmitReturnPressed( QListViewItem * item ) { 00337 if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) 00338 emit returnPressed( static_cast<KeyListViewItem*>( item ) ); 00339 } 00340 00341 void Kleo::KeyListView::slotEmitSelectionChanged( QListViewItem * item ) { 00342 if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) 00343 emit selectionChanged( static_cast<KeyListViewItem*>( item ) ); 00344 } 00345 00346 void Kleo::KeyListView::slotEmitContextMenu( KListView*, QListViewItem * item, const QPoint & p ) { 00347 if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) 00348 emit contextMenu( static_cast<KeyListViewItem*>( item ), p ); 00349 } 00350 00351 // 00352 // 00353 // KeyListViewItem 00354 // 00355 // 00356 00357 Kleo::KeyListViewItem::KeyListViewItem( KeyListView * parent, const GpgME::Key & key ) 00358 : QListViewItem( parent ) 00359 { 00360 setKey( key ); 00361 } 00362 00363 Kleo::KeyListViewItem::KeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Key & key ) 00364 : QListViewItem( parent, after ) 00365 { 00366 setKey( key ); 00367 } 00368 00369 Kleo::KeyListViewItem::KeyListViewItem( KeyListViewItem * parent, const GpgME::Key & key ) 00370 : QListViewItem( parent ) 00371 { 00372 setKey( key ); 00373 } 00374 00375 Kleo::KeyListViewItem::KeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Key & key ) 00376 : QListViewItem( parent, after ) 00377 { 00378 setKey( key ); 00379 } 00380 00381 Kleo::KeyListViewItem::~KeyListViewItem() { 00382 if ( KeyListView * lv = listView() ) 00383 lv->deregisterItem( this ); 00384 } 00385 00386 void Kleo::KeyListViewItem::setKey( const GpgME::Key & key ) { 00387 mKey = key; 00388 // the ColumnStrategy operations might be very slow, so cache their 00389 // result here, where we're non-const :) 00390 const Kleo::KeyListView::ColumnStrategy * cs = listView() ? listView()->columnStrategy() : 0 ; 00391 if ( !cs ) 00392 return; 00393 const int numCols = listView() ? listView()->columns() : 0 ; 00394 for ( int i = 0 ; i < numCols ; ++i ) { 00395 setText( i, cs->text( key, i ) ); 00396 if ( const QPixmap * pix = cs->pixmap( key, i ) ) 00397 setPixmap( i, *pix ); 00398 } 00399 repaint(); 00400 } 00401 00402 QString Kleo::KeyListViewItem::toolTip( int col ) const { 00403 return listView() && listView()->columnStrategy() 00404 ? listView()->columnStrategy()->toolTip( key(), col ) 00405 : QString::null ; 00406 } 00407 00408 int Kleo::KeyListViewItem::compare( QListViewItem * item, int col, bool ascending ) const { 00409 if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() ) 00410 return QListViewItem::compare( item, col, ascending ); 00411 KeyListViewItem * that = static_cast<KeyListViewItem*>( item ); 00412 return listView()->columnStrategy()->compare( this->key(), that->key(), col ); 00413 } 00414 00415 void Kleo::KeyListViewItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment ) { 00416 const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ; 00417 if ( !ds ) { 00418 QListViewItem::paintCell( p, cg, column, width, alignment ); 00419 return; 00420 } 00421 const QColor fg = ds->keyForeground( key(), cg.text() ); 00422 const QColor bg = ds->keyBackground( key(), cg.base() ); 00423 const QFont f = ds->keyFont( key(), p->font() ); 00424 00425 QColorGroup _cg = cg; 00426 p->setFont( f ); 00427 _cg.setColor( QColorGroup::Text, fg ); 00428 _cg.setColor( QColorGroup::Base, bg ); 00429 00430 QListViewItem::paintCell( p, _cg, column, width, alignment ); 00431 } 00432 00433 // 00434 // 00435 // SubkeyKeyListViewItem 00436 // 00437 // 00438 00439 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListView * parent, const GpgME::Subkey & subkey ) 00440 : KeyListViewItem( parent, subkey.parent() ), mSubkey( subkey ) 00441 { 00442 00443 } 00444 00445 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::Subkey & subkey ) 00446 : KeyListViewItem( parent, after, subkey.parent() ), mSubkey( subkey ) 00447 { 00448 00449 } 00450 00451 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListViewItem * parent, const GpgME::Subkey & subkey ) 00452 : KeyListViewItem( parent, subkey.parent() ), mSubkey( subkey ) 00453 { 00454 00455 } 00456 00457 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::Subkey & subkey ) 00458 : KeyListViewItem( parent, after, subkey.parent() ), mSubkey( subkey ) 00459 { 00460 00461 } 00462 00463 void Kleo::SubkeyKeyListViewItem::setSubkey( const GpgME::Subkey & subkey ) { 00464 mSubkey = subkey; 00465 setKey( subkey.parent() ); 00466 } 00467 00468 QString Kleo::SubkeyKeyListViewItem::text( int col ) const { 00469 return listView() && listView()->columnStrategy() 00470 ? listView()->columnStrategy()->subkeyText( subkey(), col ) 00471 : QString::null ; 00472 } 00473 00474 QString Kleo::SubkeyKeyListViewItem::toolTip( int col ) const { 00475 return listView() && listView()->columnStrategy() 00476 ? listView()->columnStrategy()->subkeyToolTip( subkey(), col ) 00477 : QString::null ; 00478 } 00479 00480 const QPixmap * Kleo::SubkeyKeyListViewItem::pixmap( int col ) const { 00481 return listView() && listView()->columnStrategy() 00482 ? listView()->columnStrategy()->subkeyPixmap( subkey(), col ) : 0 ; 00483 } 00484 00485 int Kleo::SubkeyKeyListViewItem::compare( QListViewItem * item, int col, bool ascending ) const { 00486 if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() ) 00487 return KeyListViewItem::compare( item, col, ascending ); 00488 SubkeyKeyListViewItem * that = static_cast<SubkeyKeyListViewItem*>( item ); 00489 return listView()->columnStrategy()->subkeyCompare( this->subkey(), that->subkey(), col ); 00490 } 00491 00492 void Kleo::SubkeyKeyListViewItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment ) { 00493 const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ; 00494 if ( !ds ) { 00495 QListViewItem::paintCell( p, cg, column, width, alignment ); 00496 return; 00497 } 00498 const QColor fg = ds->subkeyForeground( subkey(), cg.text() ); 00499 const QColor bg = ds->subkeyBackground( subkey(), cg.base() ); 00500 const QFont f = ds->subkeyFont( subkey(), p->font() ); 00501 00502 QColorGroup _cg = cg; 00503 p->setFont( f ); 00504 _cg.setColor( QColorGroup::Text, fg ); 00505 _cg.setColor( QColorGroup::Base, bg ); 00506 00507 QListViewItem::paintCell( p, _cg, column, width, alignment ); 00508 } 00509 00510 00511 // 00512 // 00513 // UserIDKeyListViewItem 00514 // 00515 // 00516 00517 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListView * parent, const GpgME::UserID & userID ) 00518 : KeyListViewItem( parent, userID.parent() ), mUserID( userID ) 00519 { 00520 00521 } 00522 00523 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID & userID ) 00524 : KeyListViewItem( parent, after, userID.parent() ), mUserID( userID ) 00525 { 00526 00527 } 00528 00529 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID & userID ) 00530 : KeyListViewItem( parent, userID.parent() ), mUserID( userID ) 00531 { 00532 00533 } 00534 00535 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID & userID ) 00536 : KeyListViewItem( parent, after, userID.parent() ), mUserID( userID ) 00537 { 00538 00539 } 00540 00541 void Kleo::UserIDKeyListViewItem::setUserID( const GpgME::UserID & userID ) { 00542 mUserID = userID; 00543 setKey( userID.parent() ); 00544 } 00545 00546 QString Kleo::UserIDKeyListViewItem::text( int col ) const { 00547 return listView() && listView()->columnStrategy() 00548 ? listView()->columnStrategy()->userIDText( userID(), col ) 00549 : QString::null ; 00550 } 00551 00552 QString Kleo::UserIDKeyListViewItem::toolTip( int col ) const { 00553 return listView() && listView()->columnStrategy() 00554 ? listView()->columnStrategy()->userIDToolTip( userID(), col ) 00555 : QString::null ; 00556 } 00557 00558 const QPixmap * Kleo::UserIDKeyListViewItem::pixmap( int col ) const { 00559 return listView() && listView()->columnStrategy() 00560 ? listView()->columnStrategy()->userIDPixmap( userID(), col ) : 0 ; 00561 } 00562 00563 int Kleo::UserIDKeyListViewItem::compare( QListViewItem * item, int col, bool ascending ) const { 00564 if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() ) 00565 return KeyListViewItem::compare( item, col, ascending ); 00566 UserIDKeyListViewItem * that = static_cast<UserIDKeyListViewItem*>( item ); 00567 return listView()->columnStrategy()->userIDCompare( this->userID(), that->userID(), col ); 00568 } 00569 00570 00571 void Kleo::UserIDKeyListViewItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment ) { 00572 const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ; 00573 if ( !ds ) { 00574 QListViewItem::paintCell( p, cg, column, width, alignment ); 00575 return; 00576 } 00577 const QColor fg = ds->useridForeground( userID(), cg.text() ); 00578 const QColor bg = ds->useridBackground( userID(), cg.base() ); 00579 const QFont f = ds->useridFont( userID(), p->font() ); 00580 00581 QColorGroup _cg = cg; 00582 p->setFont( f ); 00583 _cg.setColor( QColorGroup::Text, fg ); 00584 _cg.setColor( QColorGroup::Base, bg ); 00585 00586 QListViewItem::paintCell( p, _cg, column, width, alignment ); 00587 } 00588 00589 00590 // 00591 // 00592 // SignatureKeyListViewItem 00593 // 00594 // 00595 00596 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListView * parent, const GpgME::UserID::Signature & signature ) 00597 : KeyListViewItem( parent, signature.parent().parent() ), mSignature( signature ) 00598 { 00599 00600 } 00601 00602 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListView * parent, KeyListViewItem * after, const GpgME::UserID::Signature & signature ) 00603 : KeyListViewItem( parent, after, signature.parent().parent() ), mSignature( signature ) 00604 { 00605 00606 } 00607 00608 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListViewItem * parent, const GpgME::UserID::Signature & signature ) 00609 : KeyListViewItem( parent, signature.parent().parent() ), mSignature( signature ) 00610 { 00611 00612 } 00613 00614 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after, const GpgME::UserID::Signature & signature ) 00615 : KeyListViewItem( parent, after, signature.parent().parent() ), mSignature( signature ) 00616 { 00617 00618 } 00619 00620 void Kleo::SignatureKeyListViewItem::setSignature( const GpgME::UserID::Signature & signature ) { 00621 mSignature = signature; 00622 setKey( signature.parent().parent() ); 00623 } 00624 00625 QString Kleo::SignatureKeyListViewItem::text( int col ) const { 00626 return listView() && listView()->columnStrategy() 00627 ? listView()->columnStrategy()->signatureText( signature(), col ) 00628 : QString::null ; 00629 } 00630 00631 QString Kleo::SignatureKeyListViewItem::toolTip( int col ) const { 00632 return listView() && listView()->columnStrategy() 00633 ? listView()->columnStrategy()->signatureToolTip( signature(), col ) 00634 : QString::null ; 00635 } 00636 00637 const QPixmap * Kleo::SignatureKeyListViewItem::pixmap( int col ) const { 00638 return listView() && listView()->columnStrategy() 00639 ? listView()->columnStrategy()->signaturePixmap( signature(), col ) : 0 ; 00640 } 00641 00642 int Kleo::SignatureKeyListViewItem::compare( QListViewItem * item, int col, bool ascending ) const { 00643 if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() ) 00644 return KeyListViewItem::compare( item, col, ascending ); 00645 SignatureKeyListViewItem * that = static_cast<SignatureKeyListViewItem*>( item ); 00646 return listView()->columnStrategy()->signatureCompare( this->signature(), that->signature(), col ); 00647 } 00648 00649 void Kleo::SignatureKeyListViewItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int alignment ) { 00650 const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ; 00651 if ( !ds ) { 00652 QListViewItem::paintCell( p, cg, column, width, alignment ); 00653 return; 00654 } 00655 const QColor fg = ds->signatureForeground( signature(), cg.text() ); 00656 const QColor bg = ds->signatureBackground( signature(), cg.base() ); 00657 const QFont f = ds->signatureFont( signature(), p->font() ); 00658 00659 QColorGroup _cg = cg; 00660 p->setFont( f ); 00661 _cg.setColor( QColorGroup::Text, fg ); 00662 _cg.setColor( QColorGroup::Base, bg ); 00663 00664 QListViewItem::paintCell( p, _cg, column, width, alignment ); 00665 } 00666 00667 00668 // 00669 // 00670 // ColumnStrategy 00671 // 00672 // 00673 00674 Kleo::KeyListView::ColumnStrategy::~ColumnStrategy() {} 00675 00676 int Kleo::KeyListView::ColumnStrategy::compare( const GpgME::Key & key1, const GpgME::Key & key2, int col ) const { 00677 return QString::localeAwareCompare( text( key1, col ), text( key2, col ) ); 00678 } 00679 00680 int Kleo::KeyListView::ColumnStrategy::width( int col, const QFontMetrics & fm ) const { 00681 return fm.width( title( col ) ) * 2; 00682 } 00683 00684 int Kleo::KeyListView::ColumnStrategy::subkeyCompare( const GpgME::Subkey & sub1, const GpgME::Subkey & sub2, int col ) const { 00685 return QString::localeAwareCompare( subkeyText( sub1, col ), subkeyText( sub2, col ) ); 00686 } 00687 00688 int Kleo::KeyListView::ColumnStrategy::userIDCompare( const GpgME::UserID & uid1, const GpgME::UserID & uid2, int col ) const { 00689 return QString::localeAwareCompare( userIDText( uid1, col ), userIDText( uid2, col ) ); 00690 } 00691 00692 int Kleo::KeyListView::ColumnStrategy::signatureCompare( const GpgME::UserID::Signature & sig1, const GpgME::UserID::Signature & sig2, int col ) const { 00693 return QString::localeAwareCompare( signatureText( sig1, col ), signatureText( sig2, col ) ); 00694 } 00695 00696 QString Kleo::KeyListView::ColumnStrategy::toolTip( const GpgME::Key & key, int col ) const { 00697 return text( key, col ); 00698 } 00699 00700 QString Kleo::KeyListView::ColumnStrategy::subkeyToolTip( const GpgME::Subkey & sub, int col ) const { 00701 return subkeyText( sub, col ); 00702 } 00703 00704 QString Kleo::KeyListView::ColumnStrategy::userIDToolTip( const GpgME::UserID & uid, int col ) const { 00705 return userIDText( uid, col ); 00706 } 00707 00708 QString Kleo::KeyListView::ColumnStrategy::signatureToolTip( const GpgME::UserID::Signature & sig, int col ) const { 00709 return signatureText( sig, col ); 00710 } 00711 00712 // 00713 // 00714 // DisplayStrategy 00715 // 00716 // 00717 00718 Kleo::KeyListView::DisplayStrategy::~DisplayStrategy() {} 00719 00720 00721 //font 00722 QFont Kleo::KeyListView::DisplayStrategy::keyFont( const GpgME::Key &, const QFont & font ) const { 00723 return font; 00724 } 00725 00726 QFont Kleo::KeyListView::DisplayStrategy::subkeyFont( const GpgME::Subkey &, const QFont & font ) const { 00727 return font; 00728 } 00729 00730 QFont Kleo::KeyListView::DisplayStrategy::useridFont( const GpgME::UserID &, const QFont & font ) const { 00731 return font; 00732 } 00733 00734 QFont Kleo::KeyListView::DisplayStrategy::signatureFont( const GpgME::UserID::Signature &, const QFont & font ) const { 00735 return font; 00736 } 00737 00738 //foreground 00739 QColor Kleo::KeyListView::DisplayStrategy::keyForeground( const GpgME::Key &, const QColor & fg )const { 00740 return fg; 00741 } 00742 00743 QColor Kleo::KeyListView::DisplayStrategy::subkeyForeground( const GpgME::Subkey &, const QColor & fg ) const { 00744 return fg; 00745 } 00746 00747 QColor Kleo::KeyListView::DisplayStrategy::useridForeground( const GpgME::UserID &, const QColor & fg ) const { 00748 return fg; 00749 } 00750 00751 QColor Kleo::KeyListView::DisplayStrategy::signatureForeground( const GpgME::UserID::Signature &, const QColor & fg ) const { 00752 return fg; 00753 } 00754 00755 //background 00756 QColor Kleo::KeyListView::DisplayStrategy::keyBackground( const GpgME::Key &, const QColor & bg )const { 00757 return bg; 00758 } 00759 00760 QColor Kleo::KeyListView::DisplayStrategy::subkeyBackground( const GpgME::Subkey &, const QColor & bg ) const { 00761 return bg; 00762 } 00763 00764 QColor Kleo::KeyListView::DisplayStrategy::useridBackground( const GpgME::UserID &, const QColor & bg ) const { 00765 return bg; 00766 } 00767 00768 QColor Kleo::KeyListView::DisplayStrategy::signatureBackground( const GpgME::UserID::Signature &, const QColor & bg ) const { 00769 return bg; 00770 } 00771 00772 00773 // 00774 // 00775 // Collection of covariant return reimplementations of QListView(Item) 00776 // members: 00777 // 00778 // 00779 00780 Kleo::KeyListView * Kleo::KeyListViewItem::listView() const { 00781 return static_cast<Kleo::KeyListView*>( QListViewItem::listView() ); 00782 } 00783 00784 Kleo::KeyListViewItem * Kleo::KeyListViewItem::nextSibling() const { 00785 return static_cast<Kleo::KeyListViewItem*>( QListViewItem::nextSibling() ); 00786 } 00787 00788 Kleo::KeyListViewItem * Kleo::KeyListView::firstChild() const { 00789 return static_cast<Kleo::KeyListViewItem*>( KListView::firstChild() ); 00790 } 00791 00792 Kleo::KeyListViewItem * Kleo::KeyListView::selectedItem() const { 00793 return static_cast<Kleo::KeyListViewItem*>( KListView::selectedItem() ); 00794 } 00795 00796 static void selectedItems( QPtrList<Kleo::KeyListViewItem> & result, QListViewItem * start ) { 00797 for ( QListViewItem * item = start ; item ; item = item->nextSibling() ) { 00798 if ( item->isSelected() && 00799 ( item->rtti() & Kleo::KeyListViewItem::RTTI_MASK ) == Kleo::KeyListViewItem::RTTI ) 00800 result.append( static_cast<Kleo::KeyListViewItem*>( item ) ); 00801 selectedItems( result, item->firstChild() ); 00802 } 00803 } 00804 00805 QPtrList<Kleo::KeyListViewItem> Kleo::KeyListView::selectedItems() const { 00806 QPtrList<KeyListViewItem> result; 00807 ::selectedItems( result, firstChild() ); 00808 return result; 00809 } 00810 00811 static bool hasSelection( QListViewItem * start ) { 00812 for ( QListViewItem * item = start ; item ; item = item->nextSibling() ) 00813 if ( item->isSelected() || hasSelection( item->firstChild() ) ) 00814 return true; 00815 return false; 00816 } 00817 00818 bool Kleo::KeyListView::hasSelection() const { 00819 return ::hasSelection( firstChild() ); 00820 } 00821 00822 #include "keylistview.moc"
KDE Logo
This file is part of the documentation for certmanager Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:46 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003