From f32dc967573f7427c418e42d0aacfc9f6173da04 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Mon, 5 Sep 2022 12:56:10 -0400 Subject: [PATCH] Show entry count in status bar Closes #3963 --- src/gui/DatabaseWidget.cpp | 9 ++------- src/gui/MainWindow.cpp | 20 ++++++++++++++++++++ src/gui/MainWindow.h | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 4cba23ce3..08d8d4dec 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -200,7 +200,6 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) connect(m_previewView, SIGNAL(entryUrlActivated(Entry*)), SLOT(openUrlForEntry(Entry*))); connect(m_entryView, SIGNAL(viewStateChanged()), SIGNAL(entryViewStateChanged())); connect(m_groupView, SIGNAL(groupSelectionChanged()), SLOT(onGroupChanged())); - connect(m_groupView, SIGNAL(groupSelectionChanged()), SIGNAL(groupChanged())); connect(m_groupView, &GroupView::groupFocused, this, [this] { m_previewView->setGroup(currentGroup()); }); connect(m_entryView, SIGNAL(entryActivated(Entry*,EntryModel::ModelColumn)), SLOT(entryActivationSignalReceived(Entry*,EntryModel::ModelColumn))); @@ -1041,12 +1040,6 @@ void DatabaseWidget::switchToMainView(bool previousDialogAccepted) // Workaround: ensure entries are focused so search doesn't reset m_entryView->setFocus(); } - - if (sender() == m_entryView || sender() == m_editEntryWidget) { - onEntryChanged(m_entryView->currentEntry()); - } else if (sender() == m_groupView || sender() == m_editGroupWidget) { - onGroupChanged(); - } } void DatabaseWidget::switchToHistoryView(Entry* entry) @@ -1508,6 +1501,8 @@ void DatabaseWidget::onGroupChanged() m_shareLabel->setVisible(false); } #endif + + emit groupChanged(); } void DatabaseWidget::onDatabaseModified() diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 1b6ccd2d7..7df74fdf9 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -43,6 +43,7 @@ #include "gui/Icons.h" #include "gui/MessageBox.h" #include "gui/SearchWidget.h" +#include "gui/entry/EntryView.h" #include "gui/osutils/OSUtils.h" #ifdef WITH_XC_UPDATECHECK @@ -431,6 +432,11 @@ MainWindow::MainWindow() m_actionMultiplexer.connect(SIGNAL(entrySelectionChanged()), this, SLOT(setMenuActionState())); m_actionMultiplexer.connect(SIGNAL(groupContextMenuRequested(QPoint)), this, SLOT(showGroupContextMenu(QPoint))); m_actionMultiplexer.connect(SIGNAL(entryContextMenuRequested(QPoint)), this, SLOT(showEntryContextMenu(QPoint))); + m_actionMultiplexer.connect(SIGNAL(groupChanged()), this, SLOT(updateEntryCountLabel())); + m_actionMultiplexer.connect(SIGNAL(databaseUnlocked()), this, SLOT(updateEntryCountLabel())); + m_actionMultiplexer.connect(SIGNAL(databaseModified()), this, SLOT(updateEntryCountLabel())); + m_actionMultiplexer.connect(SIGNAL(searchModeActivated()), this, SLOT(updateEntryCountLabel())); + m_actionMultiplexer.connect(SIGNAL(listModeActivated()), this, SLOT(updateEntryCountLabel())); // Notify search when the active database changes or gets locked connect(m_ui->tabWidget, @@ -653,6 +659,7 @@ MainWindow::MainWindow() connect(qApp, SIGNAL(openFile(QString)), this, SLOT(openDatabase(QString))); connect(qApp, SIGNAL(quitSignalReceived()), this, SLOT(appExit()), Qt::DirectConnection); + // Setup the status bar statusBar()->setFixedHeight(24); m_progressBarLabel = new QLabel(statusBar()); m_progressBarLabel->setVisible(false); @@ -665,6 +672,8 @@ MainWindow::MainWindow() m_progressBar->setMaximum(100); statusBar()->addPermanentWidget(m_progressBar); connect(clipboard(), SIGNAL(updateCountdown(int, QString)), this, SLOT(updateProgressBar(int, QString))); + m_statusBarLabel = new QLabel(statusBar()); + statusBar()->addPermanentWidget(m_statusBarLabel); restoreConfigState(); } @@ -1546,6 +1555,17 @@ void MainWindow::updateProgressBar(int percentage, QString message) } } +void MainWindow::updateEntryCountLabel() +{ + auto dbWidget = m_ui->tabWidget->currentDatabaseWidget(); + if (dbWidget && dbWidget->currentMode() == DatabaseWidget::Mode::ViewMode) { + int numEntries = dbWidget->entryView()->model()->rowCount(); + m_statusBarLabel->setText(tr("%1 Entry(s)", "", numEntries).arg(numEntries)); + } else { + m_statusBarLabel->setText(""); + } +} + void MainWindow::obtainContextFocusLock() { m_contextMenuFocusLock = true; diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index f71af927a..ed9c506a3 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -147,6 +147,7 @@ private slots: void agentEnabled(bool enabled); void updateTrayIcon(); void updateProgressBar(int percentage, QString message); + void updateEntryCountLabel(); void focusSearchWidget(); private: @@ -182,6 +183,7 @@ private: QPointer m_searchWidget; QPointer m_progressBar; QPointer m_progressBarLabel; + QPointer m_statusBarLabel; Q_DISABLE_COPY(MainWindow)