mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-03-01 10:51:20 -05:00
Fix opening files from command line
* Fix #2877 - password is unchecked by default * Smarter activation of key components based on contents of text entry fields * Prevent multiple copies of the same database from opening when the canonicalFileName != fileName
This commit is contained in:
parent
52d411f423
commit
edef225eab
@ -388,11 +388,31 @@ const Metadata* Database::metadata() const
|
|||||||
return m_metadata;
|
return m_metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the original file path that was provided for
|
||||||
|
* this database. This path may not exist, may contain
|
||||||
|
* unresolved symlinks, or have malformed slashes.
|
||||||
|
*
|
||||||
|
* @return original file path
|
||||||
|
*/
|
||||||
QString Database::filePath() const
|
QString Database::filePath() const
|
||||||
{
|
{
|
||||||
return m_data.filePath;
|
return m_data.filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the canonical file path of this databases'
|
||||||
|
* set file path. This returns an empty string if the
|
||||||
|
* file does not exist or cannot be resolved.
|
||||||
|
*
|
||||||
|
* @return canonical file path
|
||||||
|
*/
|
||||||
|
QString Database::canonicalFilePath() const
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(m_data.filePath);
|
||||||
|
return fileInfo.canonicalFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
void Database::setFilePath(const QString& filePath)
|
void Database::setFilePath(const QString& filePath)
|
||||||
{
|
{
|
||||||
if (filePath == m_data.filePath) {
|
if (filePath == m_data.filePath) {
|
||||||
|
@ -82,6 +82,7 @@ public:
|
|||||||
|
|
||||||
QUuid uuid() const;
|
QUuid uuid() const;
|
||||||
QString filePath() const;
|
QString filePath() const;
|
||||||
|
QString canonicalFilePath() const;
|
||||||
void setFilePath(const QString& filePath);
|
void setFilePath(const QString& filePath);
|
||||||
|
|
||||||
Metadata* metadata();
|
Metadata* metadata();
|
||||||
|
@ -45,7 +45,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
|
|||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
m_ui->messageWidget->setHidden(true);
|
m_ui->messageWidget->setHidden(true);
|
||||||
m_ui->checkPassword->setChecked(true);
|
|
||||||
|
|
||||||
QFont font = m_ui->labelHeadline->font();
|
QFont font = m_ui->labelHeadline->font();
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
@ -159,7 +158,7 @@ void DatabaseOpenWidget::clearForms()
|
|||||||
m_ui->editPassword->setText("");
|
m_ui->editPassword->setText("");
|
||||||
m_ui->comboKeyFile->clear();
|
m_ui->comboKeyFile->clear();
|
||||||
m_ui->comboKeyFile->setEditText("");
|
m_ui->comboKeyFile->setEditText("");
|
||||||
m_ui->checkPassword->setChecked(true);
|
m_ui->checkPassword->setChecked(false);
|
||||||
m_ui->checkKeyFile->setChecked(false);
|
m_ui->checkKeyFile->setChecked(false);
|
||||||
m_ui->checkChallengeResponse->setChecked(false);
|
m_ui->checkChallengeResponse->setChecked(false);
|
||||||
m_ui->checkTouchID->setChecked(false);
|
m_ui->checkTouchID->setChecked(false);
|
||||||
@ -174,13 +173,8 @@ QSharedPointer<Database> DatabaseOpenWidget::database()
|
|||||||
|
|
||||||
void DatabaseOpenWidget::enterKey(const QString& pw, const QString& keyFile)
|
void DatabaseOpenWidget::enterKey(const QString& pw, const QString& keyFile)
|
||||||
{
|
{
|
||||||
if (!pw.isEmpty()) {
|
m_ui->editPassword->setText(pw);
|
||||||
m_ui->editPassword->setText(pw);
|
m_ui->comboKeyFile->setEditText(keyFile);
|
||||||
}
|
|
||||||
if (!keyFile.isEmpty()) {
|
|
||||||
m_ui->comboKeyFile->setEditText(keyFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
openDatabase();
|
openDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,17 +333,20 @@ void DatabaseOpenWidget::reject()
|
|||||||
|
|
||||||
void DatabaseOpenWidget::activatePassword()
|
void DatabaseOpenWidget::activatePassword()
|
||||||
{
|
{
|
||||||
m_ui->checkPassword->setChecked(true);
|
bool hasPassword = !m_ui->editPassword->text().isEmpty();
|
||||||
|
m_ui->checkPassword->setChecked(hasPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseOpenWidget::activateKeyFile()
|
void DatabaseOpenWidget::activateKeyFile()
|
||||||
{
|
{
|
||||||
m_ui->checkKeyFile->setChecked(true);
|
bool hasKeyFile = !m_ui->comboKeyFile->lineEdit()->text().isEmpty();
|
||||||
|
m_ui->checkKeyFile->setChecked(hasKeyFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseOpenWidget::activateChallengeResponse()
|
void DatabaseOpenWidget::activateChallengeResponse()
|
||||||
{
|
{
|
||||||
m_ui->checkChallengeResponse->setChecked(true);
|
bool hasCR = m_ui->comboChallengeResponse->currentData().toInt() != -1;
|
||||||
|
m_ui->checkChallengeResponse->setChecked(hasCR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseOpenWidget::browseKeyFile()
|
void DatabaseOpenWidget::browseKeyFile()
|
||||||
@ -372,6 +369,7 @@ void DatabaseOpenWidget::pollYubikey()
|
|||||||
m_ui->checkChallengeResponse->setChecked(false);
|
m_ui->checkChallengeResponse->setChecked(false);
|
||||||
m_ui->comboChallengeResponse->setEnabled(false);
|
m_ui->comboChallengeResponse->setEnabled(false);
|
||||||
m_ui->comboChallengeResponse->clear();
|
m_ui->comboChallengeResponse->clear();
|
||||||
|
m_ui->comboChallengeResponse->addItem(tr("-- SELECT --"), -1);
|
||||||
m_ui->yubikeyProgress->setVisible(true);
|
m_ui->yubikeyProgress->setVisible(true);
|
||||||
|
|
||||||
// YubiKey init is slow, detect asynchronously to not block the UI
|
// YubiKey init is slow, detect asynchronously to not block the UI
|
||||||
@ -388,6 +386,7 @@ void DatabaseOpenWidget::yubikeyDetected(int slot, bool blocking)
|
|||||||
QHash<QString, QVariant> lastChallengeResponse = config()->get("LastChallengeResponse").toHash();
|
QHash<QString, QVariant> lastChallengeResponse = config()->get("LastChallengeResponse").toHash();
|
||||||
if (lastChallengeResponse.contains(m_filename)) {
|
if (lastChallengeResponse.contains(m_filename)) {
|
||||||
m_ui->checkChallengeResponse->setChecked(true);
|
m_ui->checkChallengeResponse->setChecked(true);
|
||||||
|
m_ui->comboChallengeResponse->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,10 +157,8 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath,
|
|||||||
for (int i = 0, c = count(); i < c; ++i) {
|
for (int i = 0, c = count(); i < c; ++i) {
|
||||||
auto* dbWidget = databaseWidgetFromIndex(i);
|
auto* dbWidget = databaseWidgetFromIndex(i);
|
||||||
Q_ASSERT(dbWidget);
|
Q_ASSERT(dbWidget);
|
||||||
if (dbWidget && dbWidget->database()->filePath() == canonicalFilePath) {
|
if (dbWidget && dbWidget->database()->canonicalFilePath() == canonicalFilePath) {
|
||||||
if (!password.isEmpty()) {
|
dbWidget->performUnlockDatabase(password, keyfile);
|
||||||
dbWidget->performUnlockDatabase(password, keyfile);
|
|
||||||
}
|
|
||||||
if (!inBackground) {
|
if (!inBackground) {
|
||||||
// switch to existing tab if file is already open
|
// switch to existing tab if file is already open
|
||||||
setCurrentIndex(indexOf(dbWidget));
|
setCurrentIndex(indexOf(dbWidget));
|
||||||
@ -171,9 +169,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath,
|
|||||||
|
|
||||||
auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::create(filePath), this);
|
auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::create(filePath), this);
|
||||||
addDatabaseTab(dbWidget, inBackground);
|
addDatabaseTab(dbWidget, inBackground);
|
||||||
if (!password.isEmpty()) {
|
dbWidget->performUnlockDatabase(password, keyfile);
|
||||||
dbWidget->performUnlockDatabase(password, keyfile);
|
|
||||||
}
|
|
||||||
updateLastDatabases(filePath);
|
updateLastDatabases(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user