Permalink
Browse files

Add a password dialog that will appear when authenticationRequired is…

… emitted
  • Loading branch information...
1 parent da17ba1 commit d049c5afd8a6dc550844ff38387b69b976eb58c1 Benjamin C Meyer committed Jun 23, 2009
View
@@ -32,6 +32,8 @@ SOURCES += llembeddedbrowser.cpp \
llwebpage.cpp \
llstyle.cpp
+FORMS += passworddialog.ui
+
RCC_DIR = .rcc
UI_DIR = .ui
MOC_DIR = .moc
@@ -37,17 +37,23 @@
#include "llnetworkaccessmanager.h"
+#include <qauthenticator.h>
#include <qnetworkreply.h>
+#include <qtextdocument.h>
#include "llembeddedbrowserwindow.h"
#include "llembeddedbrowser_p.h"
+#include "ui_passworddialog.h"
+
LLNetworkAccessManager::LLNetworkAccessManager(LLEmbeddedBrowserPrivate* browser,QObject* parent)
: QNetworkAccessManager(parent)
, mBrowser(browser)
{
connect(this, SIGNAL(finished(QNetworkReply*)),
this, SLOT(finishLoading(QNetworkReply*)));
+ connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
}
void LLNetworkAccessManager::finishLoading(QNetworkReply* reply)
@@ -67,3 +73,21 @@ void LLNetworkAccessManager::finishLoading(QNetworkReply* reply)
}
}
+void LLNetworkAccessManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
+{
+ QDialog dialog;
+ Ui::PasswordDialog passwordDialog;
+ passwordDialog.setupUi(&dialog);
+ passwordDialog.icon->setText(QString());
+ passwordDialog.icon->setPixmap(qApp->style()->standardIcon(QStyle::SP_MessageBoxQuestion, 0, 0).pixmap(32, 32));
+
+ QString message = tr("<qt>Enter username and password for \"%1\" at %2</qt>")
+ .arg(Qt::escape(authenticator->realm()))
+ .arg(Qt::escape(reply->url().toString()));
+ passwordDialog.message->setText(message);
+ if (dialog.exec() == QDialog::Accepted) {
+ authenticator->setUser(passwordDialog.userName->text());
+ authenticator->setPassword(passwordDialog.password->text());
+ }
+}
+
@@ -47,8 +47,9 @@ class LLNetworkAccessManager: public QNetworkAccessManager
public:
LLNetworkAccessManager(LLEmbeddedBrowserPrivate* browser, QObject* parent = 0);
-public slots:
+private slots:
void finishLoading(QNetworkReply* reply);
+ void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
private:
LLEmbeddedBrowserPrivate* mBrowser;
View
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PasswordDialog</class>
+ <widget class="QDialog" name="PasswordDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>394</width>
+ <height>183</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>12</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="1" rowspan="3">
+ <widget class="QLabel" name="message">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="icon">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>32</horstretch>
+ <verstretch>32</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>icon</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>13</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="userNameLabel">
+ <property name="text">
+ <string>User name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="userName"/>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="passwordLabel">
+ <property name="text">
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QLineEdit" name="password">
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" colspan="2">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>PasswordDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>PasswordDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>

0 comments on commit d049c5a

Please sign in to comment.