File: ReqTreeView.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 (80 lines) | stat: -rw-r--r-- 1,809 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
/* vi: set sw=4 ts=4:
 *
 * Copyright (C) 2015 Christian Hohnstaedt.
 *
 * All rights reserved.
 */

#include "lib/pki_x509req.h"
#include "lib/load_obj.h"
#include "ReqTreeView.h"
#include "MainWindow.h"
#include "ExportDialog.h"
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QMenu>

void ReqTreeView::fillContextMenu(QMenu *menu, QMenu *subExport,
		const QModelIndex &index, QModelIndexList indexes)
{
	X509SuperTreeView::fillContextMenu(menu, subExport, index, indexes);

	pki_x509req *req = db_base::fromIndex<pki_x509req>(index);

	if (indexes.size() != 1 || !req)
		return;

	menu->addAction(tr("Sign"), this, SLOT(signReq()));
	if (req->getDone())
		menu->addAction(tr("Unmark signed"),
				this, SLOT(unmarkSigned()));
	else
		menu->addAction(tr("Mark signed"),
				this, SLOT(markSigned()));
	if (transform) {
		transform->addAction(tr("Similar Request"), this,
				SLOT(toRequest()));
	}
}

void ReqTreeView::signReq()
{
	pki_x509req *req = db_base::fromIndex<pki_x509req>(currentIndex());
	db_x509 *certs = Database.model<db_x509>();
	certs->newCert(req);
}

void ReqTreeView::toRequest()
{
	pki_x509req *req = db_base::fromIndex<pki_x509req>(currentIndex());
	if (basemodel)
		reqs()->newItem(NULL, req);
}

void ReqTreeView::markSigned()
{
	if (basemodel)
		reqs()->setSigned(currentIndex(), true);
}

void ReqTreeView::unmarkSigned()
{
	if (basemodel)
		reqs()->setSigned(currentIndex(), false);
}

void ReqTreeView::load(void)
{
	load_req l;
	load_default(&l);
}

ExportDialog *ReqTreeView::exportDialog(const QModelIndexList &indexes)
{
	return new ExportDialog(this,
		tr("Certificate request export"),
		tr("Certificate request ( *.pem *.der *.csr )"),
		indexes, QPixmap(":csrImg"),
		pki_export::select(x509_req, basemodel->exportFlags(indexes)),
		"csrexport");
}