summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libs/installer/getrepositorymetainfojob.cpp47
-rw-r--r--src/libs/installer/getrepositorymetainfojob.h5
-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
-rw-r--r--src/sdk/settingsdialog.cpp14
-rw-r--r--src/sdk/settingsdialog.h3
8 files changed, 245 insertions, 9 deletions
diff --git a/src/libs/installer/getrepositorymetainfojob.cpp b/src/libs/installer/getrepositorymetainfojob.cpp
index ac575ab18..c86ab9309 100644
--- a/src/libs/installer/getrepositorymetainfojob.cpp
+++ b/src/libs/installer/getrepositorymetainfojob.cpp
@@ -226,6 +226,8 @@ void GetRepositoryMetaInfoJob::startUpdatesXmlDownload()
connect(m_downloader, SIGNAL(downloadCanceled()), this, SLOT(updatesXmlDownloadCanceled()));
connect(m_downloader, SIGNAL(downloadAborted(QString)), this,
SLOT(updatesXmlDownloadError(QString)), Qt::QueuedConnection);
+ connect(m_downloader, SIGNAL(authenticatorChanged(QAuthenticator)), this,
+ SLOT(onAuthenticatorChanged(QAuthenticator)));
m_downloader->download();
}
@@ -440,6 +442,8 @@ void GetRepositoryMetaInfoJob::fetchNextMetaInfo()
connect(m_downloader, SIGNAL(downloadCompleted()), this, SLOT(metaDownloadFinished()));
connect(m_downloader, SIGNAL(downloadAborted(QString)), this, SLOT(metaDownloadError(QString)),
Qt::QueuedConnection);
+ connect(m_downloader, SIGNAL(authenticatorChanged(QAuthenticator)), this,
+ SLOT(onAuthenticatorChanged(QAuthenticator)));
m_downloader->download();
}
@@ -512,5 +516,48 @@ void GetRepositoryMetaInfoJob::unzipFinished(bool ok, const QString &error)
finished(QInstaller::ExtractionError, error);
}
+bool GetRepositoryMetaInfoJob::updateRepositories(QSet<Repository> *repositories, const QString &username,
+ const QString &password)
+{
+ if (!repositories->contains(m_repository))
+ return false;
+
+ repositories->remove(m_repository);
+ m_repository.setUsername(username);
+ m_repository.setPassword(password);
+ repositories->insert(m_repository);
+ return true;
+}
+
+void GetRepositoryMetaInfoJob::onAuthenticatorChanged(const QAuthenticator &authenticator)
+{
+ const QString username = authenticator.user();
+ const QString password = authenticator.password();
+ if (username != m_repository.username() || password != m_repository.password()) {
+ QSet<Repository> repositories = m_corePrivate->m_settings.defaultRepositories();
+ bool reposChanged = updateRepositories(&repositories, username, password);
+ if (reposChanged)
+ m_corePrivate->m_settings.setDefaultRepositories(repositories);
+
+ repositories = m_corePrivate->m_settings.temporaryRepositories();
+ reposChanged |= updateRepositories(&repositories, username, password);
+ if (reposChanged) {
+ m_corePrivate->m_settings.setTemporaryRepositories(repositories,
+ m_corePrivate->m_settings.hasReplacementRepos());
+ }
+
+ repositories = m_corePrivate->m_settings.userRepositories();
+ reposChanged |= updateRepositories(&repositories, username, password);
+ if (reposChanged)
+ m_corePrivate->m_settings.setUserRepositories(repositories);
+
+ if (reposChanged) {
+ if (m_corePrivate->isUpdater() || m_corePrivate->isPackageManager())
+ m_corePrivate->writeMaintenanceConfigFiles();
+ finished(QInstaller::RepositoryUpdatesReceived, tr("Repository updates received."));
+ }
+ }
+}
+
#include "getrepositorymetainfojob.moc"
#include "moc_getrepositorymetainfojob.cpp"
diff --git a/src/libs/installer/getrepositorymetainfojob.h b/src/libs/installer/getrepositorymetainfojob.h
index aec94603d..59acb7499 100644
--- a/src/libs/installer/getrepositorymetainfojob.h
+++ b/src/libs/installer/getrepositorymetainfojob.h
@@ -43,6 +43,8 @@
#include <QtCore/QStringList>
#include <QtCore/QThreadPool>
+#include <QAuthenticator>
+
namespace KDUpdater {
class FileDownloader;
}
@@ -75,6 +77,8 @@ private:
/* reimp */ void doStart();
/* reimp */ void doCancel();
void finished(int error, const QString &errorString = QString());
+ bool updateRepositories(QSet<Repository> *repositories, const QString &username,
+ const QString &password);
private Q_SLOTS:
void startUpdatesXmlDownload();
@@ -88,6 +92,7 @@ private Q_SLOTS:
void metaDownloadError(const QString &error);
void unzipFinished(bool status, const QString &error);
+ void onAuthenticatorChanged(const QAuthenticator &authenticator);
private:
bool m_canceled;
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:
diff --git a/src/sdk/settingsdialog.cpp b/src/sdk/settingsdialog.cpp
index b3508e169..9f705b41a 100644
--- a/src/sdk/settingsdialog.cpp
+++ b/src/sdk/settingsdialog.cpp
@@ -63,6 +63,11 @@ TestRepository::~TestRepository()
m_downloader->deleteLater();
}
+QInstaller::Repository TestRepository::repository() const
+{
+ return m_repository;
+}
+
void TestRepository::setRepository(const QInstaller::Repository &repository)
{
cancel();
@@ -98,6 +103,8 @@ void TestRepository::doStart()
connect(m_downloader, SIGNAL(downloadCompleted()), this, SLOT(downloadCompleted()));
connect(m_downloader, SIGNAL(downloadAborted(QString)), this, SLOT(downloadAborted(QString)),
Qt::QueuedConnection);
+ connect(m_downloader, SIGNAL(authenticatorChanged(QAuthenticator)), this,
+ SLOT(onAuthenticatorChanged(QAuthenticator)));
m_downloader->setAutoRemoveDownloadedFile(true);
m_downloader->setUrl(QUrl(url.toString() + QString::fromLatin1("/Updates.xml")));
@@ -150,6 +157,12 @@ void TestRepository::downloadAborted(const QString &reason)
emitFinishedWithError(QInstaller::DownloadError, reason);
}
+void TestRepository::onAuthenticatorChanged(const QAuthenticator &authenticator)
+{
+ m_repository.setUsername(authenticator.user());
+ m_repository.setPassword(authenticator.password());
+}
+
// -- PasswordDelegate
@@ -431,6 +444,7 @@ void SettingsDialog::testRepository()
m_testRepository.setRepository(current->repository());
m_testRepository.start();
m_testRepository.waitForFinished();
+ current->setRepository(m_testRepository.repository());
if (m_testRepository.error() > KDJob::NoError) {
QMessageBox msgBox(this);
diff --git a/src/sdk/settingsdialog.h b/src/sdk/settingsdialog.h
index a222ecf87..85fa2f26a 100644
--- a/src/sdk/settingsdialog.h
+++ b/src/sdk/settingsdialog.h
@@ -42,6 +42,7 @@
#include <QtGui/QTreeWidgetItem>
QT_BEGIN_NAMESPACE
+class QAuthenticator;
class QLocale;
class QVariant;
QT_END_NAMESPACE
@@ -70,6 +71,7 @@ public:
TestRepository(QObject *parent = 0);
~TestRepository();
+ QInstaller::Repository repository() const;
void setRepository(const QInstaller::Repository &repository);
private:
@@ -79,6 +81,7 @@ private:
private Q_SLOTS:
void downloadCompleted();
void downloadAborted(const QString &reason);
+ void onAuthenticatorChanged(const QAuthenticator &authenticator);
private:
QInstaller::Repository m_repository;