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
#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 }
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
00121
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 );
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() );
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 );
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::doHierarchicalInsert(
const GpgME::Key & key ) {
00232
const QCString fpr = key.subkey(0).fingerprint();
00233
if ( fpr.isEmpty() )
00234
return;
00235 KeyListViewItem * item = 0;
00236
if ( !key.isRoot() )
00237
if ( KeyListViewItem * parent = parentFor( key.chainID() ) ) {
00238 item =
new KeyListViewItem( parent, key );
00239 parent->setOpen(
true );
00240 }
00241
if ( !item )
00242 item =
new KeyListViewItem(
this, key );
00243
00244 d->itemMap.insert( std::make_pair( fpr, item ) );
00245 }
00246
00247
void Kleo::KeyListView::gatherScattered() {
00248 KeyListViewItem * item = firstChild();
00249
while ( item ) {
00250 KeyListViewItem * cur = item;
00251 item = item->nextSibling();
00252
if ( cur->key().isRoot() )
00253
continue;
00254
if ( KeyListViewItem * parent = parentFor( cur->key().chainID() ) ) {
00255
00256 takeItem( cur );
00257 parent->insertItem( cur );
00258 parent->setOpen(
true );
00259 }
00260 }
00261 }
00262
00263
void Kleo::KeyListView::scatterGathered(
QListViewItem * start ) {
00264
QListViewItem * item = start;
00265
while ( item ) {
00266
QListViewItem * cur = item;
00267 item = item->nextSibling();
00268
00269 scatterGathered( cur->firstChild() );
00270 assert( cur->childCount() == 0 );
00271
00272
if ( cur->parent() )
00273 cur->parent()->takeItem( cur );
00274
else
00275 takeItem( cur );
00276 insertItem( cur );
00277 }
00278 }
00279
00280
void Kleo::KeyListView::refillFingerprintDictionary() {
00281 d->itemMap.clear();
00282
for (
QListViewItemIterator it(
this ) ; it.current() ; ++it )
00283
if ( ( it.current()->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) {
00284 KeyListViewItem * item = static_cast<KeyListViewItem*>( it.current() );
00285
if (
const char * fpr = item->key().subkey(0).fingerprint() )
00286 d->itemMap.insert( std::make_pair(
QCString( fpr ), item ) );
00287 }
00288 }
00289
00290 Kleo::KeyListViewItem * Kleo::KeyListView::parentFor(
const QCString & s )
const {
00291
if ( s.isEmpty() )
00292
return 0;
00293
const std::map<QCString,KeyListViewItem*>::const_iterator it = d->itemMap.find( s );
00294
if ( it == d->itemMap.end() )
00295
return 0;
00296
return it->second;
00297 }
00298
00299
00300
void Kleo::KeyListView::slotRefreshKey(
const GpgME::Key & key ) {
00301
const char * fpr = key.subkey(0).fingerprint();
00302
if ( !fpr )
00303
return;
00304
for (
QListViewItemIterator it(
this ) ; it.current() ; ++it )
00305
if ( ( it.current()->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI ) {
00306 KeyListViewItem * item = static_cast<KeyListViewItem*>( it.current() );
00307
if ( qstrcmp( fpr, item->key().subkey(0).fingerprint() ) == 0 ) {
00308 item->setKey ( key );
00309
return;
00310 }
00311 }
00312
00313 slotAddKey( key );
00314 }
00315
00316
00317
00318
void Kleo::KeyListView::slotEmitDoubleClicked(
QListViewItem * item,
const QPoint & p,
int col ) {
00319
if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI )
00320 emit doubleClicked( static_cast<KeyListViewItem*>( item ), p, col );
00321 }
00322
00323
void Kleo::KeyListView::slotEmitReturnPressed(
QListViewItem * item ) {
00324
if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI )
00325 emit returnPressed( static_cast<KeyListViewItem*>( item ) );
00326 }
00327
00328
void Kleo::KeyListView::slotEmitSelectionChanged(
QListViewItem * item ) {
00329
if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI )
00330 emit selectionChanged( static_cast<KeyListViewItem*>( item ) );
00331 }
00332
00333
void Kleo::KeyListView::slotEmitContextMenu( KListView*,
QListViewItem * item,
const QPoint & p ) {
00334
if ( !item || ( item->rtti() & KeyListViewItem::RTTI_MASK ) == KeyListViewItem::RTTI )
00335 emit contextMenu( static_cast<KeyListViewItem*>( item ), p );
00336 }
00337
00338
00339
00340
00341
00342
00343
00344 Kleo::KeyListViewItem::KeyListViewItem( KeyListView * parent,
const GpgME::Key & key )
00345 :
QListViewItem( parent )
00346 {
00347 setKey( key );
00348 }
00349
00350 Kleo::KeyListViewItem::KeyListViewItem( KeyListView * parent, KeyListViewItem * after,
const GpgME::Key & key )
00351 :
QListViewItem( parent, after )
00352 {
00353 setKey( key );
00354 }
00355
00356 Kleo::KeyListViewItem::KeyListViewItem( KeyListViewItem * parent,
const GpgME::Key & key )
00357 :
QListViewItem( parent )
00358 {
00359 setKey( key );
00360 }
00361
00362 Kleo::KeyListViewItem::KeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after,
const GpgME::Key & key )
00363 :
QListViewItem( parent, after )
00364 {
00365 setKey( key );
00366 }
00367
00368
void Kleo::KeyListViewItem::setKey(
const GpgME::Key & key ) {
00369 mKey = key;
00370
00371
00372
const Kleo::KeyListView::ColumnStrategy * cs = listView() ? listView()->columnStrategy() : 0 ;
00373
if ( !cs )
00374
return;
00375
const int numCols = listView() ? listView()->columns() : 0 ;
00376
for (
int i = 0 ; i < numCols ; ++i ) {
00377 setText( i, cs->text( key, i ) );
00378
if (
const QPixmap * pix = cs->pixmap( key, i ) )
00379 setPixmap( i, *pix );
00380 }
00381 repaint();
00382 }
00383
00384
QString Kleo::KeyListViewItem::toolTip(
int col )
const {
00385
return listView() && listView()->columnStrategy()
00386 ? listView()->columnStrategy()->toolTip( key(), col )
00387 :
QString::null ;
00388 }
00389
00390
int Kleo::KeyListViewItem::compare(
QListViewItem * item,
int col,
bool ascending )
const {
00391
if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() )
00392
return QListViewItem::compare( item, col, ascending );
00393 KeyListViewItem * that = static_cast<KeyListViewItem*>( item );
00394
return listView()->columnStrategy()->compare( this->key(), that->key(), col );
00395 }
00396
00397
void Kleo::KeyListViewItem::paintCell(
QPainter * p,
const QColorGroup & cg,
int column,
int width,
int alignment ) {
00398
const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ;
00399
if ( !ds ) {
00400 QListViewItem::paintCell( p, cg, column, width, alignment );
00401
return;
00402 }
00403
const QColor fg = ds->keyForeground( key(), cg.text() );
00404
const QColor bg = ds->keyBackground( key(), cg.base() );
00405
const QFont f = ds->keyFont( key(), p->font() );
00406
00407
QColorGroup _cg = cg;
00408 p->setFont( f );
00409 _cg.setColor( QColorGroup::Text, fg );
00410 _cg.setColor( QColorGroup::Base, bg );
00411
00412 QListViewItem::paintCell( p, _cg, column, width, alignment );
00413 }
00414
00415
00416
00417
00418
00419
00420
00421 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListView * parent,
const GpgME::Subkey & subkey )
00422 : KeyListViewItem( parent, subkey.parent() ), mSubkey( subkey )
00423 {
00424
00425 }
00426
00427 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListView * parent, KeyListViewItem * after,
const GpgME::Subkey & subkey )
00428 : KeyListViewItem( parent, after, subkey.parent() ), mSubkey( subkey )
00429 {
00430
00431 }
00432
00433 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListViewItem * parent,
const GpgME::Subkey & subkey )
00434 : KeyListViewItem( parent, subkey.parent() ), mSubkey( subkey )
00435 {
00436
00437 }
00438
00439 Kleo::SubkeyKeyListViewItem::SubkeyKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after,
const GpgME::Subkey & subkey )
00440 : KeyListViewItem( parent, after, subkey.parent() ), mSubkey( subkey )
00441 {
00442
00443 }
00444
00445
void Kleo::SubkeyKeyListViewItem::setSubkey(
const GpgME::Subkey & subkey ) {
00446 mSubkey = subkey;
00447 setKey( subkey.parent() );
00448 }
00449
00450
QString Kleo::SubkeyKeyListViewItem::text(
int col )
const {
00451
return listView() && listView()->columnStrategy()
00452 ? listView()->columnStrategy()->subkeyText( subkey(), col )
00453 :
QString::null ;
00454 }
00455
00456
QString Kleo::SubkeyKeyListViewItem::toolTip(
int col )
const {
00457
return listView() && listView()->columnStrategy()
00458 ? listView()->columnStrategy()->subkeyToolTip( subkey(), col )
00459 :
QString::null ;
00460 }
00461
00462
const QPixmap * Kleo::SubkeyKeyListViewItem::pixmap(
int col )
const {
00463
return listView() && listView()->columnStrategy()
00464 ? listView()->columnStrategy()->subkeyPixmap( subkey(), col ) : 0 ;
00465 }
00466
00467
int Kleo::SubkeyKeyListViewItem::compare(
QListViewItem * item,
int col,
bool ascending )
const {
00468
if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() )
00469
return KeyListViewItem::compare( item, col, ascending );
00470 SubkeyKeyListViewItem * that = static_cast<SubkeyKeyListViewItem*>( item );
00471
return listView()->columnStrategy()->subkeyCompare( this->subkey(), that->subkey(), col );
00472 }
00473
00474
void Kleo::SubkeyKeyListViewItem::paintCell(
QPainter * p,
const QColorGroup & cg,
int column,
int width,
int alignment ) {
00475
const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ;
00476
if ( !ds ) {
00477 QListViewItem::paintCell( p, cg, column, width, alignment );
00478
return;
00479 }
00480
const QColor fg = ds->subkeyForeground( subkey(), cg.text() );
00481
const QColor bg = ds->subkeyBackground( subkey(), cg.base() );
00482
const QFont f = ds->subkeyFont( subkey(), p->font() );
00483
00484
QColorGroup _cg = cg;
00485 p->setFont( f );
00486 _cg.setColor( QColorGroup::Text, fg );
00487 _cg.setColor( QColorGroup::Base, bg );
00488
00489 QListViewItem::paintCell( p, _cg, column, width, alignment );
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListView * parent,
const GpgME::UserID & userID )
00500 : KeyListViewItem( parent, userID.parent() ), mUserID( userID )
00501 {
00502
00503 }
00504
00505 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListView * parent, KeyListViewItem * after,
const GpgME::UserID & userID )
00506 : KeyListViewItem( parent, after, userID.parent() ), mUserID( userID )
00507 {
00508
00509 }
00510
00511 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListViewItem * parent,
const GpgME::UserID & userID )
00512 : KeyListViewItem( parent, userID.parent() ), mUserID( userID )
00513 {
00514
00515 }
00516
00517 Kleo::UserIDKeyListViewItem::UserIDKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after,
const GpgME::UserID & userID )
00518 : KeyListViewItem( parent, after, userID.parent() ), mUserID( userID )
00519 {
00520
00521 }
00522
00523
void Kleo::UserIDKeyListViewItem::setUserID(
const GpgME::UserID & userID ) {
00524 mUserID = userID;
00525 setKey( userID.parent() );
00526 }
00527
00528
QString Kleo::UserIDKeyListViewItem::text(
int col )
const {
00529
return listView() && listView()->columnStrategy()
00530 ? listView()->columnStrategy()->userIDText( userID(), col )
00531 :
QString::null ;
00532 }
00533
00534
QString Kleo::UserIDKeyListViewItem::toolTip(
int col )
const {
00535
return listView() && listView()->columnStrategy()
00536 ? listView()->columnStrategy()->userIDToolTip( userID(), col )
00537 :
QString::null ;
00538 }
00539
00540
const QPixmap * Kleo::UserIDKeyListViewItem::pixmap(
int col )
const {
00541
return listView() && listView()->columnStrategy()
00542 ? listView()->columnStrategy()->userIDPixmap( userID(), col ) : 0 ;
00543 }
00544
00545
int Kleo::UserIDKeyListViewItem::compare(
QListViewItem * item,
int col,
bool ascending )
const {
00546
if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() )
00547
return KeyListViewItem::compare( item, col, ascending );
00548 UserIDKeyListViewItem * that = static_cast<UserIDKeyListViewItem*>( item );
00549
return listView()->columnStrategy()->userIDCompare( this->userID(), that->userID(), col );
00550 }
00551
00552
00553
void Kleo::UserIDKeyListViewItem::paintCell(
QPainter * p,
const QColorGroup & cg,
int column,
int width,
int alignment ) {
00554
const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ;
00555
if ( !ds ) {
00556 QListViewItem::paintCell( p, cg, column, width, alignment );
00557
return;
00558 }
00559
const QColor fg = ds->useridForeground( userID(), cg.text() );
00560
const QColor bg = ds->useridBackground( userID(), cg.base() );
00561
const QFont f = ds->useridFont( userID(), p->font() );
00562
00563
QColorGroup _cg = cg;
00564 p->setFont( f );
00565 _cg.setColor( QColorGroup::Text, fg );
00566 _cg.setColor( QColorGroup::Base, bg );
00567
00568 QListViewItem::paintCell( p, _cg, column, width, alignment );
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListView * parent,
const GpgME::UserID::Signature & signature )
00579 : KeyListViewItem( parent, signature.parent().parent() ), mSignature( signature )
00580 {
00581
00582 }
00583
00584 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListView * parent, KeyListViewItem * after,
const GpgME::UserID::Signature & signature )
00585 : KeyListViewItem( parent, after, signature.parent().parent() ), mSignature( signature )
00586 {
00587
00588 }
00589
00590 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListViewItem * parent,
const GpgME::UserID::Signature & signature )
00591 : KeyListViewItem( parent, signature.parent().parent() ), mSignature( signature )
00592 {
00593
00594 }
00595
00596 Kleo::SignatureKeyListViewItem::SignatureKeyListViewItem( KeyListViewItem * parent, KeyListViewItem * after,
const GpgME::UserID::Signature & signature )
00597 : KeyListViewItem( parent, after, signature.parent().parent() ), mSignature( signature )
00598 {
00599
00600 }
00601
00602
void Kleo::SignatureKeyListViewItem::setSignature(
const GpgME::UserID::Signature & signature ) {
00603 mSignature = signature;
00604 setKey( signature.parent().parent() );
00605 }
00606
00607
QString Kleo::SignatureKeyListViewItem::text(
int col )
const {
00608
return listView() && listView()->columnStrategy()
00609 ? listView()->columnStrategy()->signatureText( signature(), col )
00610 :
QString::null ;
00611 }
00612
00613
QString Kleo::SignatureKeyListViewItem::toolTip(
int col )
const {
00614
return listView() && listView()->columnStrategy()
00615 ? listView()->columnStrategy()->signatureToolTip( signature(), col )
00616 :
QString::null ;
00617 }
00618
00619
const QPixmap * Kleo::SignatureKeyListViewItem::pixmap(
int col )
const {
00620
return listView() && listView()->columnStrategy()
00621 ? listView()->columnStrategy()->signaturePixmap( signature(), col ) : 0 ;
00622 }
00623
00624
int Kleo::SignatureKeyListViewItem::compare(
QListViewItem * item,
int col,
bool ascending )
const {
00625
if ( !item || item->rtti() != RTTI || !listView() || !listView()->columnStrategy() )
00626
return KeyListViewItem::compare( item, col, ascending );
00627 SignatureKeyListViewItem * that = static_cast<SignatureKeyListViewItem*>( item );
00628
return listView()->columnStrategy()->signatureCompare( this->signature(), that->signature(), col );
00629 }
00630
00631
void Kleo::SignatureKeyListViewItem::paintCell(
QPainter * p,
const QColorGroup & cg,
int column,
int width,
int alignment ) {
00632
const KeyListView::DisplayStrategy * ds = listView() ? listView()->displayStrategy() : 0 ;
00633
if ( !ds ) {
00634 QListViewItem::paintCell( p, cg, column, width, alignment );
00635
return;
00636 }
00637
const QColor fg = ds->signatureForeground( signature(), cg.text() );
00638
const QColor bg = ds->signatureBackground( signature(), cg.base() );
00639
const QFont f = ds->signatureFont( signature(), p->font() );
00640
00641
QColorGroup _cg = cg;
00642 p->setFont( f );
00643 _cg.setColor( QColorGroup::Text, fg );
00644 _cg.setColor( QColorGroup::Base, bg );
00645
00646 QListViewItem::paintCell( p, _cg, column, width, alignment );
00647 }
00648
00649
00650
00651
00652
00653
00654
00655
00656 Kleo::KeyListView::ColumnStrategy::~ColumnStrategy() {}
00657
00658
int Kleo::KeyListView::ColumnStrategy::compare(
const GpgME::Key & key1,
const GpgME::Key & key2,
int col )
const {
00659
return QString::localeAwareCompare( text( key1, col ), text( key2, col ) );
00660 }
00661
00662
int Kleo::KeyListView::ColumnStrategy::width(
int col,
const QFontMetrics & fm )
const {
00663
return fm.width( title( col ) ) * 2;
00664 }
00665
00666
int Kleo::KeyListView::ColumnStrategy::subkeyCompare(
const GpgME::Subkey & sub1,
const GpgME::Subkey & sub2,
int col )
const {
00667
return QString::localeAwareCompare( subkeyText( sub1, col ), subkeyText( sub2, col ) );
00668 }
00669
00670
int Kleo::KeyListView::ColumnStrategy::userIDCompare(
const GpgME::UserID & uid1,
const GpgME::UserID & uid2,
int col )
const {
00671
return QString::localeAwareCompare( userIDText( uid1, col ), userIDText( uid2, col ) );
00672 }
00673
00674
int Kleo::KeyListView::ColumnStrategy::signatureCompare(
const GpgME::UserID::Signature & sig1,
const GpgME::UserID::Signature & sig2,
int col )
const {
00675
return QString::localeAwareCompare( signatureText( sig1, col ), signatureText( sig2, col ) );
00676 }
00677
00678
QString Kleo::KeyListView::ColumnStrategy::toolTip(
const GpgME::Key & key,
int col )
const {
00679
return text( key, col );
00680 }
00681
00682
QString Kleo::KeyListView::ColumnStrategy::subkeyToolTip(
const GpgME::Subkey & sub,
int col )
const {
00683
return subkeyText( sub, col );
00684 }
00685
00686
QString Kleo::KeyListView::ColumnStrategy::userIDToolTip(
const GpgME::UserID & uid,
int col )
const {
00687
return userIDText( uid, col );
00688 }
00689
00690
QString Kleo::KeyListView::ColumnStrategy::signatureToolTip(
const GpgME::UserID::Signature & sig,
int col )
const {
00691
return signatureText( sig, col );
00692 }
00693
00694
00695
00696
00697
00698
00699
00700 Kleo::KeyListView::DisplayStrategy::~DisplayStrategy() {}
00701
00702
00703
00704
QFont Kleo::KeyListView::DisplayStrategy::keyFont(
const GpgME::Key &,
const QFont & font )
const {
00705
return font;
00706 }
00707
00708
QFont Kleo::KeyListView::DisplayStrategy::subkeyFont(
const GpgME::Subkey &,
const QFont & font )
const {
00709
return font;
00710 }
00711
00712
QFont Kleo::KeyListView::DisplayStrategy::useridFont(
const GpgME::UserID &,
const QFont & font )
const {
00713
return font;
00714 }
00715
00716
QFont Kleo::KeyListView::DisplayStrategy::signatureFont(
const GpgME::UserID::Signature &,
const QFont & font )
const {
00717
return font;
00718 }
00719
00720
00721
QColor Kleo::KeyListView::DisplayStrategy::keyForeground(
const GpgME::Key &,
const QColor & fg )
const {
00722
return fg;
00723 }
00724
00725
QColor Kleo::KeyListView::DisplayStrategy::subkeyForeground(
const GpgME::Subkey &,
const QColor & fg )
const {
00726
return fg;
00727 }
00728
00729
QColor Kleo::KeyListView::DisplayStrategy::useridForeground(
const GpgME::UserID &,
const QColor & fg )
const {
00730
return fg;
00731 }
00732
00733
QColor Kleo::KeyListView::DisplayStrategy::signatureForeground(
const GpgME::UserID::Signature &,
const QColor & fg )
const {
00734
return fg;
00735 }
00736
00737
00738
QColor Kleo::KeyListView::DisplayStrategy::keyBackground(
const GpgME::Key &,
const QColor & bg )
const {
00739
return bg;
00740 }
00741
00742
QColor Kleo::KeyListView::DisplayStrategy::subkeyBackground(
const GpgME::Subkey &,
const QColor & bg )
const {
00743
return bg;
00744 }
00745
00746
QColor Kleo::KeyListView::DisplayStrategy::useridBackground(
const GpgME::UserID &,
const QColor & bg )
const {
00747
return bg;
00748 }
00749
00750
QColor Kleo::KeyListView::DisplayStrategy::signatureBackground(
const GpgME::UserID::Signature &,
const QColor & bg )
const {
00751
return bg;
00752 }
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 Kleo::KeyListView * Kleo::KeyListViewItem::listView()
const {
00763
return static_cast<Kleo::KeyListView*>( QListViewItem::listView() );
00764 }
00765
00766 Kleo::KeyListViewItem * Kleo::KeyListViewItem::nextSibling()
const {
00767
return static_cast<Kleo::KeyListViewItem*>( QListViewItem::nextSibling() );
00768 }
00769
00770 Kleo::KeyListViewItem * Kleo::KeyListView::firstChild()
const {
00771
return static_cast<Kleo::KeyListViewItem*>( KListView::firstChild() );
00772 }
00773
00774 Kleo::KeyListViewItem * Kleo::KeyListView::selectedItem()
const {
00775
return static_cast<Kleo::KeyListViewItem*>( KListView::selectedItem() );
00776 }
00777
00778
static void selectedItems(
QPtrList<Kleo::KeyListViewItem> & result,
QListViewItem * start ) {
00779
for (
QListViewItem * item = start ; item ; item = item->nextSibling() ) {
00780
if ( item->isSelected() &&
00781 ( item->rtti() & Kleo::KeyListViewItem::RTTI_MASK ) == Kleo::KeyListViewItem::RTTI )
00782 result.append( static_cast<Kleo::KeyListViewItem*>( item ) );
00783 selectedItems( result, item->firstChild() );
00784 }
00785 }
00786
00787
QPtrList<Kleo::KeyListViewItem> Kleo::KeyListView::selectedItems()
const {
00788
QPtrList<KeyListViewItem> result;
00789 ::selectedItems( result, firstChild() );
00790
return result;
00791 }
00792
00793
static bool hasSelection(
QListViewItem * start ) {
00794
for (
QListViewItem * item = start ; item ; item = item->nextSibling() )
00795
if ( item->isSelected() || hasSelection( item->firstChild() ) )
00796
return true;
00797
return false;
00798 }
00799
00800
bool Kleo::KeyListView::hasSelection()
const {
00801 return ::hasSelection( firstChild() );
00802 }
00803
00804
#include "keylistview.moc"