summaryrefslogtreecommitdiffstats
path: root/installerbuilder
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2011-11-15 12:37:01 +0100
committerKarsten Heimrich <karsten.heimrich@nokia.com>2011-11-15 14:54:00 +0100
commitd48cb97ba1b1179ce314d6ab190a7379f802465a (patch)
tree21ed68e872ef7f1eef8fad1d276786af8ac50348 /installerbuilder
parent2023eb987e50bdf751c444c3a86e36aad72efc5d (diff)
Use QSet throughout the whole code, saves us QList conversions.
Remove default parameter from Repo ctor, lead already to confusion. Also add some more specific {get/set} repo functions, to be able to distinguish between the different kind of repositories (needed for setting dialog). Change-Id: I2c1e4d5377799f54e408a89785bdc5f01619f846 Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com> Reviewed-by: Alexander Lenhardt <alexander.lenhardt@nokia.com>
Diffstat (limited to 'installerbuilder')
-rw-r--r--installerbuilder/common/repository.h2
-rw-r--r--installerbuilder/installerbase/installerbase.cpp15
-rw-r--r--installerbuilder/libinstaller/getrepositoriesmetainfojob.cpp4
-rw-r--r--installerbuilder/libinstaller/getrepositoriesmetainfojob.h6
-rw-r--r--installerbuilder/libinstaller/packagemanagercore.cpp4
-rw-r--r--installerbuilder/libinstaller/packagemanagercore.h4
-rw-r--r--installerbuilder/libinstaller/settings.cpp59
-rw-r--r--installerbuilder/libinstaller/settings.h14
-rw-r--r--installerbuilder/libinstaller/updatesettings.cpp15
-rw-r--r--installerbuilder/libinstaller/updatesettings.h6
10 files changed, 80 insertions, 49 deletions
diff --git a/installerbuilder/common/repository.h b/installerbuilder/common/repository.h
index d6e90d094..a2c77f4e0 100644
--- a/installerbuilder/common/repository.h
+++ b/installerbuilder/common/repository.h
@@ -44,7 +44,7 @@ class INSTALLER_EXPORT Repository
public:
explicit Repository();
Repository(const Repository &other);
- explicit Repository(const QUrl &url, bool isDefault = true);
+ explicit Repository(const QUrl &url, bool isDefault);
bool isValid() const;
bool isDefault() const;
diff --git a/installerbuilder/installerbase/installerbase.cpp b/installerbuilder/installerbase/installerbase.cpp
index f8473021f..ffe739ffe 100644
--- a/installerbuilder/installerbase/installerbase.cpp
+++ b/installerbuilder/installerbase/installerbase.cpp
@@ -65,20 +65,19 @@
using namespace QInstaller;
using namespace QInstallerCreator;
-static QList<Repository> repositories(const QStringList &arguments, const int index)
+static QSet<Repository> repositories(const QStringList &arguments, const int index)
{
- QList<Repository> repoList;
+ QSet<Repository> set;
if (index < arguments.size()) {
QStringList items = arguments.at(index).split(QLatin1Char(','));
foreach (const QString &item, items) {
+ set.insert(Repository(item, false));
verbose() << "Adding custom repository:" << item << std::endl;
- Repository rep(item);
- repoList.append(rep);
}
} else {
std::cerr << "No repository specified" << std::endl;
}
- return repoList;
+ return set;
}
int main(int argc, char *argv[])
@@ -255,7 +254,7 @@ int main(int argc, char *argv[])
} else if (argument == QLatin1String("--addTempRepository")
|| argument == QLatin1String("--setTempRepository")) {
++i;
- QList<Repository> repoList = repositories(args, i);
+ QSet<Repository> repoList = repositories(args, i);
if (repoList.isEmpty())
return PackageManagerCore::Failure;
@@ -265,10 +264,10 @@ int main(int argc, char *argv[])
core.setTemporaryRepositories(repoList, replace);
} else if (argument == QLatin1String("--addRepository")) {
++i;
- QList<Repository> repoList = repositories(args, i);
+ QSet<Repository> repoList = repositories(args, i);
if (repoList.isEmpty())
return PackageManagerCore::Failure;
- core.addRepositories(repoList);
+ core.addUserRepositories(repoList);
} else if (argument == QLatin1String("--no-force-installations")) {
PackageManagerCore::setNoForceInstallation(true);
} else {
diff --git a/installerbuilder/libinstaller/getrepositoriesmetainfojob.cpp b/installerbuilder/libinstaller/getrepositoriesmetainfojob.cpp
index 24a9ef794..88793bf0c 100644
--- a/installerbuilder/libinstaller/getrepositoriesmetainfojob.cpp
+++ b/installerbuilder/libinstaller/getrepositoriesmetainfojob.cpp
@@ -52,12 +52,12 @@ GetRepositoriesMetaInfoJob::GetRepositoriesMetaInfoJob(const QByteArray &publicK
setCapabilities(Cancelable);
}
-QList< Repository > GetRepositoriesMetaInfoJob::repositories() const
+QSet<Repository> GetRepositoriesMetaInfoJob::repositories() const
{
return m_repositories;
}
-void GetRepositoriesMetaInfoJob::setRepositories(const QList<Repository> &repos)
+void GetRepositoriesMetaInfoJob::setRepositories(const QSet<Repository> &repos)
{
m_repositories = repos;
foreach (const Repository &repo, repos) {
diff --git a/installerbuilder/libinstaller/getrepositoriesmetainfojob.h b/installerbuilder/libinstaller/getrepositoriesmetainfojob.h
index 18c5d3985..d57dda39b 100644
--- a/installerbuilder/libinstaller/getrepositoriesmetainfojob.h
+++ b/installerbuilder/libinstaller/getrepositoriesmetainfojob.h
@@ -53,8 +53,8 @@ class INSTALLER_EXPORT GetRepositoriesMetaInfoJob : public KDJob
public:
explicit GetRepositoriesMetaInfoJob(const QByteArray &publicKey, QObject *parent = 0);
- QList<Repository> repositories() const;
- void setRepositories(const QList<Repository> &repositories);
+ QSet<Repository> repositories() const;
+ void setRepositories(const QSet<Repository> &repositories);
QStringList temporaryDirectories() const;
QStringList releaseTemporaryDirectories() const;
@@ -80,7 +80,7 @@ private:
const QByteArray m_publicKey;
bool m_canceled;
int m_silentRetries;
- QList<Repository> m_repositories;
+ QSet<Repository> m_repositories;
QList<Repository> m_tmpRepositories;
QHash<QString, Repository> m_repositoryByTemporaryDirectory;
bool m_haveIgnoredError;
diff --git a/installerbuilder/libinstaller/packagemanagercore.cpp b/installerbuilder/libinstaller/packagemanagercore.cpp
index e6dd6124a..9769b1dbc 100644
--- a/installerbuilder/libinstaller/packagemanagercore.cpp
+++ b/installerbuilder/libinstaller/packagemanagercore.cpp
@@ -737,7 +737,7 @@ bool PackageManagerCore::removeWizardPageItem(Component *component, const QStrin
return false;
}
-void PackageManagerCore::addRepositories(const QList<Repository> &repositories)
+void PackageManagerCore::addUserRepositories(const QSet<Repository> &repositories)
{
d->m_settings.addUserRepositories(repositories);
}
@@ -746,7 +746,7 @@ void PackageManagerCore::addRepositories(const QList<Repository> &repositories)
Sets additional repository for this instance of the installer or updater.
Will be removed after invoking it again.
*/
-void PackageManagerCore::setTemporaryRepositories(const QList<Repository> &repositories, bool replace)
+void PackageManagerCore::setTemporaryRepositories(const QSet<Repository> &repositories, bool replace)
{
d->m_settings.setTemporaryRepositories(repositories, replace);
}
diff --git a/installerbuilder/libinstaller/packagemanagercore.h b/installerbuilder/libinstaller/packagemanagercore.h
index be029c159..d46ff3770 100644
--- a/installerbuilder/libinstaller/packagemanagercore.h
+++ b/installerbuilder/libinstaller/packagemanagercore.h
@@ -128,8 +128,8 @@ public:
bool testChecksum() const;
void setTestChecksum(bool test);
- void addRepositories(const QList<Repository> &repositories);
- void setTemporaryRepositories(const QList<Repository> &repositories, bool replace = false);
+ void addUserRepositories(const QSet<Repository> &repositories);
+ void setTemporaryRepositories(const QSet<Repository> &repositories, bool replace = false);
Q_INVOKABLE void autoAcceptMessageBoxes();
Q_INVOKABLE void autoRejectMessageBoxes();
diff --git a/installerbuilder/libinstaller/settings.cpp b/installerbuilder/libinstaller/settings.cpp
index 956ac2482..2f6caeae7 100644
--- a/installerbuilder/libinstaller/settings.cpp
+++ b/installerbuilder/libinstaller/settings.cpp
@@ -56,6 +56,7 @@ static const QLatin1String scBackground("Background");
static const QLatin1String scAdminTargetDir("AdminTargetDir");
static const QLatin1String scUninstallerName("UninstallerName");
static const QLatin1String scUserRepositories("UserRepositories");
+static const QLatin1String scTmpRepositories("TemporaryRepositories");
static const QLatin1String scUninstallerIniFile("UninstallerIniFile");
static const QLatin1String scRemoteRepositories("RemoteRepositories");
static const QLatin1String scSigningCertificate("SigningCertificate");
@@ -84,7 +85,7 @@ static QString splitTrimmed(const QString &string)
return result.join(QLatin1String("\n"));
}
-static QList<Repository> readRepositories(QXmlStreamReader &reader, bool isDefault)
+static QSet<Repository> readRepositories(QXmlStreamReader &reader, bool isDefault)
{
QSet<Repository> set;
while (reader.readNextStartElement()) {
@@ -107,7 +108,7 @@ static QList<Repository> readRepositories(QXmlStreamReader &reader, bool isDefau
reader.skipCurrentElement();
}
}
- return set.toList();
+ return set;
}
static QVariantHash readTitles(QXmlStreamReader &reader)
@@ -145,7 +146,12 @@ static QHash<QString, QVariantHash> readPages(QXmlStreamReader &reader)
class Settings::Private : public QSharedData
{
public:
+ Private()
+ : m_replacementRepos(false)
+ {}
+
QVariantHash m_data;
+ bool m_replacementRepos;
QString makeAbsolutePath(const QString &path) const
{
@@ -211,11 +217,8 @@ Settings Settings::fromFileAndPrefix(const QString &path, const QString &prefix)
if (name == scSigningCertificate)
s.d->m_data.insertMulti(name, s.d->makeAbsolutePath(reader.readElementText()));
- if (name == scRemoteRepositories) {
- QList<Repository> repositories = readRepositories(reader, true);
- foreach (const Repository &repository, repositories)
- s.d->m_data.insertMulti(scRepositories, QVariant().fromValue(repository));
- }
+ if (name == scRemoteRepositories)
+ s.addDefaultRepositories(readRepositories(reader, true));
if (name == scPages) {
QHash<QString, QVariantHash> pages = readPages(reader);
@@ -369,29 +372,51 @@ QByteArray Settings::publicKey() const
return d->m_data.value(scPublicKey).toByteArray();
}
-QList<Repository> Settings::repositories() const
+bool Settings::hasReplacementRepos() const
+{
+ return d->m_replacementRepos;
+}
+
+QSet<Repository> Settings::repositories() const
{
+ if (d->m_replacementRepos)
+ return variantListToSet<Repository>(d->m_data.values(scTmpRepositories));
+
return variantListToSet<Repository>(d->m_data.values(scRepositories)
- + d->m_data.values(scUserRepositories)).toList();
+ + d->m_data.values(scUserRepositories) + d->m_data.values(scTmpRepositories));
}
-void Settings::setTemporaryRepositories(const QList<Repository> &repositories, bool replace)
+QSet<Repository> Settings::defaultRepositories() const
{
- if (replace)
- d->m_data.remove(scRepositories);
+ return variantListToSet<Repository>(d->m_data.values(scRepositories));
+}
- foreach (const Repository &repository, repositories.toSet())
+void Settings::addDefaultRepositories(const QSet<Repository> &repositories)
+{
+ foreach (const Repository &repository, repositories)
d->m_data.insertMulti(scRepositories, QVariant().fromValue(repository));
}
-QList<Repository> Settings::userRepositories() const
+QSet<Repository> Settings::temporaryRepositories() const
+{
+ return variantListToSet<Repository>(d->m_data.values(scTmpRepositories));
+}
+
+void Settings::setTemporaryRepositories(const QSet<Repository> &repositories, bool replace)
+{
+ d->m_replacementRepos = replace;
+ foreach (const Repository &repository, repositories)
+ d->m_data.insertMulti(scTmpRepositories, QVariant().fromValue(repository));
+}
+
+QSet<Repository> Settings::userRepositories() const
{
- return variantListToSet<Repository>(d->m_data.values(scUserRepositories)).toList();
+ return variantListToSet<Repository>(d->m_data.values(scUserRepositories));
}
-void Settings::addUserRepositories(const QList<Repository> &repositories)
+void Settings::addUserRepositories(const QSet<Repository> &repositories)
{
- foreach (const Repository &repository, repositories.toSet())
+ foreach (const Repository &repository, repositories)
d->m_data.insertMulti(scUserRepositories, QVariant().fromValue(repository));
}
diff --git a/installerbuilder/libinstaller/settings.h b/installerbuilder/libinstaller/settings.h
index 23c28521f..876d20c54 100644
--- a/installerbuilder/libinstaller/settings.h
+++ b/installerbuilder/libinstaller/settings.h
@@ -77,11 +77,17 @@ public:
QString configurationFileName() const;
- QList<Repository> repositories() const;
- void setTemporaryRepositories(const QList<Repository> &repositories, bool replace);
+ bool hasReplacementRepos() const;
+ QSet<Repository> repositories() const;
- QList<Repository> userRepositories() const;
- void addUserRepositories(const QList<Repository> &repositories);
+ QSet<Repository> defaultRepositories() const;
+ void addDefaultRepositories(const QSet<Repository> &repositories);
+
+ QSet<Repository> temporaryRepositories() const;
+ void setTemporaryRepositories(const QSet<Repository> &repositories, bool replace);
+
+ QSet<Repository> userRepositories() const;
+ void addUserRepositories(const QSet<Repository> &repositories);
QStringList certificateFiles() const;
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
diff --git a/installerbuilder/libinstaller/updatesettings.cpp b/installerbuilder/libinstaller/updatesettings.cpp
index 6f52cdd2c..0347beb1d 100644
--- a/installerbuilder/libinstaller/updatesettings.cpp
+++ b/installerbuilder/libinstaller/updatesettings.cpp
@@ -135,22 +135,22 @@ void UpdateSettings::setCheckOnlyImportantUpdates(bool checkOnlyImportantUpdates
d->settings().setValue(QLatin1String("updatesettings/onlyimportant"), checkOnlyImportantUpdates);
}
-QList<Repository> UpdateSettings::repositories() const
+QSet<Repository> UpdateSettings::repositories() const
{
QSettings &settings = *(const_cast<QSettings*> (&d->settings()));
const int count = settings.beginReadArray(QLatin1String("updatesettings/repositories"));
- QList<Repository> result;
+ QSet<Repository> result;
for (int i = 0; i < count; ++i) {
settings.setArrayIndex(i);
- result.append(Repository(d->settings().value(QLatin1String("url")).toUrl()));
+ result.insert(Repository(d->settings().value(QLatin1String("url")).toUrl(), false));
}
settings.endArray();
try {
if(result.isEmpty()) {
result = Settings::fromFileAndPrefix(QLatin1String(":/metadata/installer-config/config.xml"),
- QLatin1String(":/metadata/installer-config/")).repositories();
+ QLatin1String(":/metadata/installer-config/")).userRepositories();
}
} catch (const Error &error) {
qDebug("Could not parse config: %s", qPrintable(error.message()));
@@ -158,12 +158,13 @@ QList<Repository> UpdateSettings::repositories() const
return result;
}
-void UpdateSettings::setRepositories(const QList<Repository> &repositories)
+void UpdateSettings::setRepositories(const QSet<Repository> &repositories)
{
+ QSet<Repository>::ConstIterator it = repositories.constBegin();
d->settings().beginWriteArray(QLatin1String("updatesettings/repositories"));
- for (int i = 0; i < repositories.count(); ++i) {
+ for (int i = 0; i < repositories.count(); ++i, ++it) {
d->settings().setArrayIndex(i);
- d->settings().setValue(QLatin1String("url"), repositories.at(i).url());
+ d->settings().setValue(QLatin1String("url"), (*it).url());
}
d->settings().endArray();
}
diff --git a/installerbuilder/libinstaller/updatesettings.h b/installerbuilder/libinstaller/updatesettings.h
index 0b2f46bd8..490dea838 100644
--- a/installerbuilder/libinstaller/updatesettings.h
+++ b/installerbuilder/libinstaller/updatesettings.h
@@ -31,7 +31,7 @@
QT_BEGIN_NAMESPACE
class QDateTime;
template<typename T>
-class QList;
+class QSet;
class QSettings;
QT_END_NAMESPACE
@@ -65,8 +65,8 @@ public:
bool checkOnlyImportantUpdates() const;
void setCheckOnlyImportantUpdates(bool checkOnlyImportantUpdates);
- QList<Repository> repositories() const;
- void setRepositories(const QList<Repository> &repositories);
+ QSet<Repository> repositories() const;
+ void setRepositories(const QSet<Repository> &repositories);
private:
class Private;