00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef KEYLISTVIEW_H
00011 #define KEYLISTVIEW_H
00012
00013 #include <QColorGroup>
00014 #include <QPixmap>
00015
00016
00017 #include <K3ListViewSearchLine>
00018 #include <K3ListView>
00019 #include <KUrl>
00020
00021 #include "kgpgkey.h"
00022
00023 using namespace KgpgCore;
00024
00025 class Q3ListViewItem;
00026 class QDragMoveEvent;
00027 class QDropEvent;
00028 class QPainter;
00029
00030 class KeyListView;
00031
00032 class KeyListViewItem : public K3ListViewItem
00033 {
00034 public:
00035 enum ItemTypeFlag
00036 {
00037 Group = 1,
00038 Secret = 2,
00039 Public = 4,
00040 Pair = Secret | Public,
00041 GSecret = Group | Secret,
00042 GPublic = Group | Public,
00043 GPair = Group | Pair,
00044 Sub = 8,
00045 Uid = 16,
00046 Uat = 32,
00047 RevSign = 64,
00048 Sign = 128
00049 };
00050 Q_DECLARE_FLAGS(ItemType, ItemTypeFlag)
00051
00052 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);
00053 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);
00054 KeyListViewItem(K3ListView *parent, const KgpgKey &key, const bool isbold);
00055 KeyListViewItem(K3ListViewItem *parent, const KgpgKeySign &sig);
00056 ~KeyListViewItem();
00057
00058 void setItemType(const ItemType &type);
00059 ItemType itemType() const;
00060
00061 void setDefault(const bool &def);
00062 bool isDefault() const;
00063
00064 void setExpired(const bool &exp);
00065 bool isExpired() const;
00066
00067 void setGroupId(const QString &nid) { delete groupId; groupId = new QString(nid); }
00068
00069 virtual void paintCell(QPainter *p, const QColorGroup &cg, int col, int width, int align);
00070 virtual int compare(Q3ListViewItem *item, int c, bool ascending) const;
00071 virtual QString key(int column, bool) const;
00072 virtual KeyListViewItem *parent() const { return static_cast<KeyListViewItem*>(K3ListViewItem::parent()); }
00073 virtual KeyListViewItem *nextSibling() const { return static_cast<KeyListViewItem*>(K3ListViewItem::nextSibling()); }
00074 virtual KeyListViewItem *firstChild() const { return static_cast<KeyListViewItem*>(K3ListViewItem::firstChild()); }
00075 virtual KgpgKey* getKey() { return m_key; }
00076 virtual const QString keyId(void) const { return m_key ? m_key->fullId() : m_sig ? m_sig->fullId() : groupId ? *groupId : text(6); }
00077 KgpgKeyTrust trust(void) const { return m_key ? m_key->trust() : TRUST_NOKEY; }
00078
00079 private:
00080 bool m_def;
00081 bool m_exp;
00082 ItemType m_type;
00083 KgpgKey *m_key;
00084 KgpgKeySign *m_sig;
00085 QString *groupId;
00086 };
00087 Q_DECLARE_OPERATORS_FOR_FLAGS(KeyListViewItem::ItemType)
00088
00089
00090 class KeyListView : public K3ListView
00091 {
00092 Q_OBJECT
00093 friend class KeysManager;
00094
00095 public:
00096 KeyListView(QWidget *parent = 0);
00097
00098 void setPreviewSize(const int &size);
00099 int previewSize() const;
00100
00101 void setDisplayPhoto(const bool &display);
00102 bool displayPhoto() const;
00103
00104 QPixmap trustbad;
00105
00106 signals:
00107 void statusMessage(QString, int, bool keep = false);
00108
00109
00110
00111
00112
00113 public slots:
00114 void slotAddColumn(const int &c);
00115 void slotRemoveColumn(const int &c);
00116 virtual KeyListViewItem *firstChild() { return static_cast<KeyListViewItem*>(K3ListView::firstChild()); }
00117 QString statusCountMessage(void);
00118
00119 protected:
00120 virtual void contentsDragMoveEvent(QDragMoveEvent *e);
00121 virtual void contentsDropEvent(QDropEvent *e);
00122 virtual void startDrag();
00123 virtual KeyListViewItem *currentItem() const { return static_cast<KeyListViewItem*>(K3ListView::currentItem()); }
00124 virtual KeyListViewItem *findItem (const QString &text, int column, ComparisonFlags compare = ExactMatch | Qt::CaseSensitive) const
00125 { return static_cast<KeyListViewItem *>(K3ListView::findItem(text, column, compare)); }
00126 virtual QList<KeyListViewItem *> selectedItems(void);
00127 virtual KeyListViewItem *lastChild() const { return static_cast<KeyListViewItem*>(K3ListView::lastChild()); }
00128 virtual KeyListViewItem *itemAtIndex(int index) { return static_cast<KeyListViewItem*>(K3ListView::itemAtIndex(index)); }
00129 virtual KeyListViewItem *findItemByKeyId(const QString &id);
00130
00131 private slots:
00132 void droppedFile(const KUrl &url);
00133
00134 void slotReloadKeys(const QStringList &keyids);
00135 void refreshAll();
00136
00137 bool refreshKeys(const QStringList &ids = QStringList());
00138 void refreshcurrentkey(const QString &id);
00139 void refreshcurrentkey(KeyListViewItem *current);
00140 void refreshselfkey();
00141
00142 void slotReloadOrphaned();
00143 void insertOrphans(const KgpgKeyList &keys);
00144
00145 void refreshGroups();
00146 void refreshTrust(int color, const QColor &newColor);
00147
00148 void expandKey(Q3ListViewItem *item);
00149 void expandGroup(KeyListViewItem *item);
00150 void insertSigns(KeyListViewItem *item, const KgpgCore::KgpgKeySignList &list);
00151
00152 private:
00153 QPixmap getTrustPix(const KgpgCore::KgpgKeyTrust &trust, const bool &isvalid);
00154
00155 private:
00156 QString photoKeysList;
00157
00158 QPixmap trustunknown;
00159 QPixmap trustrevoked;
00160 QPixmap trustgood;
00161 QPixmap trustultimate;
00162 QPixmap trustexpired;
00163 QPixmap trustmarginal;
00164
00165 int groupNb;
00166 int m_previewsize;
00167 bool m_displayphoto;
00168 };
00169
00170
00171 class KeyListViewSearchLine : public K3ListViewSearchLine
00172 {
00173 Q_OBJECT
00174
00175 public:
00176 explicit KeyListViewSearchLine(QWidget *parent = 0, KeyListView *listView = 0);
00177 virtual ~KeyListViewSearchLine() { }
00178
00179 void setHidePublic(const bool &hidepublic = true);
00180 bool hidePublic() const;
00181
00182 void setHideDisabled(const bool &hidedisabled = true);
00183 bool hideDisabled() const;
00184
00185 public slots:
00186 virtual void updateSearch(const QString &s = QString());
00187
00188 protected:
00189 virtual bool itemMatches(const Q3ListViewItem *item, const QString &s) const;
00190
00191 private:
00192 KeyListView *m_searchlistview;
00193 bool m_hidepublic;
00194 bool m_hidedisabled;
00195 };
00196
00197 #endif // KEYLISTVIEW_H