2013-02-08 18:44:26 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
2013-02-08 18:44:26 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "autofillwidget.h"
|
|
|
|
#include "ui_autofillwidget.h"
|
|
|
|
#include "autofill.h"
|
|
|
|
#include "qztools.h"
|
|
|
|
#include "webview.h"
|
|
|
|
#include "webpage.h"
|
2015-08-31 18:56:52 +02:00
|
|
|
#include "scripts.h"
|
2013-02-08 18:44:26 +01:00
|
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
AutoFillWidget::AutoFillWidget(WebView* view, QWidget* parent)
|
|
|
|
: LocationBarPopup(parent)
|
|
|
|
, ui(new Ui::AutoFillWidget)
|
|
|
|
, m_view(view)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
2013-05-14 17:25:55 +02:00
|
|
|
void AutoFillWidget::setFormData(const QVector<PasswordEntry> &data)
|
2013-02-08 18:44:26 +01:00
|
|
|
{
|
|
|
|
m_data = data;
|
|
|
|
|
|
|
|
for (int i = 0; i < data.count(); ++i) {
|
2013-05-14 17:25:55 +02:00
|
|
|
const PasswordEntry d = data.at(i);
|
2013-02-08 18:44:26 +01:00
|
|
|
if (d.username.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton* button = new QPushButton(this);
|
2014-01-08 16:59:21 +01:00
|
|
|
button->setIcon(QIcon(":icons/other/login.png"));
|
|
|
|
button->setStyleSheet("text-align:left;font-weight:bold;");
|
|
|
|
button->setText(d.username);
|
2013-02-08 18:44:26 +01:00
|
|
|
button->setProperty("data-index", i);
|
2014-01-08 16:59:21 +01:00
|
|
|
button->setFlat(true);
|
2013-02-08 18:44:26 +01:00
|
|
|
|
2014-01-08 16:59:21 +01:00
|
|
|
ui->gridLayout->addWidget(button, i, 0);
|
2013-02-08 18:44:26 +01:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(loginToPage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutoFillWidget::loginToPage()
|
|
|
|
{
|
|
|
|
QPushButton* button = qobject_cast<QPushButton*>(sender());
|
|
|
|
if (!button || !m_view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
int index = button->property("data-index").toInt(&ok);
|
|
|
|
|
2014-03-07 22:54:50 +01:00
|
|
|
if (ok && QzTools::containsIndex(m_data, index)) {
|
2013-05-14 17:25:55 +02:00
|
|
|
const PasswordEntry entry = m_data.at(index);
|
2015-08-31 18:56:52 +02:00
|
|
|
m_view->page()->runJavaScript(Scripts::completeFormData(entry.data));
|
2013-02-08 18:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoFillWidget::~AutoFillWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|