diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 87c7ce39..3912adab 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -324,20 +324,6 @@ void db_base::deletePKI(QModelIndex idx) } } -void db_base::showItem(const QModelIndex &index) -{ - pki_base *pki = static_cast(index.internalPointer()); - if (pki->isVisible() == 1) - showPki(pki); -} - -void db_base::showItem(const QString name) -{ - pki_base *pki = lookupPki(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(); diff --git a/lib/db_base.h b/lib/db_base.h index 47ee0f57..e2e03755 100644 --- a/lib/db_base.h +++ b/lib/db_base.h @@ -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); diff --git a/lib/db_crl.cpp b/lib/db_crl.cpp index 906acd4e..2b20119b 100644 --- a/lib/db_crl.cpp +++ b/lib/db_crl.cpp @@ -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(); - pki_crl *crl = dynamic_cast(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 types; diff --git a/lib/db_crl.h b/lib/db_crl.h index f1669206..b9f2ae1a 100644 --- a/lib/db_crl.h +++ b/lib/db_crl.h @@ -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); diff --git a/lib/db_key.cpp b/lib/db_key.cpp index 807b2d64..45870032 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -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); - 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 types; diff --git a/lib/db_key.h b/lib/db_key.h index 26223216..be06c66f 100644 --- a/lib/db_key.h +++ b/lib/db_key.h @@ -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); diff --git a/lib/db_temp.cpp b/lib/db_temp.cpp index 8a69ff39..013823fe 100644 --- a/lib/db_temp.cpp +++ b/lib/db_temp.cpp @@ -111,12 +111,6 @@ void db_temp::newItem() } delete dlg; } -void db_temp::showPki(pki_base *pki) -{ - pki_temp *t = dynamic_cast(pki); - if (t) - alterTemp(t); -} void db_temp::load() { diff --git a/lib/db_temp.h b/lib/db_temp.h index 3f57a401..5654c98e 100644 --- a/lib/db_temp.h +++ b/lib/db_temp.h @@ -30,7 +30,6 @@ class db_temp: public db_x509name void fillContextMenu(QMenu *menu, const QModelIndex &index); QList getAllAndPredefs(); void newItem(); - void showPki(pki_base *pki); void load(); void store(QModelIndex index); }; diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index ae849511..62ef13c5 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -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()) { diff --git a/lib/db_x509super.cpp b/lib/db_x509super.cpp index 20f9a5f9..d90e285c 100644 --- a/lib/db_x509super.cpp +++ b/lib/db_x509super.cpp @@ -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(); - pki_x509super *x = dynamic_cast(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; -} diff --git a/lib/db_x509super.h b/lib/db_x509super.h index efb74a27..98b89e7d 100644 --- a/lib/db_x509super.h +++ b/lib/db_x509super.h @@ -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 diff --git a/widgets/CertDetail.cpp b/widgets/CertDetail.cpp index d25a1822..ca2cd7fd 100644 --- a/widgets/CertDetail.cpp +++ b/widgets/CertDetail.cpp @@ -91,15 +91,18 @@ void CertDetail::setX509super(pki_x509super *x) // Comment comment->setPlainText(x->getComment()); + + setCert(dynamic_cast(x)); + setReq(dynamic_cast(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); diff --git a/widgets/CertDetail.h b/widgets/CertDetail.h index f33a11c2..7071fb61 100644 --- a/widgets/CertDetail.h +++ b/widgets/CertDetail.h @@ -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(); diff --git a/widgets/CertTreeView.cpp b/widgets/CertTreeView.cpp index 151822d0..af25eddc 100644 --- a/widgets/CertTreeView.cpp +++ b/widgets/CertTreeView.cpp @@ -7,6 +7,9 @@ #include "CertTreeView.h" #include "XcaWarning.h" +#include "lib/database_model.h" +#include "lib/db_crl.h" + #include #include #include @@ -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 (currentIndex().internalPointer()); - crls->newItem(cert); + + db_crl *crls = models()->model(); + 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()); } diff --git a/widgets/CertTreeView.h b/widgets/CertTreeView.h index 52947b43..14fa824c 100644 --- a/widgets/CertTreeView.h +++ b/widgets/CertTreeView.h @@ -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(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(); - crls = models->model(); - X509SuperTreeView::setModel(certs); - } public slots: void changeView(); diff --git a/widgets/CrlTreeView.cpp b/widgets/CrlTreeView.cpp index 81da0a96..06266ab9 100644 --- a/widgets/CrlTreeView.cpp +++ b/widgets/CrlTreeView.cpp @@ -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_crl *crls = dynamic_cast(basemodel); + pki_crl *crl = dynamic_cast(pki); -void CrlTreeView::setModels(database_model *models) -{ - db_crl *crls = models->model(); - 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; } diff --git a/widgets/CrlTreeView.h b/widgets/CrlTreeView.h index c310ddce..96c251c8 100644 --- a/widgets/CrlTreeView.h +++ b/widgets/CrlTreeView.h @@ -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 diff --git a/widgets/ImportMulti.cpp b/widgets/ImportMulti.cpp index 6c37e07c..25da1fe9 100644 --- a/widgets/ImportMulti.cpp +++ b/widgets/ImportMulti.cpp @@ -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)); + dlg->setX509super(dynamic_cast(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)); - 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)); diff --git a/widgets/KeyTreeView.cpp b/widgets/KeyTreeView.cpp index b788bf3f..ee761f51 100644 --- a/widgets/KeyTreeView.cpp +++ b/widgets/KeyTreeView.cpp @@ -8,6 +8,7 @@ #include "lib/pki_scard.h" #include "KeyTreeView.h" #include "MainWindow.h" +#include "KeyDetail.h" #include #include #include @@ -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(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); + 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; +} diff --git a/widgets/KeyTreeView.h b/widgets/KeyTreeView.h index 18822aed..4701872d 100644 --- a/widgets/KeyTreeView.h +++ b/widgets/KeyTreeView.h @@ -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(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(); - XcaTreeView::setModel(keys); - } + void showPki(pki_base *pki) const; public slots: void resetOwnPass(); diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index e1bce2cc..aa8b216e 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -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_key *keys = models->model(); + db_x509req *reqs = models->model(); 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()); + reqView->setModel(models->model()); + certView->setModel(models->model()); + tempView->setModel(models->model()); + crlView->setModel(models->model()); 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()); } diff --git a/widgets/MainWindow.h b/widgets/MainWindow.h index 47533c29..ebbd8028 100644 --- a/widgets/MainWindow.h +++ b/widgets/MainWindow.h @@ -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; } diff --git a/widgets/ReqTreeView.cpp b/widgets/ReqTreeView.cpp index 8089edff..c42c477b 100644 --- a/widgets/ReqTreeView.cpp +++ b/widgets/ReqTreeView.cpp @@ -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); } diff --git a/widgets/ReqTreeView.h b/widgets/ReqTreeView.h index 7ea5393d..e2f4cf15 100644 --- a/widgets/ReqTreeView.h +++ b/widgets/ReqTreeView.h @@ -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(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(); - X509SuperTreeView::setModel(reqs); - } public slots: void toRequest(); diff --git a/widgets/TempTreeView.cpp b/widgets/TempTreeView.cpp index 5f879b90..d2135369 100644 --- a/widgets/TempTreeView.cpp +++ b/widgets/TempTreeView.cpp @@ -28,12 +28,12 @@ void TempTreeView::duplicateTemp() { QModelIndex currentIdx = currentIndex(); - if (!currentIdx.isValid()) + if (!currentIdx.isValid() || !basemodel) return; pki_temp *temp = static_cast(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(currentIdx.internalPointer()); emit newReq(temp); } + +void TempTreeView::showPki(pki_base *pki) const +{ + pki_temp *t = dynamic_cast(pki); + if (t && basemodel) + temps()->alterTemp(t); +} diff --git a/widgets/TempTreeView.h b/widgets/TempTreeView.h index fd66f5da..8dd9155a 100644 --- a/widgets/TempTreeView.h +++ b/widgets/TempTreeView.h @@ -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(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(); - 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 *); diff --git a/widgets/X509SuperTreeView.cpp b/widgets/X509SuperTreeView.cpp index 4849646f..99b0648b 100644 --- a/widgets/X509SuperTreeView.cpp +++ b/widgets/X509SuperTreeView.cpp @@ -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 #include #include @@ -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(); + pki_x509super *x = dynamic_cast(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; } diff --git a/widgets/X509SuperTreeView.h b/widgets/X509SuperTreeView.h index d949695c..bd05afbd 100644 --- a/widgets/X509SuperTreeView.h +++ b/widgets/X509SuperTreeView.h @@ -14,21 +14,23 @@ class X509SuperTreeView: public XcaTreeView { Q_OBJECT - db_x509super *x509super; + + db_x509super *x509super() const + { + return dynamic_cast(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(model); - XcaTreeView::setModel(x509super); - } + void showPki(pki_base *pki) const; public slots: void extractPubkey(); diff --git a/widgets/XcaHeaderView.cpp b/widgets/XcaHeaderView.cpp index f8b75265..041c7610 100644 --- a/widgets/XcaHeaderView.cpp +++ b/widgets/XcaHeaderView.cpp @@ -8,6 +8,8 @@ #include "XcaHeaderView.h" #include "XcaTreeView.h" +#include + XcaHeaderView::XcaHeaderView() :QHeaderView(Qt::Horizontal) { diff --git a/widgets/XcaTreeView.cpp b/widgets/XcaTreeView.cpp index 700702b8..9d5cb241 100644 --- a/widgets/XcaTreeView.cpp +++ b/widgets/XcaTreeView.cpp @@ -5,19 +5,23 @@ * All rights reserved. */ - -#include "XcaHeaderView.h" -#include "XcaTreeView.h" -#include "XcaProxyModel.h" -#include "MainWindow.h" #include #include #include #include #include #include + +#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(index.internalPointer()); + showItem(pki); +} + +void XcaTreeView::showItem(const QString &name) +{ + pki_base *pki = db_base::lookupPki(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()) { diff --git a/widgets/XcaTreeView.h b/widgets/XcaTreeView.h index 1e4b0e4b..99a54cd7 100644 --- a/widgets/XcaTreeView.h +++ b/widgets/XcaTreeView.h @@ -14,8 +14,14 @@ #include #include -#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