1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

AutoFillManager: Add context menu with copy username/pass actions

Closes #1766
This commit is contained in:
David Rosca 2016-02-15 09:52:50 +01:00
parent bf1b762fb4
commit 966537728b
2 changed files with 41 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,6 +31,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QInputDialog> #include <QInputDialog>
#include <QFileDialog> #include <QFileDialog>
#include <QClipboard>
AutoFillManager::AutoFillManager(QWidget* parent) AutoFillManager::AutoFillManager(QWidget* parent)
: QWidget(parent) : QWidget(parent)
@ -59,6 +60,9 @@ AutoFillManager::AutoFillManager(QWidget* parent)
connect(ui->removeExcept, SIGNAL(clicked()), this, SLOT(removeExcept())); connect(ui->removeExcept, SIGNAL(clicked()), this, SLOT(removeExcept()));
connect(ui->removeAllExcept, SIGNAL(clicked()), this, SLOT(removeAllExcept())); connect(ui->removeAllExcept, SIGNAL(clicked()), this, SLOT(removeAllExcept()));
ui->treePass->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->treePass, &TreeWidget::customContextMenuRequested, this, &AutoFillManager::passwordContextMenu);
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
menu->addAction(tr("Import Passwords from File..."), this, SLOT(importPasswords())); menu->addAction(tr("Import Passwords from File..."), this, SLOT(importPasswords()));
menu->addAction(tr("Export Passwords to File..."), this, SLOT(exportPasswords())); menu->addAction(tr("Export Passwords to File..."), this, SLOT(exportPasswords()));
@ -190,6 +194,26 @@ void AutoFillManager::showPasswords()
ui->showPasswords->setText(tr("Hide Passwords")); ui->showPasswords->setText(tr("Hide Passwords"));
} }
void AutoFillManager::copyPassword()
{
QTreeWidgetItem* curItem = ui->treePass->currentItem();
if (!curItem)
return;
PasswordEntry entry = curItem->data(0, Qt::UserRole + 10).value<PasswordEntry>();
QApplication::clipboard()->setText(entry.password);
}
void AutoFillManager::copyUsername()
{
QTreeWidgetItem* curItem = ui->treePass->currentItem();
if (!curItem)
return;
PasswordEntry entry = curItem->data(0, Qt::UserRole + 10).value<PasswordEntry>();
QApplication::clipboard()->setText(entry.username);
}
void AutoFillManager::removePass() void AutoFillManager::removePass()
{ {
QTreeWidgetItem* curItem = ui->treePass->currentItem(); QTreeWidgetItem* curItem = ui->treePass->currentItem();
@ -341,6 +365,17 @@ void AutoFillManager::currentPasswordBackendChanged()
QTimer::singleShot(0, this, SLOT(loadPasswords())); QTimer::singleShot(0, this, SLOT(loadPasswords()));
} }
void AutoFillManager::passwordContextMenu(const QPoint &pos)
{
QMenu *menu = new QMenu;
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction(tr("Copy Username"), this, &AutoFillManager::copyUsername);
menu->addAction(tr("Copy Password"), this, &AutoFillManager::copyPassword);
menu->addSeparator();
menu->addAction(tr("Edit Password"), this, &AutoFillManager::editPass);
menu->popup(ui->treePass->viewport()->mapToGlobal(pos));
}
AutoFillManager::~AutoFillManager() AutoFillManager::~AutoFillManager()
{ {
delete ui; delete ui;

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -49,6 +49,9 @@ private slots:
void editPass(); void editPass();
void showPasswords(); void showPasswords();
void copyPassword();
void copyUsername();
void removeExcept(); void removeExcept();
void removeAllExcept(); void removeAllExcept();
@ -59,6 +62,7 @@ private slots:
void slotExportPasswords(); void slotExportPasswords();
void currentPasswordBackendChanged(); void currentPasswordBackendChanged();
void passwordContextMenu(const QPoint &pos);
private: private:
Ui::AutoFillManager* ui; Ui::AutoFillManager* ui;