File: db_token.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 (61 lines) | stat: -rw-r--r-- 1,328 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

#include "db_token.h"
#include "exception.h"
#include "pki_scard.h"
#include "sql.h"
#include "XcaWarningCore.h"

db_token::db_token() : db_base("manageTokens")
{
	updateHeaders();
}

void db_token::saveHeaderState()
{
}

void db_token::rename_token_in_database(pki_scard *token)
{
	if (!token)
		return;
	Transaction;
	if (!TransBegin())
		return;
	QList<pki_scard*> list = Store.sqlSELECTpki<pki_scard>(
                QString("SELECT item FROM tokens "
			"WHERE card_serial=? AND card_model=? and object_id=?"),
                QList<QVariant>() << QVariant(token->getSerial())
				<< QVariant(token->getModel())
				<< QVariant(token->getId()));

	foreach(pki_scard *item, list) {
		if (token->compare(item))
			item->updateLabel(token->getIntName());
	}
	TransCommit();
}

bool db_token::setData(const QModelIndex &index, const QVariant &value, int role)
{
	QString on, nn;
	pki_base *item;
	if (index.isValid() && role == Qt::EditRole) {
		nn = value.toString();
		item = fromIndex(index);
		on = item->getIntName();
		if (on == nn)
			return true;
		try {
			if (item->renameOnToken(slot, nn)) {
				item->setIntName(nn);
				rename_token_in_database(
					dynamic_cast<pki_scard*>(item));
				emit dataChanged(index, index);
				return true;
			}
		} catch (errorEx &err) {
			XCA_ERROR(err);
		}
	}
	return false;
}