Skip to content

Commit

Permalink
Fix bugs with preview widget
Browse files Browse the repository at this point in the history
* Add configuration to hide TOTP in preview widget (shown by default).

* Retain the visibility of TOTP and other fields when the same entry remains selected in the preview panel.

* Fix disconnecting signals when switch entries / groups. This likely is going to fix crashes because we were compounding signals when focusing in on the main window.
  • Loading branch information
droidmonkey committed Feb 27, 2023
1 parent 5b31288 commit ab8f6d9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
4 changes: 4 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@
<source>Use DuckDuckGo service to download website icons</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Hide TOTP in the entry preview panel</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AutoType</name>
Expand Down
1 change: 1 addition & 0 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::Security_PasswordsHidden, {QS("Security/PasswordsHidden"), Roaming, true}},
{Config::Security_PasswordEmptyPlaceholder, {QS("Security/PasswordEmptyPlaceholder"), Roaming, false}},
{Config::Security_HidePasswordPreviewPanel, {QS("Security/HidePasswordPreviewPanel"), Roaming, true}},
{Config::Security_HideTotpPreviewPanel, {QS("Security/HideTotpPreviewPanel"), Roaming, false}},
{Config::Security_AutoTypeAsk, {QS("Security/AutotypeAsk"), Roaming, true}},
{Config::Security_IconDownloadFallback, {QS("Security/IconDownloadFallback"), Roaming, false}},
{Config::Security_NoConfirmMoveEntryToRecycleBin,{QS("Security/NoConfirmMoveEntryToRecycleBin"), Roaming, true}},
Expand Down
1 change: 1 addition & 0 deletions src/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Config : public QObject
Security_PasswordsHidden,
Security_PasswordEmptyPlaceholder,
Security_HidePasswordPreviewPanel,
Security_HideTotpPreviewPanel,
Security_AutoTypeAsk,
Security_IconDownloadFallback,
Security_NoConfirmMoveEntryToRecycleBin,
Expand Down
2 changes: 2 additions & 0 deletions src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ void ApplicationSettingsWidget::loadSettings()
m_secUi->passwordShowDotsCheckBox->setChecked(config()->get(Config::Security_PasswordEmptyPlaceholder).toBool());
m_secUi->passwordPreviewCleartextCheckBox->setChecked(
config()->get(Config::Security_HidePasswordPreviewPanel).toBool());
m_secUi->hideTotpCheckBox->setChecked(config()->get(Config::Security_HideTotpPreviewPanel).toBool());
m_secUi->passwordsRepeatVisibleCheckBox->setChecked(
config()->get(Config::Security_PasswordsRepeatVisible).toBool());
m_secUi->hideNotesCheckBox->setChecked(config()->get(Config::Security_HideNotes).toBool());
Expand Down Expand Up @@ -427,6 +428,7 @@ void ApplicationSettingsWidget::saveSettings()
config()->set(Config::Security_PasswordEmptyPlaceholder, m_secUi->passwordShowDotsCheckBox->isChecked());

config()->set(Config::Security_HidePasswordPreviewPanel, m_secUi->passwordPreviewCleartextCheckBox->isChecked());
config()->set(Config::Security_HideTotpPreviewPanel, m_secUi->hideTotpCheckBox->isChecked());
config()->set(Config::Security_PasswordsRepeatVisible, m_secUi->passwordsRepeatVisibleCheckBox->isChecked());
config()->set(Config::Security_HideNotes, m_secUi->hideNotesCheckBox->isChecked());
config()->set(Config::Security_NoConfirmMoveEntryToRecycleBin,
Expand Down
7 changes: 7 additions & 0 deletions src/gui/ApplicationSettingsWidgetSecurity.ui
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hideTotpCheckBox">
<property name="text">
<string>Hide TOTP in the entry preview panel</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hideNotesCheckBox">
<property name="text">
Expand Down
32 changes: 22 additions & 10 deletions src/gui/EntryPreviewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,50 @@ void EntryPreviewWidget::clear()

void EntryPreviewWidget::setEntry(Entry* selectedEntry)
{
if (m_currentEntry == selectedEntry) {
return;
}

if (m_currentEntry) {
disconnect(m_currentEntry);
disconnect(m_currentEntry, nullptr, this, nullptr);
}
if (m_currentGroup) {
disconnect(m_currentGroup);
disconnect(m_currentGroup, nullptr, this, nullptr);
}

m_currentEntry = selectedEntry;
m_currentGroup = nullptr;

if (!selectedEntry) {
if (!m_currentEntry) {
hide();
return;
}

connect(selectedEntry, &Entry::modified, this, &EntryPreviewWidget::refresh);
connect(m_currentEntry, &Entry::modified, this, &EntryPreviewWidget::refresh);
refresh();

if (m_currentEntry->hasTotp()) {
m_ui->entryTotpButton->setChecked(!config()->get(Config::Security_HideTotpPreviewPanel).toBool());
}
}

void EntryPreviewWidget::setGroup(Group* selectedGroup)
{
if (m_currentGroup == selectedGroup) {
return;
}

if (m_currentEntry) {
disconnect(m_currentEntry);
disconnect(m_currentEntry, nullptr, this, nullptr);
}
if (m_currentGroup) {
disconnect(m_currentGroup);
disconnect(m_currentGroup, nullptr, this, nullptr);
}

m_currentEntry = nullptr;
m_currentGroup = selectedGroup;

if (!selectedGroup) {
if (!m_currentGroup) {
hide();
return;
}
Expand Down Expand Up @@ -226,15 +238,15 @@ void EntryPreviewWidget::updateEntryTotp()
Q_ASSERT(m_currentEntry);
const bool hasTotp = m_currentEntry->hasTotp();
m_ui->entryTotpButton->setVisible(hasTotp);
m_ui->entryTotpLabel->hide();
m_ui->entryTotpProgress->hide();
m_ui->entryTotpButton->setChecked(false);

if (hasTotp) {
m_totpTimer.start(1000);
m_ui->entryTotpProgress->setMaximum(m_currentEntry->totpSettings()->step);
updateTotpLabel();
} else {
m_ui->entryTotpLabel->hide();
m_ui->entryTotpProgress->hide();
m_ui->entryTotpButton->setChecked(false);
m_ui->entryTotpLabel->clear();
m_totpTimer.stop();
}
Expand Down

0 comments on commit ab8f6d9

Please sign in to comment.