1 /* vi: set sw=4 ts=4:
2 *
3 * Copyright (C) 2015 Christian Hohnstaedt.
4 *
5 * All rights reserved.
6 */
7
8 #include "lib/pki_x509req.h"
9 #include "ReqTreeView.h"
10 #include "MainWindow.h"
11 #include <QAbstractItemModel>
12 #include <QAbstractItemView>
13 #include <QMenu>
14
fillContextMenu(QMenu * menu,QMenu * subExport,const QModelIndex & index,QModelIndexList indexes)15 void ReqTreeView::fillContextMenu(QMenu *menu, QMenu *subExport,
16 const QModelIndex &index, QModelIndexList indexes)
17 {
18 X509SuperTreeView::fillContextMenu(menu, subExport, index, indexes);
19
20 pki_x509req *req = db_base::fromIndex<pki_x509req>(index);
21
22 if (indexes.size() != 1 || !req)
23 return;
24
25 menu->addAction(tr("Sign"), this, SLOT(signReq()));
26 if (req->getDone())
27 menu->addAction(tr("Unmark signed"),
28 this, SLOT(unmarkSigned()));
29 else
30 menu->addAction(tr("Mark signed"),
31 this, SLOT(markSigned()));
32 if (transform) {
33 transform->addAction(tr("Similar Request"), this,
34 SLOT(toRequest()));
35 }
36 }
37
signReq()38 void ReqTreeView::signReq()
39 {
40 pki_x509req *req = db_base::fromIndex<pki_x509req>(currentIndex());
41 db_x509 *certs = Database.model<db_x509>();
42 certs->newCert(req);
43 }
44
toRequest()45 void ReqTreeView::toRequest()
46 {
47 pki_x509req *req = db_base::fromIndex<pki_x509req>(currentIndex());
48 if (basemodel)
49 reqs()->newItem(NULL, req);
50 }
51
markSigned()52 void ReqTreeView::markSigned()
53 {
54 if (basemodel)
55 reqs()->setSigned(currentIndex(), true);
56 }
57
unmarkSigned()58 void ReqTreeView::unmarkSigned()
59 {
60 if (basemodel)
61 reqs()->setSigned(currentIndex(), false);
62 }
63