diff --git a/src/lib/preferences/autofillmanager.cpp b/src/lib/preferences/autofillmanager.cpp index 5cde04382..04afc9ff7 100644 --- a/src/lib/preferences/autofillmanager.cpp +++ b/src/lib/preferences/autofillmanager.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2016 David Rosca * * 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 @@ -31,6 +31,7 @@ #include #include #include +#include AutoFillManager::AutoFillManager(QWidget* parent) : QWidget(parent) @@ -59,6 +60,9 @@ AutoFillManager::AutoFillManager(QWidget* parent) connect(ui->removeExcept, SIGNAL(clicked()), this, SLOT(removeExcept())); 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); menu->addAction(tr("Import Passwords from File..."), this, SLOT(importPasswords())); menu->addAction(tr("Export Passwords to File..."), this, SLOT(exportPasswords())); @@ -190,6 +194,26 @@ void AutoFillManager::showPasswords() 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(); + 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(); + QApplication::clipboard()->setText(entry.username); +} + void AutoFillManager::removePass() { QTreeWidgetItem* curItem = ui->treePass->currentItem(); @@ -341,6 +365,17 @@ void AutoFillManager::currentPasswordBackendChanged() 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() { delete ui; diff --git a/src/lib/preferences/autofillmanager.h b/src/lib/preferences/autofillmanager.h index b26c0e564..4a7289aa6 100644 --- a/src/lib/preferences/autofillmanager.h +++ b/src/lib/preferences/autofillmanager.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2016 David Rosca * * 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 @@ -49,6 +49,9 @@ private slots: void editPass(); void showPasswords(); + void copyPassword(); + void copyUsername(); + void removeExcept(); void removeAllExcept(); @@ -59,6 +62,7 @@ private slots: void slotExportPasswords(); void currentPasswordBackendChanged(); + void passwordContextMenu(const QPoint &pos); private: Ui::AutoFillManager* ui;