Commit fe8ea25f authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Allow saving/restoring layout of key list to/from custom config group

KeyTreeView:
* Make KConfigGroup argument mandatory (to prevent wrong usage).
* Add config group argument to saveLayout() and restoreLayout() and
  make both methods public.
* Automatically save/restore layout only if config group was passed
  to constructor.

DeleteCertificatesDialog, NetKeyWidget:
* Explicitly, save/restore layout of key list(s) to/from custom config
  groups.  Previously, the layout was saved to/restored from the config
  group "KeyTreeView_default" implicitly.

TabWidget:
* Explicitly, use config group "KeyTreeView_default" for temporary
  key lists (e.g. after importing certificates). Previously, this
  config group was used implicitly.

GnuPG-bug-id: 5175
parent 9304059f
......@@ -62,6 +62,8 @@ public:
void readConfig()
{
KConfigGroup dialog(KSharedConfig::openConfig(), "DeleteCertificatesDialog");
ui.selectedKTV.restoreLayout(dialog);
ui.unselectedKTV.restoreLayout(dialog);
const QSize size = dialog.readEntry("Size", QSize(600, 400));
if (size.isValid()) {
q->resize(size);
......@@ -71,6 +73,7 @@ public:
void writeConfig()
{
KConfigGroup dialog(KSharedConfig::openConfig(), "DeleteCertificatesDialog");
ui.selectedKTV.saveLayout(dialog);
dialog.writeEntry("Size", q->size());
dialog.sync();
}
......
......@@ -226,9 +226,7 @@ void KeyTreeView::init()
KDAB_SET_OBJECT_NAME(m_proxy);
KDAB_SET_OBJECT_NAME(m_view);
if (!m_group.isValid()) {
m_group = KSharedConfig::openConfig()->group("KeyTreeView_default");
} else {
if (m_group.isValid()) {
// Reopen as non const
KConfig *conf = m_group.config();
m_group = conf->group(m_group.name());
......@@ -295,7 +293,9 @@ void KeyTreeView::init()
m_view->setModel(rearangingModel);
/* Handle expansion state */
m_expandedKeys = m_group.readEntry("Expanded", QStringList());
if (m_group.isValid()) {
m_expandedKeys = m_group.readEntry("Expanded", QStringList());
}
connect(m_view, &QTreeView::expanded, this, [this] (const QModelIndex &index) {
if (!index.isValid()) {
......@@ -311,7 +311,9 @@ void KeyTreeView::init()
return;
}
m_expandedKeys << fpr;
m_group.writeEntry("Expanded", m_expandedKeys);
if (m_group.isValid()) {
m_group.writeEntry("Expanded", m_expandedKeys);
}
});
connect(m_view, &QTreeView::collapsed, this, [this] (const QModelIndex &index) {
......@@ -323,7 +325,9 @@ void KeyTreeView::init()
return;
}
m_expandedKeys.removeAll(QString::fromLatin1(key.primaryFingerprint()));
m_group.writeEntry("Expanded", m_expandedKeys);
if (m_group.isValid()) {
m_group.writeEntry("Expanded", m_expandedKeys);
}
});
connect(KeyCache::instance().get(), &KeyCache::keysMayHaveChanged, this, [this] () {
......@@ -340,7 +344,9 @@ void KeyTreeView::init()
});
});
resizeColumns();
restoreLayout();
if (m_group.isValid()) {
restoreLayout(m_group);
}
}
void KeyTreeView::restoreExpandState()
......@@ -384,7 +390,7 @@ void KeyTreeView::setUpTagKeys()
#endif
}
void KeyTreeView::saveLayout()
void KeyTreeView::saveLayout(KConfigGroup &group)
{
QHeaderView *header = m_view->header();
......@@ -401,25 +407,25 @@ void KeyTreeView::saveLayout()
columnOrder << QVariant(header->visualIndex(i));
}
m_group.writeEntry("ColumnVisibility", columnVisibility);
m_group.writeEntry("ColumnOrder", columnOrder);
m_group.writeEntry("ColumnWidths", columnWidths);
group.writeEntry("ColumnVisibility", columnVisibility);
group.writeEntry("ColumnOrder", columnOrder);
group.writeEntry("ColumnWidths", columnWidths);
m_group.writeEntry("SortAscending", (int)header->sortIndicatorOrder());
group.writeEntry("SortAscending", (int)header->sortIndicatorOrder());
if (header->isSortIndicatorShown()) {
m_group.writeEntry("SortColumn", header->sortIndicatorSection());
group.writeEntry("SortColumn", header->sortIndicatorSection());
} else {
m_group.writeEntry("SortColumn", -1);
group.writeEntry("SortColumn", -1);
}
}
void KeyTreeView::restoreLayout()
void KeyTreeView::restoreLayout(const KConfigGroup &group)
{
QHeaderView *header = m_view->header();
QVariantList columnVisibility = m_group.readEntry("ColumnVisibility", QVariantList());
QVariantList columnOrder = m_group.readEntry("ColumnOrder", QVariantList());
QVariantList columnWidths = m_group.readEntry("ColumnWidths", QVariantList());
QVariantList columnVisibility = group.readEntry("ColumnVisibility", QVariantList());
QVariantList columnOrder = group.readEntry("ColumnOrder", QVariantList());
QVariantList columnWidths = group.readEntry("ColumnWidths", QVariantList());
if (columnVisibility.isEmpty()) {
// if config is empty then use default settings
......@@ -457,8 +463,8 @@ void KeyTreeView::restoreLayout()
m_onceResized = true;
}
int sortOrder = m_group.readEntry("SortAscending", (int)Qt::AscendingOrder);
int sortColumn = m_group.readEntry("SortColumn", 0);
int sortOrder = group.readEntry("SortAscending", (int)Qt::AscendingOrder);
int sortColumn = group.readEntry("SortColumn", 0);
if (sortColumn >= 0) {
m_view->sortByColumn(sortColumn, (Qt::SortOrder)sortOrder);
}
......@@ -466,7 +472,9 @@ void KeyTreeView::restoreLayout()
KeyTreeView::~KeyTreeView()
{
saveLayout();
if (m_group.isValid()) {
saveLayout(m_group);
}
}
static QAbstractProxyModel *find_last_proxy(QAbstractProxyModel *pm)
......
......@@ -39,7 +39,7 @@ public:
explicit KeyTreeView(QWidget *parent = nullptr);
KeyTreeView(const QString &stringFilter, const std::shared_ptr<KeyFilter> &keyFilter,
AbstractKeyListSortFilterProxyModel *additionalProxy, QWidget *parent,
const KConfigGroup &group = KConfigGroup());
const KConfigGroup &group);
~KeyTreeView();
QTreeView *view() const
......@@ -111,6 +111,9 @@ public:
bool connectSearchBar(const QObject *bar);
void resizeColumns();
void saveLayout(KConfigGroup &group);
void restoreLayout(const KConfigGroup &group);
public Q_SLOTS:
virtual void setStringFilter(const QString &text);
virtual void setKeyFilter(const std::shared_ptr<Kleo::KeyFilter> &filter);
......@@ -128,8 +131,6 @@ private:
void init();
void addKeysImpl(const std::vector<GpgME::Key> &, bool);
void restoreExpandState();
void saveLayout();
void restoreLayout();
void setUpTagKeys();
private:
......
......@@ -24,6 +24,9 @@
#include <Libkleo/KeyListModel>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QInputDialog>
#include <QLabel>
#include <QVBoxLayout>
......@@ -169,10 +172,15 @@ NetKeyWidget::NetKeyWidget(QWidget *parent) :
vLay->addLayout(actionLayout);
vLay->addStretch(1);
const KConfigGroup configGroup(KSharedConfig::openConfig(), "NetKeyCardView");
mTreeView->restoreLayout(configGroup);
}
NetKeyWidget::~NetKeyWidget()
{
KConfigGroup configGroup(KSharedConfig::openConfig(), "NetKeyCardView");
mTreeView->saveLayout(configGroup);
}
namespace
......
......@@ -838,7 +838,8 @@ QAbstractItemView *TabWidget::addView(const KConfigGroup &group)
QAbstractItemView *TabWidget::addTemporaryView(const QString &title, AbstractKeyListSortFilterProxyModel *proxy, const QString &tabToolTip)
{
Page *const page = new Page(title, QString(), QString(), proxy, tabToolTip);
const KConfigGroup group = KSharedConfig::openConfig()->group("KeyTreeView_default");
Page *const page = new Page(title, QString(), QString(), proxy, tabToolTip, nullptr, group);
page->setTemporary(true);
QAbstractItemView *v = d->addView(page, d->currentPage());
d->tabWidget.setCurrentIndex(d->tabWidget.count() - 1);
......
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