From 34f12ac39c0e700c52a173b4badcab1f6b3aad51 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sat, 30 Nov 2013 16:05:10 +0100 Subject: [PATCH 1/6] Remove duplicate menu entries to copy username and password. --- src/core/EntryAttributes.cpp | 6 ++++-- src/core/EntryAttributes.h | 2 ++ src/gui/MainWindow.cpp | 13 +++++++++++-- src/gui/MainWindow.ui | 8 ++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index 5425c38f..becf0eca 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -17,8 +17,10 @@ #include "EntryAttributes.h" -const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << "UserName" - << "Password" << "URL" << "Notes"); +const QString EntryAttributes::UserNameKey = "UserName"; +const QString EntryAttributes::PasswordKey = "Password"; +const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << UserNameKey + << PasswordKey << "URL" << "Notes"); EntryAttributes::EntryAttributes(QObject* parent) : QObject(parent) diff --git a/src/core/EntryAttributes.h b/src/core/EntryAttributes.h index 420c085f..a7bdcad4 100644 --- a/src/core/EntryAttributes.h +++ b/src/core/EntryAttributes.h @@ -46,6 +46,8 @@ public: bool operator==(const EntryAttributes& other) const; bool operator!=(const EntryAttributes& other) const; + static const QString UserNameKey; + static const QString PasswordKey; static const QStringList DefaultAttributes; static bool isDefaultAttribute(const QString& key); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 3f956a63..67c4647a 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -214,10 +214,19 @@ void MainWindow::updateCopyAttributesMenu() return; } - m_ui->menuEntryCopyAttribute->clear(); + Q_FOREACH (QAction* action, m_ui->menuEntryCopyAttribute->actions()) { + if (action != m_ui->actionEntryCopyPassword && action != m_ui->actionEntryCopyUsername) { + m_ui->menuEntryCopyAttribute->removeAction(action); + } + } + Entry* entry = dbWidget->entryView()->currentEntry(); - Q_FOREACH (const QString& key, EntryAttributes::DefaultAttributes) { + QStringList defaultAttributesWithoutPasswordAndUsername = EntryAttributes::DefaultAttributes; + defaultAttributesWithoutPasswordAndUsername.removeOne(EntryAttributes::PasswordKey); + defaultAttributesWithoutPasswordAndUsername.removeOne(EntryAttributes::UserNameKey); + + Q_FOREACH (const QString& key, defaultAttributesWithoutPasswordAndUsername) { QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); m_copyAdditionalAttributeActions->addAction(action); } diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 74f04b53..18c8346c 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -114,13 +114,13 @@ Copy attribute to clipboard + + - - @@ -306,7 +306,7 @@ false - Copy username to clipboard + Username @@ -314,7 +314,7 @@ false - Copy password to clipboard + Password From 3e4811791a5255d99313aca1e9b42d2fa4e22120 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sat, 30 Nov 2013 16:19:48 +0100 Subject: [PATCH 2/6] Delete actions after removal from menu. --- src/gui/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 67c4647a..a58ae5ee 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -217,6 +217,7 @@ void MainWindow::updateCopyAttributesMenu() Q_FOREACH (QAction* action, m_ui->menuEntryCopyAttribute->actions()) { if (action != m_ui->actionEntryCopyPassword && action != m_ui->actionEntryCopyUsername) { m_ui->menuEntryCopyAttribute->removeAction(action); + delete action; } } From 4a3da3abe7d877c79dbedf38c36eb47101cec638 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sun, 1 Dec 2013 09:43:41 +0100 Subject: [PATCH 3/6] Hard code copy action for default attributes. --- src/core/Entry.cpp | 20 ++++++++-------- src/core/EntryAttributes.cpp | 7 ++++-- src/core/EntryAttributes.h | 3 +++ src/gui/DatabaseWidget.cpp | 45 ++++++++++++++++++++++++++++++++++++ src/gui/DatabaseWidget.h | 3 +++ src/gui/MainWindow.cpp | 34 ++++++++++++++++----------- src/gui/MainWindow.ui | 27 ++++++++++++++++++++++ 7 files changed, 113 insertions(+), 26 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 41616cb8..8d2fac46 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -185,27 +185,27 @@ const AutoTypeAssociations* Entry::autoTypeAssociations() const QString Entry::title() const { - return m_attributes->value("Title"); + return m_attributes->value(EntryAttributes::TitleKey); } QString Entry::url() const { - return m_attributes->value("URL"); + return m_attributes->value(EntryAttributes::URLNameKey); } QString Entry::username() const { - return m_attributes->value("UserName"); + return m_attributes->value(EntryAttributes::UserNameKey); } QString Entry::password() const { - return m_attributes->value("Password"); + return m_attributes->value(EntryAttributes::PasswordKey); } QString Entry::notes() const { - return m_attributes->value("Notes"); + return m_attributes->value(EntryAttributes::NotesKey); } bool Entry::isExpired() const @@ -311,27 +311,27 @@ void Entry::setDefaultAutoTypeSequence(const QString& sequence) void Entry::setTitle(const QString& title) { - m_attributes->set("Title", title, m_attributes->isProtected("Title")); + m_attributes->set(EntryAttributes::TitleKey, title, m_attributes->isProtected(EntryAttributes::TitleKey)); } void Entry::setUrl(const QString& url) { - m_attributes->set("URL", url, m_attributes->isProtected("URL")); + m_attributes->set(EntryAttributes::URLNameKey, url, m_attributes->isProtected(EntryAttributes::URLNameKey)); } void Entry::setUsername(const QString& username) { - m_attributes->set("UserName", username, m_attributes->isProtected("UserName")); + m_attributes->set(EntryAttributes::UserNameKey, username, m_attributes->isProtected(EntryAttributes::UserNameKey)); } void Entry::setPassword(const QString& password) { - m_attributes->set("Password", password, m_attributes->isProtected("Password")); + m_attributes->set(EntryAttributes::PasswordKey, password, m_attributes->isProtected(EntryAttributes::PasswordKey)); } void Entry::setNotes(const QString& notes) { - m_attributes->set("Notes", notes, m_attributes->isProtected("Notes")); + m_attributes->set(EntryAttributes::NotesKey, notes, m_attributes->isProtected(EntryAttributes::NotesKey)); } void Entry::setExpires(const bool& value) diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index becf0eca..115855e2 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -17,10 +17,13 @@ #include "EntryAttributes.h" +const QString EntryAttributes::TitleKey = "Title"; const QString EntryAttributes::UserNameKey = "UserName"; const QString EntryAttributes::PasswordKey = "Password"; -const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << UserNameKey - << PasswordKey << "URL" << "Notes"); +const QString EntryAttributes::URLNameKey = "URL"; +const QString EntryAttributes::NotesKey = "Notes"; +const QStringList EntryAttributes::DefaultAttributes(QStringList() << TitleKey << UserNameKey + << PasswordKey << URLNameKey << NotesKey); EntryAttributes::EntryAttributes(QObject* parent) : QObject(parent) diff --git a/src/core/EntryAttributes.h b/src/core/EntryAttributes.h index a7bdcad4..4518cca8 100644 --- a/src/core/EntryAttributes.h +++ b/src/core/EntryAttributes.h @@ -46,8 +46,11 @@ public: bool operator==(const EntryAttributes& other) const; bool operator!=(const EntryAttributes& other) const; + static const QString TitleKey; static const QString UserNameKey; static const QString PasswordKey; + static const QString URLNameKey; + static const QString NotesKey; static const QStringList DefaultAttributes; static bool isDefaultAttribute(const QString& key); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 8c635a70..ead7f633 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -288,6 +288,21 @@ void DatabaseWidget::deleteEntries() } } +void DatabaseWidget::copyTitle() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return; + } + + clipboard()->setText(currentEntry->title()); + + if (config()->get("MinimizeOnCopy").toBool()) { + window()->showMinimized(); + } +} + void DatabaseWidget::copyUsername() { Entry* currentEntry = m_entryView->currentEntry(); @@ -318,6 +333,36 @@ void DatabaseWidget::copyPassword() } } +void DatabaseWidget::copyURL() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return; + } + + clipboard()->setText(currentEntry->url()); + + if (config()->get("MinimizeOnCopy").toBool()) { + window()->showMinimized(); + } +} + +void DatabaseWidget::copyNotes() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return; + } + + clipboard()->setText(currentEntry->notes()); + + if (config()->get("MinimizeOnCopy").toBool()) { + window()->showMinimized(); + } +} + void DatabaseWidget::copyAttribute(QAction* action) { Entry* currentEntry = m_entryView->currentEntry(); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index e5bacd5d..eb597c2e 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -86,8 +86,11 @@ public Q_SLOTS: void createEntry(); void cloneEntry(); void deleteEntries(); + void copyTitle(); void copyUsername(); void copyPassword(); + void copyURL(); + void copyNotes(); void copyAttribute(QAction* action); void performAutoType(); void openUrl(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index a58ae5ee..439bea9b 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -163,10 +163,17 @@ MainWindow::MainWindow() SLOT(switchToEntryEdit())); m_actionMultiplexer.connect(m_ui->actionEntryDelete, SIGNAL(triggered()), SLOT(deleteEntries())); + + m_actionMultiplexer.connect(m_ui->actionEntryCopyTitle, SIGNAL(triggered()), + SLOT(copyTitle())); m_actionMultiplexer.connect(m_ui->actionEntryCopyUsername, SIGNAL(triggered()), SLOT(copyUsername())); m_actionMultiplexer.connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()), SLOT(copyPassword())); + m_actionMultiplexer.connect(m_ui->actionEntryCopyURL, SIGNAL(triggered()), + SLOT(copyURL())); + m_actionMultiplexer.connect(m_ui->actionEntryCopyNotes, SIGNAL(triggered()), + SLOT(copyNotes())); m_actionMultiplexer.connect(m_ui->actionEntryAutoType, SIGNAL(triggered()), SLOT(performAutoType())); m_actionMultiplexer.connect(m_ui->actionEntryOpenUrl, SIGNAL(triggered()), @@ -214,24 +221,20 @@ void MainWindow::updateCopyAttributesMenu() return; } - Q_FOREACH (QAction* action, m_ui->menuEntryCopyAttribute->actions()) { - if (action != m_ui->actionEntryCopyPassword && action != m_ui->actionEntryCopyUsername) { - m_ui->menuEntryCopyAttribute->removeAction(action); - delete action; - } + QList actionsToRemove = m_ui->menuEntryCopyAttribute->actions(); + actionsToRemove.removeOne(m_ui->actionEntryCopyTitle); + actionsToRemove.removeOne(m_ui->actionEntryCopyUsername); + actionsToRemove.removeOne(m_ui->actionEntryCopyPassword); + actionsToRemove.removeOne(m_ui->actionEntryCopyURL); + actionsToRemove.removeOne(m_ui->actionEntryCopyNotes); + + Q_FOREACH (QAction* action, actionsToRemove) { + m_ui->menuEntryCopyAttribute->removeAction(action); + delete action; } Entry* entry = dbWidget->entryView()->currentEntry(); - QStringList defaultAttributesWithoutPasswordAndUsername = EntryAttributes::DefaultAttributes; - defaultAttributesWithoutPasswordAndUsername.removeOne(EntryAttributes::PasswordKey); - defaultAttributesWithoutPasswordAndUsername.removeOne(EntryAttributes::UserNameKey); - - Q_FOREACH (const QString& key, defaultAttributesWithoutPasswordAndUsername) { - QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); - m_copyAdditionalAttributeActions->addAction(action); - } - m_ui->menuEntryCopyAttribute->addSeparator(); Q_FOREACH (const QString& key, entry->attributes()->customKeys()) { @@ -279,8 +282,11 @@ 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->menuEntryCopyAttribute->setEnabled(singleEntrySelected); m_ui->actionEntryAutoType->setEnabled(singleEntrySelected); m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 18c8346c..30c8c8d5 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -114,8 +114,11 @@ Copy attribute to clipboard + + + @@ -346,6 +349,30 @@ Lock databases + + + false + + + Title + + + + + false + + + URL + + + + + false + + + Notes + + From 23080992607dbeea411eba7d3c469194d9df80bf Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sun, 1 Dec 2013 09:59:43 +0100 Subject: [PATCH 4/6] Small refactoring in DatabaseWidget. --- src/gui/DatabaseWidget.cpp | 36 ++++++++++-------------------------- src/gui/DatabaseWidget.h | 2 ++ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index ead7f633..08000b91 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -296,11 +296,7 @@ void DatabaseWidget::copyTitle() return; } - clipboard()->setText(currentEntry->title()); - - if (config()->get("MinimizeOnCopy").toBool()) { - window()->showMinimized(); - } + setClipboardTextAndMinimize(currentEntry->title()); } void DatabaseWidget::copyUsername() @@ -311,11 +307,7 @@ void DatabaseWidget::copyUsername() return; } - clipboard()->setText(currentEntry->username()); - - if (config()->get("MinimizeOnCopy").toBool()) { - window()->showMinimized(); - } + setClipboardTextAndMinimize(currentEntry->username()); } void DatabaseWidget::copyPassword() @@ -326,11 +318,7 @@ void DatabaseWidget::copyPassword() return; } - clipboard()->setText(currentEntry->password()); - - if (config()->get("MinimizeOnCopy").toBool()) { - window()->showMinimized(); - } + setClipboardTextAndMinimize(currentEntry->password()); } void DatabaseWidget::copyURL() @@ -341,11 +329,7 @@ void DatabaseWidget::copyURL() return; } - clipboard()->setText(currentEntry->url()); - - if (config()->get("MinimizeOnCopy").toBool()) { - window()->showMinimized(); - } + setClipboardTextAndMinimize(currentEntry->url()); } void DatabaseWidget::copyNotes() @@ -356,11 +340,7 @@ void DatabaseWidget::copyNotes() return; } - clipboard()->setText(currentEntry->notes()); - - if (config()->get("MinimizeOnCopy").toBool()) { - window()->showMinimized(); - } + setClipboardTextAndMinimize(currentEntry->notes()); } void DatabaseWidget::copyAttribute(QAction* action) @@ -371,8 +351,12 @@ void DatabaseWidget::copyAttribute(QAction* action) return; } - clipboard()->setText(currentEntry->attributes()->value(action->text())); + setClipboardTextAndMinimize(currentEntry->attributes()->value(action->text())); +} +void DatabaseWidget::setClipboardTextAndMinimize(const QString& text) +{ + clipboard()->setText(text); if (config()->get("MinimizeOnCopy").toBool()) { window()->showMinimized(); } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index eb597c2e..240fe28f 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -128,6 +128,8 @@ private Q_SLOTS: void closeSearch(); private: + void setClipboardTextAndMinimize(const QString& text); + Database* m_db; const QScopedPointer m_searchUi; QWidget* const m_searchWidget; From a3b95c1c38044b0bc7b3253754dc7f55b252512e Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sun, 1 Dec 2013 10:36:50 +0100 Subject: [PATCH 5/6] Remove unnecessary removeAction call in MainWindow. --- src/gui/MainWindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 439bea9b..cebfcbf4 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -229,7 +229,6 @@ void MainWindow::updateCopyAttributesMenu() actionsToRemove.removeOne(m_ui->actionEntryCopyNotes); Q_FOREACH (QAction* action, actionsToRemove) { - m_ui->menuEntryCopyAttribute->removeAction(action); delete action; } From fc3cc120380f3be5eaa7b6e8744bae38f0edf969 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sun, 1 Dec 2013 15:41:26 +0100 Subject: [PATCH 6/6] Optimize deletion of copy to clipboard actions. --- src/gui/MainWindow.cpp | 14 +++----------- src/gui/MainWindow.ui | 1 + 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index cebfcbf4..2b8707aa 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -221,21 +221,13 @@ void MainWindow::updateCopyAttributesMenu() return; } - QList actionsToRemove = m_ui->menuEntryCopyAttribute->actions(); - actionsToRemove.removeOne(m_ui->actionEntryCopyTitle); - actionsToRemove.removeOne(m_ui->actionEntryCopyUsername); - actionsToRemove.removeOne(m_ui->actionEntryCopyPassword); - actionsToRemove.removeOne(m_ui->actionEntryCopyURL); - actionsToRemove.removeOne(m_ui->actionEntryCopyNotes); - - Q_FOREACH (QAction* action, actionsToRemove) { - delete action; + QList actions = m_ui->menuEntryCopyAttribute->actions(); + for (int i = EntryAttributes::DefaultAttributes.size() + 1; i < actions.size(); i++) { + delete actions[i]; } Entry* entry = dbWidget->entryView()->currentEntry(); - m_ui->menuEntryCopyAttribute->addSeparator(); - Q_FOREACH (const QString& key, entry->attributes()->customKeys()) { QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); m_copyAdditionalAttributeActions->addAction(action); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 30c8c8d5..90935b97 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -119,6 +119,7 @@ +