mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-05 21:14:20 -04:00
Add menu entry to copy an entry attribute to clipboard.
This commit is contained in:
parent
18337927f5
commit
ddd5e8a209
7 changed files with 71 additions and 3 deletions
|
@ -17,8 +17,8 @@
|
||||||
|
|
||||||
#include "EntryAttributes.h"
|
#include "EntryAttributes.h"
|
||||||
|
|
||||||
const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << "URL"
|
const QStringList EntryAttributes::DefaultAttributes(QStringList() << "Title" << "UserName"
|
||||||
<< "UserName" << "Password" << "Notes");
|
<< "Password" << "URL" << "Notes");
|
||||||
|
|
||||||
EntryAttributes::EntryAttributes(QObject* parent)
|
EntryAttributes::EntryAttributes(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -31,6 +31,17 @@ QList<QString> EntryAttributes::keys() const
|
||||||
return m_attributes.keys();
|
return m_attributes.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QString> EntryAttributes::customKeys()
|
||||||
|
{
|
||||||
|
QList<QString> customKeys;
|
||||||
|
Q_FOREACH (const QString& key, keys()) {
|
||||||
|
if (!isDefaultAttribute(key)) {
|
||||||
|
customKeys.append(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return customKeys;
|
||||||
|
}
|
||||||
|
|
||||||
QString EntryAttributes::value(const QString& key) const
|
QString EntryAttributes::value(const QString& key) const
|
||||||
{
|
{
|
||||||
return m_attributes.value(key);
|
return m_attributes.value(key);
|
||||||
|
|
|
@ -32,6 +32,7 @@ class EntryAttributes : public QObject
|
||||||
public:
|
public:
|
||||||
explicit EntryAttributes(QObject* parent = Q_NULLPTR);
|
explicit EntryAttributes(QObject* parent = Q_NULLPTR);
|
||||||
QList<QString> keys() const;
|
QList<QString> keys() const;
|
||||||
|
QList<QString> customKeys();
|
||||||
QString value(const QString& key) const;
|
QString value(const QString& key) const;
|
||||||
bool isProtected(const QString& key) const;
|
bool isProtected(const QString& key) const;
|
||||||
void set(const QString& key, const QString& value, bool protect = false);
|
void set(const QString& key, const QString& value, bool protect = false);
|
||||||
|
|
|
@ -274,6 +274,17 @@ void DatabaseWidget::copyPassword()
|
||||||
clipboard()->setText(currentEntry->password());
|
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()
|
void DatabaseWidget::performAutoType()
|
||||||
{
|
{
|
||||||
Entry* currentEntry = m_entryView->currentEntry();
|
Entry* currentEntry = m_entryView->currentEntry();
|
||||||
|
|
|
@ -86,6 +86,7 @@ public Q_SLOTS:
|
||||||
void deleteEntry();
|
void deleteEntry();
|
||||||
void copyUsername();
|
void copyUsername();
|
||||||
void copyPassword();
|
void copyPassword();
|
||||||
|
void copyAttribute(QAction* action);
|
||||||
void performAutoType();
|
void performAutoType();
|
||||||
void openUrl();
|
void openUrl();
|
||||||
void createGroup();
|
void createGroup();
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "autotype/AutoType.h"
|
#include "autotype/AutoType.h"
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
|
#include "core/Entry.h"
|
||||||
#include "core/FilePath.h"
|
#include "core/FilePath.h"
|
||||||
#include "core/Metadata.h"
|
#include "core/Metadata.h"
|
||||||
#include "gui/AboutDialog.h"
|
#include "gui/AboutDialog.h"
|
||||||
|
@ -52,6 +53,12 @@ MainWindow::MainWindow()
|
||||||
connect(m_lastDatabasesActions, SIGNAL(triggered(QAction*)), this, SLOT(openRecentDatabase(QAction*)));
|
connect(m_lastDatabasesActions, SIGNAL(triggered(QAction*)), this, SLOT(openRecentDatabase(QAction*)));
|
||||||
connect(m_ui->menuRecentDatabases, SIGNAL(aboutToShow()), this, SLOT(updateLastDatabasesMenu()));
|
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<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
|
Qt::Key globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
|
||||||
Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(
|
Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(
|
||||||
config()->get("GlobalAutoTypeModifiers").toInt());
|
config()->get("GlobalAutoTypeModifiers").toInt());
|
||||||
|
@ -195,6 +202,29 @@ void MainWindow::updateLastDatabasesMenu()
|
||||||
m_ui->menuRecentDatabases->addAction(m_clearHistoryAction);
|
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)
|
void MainWindow::openRecentDatabase(QAction* action)
|
||||||
{
|
{
|
||||||
openDatabase(action->text());
|
openDatabase(action->text());
|
||||||
|
@ -235,6 +265,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||||
m_ui->actionEntryDelete->setEnabled(singleEntrySelected);
|
m_ui->actionEntryDelete->setEnabled(singleEntrySelected);
|
||||||
m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected);
|
m_ui->actionEntryCopyUsername->setEnabled(singleEntrySelected);
|
||||||
m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected);
|
m_ui->actionEntryCopyPassword->setEnabled(singleEntrySelected);
|
||||||
|
m_ui->menuEntryCopyAttribute->setEnabled(singleEntrySelected);
|
||||||
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected);
|
m_ui->actionEntryAutoType->setEnabled(singleEntrySelected);
|
||||||
m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected);
|
m_ui->actionEntryOpenUrl->setEnabled(singleEntrySelected);
|
||||||
m_ui->actionGroupNew->setEnabled(groupSelected);
|
m_ui->actionGroupNew->setEnabled(groupSelected);
|
||||||
|
@ -258,6 +289,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||||
Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) {
|
Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) {
|
||||||
action->setEnabled(false);
|
action->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
m_ui->menuEntryCopyAttribute->setEnabled(false);
|
||||||
|
|
||||||
m_ui->actionSearch->setEnabled(false);
|
m_ui->actionSearch->setEnabled(false);
|
||||||
m_ui->actionSearch->setChecked(false);
|
m_ui->actionSearch->setChecked(false);
|
||||||
|
@ -279,6 +311,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
|
||||||
Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) {
|
Q_FOREACH (QAction* action, m_ui->menuGroups->actions()) {
|
||||||
action->setEnabled(false);
|
action->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
m_ui->menuEntryCopyAttribute->setEnabled(false);
|
||||||
|
|
||||||
m_ui->actionSearch->setEnabled(false);
|
m_ui->actionSearch->setEnabled(false);
|
||||||
m_ui->actionSearch->setChecked(false);
|
m_ui->actionSearch->setChecked(false);
|
||||||
|
|
|
@ -53,6 +53,7 @@ private Q_SLOTS:
|
||||||
void openRecentDatabase(QAction* action);
|
void openRecentDatabase(QAction* action);
|
||||||
void clearLastDatabases();
|
void clearLastDatabases();
|
||||||
void updateLastDatabasesMenu();
|
void updateLastDatabasesMenu();
|
||||||
|
void updateCopyAttributesMenu();
|
||||||
void showEntryContextMenu(const QPoint& globalPos);
|
void showEntryContextMenu(const QPoint& globalPos);
|
||||||
void showGroupContextMenu(const QPoint& globalPos);
|
void showGroupContextMenu(const QPoint& globalPos);
|
||||||
void saveToolbarState(bool value);
|
void saveToolbarState(bool value);
|
||||||
|
@ -66,6 +67,7 @@ private:
|
||||||
SignalMultiplexer m_actionMultiplexer;
|
SignalMultiplexer m_actionMultiplexer;
|
||||||
QAction* m_clearHistoryAction;
|
QAction* m_clearHistoryAction;
|
||||||
QActionGroup* m_lastDatabasesActions;
|
QActionGroup* m_lastDatabasesActions;
|
||||||
|
QActionGroup* m_copyAdditionalAttributeActions;
|
||||||
|
|
||||||
Q_DISABLE_COPY(MainWindow)
|
Q_DISABLE_COPY(MainWindow)
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>21</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -107,12 +107,21 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Entries</string>
|
<string>Entries</string>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuEntryCopyAttribute">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>Copy attribute to clipboard</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
<addaction name="actionEntryNew"/>
|
<addaction name="actionEntryNew"/>
|
||||||
<addaction name="actionEntryClone"/>
|
<addaction name="actionEntryClone"/>
|
||||||
<addaction name="actionEntryEdit"/>
|
<addaction name="actionEntryEdit"/>
|
||||||
<addaction name="actionEntryDelete"/>
|
<addaction name="actionEntryDelete"/>
|
||||||
<addaction name="actionEntryCopyUsername"/>
|
<addaction name="actionEntryCopyUsername"/>
|
||||||
<addaction name="actionEntryCopyPassword"/>
|
<addaction name="actionEntryCopyPassword"/>
|
||||||
|
<addaction name="menuEntryCopyAttribute"/>
|
||||||
<addaction name="actionEntryAutoType"/>
|
<addaction name="actionEntryAutoType"/>
|
||||||
<addaction name="actionEntryOpenUrl"/>
|
<addaction name="actionEntryOpenUrl"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue