summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2012-04-26 17:31:02 +0200
committerTim Jenssen <tim.jenssen@nokia.com>2012-04-27 11:43:37 +0200
commit5236d1a186661d7373063dfd606bd822b29754d7 (patch)
tree1c055222c5a0ea7c1db4de5a78a1e6a15d8e3179 /src/libs/kdtools
parent17939d4a28cfc1fcec00894c09ca5d7a78731ce0 (diff)
Implememt a way to ask for and save user authentication settings.
Change-Id: If1fa6bbcb8cd0d3da08f33f96b52589251f9cffc Reviewed-by: Niels Weber <niels.2.weber@nokia.com> Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
Diffstat (limited to 'src/libs/kdtools')
-rw-r--r--src/libs/kdtools/authenticationdialog.ui133
-rw-r--r--src/libs/kdtools/kdtools.pri2
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloader.cpp49
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloader.h1
4 files changed, 176 insertions, 9 deletions
diff --git a/src/libs/kdtools/authenticationdialog.ui b/src/libs/kdtools/authenticationdialog.ui
new file mode 100644
index 000000000..290963b5e
--- /dev/null
+++ b/src/libs/kdtools/authenticationdialog.ui
@@ -0,0 +1,133 @@
+<ui version="4.0" >
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>389</width>
+ <height>243</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Http authentication required</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" colspan="2" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>You need to supply a Username and Password to access this site.</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Username:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLineEdit" name="userEdit" />
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLineEdit" name="passwordEdit">
+ <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>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string></string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLabel" name="siteDescription" >
+ <property name="font" >
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text" >
+ <string>%1 at %2</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>Dialog</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>Dialog</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>
diff --git a/src/libs/kdtools/kdtools.pri b/src/libs/kdtools/kdtools.pri
index 8b14def9a..a83243502 100644
--- a/src/libs/kdtools/kdtools.pri
+++ b/src/libs/kdtools/kdtools.pri
@@ -5,6 +5,8 @@ CONFIG(shared, static|shared) {
DEFINES += BUILD_SHARED_KDTOOLS
}
+FORMS += authenticationdialog.ui
+
HEADERS += $$PWD/kdtoolsglobal.h \
$$PWD/kdjob.h \
$$PWD/kdgenericfactory.h \
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.cpp b/src/libs/kdtools/kdupdaterfiledownloader.cpp
index 67639dda6..818c8ac70 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.cpp
+++ b/src/libs/kdtools/kdupdaterfiledownloader.cpp
@@ -22,9 +22,11 @@
#include "kdupdaterfiledownloader_p.h"
#include "kdupdaterfiledownloaderfactory.h"
+#include "ui_authenticationdialog.h"
#include <fileutils.h>
+#include <QDialog>
#include <QFile>
#include <QtNetwork/QFtp>
#include <QtNetwork/QNetworkAccessManager>
@@ -507,10 +509,14 @@ QAuthenticator KDUpdater::FileDownloader::authenticator() const
/*!
Sets the authenticator object for this class to be \a authenticator. A authenticator is used to
pass on the required authentication information. This might only be of use for http or ftp requests.
+ Emits the authenticator changed signal with the new authenticator in use.
*/
void KDUpdater::FileDownloader::setAuthenticator(const QAuthenticator &authenticator)
{
- d->m_authenticator = authenticator;
+ if (d->m_authenticator.isNull() || (d->m_authenticator != authenticator)) {
+ d->m_authenticator = authenticator;
+ emit authenticatorChanged(authenticator);
+ }
}
// -- KDUpdater::LocalFileDownloader
@@ -1057,8 +1063,7 @@ struct KDUpdater::HttpDownloader::Private
, destination(0)
, downloaded(false)
, aborted(false)
- , retrying(false)
- , m_authenticationDone(false)
+ , m_authenticationCount(0)
{}
HttpDownloader *const q;
@@ -1068,8 +1073,7 @@ struct KDUpdater::HttpDownloader::Private
QString destFileName;
bool downloaded;
bool aborted;
- bool retrying;
- bool m_authenticationDone;
+ int m_authenticationCount;
void shutDown()
{
@@ -1256,7 +1260,7 @@ void KDUpdater::HttpDownloader::timerEvent(QTimerEvent *event)
void KDUpdater::HttpDownloader::startDownload(const QUrl &url)
{
- d->m_authenticationDone = false;
+ d->m_authenticationCount = 0;
d->manager.setProxyFactory(proxyFactory());
d->http = d->manager.get(QNetworkRequest(url));
@@ -1285,11 +1289,38 @@ void KDUpdater::HttpDownloader::startDownload(const QUrl &url)
void KDUpdater::HttpDownloader::onAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
{
- qDebug() << reply->readAll();
- if (!d->m_authenticationDone) {
- d->m_authenticationDone = true;
+ Q_UNUSED(reply)
+ // first try with the information we have already
+ if (d->m_authenticationCount == 0) {
+ d->m_authenticationCount++;
authenticator->setUser(this->authenticator().user());
authenticator->setPassword(this->authenticator().password());
+ } else if (d->m_authenticationCount == 1) {
+ // we failed to authenticate, ask for new credentials
+ QDialog dlg;
+ Ui::Dialog ui;
+ ui.setupUi(&dlg);
+ dlg.adjustSize();
+ ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url().host()));
+
+ ui.userEdit->setText(this->authenticator().user());
+ ui.passwordEdit->setText(this->authenticator().password());
+
+ if (dlg.exec() == QDialog::Accepted) {
+ authenticator->setUser(ui.userEdit->text());
+ authenticator->setPassword(ui.passwordEdit->text());
+
+ // update the authenticator we used initially
+ QAuthenticator auth;
+ auth.setUser(ui.userEdit->text());
+ auth.setPassword(ui.passwordEdit->text());
+ emit authenticatorChanged(auth);
+ } else {
+ d->shutDown();
+ setDownloadAborted(tr("Authentication request canceled."));
+ emit downloadCanceled();
+ }
+ d->m_authenticationCount++;
}
}
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.h b/src/libs/kdtools/kdupdaterfiledownloader.h
index 67467bff4..6408b7216 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.h
+++ b/src/libs/kdtools/kdupdaterfiledownloader.h
@@ -99,6 +99,7 @@ Q_SIGNALS:
void downloadSpeed(qint64 bytesPerSecond);
void downloadStatus(const QString &status);
void downloadProgress(qint64 bytesReceived, qint64 bytesToReceive);
+ void authenticatorChanged(const QAuthenticator &authenticator);
#ifndef Q_MOC_RUN
private: