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

KeyListView, rest in pieces

svn path=/trunk/KDE/kdeutils/kgpg/; revision=773515
parent ed1938fb
......@@ -33,7 +33,6 @@ set(kgpg_SRCS ${core_SRCS}
detailedconsole.cpp
kgpglibrary.cpp
keyinfodialog.cpp
keylistview.cpp
newkey.cpp
keyexport.cpp
conf_encryption.cpp
......
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "keylistview.h"
#include <QPainter>
#include <QRect>
#include <Q3ListViewItem>
#include <Q3Header>
#include <kabc/stdaddressbook.h>
#include <KStandardDirs>
#include <KLocale>
#include "kgpgsettings.h"
#include "kgpgoptions.h"
#include "convert.h"
#include "images.h"
KeyListViewItem::KeyListViewItem(K3ListView *parent, const KgpgKey &key, const bool isbold)
: K3ListViewItem(parent)
{
m_def = isbold;
m_exp = (key.trust() == TRUST_EXPIRED);
m_type = Public;
m_key = new KgpgKey(key);
m_sig = NULL;
groupId = NULL;
if (key.secret())
m_type |= Secret;
if (key.comment().isEmpty())
setText(0, key.name());
else
setText(0, i18nc("Name (Comment)", "%1 (%2)", key.name(), key.comment()));
setText(1, key.email());
setText(2, QString());
setText(3, key.expiration());
setText(4, QString::number(key.size()));
setText(5, key.creation());
setText(6, key.id());
}
KeyListViewItem::KeyListViewItem(K3ListViewItem *parent, const KgpgKeySign &sig)
: K3ListViewItem(parent)
{
m_def = false;
m_exp = false; // TODO: sign expiration
m_type = Sign;
m_key = NULL;
groupId = NULL;
m_sig = new KgpgKeySign(sig);
QString tmpname = sig.name();
if (!sig.comment().isEmpty())
tmpname += " (" + sig.comment() + ')';
setText(0, tmpname);
QString tmpemail = sig.email();
if (sig.local())
tmpemail += i18n(" [local signature]");
if (sig.revocation()) {
tmpemail += i18n(" [Revocation signature]");
setPixmap(0, Images::revoke());
m_type = RevSign;
} else
setPixmap(0, Images::signature());
setText(1, tmpemail);
setText(2, "-");
setText(3, sig.expiration());
setText(4, "-");
setText(5, sig.creation());
setText(6, sig.id());
}
KeyListViewItem::~KeyListViewItem()
{
delete m_key;
delete m_sig;
delete groupId;
}
KeyListViewItem::ItemType KeyListViewItem::itemType() const
{
return m_type;
}
QString KeyListViewItem::key(int column, bool) const
{
return text(column).toLower();
}
KeyListView::KeyListView(QWidget *parent)
: K3ListView(parent)
{
setRootIsDecorated(true);
addColumn(i18nc("Name of key owner", "Name"), 230);
addColumn(i18nc("Email address of key owner", "Email"), 220);
addColumn(i18n("Trust"), 60);
addColumn(i18n("Expiration"), 100);
addColumn(i18n("Size"), 50);
addColumn(i18n("Creation"), 100);
addColumn(i18n("Id"), 100);
setShowSortIndicator(true);
setAllColumnsShowFocus(true);
setFullWidth(true);
setAcceptDrops(true) ;
setSelectionModeExt(Extended);
QPixmap blankFrame(KStandardDirs::locate("appdata", "pics/kgpg_blank.png"));
QRect rect(0, 0, 50, 15);
trustunknown.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustunknown.fill(Convert::toColor(TRUST_UNKNOWN));
QPainter(&trustunknown).drawPixmap(rect, blankFrame);
trustbad.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustbad.fill(Convert::toColor(TRUST_DISABLED));
QPainter(&trustbad).drawPixmap(rect, blankFrame);
trustrevoked.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustrevoked.fill(Convert::toColor(TRUST_REVOKED));
QPainter(&trustrevoked).drawPixmap(rect, blankFrame);
trustgood.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustgood.fill(Convert::toColor(TRUST_FULL));
QPainter(&trustgood).drawPixmap(rect, blankFrame);
trustultimate.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustultimate.fill(Convert::toColor(TRUST_ULTIMATE));
QPainter(&trustultimate).drawPixmap(rect, blankFrame);
trustmarginal.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustmarginal.fill(Convert::toColor(TRUST_MARGINAL));
QPainter(&trustmarginal).drawPixmap(rect, blankFrame);
trustexpired.load(KStandardDirs::locate("appdata", "pics/kgpg_fill.png"));
trustexpired.fill(Convert::toColor(TRUST_EXPIRED));
QPainter(&trustexpired).drawPixmap(rect, blankFrame);
header()->setMovingEnabled(false);
setAcceptDrops(true);
setDragEnabled(true);
}
QList<KeyListViewItem *> KeyListView::selectedItems(void)
{
QList<KeyListViewItem *> list;
Q3ListViewItemIterator it(this, Q3ListViewItemIterator::Selected);
for(; it.current(); ++it) {
Q3ListViewItem *q = Q3ListViewItem(*it).parent();
if ((q->depth() > 0) && !q->parent()->isOpen())
continue;
list.append(static_cast<KeyListViewItem*>(q));
}
return list;
}
QString KeyListView::statusCountMessage(void)
{
QString kmsg = i18np("1 Key", "%1 Keys", childCount() - groupNb);
if (groupNb == 0) {
return kmsg;
} else {
QString gmsg = i18np("1 Group", "%1 Groups", groupNb);
return kmsg + ", " + gmsg;
}
}
#include "keylistview.moc"
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KEYLISTVIEW_H
#define KEYLISTVIEW_H
#include <QPixmap>
#include <K3ListViewSearchLine>
#include <K3ListView>
#include "kgpgkey.h"
using namespace KgpgCore;
class KeyListView;
class KeyListViewItem : public K3ListViewItem
{
public:
enum ItemTypeFlag
{
Group = 1,
Secret = 2,
Public = 4,
Pair = Secret | Public,
GSecret = Group | Secret,
GPublic = Group | Public,
GPair = Group | Pair,
Sub = 8,
Uid = 16,
Uat = 32,
RevSign = 64,
Sign = 128
};
Q_DECLARE_FLAGS(ItemType, ItemTypeFlag)
KeyListViewItem(K3ListView *parent, const KgpgKey &key, const bool isbold);
KeyListViewItem(K3ListViewItem *parent, const KgpgKeySign &sig);
~KeyListViewItem();
ItemType itemType() const;
bool isDefault() 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 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; }
private:
bool m_def; /// Is set to \em true if it is the default key, \em false otherwise.
bool m_exp; /// Is set to \em true if the key is expired, \em false otherwise.
ItemType m_type;
KgpgKey *m_key;
KgpgKeySign *m_sig;
QString *groupId;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KeyListViewItem::ItemType)
class KeyListView : public K3ListView
{
Q_OBJECT
friend class KeysManager;
public:
KeyListView(QWidget *parent = 0);
QPixmap trustbad;
signals:
void statusMessage(QString, int, bool keep = false);
public slots:
virtual KeyListViewItem *firstChild() { return static_cast<KeyListViewItem*>(K3ListView::firstChild()); }
QString statusCountMessage(void);
protected:
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)); }
private:
QPixmap trustunknown;
QPixmap trustrevoked;
QPixmap trustgood;
QPixmap trustultimate;
QPixmap trustexpired;
QPixmap trustmarginal;
int groupNb;
int m_previewsize;
bool m_displayphoto;
};
#endif // KEYLISTVIEW_H
......@@ -84,7 +84,6 @@
#include "kgpgoptions.h"
#include "keyinfodialog.h"
#include "kgpglibrary.h"
#include "keylistview.h"
#include "keyadaptor.h"
#include "images.h"
#include "sourceselect.h"
......@@ -428,10 +427,6 @@ KeysManager::KeysManager(QWidget *parent)
m_statusbar->setItemAlignment(0, Qt::AlignLeft);
m_statusbar->changeItem("", 1);
#ifdef __GNUC__
#warning port me
#endif
// connect(keysList2, SIGNAL(statusMessage(QString, int, bool)), this, SLOT(changeMessage(QString, int, bool)));
connect(m_statusbartimer, SIGNAL(timeout()), this, SLOT(statusBarTimeout()));
s_kgpgEditor = new KgpgEditor(parent, Qt::WType_Dialog, qobject_cast<KAction *>(actionCollection()->action("go_default_key"))->shortcut(), true);
......@@ -900,6 +895,7 @@ return;
#ifdef __GNUC__
#warning port me
#endif
#if 0
bool foundItem = true;
KeyListViewItem *item = keysList2->firstChild();
if (!item)
......@@ -933,6 +929,7 @@ return;
}
else
KMessageBox::sorry(this, i18n("<qt>Search string '<b>%1</b>' not found.</qt>", searchString));
#endif
}
void KeysManager::findNextKey()
......@@ -948,6 +945,7 @@ return;
#ifdef __GNUC__
#warning port me
#endif
#if 0
bool foundItem = true;
KeyListViewItem *item = keysList2->currentItem();
if (!item)
......@@ -989,6 +987,7 @@ return;
}
else
findFirstKey();
#endif
}
void KeysManager::addToKAB()
......@@ -2129,6 +2128,7 @@ void KeysManager::slotPreImportKey()
void KeysManager::refreshkey()
{
imodel->refreshKeys();
changeMessage(imodel->statusCountMessage(), 1);
}
KGpgTransaction::KGpgTransaction()
......
......@@ -21,14 +21,11 @@
#include <QClipboard>
#include <KToggleAction>
#include <K3ListViewSearchLine>
#include <KXmlGuiWindow>
#include <KDialog>
#include <K3ListView>
#include <KUrl>
#include "kgpgkey.h"
#include "keylistview.h"
#include "ui_adduid.h"
#include "kgpginterface.h"
#include "kgpgitemmodel.h"
......@@ -182,13 +179,11 @@ private:
KGpgItemModel *imodel;
KeyListProxyModel *iproxy;
KeyTreeView *iview;
KeyListView *keysList2;
QString globalkeyID;
QString searchString;
QList<KGpgNode *> signList;
QList<KeyListViewItem*> keysList;
QClipboard::Mode m_clipboardmode;
QTimer *m_statusbartimer;
......
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