diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-01-28 22:57:03 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-01-28 22:57:03 +0100 |
| commit | f25f28827639da3eb54f0e4a85174fe2cc777dcb (patch) | |
| tree | f631fd6dab840f11c3ac9e17e016bc9ce73ada58 /sb.cpp | |
| parent | e651d2636724cd6c5a55f3847d275f9be620db47 (diff) | |
Diffstat (limited to 'sb.cpp')
| -rw-r--r-- | sb.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -3,7 +3,9 @@ #include <QtWidgets/QApplication> #include <QAction> +#include <QAuthenticator> #include <QtGui/QWindow> +#include <QDialog> #include <QtWidgets/QMainWindow> #include <QtWebEngineWidgets/QWebEngineView> #include <QWebEngineView> @@ -19,6 +21,8 @@ #include <X11/Xlib.h> #include <QShortcut> #include <QVBoxLayout> +#include <QLineEdit> +#include <QPushButton> bool is_valid_url(const std::string & url); @@ -246,6 +250,46 @@ main(int argc, char **argv) { } }); + web->page()->connect(web->page(), &QWebEnginePage::authenticationRequired, [&](const QUrl &url, QAuthenticator *authenticator) { + QDialog dialog; + QVBoxLayout layout; + QLineEdit user; + QLineEdit password; + QPushButton ok; + QPushButton cancel; + + ok.setText("Ok"); + cancel.setText("Cancel"); + user.setPlaceholderText("Username"); + password.setPlaceholderText("Password"); + password.setEchoMode(QLineEdit::Password); + + dialog.setLayout(&layout); + layout.addWidget(&user); + layout.addWidget(&password); + layout.addWidget(&ok); + layout.addWidget(&cancel); + + dialog.connect(&dialog, &QDialog::finished, [&](int result) { + if (result == QDialog::Accepted) { + authenticator->setUser(user.text()); + authenticator->setPassword(password.text()); + } + dialog.close(); + }); + + ok.connect(&ok, &QPushButton::pressed, [&]() { + dialog.accept(); + }); + + cancel.connect(&cancel, &QPushButton::pressed, [&]() { + web->stop(); + dialog.reject(); + }); + + dialog.exec(); + }); + register_shortcuts(view); return app.exec(); |