mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Add menu entry to copy an entry attribute to clipboard.
This commit is contained in:
parent
18337927f5
commit
ddd5e8a209
@ -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<QString> EntryAttributes::keys() const
|
||||
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
|
||||
{
|
||||
return m_attributes.value(key);
|
||||
|
@ -32,6 +32,7 @@ class EntryAttributes : public QObject
|
||||
public:
|
||||
explicit EntryAttributes(QObject* parent = Q_NULLPTR);
|
||||
QList<QString> keys() const;
|
||||
QList<QString> customKeys();
|
||||
QString value(const QString& key) const;
|
||||
bool isProtected(const QString& key) const;
|
||||
void set(const QString& key, const QString& value, bool protect = false);
|
||||
|
@ -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();
|
||||
|
@ -86,6 +86,7 @@ public Q_SLOTS:
|
||||
void deleteEntry();
|
||||
void copyUsername();
|
||||
void copyPassword();
|
||||
void copyAttribute(QAction* action);
|
||||
void performAutoType();
|
||||
void openUrl();
|
||||
void createGroup();
|
||||
|
@ -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<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
|
||||
Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(
|
||||
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);
|
||||
|
@ -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)
|
||||
};
|
||||
|
@ -70,7 +70,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>21</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@ -107,12 +107,21 @@
|
||||
<property name="title">
|
||||
<string>Entries</string>
|
||||
</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="actionEntryClone"/>
|
||||
<addaction name="actionEntryEdit"/>
|
||||
<addaction name="actionEntryDelete"/>
|
||||
<addaction name="actionEntryCopyUsername"/>
|
||||
<addaction name="actionEntryCopyPassword"/>
|
||||
<addaction name="menuEntryCopyAttribute"/>
|
||||
<addaction name="actionEntryAutoType"/>
|
||||
<addaction name="actionEntryOpenUrl"/>
|
||||
</widget>
|
||||
|
Loading…
Reference in New Issue
Block a user