summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-05-04 14:26:18 +0200
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-05-05 10:34:19 +0000
commite0c6df4cecf30626d27e25c8682e3c431eb4dccf (patch)
tree507588511ff95f2f782f9a763499ca2c5f5c0223
parent05d1c5d7b2679d45ac88441a2d23dee50be5ef6c (diff)
Move the UpdateSourcesInfo out of {KDUpdater}Application.
Do not hide the class behind {KDUpdater}Application, we can use it directly. Also remove unused code from the UpdateSourcesInfo class itself. Change-Id: I99cc34e9089da63087892d8d3540522e9f59b2c8 Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp23
-rw-r--r--src/libs/installer/packagemanagercore_p.h2
-rw-r--r--src/libs/kdtools/kdupdaterapplication.cpp55
-rw-r--r--src/libs/kdtools/kdupdaterapplication.h9
-rw-r--r--src/libs/kdtools/kdupdaterupdatefinder.cpp31
-rw-r--r--src/libs/kdtools/kdupdaterupdatefinder.h3
-rw-r--r--src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp352
-rw-r--r--src/libs/kdtools/kdupdaterupdatesourcesinfo.h50
8 files changed, 72 insertions, 453 deletions
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index f7abc955b..b41404307 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -558,7 +558,6 @@ void PackageManagerCorePrivate::initialize(const QHash<QString, QString> &params
disconnect(this, SIGNAL(uninstallationStarted()), ProgressCoordinator::instance(), SLOT(reset()));
connect(this, SIGNAL(uninstallationStarted()), ProgressCoordinator::instance(), SLOT(reset()));
- m_updaterApplication.updateSourcesInfo()->setFileName(QString());
KDUpdater::PackagesInfo &packagesInfo = *m_updaterApplication.packagesInfo();
packagesInfo.setFileName(componentsXmlPath());
@@ -576,9 +575,8 @@ void PackageManagerCorePrivate::initialize(const QHash<QString, QString> &params
if (isInstaller()) {
// TODO: this seems to be wrong, we should ask for ProductName defaulting to applicationName...
- m_updaterApplication.addUpdateSource(m_data.settings().applicationName(),
- m_data.settings().applicationName(), QString(), QUrl(QLatin1String("resource://metadata/")), 0);
- m_updaterApplication.updateSourcesInfo()->setModified(false);
+ m_updateSourcesInfo.addUpdateSource(m_data.settings().applicationName(), m_data.settings()
+ .applicationName(), QString(), QUrl(QLatin1String("resource://metadata/")), 0);
}
m_metadataJob.disconnect();
@@ -2098,6 +2096,7 @@ PackagesList PackageManagerCorePrivate::remotePackages()
m_updateFinder = new KDUpdater::UpdateFinder(&m_updaterApplication);
m_updateFinder->setAutoDelete(false);
+ m_updateFinder->setUpdateSourcesInfo(m_updateSourcesInfo);
m_updateFinder->run();
if (m_updateFinder->updates().isEmpty()) {
@@ -2185,13 +2184,10 @@ bool PackageManagerCorePrivate::addUpdateResourcesFromRepositories(bool parseChe
return m_updateSourcesAdded;
}
- // forces an refresh / clear on all update sources
- m_updaterApplication.updateSourcesInfo()->refresh();
+ m_updateSourcesInfo.clear();
if (isInstaller()) {
- m_updaterApplication.addUpdateSource(m_data.settings().applicationName(),
- m_data.settings().applicationName(), QString(),
- QUrl(QLatin1String("resource://metadata/")), 0);
- m_updaterApplication.updateSourcesInfo()->setModified(false);
+ m_updateSourcesInfo.addUpdateSource(m_data.settings().applicationName(), m_data.settings()
+ .applicationName(), QString(), QUrl(QLatin1String("resource://metadata/")), 0);
}
m_updates = false;
@@ -2231,13 +2227,12 @@ bool PackageManagerCorePrivate::addUpdateResourcesFromRepositories(bool parseChe
if (!checksum.isNull())
m_core->setTestChecksum(checksum.toElement().text().toLower() == scTrue);
}
- m_updaterApplication.addUpdateSource(appName, appName, QString(),
- QUrl::fromLocalFile(data.directory), 1);
+ m_updateSourcesInfo.addUpdateSource(appName, appName, QString(), QUrl::fromLocalFile(data
+ .directory), 1);
ProductKeyCheck::instance()->addPackagesFromXml(data.directory + QLatin1String("/Updates.xml"));
}
- m_updaterApplication.updateSourcesInfo()->setModified(false);
- if (m_updaterApplication.updateSourcesInfo()->updateSourceInfoCount() == 0) {
+ if (m_updateSourcesInfo.updateSourceInfoCount() == 0) {
setStatus(PackageManagerCore::Failure, tr("Could not find any update source information."));
return false;
}
diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h
index d8b7778ac..eb4ec70bc 100644
--- a/src/libs/installer/packagemanagercore_p.h
+++ b/src/libs/installer/packagemanagercore_p.h
@@ -44,6 +44,7 @@
#include "kdsysinfo.h"
#include "kdupdaterapplication.h"
#include "kdupdaterupdatefinder.h"
+#include "kdupdaterupdatesourcesinfo.h"
#include <QObject>
@@ -198,6 +199,7 @@ signals:
public:
UpdateFinder *m_updateFinder;
Application m_updaterApplication;
+ UpdateSourcesInfo m_updateSourcesInfo;
int m_status;
QString m_error;
diff --git a/src/libs/kdtools/kdupdaterapplication.cpp b/src/libs/kdtools/kdupdaterapplication.cpp
index 95c3613da..2621aec96 100644
--- a/src/libs/kdtools/kdupdaterapplication.cpp
+++ b/src/libs/kdtools/kdupdaterapplication.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -34,7 +35,6 @@
#include "kdupdaterapplication.h"
#include "kdupdaterpackagesinfo.h"
-#include "kdupdaterupdatesourcesinfo.h"
#include <QCoreApplication>
#include <QDebug>
@@ -86,7 +86,6 @@ using namespace KDUpdater;
\li Application Directory
\li Installation information XML file name and its corresponding
KDUpdater::PackagesInfo object
- \li Update sources XML file name and its corresponding KDUpdater::UpdateSourcesInfo object
\endlist
User can also retrieve some information from this class:
@@ -100,7 +99,6 @@ struct Application::ApplicationData
{
explicit ApplicationData(ConfigurationInterface *config) :
packagesInfo(0),
- updateSourcesInfo(0),
configurationInterface(config ? config : new ConfigurationInterface)
{
const QStringList oldFiles = configurationInterface->value(QLatin1String("FilesForDelayedDeletion")).toStringList();
@@ -117,7 +115,6 @@ struct Application::ApplicationData
~ApplicationData()
{
delete packagesInfo;
- delete updateSourcesInfo;
delete configurationInterface;
}
@@ -125,7 +122,6 @@ struct Application::ApplicationData
QString applicationDirectory;
PackagesInfo *packagesInfo;
- UpdateSourcesInfo *updateSourcesInfo;
QStringList filesForDelayedDeletion;
ConfigurationInterface *configurationInterface;
};
@@ -139,7 +135,6 @@ Application::Application(ConfigurationInterface* config, QObject* p) : QObject(p
{
d = new Application::ApplicationData( config );
d->packagesInfo = new PackagesInfo(this);
- d->updateSourcesInfo = new UpdateSourcesInfo(this);
setApplicationDirectory( QCoreApplication::applicationDirPath() );
@@ -178,7 +173,6 @@ void Application::setApplicationDirectory(const QString &dir)
// FIXME: Perhaps we should check whether dir exists on the local file system or not
d->applicationDirectory = dirObj.absolutePath();
setPackagesXMLFileName(QString::fromLatin1("%1/Packages.xml").arg(dir));
- setUpdateSourcesXMLFileName(QString::fromLatin1("%1/UpdateSources.xml").arg(dir));
}
/*!
@@ -211,25 +205,6 @@ QString Application::applicationVersion() const
return QString();
}
-/*!
- Adds the \a name, \a title, \a description, \a url, and \a priority of the
- update source to this class.
-
- \sa KDUpdater::UpdateSourceInfo
- \sa KDUpdater::UpdateSourcesInfo
-*/
-void Application::addUpdateSource(const QString &name, const QString &title,
- const QString &description, const QUrl &url, int priority)
-{
- UpdateSourceInfo info;
- info.name = name;
- info.title = title;
- info.description = description;
- info.url = url;
- info.priority = priority;
- d->updateSourcesInfo->addUpdateSourceInfo(info);
-}
-
/*!
Sets the file name of the installation information XML file for this application to \a fileName.
@@ -259,34 +234,6 @@ PackagesInfo* Application::packagesInfo() const
}
/*!
- Sets \a fileName as the file name of the update sources XML file for this
- application. By default, this is assumed to be UpdateSources.xml in the
- application directory.
-
- \sa KDUpdater::UpdateSourcesInfo::setFileName()
-*/
-void Application::setUpdateSourcesXMLFileName(const QString &fileName)
-{
- d->updateSourcesInfo->setFileName(fileName);
-}
-
-/*!
- Returns the update sources XML file name.
-*/
-QString Application::updateSourcesXMLFileName() const
-{
- return d->updateSourcesInfo->fileName();
-}
-
-/*!
- Returns the KDUpdater::UpdateSourcesInfo object associated with this application.
-*/
-UpdateSourcesInfo* Application::updateSourcesInfo() const
-{
- return d->updateSourcesInfo;
-}
-
-/*!
Prints the error code \a errorCode and error message specified by \a error.
*/
void Application::printError(int errorCode, const QString &error)
diff --git a/src/libs/kdtools/kdupdaterapplication.h b/src/libs/kdtools/kdupdaterapplication.h
index fec066880..72ce69688 100644
--- a/src/libs/kdtools/kdupdaterapplication.h
+++ b/src/libs/kdtools/kdupdaterapplication.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -42,7 +43,6 @@
namespace KDUpdater {
class PackagesInfo;
-class UpdateSourcesInfo;
class ConfigurationInterface
{
@@ -83,13 +83,6 @@ public:
QString packagesXMLFileName() const;
PackagesInfo *packagesInfo() const;
- void addUpdateSource(const QString &name, const QString &title,
- const QString &description, const QUrl &url, int priority = -1);
-
- void setUpdateSourcesXMLFileName(const QString &fileName);
- QString updateSourcesXMLFileName() const;
- UpdateSourcesInfo *updateSourcesInfo() const;
-
QStringList filesForDelayedDeletion() const;
void addFilesForDelayedDeletion(const QStringList &files);
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.cpp b/src/libs/kdtools/kdupdaterupdatefinder.cpp
index 21f6f86a5..778195646 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.cpp
+++ b/src/libs/kdtools/kdupdaterupdatefinder.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -56,8 +57,8 @@ using namespace KDUpdater;
The KDUpdater::UpdateFinder class helps in searching for updates and installing them on the
application. The class basically processes the application's KDUpdater::PackagesInfo and the
- UpdateXMLs it aggregates from all the update sources described in KDUpdater::UpdateSourcesInfo
- and populates a list of KDUpdater::Update objects.
+ UpdateXMLs it aggregates from all the update sources and populates a list of KDUpdater::Update
+ objects.
*/
//
@@ -113,6 +114,8 @@ public:
void createUpdateObjects(const UpdateSourceInfo &sourceInfo, const QList<UpdateInfo> &updateInfoList);
Resolution checkPriorityAndVersion(const UpdateSourceInfo &sourceInfo, const QVariantHash &data) const;
void slotDownloadDone();
+
+ UpdateSourcesInfo m_updateSourcesInfo;
};
@@ -188,13 +191,8 @@ void UpdateFinder::Private::computeUpdates()
}
// Now do some quick sanity checks on the update sources info
- UpdateSourcesInfo *sources = application->updateSourcesInfo();
- if (!sources) {
- q->reportError(tr("Could not access the update sources information of this application."));
- return;
- }
- if (!sources->isValid()) {
- q->reportError(sources->errorString());
+ if (m_updateSourcesInfo.updateSourceInfoCount() <= 0) {
+ q->reportError(tr("No update sources information set for this application."));
return;
}
@@ -250,13 +248,12 @@ bool UpdateFinder::Private::downloadUpdateXMLFiles()
if (!application)
return false;
- UpdateSourcesInfo *updateSources = application->updateSourcesInfo();
- if (!updateSources )
+ if (m_updateSourcesInfo.updateSourceInfoCount() <= 0)
return false;
// create UpdatesInfo for each update source
- for (int i = 0; i < updateSources->updateSourceInfoCount(); i++) {
- const UpdateSourceInfo info = updateSources->updateSourceInfo(i);
+ for (int i = 0; i < m_updateSourcesInfo.updateSourceInfoCount(); i++) {
+ const UpdateSourceInfo info = m_updateSourcesInfo.updateSourceInfo(i);
const QUrl url = QString::fromLatin1("%1/Updates.xml").arg(info.url.toString());
if (url.scheme() != QLatin1String("resource") && url.scheme() != QLatin1String("file")) {
@@ -488,6 +485,14 @@ QList<Update *> UpdateFinder::updates() const
}
/*!
+ Sets the update sources information to use when searching for updates.
+*/
+void UpdateFinder::setUpdateSourcesInfo(const UpdateSourcesInfo &sources)
+{
+ d->m_updateSourcesInfo = sources;
+}
+
+/*!
\internal
Implemented from KDUpdater::Task::doRun().
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.h b/src/libs/kdtools/kdupdaterupdatefinder.h
index c94b0cd98..77b055394 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.h
+++ b/src/libs/kdtools/kdupdaterupdatefinder.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -41,6 +42,7 @@ namespace KDUpdater {
class Application;
class Update;
+class UpdateSourcesInfo;
class KDTOOLS_EXPORT UpdateFinder : public Task
{
@@ -52,6 +54,7 @@ public:
~UpdateFinder();
QList<Update *> updates() const;
+ void setUpdateSourcesInfo(const UpdateSourcesInfo &sources);
private:
void doRun();
diff --git a/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
index 25b20c256..6125fc3e5 100644
--- a/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
+++ b/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -34,15 +35,7 @@
#include "kdupdaterupdatesourcesinfo.h"
-#include <QtXml/QDomElement>
-#include <QtXml/QDomDocument>
-#include <QtXml/QDomText>
-#include <QtXml/QDomCDATASection>
-#include <QFileInfo>
-#include <QFile>
-#include <QTextStream>
-
-using namespace KDUpdater;
+namespace KDUpdater {
/*!
\inmodule kdupdater
@@ -54,12 +47,8 @@ using namespace KDUpdater;
Applications can download updates from the update source and install them locally.
Each application can have one or more update sources from which it can download updates.
- Information about update source is stored in a file called UpdateSources.xml. This class helps
- access and modify the UpdateSources.xml file.
- The complete file name of the UpdateSources.xml file can be specified via the setFileName()
- method. The class then parses the XML file and makes available information contained in
- that XML file through an easy to use API. You can:
+ The class makes the information available through an easy to use API. You can:
\list
\li Get update sources information via the updateSourceInfoCount() and updateSourceInfo()
@@ -67,8 +56,6 @@ using namespace KDUpdater;
\li Add or remove update source information via the addUpdateSourceInfo() and
removeUpdateSourceInfo() methods.
\endlist
-
- The class emits appropriate signals to inform listeners about changes in the update application.
*/
/*!
@@ -83,42 +70,7 @@ using namespace KDUpdater;
Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false.
*/
-/*!
- \enum UpdateSourcesInfo::Error
- Error codes related to retrieving update sources.
-
- \value NoError No error occurred.
- \value NotYetReadError The update source information was not parsed yet from the
- XML file.
- \value CouldNotReadSourceFileError The specified update source file could not be read
- (does not exist or is not readable).
- \value InvalidXmlError The source file contains invalid XML.
- \value InvalidContentError The source file contains valid XML, but does not match the
- expected format for source descriptions.
- \value CouldNotSaveChangesError Changes made to the object could not be saved back to the
- source file.
-*/
-
-/*!
- \fn void UpdateSourcesInfo::reset()
-
- This signal is emitted whenever the contents of this UpdateSourcesInfo are refreshed, usually
- from within the refresh() slot.
-*/
-
-/*!
- \fn void UpdateSourcesInfo::updateSourceInfoAdded(const UpdateSourceInfo &info)
-
- This signal is emitted when \c UpdateSourceInfo \a info is added.
-*/
-
-/*!
- \fn void UpdateSourcesInfo::updateSourceInfoRemoved(const UpdateSourceInfo &info)
-
- This signal is emitted when \c UpdateSourceInfo \a info is removed.
-*/
-
-struct UpdateSourceInfoPriorityHigherThan
+struct PriorityHigherThan
{
bool operator()(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs) const
{
@@ -126,131 +78,12 @@ struct UpdateSourceInfoPriorityHigherThan
}
};
-
-struct UpdateSourcesInfo::UpdateSourcesInfoData
-{
- UpdateSourcesInfoData()
- : modified(false)
- , error(UpdateSourcesInfo::NotYetReadError)
- {}
-
- bool modified;
- UpdateSourcesInfo::Error error;
-
- QString fileName;
- QString errorMessage;
- QList<UpdateSourceInfo> updateSourceInfoList;
-
- void addUpdateSourceFrom(const QDomElement &element);
- void addChildElement(QDomDocument &doc, QDomElement &parentE, const QString &tagName,
- const QString &text, bool htmlText = false);
- void setInvalidContentError(const QString &detail);
- void clearError();
- void saveChanges();
-};
-
-void UpdateSourcesInfo::UpdateSourcesInfoData::setInvalidContentError(const QString &detail)
-{
- error = UpdateSourcesInfo::InvalidContentError;
- errorMessage = tr("%1 contains invalid content: %2").arg(fileName, detail);
-}
-
-void UpdateSourcesInfo::UpdateSourcesInfoData::clearError()
-{
- error = UpdateSourcesInfo::NoError;
- errorMessage.clear();
-}
-
-/*!
- \internal
-*/
-UpdateSourcesInfo::UpdateSourcesInfo(QObject *parent)
- : QObject(parent)
- , d(new UpdateSourcesInfo::UpdateSourcesInfoData)
-{
-}
-
-/*!
- \internal
-*/
-UpdateSourcesInfo::~UpdateSourcesInfo()
-{
- d->saveChanges();
-}
-
-/*!
- Returns \c true if UpdateSourcesInfo is valid; otherwise returns \c false.
- You can use the errorString() method to receive a descriptive error message.
-*/
-bool UpdateSourcesInfo::isValid() const
-{
- return d->error == NoError;
-}
-
-/*!
- Returns a human-readable description of the last error that occurred.
-*/
-QString UpdateSourcesInfo::errorString() const
-{
- return d->errorMessage;
-}
-
-/*!
- Returns the error that was found during the processing of the update sources XML file. If no
- error was found, returns NoError.
-*/
-UpdateSourcesInfo::Error UpdateSourcesInfo::error() const
-{
- return d->error;
-}
-
-/*!
- Returns the modified state of this object. The modified state defines if there where
- modifications done to the update-sources that need to be written to the updates XML file
- that will restore the update-sources on the next run.
-*/
-bool UpdateSourcesInfo::isModified() const
-{
- return d->modified;
-}
-
-/*!
- Sets the modified state of the object to \a modified.
-*/
-void UpdateSourcesInfo::setModified(bool modified)
-{
- d->modified = modified;
-}
-
-/*!
- Sets the complete file name of the update sources XML file to \a fileName. The function also
- issues a call to refresh() to reload update sources from the XML file.
-
- \sa KDUpdater::Application::setUpdateSourcesXMLFileName()
-*/
-void UpdateSourcesInfo::setFileName(const QString &fileName)
-{
- if (d->fileName == fileName)
- return;
-
- d->fileName = fileName;
- refresh(); // load new file
-}
-
-/*!
- Returns the name of the update sources XML file that this class refers to.
-*/
-QString UpdateSourcesInfo::fileName() const
-{
- return d->fileName;
-}
-
/*!
Returns the number of update source info structures contained in this class.
*/
int UpdateSourcesInfo::updateSourceInfoCount() const
{
- return d->updateSourceInfoList.count();
+ return m_updateSourceInfoList.count();
}
/*!
@@ -259,173 +92,52 @@ int UpdateSourcesInfo::updateSourceInfoCount() const
*/
UpdateSourceInfo UpdateSourcesInfo::updateSourceInfo(int index) const
{
- if (index < 0 || index >= d->updateSourceInfoList.count())
- return UpdateSourceInfo();
-
- return d->updateSourceInfoList[index];
+ return m_updateSourceInfoList.value(index);
}
/*!
- Adds the given update source info \a info to this class. Upon successful addition, the class
- emits an updateSourceInfoAdded() signal.
+ Adds the given update source info \a info to this class.
*/
void UpdateSourcesInfo::addUpdateSourceInfo(const UpdateSourceInfo &info)
{
- if (d->updateSourceInfoList.contains(info))
+ if (m_updateSourceInfoList.contains(info))
return;
- d->updateSourceInfoList.push_back(info);
- std::sort(d->updateSourceInfoList.begin(), d->updateSourceInfoList.end(), UpdateSourceInfoPriorityHigherThan());
- emit updateSourceInfoAdded(info);
- d->modified = true;
+ m_updateSourceInfoList.append(info);
+ std::sort(m_updateSourceInfoList.begin(), m_updateSourceInfoList.end(), PriorityHigherThan());
}
/*!
- Removes the given update source info \a info from this class. Upon successful removal, the class
- emits an updateSourceInfoRemoved() signal.
+ \overload
+
+ Adds a new update source with \a name, \a title, \a description, \a url, and \a priority to
+ this class.
*/
-void UpdateSourcesInfo::removeUpdateSourceInfo(const UpdateSourceInfo &info)
+void UpdateSourcesInfo::addUpdateSource(const QString &name, const QString &title,
+ const QString &description, const QUrl &url, int priority)
{
- if (!d->updateSourceInfoList.contains(info))
- return;
- d->updateSourceInfoList.removeAll(info);
- emit updateSourceInfoRemoved(info);
- d->modified = true;
+ UpdateSourceInfo info;
+ info.name = name;
+ info.title = title;
+ info.description = description;
+ info.url = url;
+ info.priority = priority;
+ addUpdateSourceInfo(info);
}
/*!
- Reloads the update source information from update sources XML file.
+ Removes the given update source info \a info from this class.
*/
-void UpdateSourcesInfo::refresh()
-{
- d->saveChanges(); // save changes done in the previous file
- d->updateSourceInfoList.clear();
-
- QFile file(d->fileName);
-
- // if the file does not exist then we just skip the reading
- if (!file.exists()) {
- d->clearError();
- emit reset();
- return;
- }
-
- // Open the XML file
- if (!file.open(QFile::ReadOnly)) {
- d->errorMessage = tr("Could not read \"%1\"").arg(d->fileName);
- d->error = CouldNotReadSourceFileError;
- emit reset();
- return;
- }
-
- QDomDocument doc;
- QString parseErrorMessage;
- int parseErrorLine, parseErrorColumn;
- if (!doc.setContent(&file, &parseErrorMessage, &parseErrorLine, &parseErrorColumn)) {
- d->error = InvalidXmlError;
- d->errorMessage = tr("XML Parse error in %1 at %2, %3: %4").arg(d->fileName,
- QString::number(parseErrorLine), QString::number(parseErrorColumn), parseErrorMessage);
- emit reset();
- return;
- }
-
- // Now parse the XML file.
- const QDomElement rootE = doc.documentElement();
- if (rootE.tagName() != QLatin1String("UpdateSources")) {
- d->setInvalidContentError(tr("Root element %1 unexpected, should be \"UpdateSources\"").arg(rootE.tagName()));
- emit reset();
- return;
- }
-
- const QDomNodeList childNodes = rootE.childNodes();
- for (int i = 0; i < childNodes.count(); i++) {
- QDomElement childNodeE = childNodes.item(i).toElement();
- if ((!childNodeE.isNull()) && (childNodeE.tagName() == QLatin1String("UpdateSource")))
- d->addUpdateSourceFrom(childNodeE);
- }
-
- d->clearError();
- emit reset();
-}
-
-void UpdateSourcesInfo::UpdateSourcesInfoData::saveChanges()
-{
- if (!modified || fileName.isEmpty())
- return;
-
- const bool hadSaveError = (error == UpdateSourcesInfo::CouldNotSaveChangesError);
-
- QDomDocument doc;
- QDomElement rootE = doc.createElement(QLatin1String("UpdateSources"));
- doc.appendChild(rootE);
-
- foreach (const UpdateSourceInfo &info, updateSourceInfoList) {
- QDomElement infoE = doc.createElement(QLatin1String("UpdateSource"));
- rootE.appendChild(infoE);
- addChildElement(doc, infoE, QLatin1String("Name"), info.name);
- addChildElement(doc, infoE, QLatin1String("Title"), info.title);
- addChildElement(doc, infoE, QLatin1String("Description"), info.description,
- (info.description.length() && info.description.at(0) == QLatin1Char('<')));
- addChildElement(doc, infoE, QLatin1String("Url"), info.url.toString());
- }
-
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly)) {
- error = UpdateSourcesInfo::CouldNotSaveChangesError;
- errorMessage = tr("Could not save changes to \"%1\": %2").arg(fileName, file.errorString());
- return;
- }
-
- QTextStream stream(&file);
- doc.save(stream, 2);
- stream.flush();
- file.close();
-
- if (file.error() != QFile::NoError) {
- error = UpdateSourcesInfo::CouldNotSaveChangesError;
- errorMessage = tr("Could not save changes to \"%1\": %2").arg(fileName, file.errorString());
- return;
- }
-
- //if there was a write error before, clear the error, as the write was successful now
- if (hadSaveError)
- clearError();
-
- modified = false;
-}
-
-void UpdateSourcesInfo::UpdateSourcesInfoData::addUpdateSourceFrom(const QDomElement &element)
+void UpdateSourcesInfo::removeUpdateSourceInfo(const UpdateSourceInfo &info)
{
- if (element.tagName() != QLatin1String("UpdateSource"))
- return;
-
- const QDomNodeList childNodes = element.childNodes();
- if (!childNodes.count())
- return;
-
- UpdateSourceInfo info;
- for (int i = 0; i < childNodes.count(); ++i) {
- const QDomElement childNodeE = childNodes.item(i).toElement();
- if (childNodeE.isNull())
- continue;
-
- if (childNodeE.tagName() == QLatin1String("Name"))
- info.name = childNodeE.text();
- else if (childNodeE.tagName() == QLatin1String("Title"))
- info.title = childNodeE.text();
- else if (childNodeE.tagName() == QLatin1String("Description"))
- info.description = childNodeE.text();
- else if (childNodeE.tagName() == QLatin1String("Url"))
- info.url = childNodeE.text();
- }
- this->updateSourceInfoList.append(info);
+ m_updateSourceInfoList.removeAll(info);
}
-void UpdateSourcesInfo::UpdateSourcesInfoData::addChildElement(QDomDocument &doc, QDomElement &parentE,
- const QString &tagName, const QString &text, bool htmlText)
+/*!
+ Clears the update source information this class holds.
+*/
+void UpdateSourcesInfo::clear()
{
- QDomElement childE = doc.createElement(tagName);
- parentE.appendChild(childE);
- childE.appendChild(htmlText ? doc.createCDATASection(text) : doc.createTextNode(text));
+ m_updateSourceInfoList.clear();
}
/*!
@@ -470,8 +182,6 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::addChildElement(QDomDocument &doc
\brief The priority of the update source.
*/
-namespace KDUpdater {
-
bool operator== (const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
{
return lhs.name == rhs.name && lhs.title == rhs.title && lhs.description == rhs.description
diff --git a/src/libs/kdtools/kdupdaterupdatesourcesinfo.h b/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
index d0207de63..cc483a370 100644
--- a/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
+++ b/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -37,8 +38,6 @@
#include "kdtoolsglobal.h"
-#include <QObject>
-#include <QVariant>
#include <QUrl>
namespace KDUpdater {
@@ -61,58 +60,23 @@ inline bool operator!=(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
return !operator==(lhs, rhs);
}
-class KDTOOLS_EXPORT UpdateSourcesInfo : public QObject
+class KDTOOLS_EXPORT UpdateSourcesInfo
{
- Q_OBJECT
-
public:
- ~UpdateSourcesInfo();
-
- enum Error
- {
- NoError = 0,
- NotYetReadError,
- CouldNotReadSourceFileError,
- InvalidXmlError,
- InvalidContentError,
- CouldNotSaveChangesError
- };
-
- bool isValid() const;
- QString errorString() const;
- Error error() const;
-
- bool isModified() const;
- void setModified(bool modified);
-
- void setFileName(const QString &fileName);
- QString fileName() const;
-
int updateSourceInfoCount() const;
UpdateSourceInfo updateSourceInfo(int index) const;
void addUpdateSourceInfo(const UpdateSourceInfo &info);
- void removeUpdateSourceInfo(const UpdateSourceInfo &info);
-
-protected:
- friend class Application;
- explicit UpdateSourcesInfo(QObject *parent = 0);
-
-public Q_SLOTS:
- void refresh();
+ void addUpdateSource(const QString &name, const QString &title,
+ const QString &description, const QUrl &url, int priority);
-Q_SIGNALS:
- void reset();
- void updateSourceInfoAdded(const UpdateSourceInfo &info);
- void updateSourceInfoRemoved(const UpdateSourceInfo &info);
+ void clear();
+ void removeUpdateSourceInfo(const UpdateSourceInfo &info);
private:
- struct UpdateSourcesInfoData;
- QScopedPointer<UpdateSourcesInfoData> d;
+ QList<UpdateSourceInfo> m_updateSourceInfoList;
};
} // namespace KDUpdater
-Q_DECLARE_METATYPE(KDUpdater::UpdateSourceInfo)
-
#endif // KD_UPDATER_UPDATE_SOURCES_INFO_H