Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34102788
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
17 KB
Subscribers
None
View Options
diff --git a/src/dialogs/lookupcertificatesdialog.cpp b/src/dialogs/lookupcertificatesdialog.cpp
index 6989452b6..98a01e255 100644
--- a/src/dialogs/lookupcertificatesdialog.cpp
+++ b/src/dialogs/lookupcertificatesdialog.cpp
@@ -1,269 +1,260 @@
/* -*- mode: c++; c-basic-offset:4 -*-
dialogs/lookupcertificatesdialog.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2008 Klarälvdalens Datakonsult AB
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 <config-kleopatra.h>
#include "lookupcertificatesdialog.h"
#include "ui_lookupcertificatesdialog.h"
-#include <utils/headerview.h>
-
#include <Libkleo/KeyListModel>
-#include <Libkleo/KeyListSortFilterProxyModel>
-#include <Libkleo/Stl_Util>
#include <KConfigGroup>
#include <gpgme++/key.h>
#include <KLocalizedString>
#include <QPushButton>
#include <QHeaderView>
+#include <QTreeView>
#include <KSharedConfig>
using namespace Kleo;
using namespace Kleo::Dialogs;
using namespace GpgME;
-static const int minimalSearchTextLength = 2; // ### TODO: make that KIOSK-able
+static const int minimalSearchTextLength = 2;
class LookupCertificatesDialog::Private
{
friend class ::Kleo::Dialogs::LookupCertificatesDialog;
LookupCertificatesDialog *const q;
public:
explicit Private(LookupCertificatesDialog *qq);
~Private();
private:
void slotSelectionChanged()
{
enableDisableWidgets();
}
void slotSearchTextChanged()
{
enableDisableWidgets();
}
void slotSearchClicked()
{
Q_EMIT q->searchTextChanged(ui.findED->text());
}
void slotDetailsClicked()
{
Q_ASSERT(q->selectedCertificates().size() == 1);
Q_EMIT q->detailsRequested(q->selectedCertificates().front());
}
void slotSaveAsClicked()
{
Q_EMIT q->saveAsRequested(q->selectedCertificates());
}
void readConfig();
void writeConfig();
void enableDisableWidgets();
QString searchText() const
{
return ui.findED->text().trimmed();
}
- QModelIndexList selectedIndexes() const
+
+ std::vector<Key> selectedCertificates() const
{
- if (const QItemSelectionModel *const sm = ui.resultTV->selectionModel()) {
- return sm->selectedRows();
- } else {
- return QModelIndexList();
+ const QAbstractItemView *const view = ui.resultTV->view();
+ if (!view) {
+ return std::vector<Key>();
}
+ const auto *const model = dynamic_cast<KeyListModelInterface*>(view->model());
+ Q_ASSERT(model);
+ const QItemSelectionModel *const sm = view->selectionModel();
+ Q_ASSERT(sm);
+ return model->keys(sm->selectedRows());
}
+
int numSelectedCertificates() const
{
- return selectedIndexes().size();
+ return ui.resultTV->selectedKeys().size();
}
private:
- AbstractKeyListModel *model;
- KeyListSortFilterProxyModel proxy;
bool passive;
struct Ui : Ui_LookupCertificatesDialog {
explicit Ui(LookupCertificatesDialog *q)
: Ui_LookupCertificatesDialog()
{
setupUi(q);
saveAsPB->hide(); // ### not yet implemented in LookupCertificatesCommand
findED->setClearButtonEnabled(true);
+ resultTV->setFlatModel(AbstractKeyListModel::createFlatKeyListModel(q));
+ resultTV->setHierarchicalView(false);
+
importPB()->setText(i18n("Import"));
importPB()->setEnabled(false);
- HeaderView *hv = new HeaderView(Qt::Horizontal);
- KDAB_SET_OBJECT_NAME(hv);
- resultTV->setHeader(hv);
-
- connect(resultTV, SIGNAL(doubleClicked(QModelIndex)),
+ connect(resultTV->view(), SIGNAL(doubleClicked(QModelIndex)),
importPB(), SLOT(animateClick()));
findED->setFocus();
+
+ connect(selectAllPB, &QPushButton::clicked,
+ resultTV->view(), &QTreeView::selectAll);
+ connect(deselectAllPB, &QPushButton::clicked,
+ resultTV->view(), &QTreeView::clearSelection);
}
QPushButton *importPB() const
{
return buttonBox->button(QDialogButtonBox::Save);
}
QPushButton *closePB() const
{
return buttonBox->button(QDialogButtonBox::Close);
}
} ui;
};
LookupCertificatesDialog::Private::Private(LookupCertificatesDialog *qq)
: q(qq),
- model(AbstractKeyListModel::createFlatKeyListModel()),
- proxy(),
passive(false),
ui(q)
{
- KDAB_SET_OBJECT_NAME(model);
- KDAB_SET_OBJECT_NAME(proxy);
-
- proxy.setSourceModel(model);
- ui.resultTV->setModel(&proxy);
-
- connect(ui.resultTV->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+ connect(ui.resultTV->view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
q, SLOT(slotSelectionChanged()));
}
LookupCertificatesDialog::Private::~Private() {}
void LookupCertificatesDialog::Private::readConfig()
{
KConfigGroup dialog(KSharedConfig::openConfig(), "LookupCertificatesDialog");
const QSize size = dialog.readEntry("Size", QSize(600, 400));
if (size.isValid()) {
q->resize(size);
}
- const QByteArray headerState = dialog.readEntry("header", QByteArray());
- if (!headerState.isEmpty()) {
- ui.resultTV->header()->restoreState(headerState);
- }
}
void LookupCertificatesDialog::Private::writeConfig()
{
KConfigGroup dialog(KSharedConfig::openConfig(), "LookupCertificatesDialog");
- dialog.writeEntry("header", ui.resultTV->header()->saveState());
dialog.writeEntry("Size", q->size());
dialog.sync();
}
LookupCertificatesDialog::LookupCertificatesDialog(QWidget *p, Qt::WindowFlags f)
: QDialog(p, f), d(new Private(this))
{
d->ui.findPB->setEnabled(false);
d->readConfig();
}
LookupCertificatesDialog::~LookupCertificatesDialog()
{
d->writeConfig();
}
void LookupCertificatesDialog::setCertificates(const std::vector<Key> &certs)
{
- d->model->setKeys(certs);
- d->ui.resultTV->header()->resizeSections(QHeaderView::ResizeToContents);
- d->ui.resultTV->setFocus();
+ d->ui.resultTV->view()->setFocus();
+ d->ui.resultTV->setKeys(certs);
}
std::vector<Key> LookupCertificatesDialog::selectedCertificates() const
{
- return d->proxy.keys(d->selectedIndexes());
+ return d->selectedCertificates();
}
void LookupCertificatesDialog::setPassive(bool on)
{
if (d->passive == on) {
return;
}
d->passive = on;
d->enableDisableWidgets();
}
bool LookupCertificatesDialog::isPassive() const
{
return d->passive;
}
void LookupCertificatesDialog::setSearchText(const QString &text)
{
d->ui.findED->setText(text);
}
QString LookupCertificatesDialog::searchText() const
{
return d->ui.findED->text();
}
void LookupCertificatesDialog::accept()
{
- Q_ASSERT(!d->selectedIndexes().empty());
+ Q_ASSERT(!selectedCertificates().empty());
Q_EMIT importRequested(selectedCertificates());
QDialog::accept();
}
void LookupCertificatesDialog::Private::enableDisableWidgets()
{
// enable/disable everything except 'close', based on passive:
Q_FOREACH (QObject *const o, q->children())
if (QWidget *const w = qobject_cast<QWidget *>(o)) {
w->setDisabled(passive && w != ui.closePB() && w != ui.buttonBox);
}
if (passive) {
return;
}
ui.findPB->setEnabled(searchText().length() > minimalSearchTextLength);
- const int n = numSelectedCertificates();
+ const int n = q->selectedCertificates().size();
ui.detailsPB->setEnabled(n == 1);
ui.saveAsPB->setEnabled(n == 1);
ui.importPB()->setEnabled(n != 0);
ui.importPB()->setDefault(false); // otherwise Import becomes default button if enabled and return triggers both a search and accept()
}
#include "moc_lookupcertificatesdialog.cpp"
diff --git a/src/dialogs/lookupcertificatesdialog.ui b/src/dialogs/lookupcertificatesdialog.ui
index 666cef3c6..029c84b24 100644
--- a/src/dialogs/lookupcertificatesdialog.ui
+++ b/src/dialogs/lookupcertificatesdialog.ui
@@ -1,299 +1,265 @@
<ui version="4.0" >
<class>LookupCertificatesDialog</class>
<widget class="QDialog" name="LookupCertificatesDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>292</height>
</rect>
</property>
<property name="windowTitle" >
<string>Lookup on Server</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="1" >
<widget class="QLineEdit" name="findED" />
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="findPB" >
<property name="text" >
<string>Search</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="Line" name="hr" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="2" >
<widget class="QPushButton" name="detailsPB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Details...</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item rowspan="2" row="6" column="2" >
<widget class="QPushButton" name="saveAsPB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Save As...</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="2" >
<widget class="QPushButton" name="selectAllPB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Select All</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="2" >
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="2" >
<widget class="QPushButton" name="deselectAllPB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Deselect All</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="findLB" >
<property name="text" >
<string>Find:</string>
</property>
<property name="buddy" >
<cstring>findED</cstring>
</property>
</widget>
</item>
<item rowspan="6" row="2" column="0" colspan="2" >
- <widget class="QTreeView" name="resultTV" >
+ <widget class="Kleo::KeyTreeView" name="resultTV" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
- <property name="selectionMode" >
- <enum>QAbstractItemView::ExtendedSelection</enum>
- </property>
- <property name="sortingEnabled" >
- <bool>true</bool>
- </property>
- <property name="allColumnsShowFocus" >
- <bool>true</bool>
- </property>
</widget>
</item>
<item row="8" column="0" colspan="3" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="standardButtons" >
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>Kleo::KeyTreeView</class>
+ <extends>QWidget</extends>
+ <header>view/keytreeview.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections>
<connection>
<sender>findED</sender>
<signal>returnPressed()</signal>
<receiver>findPB</receiver>
<slot>animateClick()</slot>
<hints>
<hint type="sourcelabel" >
<x>409</x>
<y>19</y>
</hint>
<hint type="destinationlabel" >
<x>430</x>
<y>19</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LookupCertificatesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>28</x>
<y>265</y>
</hint>
<hint type="destinationlabel" >
<x>46</x>
<y>291</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LookupCertificatesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>188</x>
<y>273</y>
</hint>
<hint type="destinationlabel" >
<x>218</x>
<y>291</y>
</hint>
</hints>
</connection>
- <connection>
- <sender>selectAllPB</sender>
- <signal>clicked()</signal>
- <receiver>resultTV</receiver>
- <slot>selectAll()</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>437</x>
- <y>79</y>
- </hint>
- <hint type="destinationlabel" >
- <x>409</x>
- <y>77</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>deselectAllPB</sender>
- <signal>clicked()</signal>
- <receiver>resultTV</receiver>
- <slot>clearSelection()</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>465</x>
- <y>115</y>
- </hint>
- <hint type="destinationlabel" >
- <x>409</x>
- <y>119</y>
- </hint>
- </hints>
- </connection>
<connection>
<sender>findPB</sender>
<signal>clicked()</signal>
<receiver>LookupCertificatesDialog</receiver>
<slot>slotSearchClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>437</x>
<y>39</y>
</hint>
<hint type="destinationlabel" >
<x>443</x>
<y>45</y>
</hint>
</hints>
</connection>
<connection>
<sender>detailsPB</sender>
<signal>clicked()</signal>
<receiver>LookupCertificatesDialog</receiver>
<slot>slotDetailsClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>523</x>
<y>177</y>
</hint>
<hint type="destinationlabel" >
<x>541</x>
<y>177</y>
</hint>
</hints>
</connection>
<connection>
<sender>saveAsPB</sender>
<signal>clicked()</signal>
<receiver>LookupCertificatesDialog</receiver>
<slot>slotSaveAsClicked()</slot>
<hints>
<hint type="sourcelabel" >
<x>517</x>
<y>221</y>
</hint>
<hint type="destinationlabel" >
<x>539</x>
<y>219</y>
</hint>
</hints>
</connection>
<connection>
<sender>findED</sender>
<signal>textChanged(QString)</signal>
<receiver>LookupCertificatesDialog</receiver>
<slot>slotSearchTextChanged()</slot>
<hints>
<hint type="sourcelabel" >
<x>93</x>
<y>19</y>
</hint>
<hint type="destinationlabel" >
<x>93</x>
<y>3</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slotSearchClicked()</slot>
<slot>slotDetailsClicked()</slot>
<slot>slotSaveAsClicked()</slot>
<slot>slotSearchTextChanged()</slot>
</slots>
</ui>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Dec 4, 2:12 PM (1 d, 20 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c1/92/0be7f1e6f71cf26ba735a1bf909e
Attached To
rKLEOPATRA Kleopatra
Event Timeline
Log In to Comment