34 lines
1.0 KiB
C++
34 lines
1.0 KiB
C++
#include "KeychainClass.hpp"
|
|
|
|
KeychainClass::KeychainClass(QObject *parent)
|
|
: QObject(parent),
|
|
readCredentialJob(QLatin1String(Keychain::url)),
|
|
writeCredentialJob(QLatin1String(Keychain::url)),
|
|
deleteCredentialJob(QLatin1String(Keychain::url)) {
|
|
readCredentialJob.setAutoDelete(false);
|
|
writeCredentialJob.setAutoDelete(false);
|
|
deleteCredentialJob.setAutoDelete(false);
|
|
}
|
|
|
|
void KeychainClass::readKey(QString const &key) {
|
|
readCredentialJob.setKey(key);
|
|
connect(&readCredentialJob, &QKeychain::ReadPasswordJob::finished, this, [this, key]() {
|
|
if (readCredentialJob.error())
|
|
return;
|
|
emit keyRead(key, readCredentialJob.textData());
|
|
});
|
|
|
|
readCredentialJob.start();
|
|
}
|
|
|
|
void KeychainClass::writeKey(QString const &key, QString const &value) {
|
|
writeCredentialJob.setKey(key);
|
|
writeCredentialJob.setTextData(value);
|
|
writeCredentialJob.start();
|
|
}
|
|
|
|
void KeychainClass::deleteKey(QString const &key) {
|
|
deleteCredentialJob.setKey(key);
|
|
deleteCredentialJob.start();
|
|
}
|