diff --git a/bin/locale/cs_CZ.qm b/bin/locale/cs_CZ.qm index f06ef2317..0392bf58b 100644 Binary files a/bin/locale/cs_CZ.qm and b/bin/locale/cs_CZ.qm differ diff --git a/src/autofill/autofillmodel.cpp b/src/autofill/autofillmodel.cpp index f0ec3b225..6f8693b37 100644 --- a/src/autofill/autofillmodel.cpp +++ b/src/autofill/autofillmodel.cpp @@ -110,7 +110,7 @@ bool AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString } ///WEB Form -bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QString &pass) +bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QString &user, const QString &pass) { QSqlQuery query; query.exec("SELECT data FROM autofill WHERE server='" + url.host() + "'"); @@ -118,10 +118,11 @@ bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QStr return false; } - query.prepare("INSERT INTO autofill (server, data, password) VALUES (?,?,?)"); + query.prepare("INSERT INTO autofill (server, data, username, password) VALUES (?,?,?,?)"); query.bindValue(0, url.host()); query.bindValue(1, data); - query.bindValue(2, pass); + query.bindValue(2, user); + query.bindValue(3, pass); return query.exec(); } @@ -192,37 +193,95 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo return; } - QString passwordName = ""; - QString passwordValue = ""; + QString usernameName; + QString usernameValue; + QString passwordName; + QString passwordValue; QUrl siteUrl = webView->url(); - QWebElementCollection inputs; + if (!isStoringEnabled(siteUrl)) { + return; + } + + QWebElementCollection allForms; // All form elements on page + QWebElement foundForm; // Sent form element + QList frames; - frames.append(webPage->mainFrame()); + frames.append(webPage->mainFrame()); // Find all form elements while (!frames.isEmpty()) { QWebFrame* frame = frames.takeFirst(); - inputs.append(frame->findAllElements("input[type=\"password\"]")); + allForms.append(frame->findAllElements("form")); frames += frame->childFrames(); } - foreach(QWebElement element, inputs) { - passwordName = element.attribute("name"); - passwordValue = element.evaluateJavaScript("this.value").toString(); - if (!passwordValue.isEmpty()) { + foreach(QWebElement formElement, allForms) { + foreach(QWebElement inputElement, formElement.findAll("input[type=\"password\"]")) { + passwordName = inputElement.attribute("name"); + passwordValue = getValueFromData(outgoingData, inputElement); + + if (!passwordValue.isEmpty() && dataContains(outgoingData, passwordName)) { + foundForm = formElement; + break; + } + } + + if (!foundForm.isNull()) { break; } } - //Return if storing is not enabled, data for this page is already stored, no password element found in sent data - if (passwordName.isEmpty() || !isStoringEnabled(siteUrl) || isStored(siteUrl)) { + // Return if data for this page is already stored or no password element found in sent data + if (foundForm.isNull() || isStored(siteUrl)) { return; } - //Return if no password form has been sent - if (!outgoingData.contains((QUrl(passwordName).toEncoded() + "=")) || passwordValue.isEmpty()) { - return; + // We need to find username, we suppose that username is first not empty input[type=text] in form + // Tell me better solution. Maybe first try to find name="user", name="username" ? + + foreach(QWebElement element, foundForm.findAll("input[type=\"text\"]")) { + usernameName = element.attribute("name"); + usernameValue = getValueFromData(outgoingData, element); + if (!usernameName.isEmpty() && !usernameValue.isEmpty()) { + break; + } } - AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, outgoingData, passwordValue); + AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, outgoingData, usernameValue, passwordValue); webView->addNotification(aWidget); } + +QString AutoFillModel::getValueFromData(const QByteArray &data, QWebElement element) +{ + QString name = element.attribute("name"); + if (name.isEmpty()) { + return ""; + } + + QString value = element.evaluateJavaScript("this.value").toString(); + if (value.isEmpty()) { + QueryItems queryItems = QUrl("http://a.b/?" + data).queryItems(); + for (int i = 0; i < queryItems.count(); i++) { + QueryItem item = queryItems.at(i); + + if (item.first == name) { + value = item.second; + } + } + } + + return value; +} + +bool AutoFillModel::dataContains(const QByteArray &data, const QString &attributeName) +{ + QueryItems queryItems = QUrl("http://a.b/?" + data).queryItems(); + for (int i = 0; i < queryItems.count(); i++) { + QueryItem item = queryItems.at(i); + + if (item.first == attributeName) { + return !item.second.isEmpty(); + } + } + + return false; +} diff --git a/src/autofill/autofillmodel.h b/src/autofill/autofillmodel.h index 077c442f8..2a4ef7958 100644 --- a/src/autofill/autofillmodel.h +++ b/src/autofill/autofillmodel.h @@ -21,6 +21,7 @@ #include #include #include +#include class QupZilla; class WebView; @@ -28,6 +29,9 @@ class AutoFillModel : public QObject { Q_OBJECT public: + typedef QList > QueryItems; + typedef QPair QueryItem; + explicit AutoFillModel(QupZilla* mainClass, QObject* parent = 0); void completePage(WebView* view); @@ -38,7 +42,7 @@ public: QString getUsername(const QUrl &url); QString getPassword(const QUrl &url); bool addEntry(const QUrl &url, const QString &name, const QString &pass); - bool addEntry(const QUrl &url, const QByteArray &data, const QString &pass); + bool addEntry(const QUrl &url, const QByteArray &data, const QString &user, const QString &pass); void post(const QNetworkRequest &request, const QByteArray &outgoingData); @@ -48,6 +52,9 @@ public slots: void loadSettings(); private: + bool dataContains(const QByteArray &data, const QString &attributeName); + QString getValueFromData(const QByteArray &data, QWebElement element); + QupZilla* p_QupZilla; QByteArray m_lastOutgoingData; bool m_isStoring; diff --git a/src/autofill/autofillnotification.cpp b/src/autofill/autofillnotification.cpp index 355de1ef7..0f7eb5c20 100644 --- a/src/autofill/autofillnotification.cpp +++ b/src/autofill/autofillnotification.cpp @@ -22,16 +22,17 @@ #include "animatedwidget.h" #include "iconprovider.h" -AutoFillNotification::AutoFillNotification(QUrl url, QByteArray data, QString pass, QWidget* parent) +AutoFillNotification::AutoFillNotification(const QUrl &url, const QByteArray &data, const QString &user, const QString &pass, QWidget* parent) : AnimatedWidget(AnimatedWidget::Down, 300, parent) , ui(new Ui::AutoFillWidget) , m_url(url) , m_data(data) + , m_user(user) , m_pass(pass) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(widget()); - ui->label->setText(tr("Do you want QupZilla to remember password on %1?").arg(url.host())); + ui->label->setText(tr("Do you want QupZilla to remember password for %1 on %2?").arg(user, url.host())); ui->closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton)); connect(ui->remember, SIGNAL(clicked()), this, SLOT(remember())); @@ -50,7 +51,7 @@ void AutoFillNotification::never() void AutoFillNotification::remember() { - mApp->autoFill()->addEntry(m_url, m_data, m_pass); + mApp->autoFill()->addEntry(m_url, m_data, m_user, m_pass); hide(); } diff --git a/src/autofill/autofillnotification.h b/src/autofill/autofillnotification.h index edd3a47f0..38b5f1810 100644 --- a/src/autofill/autofillnotification.h +++ b/src/autofill/autofillnotification.h @@ -35,7 +35,7 @@ class AutoFillNotification : public AnimatedWidget Q_OBJECT public: - explicit AutoFillNotification(QUrl url, QByteArray data, QString pass, QWidget* parent = 0); + explicit AutoFillNotification(const QUrl &url, const QByteArray &data, const QString &user, const QString &pass, QWidget* parent = 0); ~AutoFillNotification(); private slots: @@ -46,6 +46,7 @@ private: Ui::AutoFillWidget* ui; QUrl m_url; QByteArray m_data; + QString m_user; QString m_pass; }; diff --git a/src/desktopnotifications/desktopnotificationsfactory.cpp b/src/desktopnotifications/desktopnotificationsfactory.cpp index 2460829f7..9f81df3c2 100644 --- a/src/desktopnotifications/desktopnotificationsfactory.cpp +++ b/src/desktopnotifications/desktopnotificationsfactory.cpp @@ -88,24 +88,24 @@ void DesktopNotificationsFactory::notify(const QPixmap &icon, const QString &hea void DesktopNotificationsFactory::nativeNotificationPreview() { #ifdef Q_WS_X11 - QFile tmp(QDir::tempPath() + "/qupzilla_notif.png"); - tmp.open(QFile::WriteOnly); - QPixmap(":icons/preferences/stock_dialog-question.png").save(tmp.fileName()); + QFile tmp(QDir::tempPath() + "/qupzilla_notif.png"); + tmp.open(QFile::WriteOnly); + QPixmap(":icons/preferences/stock_dialog-question.png").save(tmp.fileName()); - QDBusInterface dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); - QVariantList args; - args.append("qupzilla"); - args.append(m_uint); - args.append(tmp.fileName()); - args.append(tr("Native System Notification")); - args.append(""); - args.append(QStringList()); - args.append(QVariantMap()); - args.append(m_timeout); - QDBusMessage message = dbus.callWithArgumentList(QDBus::Block, "Notify", args); - QVariantList list = message.arguments(); - if (list.count() > 0) { - m_uint = list.at(0).toInt(); - } + QDBusInterface dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); + QVariantList args; + args.append("qupzilla"); + args.append(m_uint); + args.append(tmp.fileName()); + args.append(tr("Native System Notification")); + args.append(""); + args.append(QStringList()); + args.append(QVariantMap()); + args.append(m_timeout); + QDBusMessage message = dbus.callWithArgumentList(QDBus::Block, "Notify", args); + QVariantList list = message.arguments(); + if (list.count() > 0) { + m_uint = list.at(0).toInt(); + } #endif } diff --git a/src/preferences/autofillmanager.cpp b/src/preferences/autofillmanager.cpp index 81f453b59..61e1f8f6b 100644 --- a/src/preferences/autofillmanager.cpp +++ b/src/preferences/autofillmanager.cpp @@ -39,15 +39,15 @@ AutoFillManager::AutoFillManager(QWidget* parent) void AutoFillManager::loadPasswords() { QSqlQuery query; - query.exec("SELECT server, password, id FROM autofill"); + query.exec("SELECT server, username, password, id FROM autofill"); ui->treePass->clear(); while (query.next()) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->treePass); item->setText(0, query.value(0).toString()); -// item->setText(1, query.value(1).toString()); - item->setText(1, "*****"); - item->setWhatsThis(0, query.value(2).toString()); - item->setWhatsThis(1, query.value(1).toString()); + item->setText(1, query.value(1).toString()); + item->setText(2, "*****"); + item->setWhatsThis(0, query.value(3).toString()); + item->setWhatsThis(1, query.value(2).toString()); ui->treePass->addTopLevelItem(item); } @@ -79,7 +79,7 @@ void AutoFillManager::showPasswords() if (!item) { continue; } - item->setText(1, item->whatsThis(1)); + item->setText(2, item->whatsThis(1)); } ui->showPasswords->hide(); diff --git a/src/preferences/autofillmanager.ui b/src/preferences/autofillmanager.ui index d4367db31..65d581bb4 100644 --- a/src/preferences/autofillmanager.ui +++ b/src/preferences/autofillmanager.ui @@ -29,14 +29,22 @@ + + 0 + - 170 + 100 Server + + + Username + + Password @@ -47,16 +55,16 @@ - + - Remove + Edit - + - Edit + Remove diff --git a/translations/cs_CZ.ts b/translations/cs_CZ.ts index dccad00c4..ea11abdb9 100644 --- a/translations/cs_CZ.ts +++ b/translations/cs_CZ.ts @@ -228,41 +228,46 @@ Hesla - - + + Server Server - + + Username + Uživatel + + + Password Heslo - - + + Remove Odstranit - + Edit Upravit - - + + Remove All Odstranit vše - + Show Passwords Zobrazit hesla - + Exceptions Vyjímky @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - Chcete aby si QupZilla zapamatovala heslo pro %1? + + Do you want QupZilla to remember password for <b>%1</b> on %2? + Chcete aby si QupZilla zapamatovala heslo pro <b>%1<b> na %2? diff --git a/translations/de_DE.ts b/translations/de_DE.ts index 76d96df2d..b1adf1d83 100644 --- a/translations/de_DE.ts +++ b/translations/de_DE.ts @@ -228,41 +228,46 @@ Passwörter - - + + Server Server - + + Username + + + + Password Passwort - - + + Remove Entfernen - + Edit Bearbeiten - - + + Remove All Alle entfernen - + Show Passwords Passwörter im Klartext anzeigen - + Exceptions Ausnahmen @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - Möchten Sie das Passwort für %1 speichern? + + Do you want QupZilla to remember password for <b>%1</b> on %2? + diff --git a/translations/es.ts b/translations/es.ts index 0792df9f0..b774f94f4 100644 --- a/translations/es.ts +++ b/translations/es.ts @@ -228,41 +228,46 @@ Contraseñas - - + + Server Servidor - + + Username + + + + Password Contraseña - - + + Remove Quitar - + Edit Editar - - + + Remove All Quitar todo - + Show Passwords Mostras contraseñas - + Exceptions Excepciones @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - ¿Desea que QupZilla recuerde la contraseña en %1? + + Do you want QupZilla to remember password for <b>%1</b> on %2? + diff --git a/translations/it_IT.ts b/translations/it_IT.ts index 364395f93..072a1d261 100644 --- a/translations/it_IT.ts +++ b/translations/it_IT.ts @@ -228,41 +228,46 @@ Passwords - - + + Server Server - + + Username + + + + Password Password - - + + Remove Elimina - + Edit Modifica - - + + Remove All Elimina Tutto - + Show Passwords Mostra le password - + Exceptions Eccezioni @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - Vuoi che QupZilla ricordi la password per %1? + + Do you want QupZilla to remember password for <b>%1</b> on %2? + diff --git a/translations/nl_NL.ts b/translations/nl_NL.ts index ebba89eeb..d7dc32eba 100644 --- a/translations/nl_NL.ts +++ b/translations/nl_NL.ts @@ -228,41 +228,46 @@ Wachtwoorden - - + + Server Server - + + Username + + + + Password Wachtwoord - - + + Remove Verwijder - + Edit Bewerk - - + + Remove All Verwijder alles - + Show Passwords Toon wachtwoorden - + Exceptions Uitzonderingen @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - Wilt u dat QupZilla uw wachtwoord onthoudt voor %1? + + Do you want QupZilla to remember password for <b>%1</b> on %2? + diff --git a/translations/sk_SK.ts b/translations/sk_SK.ts index b14e94779..05681bab7 100644 --- a/translations/sk_SK.ts +++ b/translations/sk_SK.ts @@ -228,41 +228,46 @@ Heslá - - + + Server Server - + + Username + + + + Password Heslo - - + + Remove Odstrániť - + Edit Upraviť - - + + Remove All Odstrániť všetko - + Show Passwords Zobraziť heslo - + Exceptions Výnimky @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - Chcete aby si QupZilla zapamätala heslo pre %1? + + Do you want QupZilla to remember password for <b>%1</b> on %2? + diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 1b7007423..f266c7f92 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -228,41 +228,46 @@ 密码 - - + + Server 服务器 - + + Username + + + + Password 密码 - - + + Remove 删除 - + Edit 编辑 - - + + Remove All 全部删除 - + Show Passwords 显示密码 - + Exceptions 例外 @@ -295,9 +300,9 @@ AutoFillNotification - - Do you want QupZilla to remember password on %1? - 需要QupZilla记住%1密码? + + Do you want QupZilla to remember password for <b>%1</b> on %2? +