summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libs/installer/component.cpp7
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp1
-rw-r--r--src/libs/kdtools/kdupdater.h12
-rw-r--r--src/libs/kdtools/kdupdaterapplication.cpp43
-rw-r--r--src/libs/kdtools/kdupdaterapplication.h25
-rw-r--r--src/libs/kdtools/kdupdaterpackagesinfo.cpp40
-rw-r--r--src/libs/kdtools/kdupdaterpackagesinfo.h13
-rw-r--r--src/libs/kdtools/kdupdaterupdate.cpp265
-rw-r--r--src/libs/kdtools/kdupdaterupdate.h57
-rw-r--r--src/libs/kdtools/kdupdaterupdatefinder.cpp350
-rw-r--r--src/libs/kdtools/kdupdaterupdatefinder.h19
-rw-r--r--src/libs/kdtools/kdupdaterupdateoperation.cpp20
-rw-r--r--src/libs/kdtools/kdupdaterupdateoperation.h5
-rw-r--r--src/libs/kdtools/kdupdaterupdateoperationfactory.cpp3
-rw-r--r--src/libs/kdtools/kdupdaterupdateoperations.cpp475
-rw-r--r--src/libs/kdtools/kdupdaterupdateoperations.h54
-rw-r--r--src/libs/kdtools/kdupdaterupdatesinfo.cpp149
-rw-r--r--src/libs/kdtools/kdupdaterupdatesinfo_p.h26
-rw-r--r--src/libs/kdtools/kdupdaterupdatesinfodata_p.h2
-rw-r--r--src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp153
-rw-r--r--src/libs/kdtools/kdupdaterupdatesourcesinfo.h16
-rw-r--r--tests/auto/installer/componentmodel/tst_componentmodel.cpp2
22 files changed, 261 insertions, 1476 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp
index 0ff4d07d6..e32219d72 100644
--- a/src/libs/installer/component.cpp
+++ b/src/libs/installer/component.cpp
@@ -268,15 +268,14 @@ void Component::loadDataFromPackage(const LocalPackage &package)
void Component::loadDataFromPackage(const Package &package)
{
Q_ASSERT(&package);
- Q_ASSERT(!package.name().isEmpty());
setValue(scName, package.data(scName).toString());
setValue(scDisplayName, package.data(scDisplayName).toString());
setValue(scDescription, package.data(scDescription).toString());
setValue(scDefault, package.data(scDefault).toString());
setValue(scAutoDependOn, package.data(scAutoDependOn).toString());
- setValue(scCompressedSize, QString::number(package.compressedSize()));
- setValue(scUncompressedSize, QString::number(package.uncompressedSize()));
+ setValue(scCompressedSize, QString::number(0));
+ setValue(scUncompressedSize, QString::number(0));
setValue(scRemoteVersion, package.data(scRemoteVersion).toString());
setValue(scInheritVersion, package.data(scInheritVersion).toString());
setValue(scDependencies, package.data(scDependencies).toString());
@@ -303,7 +302,7 @@ void Component::loadDataFromPackage(const Package &package)
setCheckState(Qt::Checked);
}
- setLocalTempPath(QInstaller::pathFromUrl(package.sourceInfo().url));
+ setLocalTempPath(QInstaller::pathFromUrl(package.sourceInfoUrl()));
const QStringList uis = package.data(QLatin1String("UserInterfaces")).toString()
.split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
if (!uis.isEmpty())
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index b1f0dd511..652ecb88a 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -2054,7 +2054,6 @@ PackagesList PackageManagerCorePrivate::remotePackages()
m_updateFinder = new KDUpdater::UpdateFinder(&m_updaterApplication);
m_updateFinder->setAutoDelete(false);
- m_updateFinder->setUpdateType(KDUpdater::PackageUpdate | KDUpdater::NewPackage);
m_updateFinder->run();
if (m_updateFinder->updates().isEmpty()) {
diff --git a/src/libs/kdtools/kdupdater.h b/src/libs/kdtools/kdupdater.h
index f28461d9b..8028049ea 100644
--- a/src/libs/kdtools/kdupdater.h
+++ b/src/libs/kdtools/kdupdater.h
@@ -23,7 +23,7 @@
#ifndef KD_UPDATER_H
#define KD_UPDATER_H
-#include <kdtoolsglobal.h>
+#include "kdtoolsglobal.h"
namespace KDUpdater
{
@@ -36,16 +36,6 @@ namespace KDUpdater
ECannotStopTask,
EUnknown
};
-
- enum UpdateType {
- PackageUpdate = 0x1,
- CompatUpdate = 0x2,
- NewPackage = 0x4,
- AllUpdate = PackageUpdate | CompatUpdate
- };
- Q_DECLARE_FLAGS( UpdateTypes, UpdateType )
- Q_DECLARE_OPERATORS_FOR_FLAGS( UpdateTypes )
-
KDTOOLS_EXPORT int compareVersion(const QString &v1, const QString &v2);
}
diff --git a/src/libs/kdtools/kdupdaterapplication.cpp b/src/libs/kdtools/kdupdaterapplication.cpp
index 352c33ca8..a72c16072 100644
--- a/src/libs/kdtools/kdupdaterapplication.cpp
+++ b/src/libs/kdtools/kdupdaterapplication.cpp
@@ -27,7 +27,6 @@
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
-#include <QSettings>
using namespace KDUpdater;
@@ -55,32 +54,6 @@ medium-to-large scale software systems.
\namespace KDUpdater
*/
-ConfigurationInterface::~ConfigurationInterface()
-{
-}
-
-namespace {
-
-class DefaultConfigImpl : public ConfigurationInterface
-{
-public:
- QVariant value(const QString &key) const
- {
- QSettings settings;
- settings.beginGroup(QLatin1String("KDUpdater"));
- return settings.value(key);
- }
-
- void setValue(const QString &key, const QVariant &value)
- {
- QSettings settings;
- settings.beginGroup(QLatin1String("KDUpdater"));
- settings.setValue(key, value);
- }
-};
-
-} // namespace anon
-
/*!
\class KDUpdater::Application kdupdaterapplication.h KDUpdaterApplication
\ingroup kdupdater
@@ -95,7 +68,6 @@ public:
User can also retrieve some information from this class:
\li application name
\li application version
- \li compat level
*/
struct Application::ApplicationData
@@ -103,7 +75,7 @@ struct Application::ApplicationData
explicit ApplicationData(ConfigurationInterface *config) :
packagesInfo(0),
updateSourcesInfo(0),
- configurationInterface(config ? config : new DefaultConfigImpl)
+ configurationInterface(config ? config : new ConfigurationInterface)
{
const QStringList oldFiles = configurationInterface->value(QLatin1String("FilesForDelayedDeletion")).toStringList();
Q_FOREACH(const QString &i, oldFiles) { //TODO this should happen asnyc and report errors, I guess
@@ -161,7 +133,7 @@ Application::~Application()
}
/*!
- Returns a previousle created Application instance.
+ Returns a previously created Application instance.
*/
Application *Application::instance()
{
@@ -215,17 +187,6 @@ QString Application::applicationVersion() const
return QString();
}
-/*!
- Returns the compat level that this application is in.
-*/
-int Application::compatLevel() const
-{
- if (d->packagesInfo->isValid())
- return d->packagesInfo->compatLevel();
-
- return -1;
-}
-
void Application::addUpdateSource(const QString &name, const QString &title,
const QString &description, const QUrl &url, int priority)
{
diff --git a/src/libs/kdtools/kdupdaterapplication.h b/src/libs/kdtools/kdupdaterapplication.h
index f1ca9d612..11a35a1b2 100644
--- a/src/libs/kdtools/kdupdaterapplication.h
+++ b/src/libs/kdtools/kdupdaterapplication.h
@@ -23,12 +23,9 @@
#ifndef KD_UPDATER_APPLICATION_H
#define KD_UPDATER_APPLICATION_H
-#include "kdupdater.h"
-#include <QObject>
+#include "kdtoolsglobal.h"
-QT_BEGIN_NAMESPACE
-class QUrl;
-QT_END_NAMESPACE
+#include <QSettings>
namespace KDUpdater {
@@ -38,9 +35,20 @@ class UpdateSourcesInfo;
class ConfigurationInterface
{
public:
- virtual ~ConfigurationInterface();
- virtual QVariant value(const QString &key ) const = 0;
- virtual void setValue(const QString &key, const QVariant &value) = 0;
+ virtual ~ConfigurationInterface() {}
+ virtual QVariant value(const QString &key) const
+ {
+ QSettings settings;
+ settings.beginGroup(QLatin1String("KDUpdater"));
+ return settings.value(key);
+ }
+
+ virtual void setValue(const QString &key, const QVariant &value)
+ {
+ QSettings settings;
+ settings.beginGroup(QLatin1String("KDUpdater"));
+ settings.setValue(key, value);
+ }
};
class KDTOOLS_EXPORT Application : public QObject
@@ -58,7 +66,6 @@ public:
QString applicationName() const;
QString applicationVersion() const;
- int compatLevel() const;
void setPackagesXMLFileName(const QString &fileName);
QString packagesXMLFileName() const;
diff --git a/src/libs/kdtools/kdupdaterpackagesinfo.cpp b/src/libs/kdtools/kdupdaterpackagesinfo.cpp
index 142cf67b0..dc87c6271 100644
--- a/src/libs/kdtools/kdupdaterpackagesinfo.cpp
+++ b/src/libs/kdtools/kdupdaterpackagesinfo.cpp
@@ -20,7 +20,6 @@
**
**********************************************************************/
#include "kdupdaterpackagesinfo.h"
-#include "kdupdaterapplication.h"
#include "globals.h"
#include <QFileInfo>
@@ -76,18 +75,14 @@ using namespace KDUpdater;
struct PackagesInfo::PackagesInfoData
{
PackagesInfoData() :
- application(0),
error(PackagesInfo::NotYetReadError),
- compatLevel(-1),
modified(false)
{}
- Application *application;
QString errorMessage;
PackagesInfo::Error error;
QString fileName;
QString applicationName;
QString applicationVersion;
- int compatLevel;
bool modified;
QVector<PackageInfo> packageInfoList;
@@ -105,11 +100,10 @@ void PackagesInfo::PackagesInfoData::setInvalidContentError(const QString &detai
/*!
\internal
*/
-PackagesInfo::PackagesInfo(Application *application)
- : QObject(application),
+PackagesInfo::PackagesInfo(QObject *parent)
+ : QObject(parent),
d(new PackagesInfoData())
{
- d->application = application;
}
/*!
@@ -122,15 +116,6 @@ PackagesInfo::~PackagesInfo()
}
/*!
- Returns a pointer to the application, whose package information this class provides
- access to.
-*/
-Application *PackagesInfo::application() const
-{
- return d->application;
-}
-
-/*!
Returns true if the PackagesInfo are valid else false is returned in which case
the \a errorString() method can be used to receive a describing error message.
*/
@@ -234,14 +219,6 @@ PackageInfo PackagesInfo::packageInfo(int index) const
}
/*!
- Returns the compat level of the application.
-*/
-int PackagesInfo::compatLevel() const
-{
- return d->compatLevel;
-}
-
-/*!
This function returns the index of the package whose name is \c pkgName. If no such
package was found, this function returns -1.
*/
@@ -332,8 +309,6 @@ void PackagesInfo::refresh()
d->applicationVersion = childNodeE.text();
else if (childNodeE.tagName() == QLatin1String("Package"))
d->addPackageFrom(childNodeE);
- else if (childNodeE.tagName() == QLatin1String("CompatLevel"))
- d->compatLevel = childNodeE.text().toInt();
}
d->error = NoError;
@@ -342,15 +317,6 @@ void PackagesInfo::refresh()
}
/*!
- Sets the application compat level.
-*/
-void PackagesInfo::setCompatLevel(int level)
-{
- d->compatLevel = level;
- d->modified = true;
-}
-
-/*!
Marks the package with \a name as installed in \a version.
*/
bool PackagesInfo::installPackage(const QString &name, const QString &version,
@@ -434,8 +400,6 @@ void PackagesInfo::writeToDisk()
addTextChildHelper(&root, QLatin1String("ApplicationName"), d->applicationName);
addTextChildHelper(&root, QLatin1String("ApplicationVersion"), d->applicationVersion);
- if (d->compatLevel != -1)
- addTextChildHelper(&root, QLatin1String( "CompatLevel" ), QString::number(d->compatLevel));
Q_FOREACH (const PackageInfo &info, d->packageInfoList) {
QDomElement package = doc.createElement(QLatin1String("Package"));
diff --git a/src/libs/kdtools/kdupdaterpackagesinfo.h b/src/libs/kdtools/kdupdaterpackagesinfo.h
index a70a70568..3b60f9839 100644
--- a/src/libs/kdtools/kdupdaterpackagesinfo.h
+++ b/src/libs/kdtools/kdupdaterpackagesinfo.h
@@ -33,9 +33,6 @@
namespace KDUpdater {
-class Application;
-class UpdateInstaller;
-
struct KDTOOLS_EXPORT PackageInfo
{
QString name;
@@ -69,8 +66,6 @@ public:
InvalidContentError
};
- Application *application() const;
-
bool isValid() const;
QString errorString() const;
Error error() const;
@@ -91,9 +86,6 @@ public:
QVector<KDUpdater::PackageInfo> packageInfos() const;
void writeToDisk();
- int compatLevel() const;
- void setCompatLevel(int level);
-
bool installPackage(const QString &pkgName, const QString &version, const QString &title = QString(),
const QString &description = QString(), const QStringList &dependencies = QStringList(),
bool forcedInstallation = false, bool virtualComp = false, quint64 uncompressedSize = 0,
@@ -109,11 +101,10 @@ Q_SIGNALS:
void reset();
protected:
- explicit PackagesInfo(Application *application = 0);
+ friend class Application;
+ explicit PackagesInfo(QObject *parent = 0);
private:
- friend class Application;
- friend class UpdateInstaller;
struct PackagesInfoData;
PackagesInfoData *d;
};
diff --git a/src/libs/kdtools/kdupdaterupdate.cpp b/src/libs/kdtools/kdupdaterupdate.cpp
index 0ae2ebfaf..ad8b10934 100644
--- a/src/libs/kdtools/kdupdaterupdate.cpp
+++ b/src/libs/kdtools/kdupdaterupdate.cpp
@@ -21,14 +21,6 @@
**********************************************************************/
#include "kdupdaterupdate.h"
-#include "kdupdaterapplication.h"
-#include "kdupdaterupdatesourcesinfo.h"
-#include "kdupdaterfiledownloader_p.h"
-#include "kdupdaterfiledownloaderfactory.h"
-#include "kdupdaterupdateoperations.h"
-#include "kdupdaterupdateoperationfactory.h"
-
-#include <QFile>
using namespace KDUpdater;
@@ -37,124 +29,22 @@ using namespace KDUpdater;
\class KDUpdater::Update kdupdaterupdate.h KDUpdaterUpdate
\brief Represents a single update
- The KDUpdater::Update class contains information and mechanisms to download one update. It is
- created by KDUpdater::UpdateFinder and is used by KDUpdater::UpdateInstaller to download the UpdateFile
+ The KDUpdater::Update class contains information about an update. It is created by KDUpdater::UpdateFinder
corresponding to the update.
- The class makes use of appropriate network protocols (HTTP, HTTPS, FTP, or Local File Copy) to
- download the UpdateFile.
-
The constructor of the KDUpdater::Update class is made protected, because it can be instantiated only by
KDUpdater::UpdateFinder (which is a friend class). The destructor however is public.
*/
-struct Update::UpdateData
-{
- UpdateData(Update *qq) :
- q(qq),
- application(0),
- compressedSize(0),
- uncompressedSize(0)
- {}
-
- Update *q;
- Application *application;
- UpdateSourceInfo sourceInfo;
- QHash<QString, QVariant> data;
- QUrl updateUrl;
- UpdateType type;
- QList<UpdateOperation *> operations;
- QByteArray sha1sum;
-
- quint64 compressedSize;
- quint64 uncompressedSize;
-
- FileDownloader *fileDownloader;
-};
-
/*!
\internal
*/
-Update::Update(Application *application, const UpdateSourceInfo &sourceInfo,
- UpdateType type, const QUrl &updateUrl, const QHash<QString, QVariant> &data,
- quint64 compressedSize, quint64 uncompressedSize, const QByteArray &sha1sum)
- : Task(QLatin1String("Update"), Stoppable, application),
- d(new UpdateData(this))
-{
- d->application = application;
- d->sourceInfo = sourceInfo;
- d->data = data;
- d->updateUrl = updateUrl;
- d->type = type;
-
- d->compressedSize = compressedSize;
- d->uncompressedSize = uncompressedSize;
- d->sha1sum = sha1sum;
-
- d->fileDownloader = FileDownloaderFactory::instance().create(updateUrl.scheme(), this);
- if (d->fileDownloader) {
- d->fileDownloader->setUrl(d->updateUrl);
- d->fileDownloader->setAssumedSha1Sum(d->sha1sum);
- connect(d->fileDownloader, SIGNAL(downloadProgress(double)), this, SLOT(downloadProgress(double)));
- connect(d->fileDownloader, SIGNAL(downloadCanceled()), this, SIGNAL(stopped()));
- connect(d->fileDownloader, SIGNAL(downloadCompleted()), this, SIGNAL(finished()));
- }
-
- switch (type) {
- case NewPackage:
- case PackageUpdate: {
- UpdateOperation *packageOperation = UpdateOperationFactory::instance().create(QLatin1String("UpdatePackage"));
- QStringList args;
- args << data.value(QLatin1String("Name")).toString()
- << data.value(QLatin1String("Version")).toString()
- << data.value(QLatin1String("ReleaseDate")).toString();
- packageOperation->setArguments(args);
- packageOperation->setApplication(application);
- d->operations.append(packageOperation);
- break;
- }
- case CompatUpdate: {
- UpdateOperation *compatOperation = UpdateOperationFactory::instance().create(QLatin1String("UpdateCompatLevel"));
- QStringList args;
- args << data.value(QLatin1String("CompatLevel")).toString();
- compatOperation->setArguments(args);
- compatOperation->setApplication(application);
- d->operations.append(compatOperation);
- break;
- }
- default:
- break;
- }
-}
-
-/*!
- Destructor
-*/
-Update::~Update()
-{
- const QString fileName = this->downloadedFileName();
- if (!fileName.isEmpty())
- QFile::remove(fileName);
- qDeleteAll(d->operations);
- d->operations.clear();
- delete d;
-}
-
-/*!
- Returns the application for which this class is downloading the UpdateFile
-*/
-Application *Update::application() const
+Update::Update(int priority, const QUrl &sourceInfoUrl, const QHash<QString, QVariant> &data)
+ : m_priority(priority)
+ , m_sourceInfoUrl(sourceInfoUrl)
+ , m_data(data)
{
- return d->application;
-}
-
-/*!
- Returns the release date of the update downloaded by this class
-*/
-QDate Update::releaseDate() const
-{
- return d->data.value(QLatin1String("ReleaseDate")).toDate();
}
/*!
@@ -162,150 +52,15 @@ QDate Update::releaseDate() const
*/
QVariant Update::data(const QString &name, const QVariant &defaultValue) const
{
- if (d->data.contains(name))
- return d->data.value(name);
- return defaultValue;
-}
-
-/*!
- Returns the complete URL of the UpdateFile downloaded by this class.
-*/
-QUrl Update::updateUrl() const
-{
- return d->updateUrl;
-}
-
-/*!
- Returns the update source info on which this update was created.
-*/
-UpdateSourceInfo Update::sourceInfo() const
-{
- return d->sourceInfo;
-}
-
-/*!
- * Returns the type of update
- */
-UpdateType Update::type() const
-{
- return d->type;
-}
-
-/*!
- Returns true of the update can be downloaded, false otherwise. The function
- returns false if the URL scheme is not supported by this class.
-*/
-bool Update::canDownload() const
-{
- return d->fileDownloader && d->fileDownloader->canDownload();
-}
-
-/*!
- Returns true of the update has been downloaded. If this function returns true
- the you can use the \ref downloadedFileName() method to get the complete name
- of the downloaded UpdateFile.
-
- \note: The downloaded UpdateFile will be deleted when this class is destroyed
-*/
-bool Update::isDownloaded() const
-{
- return d->fileDownloader && d->fileDownloader->isDownloaded();
-}
-
-/*!
- Returns the name of the downloaded UpdateFile after the download is complete, ie
- when \ref isDownloaded() returns true.
-*/
-QString Update::downloadedFileName() const
-{
- if (d->fileDownloader)
- return d->fileDownloader->downloadedFileName();
-
- return QString();
-}
-
-/*!
- \internal
-*/
-void Update::downloadProgress(double value)
-{
- Q_ASSERT(value <= 1);
- reportProgress(value * 100, tr("Downloading update..."));
-}
-
-/*!
- \internal
-*/
-void Update::downloadCompleted()
-{
- reportProgress(100, tr("Update downloaded"));
- reportDone();
-}
-
-/*!
- \internal
-*/
-void Update::downloadAborted(const QString &msg)
-{
- reportError(msg);
-}
-
-/*!
- \internal
-*/
-void Update::doRun()
-{
- if (d->fileDownloader)
- d->fileDownloader->download();
-}
-
-/*!
- \internal
-*/
-bool Update::doStop()
-{
- if (d->fileDownloader)
- d->fileDownloader->cancelDownload();
- return true;
-}
-
-/*!
- \internal
-*/
-bool Update::doPause()
-{
- return false;
+ return m_data.value(name, defaultValue);
}
-/*!
- \internal
-*/
-bool Update::doResume()
+int Update::priority() const
{
- return false;
+ return m_priority;
}
-/*!
- Returns a list of operations needed by this update. For example, package update needs to change
- the package version, compat update needs to change the compat level...
- */
-QList<UpdateOperation *> Update::operations() const
-{
- return d->operations;
-}
-
-/*!
- * Returns the compressed size of this update's data file.
- */
-quint64 Update::compressedSize() const
-{
- return d->compressedSize;
-}
-
-/*!
- * Returns the uncompressed size of this update's data file.
- */
-quint64 Update::uncompressedSize() const
+QUrl Update::sourceInfoUrl() const
{
- return d->uncompressedSize;
+ return m_sourceInfoUrl;
}
diff --git a/src/libs/kdtools/kdupdaterupdate.h b/src/libs/kdtools/kdupdaterupdate.h
index 17250a71e..dc5560186 100644
--- a/src/libs/kdtools/kdupdaterupdate.h
+++ b/src/libs/kdtools/kdupdaterupdate.h
@@ -23,65 +23,28 @@
#ifndef KD_UPDATER_UPDATE_H
#define KD_UPDATER_UPDATE_H
-#include "kdupdater.h"
-#include "kdupdatertask.h"
-
-#include <QUrl>
-#include <QDate>
#include <QHash>
+#include <QUrl>
#include <QVariant>
-#include <QList>
namespace KDUpdater {
-class Application;
-struct UpdateSourceInfo;
-class UpdateFinder;
-class UpdateOperation;
-
-class KDTOOLS_EXPORT Update : public Task
+class Update
{
- Q_OBJECT
-
public:
- ~Update();
-
- Application *application() const;
+ QVariant data(const QString &name, const QVariant &defaultValue = QVariant()) const;
- UpdateType type() const;
- QUrl updateUrl() const;
- QDate releaseDate() const;
- QVariant data(const QString &m_name, const QVariant &defaultValue = QVariant()) const;
- UpdateSourceInfo sourceInfo() const;
-
- bool canDownload() const;
- bool isDownloaded() const;
- void download() { run(); }
- QString downloadedFileName() const;
-
- QList<UpdateOperation *> operations() const;
-
- quint64 compressedSize() const;
- quint64 uncompressedSize() const;
-
-private Q_SLOTS:
- void downloadProgress(double);
- void downloadAborted(const QString &msg);
- void downloadCompleted();
+ int priority() const;
+ QUrl sourceInfoUrl() const;
private:
friend class UpdateFinder;
- struct UpdateData;
- UpdateData *d;
-
- void doRun();
- bool doStop();
- bool doPause();
- bool doResume();
+ Update(int p, const QUrl &sourceInfoUrl, const QHash<QString, QVariant> &data);
- Update(Application *application, const UpdateSourceInfo &sourceInfo,
- UpdateType type, const QUrl &updateUrl, const QHash<QString, QVariant> &data,
- quint64 compressedSize, quint64 uncompressedSize, const QByteArray &sha1sum);
+private:
+ int m_priority;
+ QUrl m_sourceInfoUrl;
+ QHash<QString, QVariant> m_data;
};
} // namespace KDUpdater
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.cpp b/src/libs/kdtools/kdupdaterupdatefinder.cpp
index 0262dfc50..a386736b5 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.cpp
+++ b/src/libs/kdtools/kdupdaterupdatefinder.cpp
@@ -25,14 +25,13 @@
#include "kdupdaterupdatesourcesinfo.h"
#include "kdupdaterpackagesinfo.h"
#include "kdupdaterupdate.h"
-#include "kdupdaterfiledownloader_p.h"
+#include "kdupdaterfiledownloader.h"
#include "kdupdaterfiledownloaderfactory.h"
#include "kdupdaterupdatesinfo_p.h"
#include "globals.h"
#include <QCoreApplication>
-#include <QDebug>
using namespace KDUpdater;
@@ -82,11 +81,8 @@ using namespace KDUpdater;
class UpdateFinder::Private
{
public:
- Private(UpdateFinder *qq) :
- q(qq),
- application(0),
- updateType(PackageUpdate)
- {}
+ Private(UpdateFinder *qq)
+ : q(qq), application(0) {}
~Private()
{
@@ -98,7 +94,6 @@ public:
UpdateFinder *q;
Application *application;
QList<Update *> updates;
- UpdateTypes updateType;
// Temporary structure that notes down information about updates.
bool cancel;
@@ -113,12 +108,9 @@ public:
bool downloadUpdateXMLFiles();
bool computeApplicableUpdates();
- QList<UpdateInfo> applicableUpdates(UpdatesInfo *updatesInfo,
- bool addNewPackages = false);
- void createUpdateObjects(const UpdateSourceInfo &sourceInfo,
- const QList<UpdateInfo> &updateInfoList);
- bool checkForUpdatePriority(const UpdateSourceInfo &sourceInfo,
- const UpdateInfo &updateInfo);
+ QList<UpdateInfo> applicableUpdates(UpdatesInfo *updatesInfo);
+ void createUpdateObjects(const UpdateSourceInfo &sourceInfo, const QList<UpdateInfo> &updateInfoList);
+ bool checkForUpdatePriority(const UpdateSourceInfo &sourceInfo, const UpdateInfo &updateInfo);
void slotDownloadDone();
};
@@ -176,8 +168,8 @@ void UpdateFinder::Private::computeUpdates()
// 1. Downloading Update XML files from all the update sources
// 2. Matching updates with Package XML and figuring out available updates
- cancel = false;
clear();
+ cancel = false;
// First do some quick sanity checks on the packages info
PackagesInfo *packages = application->packagesInfo();
@@ -259,8 +251,8 @@ bool UpdateFinder::Private::downloadUpdateXMLFiles()
// Create FileDownloader and UpdatesInfo for each update
for (int i = 0; i < updateSources->updateSourceInfoCount(); i++) {
- UpdateSourceInfo info = updateSources->updateSourceInfo(i);
- QUrl updateXmlUrl = QString::fromLatin1("%1/Updates.xml").arg(info.url.toString());
+ const UpdateSourceInfo info = updateSources->updateSourceInfo(i);
+ const QUrl updateXmlUrl = QString::fromLatin1("%1/Updates.xml").arg(info.url.toString());
FileDownloader *downloader = FileDownloaderFactory::instance().create(updateXmlUrl.scheme(), q);
if (!downloader)
@@ -269,82 +261,49 @@ bool UpdateFinder::Private::downloadUpdateXMLFiles()
downloader->setUrl(updateXmlUrl);
downloader->setAutoRemoveDownloadedFile(true);
- UpdatesInfo *updatesInfo = new UpdatesInfo;
updateSourceInfoList.append(info);
updateXmlFDList.append(downloader);
- updatesInfoList.append(updatesInfo);
-
- connect(downloader, SIGNAL(downloadCompleted()),
- q, SLOT(slotDownloadDone()));
- connect(downloader, SIGNAL(downloadCanceled()),
- q, SLOT(slotDownloadDone()));
- connect(downloader, SIGNAL(downloadAborted(QString)),
- q, SLOT(slotDownloadDone()));
+ updatesInfoList.append(new UpdatesInfo);
+
+ connect(downloader, SIGNAL(downloadCompleted()), q, SLOT(slotDownloadDone()));
+ connect(downloader, SIGNAL(downloadCanceled()), q, SLOT(slotDownloadDone()));
+ connect(downloader, SIGNAL(downloadAborted(QString)), q, SLOT(slotDownloadDone()));
}
// Trigger download of Updates.xml file
downloadCompleteCount = 0;
- for (int i = 0; i < updateXmlFDList.count(); i++) {
- FileDownloader *downloader = updateXmlFDList.at(i);
+ foreach (FileDownloader *const downloader, updateXmlFDList)
downloader->download();
- }
// Wait until all downloaders have completed their downloads.
while (true) {
QCoreApplication::processEvents();
if (cancel)
return false;
+
if (downloadCompleteCount == updateXmlFDList.count())
break;
- int pc = computePercent(downloadCompleteCount, updateXmlFDList.count());
- q->reportProgress(pc, tr("Downloading Updates.xml from update sources."));
- }
-
- // All the downloaders have now either downloaded or aborted the
- // download of update XML files.
-
- // Let's now get rid of update sources whose Updates.xml could not be downloaded
- for (int i = 0; i < updateXmlFDList.count(); i++) {
- FileDownloader *downloader = updateXmlFDList.at(i);
- if (downloader->isDownloaded())
- continue;
-
- UpdateSourceInfo info = updateSourceInfoList.at(i);
- QString msg = tr("Could not download updates from %1 ('%2')").arg(info.name, info.url.toString());
- q->reportError(msg);
-
- delete updatesInfoList[i];
- delete downloader;
- updateXmlFDList.removeAt(i);
- updatesInfoList.removeAt(i);
- updateSourceInfoList.removeAt(i);
- --i;
+ q->reportProgress(computePercent(downloadCompleteCount, updateXmlFDList.count()),
+ tr("Downloading Updates.xml from update sources."));
}
- if (updatesInfoList.isEmpty())
- return false;
-
- // Lets parse the downloaded update XML files and get rid of the downloaders.
- for (int i = 0; i < updateXmlFDList.count(); i++) {
- FileDownloader *downloader = updateXmlFDList.at(i);
- UpdatesInfo *updatesInfo = updatesInfoList.at(i);
-
- updatesInfo->setFileName(downloader->downloadedFileName());
-
- if (!updatesInfo->isValid()) {
- QString msg = updatesInfo->errorString();
- q->reportError(msg);
-
- delete updatesInfoList[i];
- delete downloader;
- updateXmlFDList.removeAt(i);
- updatesInfoList.removeAt(i);
- --i;
+ for (int i = updateXmlFDList.count() - 1; i >= 0; --i) {
+ UpdatesInfo *const updatesInfo = updatesInfoList.at(i);
+ FileDownloader *const downloader = updateXmlFDList.takeAt(i);
+ if (downloader->isDownloaded()) {
+ updatesInfo->setFileName(downloader->downloadedFileName());
+ if (!updatesInfo->isValid()) {
+ q->reportError(updatesInfo->errorString());
+ delete updatesInfoList.takeAt(i); // updates info
+ }
+ } else {
+ delete updatesInfoList.takeAt(i); // updates info
+ const UpdateSourceInfo info = updateSourceInfoList.takeAt(i);
+ q->reportError(tr("Could not download updates from %1 ('%2')").arg(info.name, info.url.toString()));
}
+ delete downloader;
}
- qDeleteAll(updateXmlFDList);
- updateXmlFDList.clear();
if (updatesInfoList.isEmpty())
return false;
@@ -363,109 +322,43 @@ bool UpdateFinder::Private::downloadUpdateXMLFiles()
*/
bool UpdateFinder::Private::computeApplicableUpdates()
{
- if (updateType & CompatUpdate) {
- UpdateInfo compatUpdateInfo;
- UpdateSourceInfo compatUpdateSourceInfo;
-
- // Required compat level
- int reqCompatLevel = application->compatLevel() + 1;
-
- q->reportProgress(60, tr("Looking for compatibility update..."));
-
- // We are only interested in compat updates.
- for (int i = 0; i < updatesInfoList.count(); i++) {
- UpdatesInfo *info = updatesInfoList.at(i);
- UpdateSourceInfo updateSource = updateSourceInfoList.at(i);
-
- // If we already have a compat update, just check if the source currently being
- // considered has a higher priority or not.
- if (compatUpdateInfo.data.contains(QLatin1String("CompatLevel")) && updateSource.priority < compatUpdateSourceInfo.priority)
- continue;
-
- // Let's look for compat updates that provide compat level one-higher than
- // the application's current compat level.
- QList<UpdateInfo> updatesInfo = info->updatesInfo(CompatUpdate, reqCompatLevel);
-
- if (updatesInfo.count() == 0)
- continue;
-
- compatUpdateInfo = updatesInfo.at(0);
- compatUpdateSourceInfo = updateSource;
- }
-
- bool found = compatUpdateInfo.data.contains(QLatin1String("CompatLevel"));
- if (found) {
- q->reportProgress(80, tr("Found compatibility update."));
-
- if (compatUpdateInfo.updateFiles.isEmpty()) {
- q->reportError(tr("Update not found."));
- q->reportProgress(100, tr("Update not found."));
- return false;
- }
-
- UpdateFileInfo fileInfo = compatUpdateInfo.updateFiles.at(0);
-
- // Create an update for this entry
- QUrl url = QString::fromLatin1("%1/%2").arg( compatUpdateSourceInfo.url.toString(), fileInfo.fileName);
- Update *update = q->constructUpdate(application, compatUpdateSourceInfo, CompatUpdate,
- url, compatUpdateInfo.data, fileInfo.compressedSize,
- fileInfo.uncompressedSize, fileInfo.sha1sum);
-
- // Register the update
- updates.append(update);
+ for (int i = 0; i < updatesInfoList.count(); i++) {
+ // Fetch updates applicable to this application.
+ QList<UpdateInfo> updates = applicableUpdates(updatesInfoList.at(i));
+ if (!updates.count())
+ continue;
- // Done
- q->reportProgress(100, tr("Compatibility update found."));
- } else {
- q->reportProgress(100, tr("No compatibility updates found."));
- }
- }
- if (updateType & PackageUpdate) {
- // We are looking for normal updates, not compat ones.
- for (int i = 0; i < updatesInfoList.count(); i++) {
- // Fetch updates applicable to this application.
- UpdatesInfo *info = updatesInfoList.at(i);
- QList<UpdateInfo> updates = applicableUpdates(info , updateType & NewPackage);
- if (!updates.count())
- continue;
-
- if (cancel)
- return false;
- UpdateSourceInfo updateSource = updateSourceInfoList.at(i);
+ if (cancel)
+ return false;
+ const UpdateSourceInfo updateSource = updateSourceInfoList.at(i);
- // Create Update objects for updates that have a valid
- // UpdateFile
- createUpdateObjects(updateSource, updates);
- if (cancel)
- return false;
+ // Create Update objects for updates that have a valid
+ // UpdateFile
+ createUpdateObjects(updateSource, updates);
+ if (cancel)
+ return false;
- // Report progress
- int pc = computePercent(i, updatesInfoList.count());
- pc = computeProgressPercentage(51, 100, pc);
- q->reportProgress(pc, tr("Computing applicable updates."));
- }
+ // Report progress
+ q->reportProgress(computeProgressPercentage(51, 100, computePercent(i, updatesInfoList.count())),
+ tr("Computing applicable updates."));
}
q->reportProgress(99, tr("Application updates computed."));
return true;
}
-QList<UpdateInfo> UpdateFinder::Private::applicableUpdates(UpdatesInfo *updatesInfo, bool addNewPackages)
+QList<UpdateInfo> UpdateFinder::Private::applicableUpdates(UpdatesInfo *updatesInfo)
{
- QList<UpdateInfo> retList;
-
- if (!updatesInfo || updatesInfo->updateInfoCount( PackageUpdate ) == 0)
- return retList;
+ const QList<UpdateInfo> dummy;
+ if (!updatesInfo || updatesInfo->updateInfoCount() == 0)
+ return dummy;
PackagesInfo *packages = this->application->packagesInfo();
if (!packages)
- return retList;
+ return dummy;
// Check to see if the updates info contains updates for any application
- bool anyApp = updatesInfo->applicationName() == QLatin1String("{AnyApplication}");
- int appNameIndex = -1;
-
- if (!anyApp) {
+ if (updatesInfo->applicationName() != QLatin1String("{AnyApplication}")) {
// updatesInfo->applicationName() describes one application or a series of
// application names separated by commas.
QString appName = updatesInfo->applicationName();
@@ -473,90 +366,28 @@ QList<UpdateInfo> UpdateFinder::Private::applicableUpdates(UpdatesInfo *updatesI
appName = appName.replace(QLatin1String( " ," ), QLatin1String( "," ));
// Catch hold of app names contained updatesInfo->applicationName()
- QStringList apps = appName.split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
- appNameIndex = apps.indexOf(this->application->applicationName());
-
- // If the application appName isn't one of the app names, then
- // the updates are not applicable.
- if (appNameIndex < 0)
- return retList;
- }
-
- // Check to see if version numbers match. This means that the version
- // number of the update should be greater than the version number of
- // the package that is currently installed.
- QList<UpdateInfo> updateList = updatesInfo->updatesInfo(PackageUpdate);
- for (int i = 0; i < updatesInfo->updateInfoCount(PackageUpdate); i++) {
- UpdateInfo updateInfo = updateList.at(i);
- if (!addNewPackages) {
- int pkgInfoIdx = packages->findPackageInfo( updateInfo.data.value(QLatin1String("Name")).toString());
- if (pkgInfoIdx < 0)
- continue;
-
- PackageInfo pkgInfo = packages->packageInfo(pkgInfoIdx);
-
- // First check to see if the update version is higher than package version
- QString updateVersion = updateInfo.data.value(QLatin1String("Version")).toString();
- QString pkgVersion = pkgInfo.version;
- if (KDUpdater::compareVersion(updateVersion, pkgVersion) <= 0)
- continue;
-
- // It is quite possible that we may have already installed the update.
- // Lets check the last update date of the package and the release date
- // of the update. This way we can compare and figure out if the update
- // has been installed or not.
- QDate pkgDate = pkgInfo.lastUpdateDate;
- QDate updateDate = updateInfo.data.value(QLatin1String("ReleaseDate")).toDate();
- if (pkgDate > updateDate)
- continue;
- }
-
- // Bingo, we found an update :-)
- retList.append(updateInfo);
+ // If the application appName isn't one of the app names, then the updates are not applicable.
+ const QStringList apps = appName.split(QInstaller::commaRegExp(), QString::SkipEmptyParts);
+ if (apps.indexOf(this->application->applicationName()) < 0)
+ return dummy;
}
-
- return retList;
+ return updatesInfo->updatesInfo();
}
-void UpdateFinder::Private::createUpdateObjects(const UpdateSourceInfo &sourceInfo, const QList<UpdateInfo> &updateInfoList)
+void UpdateFinder::Private::createUpdateObjects(const UpdateSourceInfo &sourceInfo,
+ const QList<UpdateInfo> &updateInfoList)
{
- for (int i = 0; i < updateInfoList.count(); i++) {
- UpdateInfo info = updateInfoList.at(i);
- // Compat level checks
- if (info.data.contains(QLatin1String("RequiredCompatLevel")) &&
- info.data.value(QLatin1String("RequiredCompatLevel")).toInt() != application->compatLevel())
- {
- qDebug().nospace() << "Update \"" << info.data.value( QLatin1String( "Name" ) ).toString()
- << "\" at \"" << sourceInfo.name << "\"(\"" << sourceInfo.url.toString()
- << "\") requires a different compat level";
- continue; // Compatibility level mismatch
- }
-
- // If another update of the same name exists, then use the update coming from
- // a higher priority.
+ foreach (const UpdateInfo &info, updateInfoList) {
+ // If another update of the same name exists, then use the update coming from a higher priority.
if (!checkForUpdatePriority(sourceInfo, info)) {
- qDebug().nospace() << "Skipping Update \""
- << info.data.value(QLatin1String("Name")).toString()
- << "\" from \""
- << sourceInfo.name
- << "\"(\""
- << sourceInfo.url.toString()
- << "\") because an update with the same name was found from a higher priority location";
-
+ qDebug().nospace() << "Skipping Update \"" << info.data.value(QLatin1String("Name")).toString()
+ << "\" from \"" << sourceInfo.name << "\"(\"" << sourceInfo.url.toString()
+ << "\") because an update with the same name was found from a higher priority location";
continue;
}
- if (info.updateFiles.isEmpty())
- continue;
-
- UpdateFileInfo fileInfo = info.updateFiles.at(0);
-
- // Create an update for this entry
- QUrl url(QString::fromLatin1("%1/%2").arg( sourceInfo.url.toString(), fileInfo.fileName));
- Update *update = q->constructUpdate(application, sourceInfo, PackageUpdate, url, info.data, fileInfo.compressedSize, fileInfo.uncompressedSize, fileInfo.sha1sum);
-
- // Register the update
- this->updates.append(update);
+ // Create and register the update
+ this->updates.append(new Update(sourceInfo.priority, sourceInfo.url, info.data));
}
}
@@ -570,14 +401,14 @@ bool UpdateFinder::Private::checkForUpdatePriority(const UpdateSourceInfo &sourc
// Bingo, update was previously found elsewhere.
// If the existing update comes from a higher priority server, then cool :)
- if (update->sourceInfo().priority > sourceInfo.priority)
+ if (update->priority() > sourceInfo.priority)
return false;
// If the existing update has a higher version number, keep it
- if (KDUpdater::compareVersion(update->data(QLatin1String("Version")).toString(),
- updateInfo.data.value(QLatin1String("Version")).toString()) > 0)
- return false;
-
+ if (KDUpdater::compareVersion(update->data(QLatin1String("Version")).toString(), updateInfo.data
+ .value(QLatin1String("Version")).toString()) > 0) {
+ return false;
+ }
// Otherwise the old update must be deleted.
this->updates.removeAll(update);
delete update;
@@ -612,15 +443,6 @@ UpdateFinder::~UpdateFinder()
}
/*!
- Returns a pointer to the update application for which this function computes all
- the updates.
-*/
-Application *UpdateFinder::application() const
-{
- return d->application;
-}
-
-/*!
Returns a list of KDUpdater::Update objects. The update objects returned in this list
are made children of the \ref KDUpdater::Application object associated with this class.
*/
@@ -630,22 +452,6 @@ QList<Update *> UpdateFinder::updates() const
}
/*!
- Looks only for a certain type of update. By default, only package update
-*/
-void UpdateFinder::setUpdateType(UpdateTypes type)
-{
- d->updateType = type;
-}
-
-/*!
- Returns the type of updates searched
-*/
-UpdateTypes UpdateFinder::updateType() const
-{
- return d->updateType;
-}
-
-/*!
\internal
Implemented from \ref KDUpdater::Task::doStart().
@@ -704,16 +510,6 @@ void UpdateFinder::Private::slotDownloadDone()
q->reportProgress( pc, tr("Downloading Updates.xml from update sources.") );
}
-/*!
- \internal
- */
-Update *UpdateFinder::constructUpdate(Application *application, const UpdateSourceInfo &sourceInfo,
- UpdateType type, const QUrl &updateUrl, const QHash<QString, QVariant> &data,
- quint64 compressedSize, quint64 uncompressedSize, const QByteArray &sha1sum )
-{
- return new Update(application, sourceInfo, type, updateUrl, data, compressedSize, uncompressedSize, sha1sum);
-}
-
/*!
\ingroup kdupdater
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.h b/src/libs/kdtools/kdupdaterupdatefinder.h
index 7f5ec1bfb..d28f8738b 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.h
+++ b/src/libs/kdtools/kdupdaterupdatefinder.h
@@ -23,48 +23,37 @@
#ifndef KD_UPDATER_UPDATE_FINDER_H
#define KD_UPDATER_UPDATE_FINDER_H
-#include "kdupdater.h"
#include "kdupdatertask.h"
-#include <QList>
#include <QHash>
-
-QT_BEGIN_NAMESPACE
-class QUrl;
-QT_END_NAMESPACE
+#include <QUrl>
namespace KDUpdater {
class Application;
class Update;
-struct UpdateSourceInfo;
class KDTOOLS_EXPORT UpdateFinder : public Task
{
Q_OBJECT
+ class Private;
public:
explicit UpdateFinder(Application *application);
~UpdateFinder();
- Application *application() const;
QList<Update *> updates() const;
- void setUpdateType(UpdateTypes type);
- UpdateTypes updateType() const;
-
private:
void doRun();
bool doStop();
bool doPause();
bool doResume();
- Update *constructUpdate(Application *application, const UpdateSourceInfo &sourceInfo,
- UpdateType type, const QUrl &updateUrl, const QHash<QString, QVariant> &data,
- quint64 compressedSize, quint64 uncompressedSize, const QByteArray &sha1sum);
+ Update *constructUpdate(int priority, const QUrl &sourceInfoUrl, const QHash<QString, QVariant> &data,
+ quint64 compressedSize, quint64 uncompressedSize) const;
private:
- class Private;
Private *d;
Q_PRIVATE_SLOT(d, void slotDownloadDone())
};
diff --git a/src/libs/kdtools/kdupdaterupdateoperation.cpp b/src/libs/kdtools/kdupdaterupdateoperation.cpp
index 6f09bc825..00248be25 100644
--- a/src/libs/kdtools/kdupdaterupdateoperation.cpp
+++ b/src/libs/kdtools/kdupdaterupdateoperation.cpp
@@ -63,7 +63,7 @@ using namespace KDUpdater;
Constructor
*/
UpdateOperation::UpdateOperation()
- : m_error(0), m_application(0)
+ : m_error(0)
{}
/*!
@@ -150,15 +150,6 @@ void UpdateOperation::setArguments(const QStringList &args)
}
/*!
- Sets the Application for this operation.
- This may be used by some operations
-*/
-void UpdateOperation::setApplication(Application *application)
-{
- m_application = application;
-}
-
-/*!
Returns the last set function arguments.
*/
QStringList UpdateOperation::arguments() const
@@ -207,7 +198,6 @@ void UpdateOperation::setError(int error, const QString &errorString)
void UpdateOperation::clear()
{
m_arguments.clear();
- m_application = 0;
}
QStringList UpdateOperation::filesForDelayedDeletion() const
@@ -248,14 +238,6 @@ bool UpdateOperation::deleteFileNowOrLater(const QString &file, QString *errorSt
}
/*!
- Returns a pointer to the current Application
-*/
-Application *UpdateOperation::application() const
-{
- return m_application;
-}
-
-/*!
\fn virtual void KDUpdater::UpdateOperation::backup() = 0;
Subclasses must implement this function to backup any data before performing the action.
diff --git a/src/libs/kdtools/kdupdaterupdateoperation.h b/src/libs/kdtools/kdupdaterupdateoperation.h
index 04f1c4858..5f3ef0736 100644
--- a/src/libs/kdtools/kdupdaterupdateoperation.h
+++ b/src/libs/kdtools/kdupdaterupdateoperation.h
@@ -32,8 +32,6 @@
namespace KDUpdater {
-class Application;
-
class KDTOOLS_EXPORT UpdateOperation
{
Q_DECLARE_TR_FUNCTIONS(UpdateOperation)
@@ -57,7 +55,6 @@ public:
void setValue(const QString &name, const QVariant &value);
void setArguments(const QStringList &args);
- void setApplication(Application *application);
QStringList arguments() const;
void clear();
QString errorString() const;
@@ -76,7 +73,6 @@ public:
protected:
void setName(const QString &name);
- Application *application() const;
void setErrorString(const QString &errorString);
void setError(int error, const QString &errorString = QString());
void registerForDelayedDeletion(const QStringList &files);
@@ -87,7 +83,6 @@ private:
QStringList m_arguments;
QString m_errorString;
int m_error;
- Application *m_application;
QVariantMap m_values;
QStringList m_delayedDeletionFiles;
};
diff --git a/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp b/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp
index aab8f6c2d..7c2468141 100644
--- a/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp
+++ b/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp
@@ -68,7 +68,4 @@ UpdateOperationFactory::UpdateOperationFactory()
registerUpdateOperation<RmdirOperation>(QLatin1String("Rmdir"));
registerUpdateOperation<AppendFileOperation>(QLatin1String("AppendFile"));
registerUpdateOperation<PrependFileOperation>(QLatin1String("PrependFile"));
- registerUpdateOperation<ExecuteOperation>(QLatin1String("Execute"));
- registerUpdateOperation<UpdatePackageOperation>(QLatin1String("UpdatePackage"));
- registerUpdateOperation<UpdateCompatOperation>(QLatin1String("UpdateCompat"));
}
diff --git a/src/libs/kdtools/kdupdaterupdateoperations.cpp b/src/libs/kdtools/kdupdaterupdateoperations.cpp
index 51fcaf7b1..484df9838 100644
--- a/src/libs/kdtools/kdupdaterupdateoperations.cpp
+++ b/src/libs/kdtools/kdupdaterupdateoperations.cpp
@@ -21,29 +21,16 @@
**********************************************************************/
#include "kdupdaterupdateoperations.h"
-#include "kdupdaterapplication.h"
-#include "kdupdaterpackagesinfo.h"
-#include "environment.h"
+#include "errors.h"
+#include "fileutils.h"
-#include <QFile>
#include <QDir>
-#include <QDirIterator>
-#include <QProcess>
+#include <QFile>
#include <QTextStream>
-#include <QDebug>
#include <QTemporaryFile>
-
#include <cerrno>
-#define SUPPORT_DETACHED_PROCESS_EXECUTION
-
-#ifdef SUPPORT_DETACHED_PROCESS_EXECUTION
-#ifdef Q_OS_WIN
-#include <windows.h>
-#endif
-#endif
-
using namespace KDUpdater;
static QString errnoToQString(int error)
@@ -58,26 +45,6 @@ static QString errnoToQString(int error)
#endif
}
-static bool removeDirectory(const QString &path, QString *errorString)
-{
- Q_ASSERT(errorString);
- const QFileInfoList entries = QDir(path).entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
- for (QFileInfoList::const_iterator it = entries.constBegin(); it != entries.constEnd(); ++it) {
- if (it->isDir() && !it->isSymLink()) {
- removeDirectory(it->filePath(), errorString);
- } else {
- QFile f(it->filePath());
- if (!f.remove())
- return false;
- }
- }
-
- errno = 0;
- const bool success = QDir().rmdir(path);
- if (errno)
- *errorString = errnoToQString(errno);
- return success;
-}
/*
* \internal
* Returns a filename for a temporary file based on \a templateName
@@ -116,31 +83,26 @@ void CopyOperation::backup()
setValue(QLatin1String("backupOfExistingDestination"), backupFileName(dest));
- // race condition: The backup file could get created
- // by another process right now. But this is the same
+ // race condition: The backup file could get created by another process right now. But this is the same
// in QFile::copy...
- const bool success = QFile::rename(dest, value(QLatin1String("backupOfExistingDestination")).toString());
- if (!success)
+ if (!QFile::rename(dest, value(QLatin1String("backupOfExistingDestination")).toString()))
setError(UserDefinedError, tr("Could not backup file %1.").arg(dest));
}
bool CopyOperation::performOperation()
{
- // We need two args to complete the copy operation.
- // First arg provides the complete file name of source
+ // We need two args to complete the copy operation. First arg provides the complete file name of source
// Second arg provides the complete file name of dest
- QStringList args = this->arguments();
+ const QStringList args = this->arguments();
if (args.count() != 2) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
return false;
}
- QString source = args.first();
- QString dest = args.last();
- // If destination file exists, then we cannot use QFile::copy()
- // because it does not overwrite an existing file. So we remove
- // the destination file.
+ const QString dest = args.last();
+ // If destination file exists, we cannot use QFile::copy() because it does not overwrite an existing
+ // file. So we remove the destination file.
if (QFile::exists(dest)) {
QFile file(dest);
if (!file.remove()) {
@@ -150,11 +112,11 @@ bool CopyOperation::performOperation()
}
}
- QFile file(source);
+ QFile file(args.first());
const bool copied = file.copy(dest);
if (!copied) {
setError(UserDefinedError);
- setErrorString(tr("Could not copy %1 to %2: %3").arg(source, dest, file.errorString()));
+ setErrorString(tr("Could not copy %1 to %2: %3").arg(file.fileName(), dest, file.errorString()));
}
return copied;
}
@@ -191,9 +153,9 @@ QDomDocument CopyOperation::toXml() const
// we don't want to save the backupOfExistingDestination
if (!hasValue(QLatin1String("backupOfExistingDestination")))
return UpdateOperation::toXml();
-
+
CopyOperation *const me = const_cast<CopyOperation *>(this);
-
+
const QVariant v = value(QLatin1String("backupOfExistingDestination"));
me->clearValue(QLatin1String("backupOfExistingDestination"));
const QDomDocument xml = UpdateOperation::toXml();
@@ -237,32 +199,26 @@ void MoveOperation::backup()
setValue(QLatin1String("backupOfExistingDestination"), backupFileName(dest));
- // race condition: The backup file could get created
- // by another process right now. But this is the same
+ // race condition: The backup file could get created by another process right now. But this is the same
// in QFile::copy...
- const bool success = QFile::rename(dest, value(QLatin1String("backupOfExistingDestination")).toString());
- if (!success)
+ if (!QFile::rename(dest, value(QLatin1String("backupOfExistingDestination")).toString()))
setError(UserDefinedError, tr("Could not backup file %1.").arg(dest));
}
bool MoveOperation::performOperation()
{
- // We need two args to complete the copy operation.
- // First arg provides the complete file name of source
- // Second arg provides the complete file name of dest
- QStringList args = this->arguments();
+ // We need two args to complete the copy operation. // First arg provides the complete file name of
+ // source, second arg provides the complete file name of dest
+ const QStringList args = this->arguments();
if (args.count() != 2) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
return false;
}
- QString source = args.first();
- QString dest = args.last();
-
- // If destination file exists, then we cannot use QFile::copy()
- // because it does not overwrite an existing file. So we remove
- // the destination file.
+ const QString dest = args.last();
+ // If destination file exists, then we cannot use QFile::copy() because it does not overwrite an existing
+ // file. So we remove the destination file.
if (QFile::exists(dest)) {
QFile file(dest);
if (!file.remove(dest)) {
@@ -273,27 +229,23 @@ bool MoveOperation::performOperation()
}
// Copy source to destination.
- QFile file(source);
- const bool copied = file.copy(source, dest);
- if (!copied) {
+ QFile file(args.first());
+ if (!file.copy(dest)) {
setError(UserDefinedError);
- setErrorString(tr("Could not copy %1 to %2: %3").arg(source, dest, file.errorString()));
+ setErrorString(tr("Could not copy %1 to %2: %3").arg(file.fileName(), dest, file.errorString()));
return false;
}
-
- return deleteFileNowOrLater(source);
+ return deleteFileNowOrLater(file.fileName());
}
bool MoveOperation::undoOperation()
{
const QStringList args = arguments();
- const QString& source = args.first();
- const QString& dest = args.last();
-
+ const QString dest = args.last();
// first: copy back the destination to source
QFile destF(dest);
- if (!destF.copy(source)) {
- setError(UserDefinedError, tr("Cannot copy %1 to %2: %3").arg(dest, source, destF.errorString()));
+ if (!destF.copy(args.first())) {
+ setError(UserDefinedError, tr("Cannot copy %1 to %2: %3").arg(dest, args.first(), destF.errorString()));
return false;
}
@@ -310,7 +262,7 @@ bool MoveOperation::undoOperation()
// otherwise we have to copy the backup back:
QFile backupF(value(QLatin1String("backupOfExistingDestination")).toString());
- const bool success = backupF.rename(dest);
+ const bool success = backupF.rename(dest);
if (!success)
setError(UserDefinedError, tr("Cannot restore backup file for %1: %2").arg(dest, backupF.errorString()));
@@ -347,25 +299,22 @@ void DeleteOperation::backup()
{
const QString fileName = arguments().first();
setValue(QLatin1String("backupOfExistingFile"), backupFileName(fileName));
+
QFile file(fileName);
- const bool success = file.copy(value(QLatin1String("backupOfExistingFile")).toString());
- if (!success)
+ if (!file.copy(value(QLatin1String("backupOfExistingFile")).toString()))
setError(UserDefinedError, tr("Cannot create backup of %1: %2").arg(fileName, file.errorString()));
}
bool DeleteOperation::performOperation()
{
- // Requires only one parameter. That is the name of
- // the file to remove.
- QStringList args = this->arguments();
+ // Requires only one parameter. That is the name of the file to remove.
+ const QStringList args = this->arguments();
if (args.count() != 1) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count()));
return false;
}
-
- const QString fName = args.first();
- return deleteFileNowOrLater(fName);
+ return deleteFileNowOrLater(args.first());
}
bool DeleteOperation::undoOperation()
@@ -378,7 +327,6 @@ bool DeleteOperation::undoOperation()
const bool success = backupF.copy(fileName) && deleteFileNowOrLater(backupF.fileName());
if (!success)
setError(UserDefinedError, tr("Cannot restore backup file for %1: %2").arg(fileName, backupF.errorString()));
-
return success;
}
@@ -401,9 +349,9 @@ QDomDocument DeleteOperation::toXml() const
// we don't want to save the backupOfExistingFile
if (!hasValue(QLatin1String("backupOfExistingFile")))
return UpdateOperation::toXml();
-
+
DeleteOperation *const me = const_cast<DeleteOperation *>(this);
-
+
const QVariant v = value(QLatin1String("backupOfExistingFile"));
me->clearValue(QLatin1String("backupOfExistingFile"));
const QDomDocument xml = UpdateOperation::toXml();
@@ -448,13 +396,14 @@ bool MkdirOperation::performOperation()
{
// Requires only one parameter. That is the name of
// the file to remove.
- QStringList args = this->arguments();
+ const QStringList args = this->arguments();
if (args.count() != 1) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count()));
return false;
}
- QString dirName = args.first();
+
+ const QString dirName = args.first();
const bool created = QDir::root().mkpath(dirName);
if (!created) {
setError(UserDefinedError);
@@ -481,25 +430,23 @@ bool MkdirOperation::undoOperation()
if (!createdDir.exists())
return true;
- QString errorString;
- if (forceremoval)
- return removeDirectory(createdDir.path(), &errorString);
+ if (forceremoval) {
+ try {
+ QInstaller::removeDirectory(createdDir.path());
+ } catch (const QInstaller::Error &error) {
+ setError(UserDefinedError, error.message());
+ return false;
+ }
+ return true;
+ }
- // even remove some hidden, OS-created files in there
-#if defined Q_OS_MAC
- QFile::remove(createdDir.path() + QLatin1String("/.DS_Store"));
-#elif defined Q_OS_WIN
- QFile::remove(createdDir.path() + QLatin1String("/Thumbs.db"));
-#endif
+ // remove some hidden, OS-created files in there
+ QInstaller::removeSystemGeneratedFiles(createdDir.path());
errno = 0;
const bool result = QDir::root().rmdir(createdDir.path());
- if (!result) {
- if (errorString.isEmpty())
- setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errorString));
- else
- setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errnoToQString(errno)));
- }
+ if (!result)
+ setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errnoToQString(errno)));
return result;
}
@@ -520,8 +467,8 @@ MkdirOperation *MkdirOperation::clone() const
RmdirOperation::RmdirOperation()
{
- setValue(QLatin1String("removed"), false);
setName(QLatin1String("Rmdir"));
+ setValue(QLatin1String("removed"), false);
}
void RmdirOperation::backup()
@@ -531,29 +478,27 @@ void RmdirOperation::backup()
bool RmdirOperation::performOperation()
{
- // Requires only one parameter. That is the name of
- // the file to remove.
- QStringList args = this->arguments();
+ // Requires only one parameter. That is the name of the file to remove.
+ const QStringList args = this->arguments();
if (args.count() != 1) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count()));
return false;
}
- QString dirName = args.first();
- QDir dir(dirName);
+ QDir dir(args.first());
if (!dir.exists()) {
setError(UserDefinedError);
- setErrorString(tr("Could not remove folder %1: The folder does not exist.").arg(dirName));
+ setErrorString(tr("Could not remove folder %1: The folder does not exist.").arg(args.first()));
return false;
}
errno = 0;
- const bool removed = dir.rmdir(dirName);
+ const bool removed = dir.rmdir(args.first());
setValue(QLatin1String("removed"), removed);
if (!removed) {
setError(UserDefinedError);
- setErrorString(tr("Could not remove folder %1: %2").arg(dirName, errnoToQString(errno)));
+ setErrorString(tr("Could not remove folder %1: %2").arg(args.first(), errnoToQString(errno)));
}
return removed;
}
@@ -563,8 +508,8 @@ bool RmdirOperation::undoOperation()
if (!value(QLatin1String("removed")).toBool())
return true;
- const QFileInfo fi(arguments().first());
errno = 0;
+ const QFileInfo fi(arguments().first());
const bool success = fi.dir().mkdir(fi.fileName());
if( !success)
setError(UserDefinedError, tr("Cannot recreate directory %1: %2").arg(fi.fileName(), errnoToQString(errno)));
@@ -610,19 +555,16 @@ void AppendFileOperation::backup()
bool AppendFileOperation::performOperation()
{
- // This operation takes two arguments. First argument is the name
- // of the file into which a text has to be appended. Second argument
- // is the text to append.
- QStringList args = this->arguments();
+ // This operation takes two arguments. First argument is the name of the file into which a text has to be
+ // appended. Second argument is the text to append.
+ const QStringList args = this->arguments();
if (args.count() != 2) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
return false;
}
- QString fName = args.first();
- QString text = args.last();
-
+ const QString fName = args.first();
QFile file(fName);
if (!file.open(QFile::Append)) {
// first we rename the file, then we copy it to the real target and open the copy - the renamed original is then marked for deletion
@@ -637,7 +579,7 @@ bool AppendFileOperation::performOperation()
}
QTextStream ts(&file);
- ts << text;
+ ts << args.last();
file.close();
return true;
@@ -711,16 +653,14 @@ bool PrependFileOperation::performOperation()
// This operation takes two arguments. First argument is the name
// of the file into which a text has to be appended. Second argument
// is the text to append.
- QStringList args = this->arguments();
+ const QStringList args = this->arguments();
if (args.count() != 2) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
return false;
}
- QString fName = args.first();
- QString text = args.last();
-
+ const QString fName = args.first();
// Load the file first.
QFile file(fName);
if (!file.open(QFile::ReadOnly)) {
@@ -728,11 +668,13 @@ bool PrependFileOperation::performOperation()
setErrorString(tr("Could not open file %1 for reading: %2").arg(file.fileName(), file.errorString()));
return false;
}
+
+ // TODO: fix this, use a text stream
QString fContents(QLatin1String(file.readAll()));
file.close();
// Prepend text to the file text
- fContents = text + fContents;
+ fContents = args.last() + fContents;
// Now re-open the file in write only mode.
if (!file.open(QFile::WriteOnly)) {
@@ -790,278 +732,3 @@ PrependFileOperation *PrependFileOperation::clone() const
{
return new PrependFileOperation;
}
-
-
-////////////////////////////////////////////////////////////////////////////
-// KDUpdater::ExecuteOperation
-////////////////////////////////////////////////////////////////////////////
-
-ExecuteOperation::ExecuteOperation()
- : QObject()
-{
- setName(QLatin1String("Execute"));
-}
-
-void ExecuteOperation::backup()
-{
- // this is not possible, since the process can do whatever...
-}
-
-#if defined(SUPPORT_DETACHED_PROCESS_EXECUTION) && defined(Q_OS_WIN)
-// stolen from qprocess_win.cpp
-static QString qt_create_commandline(const QString &program, const QStringList &arguments)
-{
- QString args;
- if (!program.isEmpty()) {
- QString programName = program;
- if (!programName.startsWith(QLatin1Char('\"')) && !programName.endsWith(QLatin1Char('\"')) && programName.contains(QLatin1Char(' ')))
- programName = QLatin1Char('\"') + programName + QLatin1Char('\"');
- programName.replace(QLatin1Char('/'), QLatin1Char('\\'));
-
- // add the prgram as the first arg ... it works better
- args = programName + QLatin1Char(' ');
- }
-
- for (int i = 0; i < arguments.size(); ++i) {
- QString tmp = arguments.at(i);
- // in the case of \" already being in the string the \ must also be escaped
- tmp.replace(QLatin1String("\\\""), QLatin1String("\\\\\""));
- // escape a single " because the arguments will be parsed
- tmp.replace(QLatin1Char('\"'), QLatin1String("\\\""));
- if (tmp.isEmpty() || tmp.contains(QLatin1Char(' ')) || tmp.contains(QLatin1Char('\t'))) {
- // The argument must not end with a \ since this would be interpreted
- // as escaping the quote -- rather put the \ behind the quote: e.g.
- // rather use "foo"\ than "foo\"
- QString endQuote(QLatin1Char('\"'));
- int i = tmp.length();
- while (i > 0 && tmp.at(i - 1) == QLatin1Char('\\')) {
- --i;
- endQuote += QLatin1Char('\\');
- }
- args += QLatin1String(" \"") + tmp.left(i) + endQuote;
- } else {
- args += QLatin1Char(' ') + tmp;
- }
- }
- return args;
-}
-#endif
-
-bool ExecuteOperation::performOperation()
-{
- // This operation receives only one argument. It is the complete
- // command line of the external program to execute.
- QStringList args = this->arguments();
- if (args.isEmpty()) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
- return false;
- }
-
- QList<int> allowedExitCodes;
-
- QRegExp re(QLatin1String("^\\{((-?\\d+,)*-?\\d+)\\}$"));
- if (re.exactMatch(args.first())) {
- const QStringList numbers = re.cap(1).split(QLatin1Char(','));
- for (QStringList::const_iterator it = numbers.begin(); it != numbers.end(); ++it)
- allowedExitCodes.push_back(it->toInt());
- args.pop_front();
- } else {
- allowedExitCodes.push_back(0);
- }
-
- bool success = false;
-#ifdef SUPPORT_DETACHED_PROCESS_EXECUTION
- // unix style: when there's an ampersand after the command, it's started detached
- if (args.count() >= 2 && args.last() == QLatin1String("&")) {
- args.pop_back();
-#ifdef Q_OS_WIN
- QString arguments = qt_create_commandline(args.front(), args.mid(1));
-
- PROCESS_INFORMATION pinfo;
-
- STARTUPINFOW startupInfo = { sizeof(STARTUPINFO), 0, 0, 0,
- static_cast< ulong >(CW_USEDEFAULT), static_cast< ulong >(CW_USEDEFAULT),
- static_cast< ulong >(CW_USEDEFAULT), static_cast< ulong >(CW_USEDEFAULT),
- 0, 0, 0, STARTF_USESHOWWINDOW, SW_HIDE, 0, 0, 0, 0, 0
- };
- success = CreateProcess(0, (wchar_t*)arguments.utf16(),
- 0, 0, false, CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE, 0,
- 0,
- &startupInfo, &pinfo);
-
-#else
- success = QProcess::startDetached(args.front(), args.mid(1));
-#endif
- }
- else
-#endif
- {
- Environment::instance().applyTo(&process); //apply non-persistent variables
- process.start(args.front(), args.mid(1));
-
- QEventLoop loop;
- QObject::connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit()));
- QObject::connect(&process, SIGNAL(readyRead()), this, SLOT(readProcessOutput()));
- success = process.waitForStarted(-1);
- if (success) {
- loop.exec();
- setValue(QLatin1String("ExitCode"), process.exitCode());
- success = allowedExitCodes.contains(process.exitCode());
- }
- }
- if (!success) {
- setError(UserDefinedError);
- setErrorString(tr("Execution failed: %1").arg(args.join(QLatin1String(" "))));
- }
-
- return success;
-}
-
-/*!
- Cancels the ExecuteOperation. This methods tries to terminate the process
- gracefully by calling QProcess::terminate. After 10 seconds, the process gets killed.
- */
-void ExecuteOperation::cancelOperation()
-{
- if (process.state() == QProcess::Running)
- process.terminate();
- if (!process.waitForFinished(10000))
- process.kill();
-}
-
-void ExecuteOperation::readProcessOutput()
-{
- QByteArray output = process.readAll();
- if (!output.isEmpty())
- emit outputTextChanged(QString::fromLocal8Bit(output));
-}
-
-bool ExecuteOperation::undoOperation()
-{
- // this is not possible, since the process can do whatever...
- return false;
-}
-
-bool ExecuteOperation::testOperation()
-{
- // TODO
- return true;
-}
-
-ExecuteOperation *ExecuteOperation::clone() const
-{
- return new ExecuteOperation;
-}
-
-
-////////////////////////////////////////////////////////////////////////////
-// KDUpdater::UpdatePackageOperation
-////////////////////////////////////////////////////////////////////////////
-
-UpdatePackageOperation::UpdatePackageOperation()
-{
- setName(QLatin1String("UpdatePackage"));
-}
-
-void UpdatePackageOperation::backup()
-{
- const PackageInfo info = application()->packagesInfo()->packageInfo(application()->packagesInfo()->findPackageInfo(arguments().first()));
- setValue(QLatin1String("oldVersion"), info.version);
- setValue(QLatin1String("oldDate"), info.lastUpdateDate);
-}
-
-bool UpdatePackageOperation::performOperation()
-{
- // This operation receives three arguments : the name of the package
- // the new version and the release date
- const QStringList args = this->arguments();
- if (args.count() != 3) {
- setError(InvalidArguments, tr("Invalid arguments: %1 arguments given, 3 expected.").arg(args.count()));
- return false;
- }
-
- const QString &packageName = args.at(0);
- const QString &version = args.at(1);
- const QDate date = QDate::fromString(args.at(2));
- const bool success = application()->packagesInfo()->updatePackage(packageName, version, date);
- if (!success)
- setError(UserDefinedError, tr("Cannot update %1-%2").arg(packageName, version));
-
- return success;
-}
-
-bool UpdatePackageOperation::undoOperation()
-{
- const QString packageName = arguments().first();
- const QString version = arguments().at(1);
- const QString oldVersion = value(QLatin1String("oldVersion")).toString();
- const QDate oldDate = value(QLatin1String("oldDate")).toDate();
- const bool success = application()->packagesInfo()->updatePackage(packageName, oldVersion, oldDate);
- if (!success)
- setError(UserDefinedError, tr("Cannot restore %1-%2").arg(packageName, version));
-
- return success;
-}
-
-bool UpdatePackageOperation::testOperation()
-{
- // TODO
- return true;
-}
-
-UpdatePackageOperation *UpdatePackageOperation::clone() const
-{
- return new UpdatePackageOperation;
-}
-
-
-////////////////////////////////////////////////////////////////////////////
-// KDUpdater::UpdateCompatOperation
-////////////////////////////////////////////////////////////////////////////
-
-UpdateCompatOperation::UpdateCompatOperation()
-{
- setName(QLatin1String("UpdateCompatLevel"));
-}
-
-void UpdateCompatOperation::backup()
-{
- setValue(QLatin1String("oldCompatLevel"), application()->packagesInfo()->compatLevel());
-}
-
-bool UpdateCompatOperation::performOperation()
-{
- // This operation receives one argument : the new compat level
- const QStringList args = this->arguments();
- if (args.count() != 1) {
- setError(InvalidArguments, tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count()));
- return false;
- }
-
- const int level = args.first().toInt();
- application()->packagesInfo()->setCompatLevel(level);
- return true;
-}
-
-bool UpdateCompatOperation::undoOperation()
-{
- if (!hasValue(QLatin1String("oldCompatLevel"))) {
- setError(UserDefinedError, tr("Cannot restore previous compat-level"));
- return false;
- }
-
- application()->packagesInfo()->setCompatLevel(value(QLatin1String("oldCompatLevel")).toInt());
- return true;
-}
-
-bool UpdateCompatOperation::testOperation()
-{
- // TODO
- return true;
-}
-
-UpdateCompatOperation *UpdateCompatOperation::clone() const
-{
- return new UpdateCompatOperation;
-}
diff --git a/src/libs/kdtools/kdupdaterupdateoperations.h b/src/libs/kdtools/kdupdaterupdateoperations.h
index 40480d1e1..5fb7f5a84 100644
--- a/src/libs/kdtools/kdupdaterupdateoperations.h
+++ b/src/libs/kdtools/kdupdaterupdateoperations.h
@@ -25,10 +25,6 @@
#include "kdupdaterupdateoperation.h"
-#include <QDir>
-#include <QObject>
-#include <QProcess>
-
namespace KDUpdater {
class KDTOOLS_EXPORT CopyOperation : public UpdateOperation
@@ -122,56 +118,6 @@ public:
PrependFileOperation *clone() const;
};
-class KDTOOLS_EXPORT ExecuteOperation : public QObject, public UpdateOperation
-{
- Q_OBJECT
-
-public:
- ExecuteOperation();
-
- void backup();
- bool performOperation();
- bool undoOperation();
- bool testOperation();
- ExecuteOperation *clone() const;
-
-public Q_SLOTS:
- void cancelOperation();
-
-private Q_SLOTS:
- void readProcessOutput();
-
-Q_SIGNALS:
- void outputTextChanged(const QString &text);
-
-private:
- QProcess process;
-};
-
-class KDTOOLS_EXPORT UpdatePackageOperation : public UpdateOperation
-{
-public:
- UpdatePackageOperation();
-
- void backup();
- bool performOperation();
- bool undoOperation();
- bool testOperation();
- UpdatePackageOperation *clone() const;
-};
-
-class KDTOOLS_EXPORT UpdateCompatOperation : public UpdateOperation
-{
-public:
- UpdateCompatOperation();
-
- void backup();
- bool performOperation();
- bool undoOperation();
- bool testOperation();
- UpdateCompatOperation *clone() const;
-};
-
} // namespace KDUpdater
#endif // KD_UPDATER_UPDATE_OPERATIONS_H
diff --git a/src/libs/kdtools/kdupdaterupdatesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesinfo.cpp
index fc4a7a2ce..730f2887d 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfo.cpp
+++ b/src/libs/kdtools/kdupdaterupdatesinfo.cpp
@@ -30,7 +30,6 @@ using namespace KDUpdater;
UpdatesInfoData::UpdatesInfoData()
: error(UpdatesInfo::NotYetReadError)
- , compatLevel(-1)
{
}
@@ -55,15 +54,11 @@ void UpdatesInfoData::parseFile(const QString &updateXmlFile)
QDomDocument doc;
QString parseErrorMessage;
- int parseErrorLine;
- int parseErrorColumn;
+ int parseErrorLine, parseErrorColumn;
if (!doc.setContent(&file, &parseErrorMessage, &parseErrorLine, &parseErrorColumn)) {
error = UpdatesInfo::InvalidXmlError;
- errorMessage = tr("Parse error in %1 at %2, %3: %4")
- .arg(updateXmlFile,
- QString::number(parseErrorLine),
- QString::number(parseErrorColumn),
- parseErrorMessage);
+ errorMessage = tr("Parse error in %1 at %2, %3: %4").arg(updateXmlFile,
+ QString::number(parseErrorLine), QString::number(parseErrorColumn), parseErrorMessage);
return;
}
@@ -75,8 +70,7 @@ void UpdatesInfoData::parseFile(const QString &updateXmlFile)
QDomNodeList childNodes = rootE.childNodes();
for(int i = 0; i < childNodes.count(); i++) {
- QDomNode childNode = childNodes.at(i);
- QDomElement childE = childNode.toElement();
+ const QDomElement childE = childNodes.at(i).toElement();
if (childE.isNull())
continue;
@@ -84,20 +78,9 @@ void UpdatesInfoData::parseFile(const QString &updateXmlFile)
applicationName = childE.text();
else if (childE.tagName() == QLatin1String("ApplicationVersion"))
applicationVersion = childE.text();
- else if (childE.tagName() == QLatin1String("RequiredCompatLevel"))
- compatLevel = childE.text().toInt();
else if (childE.tagName() == QLatin1String("PackageUpdate")) {
- const bool res = parsePackageUpdateElement(childE);
- if (!res) {
- //error handled in subroutine
- return;
- }
- } else if (childE.tagName() == QLatin1String("CompatUpdate")) {
- const bool res = parseCompatUpdateElement(childE);
- if (!res) {
- //error handled in subroutine
- return;
- }
+ if (!parsePackageUpdateElement(childE))
+ return; //error handled in subroutine
}
}
@@ -105,14 +88,14 @@ void UpdatesInfoData::parseFile(const QString &updateXmlFile)
setInvalidContentError(tr("ApplicationName element is missing."));
return;
}
-
+
if (applicationVersion.isEmpty()) {
setInvalidContentError(tr("ApplicationVersion element is missing."));
return;
}
-
- error = UpdatesInfo::NoError;
+
errorMessage.clear();
+ error = UpdatesInfo::NoError;
}
bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
@@ -121,24 +104,13 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
return false;
UpdateInfo info;
- info.type = PackageUpdate;
-
- QDomNodeList childNodes = updateE.childNodes();
- for (int i = 0; i < childNodes.count(); i++) {
- QDomNode childNode = childNodes.at(i);
- QDomElement childE = childNode.toElement();
+ for (int i = 0; i < updateE.childNodes().count(); i++) {
+ QDomElement childE = updateE.childNodes().at(i).toElement();
if (childE.isNull())
continue;
if (childE.tagName() == QLatin1String("ReleaseNotes")) {
info.data[childE.tagName()] = QUrl(childE.text());
- } else if (childE.tagName() == QLatin1String("UpdateFile")) {
- UpdateFileInfo ufInfo;
- ufInfo.compressedSize = childE.attribute(QLatin1String("CompressedSize")).toLongLong();
- ufInfo.uncompressedSize = childE.attribute(QLatin1String("UncompressedSize")).toLongLong();
- ufInfo.sha1sum = QByteArray::fromHex(childE.attribute(QLatin1String("sha1sum")).toLatin1());
- ufInfo.fileName = childE.text();
- info.updateFiles.append(ufInfo);
} else if (childE.tagName() == QLatin1String("Licenses")) {
QHash<QString, QVariant> licenseHash;
const QDomNodeList licenseNodes = childE.childNodes();
@@ -153,19 +125,17 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
if (!licenseHash.isEmpty())
info.data.insert(QLatin1String("Licenses"), licenseHash);
} else if (childE.tagName() == QLatin1String("Version")) {
- info.data.insert(QLatin1String("inheritVersionFrom"), childE.attribute(QLatin1String("inheritVersionFrom")));
+ info.data.insert(QLatin1String("inheritVersionFrom"),
+ childE.attribute(QLatin1String("inheritVersionFrom")));
info.data[childE.tagName()] = childE.text();
} else if (childE.tagName() == QLatin1String("Description")) {
-
QString languageAttribute = childE.attribute(QLatin1String("xml:lang")).toLower();
-
if (!info.data.contains(QLatin1String("Description")) && (languageAttribute.isEmpty()))
info.data[childE.tagName()] = childE.text();
// overwrite default if we have a language specific description
if (languageAttribute == QLocale().name().toLower())
info.data[childE.tagName()] = childE.text();
-
} else {
info.data[childE.tagName()] = childE.text();
}
@@ -183,55 +153,6 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
setInvalidContentError(tr("PackageUpdate element without ReleaseDate"));
return false;
}
- if (info.updateFiles.isEmpty()) {
- setInvalidContentError(tr("PackageUpdate element without UpdateFile"));
- return false;
- }
-
- updateInfoList.append(info);
- return true;
-}
-
-bool UpdatesInfoData::parseCompatUpdateElement(const QDomElement &updateE)
-{
- if (updateE.isNull())
- return false;
-
- UpdateInfo info;
- info.type = CompatUpdate;
-
- QDomNodeList childNodes = updateE.childNodes();
- for (int i = 0; i < childNodes.count(); i++) {
- QDomNode childNode = childNodes.at(i);
- QDomElement childE = childNode.toElement();
- if (childE.isNull())
- continue;
-
- if (childE.tagName() == QLatin1String("ReleaseNotes")) {
- info.data[childE.tagName()] = QUrl(childE.text());
- } else if (childE.tagName() == QLatin1String("UpdateFile")) {
- UpdateFileInfo ufInfo;
- ufInfo.fileName = childE.text();
- info.updateFiles.append(ufInfo);
- } else {
- info.data[childE.tagName()] = childE.text();
- }
- }
-
- if (!info.data.contains(QLatin1String("CompatLevel"))) {
- setInvalidContentError(tr("CompatUpdate element without CompatLevel"));
- return false;
- }
-
- if (!info.data.contains(QLatin1String("ReleaseDate"))) {
- setInvalidContentError(tr("CompatUpdate element without ReleaseDate"));
- return false;
- }
-
- if (info.updateFiles.isEmpty()) {
- setInvalidContentError(tr("CompatUpdate element without UpdateFile"));
- return false;
- }
updateInfoList.append(info);
return true;
@@ -288,55 +209,19 @@ QString UpdatesInfo::applicationVersion() const
return d->applicationVersion;
}
-int UpdatesInfo::compatLevel() const
-{
- return d->compatLevel;
-}
-
-int UpdatesInfo::updateInfoCount(int type) const
+int UpdatesInfo::updateInfoCount() const
{
- if (type == AllUpdate)
- return d->updateInfoList.count();
-
- int count = 0;
- for (int i = 0; i < d->updateInfoList.count(); ++i) {
- if (d->updateInfoList.at(i).type == type)
- ++count;
- }
- return count;
+ return d->updateInfoList.count();
}
UpdateInfo UpdatesInfo::updateInfo(int index) const
{
if (index < 0 || index >= d->updateInfoList.count())
return UpdateInfo();
-
return d->updateInfoList.at(index);
}
-QList<UpdateInfo> UpdatesInfo::updatesInfo(int type, int compatLevel) const
+QList<UpdateInfo> UpdatesInfo::updatesInfo() const
{
- QList<UpdateInfo> list;
- if (compatLevel == -1) {
- if (type == AllUpdate)
- return d->updateInfoList;
- for (int i = 0; i < d->updateInfoList.count(); ++i) {
- if (d->updateInfoList.at(i).type == type)
- list.append(d->updateInfoList.at(i));
- }
- } else {
- for (int i = 0; i < d->updateInfoList.count(); ++i) {
- UpdateInfo updateInfo = d->updateInfoList.at(i);
- if (updateInfo.type == type) {
- if (updateInfo.type == CompatUpdate) {
- if (updateInfo.data.value(QLatin1String("CompatLevel")) == compatLevel)
- list.append(updateInfo);
- } else {
- if (updateInfo.data.value(QLatin1String("RequiredCompatLevel")) == compatLevel)
- list.append(updateInfo);
- }
- }
- }
- }
- return list;
+ return d->updateInfoList;
}
diff --git a/src/libs/kdtools/kdupdaterupdatesinfo_p.h b/src/libs/kdtools/kdupdaterupdatesinfo_p.h
index a1851ddf7..2307503de 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfo_p.h
+++ b/src/libs/kdtools/kdupdaterupdatesinfo_p.h
@@ -28,7 +28,6 @@
#include <QHash>
#include <QSharedData>
-#include <QString>
#include <QVariant>
// They are not a part of the public API
@@ -36,24 +35,9 @@
namespace KDUpdater {
-struct KDTOOLS_EXPORT UpdateFileInfo
-{
- UpdateFileInfo()
- : compressedSize(0),
- uncompressedSize(0)
- {}
-
- QString fileName;
- QByteArray sha1sum;
- quint64 compressedSize;
- quint64 uncompressedSize;
-};
-
struct KDTOOLS_EXPORT UpdateInfo
{
- int type;
QHash<QString, QVariant> data;
- QList<UpdateFileInfo> updateFiles;
};
class KDTOOLS_EXPORT UpdatesInfo
@@ -72,19 +56,19 @@ public:
~UpdatesInfo();
bool isValid() const;
- QString errorString() const;
+
Error error() const;
+ QString errorString() const;
- void setFileName(const QString &updateXmlFile);
QString fileName() const;
+ void setFileName(const QString &updateXmlFile);
QString applicationName() const;
QString applicationVersion() const;
- int compatLevel() const;
- int updateInfoCount(int type = AllUpdate) const;
+ int updateInfoCount() const;
UpdateInfo updateInfo(int index) const;
- QList<UpdateInfo> updatesInfo(int type = AllUpdate, int compatLevel = -1) const;
+ QList<UpdateInfo> updatesInfo() const;
private:
QSharedDataPointer<UpdatesInfoData> d;
diff --git a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h b/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
index 4b398ee91..75acce0e9 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
+++ b/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
@@ -44,12 +44,10 @@ public:
QString updateXmlFile;
QString applicationName;
QString applicationVersion;
- int compatLevel;
QList<UpdateInfo> updateInfoList;
void parseFile(const QString &updateXmlFile);
bool parsePackageUpdateElement(const QDomElement &updateE);
- bool parseCompatUpdateElement(const QDomElement &updateE);
void setInvalidContentError(const QString &detail);
};
diff --git a/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
index 01f3a96f4..ca8d6133c 100644
--- a/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
+++ b/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
@@ -21,7 +21,6 @@
**********************************************************************/
#include "kdupdaterupdatesourcesinfo.h"
-#include "kdupdaterapplication.h"
#include <QtXml/QDomElement>
#include <QtXml/QDomDocument>
@@ -73,7 +72,7 @@
*/
/*! \var UpdateSourcesInfo::Error UpdateSourcesInfo::InvalidXmlError
- * The source file contains invalid XML.
+ * The source file contains invalid XML.
*/
/*! \var UpdateSourcesInfo::Error UpdateSourcesInfo::InvalidContentError
@@ -97,24 +96,21 @@ struct UpdateSourceInfoPriorityHigherThan
struct UpdateSourcesInfo::UpdateSourcesInfoData
{
- UpdateSourcesInfoData(UpdateSourcesInfo *qq) :
- q(qq),
- error(UpdateSourcesInfo::NotYetReadError),
- application(0),
- modified(false)
+ UpdateSourcesInfoData()
+ : modified(false)
+ , error(UpdateSourcesInfo::NotYetReadError)
{}
- UpdateSourcesInfo *q;
-
- QString errorMessage;
- UpdateSourcesInfo::Error error;
- Application *application;
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 addChildElement(QDomDocument &doc, QDomElement &parentE, const QString &tagName,
+ const QString &text, bool htmlText = false);
void setInvalidContentError(const QString &detail);
void clearError();
void saveChanges();
@@ -135,11 +131,10 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::clearError()
/*!
\internal
*/
-UpdateSourcesInfo::UpdateSourcesInfo(Application *application)
- : QObject(application),
- d(new UpdateSourcesInfo::UpdateSourcesInfoData(this))
+UpdateSourcesInfo::UpdateSourcesInfo(QObject *parent)
+ : QObject(parent)
+ , d(new UpdateSourcesInfo::UpdateSourcesInfoData)
{
- d->application = application;
}
/*!
@@ -148,15 +143,6 @@ UpdateSourcesInfo::UpdateSourcesInfo(Application *application)
UpdateSourcesInfo::~UpdateSourcesInfo()
{
d->saveChanges();
- delete d;
-}
-
-/*!
- Returns a pointer to the update application for which this class manages update sources.
-*/
-Application *UpdateSourcesInfo::application() const
-{
- return d->application;
}
/*!
@@ -264,47 +250,6 @@ void UpdateSourcesInfo::removeUpdateSourceInfo(const UpdateSourceInfo &info)
}
/*!
- Removes an update source info at \index in this class. Upon successful removal, the class emits a
- \ref updateSourceInfoRemoved() signal.
-*/
-void UpdateSourcesInfo::removeUpdateSourceInfoAt(int index)
-{
- if (index < 0 || index >= d->updateSourceInfoList.count())
- return;
- UpdateSourceInfo info = d->updateSourceInfoList[index];
- d->updateSourceInfoList.removeAt(index);
- emit updateSourceInfoRemoved(info);
- d->modified = true;
-}
-
-/*!
- Changes the update source info at \c index to \c info. If \c index is equal to the number of
- source info structures in this class (\ref updateSourceInfoCount()) then \c info is appended;
- otherwise the existing info at \c index will be changed.
-
- Depending on what the function does \ref updateSourceInfoAdded() or \ref updateSourceInfoChanged()
- signal is emitted.
-*/
-void UpdateSourcesInfo::setUpdateSourceInfoAt(int index, const UpdateSourceInfo &info)
-{
- if (index < 0 || index > d->updateSourceInfoList.count())
- return;
-
- if (index == d->updateSourceInfoList.count()) {
- d->updateSourceInfoList.append(info);
- emit updateSourceInfoAdded(info);
- } else {
- UpdateSourceInfo oldInfo = d->updateSourceInfoList[index];
- if (info == oldInfo)
- return;
-
- d->updateSourceInfoList[index] = info;
- emit updateSourceInfoChanged(info, oldInfo);
- }
- d->modified = true;
-}
-
-/*!
This slot reloads the update source information from UpdateSources.xml.
*/
void UpdateSourcesInfo::refresh()
@@ -313,14 +258,14 @@ void UpdateSourcesInfo::refresh()
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);
@@ -331,35 +276,27 @@ void UpdateSourcesInfo::refresh()
QDomDocument doc;
QString parseErrorMessage;
- int parseErrorLine;
- int parseErrorColumn;
+ 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);
+ 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.
- QDomElement rootE = doc.documentElement();
+ 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;
}
- QDomNodeList childNodes = rootE.childNodes();
+ const QDomNodeList childNodes = rootE.childNodes();
for (int i = 0; i < childNodes.count(); i++) {
- QDomNode childNode = childNodes.item(i);
- QDomElement childNodeE = childNode.toElement();
- if (childNodeE.isNull())
- continue;
-
- if (childNodeE.tagName() == QLatin1String("UpdateSource"))
+ QDomElement childNodeE = childNodes.item(i).toElement();
+ if ((!childNodeE.isNull()) && (childNodeE.tagName() == QLatin1String("UpdateSource")))
d->addUpdateSourceFrom(childNodeE);
}
@@ -372,23 +309,20 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::saveChanges()
if (!modified || fileName.isEmpty())
return;
- const bool hadSaveError = error == UpdateSourcesInfo::CouldNotSaveChangesError;
-
- QDomDocument doc;
+ const bool hadSaveError = (error == UpdateSourcesInfo::CouldNotSaveChangesError);
+ QDomDocument doc;
QDomElement rootE = doc.createElement(QLatin1String("UpdateSources"));
doc.appendChild(rootE);
- for (int i = 0; i < updateSourceInfoList.count(); i++) {
- UpdateSourceInfo info = updateSourceInfoList.at(i);
-
+ 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());
+ 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);
@@ -397,7 +331,7 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::saveChanges()
errorMessage = tr("Could not save changes to \"%1\": %2").arg(fileName, file.errorString());
return;
}
-
+
QTextStream stream(&file);
doc.save(stream, 2);
stream.flush();
@@ -408,11 +342,11 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::saveChanges()
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;
}
@@ -421,15 +355,13 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::addUpdateSourceFrom(const QDomEle
if (element.tagName() != QLatin1String("UpdateSource"))
return;
- QDomNodeList childNodes = element.childNodes();
+ const QDomNodeList childNodes = element.childNodes();
if (!childNodes.count())
return;
UpdateSourceInfo info;
-
- for (int i = 0; i<childNodes.count(); i++) {
- QDomNode childNode = childNodes.item(i);
- QDomElement childNodeE = childNode.toElement();
+ for (int i = 0; i < childNodes.count(); ++i) {
+ const QDomElement childNodeE = childNodes.item(i).toElement();
if (childNodeE.isNull())
continue;
@@ -442,22 +374,15 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::addUpdateSourceFrom(const QDomEle
else if (childNodeE.tagName() == QLatin1String("Url"))
info.url = childNodeE.text();
}
-
this->updateSourceInfoList.append(info);
}
-void UpdateSourcesInfo::UpdateSourcesInfoData::addChildElement(QDomDocument &doc, QDomElement &parentE, const QString &tagName, const QString &text, bool htmlText)
+void UpdateSourcesInfo::UpdateSourcesInfoData::addChildElement(QDomDocument &doc, QDomElement &parentE,
+ const QString &tagName, const QString &text, bool htmlText)
{
QDomElement childE = doc.createElement(tagName);
parentE.appendChild(childE);
-
- if (htmlText) {
- QDomCDATASection textE = doc.createCDATASection(text);
- childE.appendChild(textE);
- } else {
- QDomText textE = doc.createTextNode(text);
- childE.appendChild(textE);
- }
+ childE.appendChild(htmlText ? doc.createCDATASection(text) : doc.createTextNode(text));
}
/*!
@@ -491,10 +416,10 @@ void UpdateSourcesInfo::UpdateSourcesInfoData::addChildElement(QDomDocument &doc
namespace KDUpdater {
-bool operator==(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
+bool operator== (const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
{
- return lhs.name == rhs.name && lhs.title == rhs.title
- && lhs.description == rhs.description && lhs.url == rhs.url;
+ return lhs.name == rhs.name && lhs.title == rhs.title && lhs.description == rhs.description
+ && lhs.url == rhs.url;
}
} // namespace KDUpdater
diff --git a/src/libs/kdtools/kdupdaterupdatesourcesinfo.h b/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
index 2afeda966..e533471ce 100644
--- a/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
+++ b/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
@@ -23,7 +23,7 @@
#ifndef KD_UPDATER_UPDATE_SOURCES_INFO_H
#define KD_UPDATER_UPDATE_SOURCES_INFO_H
-#include "kdupdater.h"
+#include "kdtoolsglobal.h"
#include <QObject>
#include <QVariant>
@@ -31,8 +31,6 @@
namespace KDUpdater {
-class Application;
-
struct KDTOOLS_EXPORT UpdateSourceInfo
{
UpdateSourceInfo() : priority(-1) { }
@@ -68,8 +66,6 @@ public:
CouldNotSaveChangesError
};
- Application *application() const;
-
bool isValid() const;
QString errorString() const;
Error error() const;
@@ -85,11 +81,10 @@ public:
void addUpdateSourceInfo(const UpdateSourceInfo &info);
void removeUpdateSourceInfo(const UpdateSourceInfo &info);
- void removeUpdateSourceInfoAt(int index);
- void setUpdateSourceInfoAt(int index, const UpdateSourceInfo &info);
protected:
- explicit UpdateSourcesInfo(Application *application);
+ friend class Application;
+ explicit UpdateSourcesInfo(QObject *parent = 0);
public Q_SLOTS:
void refresh();
@@ -98,13 +93,10 @@ Q_SIGNALS:
void reset();
void updateSourceInfoAdded(const UpdateSourceInfo &info);
void updateSourceInfoRemoved(const UpdateSourceInfo &info);
- void updateSourceInfoChanged(const UpdateSourceInfo &newInfo,
- const UpdateSourceInfo &oldInfo);
private:
- friend class Application;
struct UpdateSourcesInfoData;
- UpdateSourcesInfoData *d;
+ QScopedPointer<UpdateSourcesInfoData> d;
};
} // namespace KDUpdater
diff --git a/tests/auto/installer/componentmodel/tst_componentmodel.cpp b/tests/auto/installer/componentmodel/tst_componentmodel.cpp
index 89e6be3d8..290f0d733 100644
--- a/tests/auto/installer/componentmodel/tst_componentmodel.cpp
+++ b/tests/auto/installer/componentmodel/tst_componentmodel.cpp
@@ -420,7 +420,7 @@ private:
{
UpdatesInfo updatesInfo;
updatesInfo.setFileName(":///data/updates.xml");
- const QList<UpdateInfo> updateInfos = updatesInfo.updatesInfo(PackageUpdate);
+ const QList<UpdateInfo> updateInfos = updatesInfo.updatesInfo();
QHash<QString, Component*> components;
foreach (const UpdateInfo &info, updateInfos) {