File indexing completed on 2024-05-19 04:58:38

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "autofillnotification.h"
0019 #include "ui_autofillnotification.h"
0020 #include "mainapplication.h"
0021 #include "iconprovider.h"
0022 
0023 AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &formData, const PasswordEntry &updateData)
0024     : AnimatedWidget(AnimatedWidget::Down, 300, nullptr)
0025     , ui(new Ui::AutoFillNotification)
0026     , m_url(url)
0027     , m_formData(formData)
0028     , m_updateData(updateData)
0029 {
0030     setAutoFillBackground(true);
0031     setAttribute(Qt::WA_DeleteOnClose);
0032     ui->setupUi(widget());
0033     ui->closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
0034 
0035     QString hostPart;
0036     QString userPart;
0037 
0038     if (!url.host().isEmpty()) {
0039         hostPart = tr("on %1").arg(url.host());
0040     }
0041 
0042     if (!m_formData.username.isEmpty()) {
0043         userPart = tr("for <b>%1</b>").arg(m_formData.username);
0044     }
0045 
0046     if (m_updateData.isValid()) {
0047         ui->label->setText(tr("Do you want Falkon to update saved password %1?").arg(userPart));
0048 
0049         ui->remember->setVisible(false);
0050         ui->never->setVisible(false);
0051     }
0052     else {
0053         ui->label->setText(tr("Do you want Falkon to remember the password %1 %2?").arg(userPart, hostPart));
0054 
0055         ui->update->setVisible(false);
0056     }
0057 
0058     connect(ui->update, SIGNAL(clicked()), this, SLOT(update()));
0059     connect(ui->remember, &QAbstractButton::clicked, this, &AutoFillNotification::remember);
0060     connect(ui->never, &QAbstractButton::clicked, this, &AutoFillNotification::never);
0061     connect(ui->notnow, SIGNAL(clicked()), this, SLOT(hide()));
0062     connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide()));
0063 
0064     startAnimation();
0065 }
0066 
0067 void AutoFillNotification::update()
0068 {
0069     mApp->autoFill()->updateEntry(m_updateData);
0070     hide();
0071 }
0072 
0073 void AutoFillNotification::never()
0074 {
0075     mApp->autoFill()->blockStoringforUrl(m_url);
0076     hide();
0077 }
0078 
0079 void AutoFillNotification::remember()
0080 {
0081     mApp->autoFill()->addEntry(m_url, m_formData);
0082     hide();
0083 }
0084 
0085 AutoFillNotification::~AutoFillNotification()
0086 {
0087     delete ui;
0088 }