mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-23 13:11:12 -05:00
Fix autotype menu entries on Windows
This commit is contained in:
parent
e16c007d43
commit
bc0a5a9440
@ -35,6 +35,14 @@
|
|||||||
#include "gui/Clipboard.h"
|
#include "gui/Clipboard.h"
|
||||||
#include "gui/Icons.h"
|
#include "gui/Icons.h"
|
||||||
|
|
||||||
|
const auto MENU_FIELD_PROP_NAME = "menu_field";
|
||||||
|
enum MENU_FIELD
|
||||||
|
{
|
||||||
|
USERNAME = 1,
|
||||||
|
PASSWORD,
|
||||||
|
TOTP,
|
||||||
|
};
|
||||||
|
|
||||||
AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
|
AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::AutoTypeSelectDialog())
|
, m_ui(new Ui::AutoTypeSelectDialog())
|
||||||
@ -260,14 +268,22 @@ void AutoTypeSelectDialog::updateActionMenu(const AutoTypeMatch& match)
|
|||||||
bool hasPassword = !match.first->password().isEmpty();
|
bool hasPassword = !match.first->password().isEmpty();
|
||||||
bool hasTotp = match.first->hasTotp();
|
bool hasTotp = match.first->hasTotp();
|
||||||
|
|
||||||
auto actions = m_actionMenu->actions();
|
for (auto action : m_actionMenu->actions()) {
|
||||||
Q_ASSERT(actions.size() >= 6);
|
auto prop = action->property(MENU_FIELD_PROP_NAME);
|
||||||
actions[0]->setEnabled(hasUsername);
|
if (prop.isValid()) {
|
||||||
actions[1]->setEnabled(hasPassword);
|
switch (prop.toInt()) {
|
||||||
actions[2]->setEnabled(hasTotp);
|
case MENU_FIELD::USERNAME:
|
||||||
actions[3]->setEnabled(hasUsername);
|
action->setEnabled(hasUsername);
|
||||||
actions[4]->setEnabled(hasPassword);
|
break;
|
||||||
actions[5]->setEnabled(hasTotp);
|
case MENU_FIELD::PASSWORD:
|
||||||
|
action->setEnabled(hasPassword);
|
||||||
|
break;
|
||||||
|
case MENU_FIELD::TOTP:
|
||||||
|
action->setEnabled(hasTotp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTypeSelectDialog::buildActionMenu()
|
void AutoTypeSelectDialog::buildActionMenu()
|
||||||
@ -282,15 +298,12 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
m_actionMenu->addAction(typeUsernameAction);
|
m_actionMenu->addAction(typeUsernameAction);
|
||||||
m_actionMenu->addAction(typePasswordAction);
|
m_actionMenu->addAction(typePasswordAction);
|
||||||
m_actionMenu->addAction(typeTotpAction);
|
m_actionMenu->addAction(typeTotpAction);
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
auto typeVirtualAction = new QAction(icons()->icon("auto-type"), tr("Use Virtual Keyboard"));
|
|
||||||
m_actionMenu->addAction(typeVirtualAction);
|
|
||||||
#endif
|
|
||||||
m_actionMenu->addAction(copyUsernameAction);
|
m_actionMenu->addAction(copyUsernameAction);
|
||||||
m_actionMenu->addAction(copyPasswordAction);
|
m_actionMenu->addAction(copyPasswordAction);
|
||||||
m_actionMenu->addAction(copyTotpAction);
|
m_actionMenu->addAction(copyTotpAction);
|
||||||
|
|
||||||
typeUsernameAction->setShortcut(Qt::CTRL + Qt::Key_1);
|
typeUsernameAction->setShortcut(Qt::CTRL + Qt::Key_1);
|
||||||
|
typeUsernameAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::USERNAME);
|
||||||
connect(typeUsernameAction, &QAction::triggered, this, [&] {
|
connect(typeUsernameAction, &QAction::triggered, this, [&] {
|
||||||
auto match = m_ui->view->currentMatch();
|
auto match = m_ui->view->currentMatch();
|
||||||
match.second = "{USERNAME}";
|
match.second = "{USERNAME}";
|
||||||
@ -298,6 +311,7 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
});
|
});
|
||||||
|
|
||||||
typePasswordAction->setShortcut(Qt::CTRL + Qt::Key_2);
|
typePasswordAction->setShortcut(Qt::CTRL + Qt::Key_2);
|
||||||
|
typePasswordAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::PASSWORD);
|
||||||
connect(typePasswordAction, &QAction::triggered, this, [&] {
|
connect(typePasswordAction, &QAction::triggered, this, [&] {
|
||||||
auto match = m_ui->view->currentMatch();
|
auto match = m_ui->view->currentMatch();
|
||||||
match.second = "{PASSWORD}";
|
match.second = "{PASSWORD}";
|
||||||
@ -305,6 +319,7 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
});
|
});
|
||||||
|
|
||||||
typeTotpAction->setShortcut(Qt::CTRL + Qt::Key_3);
|
typeTotpAction->setShortcut(Qt::CTRL + Qt::Key_3);
|
||||||
|
typeTotpAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::TOTP);
|
||||||
connect(typeTotpAction, &QAction::triggered, this, [&] {
|
connect(typeTotpAction, &QAction::triggered, this, [&] {
|
||||||
auto match = m_ui->view->currentMatch();
|
auto match = m_ui->view->currentMatch();
|
||||||
match.second = "{TOTP}";
|
match.second = "{TOTP}";
|
||||||
@ -312,6 +327,8 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
});
|
});
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
auto typeVirtualAction = new QAction(icons()->icon("auto-type"), tr("Use Virtual Keyboard"));
|
||||||
|
m_actionMenu->insertAction(copyUsernameAction, typeVirtualAction);
|
||||||
typeVirtualAction->setShortcut(Qt::CTRL + Qt::Key_4);
|
typeVirtualAction->setShortcut(Qt::CTRL + Qt::Key_4);
|
||||||
connect(typeVirtualAction, &QAction::triggered, this, [&] {
|
connect(typeVirtualAction, &QAction::triggered, this, [&] {
|
||||||
m_virtualMode = true;
|
m_virtualMode = true;
|
||||||
@ -330,6 +347,7 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
copyUsernameAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::USERNAME);
|
||||||
connect(copyUsernameAction, &QAction::triggered, this, [&] {
|
connect(copyUsernameAction, &QAction::triggered, this, [&] {
|
||||||
auto entry = m_ui->view->currentMatch().first;
|
auto entry = m_ui->view->currentMatch().first;
|
||||||
if (entry) {
|
if (entry) {
|
||||||
@ -337,6 +355,8 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
copyPasswordAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::PASSWORD);
|
||||||
connect(copyPasswordAction, &QAction::triggered, this, [&] {
|
connect(copyPasswordAction, &QAction::triggered, this, [&] {
|
||||||
auto entry = m_ui->view->currentMatch().first;
|
auto entry = m_ui->view->currentMatch().first;
|
||||||
if (entry) {
|
if (entry) {
|
||||||
@ -344,6 +364,8 @@ void AutoTypeSelectDialog::buildActionMenu()
|
|||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
copyTotpAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::TOTP);
|
||||||
connect(copyTotpAction, &QAction::triggered, this, [&] {
|
connect(copyTotpAction, &QAction::triggered, this, [&] {
|
||||||
auto entry = m_ui->view->currentMatch().first;
|
auto entry = m_ui->view->currentMatch().first;
|
||||||
if (entry) {
|
if (entry) {
|
||||||
|
Loading…
Reference in New Issue
Block a user