summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-04-27 13:39:06 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-07-21 15:04:14 (GMT)
commit1e20795fc16b18ee0da2abc6b05e0793b49d0884 (patch)
tree8115f986dce6ff580ef33efeb5bd8007dc6fdcad
parent138a49f7553c8c19c5fdbfd2dad3b4bfbac2f394 (diff)
Add new KeyModel based on KeyRearangeColumnsProxy
This adds a direct depdencency to KItemModels as we now use KRearrangeColumnsProxyModel to hide the columns from the model that we do not want to show. This is also the first step for a configurable column selection and order for which the RearangeColumnsProxy gives us the flexibility. This also adds a new hidden summary column as the first column hidden in the normal tabwidget.
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/dialogs/certificateselectiondialog.cpp6
-rw-r--r--src/models/keylistmodel.cpp10
-rw-r--r--src/models/keylistmodelinterface.h2
-rw-r--r--src/models/keyrearangecolumnsproxymodel.cpp81
-rw-r--r--src/models/keyrearangecolumnsproxymodel.h57
-rw-r--r--src/utils/formatting.cpp5
-rw-r--r--src/utils/formatting.h1
-rw-r--r--src/view/keytreeview.cpp16
-rw-r--r--src/view/tabwidget.cpp14
-rw-r--r--src/view/tabwidget.h2
12 files changed, 189 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fde040d..fc6db56 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Config ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5I18n ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5IconThemes ${KF5_VERSION} CONFIG REQUIRED)
+find_package(KF5ItemModels ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5XmlGui ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5WindowSystem ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5DocTools ${KF5_VERSION} CONFIG)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 462b94f..62abc96 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -98,6 +98,7 @@ set(_kleopatra_SRCS
models/keycache.cpp
models/keylistmodel.cpp
models/keylistsortfilterproxymodel.cpp
+ models/keyrearangecolumnsproxymodel.cpp
models/subkeylistmodel.cpp
models/useridlistmodel.cpp
@@ -279,6 +280,7 @@ target_link_libraries(kleopatra_bin
KF5::IconThemes
KF5::WindowSystem
KF5::CoreAddons
+ KF5::ItemModels
Qt5::Network
Qt5::PrintSupport # Printing secret keys
${_kleopatra_uiserver_extra_libs}
diff --git a/src/dialogs/certificateselectiondialog.cpp b/src/dialogs/certificateselectiondialog.cpp
index 7eff9dd..613d41f 100644
--- a/src/dialogs/certificateselectiondialog.cpp
+++ b/src/dialogs/certificateselectiondialog.cpp
@@ -243,7 +243,7 @@ void CertificateSelectionDialog::selectCertificates(const std::vector<Key> &keys
if (!view) {
return;
}
- const KeyListModelInterface *const model = dynamic_cast<KeyListModelInterface *>(view->model());
+ const auto *const model = d->ui.tabWidget.currentModel();
assert(model);
QItemSelectionModel *const sm = view->selectionModel();
assert(sm);
@@ -265,7 +265,7 @@ std::vector<Key> CertificateSelectionDialog::selectedCertificates() const
if (!view) {
return std::vector<Key>();
}
- const KeyListModelInterface *const model = dynamic_cast<KeyListModelInterface *>(view->model());
+ const auto *const model = d->ui.tabWidget.currentModel();
assert(model);
const QItemSelectionModel *const sm = view->selectionModel();
assert(sm);
@@ -368,7 +368,7 @@ void CertificateSelectionDialog::Private::slotDoubleClicked(const QModelIndex &i
{
QAbstractItemView *const view = ui.tabWidget.currentView();
assert(view);
- const KeyListModelInterface *const model = dynamic_cast<KeyListModelInterface *>(view->model());
+ const auto *const model = ui.tabWidget.currentModel();
assert(model);
Q_UNUSED(model);
QItemSelectionModel *const sm = view->selectionModel();
diff --git a/src/models/keylistmodel.cpp b/src/models/keylistmodel.cpp
index 5f8aaf7..4239856 100644
--- a/src/models/keylistmodel.cpp
+++ b/src/models/keylistmodel.cpp
@@ -73,6 +73,8 @@
using namespace GpgME;
using namespace Kleo;
+Q_DECLARE_METATYPE(Key);
+
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
@@ -300,7 +302,7 @@ QVariant AbstractKeyListModel::data(const QModelIndex &index, int role) const
const int column = index.column();
- if (role == Qt::DisplayRole || role == Qt::EditRole)
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch (column) {
case PrettyName:
return Formatting::prettyName(key);
@@ -331,10 +333,12 @@ QVariant AbstractKeyListModel::data(const QModelIndex &index, int role) const
return Formatting::type(key);
case ShortKeyID:
return QString::fromLatin1(key.shortKeyID());
+ case Summary:
+ return Formatting::summaryLine(key);
case NumColumns:
break;
}
- else if (role == Qt::ToolTipRole) {
+ } else if (role == Qt::ToolTipRole) {
return Formatting::toolTip(key, toolTipOptions());
} else if (role == Qt::FontRole) {
return KeyFilterManager::instance()->font(key, (column == ShortKeyID) ? QFont(QStringLiteral("courier")) : QFont());
@@ -346,6 +350,8 @@ QVariant AbstractKeyListModel::data(const QModelIndex &index, int role) const
return returnIfValid(KeyFilterManager::instance()->fgColor(key));
} else if (role == FingerprintRole) {
return QString::fromLatin1(key.primaryFingerprint());
+ } else if (role == KeyRole) {
+ return QVariant::fromValue(key);
}
return QVariant();
}
diff --git a/src/models/keylistmodelinterface.h b/src/models/keylistmodelinterface.h
index 4d30df3..b786780 100644
--- a/src/models/keylistmodelinterface.h
+++ b/src/models/keylistmodelinterface.h
@@ -52,6 +52,7 @@ public:
virtual ~KeyListModelInterface() {}
static const int FingerprintRole = 0xF1;
+ static const int KeyRole = 0xF2;
enum Columns {
PrettyName,
@@ -61,6 +62,7 @@ public:
TechnicalDetails,
/* OpenPGP only, really */
ShortKeyID,
+ Summary, // Short summary line
#if 0
Fingerprint,
LongKeyID,
diff --git a/src/models/keyrearangecolumnsproxymodel.cpp b/src/models/keyrearangecolumnsproxymodel.cpp
new file mode 100644
index 0000000..133563c
--- /dev/null
+++ b/src/models/keyrearangecolumnsproxymodel.cpp
@@ -0,0 +1,81 @@
+/* models/keyrearangecolumnsproxymodel.cpp
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2016 Intevation GmbH
+
+ Kleopatra 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.
+
+ Kleopatra is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+#include "keyrearangecolumnsproxymodel.h"
+
+#include <gpgme++/key.h>
+#include <cassert>
+
+using namespace Kleo;
+using namespace GpgME;
+
+KeyRearangeColumnsProxyModel::KeyRearangeColumnsProxyModel(QObject *parent) :
+ KRearrangeColumnsProxyModel(parent),
+ KeyListModelInterface()
+{
+
+}
+
+KeyListModelInterface *KeyRearangeColumnsProxyModel::klm() const
+{
+ KeyListModelInterface *ret = dynamic_cast<KeyListModelInterface *>(sourceModel());
+ assert(ret);
+ return ret;
+}
+
+Key KeyRearangeColumnsProxyModel::key(const QModelIndex &idx) const
+{
+ return klm()->key(mapToSource(idx));
+}
+
+std::vector<GpgME::Key> KeyRearangeColumnsProxyModel::keys(const QList<QModelIndex> &idxs) const
+{
+ QList<QModelIndex> srcIdxs;
+ Q_FOREACH (const QModelIndex idx, idxs) {
+ srcIdxs << mapToSource(idx);
+ }
+ return klm()->keys(srcIdxs);
+}
+
+
+QModelIndex KeyRearangeColumnsProxyModel::index(const GpgME::Key &key) const
+{
+ return mapFromSource(klm()->index(key));
+}
+
+QList<QModelIndex> KeyRearangeColumnsProxyModel::indexes(const std::vector<GpgME::Key> &keys) const
+{
+ QList<QModelIndex> myIdxs;
+ const QList <QModelIndex> srcIdxs = klm()->indexes(keys);
+ Q_FOREACH (const QModelIndex idx, srcIdxs) {
+ myIdxs << mapFromSource(idx);
+ }
+ return myIdxs;
+}
diff --git a/src/models/keyrearangecolumnsproxymodel.h b/src/models/keyrearangecolumnsproxymodel.h
new file mode 100644
index 0000000..1f9a05d
--- /dev/null
+++ b/src/models/keyrearangecolumnsproxymodel.h
@@ -0,0 +1,57 @@
+/* models/keyrearangecolumnsproxymodel.h
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2016 Intevation GmbH
+
+ Kleopatra 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.
+
+ Kleopatra is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+#ifndef KEYREARANGECOLUMNSPROXYMODEL_H
+#define KEYREARANGECOLUMNSPROXYMODEL_H
+
+#include "keylistmodelinterface.h"
+#include <KRearrangeColumnsProxyModel>
+
+namespace Kleo
+{
+/** KRearangeColumnsProxymodel that implements the KeyListModelInterface. */
+class KeyRearangeColumnsProxyModel: public KRearrangeColumnsProxyModel,
+ public KeyListModelInterface
+{
+public:
+ explicit KeyRearangeColumnsProxyModel(QObject *parent = Q_NULLPTR);
+
+ GpgME::Key key(const QModelIndex &idx) const Q_DECL_OVERRIDE;
+ std::vector<GpgME::Key> keys(const QList<QModelIndex> &idxs) const Q_DECL_OVERRIDE;
+
+ using KRearrangeColumnsProxyModel::index;
+
+ QModelIndex index(const GpgME::Key &key) const Q_DECL_OVERRIDE;
+ QList<QModelIndex> indexes(const std::vector<GpgME::Key> &keys) const Q_DECL_OVERRIDE;
+private:
+ KeyListModelInterface *klm() const;
+};
+} // namespace Kleo
+#endif // KEYREARANGECOLUMNSPROXYMODEL_H
diff --git a/src/utils/formatting.cpp b/src/utils/formatting.cpp
index 301365b..6833750 100644
--- a/src/utils/formatting.cpp
+++ b/src/utils/formatting.cpp
@@ -752,3 +752,8 @@ QString Formatting::usageString(const Subkey &sub)
}
return usageStrings.join(QStringLiteral(", "));
}
+
+QString Formatting::summaryLine(const Key &key)
+{
+ return keyToString(key) + QStringLiteral(" (%1 - %2)").arg(key.shortKeyID()).arg(displayName(key.protocol()));
+}
diff --git a/src/utils/formatting.h b/src/utils/formatting.h
index c036049..cc1ba23 100644
--- a/src/utils/formatting.h
+++ b/src/utils/formatting.h
@@ -124,6 +124,7 @@ QString importMetaData(const GpgME::Import &import, const QStringList &sources);
QString formatOverview(const GpgME::Key &key);
QString usageString(const GpgME::Subkey &subkey);
+QString summaryLine(const GpgME::Key &key);
}
}
diff --git a/src/view/keytreeview.cpp b/src/view/keytreeview.cpp
index 5b29e28..3a5d570 100644
--- a/src/view/keytreeview.cpp
+++ b/src/view/keytreeview.cpp
@@ -34,8 +34,9 @@
#include "keytreeview.h"
-#include <models/keylistmodel.h>
-#include <models/keylistsortfilterproxymodel.h>
+#include "models/keylistmodel.h"
+#include "models/keylistsortfilterproxymodel.h"
+#include "models/keyrearangecolumnsproxymodel.h"
#include <Libkleo/Predicates>
#include <utils/headerview.h>
@@ -200,7 +201,16 @@ void KeyTreeView::init()
}
m_proxy->setFilterFixedString(m_stringFilter);
m_proxy->setKeyFilter(m_keyFilter);
- m_view->setModel(m_proxy);
+ KeyRearangeColumnsProxyModel *rearangingModel = new KeyRearangeColumnsProxyModel(this);
+ rearangingModel->setSourceModel(m_proxy);
+ /* TODO: Make this configurable by the user. E.g. kdepim/src/todo/todoview.cpp */
+ rearangingModel->setSourceColumns(QVector<int>() << KeyListModelInterface::PrettyName
+ << KeyListModelInterface::PrettyEMail
+ << KeyListModelInterface::ValidFrom
+ << KeyListModelInterface::ValidUntil
+ << KeyListModelInterface::TechnicalDetails
+ << KeyListModelInterface::ShortKeyID);
+ m_view->setModel(rearangingModel);
}
KeyTreeView::~KeyTreeView() {}
diff --git a/src/view/tabwidget.cpp b/src/view/tabwidget.cpp
index f1df504..14113d4 100644
--- a/src/view/tabwidget.cpp
+++ b/src/view/tabwidget.cpp
@@ -59,6 +59,7 @@
#include <QMenu>
#include <QVBoxLayout>
#include <QRegularExpression>
+#include <QAbstractProxyModel>
#include <map>
#include <vector>
@@ -736,6 +737,19 @@ QAbstractItemView *TabWidget::currentView() const
}
}
+KeyListModelInterface *TabWidget::currentModel() const
+{
+ const QAbstractItemView *const view = currentView();
+ if (!view) {
+ return Q_NULLPTR;
+ }
+ QAbstractProxyModel *const proxy = qobject_cast<QAbstractProxyModel *>(view->model());
+ if (!proxy) {
+ return Q_NULLPTR;
+ }
+ return dynamic_cast<KeyListModelInterface *>(proxy);
+}
+
unsigned int TabWidget::count() const
{
return d->tabWidget.count();
diff --git a/src/view/tabwidget.h b/src/view/tabwidget.h
index a60f782..cb96412 100644
--- a/src/view/tabwidget.h
+++ b/src/view/tabwidget.h
@@ -53,6 +53,7 @@ namespace Kleo
class AbstractKeyListModel;
class AbstractKeyListSortFilterProxyModel;
class KeyFilter;
+class KeyListModelInterface;
class TabWidget : public QWidget
{
@@ -75,6 +76,7 @@ public:
std::vector<QAbstractItemView *> views() const;
QAbstractItemView *currentView() const;
+ KeyListModelInterface *currentModel() const;
unsigned int count() const;