File: TempTreeView.cpp

package info (click to toggle)
xca 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,328 kB
  • sloc: cpp: 30,584; sh: 341; xml: 74; makefile: 56; python: 34
file content (128 lines) | stat: -rw-r--r-- 2,693 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* vi: set sw=4 ts=4:
 *
 * Copyright (C) 2015 - 2020 Christian Hohnstaedt.
 *
 * All rights reserved.
 */

#include "lib/pki_temp.h"
#include "lib/load_obj.h"
#include "TempTreeView.h"
#include "ExportDialog.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()
{
	pki_temp *temp = db_base::fromIndex<pki_temp>(currentIndex());
    db_temp* db_temp = temps();
    if (!temp || !basemodel || !db_temp)
		return;

	pki_temp *newtemp = new pki_temp(temp);
	newtemp->setIntName(newtemp->getIntName() + " " + tr("copy"));
    db_temp->insertPKI(newtemp);
}

void TempTreeView::certFromTemp()
{
	pki_temp *temp = db_base::fromIndex<pki_temp>(currentIndex());
	if (temp)
		emit newCert(temp);
}

void TempTreeView::reqFromTemp()
{
	pki_temp *temp = db_base::fromIndex<pki_temp>(currentIndex());
	if (temp)
		emit newReq(temp);
}

void TempTreeView::showPki(pki_base *pki)
{
	alterTemp(dynamic_cast<pki_temp *>(pki));
}

bool TempTreeView::runTempDlg(pki_temp *temp)
{
	NewX509 *dlg = new NewX509(this);

	dlg->setTemp(temp, true);
	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(this, tmpl, ic,
				tr("Preset Template values"), QString());
	if (dlg->exec()) {
		temp = new pki_temp(ic->currentPkiItem());
		if (temp) {
			temp->pkiSource = generated;
			if (runTempDlg(temp)) {
				temp = dynamic_cast<pki_temp *>(
						temps()->insertPKI(temp));
				temps()->createSuccess(temp);
			} else {
				delete temp;
			}
		}
	}
	delete dlg;
}

bool TempTreeView::alterTemp(pki_temp *temp)
{
	if (!basemodel || !temp)
		return false;

	if (!runTempDlg(temp))
		return false;

	temps()->alterTemp(temp);
	return true;
}

void TempTreeView::load()
{
	load_temp l;
	load_default(&l);
}

ExportDialog *TempTreeView::exportDialog(const QModelIndexList &indexes)
{
	return new ExportDialog(this,
		tr("Template export"),
		tr("XCA Templates ( *.xca )"),
		indexes, QPixmap(":tempImg"),
		pki_export::select(tmpl, basemodel->exportFlags(indexes)));
}