diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index 5701ccd55..d48d61e5a 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -42,7 +42,17 @@ namespace bool isQuickUnlockAvailable() { if (config()->get(Config::Security_QuickUnlock).toBool()) { - return getQuickUnlock()->isAvailable(); + auto qu = QuickUnlockManager::get()->getQuickUnlock(); + return qu && qu->isAvailable(); + } + return false; + } + + bool canPerformQuickUnlock(const QUuid& dbUuid) + { + if (isQuickUnlockAvailable()) { + auto qu = QuickUnlockManager::get()->getQuickUnlock(); + return qu->hasKey(dbUuid); } return false; } @@ -326,9 +336,9 @@ void DatabaseOpenWidget::openDatabase() // Save Quick Unlock credentials if available if (!blockQuickUnlock && isQuickUnlockAvailable()) { auto keyData = databaseKey->serialize(); - if (!getQuickUnlock()->setKey(m_db->publicUuid(), keyData) && !getQuickUnlock()->errorString().isEmpty()) { - getMainWindow()->displayTabMessage(getQuickUnlock()->errorString(), - MessageWidget::MessageType::Warning); + auto qu = QuickUnlockManager::get()->getQuickUnlock(); + if (!qu->setKey(m_db->publicUuid(), keyData) && !qu->errorString().isEmpty()) { + getMainWindow()->displayTabMessage(qu->errorString(), MessageWidget::MessageType::Warning); } m_ui->messageWidget->hideMessage(); } @@ -377,11 +387,12 @@ QSharedPointer DatabaseOpenWidget::buildDatabaseKey() if (!m_db.isNull() && canPerformQuickUnlock(m_db->publicUuid())) { // try to retrieve the stored password using quick unlock QByteArray keyData; - if (!getQuickUnlock()->getKey(m_db->publicUuid(), keyData)) { + auto qu = QuickUnlockManager::get()->getQuickUnlock(); + if (!qu->getKey(m_db->publicUuid(), keyData)) { m_ui->messageWidget->showMessage( - tr("Failed to authenticate with Quick Unlock: %1").arg(getQuickUnlock()->errorString()), + tr("Failed to authenticate with Quick Unlock: %1").arg(qu->errorString()), MessageWidget::Error); - if (!getQuickUnlock()->hasKey(m_db->publicUuid())) { + if (!qu->hasKey(m_db->publicUuid())) { resetQuickUnlock(); } return {}; @@ -616,7 +627,7 @@ void DatabaseOpenWidget::resetQuickUnlock() return; } if (!m_db.isNull()) { - getQuickUnlock()->reset(m_db->publicUuid()); + QuickUnlockManager::get()->getQuickUnlock()->reset(m_db->publicUuid()); } load(m_filename); } diff --git a/src/quickunlock/QuickUnlockInterface.cpp b/src/quickunlock/QuickUnlockInterface.cpp index a2cef251a..1863d0aa8 100644 --- a/src/quickunlock/QuickUnlockInterface.cpp +++ b/src/quickunlock/QuickUnlockInterface.cpp @@ -50,7 +50,7 @@ const QuickUnlockManager* QuickUnlockManager::get() return quickUnlockManager; } -QuickUnlockInterface* QuickUnlockManager::getQuickUnlock() +QuickUnlockInterface* QuickUnlockManager::getQuickUnlock() const { for (auto* interface : m_interfaces) { if (interface->isAvailable()) { diff --git a/src/quickunlock/QuickUnlockInterface.h b/src/quickunlock/QuickUnlockInterface.h index c2cc89773..aa6e1353b 100644 --- a/src/quickunlock/QuickUnlockInterface.h +++ b/src/quickunlock/QuickUnlockInterface.h @@ -51,8 +51,9 @@ public: ~QuickUnlockManager(); static const QuickUnlockManager* get(); + static bool isAvailable(); - QuickUnlockInterface* getQuickUnlock(); + QuickUnlockInterface* getQuickUnlock() const; private: QList m_interfaces;