diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index f213a5da6..5425c38f2 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -17,8 +17,8 @@ #include "EntryAttributes.h" -const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << "URL" - << "UserName" << "Password" << "Notes"); +const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << "UserName" + << "Password" << "URL" << "Notes"); EntryAttributes::EntryAttributes(QObject* parent) : QObject(parent) @@ -31,6 +31,17 @@ QList EntryAttributes::keys() const return m_attributes.keys(); } +QList EntryAttributes::customKeys() +{ + QList customKeys; + Q_FOREACH (const QString& key, keys()) { + if (!isDefaultAttribute(key)) { + customKeys.append(key); + } + } + return customKeys; +} + QString EntryAttributes::value(const QString& key) const { return m_attributes.value(key); diff --git a/src/core/EntryAttributes.h b/src/core/EntryAttributes.h index 49282d553..8d17eb81b 100644 --- a/src/core/EntryAttributes.h +++ b/src/core/EntryAttributes.h @@ -32,6 +32,7 @@ class EntryAttributes : public QObject public: explicit EntryAttributes(QObject* parent = Q_NULLPTR); QList keys() const; + QList customKeys(); QString value(const QString& key) const; bool isProtected(const QString& key) const; void set(const QString& key, const QString& value, bool protect = false); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index a59ce6dcc..aedad473c 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -274,6 +274,17 @@ void DatabaseWidget::copyPassword() clipboard()->setText(currentEntry->password()); } +void DatabaseWidget::copyAttribute(QAction* action) +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return; + } + + clipboard()->setText(currentEntry->attributes()->value(action->text())); +} + void DatabaseWidget::performAutoType() { Entry* currentEntry = m_entryView->currentEntry(); diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index f680f67ce..a39b085da 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -86,6 +86,7 @@ public Q_SLOTS: void deleteEntry(); void copyUsername(); void copyPassword(); + void copyAttribute(QAction* action); void performAutoType(); void openUrl(); void createGroup(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 90516f68f..9c3399921 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -24,6 +24,7 @@ #include "autotype/AutoType.h" #include "core/Config.h" #include "core/Database.h" +#include "core/Entry.h" #include "core/FilePath.h" #include "core/Metadata.h" #include "gui/AboutDialog.h" @@ -52,6 +53,12 @@ MainWindow::MainWindow() connect(m_lastDatabasesActions, SIGNAL(triggered(QAction*)), this, SLOT(openRecentDatabase(QAction*))); connect(m_ui->menuRecentDatabases, SIGNAL(aboutToShow()), this, SLOT(updateLastDatabasesMenu())); + m_copyAdditionalAttributeActions = new QActionGroup(m_ui->menuEntryCopyAttribute); + m_actionMultiplexer.connect(m_copyAdditionalAttributeActions, SIGNAL(triggered(QAction*)), + SLOT(copyAttribute(QAction*))); + connect(m_ui->menuEntryCopyAttribute, SIGNAL(aboutToShow()), + this, SLOT(updateCopyAttributesMenu())); + Qt::Key globalAutoTypeKey = static_cast(config()->get("GlobalAutoTypeKey").toInt()); Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast( config()->get("GlobalAutoTypeModifiers").toInt()); @@ -195,6 +202,29 @@ void MainWindow::updateLastDatabasesMenu() m_ui->menuRecentDatabases->addAction(m_clearHistoryAction); } +void MainWindow::updateCopyAttributesMenu() +{ + m_ui->menuEntryCopyAttribute->clear(); + + DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget(); + Q_ASSERT(dbWidget); + Q_ASSERT(dbWidget->entryView()->isSingleEntrySelected()); + + Entry* entry = dbWidget->entryView()->currentEntry(); + + Q_FOREACH (const QString& key, EntryAttributes::DefaultAttributes) { + QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); + m_copyAdditionalAttributeActions->addAction(action); + } + + m_ui->menuEntryCopyAttribute->addSeparator(); + + Q_FOREACH (const QString& key, entry->attributes()->customKeys()) { + QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); + m_copyAdditionalAttributeActions->addAction(action); + } +} + void MainWindow::openRecentDatabase(QAction* action) { openDatabase(action->text()); @@ -235,6 +265,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryDelete->setEnabled(singleEntrySelected); m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected); m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected); + m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected); m_ui->actionEntryAutoType->setEnabled(singleEntrySelected); m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected); m_ui->actionGroupNew->setEnabled(groupSelected); @@ -258,6 +289,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) { action->setEnabled(false); } + m_ui->menuEntryCopyAttribute->setEnabled(false); m_ui->actionSearch->setEnabled(false); m_ui->actionSearch->setChecked(false); @@ -279,6 +311,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) { action->setEnabled(false); } + m_ui->menuEntryCopyAttribute->setEnabled(false); m_ui->actionSearch->setEnabled(false); m_ui->actionSearch->setChecked(false); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 958a56023..b6c309145 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -53,6 +53,7 @@ private Q_SLOTS: void openRecentDatabase(QAction* action); void clearLastDatabases(); void updateLastDatabasesMenu(); + void updateCopyAttributesMenu(); void showEntryContextMenu(const QPoint& globalPos); void showGroupContextMenu(const QPoint& globalPos); void saveToolbarState(bool value); @@ -66,6 +67,7 @@ private: SignalMultiplexer m_actionMultiplexer; QAction* m_clearHistoryAction; QActionGroup* m_lastDatabasesActions; + QActionGroup* m_copyAdditionalAttributeActions; Q_DISABLE_COPY(MainWindow) }; diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index fcc862ac7..74f04b530 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -70,7 +70,7 @@ 0 0 800 - 21 + 20 @@ -107,12 +107,21 @@ Entries + + + false + + + Copy attribute to clipboard + + +