Falkon Develop
Cross-platform Qt-based web browser
autofillwidget.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "autofillwidget.h"
19#include "ui_autofillwidget.h"
20#include "autofill.h"
21#include "webview.h"
22#include "webpage.h"
23#include "scripts.h"
24#include "mainapplication.h"
25#include "passwordmanager.h"
26
27#include <QPushButton>
28
30 : LocationBarPopup(parent)
31 , ui(new Ui::AutoFillWidget)
32 , m_view(view)
33{
34 ui->setupUi(this);
35}
36
37void AutoFillWidget::setUsernames(const QStringList &usernames)
38{
39 int i = 0;
40 for (const QString &username : usernames) {
41 if (username.isEmpty()) {
42 continue;
43 }
44
45 auto* button = new QPushButton(this);
46 button->setIcon(QIcon(QSL(":icons/other/login.png")));
47 button->setStyleSheet(QSL("text-align:left;font-weight:bold;"));
48 button->setText(username);
49 button->setFlat(true);
50
51 ui->gridLayout->addWidget(button, i++, 0);
52 connect(button, &QPushButton::clicked, this, [=]() {
53 const auto entries = mApp->autoFill()->getFormData(m_view->url());
54 PasswordEntry entry;
55 // Find exact username match
56 for (const PasswordEntry &e : entries) {
57 if (e.username == username) {
58 entry = e;
59 break;
60 }
61 }
62 // Find by index
63 // This is needed for DatabaseEncryptedPasswordBackend because it also encrypts usernames.
64 if (!entry.isValid()) {
65 entry = entries.value(i - 1);
66 }
67 if (entry.isValid()) {
68 mApp->autoFill()->updateLastUsed(entry);
69 m_view->page()->runJavaScript(Scripts::completeFormData(entry.data), WebPage::SafeJsWorld);
70 }
71 close();
72 });
73 }
74}
75
77{
78 delete ui;
79}
AutoFillWidget(WebView *view, QWidget *parent=nullptr)
void setUsernames(const QStringList &usernames)
#define mApp
i
Definition: i18n.py:23
#define QSL(x)
Definition: qzcommon.h:40