Support key files with Auto Open feature

Fixes #3495

* Look for keyfile in username parameter of the Auto Open entries. If present, pass on to unlock call to the database.
This commit is contained in:
metaphys 2019-09-03 23:17:33 +02:00 committed by Jonathan White
parent 0a75b47509
commit 72c1783b5b
4 changed files with 36 additions and 9 deletions

View file

@ -987,10 +987,8 @@ void DatabaseWidget::unlockDatabase(bool accepted)
}
replaceDatabase(db);
if (db->isReadOnly()) {
showMessage(tr("This database is opened in read-only mode. Autosave is disabled."),
MessageWidget::Warning,
false,
-1);
showMessage(
tr("This database is opened in read-only mode. Autosave is disabled."), MessageWidget::Warning, false, -1);
}
restoreGroupEntryFocus(m_groupBeforeLock, m_entryBeforeLock);
@ -1740,6 +1738,8 @@ void DatabaseWidget::processAutoOpen()
continue;
}
QFileInfo filepath;
QFileInfo keyfile;
if (entry->url().startsWith("file://")) {
QUrl url(entry->url());
filepath.setFile(url.toLocalFile());
@ -1755,7 +1755,20 @@ void DatabaseWidget::processAutoOpen()
continue;
}
// Request to open the database file in the background
emit requestOpenDatabase(filepath.canonicalFilePath(), true, entry->password());
if (!entry->username().isEmpty()) {
if (entry->username().startsWith("file://")) {
QUrl keyfileUrl(entry->username());
keyfile.setFile(keyfileUrl.toLocalFile());
} else {
keyfile.setFile(entry->username());
if (keyfile.isRelative()) {
QFileInfo currentpath(m_db->filePath());
keyfile.setFile(currentpath.absoluteDir(), entry->username());
}
}
}
// Request to open the database file in the background with a password and keyfile
emit requestOpenDatabase(filepath.canonicalFilePath(), true, entry->password(), keyfile.canonicalFilePath());
}
}