diff options
-rw-r--r-- | src/core/Config.cpp | 1 | ||||
-rw-r--r-- | src/core/Config.h | 1 | ||||
-rw-r--r-- | src/gui/DatabaseWidget.cpp | 32 | ||||
-rw-r--r-- | src/gui/DatabaseWidget.h | 4 | ||||
-rw-r--r-- | src/gui/DatabaseWidgetStateSync.cpp | 12 | ||||
-rw-r--r-- | src/gui/DatabaseWidgetStateSync.h | 3 | ||||
-rw-r--r-- | src/gui/MainWindow.cpp | 29 | ||||
-rw-r--r-- | src/gui/MainWindow.h | 2 | ||||
-rw-r--r-- | src/gui/MainWindow.ui | 27 | ||||
-rw-r--r-- | src/gui/entry/EntryModel.cpp | 60 | ||||
-rw-r--r-- | src/gui/entry/EntryModel.h | 16 | ||||
-rw-r--r-- | src/gui/entry/EntryView.cpp | 63 | ||||
-rw-r--r-- | src/gui/entry/EntryView.h | 10 |
13 files changed, 64 insertions, 196 deletions
diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 58ddd9ae4..4c00dabbc 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -99,6 +99,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = { {Config::GUI_MinimizeOnStartup, {QS("GUI/MinimizeOnStartup"), Roaming, false}}, {Config::GUI_MinimizeOnClose, {QS("GUI/MinimizeOnClose"), Roaming, false}}, {Config::GUI_HideUsernames, {QS("GUI/HideUsernames"), Roaming, false}}, + {Config::GUI_HidePasswords, {QS("GUI/HidePasswords"), Roaming, true}}, {Config::GUI_AdvancedSettings, {QS("GUI/AdvancedSettings"), Roaming, false}}, {Config::GUI_MonospaceNotes, {QS("GUI/MonospaceNotes"), Roaming, false}}, {Config::GUI_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}}, diff --git a/src/core/Config.h b/src/core/Config.h index 2ed4c6ec1..423e1ee81 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -81,6 +81,7 @@ public: GUI_MinimizeOnStartup, GUI_MinimizeOnClose, GUI_HideUsernames, + GUI_HidePasswords, GUI_AdvancedSettings, GUI_MonospaceNotes, GUI_ApplicationTheme, diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 5cfe26e03..8d813aa61 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -330,38 +330,6 @@ void DatabaseWidget::setPreviewSplitterSizes(const QList<int>& sizes) } /** - * Get current state of entry view 'Hide Usernames' setting - */ -bool DatabaseWidget::isUsernamesHidden() const -{ - return m_entryView->isUsernamesHidden(); -} - -/** - * Set state of entry view 'Hide Usernames' setting - */ -void DatabaseWidget::setUsernamesHidden(bool hide) -{ - m_entryView->setUsernamesHidden(hide); -} - -/** - * Get current state of entry view 'Hide Passwords' setting - */ -bool DatabaseWidget::isPasswordsHidden() const -{ - return m_entryView->isPasswordsHidden(); -} - -/** - * Set state of entry view 'Hide Passwords' setting - */ -void DatabaseWidget::setPasswordsHidden(bool hide) -{ - m_entryView->setPasswordsHidden(hide); -} - -/** * Get current view state of entry view */ QByteArray DatabaseWidget::entryViewState() const diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 71fceadf5..efe602121 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -104,10 +104,6 @@ public: QStringList customEntryAttributes() const; bool isEditWidgetModified() const; - bool isUsernamesHidden() const; - void setUsernamesHidden(bool hide); - bool isPasswordsHidden() const; - void setPasswordsHidden(bool hide); void clearAllWidgets(); bool currentEntryHasTitle(); bool currentEntryHasUsername(); diff --git a/src/gui/DatabaseWidgetStateSync.cpp b/src/gui/DatabaseWidgetStateSync.cpp index e984e3d5f..0d8607374 100644 --- a/src/gui/DatabaseWidgetStateSync.cpp +++ b/src/gui/DatabaseWidgetStateSync.cpp @@ -29,8 +29,6 @@ DatabaseWidgetStateSync::DatabaseWidgetStateSync(QObject* parent) { m_mainSplitterSizes = variantToIntList(config()->get(Config::GUI_SplitterState)); m_previewSplitterSizes = variantToIntList(config()->get(Config::GUI_PreviewSplitterState)); - m_hideUsernames = config()->get(Config::GUI_HideUsernames).toBool(); - m_hidePasswords = true; m_listViewState = config()->get(Config::GUI_ListViewState).toByteArray(); m_searchViewState = config()->get(Config::GUI_SearchViewState).toByteArray(); @@ -48,7 +46,6 @@ void DatabaseWidgetStateSync::sync() { config()->set(Config::GUI_SplitterState, intListToVariant(m_mainSplitterSizes)); config()->set(Config::GUI_PreviewSplitterState, intListToVariant(m_previewSplitterSizes)); - config()->set(Config::GUI_HideUsernames, m_hideUsernames); config()->set(Config::GUI_ListViewState, m_listViewState); config()->set(Config::GUI_SearchViewState, m_searchViewState); config()->sync(); @@ -104,9 +101,6 @@ void DatabaseWidgetStateSync::setActive(DatabaseWidget* dbWidget) */ void DatabaseWidgetStateSync::restoreListView() { - m_activeDbWidget->setUsernamesHidden(m_hideUsernames); - m_activeDbWidget->setPasswordsHidden(m_hidePasswords); - if (!m_listViewState.isEmpty()) { m_activeDbWidget->setEntryViewState(m_listViewState); } @@ -129,9 +123,6 @@ void DatabaseWidgetStateSync::restoreListView() */ void DatabaseWidgetStateSync::restoreSearchView() { - m_activeDbWidget->setUsernamesHidden(m_hideUsernames); - m_activeDbWidget->setPasswordsHidden(m_hidePasswords); - if (!m_searchViewState.isEmpty()) { m_activeDbWidget->setEntryViewState(m_searchViewState); } else { @@ -169,9 +160,6 @@ void DatabaseWidgetStateSync::updateViewState() return; } - m_hideUsernames = m_activeDbWidget->isUsernamesHidden(); - m_hidePasswords = m_activeDbWidget->isPasswordsHidden(); - if (m_activeDbWidget->isSearchActive()) { m_searchViewState = m_activeDbWidget->entryViewState(); } else { diff --git a/src/gui/DatabaseWidgetStateSync.h b/src/gui/DatabaseWidgetStateSync.h index bf254e1f5..4e28b0a43 100644 --- a/src/gui/DatabaseWidgetStateSync.h +++ b/src/gui/DatabaseWidgetStateSync.h @@ -51,9 +51,6 @@ private: QList<int> m_mainSplitterSizes; QList<int> m_previewSplitterSizes; - bool m_hideUsernames; - bool m_hidePasswords; - QByteArray m_listViewState; QByteArray m_searchViewState; }; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 70a688236..49ab5abb2 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -332,10 +332,6 @@ MainWindow::MainWindow() shortcut = new QShortcut(dbTabModifier + Qt::Key_9, this); connect(shortcut, &QShortcut::activated, [this]() { selectDatabaseTab(m_ui->tabWidget->count() - 1); }); - // Toggle password and username visibility in entry view - new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_C, this, SLOT(togglePasswordsHidden())); - new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_B, this, SLOT(toggleUsernamesHidden())); - m_ui->actionDatabaseNew->setIcon(resources()->icon("document-new")); m_ui->actionDatabaseOpen->setIcon(resources()->icon("document-open")); m_ui->menuRecentDatabases->setIcon(resources()->icon("document-open-recent")); @@ -1126,22 +1122,6 @@ void MainWindow::databaseTabChanged(int tabIndex) m_actionMultiplexer.setCurrentObject(m_ui->tabWidget->currentDatabaseWidget()); } -void MainWindow::togglePasswordsHidden() -{ - auto dbWidget = m_ui->tabWidget->currentDatabaseWidget(); - if (dbWidget) { - dbWidget->setPasswordsHidden(!dbWidget->isPasswordsHidden()); - } -} - -void MainWindow::toggleUsernamesHidden() -{ - auto dbWidget = m_ui->tabWidget->currentDatabaseWidget(); - if (dbWidget) { - dbWidget->setUsernamesHidden(!dbWidget->isUsernamesHidden()); - } -} - void MainWindow::closeEvent(QCloseEvent* event) { if (m_appExiting) { @@ -1767,4 +1747,13 @@ void MainWindow::initViewMenu() show(); }); + m_ui->actionHideUsernames->setChecked(config()->get(Config::GUI_HideUsernames).toBool()); + connect(m_ui->actionHideUsernames, &QAction::toggled, this, [](bool checked) { + config()->set(Config::GUI_HideUsernames, checked); + }); + + m_ui->actionHidePasswords->setChecked(config()->get(Config::GUI_HidePasswords).toBool()); + connect(m_ui->actionHidePasswords, &QAction::toggled, this, [](bool checked) { + config()->set(Config::GUI_HidePasswords, checked); + }); } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 7da6b049b..bfbb53538 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -131,8 +131,6 @@ private slots: void selectNextDatabaseTab(); void selectPreviousDatabaseTab(); void selectDatabaseTab(int tabIndex, bool wrap = false); - void togglePasswordsHidden(); - void toggleUsernamesHidden(); void obtainContextFocusLock(); void releaseContextFocusLock(); void agentEnabled(bool enabled); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index c76be3516..e44d3d217 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -384,6 +384,8 @@ <addaction name="actionAlwaysOnTop"/> <addaction name="actionShowPreviewPanel"/> <addaction name="actionShowToolbar"/> + <addaction name="actionHideUsernames"/> + <addaction name="actionHidePasswords"/> </widget> <addaction name="menuFile"/> <addaction name="menuEntries"/> @@ -984,6 +986,31 @@ <string notr="true">Ctrl+Shift+A</string> </property> </action> + <action name="actionHideUsernames"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Hide Usernames</string> + </property> + <property name="shortcut"> + <string notr="true">Ctrl+Shift+B</string> + </property> + </action> + <action name="actionHidePasswords"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="text"> + <string>Hide Passwords</string> + </property> + <property name="shortcut"> + <string notr="true">Ctrl+Shift+C</string> + </property> + </action> </widget> <customwidgets> <customwidget> diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 0b766c854..9a9cbecab 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -37,11 +37,10 @@ EntryModel::EntryModel(QObject* parent) : QAbstractTableModel(parent) , m_group(nullptr) - , m_hideUsernames(false) - , m_hidePasswords(true) , HiddenContentDisplay(QString("\u25cf").repeated(6)) , DateFormat(Qt::DefaultLocaleShortDate) { + connect(config(), &Config::changed, this, &EntryModel::onConfigChanged); } Entry* EntryModel::entryFromIndex(const QModelIndex& index) const @@ -156,7 +155,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const } return result; case Username: - if (m_hideUsernames) { + if (config()->get(Config::GUI_HideUsernames).toBool()) { result = EntryModel::HiddenContentDisplay; } else { result = entry->resolveMultiplePlaceholders(entry->username()); @@ -164,9 +163,12 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const if (attr->isReference(EntryAttributes::UserNameKey)) { result.prepend(tr("Ref: ", "Reference abbreviation")); } + if (entry->username().isEmpty() && !config()->get(Config::Security_PasswordEmptyPlaceholder).toBool()) { + result = ""; + } return result; case Password: - if (m_hidePasswords) { + if (config()->get(Config::GUI_HidePasswords).toBool()) { result = EntryModel::HiddenContentDisplay; } else { result = entry->resolveMultiplePlaceholders(entry->password()); @@ -537,6 +539,20 @@ void EntryModel::entryDataChanged(Entry* entry) emit dataChanged(index(row, 0), index(row, columnCount() - 1)); } +void EntryModel::onConfigChanged(Config::ConfigKey key) +{ + switch (key) { + case Config::GUI_HideUsernames: + emit dataChanged(index(0, Username), index(rowCount() - 1, Username), {Qt::DisplayRole}); + break; + case Config::GUI_HidePasswords: + emit dataChanged(index(0, Password), index(rowCount() - 1, Password), {Qt::DisplayRole}); + break; + default: + break; + } +} + void EntryModel::severConnections() { if (m_group) { @@ -560,39 +576,3 @@ void EntryModel::makeConnections(const Group* group) connect(group, SIGNAL(entryMovedDown()), SLOT(entryMovedDown())); connect(group, SIGNAL(entryDataChanged(Entry*)), SLOT(entryDataChanged(Entry*))); } - -/** - * Get current state of 'Hide Usernames' setting - */ -bool EntryModel::isUsernamesHidden() const -{ - return m_hideUsernames; -} - -/** - * Set state of 'Hide Usernames' setting and signal change - */ -void EntryModel::setUsernamesHidden(bool hide) -{ - m_hideUsernames = hide; - emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); - emit usernamesHiddenChanged(); -} - -/** - * Get current state of 'Hide Passwords' setting - */ -bool EntryModel::isPasswordsHidden() const -{ - return m_hidePasswords; -} - -/** - * Set state of 'Hide Passwords' setting and signal change - */ -void EntryModel::setPasswordsHidden(bool hide) -{ - m_hidePasswords = hide; - emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); - emit passwordsHiddenChanged(); -} diff --git a/src/gui/entry/EntryModel.h b/src/gui/entry/EntryModel.h index 78da7194c..01c2483a9 100644 --- a/src/gui/entry/EntryModel.h +++ b/src/gui/entry/EntryModel.h @@ -21,6 +21,8 @@ #include <QAbstractTableModel> #include <QPixmap> +#include "core/Config.h" + class Entry; class Group; @@ -64,15 +66,6 @@ public: void setGroup(Group* group); void setEntries(const QList<Entry*>& entries); - bool isUsernamesHidden() const; - void setUsernamesHidden(bool hide); - bool isPasswordsHidden() const; - void setPasswordsHidden(bool hide); - -signals: - void usernamesHiddenChanged(); - void passwordsHiddenChanged(); - private slots: void entryAboutToAdd(Entry* entry); void entryAdded(Entry* entry); @@ -84,6 +77,8 @@ private slots: void entryMovedDown(); void entryDataChanged(Entry* entry); + void onConfigChanged(Config::ConfigKey key); + private: void severConnections(); void makeConnections(const Group* group); @@ -93,9 +88,6 @@ private: QList<Entry*> m_orgEntries; QList<const Group*> m_allGroups; - bool m_hideUsernames; - bool m_hidePasswords; - const QString HiddenContentDisplay; const Qt::DateFormat DateFormat; }; diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 53f03b989..54c1547c7 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -32,7 +32,7 @@ EntryView::EntryView(QWidget* parent) , m_sortModel(new SortFilterHideProxyModel(this)) , m_lastIndex(-1) , m_lastOrder(Qt::AscendingOrder) - , m_inSearchMode(false) + , m_headerMenu(new QMenu(this)) { m_sortModel->setSourceModel(m_model); m_sortModel->setDynamicSortFilter(true); @@ -55,22 +55,10 @@ EntryView::EntryView(QWidget* parent) // clang-format off connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(emitEntrySelectionChanged())); - connect(m_model, SIGNAL(usernamesHiddenChanged()), SIGNAL(viewStateChanged())); - connect(m_model, SIGNAL(passwordsHiddenChanged()), SIGNAL(viewStateChanged())); // clang-format on new QShortcut(Qt::CTRL + Qt::Key_F10, this, SLOT(contextMenuShortcutPressed()), nullptr, Qt::WidgetShortcut); - m_headerMenu = new QMenu(this); - m_headerMenu->setTitle(tr("Customize View")); - m_headerMenu->addSection(tr("Customize View")); - - m_hideUsernamesAction = m_headerMenu->addAction(tr("Hide Usernames"), this, SLOT(setUsernamesHidden(bool))); - m_hideUsernamesAction->setCheckable(true); - m_hidePasswordsAction = m_headerMenu->addAction(tr("Hide Passwords"), this, SLOT(setPasswordsHidden(bool))); - m_hidePasswordsAction->setCheckable(true); - m_headerMenu->addSeparator(); - resetViewToDefaults(); // Actions to toggle column visibility, each carrying the corresponding @@ -293,50 +281,6 @@ int EntryView::currentEntryIndex() } /** - * Get current state of 'Hide Usernames' setting (NOTE: just pass-through for - * m_model) - */ -bool EntryView::isUsernamesHidden() const -{ - return m_model->isUsernamesHidden(); -} - -/** - * Set state of 'Hide Usernames' setting (NOTE: just pass-through for m_model) - */ -void EntryView::setUsernamesHidden(bool hide) -{ - bool block = m_hideUsernamesAction->signalsBlocked(); - m_hideUsernamesAction->blockSignals(true); - m_hideUsernamesAction->setChecked(hide); - m_hideUsernamesAction->blockSignals(block); - - m_model->setUsernamesHidden(hide); -} - -/** - * Get current state of 'Hide Passwords' setting (NOTE: just pass-through for - * m_model) - */ -bool EntryView::isPasswordsHidden() const -{ - return m_model->isPasswordsHidden(); -} - -/** - * Set state of 'Hide Passwords' setting (NOTE: just pass-through for m_model) - */ -void EntryView::setPasswordsHidden(bool hide) -{ - bool block = m_hidePasswordsAction->signalsBlocked(); - m_hidePasswordsAction->blockSignals(true); - m_hidePasswordsAction->setChecked(hide); - m_hidePasswordsAction->blockSignals(block); - - m_model->setPasswordsHidden(hide); -} - -/** * Get current view state */ QByteArray EntryView::viewState() const @@ -363,8 +307,6 @@ bool EntryView::setViewState(const QByteArray& state) */ void EntryView::showHeaderMenu(const QPoint& position) { - m_hideUsernamesAction->setChecked(m_model->isUsernamesHidden()); - m_hidePasswordsAction->setChecked(m_model->isPasswordsHidden()); const QList<QAction*> actions = m_columnActions->actions(); for (auto& action : actions) { Q_ASSERT(static_cast<QMetaType::Type>(action->data().type()) == QMetaType::Int); @@ -469,9 +411,6 @@ void EntryView::resetFixedColumns() */ void EntryView::resetViewToDefaults() { - m_model->setUsernamesHidden(false); - m_model->setPasswordsHidden(true); - // Reduce number of columns that are shown by default if (m_inSearchMode) { header()->showSection(EntryModel::ParentGroup); diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h index 65cbf104a..ad2fd037c 100644 --- a/src/gui/entry/EntryView.h +++ b/src/gui/entry/EntryView.h @@ -44,8 +44,6 @@ public: bool isSorted(); int numberOfSelectedEntries(); void setFirstEntryActive(); - bool isUsernamesHidden() const; - bool isPasswordsHidden() const; QByteArray viewState() const; bool setViewState(const QByteArray& state); @@ -57,10 +55,6 @@ signals: void entrySelectionChanged(Entry* entry); void viewStateChanged(); -public slots: - void setUsernamesHidden(bool hide); - void setPasswordsHidden(bool hide); - protected: void keyPressEvent(QKeyEvent* event) override; void focusInEvent(QFocusEvent* event) override; @@ -86,12 +80,10 @@ private: SortFilterHideProxyModel* const m_sortModel; int m_lastIndex; Qt::SortOrder m_lastOrder; - bool m_inSearchMode; + bool m_inSearchMode = false; bool m_columnsNeedRelayout = true; QMenu* m_headerMenu; - QAction* m_hideUsernamesAction; - QAction* m_hidePasswordsAction; QActionGroup* m_columnActions; }; |