diff options
author | Samuli Piippo <samuli.piippo@digia.com> | 2013-11-19 16:22:42 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@digia.com> | 2013-11-20 12:33:46 +0100 |
commit | 6213db49c8281ed9cb84e32b1cee261202f9ad73 (patch) | |
tree | bfaca77e635cf550a19d0181bcbdb9aefa5b3c1c /src | |
parent | 9dd6a230ff1373da68f5fe9684cad08ed8b6992e (diff) |
Move TestRepository from sdk to own file in installer lib
Moved the class to installer lib so it can be reused
in ProductKeyCheck as well.
Change-Id: I8b207f4816505671fa05ebf602895978e04d13e9
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/installer.pro | 6 | ||||
-rw-r--r-- | src/libs/installer/testrepository.cpp | 168 | ||||
-rw-r--r-- | src/libs/installer/testrepository.h | 95 | ||||
-rw-r--r-- | src/sdk/settingsdialog.cpp | 126 | ||||
-rw-r--r-- | src/sdk/settingsdialog.h | 39 |
5 files changed, 269 insertions, 165 deletions
diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index 1595773f2..197e853c3 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -102,7 +102,8 @@ HEADERS += packagemanagercore.h \ applyproductkeyoperation.h \ globals.h \ graph.h \ - settingsoperation.h + settingsoperation.h \ + testrepository.h SOURCES += packagemanagercore.cpp \ packagemanagercore_p.cpp \ @@ -165,7 +166,8 @@ HEADERS += packagemanagercore.h \ packagemanagercoredata.cpp \ applyproductkeyoperation.cpp \ globals.cpp \ - settingsoperation.cpp + settingsoperation.cpp \ + testrepository.cpp RESOURCES += resources/patch_file_lists.qrc \ resources/installer.qrc diff --git a/src/libs/installer/testrepository.cpp b/src/libs/installer/testrepository.cpp new file mode 100644 index 000000000..a39c499a1 --- /dev/null +++ b/src/libs/installer/testrepository.cpp @@ -0,0 +1,168 @@ +/************************************************************************** +** +** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ +#include "testrepository.h" + +#include <kdupdaterfiledownloader.h> +#include <kdupdaterfiledownloaderfactory.h> + +#include <QtCore/QFile> + +using namespace QInstaller; + +TestRepository::TestRepository(QObject *parent) + : KDJob(parent) + , m_downloader(0) +{ + setTimeout(10000); + setAutoDelete(false); + setCapabilities(Cancelable); +} + +TestRepository::~TestRepository() +{ + if (m_downloader) + m_downloader->deleteLater(); +} + +Repository TestRepository::repository() const +{ + return m_repository; +} + +void TestRepository::setRepository(const Repository &repository) +{ + cancel(); + + setError(NoError); + setErrorString(QString()); + m_repository = repository; +} + +void TestRepository::doStart() +{ + if (m_downloader) + m_downloader->deleteLater(); + + const QUrl url = m_repository.url(); + if (url.isEmpty()) { + emitFinishedWithError(InvalidUrl, tr("Empty repository URL.")); + return; + } + + m_downloader = KDUpdater::FileDownloaderFactory::instance().create(url.scheme(), this); + if (!m_downloader) { + emitFinishedWithError(InvalidUrl, tr("URL scheme not supported: %1 (%2).") + .arg(url.scheme(), url.toString())); + return; + } + + QAuthenticator auth; + auth.setUser(m_repository.username()); + auth.setPassword(m_repository.password()); + m_downloader->setAuthenticator(auth); + + 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"))); + + m_downloader->download(); +} + +void TestRepository::doCancel() +{ + if (m_downloader) { + QString errorString = m_downloader->errorString(); + if (errorString.isEmpty()) + errorString = tr("Got a timeout while testing: '%1'").arg(m_repository.displayname()); + // at the moment the download sends downloadCompleted() if we cancel it, so just + disconnect(m_downloader, 0, this, 0); + m_downloader->cancelDownload(); + emitFinishedWithError(KDJob::Canceled, errorString); + } +} + +void TestRepository::downloadCompleted() +{ + QString errorMsg; + int error = DownloadError; + + if (m_downloader->isDownloaded()) { + QFile file(m_downloader->downloadedFileName()); + if (file.exists() && file.open(QIODevice::ReadOnly)) { + QDomDocument doc; + QString errorMsg; + if (!doc.setContent(&file, &errorMsg)) { + error = InvalidUpdatesXml; + errorMsg = tr("Could not parse Updates.xml! Error: %1.").arg(errorMsg); + } else { + error = NoError; + } + } else { + errorMsg = tr("Updates.xml could not be opened for reading!"); + } + } else { + errorMsg = tr("Updates.xml could not be found on server!"); + } + + if (error > NoError) + emitFinishedWithError(error, errorMsg); + else + emitFinished(); + + m_downloader->deleteLater(); + m_downloader = 0; +} + +void TestRepository::downloadAborted(const QString &reason) +{ + emitFinishedWithError(DownloadError, reason); +} + +void TestRepository::onAuthenticatorChanged(const QAuthenticator &authenticator) +{ + m_repository.setUsername(authenticator.user()); + m_repository.setPassword(authenticator.password()); +} diff --git a/src/libs/installer/testrepository.h b/src/libs/installer/testrepository.h new file mode 100644 index 000000000..c1ecc039c --- /dev/null +++ b/src/libs/installer/testrepository.h @@ -0,0 +1,95 @@ +/************************************************************************** +** +** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ +#ifndef TESTREPOSITORY_H +#define TESTREPOSITORY_H + +#include "qinstallerglobal.h" + +#include <repository.h> +#include <settings.h> + +#include <kdjob.h> + +QT_BEGIN_NAMESPACE +class QAuthenticator; +class QLocale; +class QVariant; +QT_END_NAMESPACE + +namespace KDUpdater { + class FileDownloader; +} + +namespace QInstaller { + class PackageManagerCore; +} + +namespace QInstaller { + +class INSTALLER_EXPORT TestRepository : public KDJob +{ + Q_OBJECT + +public: + + explicit TestRepository(QObject *parent = 0); + ~TestRepository(); + + QInstaller::Repository repository() const; + void setRepository(const QInstaller::Repository &repository); + +private: + void doStart(); + void doCancel(); + +private Q_SLOTS: + void downloadCompleted(); + void downloadAborted(const QString &reason); + void onAuthenticatorChanged(const QAuthenticator &authenticator); + +private: + QInstaller::Repository m_repository; + KDUpdater::FileDownloader *m_downloader; +}; + +} //namespace QInstaller + +#endif // TESTREPOSITORY_H diff --git a/src/sdk/settingsdialog.cpp b/src/sdk/settingsdialog.cpp index 1a7903403..0f1f3ff6e 100644 --- a/src/sdk/settingsdialog.cpp +++ b/src/sdk/settingsdialog.cpp @@ -42,8 +42,6 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" -#include <kdupdaterfiledownloader.h> -#include <kdupdaterfiledownloaderfactory.h> #include <packagemanagercore.h> #include <productkeycheck.h> @@ -57,130 +55,6 @@ using namespace QInstaller; - -// -- TestRepositoryJob - -TestRepository::TestRepository(QObject *parent) - : KDJob(parent) - , m_downloader(0) -{ - setTimeout(10000); - setAutoDelete(false); - setCapabilities(Cancelable); -} - -TestRepository::~TestRepository() -{ - if (m_downloader) - m_downloader->deleteLater(); -} - -Repository TestRepository::repository() const -{ - return m_repository; -} - -void TestRepository::setRepository(const Repository &repository) -{ - cancel(); - - setError(NoError); - setErrorString(QString()); - m_repository = repository; -} - -void TestRepository::doStart() -{ - if (m_downloader) - m_downloader->deleteLater(); - - const QUrl url = m_repository.url(); - if (url.isEmpty()) { - emitFinishedWithError(InvalidUrl, tr("Empty repository URL.")); - return; - } - - m_downloader = KDUpdater::FileDownloaderFactory::instance().create(url.scheme(), this); - if (!m_downloader) { - emitFinishedWithError(InvalidUrl, tr("URL scheme not supported: %1 (%2).") - .arg(url.scheme(), url.toString())); - return; - } - - QAuthenticator auth; - auth.setUser(m_repository.username()); - auth.setPassword(m_repository.password()); - m_downloader->setAuthenticator(auth); - - 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"))); - - m_downloader->download(); -} - -void TestRepository::doCancel() -{ - if (m_downloader) { - QString errorString = m_downloader->errorString(); - if (errorString.isEmpty()) - errorString = tr("Got a timeout while testing: '%1'").arg(m_repository.displayname()); - // at the moment the download sends downloadCompleted() if we cancel it, so just - disconnect(m_downloader, 0, this, 0); - m_downloader->cancelDownload(); - emitFinishedWithError(KDJob::Canceled, errorString); - } -} - -void TestRepository::downloadCompleted() -{ - QString errorMsg; - int error = DownloadError; - - if (m_downloader->isDownloaded()) { - QFile file(m_downloader->downloadedFileName()); - if (file.exists() && file.open(QIODevice::ReadOnly)) { - QDomDocument doc; - QString errorMsg; - if (!doc.setContent(&file, &errorMsg)) { - error = InvalidUpdatesXml; - errorMsg = tr("Could not parse Updates.xml! Error: %1.").arg(errorMsg); - } else { - error = NoError; - } - } else { - errorMsg = tr("Updates.xml could not be opened for reading!"); - } - } else { - errorMsg = tr("Updates.xml could not be found on server!"); - } - - if (error > NoError) - emitFinishedWithError(error, errorMsg); - else - emitFinished(); - - m_downloader->deleteLater(); - m_downloader = 0; -} - -void TestRepository::downloadAborted(const QString &reason) -{ - emitFinishedWithError(DownloadError, reason); -} - -void TestRepository::onAuthenticatorChanged(const QAuthenticator &authenticator) -{ - m_repository.setUsername(authenticator.user()); - m_repository.setPassword(authenticator.password()); -} - - // -- PasswordDelegate void PasswordDelegate::showPasswords(bool show) diff --git a/src/sdk/settingsdialog.h b/src/sdk/settingsdialog.h index 1a6633c67..a2386acbb 100644 --- a/src/sdk/settingsdialog.h +++ b/src/sdk/settingsdialog.h @@ -43,8 +43,7 @@ #include <repository.h> #include <settings.h> - -#include <kdjob.h> +#include <testrepository.h> #include <QDialog> #include <QStyledItemDelegate> @@ -56,10 +55,6 @@ class QLocale; class QVariant; QT_END_NAMESPACE -namespace KDUpdater { - class FileDownloader; -} - namespace QInstaller { class PackageManagerCore; } @@ -68,36 +63,6 @@ namespace Ui { class SettingsDialog; } - -// -- TestRepositoryJob - -class TestRepository : public KDJob -{ - Q_OBJECT - -public: - - explicit TestRepository(QObject *parent = 0); - ~TestRepository(); - - QInstaller::Repository repository() const; - void setRepository(const QInstaller::Repository &repository); - -private: - void doStart(); - void doCancel(); - -private Q_SLOTS: - void downloadCompleted(); - void downloadAborted(const QString &reason); - void onAuthenticatorChanged(const QAuthenticator &authenticator); - -private: - QInstaller::Repository m_repository; - KDUpdater::FileDownloader *m_downloader; -}; - - // -- PasswordDelegate class PasswordDelegate : public QStyledItemDelegate @@ -177,7 +142,7 @@ private: QInstaller::PackageManagerCore *m_core; bool m_showPasswords; - TestRepository m_testRepository; + QInstaller::TestRepository m_testRepository; QList<QTreeWidgetItem*> m_rootItems; }; |