From 651c00239a9d80dbbb646aef6e19cd7c1abd3324 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 12 Jul 2012 22:35:51 +0200 Subject: [PATCH] Add an auto-type entry action. --- src/gui/DatabaseTabWidget.cpp | 5 +++++ src/gui/DatabaseTabWidget.h | 1 + src/gui/DatabaseWidget.cpp | 24 ++++++++++++++++++++++++ src/gui/DatabaseWidget.h | 5 ++++- src/gui/MainWindow.cpp | 6 ++++++ src/gui/MainWindow.ui | 9 +++++++++ 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 7474d686e..93cb44a5a 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -391,6 +391,11 @@ void DatabaseTabWidget::copyPassword() currentDatabaseWidget()->copyPassword(); } +void DatabaseTabWidget::performAutoType() +{ + currentDatabaseWidget()->performAutoType(); +} + void DatabaseTabWidget::createGroup() { currentDatabaseWidget()->createGroup(); diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index 35c72f530..e88e53c60 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -73,6 +73,7 @@ public Q_SLOTS: void deleteEntry(); void copyUsername(); void copyPassword(); + void performAutoType(); void createGroup(); void editGroup(); void deleteGroup(); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index a79b99c07..33ecb2263 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -27,6 +27,7 @@ #include #include +#include "autotype/AutoType.h" #include "core/DataPath.h" #include "core/Metadata.h" #include "core/Tools.h" @@ -144,6 +145,15 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) m_actionEntryCopyPassword = m_menuEntry->addAction(tr("Copy password to clipboard"), this, SLOT(copyPassword()), Qt::CTRL + Qt::Key_C); m_actionEntryCopyPassword->setEnabled(false); + m_actionEntryAutoType = m_menuEntry->addAction(tr("Perform Auto-Type"), this, + SLOT(performAutoType())); + if (!QKeySequence::keyBindings(QKeySequence::Paste).isEmpty()) { + m_actionEntryAutoType->setShortcuts(QKeySequence::Paste); + } + else { + m_actionEntryAutoType->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V)); + } + m_actionEntryAutoType->setEnabled(false); m_actionGroupNew = m_menuGroup->addAction(tr("Add new group"), this, SLOT(createGroup())); m_actionGroupNew->setIcon(dataPath()->icon("actions", "group-new", false)); @@ -223,6 +233,8 @@ bool DatabaseWidget::actionEnabled(Action action) return m_actionEntryCopyUsername->isEnabled(); case EntryCopyPassword: return m_actionEntryCopyPassword->isEnabled(); + case EntryAutoType: + return m_actionEntryAutoType->isEnabled(); default: Q_ASSERT(false); return false; @@ -324,6 +336,17 @@ void DatabaseWidget::copyPassword() clipboard()->setText(currentEntry->password()); } +void DatabaseWidget::performAutoType() +{ + Entry* currentEntry = m_entryView->currentEntry(); + if (!currentEntry) { + Q_ASSERT(false); + return; + } + + autoType()->performAutoType(currentEntry, window()); +} + void DatabaseWidget::createGroup() { if (!m_groupView->currentGroup()) { @@ -669,6 +692,7 @@ void DatabaseWidget::updateEntryActions() m_actionEntryDelete->setEnabled(singleEntrySelected); m_actionEntryCopyUsername->setEnabled(singleEntrySelected); m_actionEntryCopyPassword->setEnabled(singleEntrySelected); + m_actionEntryAutoType->setEnabled(singleEntrySelected); } void DatabaseWidget::showGroupContextMenu(const QPoint& pos) diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index ffa76f1f5..9d682e056 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -62,7 +62,8 @@ public: EntryEditView, EntryDelete, EntryCopyUsername, - EntryCopyPassword + EntryCopyPassword, + EntryAutoType }; explicit DatabaseWidget(Database* db, QWidget* parent = Q_NULLPTR); @@ -88,6 +89,7 @@ public Q_SLOTS: void deleteEntry(); void copyUsername(); void copyPassword(); + void performAutoType(); void createGroup(); void deleteGroup(); void switchToEntryEdit(); @@ -152,6 +154,7 @@ private: QAction* m_actionEntryDelete; QAction* m_actionEntryCopyUsername; QAction* m_actionEntryCopyPassword; + QAction* m_actionEntryAutoType; }; #endif // KEEPASSX_DATABASEWIDGET_H diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7265d94b3..8e322dd69 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -45,6 +45,7 @@ MainWindow::MainWindow() setShortcut(m_ui->actionSearch, QKeySequence::Find, Qt::CTRL + Qt::Key_F); m_ui->actionEntryCopyUsername->setShortcut(Qt::CTRL + Qt::Key_B); m_ui->actionEntryCopyPassword->setShortcut(Qt::CTRL + Qt::Key_C); + setShortcut(m_ui->actionEntryAutoType, QKeySequence::Paste, Qt::CTRL + Qt::Key_V); m_ui->actionDatabaseNew->setIcon(dataPath()->icon("actions", "document-new")); m_ui->actionDatabaseOpen->setIcon(dataPath()->icon("actions", "document-open")); @@ -113,6 +114,8 @@ MainWindow::MainWindow() SLOT(copyUsername())); connect(m_ui->actionEntryCopyPassword, SIGNAL(triggered()), m_ui->tabWidget, SLOT(copyPassword())); + connect(m_ui->actionEntryAutoType, SIGNAL(triggered()), m_ui->tabWidget, + SLOT(performAutoType())); connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createGroup())); @@ -161,6 +164,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryDelete->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryDelete)); m_ui->actionEntryCopyUsername->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryCopyUsername)); m_ui->actionEntryCopyPassword->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryCopyPassword)); + m_ui->actionEntryAutoType->setEnabled(dbWidget->actionEnabled(DatabaseWidget::EntryAutoType)); m_ui->actionGroupNew->setEnabled(dbWidget->actionEnabled(DatabaseWidget::GroupNew)); m_ui->actionGroupEdit->setEnabled(dbWidget->actionEnabled(DatabaseWidget::GroupEdit)); m_ui->actionGroupDelete->setEnabled(dbWidget->actionEnabled(DatabaseWidget::GroupDelete)); @@ -180,6 +184,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryDelete->setEnabled(false); m_ui->actionEntryCopyUsername->setEnabled(false); m_ui->actionEntryCopyPassword->setEnabled(false); + m_ui->actionEntryAutoType->setEnabled(false); m_ui->actionGroupNew->setEnabled(false); m_ui->actionGroupEdit->setEnabled(false); m_ui->actionGroupDelete->setEnabled(false); @@ -202,6 +207,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryDelete->setEnabled(false); m_ui->actionEntryCopyUsername->setEnabled(false); m_ui->actionEntryCopyPassword->setEnabled(false); + m_ui->actionEntryAutoType->setEnabled(false); m_ui->actionGroupNew->setEnabled(false); m_ui->actionGroupEdit->setEnabled(false); m_ui->actionGroupDelete->setEnabled(false); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index e3ddba4da..337e400ab 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -106,6 +106,7 @@ + @@ -304,6 +305,14 @@ Settings + + + false + + + Perform Auto-Type + +