From ffdc478f5c96000910c20f4fe51e92caec27f9ec Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Wed, 15 Nov 2006 11:38:32 +0100 Subject: [PATCH] move edit() to db_base for all ItemModels add EditRole to get the original name when editing delete the CA, client, server Templates and keep only one. --- lib/db_base.cpp | 9 +++++++++ lib/db_base.h | 3 +++ lib/db_crl.cpp | 4 ++-- lib/db_key.cpp | 8 +------- lib/db_key.h | 1 - lib/db_temp.cpp | 41 ++++++++--------------------------------- lib/db_temp.h | 10 +++++----- lib/db_x509.cpp | 12 +++--------- lib/db_x509.h | 1 - lib/db_x509req.cpp | 8 +------- lib/db_x509req.h | 1 - lib/pki_temp.cpp | 36 ++---------------------------------- lib/pki_temp.h | 3 +-- ui/MainWindow.ui | 29 ++++------------------------- widgets/MW_database.cpp | 19 ++----------------- widgets/MainWindow.h | 5 +---- 16 files changed, 42 insertions(+), 148 deletions(-) diff --git a/lib/db_base.cpp b/lib/db_base.cpp index be4be18e..a6620ad6 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -73,6 +73,7 @@ db_base::db_base(QString db, MainWindow *mw) headertext.clear(); mainwin = mw; currentIdx = QModelIndex(); + view = NULL; } db_base::~db_base() @@ -420,6 +421,7 @@ QVariant db_base::data(const QModelIndex &index, int role) const pki_base *item = static_cast(index.internalPointer()); switch (role) { + case Qt::EditRole: case Qt::DisplayRole: return item->column_data(index.column()); case Qt::DecorationRole: @@ -508,3 +510,10 @@ void db_base::load_default(load_base &load) delete dlgi; } +void db_base::edit() +{ + if (!currentIdx.isValid()) + return; + view->edit(currentIdx); +} + diff --git a/lib/db_base.h b/lib/db_base.h index 76438eb6..2fdbfb21 100644 --- a/lib/db_base.h +++ b/lib/db_base.h @@ -58,6 +58,7 @@ #include #include #include "pki_base.h" +#include "widgets/XcaTreeView.h" #define FOR_ALL_pki(pki, pki_type) \ for(pki_type *pki=(pki_type*)rootItem->iterate(); pki; pki=(pki_type*)pki->iterate()) @@ -78,6 +79,7 @@ class db_base: public QAbstractItemModel enum pki_type pkitype; QList headertext; MainWindow *mainwin; + XcaTreeView *view; public: pki_base *rootItem; @@ -135,6 +137,7 @@ class db_base: public QAbstractItemModel public slots: void deletePKI(); void delete_ask(); + void edit(); virtual void store(){}; virtual void showItem(){}; }; diff --git a/lib/db_crl.cpp b/lib/db_crl.cpp index 96252c58..2443cdaa 100644 --- a/lib/db_crl.cpp +++ b/lib/db_crl.cpp @@ -61,7 +61,7 @@ db_crl::db_crl(QString db, MainWindow *mw) rootItem = newPKI(); headertext << "Name" << "Common name" << "revoked"; delete_txt = tr("Delete the revokation list(s)"); - + view = mw->crlView; loadContainer(); } @@ -178,7 +178,7 @@ pki_crl *db_crl::newItem(pki_x509 *cert) cert->setLastCrl(time); crl->sign(cert->getRefKey(), EVP_sha1()); mainwin->certs->updatePKI(cert); - // FIXME: set Last update +#warning FIXME: set Last update insert(crl); } catch (errorEx &err) { diff --git a/lib/db_key.cpp b/lib/db_key.cpp index d4a388aa..3e4c465c 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -67,6 +67,7 @@ db_key::db_key(QString db, MainWindow *mw) rootItem = newPKI(); headertext << "Name" << "Type" << "Size" << "Use counter"; delete_txt = tr("Delete the key(s)"); + view = mw->keyView; loadContainer(); } @@ -218,13 +219,6 @@ void db_key::showItem() showItem(currentIdx); } -void db_key::edit() -{ - if (!currentIdx.isValid()) - return; - mainwin->keyView->edit(currentIdx); -} - void db_key::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) { QMenu *menu = new QMenu(mainwin); diff --git a/lib/db_key.h b/lib/db_key.h index 6d275ed0..93b78adc 100644 --- a/lib/db_key.h +++ b/lib/db_key.h @@ -79,7 +79,6 @@ class db_key: public db_base void load(void); void store(); void showItem(); - void edit(); void showItem(const QModelIndex &index); void setOwnPass(); void resetOwnPass(); diff --git a/lib/db_temp.cpp b/lib/db_temp.cpp index 061fcd1d..b726167e 100644 --- a/lib/db_temp.cpp +++ b/lib/db_temp.cpp @@ -62,6 +62,7 @@ db_temp::db_temp(QString DBfile, MainWindow *mw) rootItem = newPKI(); headertext << "Name" << "Type"; delete_txt = tr("Delete the key(s)"); + view = mw->tempView; loadContainer(); } @@ -72,7 +73,7 @@ pki_base *db_temp::newPKI(){ bool db_temp::runTempDlg(pki_temp *temp) { NewX509 *dlg = new NewX509(mainwin); - //emit connNewX509(dlg); + mainwin->connNewX509(dlg); dlg->setTemp(temp); dlg->fromTemplate(temp); @@ -85,29 +86,9 @@ bool db_temp::runTempDlg(pki_temp *temp) return true; } -void db_temp::newEmptyTemp() +void db_temp::newItem() { - newItem(pki_temp::EMPTY); -} - -void db_temp::newCaTemp() -{ - newItem(pki_temp::CA); -} - -void db_temp::newClientTemp() -{ - newItem(pki_temp::CLIENT); -} - -void db_temp::newServerTemp() -{ - newItem(pki_temp::SERVER); -} - -void db_temp::newItem(int type) -{ - pki_temp *temp = new pki_temp("--", type); + pki_temp *temp = new pki_temp("--"); if (runTempDlg(temp)) { insertPKI(temp); printf("Insert PKI temp\n"); @@ -188,7 +169,7 @@ void db_temp::certFromTemp() if (!currentIdx.isValid()) return; pki_temp *temp = static_cast(currentIdx.internalPointer()); -// newCert(temp); + emit newCert(temp); } void db_temp::reqFromTemp() @@ -196,24 +177,18 @@ void db_temp::reqFromTemp() if (!currentIdx.isValid()) return; pki_temp *temp = static_cast(currentIdx.internalPointer()); -// newReq(temp); + emit newReq(temp); } void db_temp::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) { QMenu *menu = new QMenu(mainwin); - QMenu *subMenu; currentIdx = index; - subMenu = menu->addMenu(tr("New Template")); - subMenu->addAction(tr("Empty"), this, SLOT(newEmptyTemp())); - subMenu->addAction(tr("CA"), this, SLOT(newCaTemp())); - subMenu->addAction(tr("Client"), this, SLOT(newClientTemp())); - subMenu->addAction(tr("Server"), this, SLOT(newServerTemp())); + menu->addAction(tr("New Template"), this, SLOT(newItem())); menu->addAction(tr("Import"), this, SLOT(load())); if (index != QModelIndex()) { - menu->addAction(tr("Rename"), mainwin->tempView, - SLOT(edit(currentIdx))); + menu->addAction(tr("Rename"), this, SLOT(edit())); menu->addAction(tr("Export"), this, SLOT(store())); menu->addAction(tr("Change"), this, SLOT(alterTemp())); menu->addAction(tr("Delete"), this, SLOT(deleteItem())); diff --git a/lib/db_temp.h b/lib/db_temp.h index 7d14df8c..252a4263 100644 --- a/lib/db_temp.h +++ b/lib/db_temp.h @@ -65,16 +65,12 @@ class db_temp: public db_base public: db_temp(QString DBfile, MainWindow *mw); pki_base *newPKI(); - void newItem(int type); bool runTempDlg(pki_temp *temp); bool alterTemp(pki_temp *temp); void showContextMenu(QContextMenuEvent *e, const QModelIndex &index); public slots: - void newEmptyTemp(); - void newCaTemp(); - void newClientTemp(); - void newServerTemp(); + void newItem(); void changeTemp(); void showItem(const QModelIndex &index); void showItem(); @@ -82,5 +78,9 @@ class db_temp: public db_base void store(); void certFromTemp(); void reqFromTemp(); + signals: + void newReq(pki_temp *); + void newCert(pki_temp *); + }; #endif diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index d00e8e81..2f6751d5 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -69,6 +69,7 @@ db_x509::db_x509(QString DBfile, MainWindow *mw) tr("not After") << tr("Trust state") << tr("Revocation"); delete_txt = tr("Delete the certificates(s)"); + view = mw->certView; loadContainer(); } @@ -361,12 +362,12 @@ void db_x509::newCert(pki_x509req *req) delete dlg; } -void db_x509::newCert(pki_temp *req) +void db_x509::newCert(pki_temp *temp) { NewX509 *dlg = new NewX509(mainwin); emit connNewX509(dlg); dlg->setCert(); - dlg->defineTemplate(req); + dlg->defineTemplate(temp); if (dlg->exec()) { newCert(dlg); } @@ -553,13 +554,6 @@ void db_x509::showItem(const QModelIndex &index) } } -void db_x509::edit() -{ - if (!currentIdx.isValid()) - return; - mainwin->certView->edit(currentIdx); -} - void db_x509::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) { QMenu *menu = new QMenu(mainwin); diff --git a/lib/db_x509.h b/lib/db_x509.h index 5c54887e..99144ea5 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -111,7 +111,6 @@ class db_x509: public db_x509super void toRequest(); void newCert(pki_temp *); void newCert(pki_x509req *); - void edit(); }; #endif diff --git a/lib/db_x509req.cpp b/lib/db_x509req.cpp index 7fe3a341..dd22f379 100644 --- a/lib/db_x509req.cpp +++ b/lib/db_x509req.cpp @@ -64,6 +64,7 @@ db_x509req::db_x509req(QString DBfile, MainWindow *mw) headertext << "Name" << "Subject" << "Serial" ; delete_txt = tr("Delete the request(s)"); loadContainer(); + view = mw->reqView; } pki_base *db_x509req::newPKI() @@ -181,13 +182,6 @@ void db_x509req::signReq() emit newCert(req); } -void db_x509req::edit() -{ - if (!currentIdx.isValid()) - return; - mainwin->reqView->edit(currentIdx); -} - void db_x509req::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) { QMenu *menu = new QMenu(mainwin); diff --git a/lib/db_x509req.h b/lib/db_x509req.h index 809f4ab1..96c8de9a 100644 --- a/lib/db_x509req.h +++ b/lib/db_x509req.h @@ -77,7 +77,6 @@ class db_x509req: public db_x509super void showItem(pki_x509req *req); void showItem(const QModelIndex &index); void signReq(void); - void edit(); signals: void newCert(pki_x509req *req); }; diff --git a/lib/pki_temp.cpp b/lib/pki_temp.cpp index 7027cf91..392d9511 100644 --- a/lib/pki_temp.cpp +++ b/lib/pki_temp.cpp @@ -94,7 +94,7 @@ pki_temp::pki_temp(const pki_temp *pk) eKeyUse=pk->eKeyUse; } -pki_temp::pki_temp(const QString d, int atype) +pki_temp::pki_temp(const QString d) :pki_base(d) { class_name = "pki_temp"; @@ -102,7 +102,7 @@ pki_temp::pki_temp(const QString d, int atype) pkiType=tmpl; cols=2; - type=atype; + type=0; subAltName=""; issAltName=""; crlDist=""; @@ -130,38 +130,6 @@ pki_temp::pki_temp(const QString d, int atype) validM=0; keyUse=0; eKeyUse=0; - if (type == CA) { - ca=1; - bcCrit=true; - subKey=true; - authKey=true; - issAltCp=false; - nsCertType=112; - keyUse=96; - validN=10; - validM=2; - } - if (type == CLIENT) { - ca=2; - bcCrit=true; - subKey=true; - authKey=true; - issAltCp=true; - subAltCp=true; - nsCertType=5; - keyUse=13; - } - if (type == SERVER) { - ca=2; - bcCrit=true; - subKey=true; - authKey=true; - issAltCp=true; - subAltCp=true; - nsCertType=2; - keyUse=7; - } - } diff --git a/lib/pki_temp.h b/lib/pki_temp.h index 7992c097..400b7e74 100644 --- a/lib/pki_temp.h +++ b/lib/pki_temp.h @@ -60,7 +60,6 @@ class pki_temp: public pki_base int version; int dataSize(); public: - enum { EMPTY, CA, CLIENT, SERVER }; static QPixmap *icon; x509name xname; QString subAltName, issAltName, crlDist, authInfAcc, certPol; @@ -74,7 +73,7 @@ class pki_temp: public pki_base // methods pki_temp(const pki_temp *pk); - pki_temp(const QString d, int atype=0); + pki_temp(const QString d); void loadTemp(const QString fname); void writeDefault(const QString fname); /* destructor */ diff --git a/ui/MainWindow.ui b/ui/MainWindow.ui index 77eaf4e3..c5cee155 100644 --- a/ui/MainWindow.ui +++ b/ui/MainWindow.ui @@ -407,30 +407,9 @@ 6 - + - New &empty template - - - - - - - New C&A template - - - - - - - New &client template - - - - - - - New &server template + &New template @@ -451,14 +430,14 @@ - Import + &Import - Export + &Export diff --git a/widgets/MW_database.cpp b/widgets/MW_database.cpp index 656191dd..c6c4c89f 100644 --- a/widgets/MW_database.cpp +++ b/widgets/MW_database.cpp @@ -316,25 +316,10 @@ void MainWindow::on_BNexportTemp_clicked(void) if(temps) temps->storeSelectedItems(tempView); } -void MainWindow::on_BNemptyTemp_clicked(void) +void MainWindow::on_BNnewTemp_clicked(void) { if (temps) - temps->newEmptyTemp(); -} -void MainWindow::on_BNcaTemp_clicked(void) -{ - if (temps) - temps->newCaTemp(); -} -void MainWindow::on_BNserverTemp_clicked(void) -{ - if (temps) - temps->newServerTemp(); -} -void MainWindow::on_BNclientTemp_clicked(void) -{ - if (temps) - temps->newClientTemp(); + temps->newItem(); } /* CRL buttons */ diff --git a/widgets/MainWindow.h b/widgets/MainWindow.h index 60fee791..638ca2cd 100644 --- a/widgets/MainWindow.h +++ b/widgets/MainWindow.h @@ -149,14 +149,11 @@ class MainWindow: public QMainWindow, public Ui::MainWindow void on_BNimportPKCS12_clicked(void); void on_BNimportPKCS7_clicked(void); + void on_BNnewTemp_clicked(void); void on_BNdeleteTemp_clicked(void); void on_BNchangeTemp_clicked(void); void on_BNimportTemp_clicked(void); void on_BNexportTemp_clicked(void); - void on_BNemptyTemp_clicked(void); - void on_BNcaTemp_clicked(void); - void on_BNserverTemp_clicked(void); - void on_BNclientTemp_clicked(void); void on_BNdeleteCrl_clicked(void); void on_BNdetailsCrl_clicked(void);