diff options
author | kh1 <karsten.heimrich@nokia.com> | 2011-11-25 14:38:36 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@nokia.com> | 2011-11-28 14:05:25 +0100 |
commit | c4dc22c5fd76e8b028200d33553b97079adeaeb3 (patch) | |
tree | f5103704e8b00e767c0133d16c3c699785a7885a /installerbuilder/libinstaller | |
parent | e9a5dce1593172a69fbcc1a8e2c62cc63d33b486 (diff) |
Implement network settings dialog.
User settings are stored inside a network.xml file, e.g. proxy
type, proxy authentification, repositories etc... Default repos
are saved kind of encrypted inside the already existing ini file.
Change-Id: Ie97f2e82af7faf4d15719c669a0fa4158b503ce3
Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com>
Diffstat (limited to 'installerbuilder/libinstaller')
5 files changed, 183 insertions, 44 deletions
diff --git a/installerbuilder/libinstaller/libinstaller.pro b/installerbuilder/libinstaller/libinstaller.pro index dae985890..bcf64b026 100644 --- a/installerbuilder/libinstaller/libinstaller.pro +++ b/installerbuilder/libinstaller/libinstaller.pro @@ -100,7 +100,8 @@ HEADERS += $$PWD/packagemanagercore.h \ updatecreatorsettingsfrom21to22operation.h \ qprocesswrapper.h \ qsettingswrapper.h \ - constants.h + constants.h \ + packagemanagerproxyfactory.h SOURCES += $$PWD/packagemanagercore.cpp \ $$PWD/packagemanagercore_p.cpp \ @@ -166,7 +167,8 @@ SOURCES += $$PWD/packagemanagercore.cpp \ qprocesswrapper.cpp \ templates.cpp \ qsettingswrapper.cpp \ - settings.cpp + settings.cpp \ + packagemanagerproxyfactory.cpp macx { HEADERS += macrelocateqt.h \ @@ -200,3 +202,5 @@ TRANSLATIONS += translations/de_de.ts \ RESOURCES += ../common/openssl.qrc \ resources/patch_file_lists.qrc + + diff --git a/installerbuilder/libinstaller/packagemanagercore.cpp b/installerbuilder/libinstaller/packagemanagercore.cpp index fd3ff0cb4..fa65a44b8 100644 --- a/installerbuilder/libinstaller/packagemanagercore.cpp +++ b/installerbuilder/libinstaller/packagemanagercore.cpp @@ -605,6 +605,19 @@ LocalPackagesHash PackageManagerCore::localInstalledPackages() return d->localInstalledPackages(); } +void PackageManagerCore::networkSettingsChanged() +{ + cancelMetaInfoJob(); + + d->m_updates = false; + d->m_repoFetched = false; + d->m_updateSourcesAdded = false; + + if (d->isUpdater() || d->isPackageManager()) + d->writeMaintenanceConfigFiles(); + KDUpdater::FileDownloaderFactory::instance().setProxyFactory(proxyFactory()); +} + KDUpdater::FileDownloaderProxyFactory *PackageManagerCore::proxyFactory() const { if (d->m_proxyFactory) @@ -996,7 +1009,7 @@ QList<Component*> PackageManagerCore::dependencies(const Component *component, Q return result; } -const Settings &PackageManagerCore::settings() const +Settings &PackageManagerCore::settings() const { return d->m_settings; } diff --git a/installerbuilder/libinstaller/packagemanagercore.h b/installerbuilder/libinstaller/packagemanagercore.h index ef460fa17..d9ae85076 100644 --- a/installerbuilder/libinstaller/packagemanagercore.h +++ b/installerbuilder/libinstaller/packagemanagercore.h @@ -94,6 +94,7 @@ public: bool fetchLocalPackagesTree(); LocalPackagesHash localInstalledPackages(); + void networkSettingsChanged(); KDUpdater::FileDownloaderProxyFactory *proxyFactory() const; void setProxyFactory(KDUpdater::FileDownloaderProxyFactory *factory); @@ -197,7 +198,7 @@ public: Q_INVOKABLE bool isProcessRunning(const QString &name) const; - const Settings &settings() const; + Settings &settings() const; Q_INVOKABLE bool addWizardPage(QInstaller::Component *component, const QString &name, int page); Q_INVOKABLE bool removeWizardPage(QInstaller::Component *component, const QString &name); diff --git a/installerbuilder/libinstaller/packagemanagercore_p.cpp b/installerbuilder/libinstaller/packagemanagercore_p.cpp index bf3773a26..d3a632d62 100644 --- a/installerbuilder/libinstaller/packagemanagercore_p.cpp +++ b/installerbuilder/libinstaller/packagemanagercore_p.cpp @@ -60,6 +60,9 @@ #include <QtCore/QFutureWatcher> #include <QtCore/QTemporaryFile> +#include <QtXml/QXmlStreamReader> +#include <QtXml/QXmlStreamWriter> + #include <errno.h> namespace QInstaller { @@ -567,9 +570,9 @@ void PackageManagerCorePrivate::initialize() if (!m_core->isInstaller()) { #ifdef Q_WS_MAC - readUninstallerIniFile(QCoreApplication::applicationDirPath() + QLatin1String("/../../..")); + readMaintenanceConfigFiles(QCoreApplication::applicationDirPath() + QLatin1String("/../../..")); #else - readUninstallerIniFile(QCoreApplication::applicationDirPath()); + readMaintenanceConfigFiles(QCoreApplication::applicationDirPath()); #endif } @@ -721,22 +724,162 @@ QString PackageManagerCorePrivate::uninstallerName() const return QString::fromLatin1("%1/%2").arg(targetDir()).arg(filename); } -void PackageManagerCorePrivate::readUninstallerIniFile(const QString &targetDir) +static QNetworkProxy readProxy(QXmlStreamReader &reader) +{ + QNetworkProxy proxy(QNetworkProxy::HttpProxy); + while (reader.readNextStartElement()) { + if (reader.name() == QLatin1String("Host")) + proxy.setHostName(reader.readElementText()); + else if (reader.name() == QLatin1String("Port")) + proxy.setPort(reader.readElementText().toInt()); + else if (reader.name() == QLatin1String("Username")) + proxy.setUser(reader.readElementText()); + else if (reader.name() == QLatin1String("Password")) + proxy.setPassword(reader.readElementText()); + else + reader.skipCurrentElement(); + } + return proxy; +} + +static QSet<Repository> readRepositories(QXmlStreamReader &reader, bool isDefault) +{ + QSet<Repository> set; + while (reader.readNextStartElement()) { + if (reader.name() == QLatin1String("Repository")) { + Repository repo(QString(), isDefault); + while (reader.readNextStartElement()) { + if (reader.name() == QLatin1String("Host")) + repo.setUrl(reader.readElementText()); + else if (reader.name() == QLatin1String("Username")) + repo.setUsername(reader.readElementText()); + else if (reader.name() == QLatin1String("Password")) + repo.setPassword(reader.readElementText()); + else if (reader.name() == QLatin1String("Enabled")) + repo.setEnabled(bool(reader.readElementText().toInt())); + else + reader.skipCurrentElement(); + } + set.insert(repo); + } else { + reader.skipCurrentElement(); + } + } + return set; +} + +void PackageManagerCorePrivate::writeMaintenanceConfigFiles() { - const QString iniPath = targetDir + QLatin1Char('/') + m_settings.uninstallerIniFile(); + // write current state (variables) to the uninstaller ini file + const QString iniPath = targetDir() + QLatin1Char('/') + m_settings.uninstallerIniFile(); + + QVariantHash vars; QSettingsWrapper cfg(iniPath, QSettingsWrapper::IniFormat); + foreach (const QString &key, m_vars.keys()) { + if (key != scRunProgramDescription && key != scRunProgram) + vars.insert(key, m_vars.value(key)); + } + cfg.setValue(QLatin1String("Variables"), vars); + + QVariantList repos; + foreach (const Repository &repo, m_settings.defaultRepositories()) + repos.append(QVariant().fromValue(repo)); + cfg.setValue(QLatin1String("DefaultRepositories"), repos); + + cfg.sync(); + if (cfg.status() != QSettingsWrapper::NoError) { + const QString reason = cfg.status() == QSettingsWrapper::AccessError ? tr("Access error") + : tr("Format error"); + throw Error(tr("Could not write installer configuration to %1: %2").arg(iniPath, reason)); + } + + QFile file(targetDir() + QLatin1Char('/') + QLatin1String("network.xml")); + if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + QXmlStreamWriter writer(&file); + writer.setCodec("UTF-8"); + writer.setAutoFormatting(true); + writer.writeStartDocument(); + + writer.writeStartElement(QLatin1String("Network")); + writer.writeTextElement(QLatin1String("ProxyType"), QString::number(m_settings.proxyType())); + writer.writeStartElement(QLatin1String("Ftp")); + const QNetworkProxy &ftpProxy = m_settings.ftpProxy(); + writer.writeTextElement(QLatin1String("Host"), ftpProxy.hostName()); + writer.writeTextElement(QLatin1String("Port"), QString::number(ftpProxy.port())); + writer.writeTextElement(QLatin1String("Username"), ftpProxy.user()); + writer.writeTextElement(QLatin1String("Password"), ftpProxy.password()); + writer.writeEndElement(); + writer.writeStartElement(QLatin1String("Http")); + const QNetworkProxy &httpProxy = m_settings.httpProxy(); + writer.writeTextElement(QLatin1String("Host"), httpProxy.hostName()); + writer.writeTextElement(QLatin1String("Port"), QString::number(httpProxy.port())); + writer.writeTextElement(QLatin1String("Username"), httpProxy.user()); + writer.writeTextElement(QLatin1String("Password"), httpProxy.password()); + writer.writeEndElement(); + + writer.writeStartElement(QLatin1String("Repositories")); + foreach (const Repository &repo, m_settings.userRepositories()) { + writer.writeStartElement(QLatin1String("Repository")); + writer.writeTextElement(QLatin1String("Host"), repo.url().toString()); + writer.writeTextElement(QLatin1String("Username"), repo.username()); + writer.writeTextElement(QLatin1String("Password"), repo.password()); + writer.writeTextElement(QLatin1String("Enabled"), QString::number(repo.isEnabled())); + writer.writeEndElement(); + } + writer.writeEndElement(); + writer.writeEndElement(); + } +} + +void PackageManagerCorePrivate::readMaintenanceConfigFiles(const QString &targetDir) +{ + QSettingsWrapper cfg(targetDir + QLatin1Char('/') + m_settings.uninstallerIniFile(), + QSettingsWrapper::IniFormat); const QVariantHash vars = cfg.value(QLatin1String("Variables")).toHash(); - QHash<QString, QVariant>::ConstIterator it = vars.constBegin(); - while (it != vars.constEnd()) { + for (QHash<QString, QVariant>::ConstIterator it = vars.constBegin(); it != vars.constEnd(); ++it) m_vars.insert(it.key(), it.value().toString()); - ++it; - } - QSet<Repository> repositories; - const QStringList list = cfg.value(scRepositories).toStringList(); - foreach (const QString &url, list) - repositories.insert(Repository(url, false)); - m_settings.addUserRepositories(repositories); + QSet<Repository> repos; + const QVariantList variants = cfg.value(QLatin1String("DefaultRepositories")).toList(); + foreach (const QVariant &variant, variants) + repos.insert(variant.value<Repository>()); + if (!repos.isEmpty()) + m_settings.setDefaultRepositories(repos); + + QFile file(targetDir + QLatin1String("/network.xml")); + if (!file.open(QIODevice::ReadOnly)) + return; + + QXmlStreamReader reader(&file); + while (!reader.atEnd()) { + switch (reader.readNext()) { + case QXmlStreamReader::StartElement: { + if (reader.name() == QLatin1String("Network")) { + while (reader.readNextStartElement()) { + const QStringRef name = reader.name(); + if (name == QLatin1String("Ftp")) { + m_settings.setFtpProxy(readProxy(reader)); + } else if (name == QLatin1String("Http")) { + m_settings.setHttpProxy(readProxy(reader)); + } else if (reader.name() == QLatin1String("Repositories")) { + m_settings.addUserRepositories(readRepositories(reader, false)); + } else if (name == QLatin1String("ProxyType")) { + m_settings.setProxyType(Settings::ProxyType(reader.readElementText().toInt())); + } else { + reader.skipCurrentElement(); + } + } + } + } break; + + case QXmlStreamReader::Invalid: { + qDebug() << reader.errorString(); + } break; + + default: + break; + } + } } void PackageManagerCorePrivate::callBeginInstallation(const QList<Component*> &componentList) @@ -960,32 +1103,7 @@ void PackageManagerCorePrivate::writeUninstaller(OperationList performedOperatio performedOperations.append(takeOwnedOperation(op)); } - { - // write current state (variables) to the uninstaller ini file - const QString iniPath = targetDir() + QLatin1Char('/') + m_settings.uninstallerIniFile(); - QSettingsWrapper cfg(iniPath, QSettingsWrapper::IniFormat); - QVariantHash vars; - QHash<QString, QString>::ConstIterator it = m_vars.constBegin(); - while (it != m_vars.constEnd()) { - const QString &key = it.key(); - if (key != scRunProgramDescription && key != scRunProgram) - vars.insert(key, it.value()); - ++it; - } - cfg.setValue(QLatin1String("Variables"), vars); - - QStringList list; - foreach (const Repository &repository, m_settings.userRepositories()) - list.append(repository.url().toString()); - cfg.setValue(scRepositories, list); - - cfg.sync(); - if (cfg.status() != QSettingsWrapper::NoError) { - const QString reason = cfg.status() == QSettingsWrapper::AccessError ? tr("Access error") - : tr("Format error"); - throw Error(tr("Could not write installer configuration to %1: %2").arg(iniPath, reason)); - } - } + writeMaintenanceConfigFiles(); #ifdef Q_WS_MAC // if it is a bundle, we need some stuff in it... diff --git a/installerbuilder/libinstaller/packagemanagercore_p.h b/installerbuilder/libinstaller/packagemanagercore_p.h index b7bf07342..05596d870 100644 --- a/installerbuilder/libinstaller/packagemanagercore_p.h +++ b/installerbuilder/libinstaller/packagemanagercore_p.h @@ -92,7 +92,10 @@ public: QString uninstallerName() const; QString installerBinaryPath() const; - void readUninstallerIniFile(const QString &targetDir); + + void writeMaintenanceConfigFiles(); + void readMaintenanceConfigFiles(const QString &targetDir); + void writeUninstaller(OperationList performedOperations); QString componentsXmlPath() const; |