Move "showPki()" from the model class to the view

The displaying function requires UI.
This commit is contained in:
Christian Hohnstaedt 2020-03-05 17:23:25 +01:00
parent d0d387b03e
commit 3dd34a61bc
31 changed files with 259 additions and 304 deletions

View File

@ -324,20 +324,6 @@ void db_base::deletePKI(QModelIndex idx)
}
}
void db_base::showItem(const QModelIndex &index)
{
pki_base *pki = static_cast<pki_base*>(index.internalPointer());
if (pki->isVisible() == 1)
showPki(pki);
}
void db_base::showItem(const QString name)
{
pki_base *pki = lookupPki<pki_base>(name.toULongLong());
if (pki && pki->isVisible() == 1)
showPki(pki);
}
void db_base::insertChild(pki_base *parent, pki_base *child)
{
QModelIndex idx = QModelIndex();
@ -556,11 +542,15 @@ bool db_base::setData(const QModelIndex &index, const QVariant &value, int role)
return false;
}
void db_base::updateItem(pki_base *pki, QString name, QString comment)
void db_base::updateItem(pki_base *pki, const QString &name,
const QString &comment)
{
XSqlQuery q;
QSqlError e;
if (name == pki->getIntName() && comment == pki->getComment())
return;
Transaction;
TransThrow();

View File

@ -55,7 +55,6 @@ class db_base: public QAbstractItemModel
virtual dbheaderList getHeaders();
int colResizing;
QString sqlItemSelector();
void updateItem(pki_base *pki, QString name, QString comment);
virtual exportType::etype clipboardFormat(QModelIndexList) const
{
return exportType::Separator;
@ -104,6 +103,8 @@ class db_base: public QAbstractItemModel
}
return x;
}
void updateItem(pki_base *pki, const QString &name,
const QString &comment);
virtual pki_base *newPKI(enum pki_type type = none);
pki_base *rootItem;
@ -173,9 +174,6 @@ class db_base: public QAbstractItemModel
virtual void newItem() { }
virtual void load() { }
void columnResetDefaults();
virtual void showPki(pki_base *) {};
virtual void showItem(const QModelIndex &index);
virtual void showItem(const QString keyname);
void sectionResized(int i, int, int newSize);
void sortIndicatorChanged(int, Qt::SortOrder);

View File

@ -120,34 +120,6 @@ pki_base *db_crl::insert(pki_base *item)
return crl;
}
void db_crl::showPki(pki_base *pki)
{
db_x509 *certs = models()->model<db_x509>();
pki_crl *crl = dynamic_cast<pki_crl *>(pki);
if (!crl || !certs)
return;
CrlDetail *dlg = new CrlDetail(NULL);
if (!dlg)
return;
dlg->setCrl(crl);
connect(dlg->issuerIntName, SIGNAL(doubleClicked(QString)),
certs, SLOT(showItem(QString)));
connect(certs, SIGNAL(pkiChanged(pki_base*)),
dlg, SLOT(itemChanged(pki_base*)));
if (dlg->exec()) {
QString newname = dlg->descr->text();
QString newcomment = dlg->comment->toPlainText();
if (newname != pki->getIntName() ||
newcomment != pki->getComment())
{
updateItem(pki, newname, newcomment);
}
}
delete dlg;
}
void db_crl::store(QModelIndex index)
{
QList<exportType> types;

View File

@ -28,7 +28,6 @@ class db_crl: public db_x509name
void removeSigner(pki_base *signer);
void store(QModelIndex index);
void load();
void showPki(pki_base *pki);
void updateCertView();
void newItem(const crljob &crljob);

View File

@ -237,27 +237,6 @@ void db_key::load(void)
load_default(l);
}
void db_key::showPki(pki_base *pki)
{
pki_key *key = dynamic_cast<pki_key *>(pki);
if (!key)
return;
KeyDetail *dlg = new KeyDetail(NULL);
if (!dlg)
return;
dlg->setKey(key);
if (dlg->exec()) {
QString newname = dlg->keyDesc->text();
QString newcomment = dlg->comment->toPlainText();
if (newname != pki->getIntName() ||
newcomment != pki->getComment())
{
updateItem(pki, newname, newcomment);
}
}
delete dlg;
}
exportType::etype db_key::clipboardFormat(QModelIndexList indexes) const
{
QList<exportType> types;

View File

@ -40,7 +40,6 @@ class db_key: public db_base
void newItem(QString name);
void load();
void store(QModelIndex index);
void showPki(pki_base *pki);
signals:
void delKey(pki_key *delkey);

View File

@ -111,12 +111,6 @@ void db_temp::newItem()
}
delete dlg;
}
void db_temp::showPki(pki_base *pki)
{
pki_temp *t = dynamic_cast<pki_temp *>(pki);
if (t)
alterTemp(t);
}
void db_temp::load()
{

View File

@ -30,7 +30,6 @@ class db_temp: public db_x509name
void fillContextMenu(QMenu *menu, const QModelIndex &index);
QList<pki_temp*> getAllAndPredefs();
void newItem();
void showPki(pki_base *pki);
void load();
void store(QModelIndex index);
};

View File

@ -143,6 +143,7 @@ void db_x509::changeView()
beginRemoveRows(QModelIndex(), 0, rows -1);
pki_base *pki = rootItem;
pki_base *parent;
#warning refactor child management from pointer to sqlItemId
while (pki->childCount()) {
pki = pki->takeFirst();
while (pki != rootItem && !pki->childCount()) {

View File

@ -201,40 +201,3 @@ void db_x509super::toTemplate(QModelIndex index)
XCA_ERROR(err);
}
}
void db_x509super::showPki(pki_base *pki)
{
db_key *keys = models()->model<db_key>();
pki_x509super *x = dynamic_cast<pki_x509super *>(pki);
if (!x)
return;
CertDetail *dlg = new CertDetail(mainwin);
if (!dlg)
return;
switch (x->getType()) {
case x509_req: dlg->setReq((pki_x509req*)x); break;
case x509: dlg->setCert((pki_x509*)x); break;
default:
delete dlg;
return;
}
connect(dlg->privKey, SIGNAL(doubleClicked(QString)),
keys, SLOT(showItem(QString)));
connect(dlg->signature, SIGNAL(doubleClicked(QString)),
this, SLOT(showItem(QString)));
connect(this, SIGNAL(pkiChanged(pki_base*)),
dlg, SLOT(itemChanged(pki_base*)));
connect(keys, SIGNAL(pkiChanged(pki_base*)),
dlg, SLOT(itemChanged(pki_base*)));
if (dlg->exec()) {
QString newname = dlg->descr->text();
QString newcomment = dlg->comment->toPlainText();
if (newname != pki->getIntName() ||
newcomment != pki->getComment())
{
updateItem(pki, newname, newcomment);
}
}
delete dlg;
}

View File

@ -38,7 +38,6 @@ class db_x509super: public db_x509name
void extractPubkey(QModelIndex index);
void toTemplate(QModelIndex index);
void toOpenssl(QModelIndex index) const;
void showPki(pki_base *pki);
};
#endif

View File

@ -91,15 +91,18 @@ void CertDetail::setX509super(pki_x509super *x)
// Comment
comment->setPlainText(x->getComment());
setCert(dynamic_cast<pki_x509*>(x));
setReq(dynamic_cast<pki_x509req*>(x));
}
void CertDetail::setCert(pki_x509 *cert)
{
if (!cert)
return;
image->setPixmap(QPixmap(":certImg"));
headerLabel->setText(tr("Details of the Certificate"));
try {
setX509super(cert);
// No attributes
tabwidget->removeTab(3);
@ -163,11 +166,11 @@ void CertDetail::setCert(pki_x509 *cert)
void CertDetail::setReq(pki_x509req *req)
{
if (!req)
return;
image->setPixmap(QPixmap(":csrImg"));
headerLabel->setText(tr("Details of the certificate signing request"));
try {
setX509super(req);
// No issuer
tabwidget->removeTab(2);

View File

@ -22,14 +22,14 @@ class CertDetail: public QDialog, public Ui::CertDetail
QVariant keySqlId, issuerSqlId;
QString conf, exts;
QLabel *labelFromAsn1String(ASN1_STRING *s);
void setX509super(pki_x509super *x);
pki_key *myPubKey;
void setCert(pki_x509 *cert);
void setReq(pki_x509req *req);
public:
CertDetail(QWidget *parent);
~CertDetail();
void setCert(pki_x509 *cert);
void setReq(pki_x509req *req);
void setX509super(pki_x509super *x);
private slots:
void on_showExt_clicked();

View File

@ -7,6 +7,9 @@
#include "CertTreeView.h"
#include "XcaWarning.h"
#include "lib/database_model.h"
#include "lib/db_crl.h"
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QMenu>
@ -86,52 +89,50 @@ void CertTreeView::fillContextMenu(QMenu *menu, QMenu *subExport,
void CertTreeView::changeView()
{
if (!certs)
if (!basemodel)
return;
db_x509 *c = certs;
hide();
setModel();
setModel(NULL);
c->changeView();
certs()->changeView();
setModel(c);
setModel(certs());
show();
setRootIsDecorated(db_x509::treeview);
}
void CertTreeView::toRequest()
{
if (certs)
certs->toRequest(currentIndex());
if (basemodel)
certs()->toRequest(currentIndex());
}
void CertTreeView::toToken()
{
if (certs)
certs->toToken(currentIndex(), false);
if (basemodel)
certs()->toToken(currentIndex(), false);
}
void CertTreeView::toOtherToken()
{
if (certs)
certs->toToken(currentIndex(), true);
if (basemodel)
certs()->toToken(currentIndex(), true);
}
void CertTreeView::loadPKCS12()
{
if (certs) {
if (basemodel) {
load_pkcs12 l;
certs->load_default(l);
certs()->load_default(l);
}
}
void CertTreeView::loadPKCS7()
{
if (certs) {
if (basemodel) {
load_pkcs7 l;
certs->load_default(l);
certs()->load_default(l);
}
}
@ -139,13 +140,16 @@ void CertTreeView::genCrl()
{
pki_x509 *cert = static_cast<pki_x509*>
(currentIndex().internalPointer());
crls->newItem(cert);
db_crl *crls = models()->model<db_crl>();
if (crls)
crls->newItem(cert);
}
void CertTreeView::toCertificate()
{
if (certs)
certs->toCertificate(currentIndex());
if (basemodel)
certs()->toCertificate(currentIndex());
}
void CertTreeView::deleteFromToken()
@ -161,30 +165,30 @@ void CertTreeView::deleteFromToken()
void CertTreeView::manageRevocations()
{
if (certs)
certs->manageRevocations(currentIndex());
if (basemodel)
certs()->manageRevocations(currentIndex());
}
void CertTreeView::caProperties()
{
if (certs)
certs->caProperties(currentIndex());
if (basemodel)
certs()->caProperties(currentIndex());
}
void CertTreeView::certRenewal()
{
if (certs)
certs->certRenewal(getSelectedIndexes());
if (basemodel)
certs()->certRenewal(getSelectedIndexes());
}
void CertTreeView::revoke()
{
if (certs)
certs->revoke(getSelectedIndexes());
if (basemodel)
certs()->revoke(getSelectedIndexes());
}
void CertTreeView::unRevoke()
{
if (certs)
certs->unRevoke(getSelectedIndexes());
if (basemodel)
certs()->unRevoke(getSelectedIndexes());
}

View File

@ -10,29 +10,20 @@
#include "X509SuperTreeView.h"
#include "lib/db_x509.h"
#include "lib/db_crl.h"
#include "lib/database_model.h"
class CertTreeView: public X509SuperTreeView
{
Q_OBJECT
db_x509 *certs;
db_crl *crls;
db_x509 *certs() const
{
return dynamic_cast<db_x509*>(basemodel);
}
public:
CertTreeView(QWidget *parent) : X509SuperTreeView(parent)
{
certs = NULL;
}
CertTreeView(QWidget *parent) : X509SuperTreeView(parent) { }
void fillContextMenu(QMenu *menu, QMenu *subExport,
const QModelIndex &index, QModelIndexList indexes);
void setModels(database_model *models)
{
certs = models->model<db_x509>();
crls = models->model<db_crl>();
X509SuperTreeView::setModel(certs);
}
public slots:
void changeView();

View File

@ -6,16 +6,33 @@
*/
#include "CrlTreeView.h"
#include "CrlDetail.h"
#include "CrlDetail.h"
#include "MainWindow.h"
#include "lib/db_crl.h"
#include "lib/database_model.h"
CrlTreeView::CrlTreeView(QWidget *parent)
: XcaTreeView(parent)
void CrlTreeView::showPki(pki_base *pki) const
{
}
db_x509 *certs = models()->model<db_x509>();
db_crl *crls = dynamic_cast<db_crl*>(basemodel);
pki_crl *crl = dynamic_cast<pki_crl *>(pki);
void CrlTreeView::setModels(database_model *models)
{
db_crl *crls = models->model<db_crl>();
XcaTreeView::setModel(crls);
if (!crl || !crls || !certs)
return;
CrlDetail *dlg = new CrlDetail(NULL);
if (!dlg)
return;
dlg->setCrl(crl);
connect(dlg->issuerIntName, SIGNAL(doubleClicked(QString)),
mainwin->certView, SLOT(showItem(QString)));
connect(certs, SIGNAL(pkiChanged(pki_base*)),
dlg, SLOT(itemChanged(pki_base*)));
if (dlg->exec()) {
crls->updateItem(pki, dlg->descr->text(),
dlg->comment->toPlainText());
}
delete dlg;
}

View File

@ -9,14 +9,13 @@
#define __CRLTREEVIEW_H
#include "XcaTreeView.h"
#include "lib/database_model.h"
class CrlTreeView: public XcaTreeView
{
Q_OBJECT
public:
CrlTreeView(QWidget *parent);
void setModels(database_model *models);
CrlTreeView(QWidget *parent) : XcaTreeView(parent) { }
void showPki(pki_base *pki) const;
};
#endif

View File

@ -262,11 +262,13 @@ void ImportMulti::on_butDetails_clicked()
if (!pki)
return;
#warning Get rid of the typeid()
const std::type_info &t = typeid(*pki);
try {
if (t == typeid(pki_x509)){
if (t == typeid(pki_x509) ||
t == typeid(pki_x509req)) {
CertDetail *dlg = new CertDetail(mainwin);
dlg->setCert(static_cast<pki_x509 *>(pki));
dlg->setX509super(dynamic_cast<pki_x509super*>(pki));
connect(dlg->privKey, SIGNAL(doubleClicked(QString)),
keys, SLOT(showItem(QString)));
connect(dlg->signature,
@ -281,14 +283,6 @@ void ImportMulti::on_butDetails_clicked()
if (dlg->exec())
pki->setIntName(dlg->keyDesc->text());
delete dlg;
} else if (t == typeid(pki_x509req)) {
CertDetail *dlg = new CertDetail(mainwin);
dlg->setReq(static_cast<pki_x509req *>(pki));
connect(dlg->privKey, SIGNAL(doubleClicked(QString)),
keys, SLOT(showItem(QString)));
if (dlg->exec())
pki->setIntName(dlg->descr->text());
delete dlg;
} else if (t == typeid(pki_crl)) {
CrlDetail *dlg = new CrlDetail(mainwin);
dlg->setCrl(static_cast<pki_crl *>(pki));

View File

@ -8,6 +8,7 @@
#include "lib/pki_scard.h"
#include "KeyTreeView.h"
#include "MainWindow.h"
#include "KeyDetail.h"
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QMenu>
@ -55,8 +56,10 @@ void KeyTreeView::fillContextMenu(QMenu *menu, QMenu *subExport,
void KeyTreeView::setOwnPass()
{
if (!basemodel)
return;
try {
keys->setOwnPass(currentIndex(), pki_key::ptPrivate);
keys()->setOwnPass(currentIndex(), pki_key::ptPrivate);
} catch (errorEx &err) {
XCA_ERROR(err);
}
@ -64,8 +67,10 @@ void KeyTreeView::setOwnPass()
void KeyTreeView::resetOwnPass()
{
if (!basemodel)
return;
try {
keys->setOwnPass(currentIndex(), pki_key::ptCommon);
keys()->setOwnPass(currentIndex(), pki_key::ptCommon);
} catch (errorEx &err) {
XCA_ERROR(err);
}
@ -129,7 +134,7 @@ void KeyTreeView::toToken()
{
QModelIndex currentIdx = currentIndex();
if (!currentIdx.isValid())
if (!currentIdx.isValid() || !basemodel)
return;
pki_key *key = static_cast<pki_scard*>(currentIdx.internalPointer());
@ -149,8 +154,8 @@ void KeyTreeView::toToken()
QString msg = tr("Shall the original key '%1' be replaced by the key on the token?\nThis will delete the key '%1' and make it unexportable").
arg(key->getIntName());
if (XCA_YESNO(msg)) {
keys->deletePKI(currentIdx);
keys->insertPKI(card);
keys()->deletePKI(currentIdx);
keys()->insertPKI(card);
card = NULL;
}
} catch (errorEx &err) {
@ -158,3 +163,21 @@ void KeyTreeView::toToken()
}
delete card;
}
void KeyTreeView::showPki(pki_base *pki) const
{
pki_key *key = dynamic_cast<pki_key *>(pki);
if (!key || !basemodel)
return;
KeyDetail *dlg = new KeyDetail(mainwin);
if (!dlg)
return;
dlg->setKey(key);
if (dlg->exec() && basemodel) {
keys()->updateItem(pki, dlg->keyDesc->text(),
dlg->comment->toPlainText());
}
delete dlg;
}

View File

@ -10,25 +10,21 @@
#include "XcaTreeView.h"
#include "lib/db_key.h"
#include "lib/database_model.h"
class KeyTreeView: public XcaTreeView
{
Q_OBJECT
db_key *keys;
db_key *keys() const
{
return dynamic_cast<db_key*>(basemodel);
}
public:
KeyTreeView(QWidget *parent) : XcaTreeView(parent)
{
keys = NULL;
}
KeyTreeView(QWidget *parent) : XcaTreeView(parent) { }
void fillContextMenu(QMenu *menu, QMenu *subExport,
const QModelIndex &index, QModelIndexList indexes);
void setModels(database_model *models)
{
keys = models->model<db_key>();
XcaTreeView::setModel(keys);
}
void showPki(pki_base *pki) const;
public slots:
void resetOwnPass();

View File

@ -209,35 +209,6 @@ void MainWindow::init_images()
bigRev->setPixmap(QPixmap(":revImg"));
setWindowIcon(QPixmap(":appIco"));
}
#if 0
QString file = filename2QString(arg);
if (force_load) {
if (changeDB(file) == 2)
exitApp = 1;
force_load = 0;
} else if (export_index) {
if (exportIndex(file, (export_index == 2)) == 2)
exitApp = 1;
export_index = 0;
} else {
int ret;
pki_multi *pki = probeAnything(file, &ret);
if (!pki) {
if (ret == 2)
exitApp = 1;
else if (ret == 1)
failed << file;
}
dlgi->addItem(pki);
}
cnt++;
}
dlgi->execute(1, failed); /* force showing of import dialog */
if (dlgi->result() == QDialog::Rejected)
exitApp = 1;
delete dlgi;
#endif
void MainWindow::loadPem()
{
@ -539,17 +510,18 @@ void MainWindow::changeDbPass()
}
}
#warning This connNewX509() is very ugly and can be replaced by something smarter
void MainWindow::connNewX509(NewX509 *nx)
{
db_x509req *reqs = models->model<db_x509req>();
db_key *keys = models->model<db_key>();
db_x509req *reqs = models->model<db_x509req>();
connect(nx, SIGNAL(genKey(QString)),
keys, SLOT(newItem(QString)));
connect(keys, SIGNAL(keyDone(pki_key*)),
nx, SLOT(newKeyDone(pki_key*)));
connect(nx, SIGNAL(showReq(pki_base*)),
reqs, SLOT(showPki(pki_base*)));
reqView, SLOT(showPki(pki_base*)));
connect(reqs, SIGNAL(pkiChanged(pki_base*)),
nx, SLOT(itemChanged(pki_base*)));
}
@ -637,8 +609,11 @@ enum open_result MainWindow::init_database(database_model *m)
setOptions();
}
foreach(XcaTreeView *v, views)
v->setModels(models);
keyView->setModel(models->model<db_key>());
reqView->setModel(models->model<db_x509req>());
certView->setModel(models->model<db_x509>());
tempView->setModel(models->model<db_temp>());
crlView->setModel(models->model<db_crl>());
searchEdit->setText("");
searchEdit->show();
@ -694,7 +669,7 @@ void MainWindow::close_database()
update_history_menu();
currentDB.clear();
foreach(XcaTreeView *v, views)
v->setModel();
v->setModel(NULL);
enableTokenMenu(pkcs11::loaded());
}

View File

@ -98,7 +98,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow
public:
int exitApp;
QLabel *dbindex;
database_model *getModels()
database_model *getModels() const
{
return models;
}

View File

@ -37,24 +37,24 @@ void ReqTreeView::fillContextMenu(QMenu *menu, QMenu *subExport,
void ReqTreeView::toRequest()
{
if (reqs)
reqs->toRequest(currentIndex());
if (basemodel)
reqs()->toRequest(currentIndex());
}
void ReqTreeView::signReq()
{
if (reqs)
reqs->signReq(currentIndex());
if (basemodel)
reqs()->signReq(currentIndex());
}
void ReqTreeView::markSigned()
{
if (reqs)
reqs->setSigned(currentIndex(), true);
if (basemodel)
reqs()->setSigned(currentIndex(), true);
}
void ReqTreeView::unmarkSigned()
{
if (reqs)
reqs->setSigned(currentIndex(), false);
if (basemodel)
reqs()->setSigned(currentIndex(), false);
}

View File

@ -10,25 +10,20 @@
#include "X509SuperTreeView.h"
#include "lib/db_x509req.h"
#include "lib/database_model.h"
class ReqTreeView: public X509SuperTreeView
{
Q_OBJECT
db_x509req *reqs;
db_x509req *reqs() const
{
return dynamic_cast<db_x509req*>(basemodel);
}
public:
ReqTreeView(QWidget *parent) : X509SuperTreeView(parent)
{
reqs = NULL;
}
ReqTreeView(QWidget *parent) : X509SuperTreeView(parent) { }
void fillContextMenu(QMenu *menu, QMenu *subExport,
const QModelIndex &index, QModelIndexList indexes);
void setModels(database_model *models)
{
reqs = models->model<db_x509req>();
X509SuperTreeView::setModel(reqs);
}
public slots:
void toRequest();

View File

@ -28,12 +28,12 @@ void TempTreeView::duplicateTemp()
{
QModelIndex currentIdx = currentIndex();
if (!currentIdx.isValid())
if (!currentIdx.isValid() || !basemodel)
return;
pki_temp *temp = static_cast<pki_temp*>(currentIdx.internalPointer());
pki_temp *newtemp = new pki_temp(temp);
newtemp->setIntName(newtemp->getIntName() + " " + tr("copy"));
temps->insertPKI(newtemp);
temps()->insertPKI(newtemp);
}
void TempTreeView::certFromTemp()
@ -55,3 +55,10 @@ void TempTreeView::reqFromTemp()
pki_temp *temp = static_cast<pki_temp*>(currentIdx.internalPointer());
emit newReq(temp);
}
void TempTreeView::showPki(pki_base *pki) const
{
pki_temp *t = dynamic_cast<pki_temp *>(pki);
if (t && basemodel)
temps()->alterTemp(t);
}

View File

@ -10,30 +10,27 @@
#include "XcaTreeView.h"
#include "lib/db_temp.h"
#include "lib/database_model.h"
class TempTreeView: public XcaTreeView
{
Q_OBJECT
db_temp *temps;
db_temp *temps() const
{
return dynamic_cast<db_temp*>(basemodel);
}
public:
TempTreeView(QWidget *parent) : XcaTreeView(parent)
{
temps = NULL;
}
TempTreeView(QWidget *parent) : XcaTreeView(parent) { }
void fillContextMenu(QMenu *menu, QMenu *subExport,
const QModelIndex &index, QModelIndexList indexes);
void setModels(database_model *models)
{
temps = models->model<db_temp>();
XcaTreeView::setModel(temps);
}
void showPki(pki_base *pki) const;
public slots:
void certFromTemp();
void reqFromTemp();
void duplicateTemp();
signals:
void newReq(pki_temp *);
void newCert(pki_temp *);

View File

@ -5,9 +5,12 @@
* All rights reserved.
*/
#include "lib/pki_x509req.h"
#include "lib/db_x509super.h"
#include "lib/database_model.h"
#include "X509SuperTreeView.h"
#include "CertDetail.h"
#include "MainWindow.h"
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QMenu>
@ -33,22 +36,51 @@ void X509SuperTreeView::extractPubkey()
{
QModelIndex idx = currentIndex();
if (idx.isValid() && x509super)
x509super->extractPubkey(idx);
if (idx.isValid() && basemodel)
x509super()->extractPubkey(idx);
}
void X509SuperTreeView::toTemplate()
{
QModelIndex idx = currentIndex();
if (idx.isValid() && x509super)
x509super->toTemplate(idx);
if (idx.isValid() && basemodel)
x509super()->toTemplate(idx);
}
void X509SuperTreeView::toOpenssl()
{
QModelIndex idx = currentIndex();
if (idx.isValid() && x509super)
x509super->toOpenssl(idx);
if (idx.isValid() && basemodel)
x509super()->toOpenssl(idx);
}
void X509SuperTreeView::showPki(pki_base *pki) const
{
db_key *keys = models()->model<db_key>();
pki_x509super *x = dynamic_cast<pki_x509super *>(pki);
if (!x)
return;
CertDetail *dlg = new CertDetail(mainwin);
if (!dlg)
return;
dlg->setX509super(x);
connect(dlg->privKey, SIGNAL(doubleClicked(QString)),
mainwin->keyView, SLOT(showItem(QString)));
connect(dlg->signature, SIGNAL(doubleClicked(QString)),
this, SLOT(showItem(QString)));
connect(basemodel, SIGNAL(pkiChanged(pki_base*)),
dlg, SLOT(itemChanged(pki_base*)));
connect(keys, SIGNAL(pkiChanged(pki_base*)),
dlg, SLOT(itemChanged(pki_base*)));
if (dlg->exec() && basemodel) {
x509super()->updateItem(pki, dlg->descr->text(),
dlg->comment->toPlainText());
}
delete dlg;
}

View File

@ -14,21 +14,23 @@
class X509SuperTreeView: public XcaTreeView
{
Q_OBJECT
db_x509super *x509super;
db_x509super *x509super() const
{
return dynamic_cast<db_x509super*>(basemodel);
}
protected:
QMenu *transform;
public:
QMenu *transform;
X509SuperTreeView(QWidget *parent) : XcaTreeView(parent)
{
x509super = NULL;
transform = NULL;
}
void fillContextMenu(QMenu *menu, QMenu *subExport,
const QModelIndex &index, QModelIndexList indexes);
void setModel(QAbstractItemModel *model=NULL)
{
x509super = dynamic_cast<db_x509super*>(model);
XcaTreeView::setModel(x509super);
}
void showPki(pki_base *pki) const;
public slots:
void extractPubkey();

View File

@ -8,6 +8,8 @@
#include "XcaHeaderView.h"
#include "XcaTreeView.h"
#include <QContextMenuEvent>
XcaHeaderView::XcaHeaderView()
:QHeaderView(Qt::Horizontal)
{

View File

@ -5,19 +5,23 @@
* All rights reserved.
*/
#include "XcaHeaderView.h"
#include "XcaTreeView.h"
#include "XcaProxyModel.h"
#include "MainWindow.h"
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QContextMenuEvent>
#include <QMenu>
#include <QVariant>
#include <QRegExp>
#include "XcaHeaderView.h"
#include "XcaTreeView.h"
#include "XcaProxyModel.h"
#include "MainWindow.h"
#include "lib/database_model.h"
database_model *XcaTreeView::models() const
{
return mainwin ? mainwin->getModels() : NULL;
}
XcaTreeView::XcaTreeView(QWidget *parent)
:QTreeView(parent)
@ -90,11 +94,6 @@ void XcaTreeView::setMainwin(MainWindow *mw, QLineEdit *filter)
this, SLOT(setFilter(const QString&)));
}
void XcaTreeView::setModels(database_model *)
{
setModel(NULL);
}
void XcaTreeView::setModel(QAbstractItemModel *model)
{
QByteArray ba;
@ -263,11 +262,9 @@ void XcaTreeView::storeItems(void)
void XcaTreeView::showItems(void)
{
if (basemodel) {
QModelIndexList indexes = getSelectedIndexes();
foreach(QModelIndex index, indexes)
basemodel->showItem(index);
}
QModelIndexList indexes = getSelectedIndexes();
foreach(QModelIndex index, indexes)
showItem(index);
}
void XcaTreeView::newItem(void)
@ -284,8 +281,7 @@ void XcaTreeView::load(void)
void XcaTreeView::doubleClick(const QModelIndex &m)
{
if (basemodel)
basemodel->showItem(getIndex(m));
showItem(getIndex(m));
}
void XcaTreeView::editComment(void)
@ -312,6 +308,24 @@ void XcaTreeView::columnRemove(void)
curr_hd->action->setChecked(false);
}
void XcaTreeView::showItem(const QModelIndex &index)
{
pki_base *pki = static_cast<pki_base*>(index.internalPointer());
showItem(pki);
}
void XcaTreeView::showItem(const QString &name)
{
pki_base *pki = db_base::lookupPki<pki_base>(name.toULongLong());
showItem(pki);
}
void XcaTreeView::showItem(pki_base *pki)
{
if (pki && pki->isVisible() == 1)
showPki(pki);
}
static void addSubmenu(tipMenu *menu, tipMenu *sub)
{
if (sub->isEmpty())
@ -431,6 +445,7 @@ void XcaTreeView::showContextMenu(QContextMenuEvent *e,
contextMenu(e, menu, -1);
}
void XcaTreeView::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {

View File

@ -14,8 +14,14 @@
#include <QSortFilterProxyModel>
#include <QTimer>
#include "lib/db_base.h"
#include "lib/database_model.h"
class database_model;
class MainWindow;
class db_base;
class dbheader;
class pki_base;
class QKeyEvent;
class QContextMenuEvent;
class QMenu;
class XcaTreeView: public QTreeView
{
@ -28,13 +34,13 @@ class XcaTreeView: public QTreeView
db_base *basemodel;
QSortFilterProxyModel *proxy;
MainWindow *mainwin;
database_model *models() const;
public:
XcaTreeView(QWidget *parent = 0);
virtual ~XcaTreeView();
void contextMenuEvent(QContextMenuEvent *e);
virtual void setModels(database_model *);
virtual void setModel(QAbstractItemModel *model=NULL);
void setModel(QAbstractItemModel *model);
void setMainwin(MainWindow *mw, QLineEdit *filter);
QModelIndex getIndex(const QModelIndex &index);
QModelIndex getProxyIndex(const QModelIndex &index);
@ -51,6 +57,7 @@ class XcaTreeView: public QTreeView
void contextMenu(QContextMenuEvent *e,
QMenu *parent = NULL, int sect = -1);
void keyPressEvent(QKeyEvent *event);
virtual void showPki(pki_base *) const {};
public slots:
void showHideSections();
@ -69,5 +76,8 @@ class XcaTreeView: public QTreeView
void columnRemove(void);
void columnsChanged(void);
void editComment(void);
void showItem(pki_base *);
void showItem(const QModelIndex &index);
void showItem(const QString &name);
};
#endif