aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--context.h2
-rw-r--r--gpg4usb.pro6
-rw-r--r--keylist.cpp38
-rw-r--r--keylist.h3
-rw-r--r--keytablemodel.cpp85
-rw-r--r--keytablemodel.h26
6 files changed, 141 insertions, 19 deletions
diff --git a/context.h b/context.h
index 5acc04b..240b5b0 100644
--- a/context.h
+++ b/context.h
@@ -46,7 +46,7 @@ public:
bool privkey;
};
-typedef QLinkedList< GpgKey > GpgKeyList;
+typedef QList< GpgKey > GpgKeyList;
namespace GpgME
{
diff --git a/gpg4usb.pro b/gpg4usb.pro
index 8265221..bb336a6 100644
--- a/gpg4usb.pro
+++ b/gpg4usb.pro
@@ -25,7 +25,8 @@ HEADERS += attachments.h \
keygenthread.h \
keydetailsdialog.h \
settingsdialog.h \
- attachmenttablemodel.h
+ attachmenttablemodel.h \
+ keytablemodel.h
SOURCES += attachments.cpp \
context.cpp \
gpgwin.cpp \
@@ -37,7 +38,8 @@ SOURCES += attachments.cpp \
keygenthread.cpp \
keydetailsdialog.cpp \
settingsdialog.cpp \
- attachmenttablemodel.cpp
+ attachmenttablemodel.cpp \
+ keytablemodel.cpp
RC_FILE = gpg4usb.rc
# comment out line below for static building
diff --git a/keylist.cpp b/keylist.cpp
index d9976fd..717dd68 100644
--- a/keylist.cpp
+++ b/keylist.cpp
@@ -27,16 +27,24 @@ KeyList::KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent)
mCtx = ctx;
this->iconPath = iconpath;
- mKeyList = new QTableWidget(this);
- mKeyList->setColumnCount(5);
+ KeyTableModel *table = new KeyTableModel(ctx, iconpath, this);
+
+ QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
+ proxyModel->setSourceModel(table);
+ proxyModel->setDynamicSortFilter(true);
+
+ mKeyList = new QTableView(this);
+ mKeyList->setModel(proxyModel);
+ //mKeyList->setColumnCount(5);
mKeyList->verticalHeader()->hide();
mKeyList->setShowGrid(false);
mKeyList->setColumnWidth(0, 24);
mKeyList->setColumnWidth(1, 20);
mKeyList->sortByColumn(2, Qt::AscendingOrder);
mKeyList->setSelectionBehavior(QAbstractItemView::SelectRows);
+ mKeyList->setSortingEnabled(true);
// id of key
- mKeyList->setColumnHidden(4, true);
+ //mKeyList->setColumnHidden(4, true);
// tableitems not editable
mKeyList->setEditTriggers(QAbstractItemView::NoEditTriggers);
// no focus (rectangle around tableitems)
@@ -45,10 +53,10 @@ KeyList::KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent)
mKeyList->setAlternatingRowColors(true);
- QStringList labels;
+ /*QStringList labels;
labels << "" << "" << tr("Name") << tr("EMail") << "id";
mKeyList->setHorizontalHeaderLabels(labels);
- mKeyList->horizontalHeader()->setStretchLastSection(true);
+ mKeyList->horizontalHeader()->setStretchLastSection(true);*/
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mKeyList);
@@ -64,7 +72,7 @@ KeyList::KeyList(GpgME::Context *ctx, QString iconpath, QWidget *parent)
void KeyList::refresh()
{
// while filling the table, sort enabled causes errors
- mKeyList->setSortingEnabled(false);
+ /*mKeyList->setSortingEnabled(false);
mKeyList->clearContents();
GpgKeyList keys = mCtx->listKeys();
@@ -94,41 +102,41 @@ void KeyList::refresh()
it++;
++row;
}
- mKeyList->setSortingEnabled(true);
+ mKeyList->setSortingEnabled(true);*/
}
QStringList *KeyList::getChecked()
{
QStringList *ret = new QStringList();
- for (int i = 0; i < mKeyList->rowCount(); i++) {
+ /* for (int i = 0; i < mKeyList->rowCount(); i++) {
if (mKeyList->item(i, 0)->checkState() == Qt::Checked) {
*ret << mKeyList->item(i, 4)->text();
}
- }
+ }*/
return ret;
}
QStringList *KeyList::getPrivateChecked()
{
QStringList *ret = new QStringList();
- for (int i = 0; i < mKeyList->rowCount(); i++) {
+ /* for (int i = 0; i < mKeyList->rowCount(); i++) {
if ((mKeyList->item(i, 0)->checkState() == Qt::Checked) && (mKeyList->item(i, 1))) {
*ret << mKeyList->item(i, 4)->text();
}
- }
+ }*/
return ret;
}
void KeyList::setChecked(QStringList *keyIds)
{
- if (!keyIds->isEmpty()) {
+/* if (!keyIds->isEmpty()) {
for (int i = 0; i < mKeyList->rowCount(); i++) {
if (keyIds->contains(mKeyList->item(i, 4)->text())) {
mKeyList->item(i, 0)->setCheckState(Qt::Checked);
}
}
- }
+ }*/
}
/*QStringList *KeyList::getPrivateChecked()
@@ -146,11 +154,11 @@ QStringList *KeyList::getSelected()
{
QStringList *ret = new QStringList();
- for (int i = 0; i < mKeyList->rowCount(); i++) {
+/* for (int i = 0; i < mKeyList->rowCount(); i++) {
if (mKeyList->item(i, 0)->isSelected() == 1) {
*ret << mKeyList->item(i, 4)->text();
}
- }
+ }*/
return ret;
}
diff --git a/keylist.h b/keylist.h
index 4c5ed3f..b23f0d8 100644
--- a/keylist.h
+++ b/keylist.h
@@ -23,6 +23,7 @@
#define __KEYLIST_H__
#include "context.h"
+#include "keytablemodel.h"
class QWidget;
class QVBoxLayout;
@@ -54,7 +55,7 @@ public slots:
private:
GpgME::Context *mCtx;
- QTableWidget *mKeyList;
+ QTableView *mKeyList;
QString iconPath;
QMenu *popupMenu;
diff --git a/keytablemodel.cpp b/keytablemodel.cpp
new file mode 100644
index 0000000..d51b865
--- /dev/null
+++ b/keytablemodel.cpp
@@ -0,0 +1,85 @@
+#include "keytablemodel.h"
+
+KeyTableModel::KeyTableModel(GpgME::Context *ctx, QString iconpath, QObject *parent) :
+ QAbstractTableModel(parent)
+{
+ mCtx = ctx;
+ iconPath = iconpath;
+ keys = mCtx->listKeys();
+}
+
+int KeyTableModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return keys.size();
+}
+
+int KeyTableModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return 4;
+}
+
+QVariant KeyTableModel::data(const QModelIndex &index, int role) const
+{
+
+ //qDebug() << "called, index: " << index.column();
+
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= keys.size() || index.row() < 0)
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ GpgKey key = keys.at(index.row());
+
+ if (index.column() == 0)
+ return "";
+ if (index.column() == 1)
+ return "";
+ if (index.column() == 2)
+ return key.name;
+ if (index.column() == 3)
+ return key.email;
+
+
+ }
+
+ // set icon
+ if (role == Qt::DecorationRole && index.column() == 1) {
+ //return QIcon(icon);
+ GpgKey key = keys.at(index.row());
+ if(key.privkey) return QIcon(iconPath + "kgpg_key2.png");
+ }
+
+ return QVariant();
+}
+
+QVariant KeyTableModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (orientation == Qt::Horizontal) {
+ switch (section) {
+
+ case 0:
+ return tr("");
+
+ case 1:
+ return tr("");
+
+ case 2:
+ return tr("Name");
+
+ case 3:
+ return tr("EMail");
+
+ default:
+ return QVariant();
+ }
+ }
+ return QVariant();
+}
diff --git a/keytablemodel.h b/keytablemodel.h
new file mode 100644
index 0000000..1f3c35d
--- /dev/null
+++ b/keytablemodel.h
@@ -0,0 +1,26 @@
+#ifndef KEYTABLEMODEL_H
+#define KEYTABLEMODEL_H
+
+#include "context.h"
+#include <QAbstractTableModel>
+
+class KeyTableModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ KeyTableModel(GpgME::Context *ctx, QString iconpath, QObject *parent = 0);
+
+ int rowCount(const QModelIndex &parent) const;
+ int columnCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+private:
+ GpgKeyList keys;
+ QString iconPath;
+ GpgME::Context *mCtx;
+
+};
+
+#endif // KEYTABLEMODEL_H