Add methods isHardwareKeySupported and refreshHardwareKeys to DBus

This commit is contained in:
Felix Stupp 2022-05-14 15:41:03 +02:00 committed by Jonathan White
parent 20a2a96222
commit de3d40b644
3 changed files with 45 additions and 0 deletions

View File

@ -716,6 +716,43 @@ void MainWindow::appExit()
close();
}
/**
* Returns if application was built with hardware key support.
* Intented to be used by 3rd-party applications using DBus.
*
* @return True if built with hardware key support, false otherwise
*/
bool MainWindow::isHardwareKeySupported()
{
#ifdef WITH_XC_YUBIKEY
return true;
#else
return false;
#endif
}
/**
* Refreshes list of hardware keys known.
* Triggers the DatabaseOpenWidget to automatically select the key last used for a database if found.
* Intented to be used by 3rd-party applications using DBus.
*
* @return True if any key was found, false otherwise or if application lacks hardware key support
*/
bool MainWindow::refreshHardwareKeys()
{
#ifdef WITH_XC_YUBIKEY
auto yk = YubiKey::instance();
// find keys sync to allow returning if any key was found
bool found = yk->findValidKeys();
// emit signal so DatabaseOpenWidget can select last used key
// emit here manually because sync findValidKeys() cannot do that properly
emit yk->detectComplete(found);
return found;
#else
return false;
#endif
}
void MainWindow::updateLastDatabasesMenu()
{
m_ui->menuRecentDatabases->clear();

View File

@ -69,6 +69,8 @@ signals:
public slots:
void openDatabase(const QString& filePath, const QString& password = {}, const QString& keyfile = {});
void appExit();
bool isHardwareKeySupported();
bool refreshHardwareKeys();
void displayGlobalMessage(const QString& text,
MessageWidget::MessageType type,
bool showClosebutton = true,

View File

@ -15,6 +15,12 @@
</method>
<method name="appExit">
</method>
<method name="isHardwareKeySupported">
<arg name="hardwareKeySupported" type="b" direction="out"/>
</method>
<method name="refreshHardwareKeys">
<arg name="found" type="b" direction="out"/>
</method>
<method name="lockAllDatabases">
</method>
<method name="closeAllDatabases">