diff --git a/src/lib/autofill/autofill.cpp b/src/lib/autofill/autofill.cpp index 5fb57c255..f50926423 100644 --- a/src/lib/autofill/autofill.cpp +++ b/src/lib/autofill/autofill.cpp @@ -191,6 +191,30 @@ void AutoFill::addEntry(const QUrl &url, const PageFormData &formData) mApp->dbWriter()->executeQuery(query); } +void AutoFill::updateEntry(const QUrl &url, const PageFormData &formData) +{ + QSqlQuery query; + query.prepare("SELECT data FROM autofill WHERE server=?"); + query.addBindValue(url.host()); + query.exec(); + + if (!query.next()) { + return; + } + + QString server = url.host(); + if (server.isEmpty()) { + server = url.toString(); + } + + query.prepare("UPDATE autofill SET data=?, username=?, password=? WHERE server=?"); + query.addBindValue(formData.postData); + query.addBindValue(formData.username); + query.addBindValue(formData.password); + query.addBindValue(server); + mApp->dbWriter()->executeQuery(query); +} + void AutoFill::completePage(WebPage* page) { if (!page) { @@ -238,23 +262,32 @@ void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingDa return; } - PageFormCompleter completer(webPage); - -// v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101)); -// QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt(); - -// if (type != QWebPage::NavigationTypeFormSubmitted) { -// return; -// } - const QUrl &siteUrl = webPage->url(); - const PageFormData &formData = completer.extractFormData(outgoingData); - if (!isStoringEnabled(siteUrl) || isStored(siteUrl) || !formData.found) { + if (!isStoringEnabled(siteUrl)) { return; } - AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, formData); + PageFormCompleter completer(webPage); + const PageFormData &formData = completer.extractFormData(outgoingData); + + if (!formData.found) { + return; + } + + bool updateData = false; + if (isStored(siteUrl)) { + const QString &user = getUsername(siteUrl); + const QString &pass = getPassword(siteUrl); + + if (user == formData.username && pass == formData.password) { + return; + } + + updateData = true; + } + + AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, formData, updateData); webView->addNotification(aWidget); } diff --git a/src/lib/autofill/autofill.h b/src/lib/autofill/autofill.h index b33448c5a..8dcfbb928 100644 --- a/src/lib/autofill/autofill.h +++ b/src/lib/autofill/autofill.h @@ -44,9 +44,12 @@ public: QString getUsername(const QUrl &url); QString getPassword(const QUrl &url); + void addEntry(const QUrl &url, const QString &name, const QString &pass); void addEntry(const QUrl &url, const PageFormData &formData); + void updateEntry(const QUrl &url, const PageFormData &formData); + void post(const QNetworkRequest &request, const QByteArray &outgoingData); void completePage(WebPage* frame); diff --git a/src/lib/autofill/autofillnotification.cpp b/src/lib/autofill/autofillnotification.cpp index 128d0a82f..daba646cb 100644 --- a/src/lib/autofill/autofillnotification.cpp +++ b/src/lib/autofill/autofillnotification.cpp @@ -22,9 +22,10 @@ #include "animatedwidget.h" #include "iconprovider.h" -AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &formData) +AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData &formData, bool updateData) : AnimatedWidget(AnimatedWidget::Down, 300, 0) , ui(new Ui::AutoFillWidget) + , m_updateData(updateData) , m_url(url) , m_formData(formData) { @@ -43,8 +44,19 @@ AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData & userPart = tr("for %1").arg(m_formData.username); } - ui->label->setText(tr("Do you want QupZilla to remember the password %1 %2?").arg(userPart, hostPart)); + if (updateData) { + ui->label->setText(tr("Do you want QupZilla to update saved password %1?").arg(hostPart)); + ui->remember->setVisible(false); + ui->never->setVisible(false); + } + else { + ui->label->setText(tr("Do you want QupZilla to remember the password %1 %2?").arg(userPart, hostPart)); + + ui->update->setVisible(false); + } + + connect(ui->update, SIGNAL(clicked()), this, SLOT(update())); connect(ui->remember, SIGNAL(clicked()), this, SLOT(remember())); connect(ui->never, SIGNAL(clicked()), this, SLOT(never())); connect(ui->notnow, SIGNAL(clicked()), this, SLOT(hide())); @@ -53,6 +65,12 @@ AutoFillNotification::AutoFillNotification(const QUrl &url, const PageFormData & startAnimation(); } +void AutoFillNotification::update() +{ + mApp->autoFill()->updateEntry(m_url, m_formData); + hide(); +} + void AutoFillNotification::never() { mApp->autoFill()->blockStoringfor(m_url); diff --git a/src/lib/autofill/autofillnotification.h b/src/lib/autofill/autofillnotification.h index 2a28f4515..1cec5bfc4 100644 --- a/src/lib/autofill/autofillnotification.h +++ b/src/lib/autofill/autofillnotification.h @@ -36,16 +36,19 @@ class QT_QUPZILLA_EXPORT AutoFillNotification : public AnimatedWidget Q_OBJECT public: - explicit AutoFillNotification(const QUrl &url, const PageFormData &formData); + explicit AutoFillNotification(const QUrl &url, + const PageFormData &formData, bool updateData); ~AutoFillNotification(); private slots: + void update(); void remember(); void never(); private: Ui::AutoFillWidget* ui; + bool m_updateData; QUrl m_url; PageFormData m_formData; }; diff --git a/src/lib/autofill/autofillnotification.ui b/src/lib/autofill/autofillnotification.ui index d61738912..97faed650 100644 --- a/src/lib/autofill/autofillnotification.ui +++ b/src/lib/autofill/autofillnotification.ui @@ -63,6 +63,13 @@ + + + + Update + + + diff --git a/translations/empty.ts b/translations/empty.ts index 3783b614b..f5a8221b7 100644 --- a/translations/empty.ts +++ b/translations/empty.ts @@ -345,6 +345,10 @@ Successfully exported + + Search + + AutoFillNotification @@ -360,6 +364,10 @@ Do you want QupZilla to remember the password %1 %2? + + Do you want QupZilla to update saved password %1? + + AutoFillWidget @@ -375,6 +383,10 @@ Not Now + + Update + + BookmarkIcon