Commit e1febf94 authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

remove a bunch of already dead code

svn path=/branches/work/kgpg2/; revision=763814
parent dc009e5c
......@@ -29,28 +29,6 @@
#include "convert.h"
#include "images.h"
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)
: K3ListViewItem(parent, name, email, trust, expiration, size, creation, id)
{
m_def = isdefault;
m_exp = isexpired;
m_type = type;
m_key = NULL;
m_sig = NULL;
groupId = NULL;
}
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)
: K3ListViewItem(parent, name, email, trust, expiration, size, creation, id)
{
m_def = isdefault;
m_exp = isexpired;
m_type = type;
m_key = NULL;
m_sig = NULL;
groupId = NULL;
}
KeyListViewItem::KeyListViewItem(K3ListView *parent, const KgpgKey &key, const bool isbold)
: K3ListViewItem(parent)
{
......@@ -116,113 +94,11 @@ KeyListViewItem::~KeyListViewItem()
delete groupId;
}
void KeyListViewItem::setItemType(const ItemType &type)
{
m_type = type;
}
KeyListViewItem::ItemType KeyListViewItem::itemType() const
{
return m_type;
}
void KeyListViewItem::setDefault(const bool &def)
{
m_def = def;
}
bool KeyListViewItem::isDefault() const
{
return m_def;
}
void KeyListViewItem::setExpired(const bool &exp)
{
m_exp = exp;
}
bool KeyListViewItem::isExpired() const
{
return m_exp;
}
void KeyListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
QColorGroup _cg(cg);
if (itemType() & Public)
{
if (m_def && (column < 2))
{
QFont font(p->font());
font.setBold(true);
p->setFont(font);
}
else
if (m_exp && (column == 3))
_cg.setColor(QPalette::Text, Qt::red);
}
else
if (column < 2)
{
QFont font(p->font());
font.setItalic(true);
p->setFont(font);
}
K3ListViewItem::paintCell(p, _cg, column, width, alignment);
}
int KeyListViewItem::compare(Q3ListViewItem *itemx, int c, bool ascending) const
{
KeyListViewItem *item = static_cast<KeyListViewItem *>(itemx);
switch (c) {
case 3: // expiration date
case 5: { // creation date
QDate d = KGlobal::locale()->readDate(text(c));
QDate itemDate = KGlobal::locale()->readDate(item->text(c));
bool thisDateValid = d.isValid();
bool itemDateValid = itemDate.isValid();
if (thisDateValid) {
if (itemDateValid) {
if (d < itemDate) return -1;
if (d > itemDate) return 1;
} else
return -1;
} else if (itemDateValid)
return 1;
return 0;
}
case 2: { // trust
if (trust() < item->trust()) return -1;
if (trust() > item->trust()) return 1;
return 0;
}
case 0: {
ItemType item1 = itemType();
ItemType item2 = item->itemType();
bool test1 = (item1 & KeyListViewItem::Public) && !(item1 & KeyListViewItem::Secret); // only a public key
bool test2 = (item2 & KeyListViewItem::Public) && !(item2 & KeyListViewItem::Secret); // only a public key
// key-pair goes before simple public key
if (item1 == KeyListViewItem::Pair && test2) return -1;
if (item2 == KeyListViewItem::Pair && test1) return 1;
if (item1 < item2) return -1;
if (item1 > item2) return 1;
// fallthrough
}
default:
return K3ListViewItem::compare(item, c, ascending);
}
}
QString KeyListViewItem::key(int column, bool) const
{
return text(column).toLower();
......@@ -276,298 +152,11 @@ KeyListView::KeyListView(QWidget *parent)
trustexpired.fill(Convert::toColor(TRUST_EXPIRED));
QPainter(&trustexpired).drawPixmap(rect, blankFrame);
connect(this, SIGNAL(expanded(Q3ListViewItem *)), this, SLOT(expandKey(Q3ListViewItem *)));
header()->setMovingEnabled(false);
setAcceptDrops(true);
setDragEnabled(true);
}
void KeyListView::slotAddColumn(const int &c)
{
header()->setResizeEnabled(true, c);
adjustColumn(c);
}
void KeyListView::slotRemoveColumn(const int &c)
{
hideColumn(c);
header()->setResizeEnabled(false, c);
header()->setStretchEnabled(true, 6);
}
void KeyListView::contentsDragMoveEvent(QDragMoveEvent *e)
{
e->setAccepted(KUrl::List::canDecode(e->mimeData()));
}
void KeyListView::contentsDropEvent(QDropEvent *o)
{
KUrl::List uriList = KUrl::List::fromMimeData(o->mimeData());
if (!uriList.isEmpty())
droppedFile(uriList.first());
}
void KeyListView::startDrag()
{
KeyListViewItem *ki = currentItem();
QString keyid = ki->text(6);
if (!(ki->itemType() & KeyListViewItem::Public))
return;
KgpgInterface *interface = new KgpgInterface();
QString keytxt = interface->getKeys(NULL, QStringList(keyid));
delete interface;
Q3DragObject *d = new Q3TextDrag(keytxt, this);
d->dragCopy();
// do NOT delete d.
}
void KeyListView::droppedFile(const KUrl &url)
{
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)
return;
KgpgInterface *interface = new KgpgInterface();
connect(interface, SIGNAL(importKeyFinished(QStringList)), this, SLOT(slotReloadKeys(QStringList)));
interface->importKey(url);
}
void KeyListView::slotReloadKeys(const QStringList &keyids)
{
if (keyids.isEmpty())
return;
if (keyids.first() == "ALL")
{
refreshAll();
return;
}
refreshKeys(keyids);
ensureItemVisible(this->findItemByKeyId(keyids.last()));
emit statusMessage(statusCountMessage(), 1);
emit statusMessage(i18nc("No operation in progress", "Ready"), 0);
}
void KeyListView::refreshAll()
{
emit statusMessage(i18n("Loading Keys..."), 0, true);
kapp->processEvents();
// update display of keys in main management window
kDebug(2100) << "Refreshing All" ;
// get current position.
KeyListViewItem *current = currentItem();
if(current != 0)
{
while(current->depth() > 0)
current = current->parent();
takeItem(current);
}
// clear the list
clear();
if (refreshKeys())
{
kDebug(2100) << "No key found" ;
emit statusMessage(i18nc("No operation in progress", "Ready"), 0);
return;
}
KeyListViewItem *newPos = NULL;
if(current != 0)
{
// select previous selected
if (!current->text(6).isEmpty())
newPos = findItemByKeyId(current->keyId());
else
newPos = findItem(current->text(0), 0);
delete current;
}
/* if (newPos != NULL)
{
setCurrentItem(newPos);
setSelected(newPos, true);
ensureItemVisible(newPos);
}
else
{
setCurrentItem(firstChild());
setSelected(firstChild(), true);
}*/
emit statusMessage(statusCountMessage(), 1);
emit statusMessage(i18nc("No operation in progress", "Ready"),0);
kDebug(2100) << "Refresh Finished" ;
}
bool KeyListView::refreshKeys(const QStringList &ids)
{
KgpgInterface *interface = new KgpgInterface();
KgpgKeyList secretlist = interface->readSecretKeys(ids);
QStringList issec = secretlist;
KgpgKeyList publiclist = interface->readPublicKeys(true, ids);
delete interface;
KeyListViewItem *item = 0;
QString defaultkey = KGpgSettings::defaultKey();
for (int i = 0; i < publiclist.size(); ++i)
{
KgpgKey key = publiclist.at(i);
bool isbold;
if (defaultkey.length() == 16)
isbold = (key.fullId() == defaultkey);
else
isbold = (key.id() == defaultkey);
int index = issec.indexOf(key.fullId());
if (index != -1)
{
key.setSecret(true);
issec.removeAt(index);
secretlist.removeAt(index);
}
item = new KeyListViewItem(this, key, isbold);
item->setPixmap(2, getTrustPix(key.trust(), key.valid()));
item->setVisible(true);
item->setExpandable(true);
if (key.secret())
item->setPixmap(0, Images::pair());
else
item->setPixmap(0, Images::single());
}
if (publiclist.size() == 0)
return 1;
else
{
sort();
if (publiclist.size() == 1)
{
clearSelection();
setCurrentItem(item);
}
return 0;
}
}
void KeyListView::expandKey(Q3ListViewItem *item2)
{
KeyListViewItem *item = static_cast<KeyListViewItem *>(item2);
if (item->childCount() != 0)
return; // key has already been expanded
if (item->itemType() == KeyListViewItem::Group) {
return;
}
QString keyid = item->keyId();
KgpgInterface *interface = new KgpgInterface();
KgpgKeyList keys = interface->readPublicKeys(true, keyid, true);
KgpgKey key = keys.at(0);
KeyListViewItem *tmpitem;
/********* insertion of sub keys ********/
for (int i = 0; i < key.subList()->size(); ++i)
{
KgpgKeySub sub = key.subList()->at(i);
QString algo = i18n("%1 subkey", Convert::toString(sub.algorithm()));
tmpitem = new KeyListViewItem(item, algo, QString(), QString(), sub.expiration(), QString::number(sub.size()), sub.creation(), sub.id(), false, false, KeyListViewItem::Sub);
tmpitem->setPixmap(0, Images::single());
tmpitem->setPixmap(2, getTrustPix(sub.trust(), sub.valid()));
insertSigns(tmpitem, sub.signList());
}
/****************************************/
/********* insertion of users id ********/
for (int i = 0; i < key.uidList()->size(); ++i)
{
KgpgKeyUid uid = key.uidList()->at(i);
QString index;
index.setNum(uid.index());
tmpitem = new KeyListViewItem(item, uid.name(), uid.email(), QString(), "-", "-", "-", index, false, false, KeyListViewItem::Uid);
tmpitem->setPixmap(2, getTrustPix(key.trust(), key.valid()));
tmpitem->setPixmap(0, Images::userId());
insertSigns(tmpitem, uid.signList());
}
/****************************************/
/******** insertion of photos id ********/
QStringList photolist = key.photoList();
for (int i = 0; i < photolist.size(); ++i)
{
KgpgKeyUat uat = key.uatList()->at(i);
tmpitem = new KeyListViewItem(item, i18n("Photo id"), QString(), QString(), "-", "-", uat.creation(), photolist.at(i), false, false, KeyListViewItem::Uat);
tmpitem->setPixmap(2, getTrustPix(key.trust(), key.valid()));
if (m_displayphoto)
{
QPixmap pixmap = interface->loadPhoto(keyid, photolist.at(i), true);
tmpitem->setPixmap(0, pixmap.scaled(m_previewsize + 5, m_previewsize, Qt::KeepAspectRatio));
}
else
tmpitem->setPixmap(0, Images::photo());
insertSigns(tmpitem, uat.signList());
}
/****************************************/
delete interface;
/******** insertion of signature ********/
insertSigns(item, key.signList());
/****************************************/
}
void KeyListView::insertSigns(KeyListViewItem *item, const KgpgKeySignList &list)
{
for (int i = 0; i < list.size(); ++i)
{
(void) new KeyListViewItem(item, list.at(i));
}
}
QPixmap KeyListView::getTrustPix(const KgpgKeyTrust &trust, const bool &isvalid)
{
if (!isvalid)
return trustbad;
switch (trust) {
case TRUST_ULTIMATE: return trustultimate;
case TRUST_FULL: return trustgood;
case TRUST_REVOKED: return trustrevoked;
case TRUST_INVALID:
case TRUST_DISABLED: return trustbad;
case TRUST_EXPIRED: return trustexpired;
case TRUST_MARGINAL: return trustmarginal;
case TRUST_UNKNOWN:
case TRUST_UNDEFINED:
case TRUST_NONE: return trustunknown;
default:
kDebug(3125) << "Oops, unmatched trust value " << trust ;
return trustunknown;
}
}
QList<KeyListViewItem *> KeyListView::selectedItems(void)
{
QList<KeyListViewItem *> list;
......@@ -584,38 +173,6 @@ QList<KeyListViewItem *> KeyListView::selectedItems(void)
return list;
}
/**
* Find the item that is a primary key with the given id. Match will be
* by full id if possible, else by short id. Passing a fingerprint is
* explicitly allowed (forward compatibility) but currently matching
* is only done by full id.
*/
KeyListViewItem *KeyListView::findItemByKeyId(const QString &id)
{
QString fullid = id.right(16);
KeyListViewItem *cur = findItem(fullid.right(8), 6);
if ((cur == NULL) || ((fullid.length() < 16) && (cur->getKey() != NULL)))
return cur;
KgpgKey *key = cur->getKey();
if ((key != NULL) && (key->fullId() == id))
return cur;
// The first hit doesn't match the full id. Do deep scanning.
Q3ListViewItemIterator it(this);
for(; it.current(); ++it) {
cur = static_cast<KeyListViewItem*>(it.current());
key = cur->getKey();
if (key == NULL)
continue;
if (key->fullId() == fullid)
return cur;
}
return NULL;
}
QString KeyListView::statusCountMessage(void)
{
QString kmsg = i18np("1 Key", "%1 Keys", childCount() - groupNb);
......
......@@ -49,30 +49,18 @@ public:
};
Q_DECLARE_FLAGS(ItemType, ItemTypeFlag)
explicit KeyListViewItem(KeyListView *parent, const QString &name = QString(), const QString &email = QString(), const QString &trust = QString(), const QString &expiration = QString(), const QString &size = QString(), const QString &creation = QString(), const QString &id = QString() , const bool isdefault = false, const bool isexpired = false, ItemType type = Public);
explicit KeyListViewItem(KeyListViewItem *parent, const QString &name = QString(), const QString &email = QString(), const QString &trust = QString(), const QString &expiration = QString(), const QString &size = QString(), const QString &creation = QString(), const QString &id = QString(), const bool isdefault = false, const bool isexpired = false, ItemType type = Public);
KeyListViewItem(K3ListView *parent, const KgpgKey &key, const bool isbold);
KeyListViewItem(K3ListViewItem *parent, const KgpgKeySign &sig);
~KeyListViewItem();
void setItemType(const ItemType &type);
ItemType itemType() const;
void setDefault(const bool &def);
bool isDefault() const;
void setExpired(const bool &exp);
bool isExpired() const;
void setGroupId(const QString &nid) { delete groupId; groupId = new QString(nid); }
virtual void paintCell(QPainter *p, const QColorGroup &cg, int col, int width, int align);
virtual int compare(Q3ListViewItem *item, int c, bool ascending) const;
virtual QString key(int column, bool) const;
virtual KeyListViewItem *parent() const { return static_cast<KeyListViewItem*>(K3ListViewItem::parent()); }
virtual KeyListViewItem *nextSibling() const { return static_cast<KeyListViewItem*>(K3ListViewItem::nextSibling()); }
virtual KeyListViewItem *firstChild() const { return static_cast<KeyListViewItem*>(K3ListViewItem::firstChild()); }
virtual KgpgKey* getKey() { return m_key; }
virtual const QString keyId(void) const { return m_key ? m_key->fullId() : m_sig ? m_sig->fullId() : groupId ? *groupId : text(6); }
KgpgKeyTrust trust(void) const { return m_key ? m_key->trust() : TRUST_NOKEY; }
......@@ -99,46 +87,20 @@ public:
signals:
void statusMessage(QString, int, bool keep = false);
/* void expanded(KeyListViewItem *);
void returnPressed(KeyListViewItem *);
void doubleClicked(KeyListViewItem *, QPoint, int);
void contextMenuRequested(KeyListViewItem*, QPoint, int);*/
public slots:
void slotAddColumn(const int &c);
void slotRemoveColumn(const int &c);
virtual KeyListViewItem *firstChild() { return static_cast<KeyListViewItem*>(K3ListView::firstChild()); }
QString statusCountMessage(void);
protected:
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
virtual void contentsDropEvent(QDropEvent *e);
virtual void startDrag();
virtual KeyListViewItem *currentItem() const { return static_cast<KeyListViewItem*>(K3ListView::currentItem()); }
virtual KeyListViewItem *findItem (const QString &text, int column, ComparisonFlags compare = ExactMatch | Qt::CaseSensitive) const
{ return static_cast<KeyListViewItem *>(K3ListView::findItem(text, column, compare)); }
virtual QList<KeyListViewItem *> selectedItems(void);
virtual KeyListViewItem *lastChild() const { return static_cast<KeyListViewItem*>(K3ListView::lastChild()); }
virtual KeyListViewItem *itemAtIndex(int index) { return static_cast<KeyListViewItem*>(K3ListView::itemAtIndex(index)); }
virtual KeyListViewItem *findItemByKeyId(const QString &id);
private slots:
void droppedFile(const KUrl &url);
void slotReloadKeys(const QStringList &keyids);
void refreshAll();
bool refreshKeys(const QStringList &ids = QStringList());
void expandKey(Q3ListViewItem *item);
void insertSigns(KeyListViewItem *item, const KgpgCore::KgpgKeySignList &list);
private:
QPixmap getTrustPix(const KgpgCore::KgpgKeyTrust &trust, const bool &isvalid);
private:
QString photoKeysList;
QPixmap trustunknown;
QPixmap trustrevoked;
QPixmap trustgood;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment