forked from MUME/MMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordConfig.cpp
More file actions
60 lines (52 loc) 路 1.47 KB
/
Copy pathPasswordConfig.cpp
File metadata and controls
60 lines (52 loc) 路 1.47 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
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2019 The MMapper Authors
#include "PasswordConfig.h"
#include "../global/macros.h"
#ifndef MMAPPER_NO_QTKEYCHAIN
static const QString PASSWORD_KEY = QStringLiteral("password");
static const QString APP_NAME = QStringLiteral("org.mume.mmapper");
#endif
PasswordConfig::PasswordConfig(QObject *const parent)
: QObject(parent)
#ifndef MMAPPER_NO_QTKEYCHAIN
, m_readJob(APP_NAME)
, m_writeJob(APP_NAME)
{
m_readJob.setAutoDelete(false);
m_writeJob.setAutoDelete(false);
connect(&m_readJob, &QKeychain::ReadPasswordJob::finished, [this]() {
if (m_readJob.error()) {
emit sig_error(m_readJob.errorString());
} else {
emit sig_incomingPassword(m_readJob.textData());
}
});
connect(&m_writeJob, &QKeychain::WritePasswordJob::finished, [this]() {
if (m_writeJob.error()) {
emit sig_error(m_writeJob.errorString());
}
});
}
#else
{}
#endif
void PasswordConfig::setPassword(const QString &password)
{
#ifndef MMAPPER_NO_QTKEYCHAIN
m_writeJob.setKey(PASSWORD_KEY);
m_writeJob.setTextData(password);
m_writeJob.start();
#else
std::ignore = password;
emit sig_error("Password setting is not available.");
#endif
}
void PasswordConfig::getPassword()
{
#ifndef MMAPPER_NO_QTKEYCHAIN
m_readJob.setKey(PASSWORD_KEY);
m_readJob.start();
#else
emit sig_error("Password retrieval is not available.");
#endif
}