forked from chris2511/xca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_token.cpp
More file actions
61 lines (55 loc) · 1.3 KB
/
db_token.cpp
File metadata and controls
61 lines (55 loc) · 1.3 KB
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;
}