From f6933a88681cd57fd3d08db290ff4966eda810ad Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 24 Oct 2017 15:25:38 +0200 Subject: Ensure that YubiKey is only polled once, even if showEvent() is called twice --- src/gui/DatabaseOpenWidget.cpp | 18 +++++++++++++----- src/gui/DatabaseOpenWidget.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index ee0e9de26..e487f97ca 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -95,11 +95,16 @@ void DatabaseOpenWidget::showEvent(QShowEvent* event) m_ui->editPassword->setFocus(); #ifdef WITH_XC_YUBIKEY - connect(YubiKey::instance(), SIGNAL(detected(int,bool)), SLOT(yubikeyDetected(int,bool)), Qt::QueuedConnection); - connect(YubiKey::instance(), SIGNAL(detectComplete()), SLOT(yubikeyDetectComplete()), Qt::QueuedConnection); - connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection); - - pollYubikey(); + // showEvent() may be called twice, so make sure we are only polling once + if (!m_yubiKeyBeingPolled) { + connect(YubiKey::instance(), SIGNAL(detected(int, bool)), SLOT(yubikeyDetected(int, bool)), + Qt::QueuedConnection); + connect(YubiKey::instance(), SIGNAL(detectComplete()), SLOT(yubikeyDetectComplete()), Qt::QueuedConnection); + connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection); + + pollYubikey(); + m_yubiKeyBeingPolled = true; + } #endif } @@ -110,6 +115,7 @@ void DatabaseOpenWidget::hideEvent(QHideEvent* event) #ifdef WITH_XC_YUBIKEY // Don't listen to any Yubikey events if we are hidden disconnect(YubiKey::instance(), 0, this, 0); + m_yubiKeyBeingPolled = false; #endif } @@ -311,10 +317,12 @@ void DatabaseOpenWidget::yubikeyDetectComplete() m_ui->checkChallengeResponse->setEnabled(true); m_ui->buttonRedetectYubikey->setEnabled(true); m_ui->yubikeyProgress->setVisible(false); + m_yubiKeyBeingPolled = false; } void DatabaseOpenWidget::noYubikeyFound() { m_ui->buttonRedetectYubikey->setEnabled(true); m_ui->yubikeyProgress->setVisible(false); + m_yubiKeyBeingPolled = false; } diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h index a7691a91e..aade111c3 100644 --- a/src/gui/DatabaseOpenWidget.h +++ b/src/gui/DatabaseOpenWidget.h @@ -73,6 +73,7 @@ protected: QString m_filename; private: + bool m_yubiKeyBeingPolled = false; Q_DISABLE_COPY(DatabaseOpenWidget) }; -- cgit v1.2.3 From 05d02b702ad232f673860457dfe9ee258a1e937d Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Tue, 24 Oct 2017 15:07:10 +0200 Subject: Restrict global menu fix to Qt < 5.9.0, resolves #691 --- src/gui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index f1d5f866c..e37a7d28c 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -881,7 +881,7 @@ void MainWindow::toggleWindow() raise(); activateWindow(); -#if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS) +#if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS) && (QT_VERSION < QT_VERSION_CHECK(5, 9, 0)) // re-register global D-Bus menu (needed on Ubuntu with Unity) // see https://github.com/keepassxreboot/keepassxc/issues/271 // and https://bugreports.qt.io/browse/QTBUG-58723 -- cgit v1.2.3 From 4e7f2c6a4fe920ec4301b110258f894fc9ea87bf Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 28 Oct 2017 09:23:45 -0400 Subject: Fix apply button not saving new entries --- src/gui/entry/EditEntryWidget.cpp | 4 +++- src/gui/entry/EditEntryWidget.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 809ac95eb..5a058bda4 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -278,6 +278,7 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q m_database = database; m_create = create; m_history = history; + m_saved = false; if (history) { setHeadline(QString("%1 > %2").arg(parentName, tr("Entry history"))); @@ -438,6 +439,7 @@ void EditEntryWidget::saveEntry() } updateEntryData(m_entry); + m_saved = true; if (!m_create) { m_entry->endUpdate(); @@ -510,7 +512,7 @@ void EditEntryWidget::cancel() clear(); - emit editFinished(false); + emit editFinished(m_saved); } void EditEntryWidget::clear() diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index 2888d43a8..628f8f8ed 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -121,6 +121,7 @@ private: bool m_create; bool m_history; + bool m_saved; const QScopedPointer m_mainUi; const QScopedPointer m_advancedUi; const QScopedPointer m_autoTypeUi; -- cgit v1.2.3 From e17b3d24bfa19c199bcfe0ebffe0ae036378af4a Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Thu, 23 Nov 2017 12:51:02 -0500 Subject: Corrected database corruption when locked [#1113] --- src/gui/DatabaseTabWidget.cpp | 16 +++++++++------- src/gui/DatabaseWidget.cpp | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 4c9445ccc..f70df4c79 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -298,8 +298,7 @@ bool DatabaseTabWidget::closeDatabase(Database* db) if (!saveDatabase(db)) { return false; } - } - else { + } else if (dbStruct.dbWidget->currentMode() != DatabaseWidget::LockedMode) { QMessageBox::StandardButton result = MessageBox::question( this, tr("Save changes?"), @@ -307,10 +306,9 @@ bool DatabaseTabWidget::closeDatabase(Database* db) QMessageBox::Yes | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Yes); if (result == QMessageBox::Yes) { if (!saveDatabase(db)) { - return false; + return false; } - } - else if (result == QMessageBox::Cancel) { + } else if (result == QMessageBox::Cancel) { return false; } } @@ -355,8 +353,13 @@ bool DatabaseTabWidget::saveDatabase(Database* db) { DatabaseManagerStruct& dbStruct = m_dbList[db]; - if (dbStruct.saveToFilename) { + if (dbStruct.dbWidget->currentMode() == DatabaseWidget::LockedMode) { + // Never allow saving a locked database; it causes corruption + // We return true since a save is not required + return true; + } + if (dbStruct.saveToFilename) { dbStruct.dbWidget->blockAutoReload(true); QString errorMessage = db->saveToFile(dbStruct.canonicalFilePath); dbStruct.dbWidget->blockAutoReload(false); @@ -375,7 +378,6 @@ bool DatabaseTabWidget::saveDatabase(Database* db) MessageWidget::Error); return false; } - } else { return saveDatabaseAs(db); } diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 3a39bddcf..453b2009b 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1125,7 +1125,7 @@ void DatabaseWidget::onWatchedFileChanged() void DatabaseWidget::reloadDatabaseFile() { - if (m_db == nullptr) + if (m_db == nullptr || currentMode() == DatabaseWidget::LockedMode) return; if (! config()->get("AutoReloadOnChange").toBool()) { -- cgit v1.2.3 From 8905fe5a5455f2c8d7a5b6ffddf0ae9e0116cbc8 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sun, 26 Nov 2017 16:48:09 +0100 Subject: Use Consolas on Windows for PasswordEdit instead of the default Courier New, resolves #1226 --- src/gui/PasswordEdit.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/PasswordEdit.cpp b/src/gui/PasswordEdit.cpp index 54b0ca288..ad736bf20 100644 --- a/src/gui/PasswordEdit.cpp +++ b/src/gui/PasswordEdit.cpp @@ -31,9 +31,18 @@ PasswordEdit::PasswordEdit(QWidget* parent) { setEchoMode(QLineEdit::Password); updateStylesheet(); - - // set font to system monospace font and increase letter spacing + + // use a monospace font for the password field QFont passwordFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); +#ifdef Q_OS_WIN + // try to use Consolas on Windows, because the default Courier New has too many similar characters + QFont consolasFont = QFontDatabase().font("Consolas", passwordFont.styleName(), passwordFont.pointSize()); + const QFont defaultFont; + if (passwordFont != defaultFont) { + passwordFont = consolasFont; + } +#endif + passwordFont.setLetterSpacing(QFont::PercentageSpacing, 110); setFont(passwordFont); } -- cgit v1.2.3 From 0ff75e7a882523d49c5bf74a32fcb68d0d7b1afc Mon Sep 17 00:00:00 2001 From: Michal Kaptur Date: Mon, 27 Nov 2017 21:41:58 +0100 Subject: Fixed memory leaks in non-gui tests Fixed 2 memory leaks in production code and a few in testcases. As a result leak_check_at_exit ASAN option does not need to turned off for non-gui tests. Smart pointers should be used elsewhere for consistency, but the sooner this fixes are delivered, the lesser memory leaks are introduced. --- src/gui/DatabaseRepairWidget.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/DatabaseRepairWidget.cpp b/src/gui/DatabaseRepairWidget.cpp index 2b0039408..d3dddf14f 100644 --- a/src/gui/DatabaseRepairWidget.cpp +++ b/src/gui/DatabaseRepairWidget.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Felix Geyer + * Copyright (C) 2017 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -69,7 +70,8 @@ void DatabaseRepairWidget::openDatabase() delete m_db; } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - KeePass2Repair::RepairResult repairResult = repair.repairDatabase(&file, masterKey); + auto repairOutcome = repair.repairDatabase(&file, masterKey); + KeePass2Repair::RepairResult repairResult = repairOutcome.first; QApplication::restoreOverrideCursor(); switch (repairResult) { @@ -83,7 +85,7 @@ void DatabaseRepairWidget::openDatabase() emit editFinished(false); return; case KeePass2Repair::RepairSuccess: - m_db = repair.database(); + m_db = repairOutcome.second; MessageBox::warning(this, tr("Success"), tr("The database has been successfully repaired\nYou can now save it.")); emit editFinished(true); return; -- cgit v1.2.3