33
44#include " PasswordConfig.h"
55
6- #include " ../global/macros.h"
6+ #include " ../global/ConfigConsts-Computed.h"
7+ #include " ../global/ConfigEnums.h"
8+ #include " configuration.h"
79
810#ifndef MMAPPER_NO_QTKEYCHAIN
911static const QLatin1String PASSWORD_KEY (" password" );
@@ -15,21 +17,43 @@ PasswordConfig::PasswordConfig(QObject *const parent)
1517#ifndef MMAPPER_NO_QTKEYCHAIN
1618 , m_readJob(APP_NAME )
1719 , m_writeJob(APP_NAME )
20+ , m_deleteJob(APP_NAME )
1821{
1922 m_readJob.setAutoDelete (false );
2023 m_writeJob.setAutoDelete (false );
24+ m_deleteJob.setAutoDelete (false );
2125
22- connect (&m_readJob, &QKeychain::ReadPasswordJob::finished, [this ]() {
26+ auto handleError = [this ](const QKeychain::Job &job) {
27+ if constexpr (CURRENT_PLATFORM == PlatformEnum::Wasm) {
28+ if (job.error () == QKeychain::AccessDeniedByUser) {
29+ return true ;
30+ }
31+ }
32+ emit sig_error (job.errorString ());
33+ return false ;
34+ };
35+
36+ connect (&m_readJob, &QKeychain::ReadPasswordJob::finished, [this , handleError]() {
2337 if (m_readJob.error ()) {
24- emit sig_error (m_readJob. errorString () );
38+ handleError (m_readJob);
2539 } else {
2640 emit sig_incomingPassword (m_readJob.textData ());
2741 }
2842 });
2943
30- connect (&m_writeJob, &QKeychain::WritePasswordJob::finished, [this ]() {
44+ connect (&m_writeJob, &QKeychain::WritePasswordJob::finished, [this , handleError ]() {
3145 if (m_writeJob.error ()) {
32- emit sig_error (m_writeJob.errorString ());
46+ handleError (m_writeJob);
47+ } else {
48+ emit sig_passwordSaved ();
49+ }
50+ });
51+
52+ connect (&m_deleteJob, &QKeychain::DeletePasswordJob::finished, [this , handleError]() {
53+ if (m_deleteJob.error ()) {
54+ handleError (m_deleteJob);
55+ } else {
56+ emit sig_passwordDeleted ();
3357 }
3458 });
3559}
@@ -41,7 +65,11 @@ PasswordConfig::PasswordConfig(QObject *const parent)
4165void PasswordConfig::setPassword (const QString &password)
4266{
4367#ifndef MMAPPER_NO_QTKEYCHAIN
44- m_writeJob.setKey (PASSWORD_KEY );
68+ if constexpr (CURRENT_PLATFORM == PlatformEnum::Wasm) {
69+ m_writeJob.setKey (getConfig ().account .accountName );
70+ } else {
71+ m_writeJob.setKey (PASSWORD_KEY );
72+ }
4573 m_writeJob.setTextData (password);
4674 m_writeJob.start ();
4775#else
@@ -53,9 +81,27 @@ void PasswordConfig::setPassword(const QString &password)
5381void PasswordConfig::getPassword ()
5482{
5583#ifndef MMAPPER_NO_QTKEYCHAIN
56- m_readJob.setKey (PASSWORD_KEY );
84+ if constexpr (CURRENT_PLATFORM == PlatformEnum::Wasm) {
85+ m_readJob.setKey (getConfig ().account .accountName );
86+ } else {
87+ m_readJob.setKey (PASSWORD_KEY );
88+ }
5789 m_readJob.start ();
5890#else
5991 emit sig_error (" Password retrieval is not available." );
6092#endif
6193}
94+
95+ void PasswordConfig::deletePassword ()
96+ {
97+ #ifndef MMAPPER_NO_QTKEYCHAIN
98+ if constexpr (CURRENT_PLATFORM == PlatformEnum::Wasm) {
99+ m_deleteJob.setKey (getConfig ().account .accountName );
100+ } else {
101+ m_deleteJob.setKey (PASSWORD_KEY );
102+ }
103+ m_deleteJob.start ();
104+ #else
105+ emit sig_error (" Password deletion is not available." );
106+ #endif
107+ }
0 commit comments