diff --git a/src/Cache.cpp b/src/Cache.cpp
index 5d11a178..dac0b23a 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -167,13 +167,14 @@ Cache::Cache(const QString &userId, QObject *parent)
void
Cache::setup()
{
- UserSettings settings;
+ auto settings = UserSettings::instance();
nhlog::db()->debug("setting up cache");
cacheDirectory_ = QString("%1/%2%3")
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
- .arg(QString::fromUtf8(localUserId_.toUtf8().toHex())).arg(QString::fromUtf8(settings.profile().toUtf8().toHex()));
+ .arg(QString::fromUtf8(localUserId_.toUtf8().toHex()))
+ .arg(QString::fromUtf8(settings->profile().toUtf8().toHex()));
bool isInitial = !QFile::exists(cacheDirectory_);
@@ -186,7 +187,9 @@ Cache::setup()
if (!QDir().mkpath(cacheDirectory_)) {
throw std::runtime_error(
- ("Unable to create state directory:" + cacheDirectory_).toStdString().c_str());
+ ("Unable to create state directory:" + cacheDirectory_)
+ .toStdString()
+ .c_str());
}
}
@@ -575,14 +578,14 @@ Cache::restoreOlmAccount()
void
Cache::storeSecret(const std::string &name, const std::string &secret)
{
- UserSettings settings;
+ auto settings = UserSettings::instance();
QKeychain::WritePasswordJob job(QCoreApplication::applicationName());
job.setAutoDelete(false);
job.setInsecureFallback(true);
- job.setKey(
- "matrix." +
- QString(QCryptographicHash::hash(settings.profile().toUtf8(), QCryptographicHash::Sha256)) +
- "." + name.c_str());
+ job.setKey("matrix." +
+ QString(QCryptographicHash::hash(settings->profile().toUtf8(),
+ QCryptographicHash::Sha256)) +
+ "." + name.c_str());
job.setTextData(QString::fromStdString(secret));
QEventLoop loop;
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
@@ -600,14 +603,14 @@ Cache::storeSecret(const std::string &name, const std::string &secret)
void
Cache::deleteSecret(const std::string &name)
{
- UserSettings settings;
+ auto settings = UserSettings::instance();
QKeychain::DeletePasswordJob job(QCoreApplication::applicationName());
job.setAutoDelete(false);
job.setInsecureFallback(true);
- job.setKey(
- "matrix." +
- QString(QCryptographicHash::hash(settings.profile().toUtf8(), QCryptographicHash::Sha256)) +
- "." + name.c_str());
+ job.setKey("matrix." +
+ QString(QCryptographicHash::hash(settings->profile().toUtf8(),
+ QCryptographicHash::Sha256)) +
+ "." + name.c_str());
QEventLoop loop;
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
job.start();
@@ -619,14 +622,14 @@ Cache::deleteSecret(const std::string &name)
std::optional<std::string>
Cache::secret(const std::string &name)
{
- UserSettings settings;
+ auto settings = UserSettings::instance();
QKeychain::ReadPasswordJob job(QCoreApplication::applicationName());
job.setAutoDelete(false);
job.setInsecureFallback(true);
- job.setKey(
- "matrix." +
- QString(QCryptographicHash::hash(settings.profile().toUtf8(), QCryptographicHash::Sha256)) +
- "." + name.c_str());
+ job.setKey("matrix." +
+ QString(QCryptographicHash::hash(settings->profile().toUtf8(),
+ QCryptographicHash::Sha256)) +
+ "." + name.c_str());
QEventLoop loop;
job.connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit);
job.start();
|