22#include "keyselectdlg.h"
24#include "ui_keyselect.h"
32#define ONLY_SHOW_KEYBUNDLE
36class KeyStoreItemShared
39 KeyStoreIconset iconset;
40 QString notAvailableString;
65 const KeyStoreIconset &iconset = _shared->iconset;
67 case QCA::KeyStoreEntry::TypeKeyBundle:
68 out = iconset[KeySelectDlg::IconKeyBundle];
70 case QCA::KeyStoreEntry::TypeCertificate:
71 out = iconset[KeySelectDlg::IconCert];
73 case QCA::KeyStoreEntry::TypeCRL:
74 out = iconset[KeySelectDlg::IconCrl];
76 case QCA::KeyStoreEntry::TypePGPSecretKey:
77 out = iconset[KeySelectDlg::IconPgpSec];
79 case QCA::KeyStoreEntry::TypePGPPublicKey:
80 out = iconset[KeySelectDlg::IconPgpPub];
89 KeyStoreItemShared *_shared;
91 QCA::KeyStore *keyStore;
92 QCA::KeyStoreEntry keyStoreEntry;
94 KeyStoreItem(Type type, KeyStoreItemShared *shared)
104 setData((
int)type, SubTypeRole);
110 setData((
int)type, SubTypeRole);
111 setData(available, AvailabilityRole);
115 virtual QVariant data(
int role)
const
118 if (_type == Store) {
119 return data(NameRole).toString();
120 }
else if (_type == Entry) {
121 QString str = data(NameRole).toString();
122 if (_shared && !data(AvailabilityRole).toBool())
123 str += QString(
" ") + _shared->notAvailableString;
128 if (_type == Entry) {
130 return entryTypeToIcon(type);
137 virtual int type()
const
144 return new KeyStoreItem(*
this);
152 KeyStoreItemShared shared;
154 QCA::KeyStoreManager ksm;
160 shared.notAvailableString =
tr(
"(not available)");
165 connect(&ksm, SIGNAL(keyStoreAvailable(
const QString &)), SLOT(ks_available(
const QString &)));
166 QStringList
list = ksm.keyStores();
167 foreach (
const QString &s, list)
173 KeyStoreItem *itemFromStore(QCA::KeyStore *ks)
const
175 for (
int n = 0; n <
rowCount(); ++n) {
176 KeyStoreItem *i = (KeyStoreItem *)
item(n);
177 if (i->keyStore == ks)
184 void ks_available(
const QString &keyStoreId)
186 QCA::KeyStore *ks =
new QCA::KeyStore(keyStoreId, &ksm);
188#ifdef ONLY_SHOW_KEYBUNDLE
194 connect(ks, SIGNAL(updated()), SLOT(ks_updated()));
195 connect(ks, SIGNAL(unavailable()), SLOT(ks_unavailable()));
197 KeyStoreItem *store_item =
new KeyStoreItem(KeyStoreItem::Store, &shared);
198 store_item->setStore(ks->
name(), ks->
type());
199 store_item->keyStore = ks;
206 QCA::KeyStore *ks = (QCA::KeyStore *)
sender();
207 KeyStoreItem *store_item = itemFromStore(ks);
208 Q_ASSERT(store_item);
210 QList<QCA::KeyStoreEntry> newEntries = ks->
entryList();
212#ifdef ONLY_SHOW_KEYBUNDLE
214 for (
int n = 0; n < newEntries.
count(); ++n) {
215 if (newEntries[n].
type() != QCA::KeyStoreEntry::TypeKeyBundle) {
223 store_item->setStore(ks->
name(), ks->
type());
226 for (
int n = 0; n < store_item->
rowCount(); ++n) {
227 KeyStoreItem *i = (KeyStoreItem *)store_item->
child(n);
231 foreach (
const QCA::KeyStoreEntry &ne, newEntries) {
232 if (ne.
id() == i->keyStoreEntry.
id()) {
246 for (
int n = 0; n < newEntries.
count(); ++n) {
247 const QCA::KeyStoreEntry &ne = newEntries[n];
250 KeyStoreItem *entry_item = 0;
251 for (
int k = 0; k < store_item->
rowCount(); ++k) {
252 KeyStoreItem *i = (KeyStoreItem *)store_item->
child(k);
253 if (i->keyStoreEntry.
id() == ne.
id()) {
261 entry_item =
new KeyStoreItem(KeyStoreItem::Entry, &shared);
262 entry_item->keyStoreEntry = ne;
263 entry_item->setEntry(newEntries[n].
name(), newEntries[n].
type(), newEntries[n].isAvailable(), n);
268 entry_item->keyStoreEntry = ne;
269 entry_item->setEntry(newEntries[n].
name(), newEntries[n].
type(), newEntries[n].isAvailable(), n);
276 void ks_unavailable()
278 QCA::KeyStore *ks = (QCA::KeyStore *)
sender();
279 KeyStoreItem *store_item = itemFromStore(ks);
280 Q_ASSERT(store_item);
288class KeySelectDlg::Private :
public QObject
294 KeyStoreModel *model;
295 QCA::KeyStoreEntry cur_entry;
298 Private(KeySelectDlg *_q)
304 model =
new KeyStoreModel(
this);
305 connect(&model->ksm, SIGNAL(busyStarted()), SLOT(ksm_busyStarted()));
306 connect(&model->ksm, SIGNAL(busyFinished()), SLOT(ksm_busyFinished()));
307 if (model->ksm.isBusy())
310 ui.lv_stores->header()->hide();
312 ui.lv_stores->setModel(model);
314 connect(ui.lv_stores->selectionModel(),
315 SIGNAL(selectionChanged(
const QItemSelection &,
const QItemSelection &)),
316 SLOT(stores_selectionChanged(
const QItemSelection &,
const QItemSelection &)));
319 SLOT(stores_customContextMenuRequested(
const QPoint &)));
321 actionView =
new QAction(
tr(
"&View"),
this);
322 connect(actionView, SIGNAL(triggered()), SLOT(view()));
323 actionView->setEnabled(
false);
327 void ksm_busyStarted()
329 ui.lb_busy->setText(
tr(
"Looking for devices..."));
332 void ksm_busyFinished()
334 ui.lb_busy->setText(
"");
337 void stores_selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected)
339 Q_UNUSED(deselected);
342 if (!selected.
indexes().isEmpty()) {
343 QModelIndex index = selected.
indexes().first();
344 i = (KeyStoreItem *)model->itemFromIndex(index);
347 bool viewable =
false;
348 bool choosable =
false;
349 if (i && i->type() == KeyStoreItem::Entry) {
350 QCA::KeyStoreEntry entry = i->keyStoreEntry;
351 if (entry.
type() == QCA::KeyStoreEntry::TypeKeyBundle) {
359 cur_entry = QCA::KeyStoreEntry();
361 actionView->setEnabled(viewable);
370 void stores_customContextMenuRequested(
const QPoint &
pos)
372 QItemSelection selection = ui.lv_stores->selectionModel()->selection();
373 if (selection.
indexes().isEmpty())
376 QModelIndex index = selection.
indexes().first();
377 KeyStoreItem *i = (KeyStoreItem *)model->itemFromIndex(index);
378 if (i && i->type() == KeyStoreItem::Entry) {
380 menu.addAction(actionView);
381 menu.exec(ui.lv_stores->viewport()->mapToGlobal(
pos));
387 emit q->viewCertificate(cur_entry.keyBundle().certificateChain());
391KeySelectDlg::KeySelectDlg(
QWidget *parent)
394 d =
new Private(
this);
397KeySelectDlg::~KeySelectDlg()
402void KeySelectDlg::setIcon(IconType type,
const QPixmap &icon)
404 d->model->shared.iconset[
type] = icon;
407void KeySelectDlg::accept()
409 QCA::KeyStoreEntry entry = d->cur_entry;
411 emit selected(entry);
414#include "keyselectdlg.moc"
void setEnabled(bool enable)
Type
The type of entry in the KeyStore.
Type type() const
Determine the type of key stored in this object.
QString id() const
The ID associated with the key stored in this object.
static void start()
Initialize all key store providers.
QString name() const
The name associated with the KeyStore.
QList< KeyStoreEntry > entryList() const
A list of the KeyStoreEntry objects in this store.
Type type() const
The KeyStore Type.
void startAsynchronousMode()
Turns on asynchronous mode for this KeyStore instance.
Type
The type of keystore.
@ PGPKeyring
for a PGP keyring
bool holdsIdentities() const
test if the KeyStore holds identities (eg KeyBundle or PGPSecretKey)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
bool removeRow(int row, const QModelIndex &parent)
QModelIndexList indexes() const const
qsizetype count() const const
void removeAt(qsizetype i)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * sender() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
void appendRow(QStandardItem *item)
QStandardItem * child(int row, int column) const const
virtual QVariant data(int role) const const
void removeRows(int row, int count)
int rowCount() const const
virtual void setData(const QVariant &value, int role)
void setFlags(Qt::ItemFlags flags)
void sortChildren(int column, Qt::SortOrder order)
QStandardItemModel(QObject *parent)
void appendRow(QStandardItem *item)
QStandardItem * item(int row, int column) const const
virtual QModelIndex parent(const QModelIndex &child) const const override
virtual int rowCount(const QModelIndex &parent) const const override
void setSortRole(int role)