From a599787a25aa71d0609b3ce9d9ab544456770933 Mon Sep 17 00:00:00 2001 From: Amir Pakdel Date: Tue, 12 May 2015 15:50:10 -0400 Subject: [PATCH 1/2] Bug #290 Show realted menu option to current entry only if the corresponding field is not empty. --- src/gui/DatabaseWidget.cpp | 50 ++++++++++++++++++++++++++++++++++++++ src/gui/DatabaseWidget.h | 5 ++++ src/gui/MainWindow.cpp | 12 ++++----- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 369c6903..c0fe81f3 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -906,3 +906,53 @@ bool DatabaseWidget::isGroupSelected() const { return m_groupView->currentGroup() != Q_NULLPTR; } + +bool DatabaseWidget::hasTitle() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return false; + } + return !currentEntry->title().isEmpty(); +} + +bool DatabaseWidget::hasUsername() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return false; + } + return !currentEntry->username().isEmpty(); +} + +bool DatabaseWidget::hasPassword() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return false; + } + return !currentEntry->password().isEmpty(); +} + +bool DatabaseWidget::hasUrl() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return false; + } + return !currentEntry->url().isEmpty(); +} + +bool DatabaseWidget::hasNotes() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return false; + } + return !currentEntry->notes().isEmpty(); +} diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index a38af731..7e565de0 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -80,6 +80,11 @@ public: QList entryHeaderViewSizes() const; void setEntryViewHeaderSizes(const QList& sizes); void clearAllWidgets(); + bool hasTitle(); + bool hasUsername(); + bool hasPassword(); + bool hasUrl(); + bool hasNotes(); Q_SIGNALS: void closeRequest(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 93084f64..5f3d1b36 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -286,14 +286,14 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch); m_ui->actionEntryEdit->setEnabled(singleEntrySelected); m_ui->actionEntryDelete->setEnabled(entriesSelected); - m_ui->actionEntryCopyTitle->setEnabled(singleEntrySelected); - m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected); - m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected); - m_ui->actionEntryCopyURL->setEnabled(singleEntrySelected); - m_ui->actionEntryCopyNotes->setEnabled(singleEntrySelected); + m_ui->actionEntryCopyTitle->setEnabled(singleEntrySelected && dbWidget->hasTitle()); + m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected && dbWidget->hasUsername()); + m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected && dbWidget->hasPassword()); + m_ui->actionEntryCopyURL->setEnabled(singleEntrySelected && dbWidget->hasUrl()); + m_ui->actionEntryCopyNotes->setEnabled(singleEntrySelected && dbWidget->hasUrl()); m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected); m_ui->actionEntryAutoType->setEnabled(singleEntrySelected); - m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected); + m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected && dbWidget->hasUrl()); m_ui->actionGroupNew->setEnabled(groupSelected); m_ui->actionGroupEdit->setEnabled(groupSelected); m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup()); From b45437d5026cae101dc9f4b88da36749f3362e0d Mon Sep 17 00:00:00 2001 From: Amir Pakdel Date: Tue, 12 May 2015 15:54:39 -0400 Subject: [PATCH 2/2] Refactored DatabaseWidget::currentEntryHas*() --- src/gui/DatabaseWidget.cpp | 10 +++++----- src/gui/DatabaseWidget.h | 10 +++++----- src/gui/MainWindow.cpp | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index c0fe81f3..6729a06e 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -907,7 +907,7 @@ bool DatabaseWidget::isGroupSelected() const return m_groupView->currentGroup() != Q_NULLPTR; } -bool DatabaseWidget::hasTitle() +bool DatabaseWidget::currentEntryHasTitle() { Entry* currentEntry = m_entryView->currentEntry(); if (!currentEntry) { @@ -917,7 +917,7 @@ bool DatabaseWidget::hasTitle() return !currentEntry->title().isEmpty(); } -bool DatabaseWidget::hasUsername() +bool DatabaseWidget::currentEntryHasUsername() { Entry* currentEntry = m_entryView->currentEntry(); if (!currentEntry) { @@ -927,7 +927,7 @@ bool DatabaseWidget::hasUsername() return !currentEntry->username().isEmpty(); } -bool DatabaseWidget::hasPassword() +bool DatabaseWidget::currentEntryHasPassword() { Entry* currentEntry = m_entryView->currentEntry(); if (!currentEntry) { @@ -937,7 +937,7 @@ bool DatabaseWidget::hasPassword() return !currentEntry->password().isEmpty(); } -bool DatabaseWidget::hasUrl() +bool DatabaseWidget::currentEntryHasUrl() { Entry* currentEntry = m_entryView->currentEntry(); if (!currentEntry) { @@ -947,7 +947,7 @@ bool DatabaseWidget::hasUrl() return !currentEntry->url().isEmpty(); } -bool DatabaseWidget::hasNotes() +bool DatabaseWidget::currentEntryHasNotes() { Entry* currentEntry = m_entryView->currentEntry(); if (!currentEntry) { diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 7e565de0..1ba3dd1f 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -80,11 +80,11 @@ public: QList entryHeaderViewSizes() const; void setEntryViewHeaderSizes(const QList& sizes); void clearAllWidgets(); - bool hasTitle(); - bool hasUsername(); - bool hasPassword(); - bool hasUrl(); - bool hasNotes(); + bool currentEntryHasTitle(); + bool currentEntryHasUsername(); + bool currentEntryHasPassword(); + bool currentEntryHasUrl(); + bool currentEntryHasNotes(); Q_SIGNALS: void closeRequest(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 5f3d1b36..ce814ae9 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -286,14 +286,14 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryClone->setEnabled(singleEntrySelected && !inSearch); m_ui->actionEntryEdit->setEnabled(singleEntrySelected); m_ui->actionEntryDelete->setEnabled(entriesSelected); - m_ui->actionEntryCopyTitle->setEnabled(singleEntrySelected && dbWidget->hasTitle()); - m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected && dbWidget->hasUsername()); - m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected && dbWidget->hasPassword()); - m_ui->actionEntryCopyURL->setEnabled(singleEntrySelected && dbWidget->hasUrl()); - m_ui->actionEntryCopyNotes->setEnabled(singleEntrySelected && dbWidget->hasUrl()); + m_ui->actionEntryCopyTitle->setEnabled(singleEntrySelected && dbWidget->currentEntryHasTitle()); + m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUsername()); + m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected && dbWidget->currentEntryHasPassword()); + m_ui->actionEntryCopyURL->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl()); + m_ui->actionEntryCopyNotes->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl()); m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected); m_ui->actionEntryAutoType->setEnabled(singleEntrySelected); - m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected && dbWidget->hasUrl()); + m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl()); m_ui->actionGroupNew->setEnabled(groupSelected); m_ui->actionGroupEdit->setEnabled(groupSelected); m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup());