00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "keylistview.h"
00011
00012 #include <QDragMoveEvent>
00013 #include <QDropEvent>
00014 #include <QPainter>
00015 #include <QRect>
00016
00017 #include <Q3ListViewItem>
00018 #include <Q3TextDrag>
00019 #include <Q3Header>
00020
00021 #include <kabc/stdaddressbook.h>
00022 #include <KStandardDirs>
00023 #include <KApplication>
00024 #include <KMessageBox>
00025 #include <KLocale>
00026
00027 #include "kgpgsettings.h"
00028 #include "kgpgoptions.h"
00029 #include "convert.h"
00030 #include "images.h"
00031
00032 KeyListViewItem::KeyListViewItem(KeyListView *parent, const QString &name, const QString &email, const QString &trust, const QString &expiration, const QString &size, const QString &creation, const QString &id, const bool isdefault, bool isexpired, ItemType type)
00033 : K3ListViewItem(parent, name, email, trust, expiration, size, creation, id)
00034 {
00035 m_def = isdefault;
00036 m_exp = isexpired;
00037 m_type = type;
00038 m_key = NULL;
00039 m_sig = NULL;
00040 groupId = NULL;
00041 }
00042
00043 KeyListViewItem::KeyListViewItem(KeyListViewItem *parent, const QString &name, const QString &email, const QString &trust, const QString &expiration, const QString &size, const QString &creation, const QString &id, const bool isdefault, const bool isexpired, ItemType type)
00044 : K3ListViewItem(parent, name, email, trust, expiration, size, creation, id)
00045 {
00046 m_def = isdefault;
00047 m_exp = isexpired;
00048 m_type = type;
00049 m_key = NULL;
00050 m_sig = NULL;
00051 groupId = NULL;
00052 }
00053
00054 KeyListViewItem::KeyListViewItem(K3ListView *parent, const KgpgKey &key, const bool isbold)
00055 : K3ListViewItem(parent)
00056 {
00057 m_def = isbold;
00058 m_exp = (key.trust() == TRUST_EXPIRED);
00059 m_type = Public;
00060 m_key = new KgpgKey(key);
00061 m_sig = NULL;
00062 groupId = NULL;
00063 if (key.secret())
00064 m_type |= Secret;
00065 if (key.comment().isEmpty())
00066 setText(0, key.name());
00067 else
00068 setText(0, i18nc("Name (Comment)", "%1 (%2)", key.name(), key.comment()));
00069 setText(1, key.email());
00070 setText(2, QString());
00071 setText(3, key.expiration());
00072 setText(4, QString::number(key.size()));
00073 setText(5, key.creation());
00074 setText(6, key.id());
00075 }
00076
00077 KeyListViewItem::KeyListViewItem(K3ListViewItem *parent, const KgpgKeySign &sig)
00078 : K3ListViewItem(parent)
00079 {
00080 m_def = false;
00081 m_exp = false;
00082 m_type = Sign;
00083 m_key = NULL;
00084 groupId = NULL;
00085 m_sig = new KgpgKeySign(sig);
00086
00087 QString tmpname = sig.name();
00088 if (!sig.comment().isEmpty())
00089 tmpname += " (" + sig.comment() + ')';
00090
00091 setText(0, tmpname);
00092
00093 QString tmpemail = sig.email();
00094 if (sig.local())
00095 tmpemail += i18n(" [local signature]");
00096
00097 if (sig.revocation()) {
00098 tmpemail += i18n(" [Revocation signature]");
00099 setPixmap(0, Images::revoke());
00100 m_type = RevSign;
00101 } else
00102 setPixmap(0, Images::signature());
00103
00104 setText(1, tmpemail);
00105 setText(2, "-");
00106 setText(3, sig.expiration());
00107 setText(4, "-");
00108 setText(5, sig.creation());
00109 setText(6, sig.id());
00110 }
00111
00112 KeyListViewItem::~KeyListViewItem()
00113 {
00114 delete m_key;
00115 delete m_sig;
00116 delete groupId;
00117 }
00118
00119 void KeyListViewItem::setItemType(const ItemType &type)
00120 {
00121 m_type = type;
00122 }
00123
00124 KeyListViewItem::ItemType KeyListViewItem::itemType() const
00125 {
00126 return m_type;
00127 }
00128
00129 void KeyListViewItem::setDefault(const bool &def)
00130 {
00131 m_def = def;
00132 }
00133
00134 bool KeyListViewItem::isDefault() const
00135 {
00136 return m_def;
00137 }
00138
00139 void KeyListViewItem::setExpired(const bool &exp)
00140 {
00141 m_exp = exp;
00142 }
00143
00144 bool KeyListViewItem::isExpired() const
00145 {
00146 return m_exp;
00147 }
00148
00149 void KeyListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
00150 {
00151 QColorGroup _cg(cg);
00152
00153 if (itemType() & Public)
00154 {
00155 if (m_def && (column < 2))
00156 {
00157 QFont font(p->font());
00158 font.setBold(true);
00159 p->setFont(font);
00160 }
00161 else
00162 if (m_exp && (column == 3))
00163 _cg.setColor(QPalette::Text, Qt::red);
00164 }
00165 else
00166 if (column < 2)
00167 {
00168 QFont font(p->font());
00169 font.setItalic(true);
00170 p->setFont(font);
00171 }
00172
00173 K3ListViewItem::paintCell(p, _cg, column, width, alignment);
00174 }
00175
00176 int KeyListViewItem::compare(Q3ListViewItem *itemx, int c, bool ascending) const
00177 {
00178 KeyListViewItem *item = static_cast<KeyListViewItem *>(itemx);
00179
00180 switch (c) {
00181 case 3:
00182 case 5: {
00183 QDate d = KGlobal::locale()->readDate(text(c));
00184 QDate itemDate = KGlobal::locale()->readDate(item->text(c));
00185
00186 bool thisDateValid = d.isValid();
00187 bool itemDateValid = itemDate.isValid();
00188
00189 if (thisDateValid) {
00190 if (itemDateValid) {
00191 if (d < itemDate) return -1;
00192 if (d > itemDate) return 1;
00193 } else
00194 return -1;
00195 } else if (itemDateValid)
00196 return 1;
00197
00198 return 0;
00199 }
00200 case 2: {
00201 if (trust() < item->trust()) return -1;
00202 if (trust() > item->trust()) return 1;
00203 return 0;
00204 }
00205 case 0: {
00206 ItemType item1 = itemType();
00207 ItemType item2 = item->itemType();
00208
00209 bool test1 = (item1 & KeyListViewItem::Public) && !(item1 & KeyListViewItem::Secret);
00210 bool test2 = (item2 & KeyListViewItem::Public) && !(item2 & KeyListViewItem::Secret);
00211
00212
00213 if (item1 == KeyListViewItem::Pair && test2) return -1;
00214 if (item2 == KeyListViewItem::Pair && test1) return 1;
00215
00216 if (item1 < item2) return -1;
00217 if (item1 > item2) return 1;
00218
00219
00220 }
00221 default:
00222 return K3ListViewItem::compare(item, c, ascending);
00223 }
00224 }
00225
00226 QString KeyListViewItem::key(int column, bool) const
00227 {
00228 return text(column).toLower();
00229 }
00230
00231 KeyListView::KeyListView(QWidget *parent)
00232 : K3ListView(parent)
00233 {
00234 setRootIsDecorated(true);
00235 addColumn(i18nc("Name of key owner", "Name"), 230);
00236 addColumn(i18nc("Email address of key owner", "Email"), 220);
00237 addColumn(i18n("Trust"), 60);
00238 addColumn(i18n("Expiration"), 100);
00239 addColumn(i18n("Size"), 50);
00240 addColumn(i18n("Creation"), 100);
00241 addColumn(i18n("Id"), 100);
00242 setShowSortIndicator(true);
00243 setAllColumnsShowFocus(true);
00244 setFullWidth(true);
00245 setSelectionModeExt(Extended);
00246
00247 QPixmap blankFrame(KStandardDirs::locate("appdata", "pics/kgpg_blank.png"));
00248 QRect rect(0, 0, 50, 15);
00249
00250 trustunknown.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00251 trustunknown.fill(Convert::toColor(TRUST_UNKNOWN));
00252 QPainter(&trustunknown).drawPixmap(rect, blankFrame);
00253
00254 trustbad.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00255 trustbad.fill(Convert::toColor(TRUST_DISABLED));
00256 QPainter(&trustbad).drawPixmap(rect, blankFrame);
00257
00258 trustrevoked.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00259 trustrevoked.fill(Convert::toColor(TRUST_REVOKED));
00260 QPainter(&trustrevoked).drawPixmap(rect, blankFrame);
00261
00262 trustgood.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00263 trustgood.fill(Convert::toColor(TRUST_FULL));
00264 QPainter(&trustgood).drawPixmap(rect, blankFrame);
00265
00266 trustultimate.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00267 trustultimate.fill(Convert::toColor(TRUST_ULTIMATE));
00268 QPainter(&trustultimate).drawPixmap(rect, blankFrame);
00269
00270 trustmarginal.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00271 trustmarginal.fill(Convert::toColor(TRUST_MARGINAL));
00272 QPainter(&trustmarginal).drawPixmap(rect, blankFrame);
00273
00274 trustexpired.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00275 trustexpired.fill(Convert::toColor(TRUST_EXPIRED));
00276 QPainter(&trustexpired).drawPixmap(rect, blankFrame);
00277
00278 connect(this, SIGNAL(expanded(Q3ListViewItem *)), this, SLOT(expandKey(Q3ListViewItem *)));
00279
00280 header()->setMovingEnabled(false);
00281 setAcceptDrops(true);
00282 setDragEnabled(true);
00283 }
00284
00285 void KeyListView::setPreviewSize(const int &size)
00286 {
00287 m_previewsize = size;
00288 }
00289
00290 int KeyListView::previewSize() const
00291 {
00292 return m_previewsize;
00293 }
00294
00295 void KeyListView::setDisplayPhoto(const bool &display)
00296 {
00297 m_displayphoto = display;
00298 }
00299
00300 bool KeyListView::displayPhoto() const
00301 {
00302 return m_displayphoto;
00303 }
00304
00305 void KeyListView::slotAddColumn(const int &c)
00306 {
00307 header()->setResizeEnabled(true, c);
00308 adjustColumn(c);
00309 }
00310
00311 void KeyListView::slotRemoveColumn(const int &c)
00312 {
00313 hideColumn(c);
00314 header()->setResizeEnabled(false, c);
00315 header()->setStretchEnabled(true, 6);
00316 }
00317
00318 void KeyListView::contentsDragMoveEvent(QDragMoveEvent *e)
00319 {
00320 e->setAccepted(KUrl::List::canDecode(e->mimeData()));
00321 }
00322
00323 void KeyListView::contentsDropEvent(QDropEvent *o)
00324 {
00325 KUrl::List uriList = KUrl::List::fromMimeData(o->mimeData());
00326 if (!uriList.isEmpty())
00327 droppedFile(uriList.first());
00328 }
00329
00330 void KeyListView::startDrag()
00331 {
00332 KeyListViewItem *ki = currentItem();
00333 QString keyid = ki->text(6);
00334
00335 if (!(ki->itemType() & KeyListViewItem::Public))
00336 return;
00337
00338 KgpgInterface *interface = new KgpgInterface();
00339 QString keytxt = interface->getKeys(true, NULL, QStringList(keyid));
00340 delete interface;
00341
00342 Q3DragObject *d = new Q3TextDrag(keytxt, this);
00343 d->dragCopy();
00344
00345 }
00346
00347 void KeyListView::droppedFile(const KUrl &url)
00348 {
00349 if (KMessageBox::questionYesNo(this, i18n("<p>Do you want to import file <b>%1</b> into your key ring?</p>", url.path()), QString(), KGuiItem(i18n("Import")), KGuiItem(i18n("Do Not Import"))) != KMessageBox::Yes)
00350 return;
00351
00352 KgpgInterface *interface = new KgpgInterface();
00353 connect(interface, SIGNAL(importKeyFinished(QStringList)), this, SLOT(slotReloadKeys(QStringList)));
00354 interface->importKey(url);
00355 }
00356
00357 void KeyListView::slotReloadKeys(const QStringList &keyids)
00358 {
00359 if (keyids.isEmpty())
00360 return;
00361
00362 if (keyids.first() == "ALL")
00363 {
00364 refreshAll();
00365 return;
00366 }
00367
00368 refreshKeys(keyids);
00369
00370 ensureItemVisible(this->findItemByKeyId(keyids.last()));
00371 emit statusMessage(statusCountMessage(), 1);
00372 emit statusMessage(i18nc("No operation in progress", "Ready"), 0);
00373 }
00374
00375 void KeyListView::refreshAll()
00376 {
00377 emit statusMessage(i18n("Loading Keys..."), 0, true);
00378 kapp->processEvents();
00379
00380
00381 kDebug(2100) << "Refreshing All" ;
00382
00383
00384 KeyListViewItem *current = currentItem();
00385 if(current != 0)
00386 {
00387 while(current->depth() > 0)
00388 current = current->parent();
00389 takeItem(current);
00390 }
00391
00392
00393 clear();
00394
00395 if (refreshKeys())
00396 {
00397 kDebug(2100) << "No key found" ;
00398 emit statusMessage(i18nc("No operation in progress", "Ready"), 0);
00399 return;
00400 }
00401
00402 refreshGroups();
00403
00404 KeyListViewItem *newPos = NULL;
00405 if(current != 0)
00406 {
00407
00408 if (!current->text(6).isEmpty())
00409 newPos = findItemByKeyId(current->keyId());
00410 else
00411 newPos = findItem(current->text(0), 0);
00412 delete current;
00413 }
00414
00415 if (newPos != NULL)
00416 {
00417 setCurrentItem(newPos);
00418 setSelected(newPos, true);
00419 ensureItemVisible(newPos);
00420 }
00421 else
00422 {
00423 setCurrentItem(firstChild());
00424 setSelected(firstChild(), true);
00425 }
00426
00427 emit statusMessage(statusCountMessage(), 1);
00428 emit statusMessage(i18nc("No operation in progress", "Ready"),0);
00429 kDebug(2100) << "Refresh Finished" ;
00430 }
00431
00432 bool KeyListView::refreshKeys(const QStringList &ids)
00433 {
00434 KgpgInterface *interface = new KgpgInterface();
00435 KgpgKeyList secretlist = interface->readSecretKeys(ids);
00436
00437 QStringList issec = secretlist;
00438
00439 KgpgKeyList publiclist = interface->readPublicKeys(true, ids);
00440 delete interface;
00441
00442 KeyListViewItem *item = 0;
00443 QString defaultkey = KGpgSettings::defaultKey();
00444 for (int i = 0; i < publiclist.size(); ++i)
00445 {
00446 KgpgKey key = publiclist.at(i);
00447
00448 bool isbold;
00449 if (defaultkey.length() == 16)
00450 isbold = (key.fullId() == defaultkey);
00451 else
00452 isbold = (key.id() == defaultkey);
00453 int index = issec.indexOf(key.fullId());
00454 if (index != -1)
00455 {
00456 key.setSecret(true);
00457 issec.removeAt(index);
00458 secretlist.removeAt(index);
00459 }
00460
00461 item = new KeyListViewItem(this, key, isbold);
00462 item->setPixmap(2, getTrustPix(key.trust(), key.valid()));
00463 item->setVisible(true);
00464 item->setExpandable(true);
00465
00466 if (key.secret())
00467 item->setPixmap(0, Images::pair());
00468 else
00469 item->setPixmap(0, Images::single());
00470 }
00471
00472 if (!issec.isEmpty())
00473 insertOrphans(secretlist);
00474
00475 if (publiclist.size() == 0)
00476 return 1;
00477 else
00478 {
00479 sort();
00480 if (publiclist.size() == 1)
00481 {
00482 clearSelection();
00483 setCurrentItem(item);
00484 }
00485 return 0;
00486 }
00487 }
00488
00489 void KeyListView::refreshcurrentkey(const QString &id)
00490 {
00491 refreshcurrentkey(findItemByKeyId(id));
00492 }
00493
00494 void KeyListView::refreshcurrentkey(KeyListViewItem *current)
00495 {
00496 if (!current)
00497 return;
00498
00499 QString keyUpdate = current->text(6);
00500 if (keyUpdate.isEmpty())
00501 return;
00502 bool keyIsOpen = current->isOpen();
00503
00504 delete current;
00505
00506 refreshKeys(QStringList(keyUpdate));
00507
00508 if (currentItem())
00509 if (currentItem()->text(6) == keyUpdate)
00510 currentItem()->setOpen(keyIsOpen);
00511 }
00512
00513 void KeyListView::refreshselfkey()
00514 {
00515 if (currentItem()->depth() == 0)
00516 refreshcurrentkey(currentItem());
00517 else
00518 refreshcurrentkey(currentItem()->parent());
00519 }
00520
00521 void KeyListView::slotReloadOrphaned()
00522 {
00523 QStringList issec;
00524
00525 KgpgInterface *interface = new KgpgInterface();
00526 KgpgKeyList listkeys, seckeys;
00527
00528 seckeys = interface->readSecretKeys();
00529 issec = seckeys;
00530 listkeys = interface->readPublicKeys(true, issec);
00531 for (int i = 0; i < listkeys.size(); ++i)
00532 issec.removeAll(listkeys.at(i).fullId());
00533
00534 delete interface;
00535
00536 QStringList::Iterator it;
00537 QStringList list;
00538 for (it = issec.begin(); it != issec.end(); ++it)
00539 if (findItemByKeyId(*it) == NULL)
00540 list += *it;
00541
00542 if (list.size() != 0)
00543 insertOrphans(seckeys);
00544
00545 setSelected(findItemByKeyId(*it), true);
00546 emit statusMessage(statusCountMessage(), 1);
00547 emit statusMessage(i18nc("No operation in progress", "Ready"), 0);
00548 }
00549
00550 void KeyListView::insertOrphans(const KgpgKeyList &keys)
00551 {
00552 KeyListViewItem *item = 0;
00553 for (int i = 0; i < keys.count(); ++i)
00554 {
00555 KgpgKey key = keys.at(i);
00556
00557 item = new KeyListViewItem(this, key, false);
00558 item->setItemType(KeyListViewItem::Secret);
00559 item->setPixmap(0, Images::orphan());
00560 }
00561
00562 if (keys.size() == 1)
00563 {
00564 clearSelection();
00565 setCurrentItem(item);
00566 setSelected(item, true);
00567 }
00568 }
00569
00570 void KeyListView::refreshGroups()
00571 {
00572 kDebug(2100) << "Refreshing groups..." ;
00573 KeyListViewItem *item = firstChild();
00574 while (item)
00575 {
00576 if (item->itemType() == KeyListViewItem::Group)
00577 {
00578 KeyListViewItem *item2 = item->nextSibling();
00579 delete item;
00580 item = item2;
00581 }
00582 else
00583 item = item->nextSibling();
00584 }
00585
00586 QStringList groups = KgpgInterface::getGpgGroupNames(KGpgSettings::gpgConfigPath());
00587 groupNb = groups.count();
00588
00589 for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it)
00590 if (!QString(*it).isEmpty())
00591 {
00592 QStringList keys = KgpgInterface::getGpgGroupSetting(QString(*it), KGpgSettings::gpgConfigPath());
00593 item = new KeyListViewItem(this, QString(*it), "-", "-", "-", i18np("%1 key", "%1 keys", keys.count()), "-", "-", false, false, KeyListViewItem::Group);
00594 item->setPixmap(0, Images::group());
00595 item->setExpandable(true);
00596 }
00597
00598 emit statusMessage(statusCountMessage(), 1);
00599 emit statusMessage(i18nc("No operation in progress", "Ready"), 0);
00600 }
00601
00602 void KeyListView::refreshTrust(int color, const QColor &newColor)
00603 {
00604 if (!newColor.isValid())
00605 return;
00606
00607 QPixmap blankFrame;
00608 QPixmap newtrust;
00609 int trustFinger = 0;
00610
00611 blankFrame.load(KStandardDirs::locate("appdata", "pics/kgpg_blank.png"));
00612 newtrust.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
00613 newtrust.fill(newColor);
00614
00615 QPainter p(&newtrust);
00616 p.drawPixmap(QPoint(0, 0), blankFrame, QRect(0, 0, 50, 15));
00617
00618 switch (color)
00619 {
00620 case kgpgOptions::UltimateColor:
00621 trustFinger = trustultimate.serialNumber();
00622 trustultimate = newtrust;
00623 break;
00624
00625 case kgpgOptions::GoodColor:
00626 trustFinger = trustgood.serialNumber();
00627 trustgood = newtrust;
00628 break;
00629
00630 case kgpgOptions::MarginalColor:
00631 trustFinger = trustmarginal.serialNumber();
00632 trustmarginal = newtrust;
00633 break;
00634
00635 case kgpgOptions::ExpiredColor:
00636 trustFinger = trustexpired.serialNumber();
00637 trustexpired = newtrust;
00638 break;
00639
00640 case kgpgOptions::BadColor:
00641 trustFinger = trustbad.serialNumber();
00642 trustbad = newtrust;
00643 break;
00644
00645 case kgpgOptions::UnknownColor:
00646 trustFinger = trustunknown.serialNumber();
00647 trustunknown = newtrust;
00648 break;
00649
00650 case kgpgOptions::RevColor:
00651 trustFinger = trustrevoked.serialNumber();
00652 trustrevoked = newtrust;
00653 break;
00654 }
00655
00656 KeyListViewItem *item = firstChild();
00657 while (item)
00658 {
00659 if (item->pixmap(2))
00660 if (item->pixmap(2)->serialNumber() == trustFinger)
00661 item->setPixmap(2, newtrust);
00662 item = item->nextSibling();
00663 }
00664 }
00665
00666 void KeyListView::expandKey(Q3ListViewItem *item2)
00667 {
00668 KeyListViewItem *item = static_cast<KeyListViewItem *>(item2);
00669
00670 if (item->childCount() != 0)
00671 return;
00672
00673 if (item->itemType() == KeyListViewItem::Group) {
00674 expandGroup(item);
00675 return;
00676 }
00677
00678 QString keyid = item->keyId();
00679
00680 KgpgInterface *interface = new KgpgInterface();
00681 KgpgKeyList keys = interface->readPublicKeys(true, keyid, true);
00682 KgpgKey key = keys.at(0);
00683
00684 KeyListViewItem *tmpitem;
00685
00686
00687
00688 for (int i = 0; i < key.subList()->size(); ++i)
00689 {
00690 KgpgKeySub sub = key.subList()->at(i);
00691
00692 QString algo = i18n("%1 subkey", Convert::toString(sub.algorithm()));
00693 tmpitem = new KeyListViewItem(item, algo, QString(), QString(), sub.expiration(), QString::number(sub.size()), sub.creation(), sub.id(), false, false, KeyListViewItem::Sub);
00694 tmpitem->setPixmap(0, Images::single());
00695 tmpitem->setPixmap(2, getTrustPix(sub.trust(), sub.valid()));
00696 insertSigns(tmpitem, sub.signList());
00697 }
00698
00699
00700
00701
00702 for (int i = 0; i < key.uidList()->size(); ++i)
00703 {
00704 KgpgKeyUid uid = key.uidList()->at(i);
00705 QString index;
00706
00707 index.setNum(uid.index());
00708
00709 tmpitem = new KeyListViewItem(item, uid.name(), uid.email(), QString(), "-", "-", "-", index, false, false, KeyListViewItem::Uid);
00710 tmpitem->setPixmap(2, getTrustPix(key.trust(), key.valid()));
00711 tmpitem->setPixmap(0, Images::userId());
00712 insertSigns(tmpitem, uid.signList());
00713 }
00714
00715
00716
00717
00718 QStringList photolist = key.photoList();
00719 for (int i = 0; i < photolist.size(); ++i)
00720 {
00721 KgpgKeyUat uat = key.uatList()->at(i);
00722 tmpitem = new KeyListViewItem(item, i18n("Photo id"), QString(), QString(), "-", "-", uat.creation(), photolist.at(i), false, false, KeyListViewItem::Uat);
00723 tmpitem->setPixmap(2, getTrustPix(key.trust(), key.valid()));
00724
00725 if (m_displayphoto)
00726 {
00727 QPixmap pixmap = interface->loadPhoto(keyid, photolist.at(i), true);
00728 tmpitem->setPixmap(0, pixmap.scaled(m_previewsize + 5, m_previewsize, Qt::KeepAspectRatio));
00729 }
00730 else
00731 tmpitem->setPixmap(0, Images::photo());
00732
00733 insertSigns(tmpitem, uat.signList());
00734 }
00735
00736
00737 delete interface;
00738
00739
00740 insertSigns(item, key.signList());
00741
00742 }
00743
00744 void KeyListView::insertSigns(KeyListViewItem *item, const KgpgKeySignList &list)
00745 {
00746 for (int i = 0; i < list.size(); ++i)
00747 {
00748 (void) new KeyListViewItem(item, list.at(i));
00749 }
00750 }
00751
00752 void KeyListView::expandGroup(KeyListViewItem *item)
00753 {
00754 QStringList keysGroup = KgpgInterface::getGpgGroupSetting(item->text(0), KGpgSettings::gpgConfigPath());
00755
00756 kDebug(2100) << keysGroup ;
00757
00758 for (QStringList::Iterator it = keysGroup.begin(); it != keysGroup.end(); ++it)
00759 {
00760 KeyListViewItem *item2 = new KeyListViewItem(item, QString(*it));
00761 KeyListViewItem *target = findItemByKeyId(QString(*it));
00762
00763 if (target == NULL) {
00764 item2->setPixmap(0, Images::single());
00765 item2->setItemType(KeyListViewItem::GPublic);
00766 } else {
00767 item2->setPixmap(0, *target->pixmap(0));
00768 item2->setText(0, target->text(0));
00769 item2->setItemType(target->itemType() | KeyListViewItem::Group);
00770 item2->setGroupId(QString(*it));
00771 }
00772 item2->setText(6, QString(*it).right(8));
00773 item2->setExpandable(false);
00774 }
00775 }
00776
00777 QPixmap KeyListView::getTrustPix(const KgpgKeyTrust &trust, const bool &isvalid)
00778 {
00779 if (!isvalid)
00780 return trustbad;
00781 switch (trust) {
00782 case TRUST_ULTIMATE: return trustultimate;
00783 case TRUST_FULL: return trustgood;
00784 case TRUST_REVOKED: return trustrevoked;
00785 case TRUST_INVALID:
00786 case TRUST_DISABLED: return trustbad;
00787 case TRUST_EXPIRED: return trustexpired;
00788 case TRUST_MARGINAL: return trustmarginal;
00789 case TRUST_UNKNOWN:
00790 case TRUST_UNDEFINED:
00791 case TRUST_NONE: return trustunknown;
00792 default:
00793 kDebug(3125) << "Oops, unmatched trust value " << trust ;
00794 return trustunknown;
00795 }
00796 }
00797
00798 QList<KeyListViewItem *> KeyListView::selectedItems(void)
00799 {
00800 QList<KeyListViewItem *> list;
00801
00802 Q3ListViewItemIterator it(this, Q3ListViewItemIterator::Selected);
00803
00804 for(; it.current(); ++it) {
00805 Q3ListViewItem *q = Q3ListViewItem(*it).parent();
00806 if ((q->depth() > 0) && !q->parent()->isOpen())
00807 continue;
00808 list.append(static_cast<KeyListViewItem*>(q));
00809 }
00810
00811 return list;
00812 }
00813
00820 KeyListViewItem *KeyListView::findItemByKeyId(const QString &id)
00821 {
00822 QString fullid = id.right(16);
00823 KeyListViewItem *cur = findItem(fullid.right(8), 6);
00824
00825 if ((cur == NULL) || ((fullid.length() < 16) && (cur->getKey() != NULL)))
00826 return cur;
00827
00828 KgpgKey *key = cur->getKey();
00829 if ((key != NULL) && (key->fullId() == id))
00830 return cur;
00831
00832
00833 Q3ListViewItemIterator it(this);
00834
00835 for(; it.current(); ++it) {
00836 cur = static_cast<KeyListViewItem*>(it.current());
00837 key = cur->getKey();
00838 if (key == NULL)
00839 continue;
00840 if (key->fullId() == fullid)
00841 return cur;
00842 }
00843 return NULL;
00844 }
00845
00846 QString KeyListView::statusCountMessage(void)
00847 {
00848 QString kmsg = i18np("1 Key", "%1 Keys", childCount() - groupNb);
00849
00850 if (groupNb == 0) {
00851 return kmsg;
00852 } else {
00853 QString gmsg = i18np("1 Group", "%1 Groups", groupNb);
00854
00855 return kmsg + ", " + gmsg;
00856 }
00857 }
00858
00859 KeyListViewSearchLine::KeyListViewSearchLine(QWidget *parent, KeyListView *listView)
00860 : K3ListViewSearchLine(parent, listView)
00861 {
00862 m_searchlistview = listView;
00863 setKeepParentsVisible(false);
00864 m_hidepublic = false;
00865 m_hidedisabled = false;
00866 }
00867
00868 void KeyListViewSearchLine::setHidePublic(const bool &hidepublic)
00869 {
00870 m_hidepublic = hidepublic;
00871 }
00872
00873 bool KeyListViewSearchLine::hidePublic() const
00874 {
00875 return m_hidepublic;
00876 }
00877
00878 void KeyListViewSearchLine::setHideDisabled(const bool &hidedisabled)
00879 {
00880 m_hidedisabled = hidedisabled;
00881 }
00882
00883 bool KeyListViewSearchLine::hideDisabled() const
00884 {
00885 return m_hidedisabled;
00886 }
00887
00888 void KeyListViewSearchLine::updateSearch(const QString& s)
00889 {
00890 K3ListViewSearchLine::updateSearch(s);
00891
00892 if (m_hidepublic || m_hidedisabled)
00893 {
00894 KeyListViewItem *item = m_searchlistview->firstChild();
00895 while (item)
00896 {
00897 if (item->isVisible())
00898 {
00899 if (m_hidepublic)
00900 if ((item->itemType() == KeyListViewItem::Public) && (item->itemType() != KeyListViewItem::Secret)) {
00901 item->setVisible(false);
00902 continue;
00903 }
00904
00905 if (m_hidedisabled) {
00906 KgpgKey *key = item->getKey();
00907 if (item->isExpired() || (key && (key->trust() == TRUST_REVOKED)))
00908 item->setVisible(false);
00909 }
00910
00911 }
00912 item = item->nextSibling();
00913 }
00914 }
00915 }
00916
00917 bool KeyListViewSearchLine::itemMatches(const Q3ListViewItem *item, const QString &s) const
00918 {
00919 if (item->depth() != 0)
00920 return true;
00921 else
00922 return K3ListViewSearchLine::itemMatches(item, s);
00923 }
00924
00925 #include "keylistview.moc"