mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
for certificates create a function returning a dynamically casted pki_x509 pointer Add NULL check of dynamically casted pointer, because it could be a folder...
122 lines
2.5 KiB
C++
122 lines
2.5 KiB
C++
/* vi: set sw=4 ts=4:
|
|
*
|
|
* Copyright (C) 2015 - 2020 Christian Hohnstaedt.
|
|
*
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#include "lib/pki_temp.h"
|
|
#include "TempTreeView.h"
|
|
#include "NewX509.h"
|
|
#include "XcaDialog.h"
|
|
#include "MainWindow.h"
|
|
#include <QAbstractItemModel>
|
|
#include <QAbstractItemView>
|
|
#include <QMenu>
|
|
|
|
void TempTreeView::fillContextMenu(QMenu *menu, QMenu *,
|
|
const QModelIndex &, QModelIndexList indexes)
|
|
{
|
|
if (indexes.size() != 1)
|
|
return;
|
|
|
|
menu->addAction(tr("Duplicate"), this, SLOT(duplicateTemp()));
|
|
menu->addAction(tr("Create certificate"), this, SLOT(certFromTemp()));
|
|
menu->addAction(tr("Create request"), this, SLOT(reqFromTemp()));
|
|
}
|
|
|
|
void TempTreeView::duplicateTemp()
|
|
{
|
|
QModelIndex currentIdx = currentIndex();
|
|
|
|
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);
|
|
}
|
|
|
|
void TempTreeView::certFromTemp()
|
|
{
|
|
QModelIndex currentIdx = currentIndex();
|
|
|
|
if (!currentIdx.isValid())
|
|
return;
|
|
pki_temp *temp = static_cast<pki_temp*>(currentIdx.internalPointer());
|
|
emit newCert(temp);
|
|
}
|
|
|
|
void TempTreeView::reqFromTemp()
|
|
{
|
|
QModelIndex currentIdx = currentIndex();
|
|
|
|
if (!currentIdx.isValid())
|
|
return;
|
|
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);
|
|
}
|
|
|
|
bool TempTreeView::runTempDlg(pki_temp *temp)
|
|
{
|
|
NewX509 *dlg = new NewX509(mainwin);
|
|
|
|
dlg->setTemp(temp);
|
|
if (!dlg->exec()) {
|
|
delete dlg;
|
|
return false;
|
|
}
|
|
dlg->toTemplate(temp);
|
|
delete dlg;
|
|
return true;
|
|
}
|
|
|
|
void TempTreeView::newItem()
|
|
{
|
|
pki_temp *temp = NULL;
|
|
QString type;
|
|
|
|
if (!basemodel)
|
|
return;
|
|
|
|
itemComboTemp *ic = new itemComboTemp(NULL);
|
|
ic->insertPkiItems(temps()->getPredefs());
|
|
XcaDialog *dlg = new XcaDialog(mainwin, tmpl, ic,
|
|
tr("Preset Template values"), QString());
|
|
if (dlg->exec()) {
|
|
temp = new pki_temp(ic->currentPkiItem());
|
|
if (temp) {
|
|
temp->pkiSource = generated;
|
|
if (runTempDlg(temp)) {
|
|
temps()->insertPKI(temp);
|
|
temps()->createSuccess(temp);
|
|
} else {
|
|
delete temp;
|
|
}
|
|
}
|
|
}
|
|
delete dlg;
|
|
}
|
|
|
|
bool TempTreeView::alterTemp(pki_temp *temp)
|
|
{
|
|
XSqlQuery q;
|
|
QSqlError e;
|
|
|
|
if (!basemodel)
|
|
return false;
|
|
|
|
if (!runTempDlg(temp))
|
|
return false;
|
|
|
|
temps()->alterTemp(temp);
|
|
return true;
|
|
}
|