Add menu entry to copy an entry attribute to clipboard.

This commit is contained in:
Florian Geyer 2012-10-24 00:15:23 +02:00
parent 18337927f5
commit ddd5e8a209
7 changed files with 71 additions and 3 deletions

View file

@ -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();

View file

@ -86,6 +86,7 @@ public Q_SLOTS:
void deleteEntry();
void copyUsername();
void copyPassword();
void copyAttribute(QAction* action);
void performAutoType();
void openUrl();
void createGroup();

View file

@ -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);

View file

@ -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)
};

View file

@ -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>