summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/kdtools')
-rw-r--r--src/libs/kdtools/environment.h6
-rw-r--r--src/libs/kdtools/filedownloader.cpp (renamed from src/libs/kdtools/kdupdaterfiledownloader.cpp)48
-rw-r--r--src/libs/kdtools/filedownloader.h (renamed from src/libs/kdtools/kdupdaterfiledownloader.h)10
-rw-r--r--src/libs/kdtools/filedownloader_p.h (renamed from src/libs/kdtools/kdupdaterfiledownloader_p.h)8
-rw-r--r--src/libs/kdtools/filedownloaderfactory.cpp (renamed from src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp)11
-rw-r--r--src/libs/kdtools/filedownloaderfactory.h (renamed from src/libs/kdtools/kdupdaterfiledownloaderfactory.h)13
-rw-r--r--src/libs/kdtools/genericfactory.cpp128
-rw-r--r--src/libs/kdtools/genericfactory.h91
-rw-r--r--src/libs/kdtools/job.cpp (renamed from src/libs/kdtools/kdjob.cpp)84
-rw-r--r--src/libs/kdtools/job.h (renamed from src/libs/kdtools/kdjob.h)22
-rw-r--r--src/libs/kdtools/kdgenericfactory.cpp180
-rw-r--r--src/libs/kdtools/kdgenericfactory.h105
-rw-r--r--src/libs/kdtools/kdsysinfo_win.cpp2
-rw-r--r--src/libs/kdtools/kdtools.pri95
-rw-r--r--src/libs/kdtools/kdtoolsglobal.h6
-rw-r--r--src/libs/kdtools/kdupdaterapplication.cpp311
-rw-r--r--src/libs/kdtools/kdupdaterapplication.h105
-rw-r--r--src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp480
-rw-r--r--src/libs/kdtools/kdupdaterupdatesourcesinfo.h117
-rw-r--r--src/libs/kdtools/localpackagehub.cpp (renamed from src/libs/kdtools/kdupdaterpackagesinfo.cpp)301
-rw-r--r--src/libs/kdtools/localpackagehub.h (renamed from src/libs/kdtools/kdupdaterpackagesinfo.h)72
-rw-r--r--src/libs/kdtools/lockfile.cpp (renamed from src/libs/kdtools/kdlockfile.cpp)18
-rw-r--r--src/libs/kdtools/lockfile.h (renamed from src/libs/kdtools/kdlockfile.h)20
-rw-r--r--src/libs/kdtools/lockfile_p.h (renamed from src/libs/kdtools/kdlockfile_p.h)14
-rw-r--r--src/libs/kdtools/lockfile_unix.cpp (renamed from src/libs/kdtools/kdlockfile_unix.cpp)27
-rw-r--r--src/libs/kdtools/lockfile_win.cpp (renamed from src/libs/kdtools/kdlockfile_win.cpp)33
-rw-r--r--src/libs/kdtools/runoncechecker.cpp (renamed from src/libs/kdtools/kdrunoncechecker.cpp)16
-rw-r--r--src/libs/kdtools/runoncechecker.h (renamed from src/libs/kdtools/kdrunoncechecker.h)20
-rw-r--r--src/libs/kdtools/selfrestarter.cpp (renamed from src/libs/kdtools/kdselfrestarter.cpp)22
-rw-r--r--src/libs/kdtools/selfrestarter.h (renamed from src/libs/kdtools/kdselfrestarter.h)14
-rw-r--r--src/libs/kdtools/sysinfo.cpp (renamed from src/libs/kdtools/kdsysinfo.cpp)2
-rw-r--r--src/libs/kdtools/sysinfo.h (renamed from src/libs/kdtools/kdsysinfo.h)8
-rw-r--r--src/libs/kdtools/sysinfo_mac.cpp (renamed from src/libs/kdtools/kdsysinfo_mac.cpp)2
-rw-r--r--src/libs/kdtools/sysinfo_x11.cpp (renamed from src/libs/kdtools/kdsysinfo_x11.cpp)4
-rw-r--r--src/libs/kdtools/task.cpp (renamed from src/libs/kdtools/kdupdatertask.cpp)2
-rw-r--r--src/libs/kdtools/task.h (renamed from src/libs/kdtools/kdupdatertask.h)8
-rw-r--r--src/libs/kdtools/update.cpp (renamed from src/libs/kdtools/kdupdaterupdate.cpp)28
-rw-r--r--src/libs/kdtools/update.h (renamed from src/libs/kdtools/kdupdaterupdate.h)20
-rw-r--r--src/libs/kdtools/updatefinder.cpp (renamed from src/libs/kdtools/kdupdaterupdatefinder.cpp)138
-rw-r--r--src/libs/kdtools/updatefinder.h (renamed from src/libs/kdtools/kdupdaterupdatefinder.h)19
-rw-r--r--src/libs/kdtools/updateoperation.cpp (renamed from src/libs/kdtools/kdupdaterupdateoperation.cpp)124
-rw-r--r--src/libs/kdtools/updateoperation.h (renamed from src/libs/kdtools/kdupdaterupdateoperation.h)20
-rw-r--r--src/libs/kdtools/updateoperationfactory.cpp (renamed from src/libs/kdtools/kdupdaterupdateoperationfactory.cpp)9
-rw-r--r--src/libs/kdtools/updateoperationfactory.h (renamed from src/libs/kdtools/kdupdaterupdateoperationfactory.h)19
-rw-r--r--src/libs/kdtools/updateoperations.cpp (renamed from src/libs/kdtools/kdupdaterupdateoperations.cpp)214
-rw-r--r--src/libs/kdtools/updateoperations.h (renamed from src/libs/kdtools/kdupdaterupdateoperations.h)29
-rw-r--r--src/libs/kdtools/updater.h (renamed from src/libs/kdtools/kdupdater.h)6
-rw-r--r--src/libs/kdtools/updatesinfo.cpp (renamed from src/libs/kdtools/kdupdaterupdatesinfo.cpp)18
-rw-r--r--src/libs/kdtools/updatesinfo_p.h (renamed from src/libs/kdtools/kdupdaterupdatesinfo_p.h)10
-rw-r--r--src/libs/kdtools/updatesinfodata_p.h (renamed from src/libs/kdtools/kdupdaterupdatesinfodata_p.h)12
50 files changed, 1025 insertions, 2046 deletions
diff --git a/src/libs/kdtools/environment.h b/src/libs/kdtools/environment.h
index a17d0a4a0..748063959 100644
--- a/src/libs/kdtools/environment.h
+++ b/src/libs/kdtools/environment.h
@@ -31,8 +31,8 @@
**
****************************************************************************/
-#ifndef LIBINSTALLER_ENVIRONMENT_H
-#define LIBINSTALLER_ENVIRONMENT_H
+#ifndef ENVIRONMENT_H
+#define ENVIRONMENT_H
#include "kdtoolsglobal.h"
@@ -69,4 +69,4 @@ private:
} // namespace KDUpdater
-#endif
+#endif // ENVIRONMENT_H
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.cpp b/src/libs/kdtools/filedownloader.cpp
index 4027dda8a..508cc395d 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.cpp
+++ b/src/libs/kdtools/filedownloader.cpp
@@ -31,13 +31,14 @@
**
****************************************************************************/
-#include "kdupdaterfiledownloader_p.h"
-#include "kdupdaterfiledownloaderfactory.h"
+#include "filedownloader_p.h"
+#include "filedownloaderfactory.h"
#include "ui_authenticationdialog.h"
-#include <fileutils.h>
+#include "fileutils.h"
#include <QDialog>
+#include <QDir>
#include <QFile>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkProxyFactory>
@@ -695,8 +696,8 @@ void KDUpdater::LocalFileDownloader::doDownload()
d->source = new QFile(localFile, this);
if (!d->source->open(QFile::ReadOnly)) {
onError();
- setDownloadAborted(tr("Cannot open source file '%1' for reading.").arg(QFileInfo(localFile)
- .fileName()));
+ setDownloadAborted(tr("Cannot open file \"%1\" for reading: %2").arg(QFileInfo(localFile)
+ .fileName(), d->source->errorString()));
return;
}
@@ -711,8 +712,8 @@ void KDUpdater::LocalFileDownloader::doDownload()
if (!d->destination->isOpen()) {
onError();
- setDownloadAborted(tr("Cannot open destination file '%1' for writing.")
- .arg(QFileInfo(d->destination->fileName()).fileName()));
+ setDownloadAborted(tr("Cannot open file \"%1\" for writing: %2")
+ .arg(QFileInfo(d->destination->fileName()).fileName(), d->destination->errorString()));
return;
}
@@ -784,8 +785,9 @@ void KDUpdater::LocalFileDownloader::timerEvent(QTimerEvent *event)
killTimer(d->timerId);
d->timerId = -1;
onError();
- setDownloadAborted(tr("Writing to %1 failed: %2").arg(d->destination->fileName(),
- d->destination->errorString()));
+ setDownloadAborted(tr("Writing to file \"%1\" failed: %2").arg(
+ QDir::toNativeSeparators(d->destination->fileName()),
+ d->destination->errorString()));
return;
}
toWrite -= numWritten;
@@ -974,7 +976,7 @@ void KDUpdater::ResourceFileDownloader::timerEvent(QTimerEvent *event)
onError();
killTimer(d->timerId);
emit downloadProgress(1);
- setDownloadAborted(tr("Could not read resource file \"%1\". Reason:").arg(downloadedFileName(),
+ setDownloadAborted(tr("Cannot read resource file \"%1\": %2").arg(downloadedFileName(),
d->destFile.errorString()));
return;
}
@@ -1058,7 +1060,7 @@ struct KDUpdater::HttpDownloader::Private
void shutDown()
{
- disconnect(http, SIGNAL(finished()), q, SLOT(httpReqFinished()));
+ disconnect(http, &QNetworkReply::finished, q, &HttpDownloader::httpReqFinished);
http->deleteLater();
http = 0;
destination->close();
@@ -1076,11 +1078,11 @@ KDUpdater::HttpDownloader::HttpDownloader(QObject *parent)
, d(new Private(this))
{
#ifndef QT_NO_SSL
- connect(&d->manager, SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
- this, SLOT(onSslErrors(QNetworkReply*, QList<QSslError>)));
+ connect(&d->manager, &QNetworkAccessManager::sslErrors,
+ this, &HttpDownloader::onSslErrors);
#endif
- connect(&d->manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this,
- SLOT(onAuthenticationRequired(QNetworkReply*, QAuthenticator*)));
+ connect(&d->manager, &QNetworkAccessManager::authenticationRequired,
+ this, &HttpDownloader::onAuthenticationRequired);
}
/*!
@@ -1162,7 +1164,7 @@ void KDUpdater::HttpDownloader::httpReadyRead()
const QString error = d->destination->errorString();
const QString fileName = d->destination->fileName();
d->shutDown();
- setDownloadAborted(tr("Cannot download %1: Writing to file '%2' failed: %3")
+ setDownloadAborted(tr("Cannot download %1. Writing to file \"%2\" failed: %3")
.arg(url().toString(), fileName, error));
return;
}
@@ -1292,12 +1294,12 @@ void KDUpdater::HttpDownloader::startDownload(const QUrl &url)
d->manager.setProxyFactory(proxyFactory());
d->http = d->manager.get(QNetworkRequest(url));
- connect(d->http, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
- connect(d->http, SIGNAL(downloadProgress(qint64, qint64)), this,
- SLOT(httpReadProgress(qint64, qint64)));
- connect(d->http, SIGNAL(finished()), this, SLOT(httpReqFinished()));
- connect(d->http, SIGNAL(error(QNetworkReply::NetworkError)), this,
- SLOT(httpError(QNetworkReply::NetworkError)));
+ connect(d->http, &QIODevice::readyRead, this, &HttpDownloader::httpReadyRead);
+ connect(d->http, &QNetworkReply::downloadProgress,
+ this, &HttpDownloader::httpReadProgress);
+ connect(d->http, &QNetworkReply::finished, this, &HttpDownloader::httpReqFinished);
+ void (QNetworkReply::*errorSignal)(QNetworkReply::NetworkError) = &QNetworkReply::error;
+ connect(d->http, errorSignal, this, &HttpDownloader::httpError);
if (d->destFileName.isEmpty()) {
QTemporaryFile *file = new QTemporaryFile(this);
@@ -1312,7 +1314,7 @@ void KDUpdater::HttpDownloader::startDownload(const QUrl &url)
const QString error = d->destination->errorString();
const QString fileName = d->destination->fileName();
d->shutDown();
- setDownloadAborted(tr("Cannot download %1: Could not create %2: %3").arg(
+ setDownloadAborted(tr("Cannot download %1. Cannot create file \"%2\": %3").arg(
url.toString(), fileName, error));
}
}
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.h b/src/libs/kdtools/filedownloader.h
index 989d46c30..4d19bad24 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.h
+++ b/src/libs/kdtools/filedownloader.h
@@ -31,8 +31,8 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_FILE_DOWNLOADER_H
-#define KD_UPDATER_FILE_DOWNLOADER_H
+#ifndef FILEDOWNLOADER_H
+#define FILEDOWNLOADER_H
#include "kdtoolsglobal.h"
@@ -109,10 +109,6 @@ Q_SIGNALS:
void downloadStatus(const QString &status);
void downloadProgress(qint64 bytesReceived, qint64 bytesToReceive);
void authenticatorChanged(const QAuthenticator &authenticator);
-
-#ifndef Q_MOC_RUN
-private:
-#endif
void downloadCompleted();
void downloadAborted(const QString &errorMessage);
@@ -147,4 +143,4 @@ private:
} // namespace KDUpdater
-#endif // KD_UPDATER_FILE_DOWNLOADER_H
+#endif // FILEDOWNLOADER_H
diff --git a/src/libs/kdtools/kdupdaterfiledownloader_p.h b/src/libs/kdtools/filedownloader_p.h
index 0b1016bee..f81ff53c9 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader_p.h
+++ b/src/libs/kdtools/filedownloader_p.h
@@ -31,10 +31,10 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_FILE_DOWNLOADER_P_H
-#define KD_UPDATER_FILE_DOWNLOADER_P_H
+#ifndef FILEDOWNLOADER_P_H
+#define FILEDOWNLOADER_P_H
-#include "kdupdaterfiledownloader.h"
+#include "filedownloader.h"
#include <QtNetwork/QNetworkReply>
@@ -146,4 +146,4 @@ private:
} // namespace KDUpdater
-#endif // KD_UPDATER_FILE_DOWNLOADER_P_H
+#endif // FILEDOWNLOADER_P_H
diff --git a/src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp b/src/libs/kdtools/filedownloaderfactory.cpp
index 1a7b9fb47..cebedcc30 100644
--- a/src/libs/kdtools/kdupdaterfiledownloaderfactory.cpp
+++ b/src/libs/kdtools/filedownloaderfactory.cpp
@@ -31,8 +31,8 @@
**
****************************************************************************/
-#include "kdupdaterfiledownloaderfactory.h"
-#include "kdupdaterfiledownloader_p.h"
+#include "filedownloaderfactory.h"
+#include "filedownloader_p.h"
#include <QtNetwork/QSslSocket>
@@ -73,7 +73,7 @@ FileDownloaderFactory::FileDownloaderFactory()
if (QSslSocket::supportsSsl())
registerFileDownloader<HttpDownloader>(QLatin1String("https"));
else
- qWarning() << "Could not register file downloader for https protocol: QSslSocket::supportsSsl() returns false";
+ qWarning() << "Cannot register file downloader for https protocol: QSslSocket::supportsSsl() returns false";
#endif
d->m_followRedirects = false;
@@ -154,10 +154,9 @@ bool FileDownloaderFactory::isSupportedScheme(const QString &scheme)
*/
FileDownloader *FileDownloaderFactory::create(const QString &scheme, QObject *parent) const
{
- FileDownloader *downloader = KDGenericFactory<FileDownloader>::create(scheme);
+ FileDownloader *downloader =
+ GenericFactory<FileDownloader, QString, QObject*>::create(scheme, parent);
if (downloader != 0) {
- downloader->setParent(parent);
- downloader->setScheme(scheme);
downloader->setFollowRedirects(d->m_followRedirects);
downloader->setIgnoreSslErrors(d->m_ignoreSslErrors);
if (d->m_factory)
diff --git a/src/libs/kdtools/kdupdaterfiledownloaderfactory.h b/src/libs/kdtools/filedownloaderfactory.h
index c0ec8893b..fbb2b5d48 100644
--- a/src/libs/kdtools/kdupdaterfiledownloaderfactory.h
+++ b/src/libs/kdtools/filedownloaderfactory.h
@@ -31,11 +31,11 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_FILE_DOWNLOADER_FACTORY_H
-#define KD_UPDATER_FILE_DOWNLOADER_FACTORY_H
+#ifndef FILEDOWNLOADERFACTORY_H
+#define FILEDOWNLOADERFACTORY_H
-#include "kdupdater.h"
-#include <kdgenericfactory.h>
+#include "genericfactory.h"
+#include "updater.h"
#include <QtCore/QStringList>
#include <QtCore/QUrl>
@@ -57,7 +57,8 @@ public:
virtual FileDownloaderProxyFactory *clone() const = 0;
};
-class KDTOOLS_EXPORT FileDownloaderFactory : public KDGenericFactory<FileDownloader>
+class KDTOOLS_EXPORT FileDownloaderFactory : public GenericFactory<FileDownloader, QString,
+ QObject*>
{
Q_DISABLE_COPY(FileDownloaderFactory)
struct FileDownloaderFactoryData {
@@ -102,4 +103,4 @@ private:
} // namespace KDUpdater
-#endif // KD_UPDATER_FILE_DOWNLOADER_FACTORY_H
+#endif // FILEDOWNLOADERFACTORY_H
diff --git a/src/libs/kdtools/genericfactory.cpp b/src/libs/kdtools/genericfactory.cpp
new file mode 100644
index 000000000..e29a8da4a
--- /dev/null
+++ b/src/libs/kdtools/genericfactory.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "genericfactory.h"
+
+/*!
+ \inmodule kdupdater
+ \namespace KDUpdater
+ \brief The KDUpdater classes provide functions to automatically detect
+ updates to applications, to retrieve them from external repositories, and to
+ install them.
+
+ KDUpdater classes are a fork of KDAB's general
+ \l{http://docs.kdab.com/kdtools/2.2.2/group__kdupdater.html}{KDUpdater module}.
+*/
+
+/*!
+ \inmodule kdupdater
+ \class GenericFactory
+ \brief The GenericFactory class implements a template-based generic factory.
+
+ GenericFactory is an implementation of the factory pattern. It can be used to produce
+ instances of different classes having a common superclass \c BASE. The user of the factory
+ registers those producible classes in the factory by using the identifier \c IDENTIFIER. That
+ identifier can then be used to produce as many instances of the registered product as the
+ user wants.
+
+ One factory instance is able to produce instances of different types of DERIVED classes only
+ when the constructor of DERIVED or the registered generator function have a common signature
+ for all DERIVED classes. This signature is described by the declaration order of ARGUMENTS. It
+ is referred to as SIGNATURE in the following paragraphs.
+
+ If a class derived from BASE does not contain a SIGNATURE matching the registered one for the
+ constructor or the generator function, it is not possible to create instances of it using one
+ instance of GenericFactory subclass. In that case, more than one GenericFactory subclass
+ and instance are needed.
+
+ It is possible to register a subclass of BASE inside an instance of GenericFactory subclass
+ using the registerProduct() function. At least one of the following conditions needs to be met:
+
+ \list
+ \li A global or static function with SIGNATURE exists.
+ \li The DERIVED class has a constructor with SIGNATURE.
+ \li The DERIVED class has a static function with SIGNATURE.
+ \endlist
+
+ To get a new instance of DERIVED, one needs to call the create() function. The value of
+ IDENTIFIER determines the product's subclass registered in the factory, while the values
+ of SIGNATURE are the actual arguments passed to the class constructor or the registered
+ generator function.
+*/
+
+/*!
+ \fn GenericFactory::GenericFactory()
+
+ Creates the generic factory.
+*/
+
+/*!
+ \fn GenericFactory::~GenericFactory()
+
+ Destroys the generic factory.
+*/
+
+/*!
+ \typedef GenericFactory::FactoryFunction
+
+ This typedef defines a factory function producing an object of type BASE.
+*/
+
+/*!
+ \fn void GenericFactory::registerProduct(const IDENTIFIER &id)
+
+ Registers a type DERIVED, identified by \a id in the factory. Any type with the same id gets
+ unregistered.
+*/
+
+/*!
+ \overload
+ \fn void GenericFactory::registerProduct(const IDENTIFIER &id, FactoryFunction func)
+
+ Registers a function \a func that can create the type DERIVED, identified by \a id in the
+ factory. Any type with the same id gets unregistered.
+*/
+
+/*!
+ \fn bool GenericFactory::containsProduct(const IDENTIFIER &id) const
+
+ Returns \c true if the factory contains a type with the \a id; otherwise returns false.
+*/
+
+/*!
+ \fn BASE *GenericFactory::create(const IDENTIFIER &id, ARGUMENTS... args) const
+
+ Creates and returns the type identified by \a id, but automatically upcasted to BASE. Ownership
+ of the type is transferred to the caller.
+*/
diff --git a/src/libs/kdtools/genericfactory.h b/src/libs/kdtools/genericfactory.h
new file mode 100644
index 000000000..8588ada5e
--- /dev/null
+++ b/src/libs/kdtools/genericfactory.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GENERICFACTORY_H
+#define GENERICFACTORY_H
+
+#include "kdtoolsglobal.h"
+
+#include <QtCore/QHash>
+
+template <typename BASE, typename IDENTIFIER = QString, typename... ARGUMENTS>
+class GenericFactory
+{
+public:
+ virtual ~GenericFactory() {}
+
+ typedef BASE *(*FactoryFunction)(ARGUMENTS...);
+
+ template <typename DERIVED>
+ void registerProduct(const IDENTIFIER &id)
+ {
+ m_hash.insert(id, &GenericFactory::create<DERIVED>);
+ }
+
+ void registerProduct(const IDENTIFIER &id, FactoryFunction func)
+ {
+ m_hash.insert(id, func);
+ }
+
+ bool containsProduct(const IDENTIFIER &id) const
+ {
+ return m_hash.contains(id);
+ }
+
+ BASE *create(const IDENTIFIER &id, ARGUMENTS... args) const
+ {
+ const auto it = m_hash.constFind(id);
+ if (it == m_hash.constEnd())
+ return 0;
+ return (*it)(std::forward<ARGUMENTS>(args)...);
+ }
+
+protected:
+ GenericFactory() = default;
+
+private:
+ template <typename DERIVED>
+ static BASE *create(ARGUMENTS... args)
+ {
+ return new DERIVED(std::forward<ARGUMENTS>(args)...);
+ }
+
+ GenericFactory(const GenericFactory &) = delete;
+ GenericFactory &operator=(const GenericFactory &) = delete;
+
+private:
+ QHash<IDENTIFIER, FactoryFunction> m_hash;
+};
+
+#endif // GENERICFACTORY_H
diff --git a/src/libs/kdtools/kdjob.cpp b/src/libs/kdtools/job.cpp
index 5fbad7956..7d8036079 100644
--- a/src/libs/kdtools/kdjob.cpp
+++ b/src/libs/kdtools/job.cpp
@@ -31,30 +31,30 @@
**
****************************************************************************/
-#include "kdjob.h"
+#include "job.h"
-#include <QtCore/QDebug>
-#include <QtCore/QEventLoop>
-#include <QtCore/QTimer>
+#include <QDebug>
+#include <QEventLoop>
+#include <QTimer>
-// -- KDJob::Private
+// -- Job::Private
-class KDJob::Private
+class Job::Private
{
- KDJob *const q;
+ Job *const q;
public:
- explicit Private(KDJob *qq)
+ explicit Private(Job *qq)
: q(qq)
- , error(KDJob::NoError)
- , caps(KDJob::NoCapabilities)
+ , error(Job::NoError)
+ , caps(Job::NoCapabilities)
, autoDelete(true)
, totalAmount(100)
, processedAmount(0)
, m_timeout(-1)
{
- connect(&m_timer, SIGNAL(timeout()), q, SLOT(cancel()));
+ connect(&m_timer, &QTimer::timeout, q, &Job::cancel);
}
~Private()
@@ -83,7 +83,7 @@ public:
int error;
QString errorString;
- KDJob::Capabilities caps;
+ Job::Capabilities caps;
bool autoDelete;
quint64 totalAmount;
quint64 processedAmount;
@@ -92,93 +92,93 @@ public:
};
-// -- KDJob
+// -- Job
-KDJob::KDJob(QObject *parent)
+Job::Job(QObject *parent)
: QObject(parent),
d(new Private(this))
{
- connect(this, SIGNAL(finished(KDJob*)), this, SLOT(onFinished()));
+ connect(this, &Job::finished, this, &Job::onFinished);
}
-KDJob::~KDJob()
+Job::~Job()
{
delete d;
}
-bool KDJob::autoDelete() const
+bool Job::autoDelete() const
{
return d->autoDelete;
}
-void KDJob::setAutoDelete(bool autoDelete)
+void Job::setAutoDelete(bool autoDelete)
{
d->autoDelete = autoDelete;
}
-int KDJob::error() const
+int Job::error() const
{
return d->error;
}
-QString KDJob::errorString() const
+QString Job::errorString() const
{
return d->errorString;
}
-void KDJob::emitFinished()
+void Job::emitFinished()
{
emit finished(this);
}
-void KDJob::emitFinishedWithError(int error, const QString &errorString)
+void Job::emitFinishedWithError(int error, const QString &errorString)
{
d->error = error;
d->errorString = errorString;
emitFinished();
}
-void KDJob::setError(int error)
+void Job::setError(int error)
{
d->error = error;
}
-void KDJob::setErrorString(const QString &errorString)
+void Job::setErrorString(const QString &errorString)
{
d->errorString = errorString;
}
-void KDJob::waitForStarted()
+void Job::waitForStarted()
{
- d->waitForSignal(SIGNAL(started(KDJob*)));
+ d->waitForSignal(SIGNAL(started(Job*)));
}
-void KDJob::waitForFinished()
+void Job::waitForFinished()
{
- d->waitForSignal(SIGNAL(finished(KDJob*)));
+ d->waitForSignal(SIGNAL(finished(Job*)));
}
-KDJob::Capabilities KDJob::capabilities() const
+Job::Capabilities Job::capabilities() const
{
return d->caps;
}
-bool KDJob::hasCapability(Capability c) const
+bool Job::hasCapability(Capability c) const
{
return d->caps.testFlag(c);
}
-void KDJob::setCapabilities(Capabilities c)
+void Job::setCapabilities(Capabilities c)
{
d->caps = c;
}
-void KDJob::start()
+void Job::start()
{
QMetaObject::invokeMethod(this, "delayedStart", Qt::QueuedConnection);
}
-void KDJob::cancel()
+void Job::cancel()
{
if (d->caps & Cancelable) {
doCancel();
@@ -192,17 +192,17 @@ void KDJob::cancel()
}
}
-quint64 KDJob::totalAmount() const
+quint64 Job::totalAmount() const
{
return d->totalAmount;
}
-quint64 KDJob::processedAmount() const
+quint64 Job::processedAmount() const
{
return d->processedAmount;
}
-void KDJob::setTotalAmount(quint64 amount)
+void Job::setTotalAmount(quint64 amount)
{
if (d->totalAmount == amount)
return;
@@ -214,22 +214,22 @@ void KDJob::setTotalAmount(quint64 amount)
Returns the timeout in milliseconds before the job's cancel slot gets triggered. A return value
of -1 means there is currently no timeout used for the job.
*/
-int KDJob::timeout() const
+int Job::timeout() const
{
return d->m_timeout;
}
/*!
Sets the timeout in \a milliseconds before the job's cancel slot gets triggered. \note Only jobs
- that have the \c KDJob::Cancelable capability can be canceled by a timeout. A value of -1 will
+ that have the \c Job::Cancelable capability can be canceled by a timeout. A value of -1 will
stop the timeout mechanism.
*/
-void KDJob::setTimeout(int milliseconds)
+void Job::setTimeout(int milliseconds)
{
d->m_timeout = milliseconds;
}
-void KDJob::setProcessedAmount(quint64 amount)
+void Job::setProcessedAmount(quint64 amount)
{
if (d->processedAmount == amount)
return;
@@ -237,11 +237,11 @@ void KDJob::setProcessedAmount(quint64 amount)
emit progress(this, d->processedAmount, d->totalAmount);
}
-void KDJob::onFinished()
+void Job::onFinished()
{
d->m_timer.stop();
if (d->autoDelete)
deleteLater();
}
-#include "moc_kdjob.cpp"
+#include "moc_job.cpp"
diff --git a/src/libs/kdtools/kdjob.h b/src/libs/kdtools/job.h
index 78786c778..5df1b4bd4 100644
--- a/src/libs/kdtools/kdjob.h
+++ b/src/libs/kdtools/job.h
@@ -31,14 +31,14 @@
**
****************************************************************************/
-#ifndef KDTOOLS_KDJOB_H
-#define KDTOOLS_KDJOB_H
+#ifndef JOB_H
+#define JOB_H
#include "kdtoolsglobal.h"
#include <QtCore/QObject>
-class KDTOOLS_EXPORT KDJob : public QObject
+class KDTOOLS_EXPORT Job : public QObject
{
Q_OBJECT
class Private;
@@ -47,8 +47,8 @@ class KDTOOLS_EXPORT KDJob : public QObject
Q_PROPERTY(bool autoDelete READ autoDelete WRITE setAutoDelete)
public:
- explicit KDJob(QObject *parent = 0);
- ~KDJob();
+ explicit Job(QObject *parent = 0);
+ ~Job();
enum Error {
NoError = 0,
@@ -86,11 +86,11 @@ public Q_SLOTS:
void cancel();
Q_SIGNALS:
- void started(KDJob *job);
- void finished(KDJob *job);
+ void started(Job *job);
+ void finished(Job *job);
- void infoMessage(KDJob *job, const QString &message);
- void progress(KDJob *job, quint64 processed, quint64 total);
+ void infoMessage(Job *job, const QString &message);
+ void progress(Job *job, quint64 processed, quint64 total);
protected:
virtual void doStart() = 0;
@@ -115,6 +115,6 @@ private:
Q_PRIVATE_SLOT(d, void delayedStart())
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(KDJob::Capabilities)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Job::Capabilities)
-#endif // KDTOOLS_KDJOB_H
+#endif // JOB_H
diff --git a/src/libs/kdtools/kdgenericfactory.cpp b/src/libs/kdtools/kdgenericfactory.cpp
deleted file mode 100644
index 8bb13391c..000000000
--- a/src/libs/kdtools/kdgenericfactory.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "kdgenericfactory.h"
-
-/*!
- \inmodule kdupdater
- \class KDGenericFactory
- \brief The KDGenericFactory class implements a template-based generic factory.
-
- KDGenericFactory is an implementation of the factory pattern. It can be used to produce
- instances of different classes having a common superclass \c T_Product. The user of the
- factory registers those producible classes in the factory by using an identifier
- \c T_Identifier. That identifier can then be used to produce as many instances of the
- registered product as the user wants.
-
- The advanced user can even choose the type of the class the factory is using to store its
- FactoryFunctions by passing a \c T_Map template parameter. It defaults to QHash.
-
- KDGenericFactory expects the storage container to be a template class accepting \c T_Identifier
- and \c FactoryFunction as parameters. Additionally it needs to provide:
-
- \table
- \header
- \li Method
- \li Description
- \row
- \li \c {const_iterator}
- \li A type that provides a random-access iterator that can read a const element and
- when dereferenced has type \c {const &FactoryFunction}.
- \row
- \li \c {insert(T_Identifier, FactoryFunction)}
- \li A function that inserts a new item with \c T_Identifier as key and \c FactoryFunction
- as value. If there is already an item with \c T_Identifier as key, that item's value
- must be replaced with \c FactoryFunction.
- \row
- \li \c {find(T_Identifier)}
- \li A function returning an iterator pointing to the item with the key \c T_Identifier.
-
- \row
- \li \c {end()}
- \li A function returning an iterator pointing to the imaginary item after the last item.
-
- \row
- \li \c {size()}
- \li A function returning the number of items.
- \row
- \li \c {remove(T_Identifier)}
- \li A function removing all items that have the key \c T_Identifier.
- \row
- \li \c {keys()}
- \li A function returning a list of all the keys \c T_Identifier in an arbitrary order.
- \endtable
-
- The only two class templates that currently match this concept are QHash and QMap. QMultiHash
- and QMultiMap do not work, because they violate the requirement on insert() above and std::map
- and std::unordered_map do not match, because they do not have keys() and, because a dereferenced
- iterator has type \c {std::pair<const T_Identifier, FactoryFunction>} instead of just
- \c FactoryFunction.
-
- The following example shows how the general use case of KDGenericFactory looks like:
-
- \code
-
- class Fruit
- {
- };
-
- class Apple : public Fruit
- {
- };
-
- class Pear : public Fruit
- {
- };
-
- int main()
- {
- // creates a common fruit "factory"
- KDGenericFactory< Fruit > fruitPlantation;
- // registers the product "Apple"
- fruitPlantation.registerProduct< Apple >( "Apple" );
- // registers the product "Pear"
- fruitPlantation.registerProduct< Pear >( "Pear" );
-
- // lets create some stuff - here comes our tasty apple:
- Fruit* myApple = fruitPlantation.create( "Apple" );
-
- // and a pear, please:
- Fruit* myPear = fruitPlantation.create( "Pear" );
-
- // ohh - that doesn't work, returns a null pointer:
- Fruit* myCherry = fruitPlantation.create( "Cherry" );
- }
- \endcode
-*/
-
-/*!
- \fn KDGenericFactory::~KDGenericFactory()
-
- Destroys the generic factory.
-*/
-
-/*!
- \typedef KDGenericFactory::FactoryFunction
-
- This typedef defines a factory function producing an object of type T_Product.
-*/
-
-/*!
- \typedef KDGenericFactory::FactoryFunctionWithArg
-
- This typedef defines a factory function producing an object of type T_Product
- with the arguments specified by \a arg.
-*/
-
-/*!
- \fn KDGenericFactory::registerProduct( const T_Identifier& name )
-
- Registers a product of the type T, identified by \a name in the factory.
- Any type with the same name gets unregistered.
-
- If a product was registered via this method, it will be created using its
- default constructor.
-*/
-
-/*!
- \fn KDGenericFactory::registerProductWithArg(const T_Identifier &name)
-
- Registers a product of the type T, identified by \a name, with arguments.
- Any type with the same name gets unregistered.
-
- If a product was registered via this method, it will be created using its
- default constructor.
-*/
-
-/*!
- \fn KDGenericFactory::create( const T_Identifier& name ) const
-
- Creates and returns a product of the type T identified by \a name.
- Ownership of the product is transferred to the caller.
-*/
-
-/*!
- \fn KDGenericFactory::createWithArg(const T_Identifier &name, const T_Argument &arg) const
-
- Creates and returns a product of the type T identified by \a name with the
- arguments specified by \a arg.
- Ownership of the product is transferred to the caller.
-*/
diff --git a/src/libs/kdtools/kdgenericfactory.h b/src/libs/kdtools/kdgenericfactory.h
deleted file mode 100644
index d1a3e2954..000000000
--- a/src/libs/kdtools/kdgenericfactory.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef KDTOOLS__KDGENERICFACTORY_H
-#define KDTOOLS__KDGENERICFACTORY_H
-
-#include <kdtoolsglobal.h>
-
-#include <QtCore/QHash>
-
-template <typename T_Product, typename T_Identifier = QString, typename T_Argument = QString>
-class KDGenericFactory
-{
-public:
- virtual ~KDGenericFactory() {}
-
- typedef T_Product *(*FactoryFunction)();
- typedef T_Product *(*FactoryFunctionWithArg)(const T_Argument &arg);
-
- template <typename T>
- void registerProduct(const T_Identifier &name)
- {
-#ifdef Q_CC_MSVC
- FactoryFunction function = &KDGenericFactory::create<T>;
-#else // compile fix for old gcc
- FactoryFunction function = &create<T>;
-#endif
- map.insert(name, function);
- }
-
- T_Product *create(const T_Identifier &name) const
- {
- const typename QHash<T_Identifier, FactoryFunction>::const_iterator it = map.find(name);
- if (it == map.end())
- return 0;
- return (*it)();
- }
-
- template <typename T>
- void registerProductWithArg(const T_Identifier &name)
- {
-#ifdef Q_CC_MSVC
- FactoryFunctionWithArg function = &KDGenericFactory::create<T>;
-#else // compile fix for old gcc
- FactoryFunctionWithArg function = &create<T>;
-#endif
- map2.insert(name, function);
- }
-
- T_Product *createWithArg(const T_Identifier &name, const T_Argument &arg) const
- {
- const typename QHash<T_Identifier, FactoryFunctionWithArg>::const_iterator it = map2.find(name);
- if (it == map2.end())
- return 0;
- return (*it)(arg);
- }
-
-private:
- template <typename T>
- static T_Product *create()
- {
- return new T;
- }
-
- template <typename T>
- static T_Product *create(const T_Argument &arg)
- {
- return new T(arg);
- }
-
- QHash<T_Identifier, FactoryFunction> map;
- QHash<T_Identifier, FactoryFunctionWithArg> map2;
-};
-
-#endif
diff --git a/src/libs/kdtools/kdsysinfo_win.cpp b/src/libs/kdtools/kdsysinfo_win.cpp
index 2bd1a32d4..ea209ed95 100644
--- a/src/libs/kdtools/kdsysinfo_win.cpp
+++ b/src/libs/kdtools/kdsysinfo_win.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdsysinfo.h"
+#include "sysinfo.h"
#include <QLibrary>
#include <QStringList>
diff --git a/src/libs/kdtools/kdtools.pri b/src/libs/kdtools/kdtools.pri
index 520426096..eaa391e0f 100644
--- a/src/libs/kdtools/kdtools.pri
+++ b/src/libs/kdtools/kdtools.pri
@@ -5,53 +5,54 @@ DEFINES += BUILD_SHARED_KDTOOLS
FORMS += $$PWD/authenticationdialog.ui
HEADERS += $$PWD/kdtoolsglobal.h \
- $$PWD/kdjob.h \
- $$PWD/kdgenericfactory.h \
- $$PWD/kdselfrestarter.h \
- $$PWD/kdrunoncechecker.h \
- $$PWD/kdlockfile.h \
- $$PWD/kdsysinfo.h
-
-SOURCES += $$PWD/kdjob.cpp \
- $$PWD/kdselfrestarter.cpp \
- $$PWD/kdrunoncechecker.cpp \
- $$PWD/kdlockfile.cpp \
- $$PWD/kdsysinfo.cpp
-
-
-HEADERS += $$PWD/kdupdater.h \
- $$PWD/kdupdaterapplication.h \
- $$PWD/kdupdaterfiledownloader.h \
- $$PWD/kdupdaterfiledownloader_p.h \
- $$PWD/kdupdaterfiledownloaderfactory.h \
- $$PWD/kdupdaterpackagesinfo.h \
- $$PWD/kdupdaterupdate.h \
- $$PWD/kdupdaterupdateoperation.h \
- $$PWD/kdupdaterupdateoperationfactory.h \
- $$PWD/kdupdaterupdateoperations.h \
- $$PWD/kdupdaterupdatesourcesinfo.h \
- $$PWD/kdupdatertask.h \
- $$PWD/kdupdaterupdatefinder.h \
- $$PWD/kdupdaterupdatesinfo_p.h \
+ $$PWD/job.h \
+ $$PWD/genericfactory.h \
+ $$PWD/selfrestarter.h \
+ $$PWD/runoncechecker.h \
+ $$PWD/lockfile.h \
+ $$PWD/sysinfo.h
+
+SOURCES += $$PWD/job.cpp \
+ $$PWD/selfrestarter.cpp \
+ $$PWD/runoncechecker.cpp \
+ $$PWD/lockfile.cpp \
+ $$PWD/sysinfo.cpp
+
+
+HEADERS += $$PWD/updater.h \
+ $$PWD/filedownloader.h \
+ $$PWD/filedownloader_p.h \
+ $$PWD/filedownloaderfactory.h \
+ $$PWD/localpackagehub.h \
+ $$PWD/update.h \
+ $$PWD/updateoperation.h \
+ $$PWD/updateoperationfactory.h \
+ $$PWD/updateoperations.h \
+ $$PWD/task.h \
+ $$PWD/updatefinder.h \
+ $$PWD/updatesinfo_p.h \
$$PWD/environment.h \
- $$PWD/kdupdaterupdatesinfodata_p.h
-
-SOURCES += $$PWD/kdupdaterapplication.cpp \
- $$PWD/kdupdaterfiledownloader.cpp \
- $$PWD/kdupdaterfiledownloaderfactory.cpp \
- $$PWD/kdupdaterpackagesinfo.cpp \
- $$PWD/kdupdaterupdate.cpp \
- $$PWD/kdupdaterupdateoperation.cpp \
- $$PWD/kdupdaterupdateoperationfactory.cpp \
- $$PWD/kdupdaterupdateoperations.cpp \
- $$PWD/kdupdaterupdatesourcesinfo.cpp \
- $$PWD/kdupdatertask.cpp \
- $$PWD/kdupdaterupdatefinder.cpp \
- $$PWD/kdupdaterupdatesinfo.cpp \
+ $$PWD/updatesinfodata_p.h
+
+SOURCES += $$PWD/filedownloader.cpp \
+ $$PWD/filedownloaderfactory.cpp \
+ $$PWD/localpackagehub.cpp \
+ $$PWD/update.cpp \
+ $$PWD/updateoperation.cpp \
+ $$PWD/updateoperationfactory.cpp \
+ $$PWD/updateoperations.cpp \
+ $$PWD/task.cpp \
+ $$PWD/updatefinder.cpp \
+ $$PWD/updatesinfo.cpp \
$$PWD/environment.cpp
-unix:SOURCES += $$PWD/kdlockfile_unix.cpp
-win32:SOURCES += $$PWD/kdlockfile_win.cpp
-win32:SOURCES += $$PWD/kdsysinfo_win.cpp
-macx:SOURCES += $$PWD/kdsysinfo_mac.cpp
-unix:!macx:SOURCES += $$PWD/kdsysinfo_x11.cpp
+win32 {
+ SOURCES += $$PWD/lockfile_win.cpp \
+ $$PWD/kdsysinfo_win.cpp
+}
+
+unix {
+ SOURCES += $$PWD/lockfile_unix.cpp
+ osx: SOURCES += $$PWD/sysinfo_mac.cpp
+ else: SOURCES += $$PWD/sysinfo_x11.cpp
+}
diff --git a/src/libs/kdtools/kdtoolsglobal.h b/src/libs/kdtools/kdtoolsglobal.h
index 6cf288828..731df4a21 100644
--- a/src/libs/kdtools/kdtoolsglobal.h
+++ b/src/libs/kdtools/kdtoolsglobal.h
@@ -31,8 +31,8 @@
**
****************************************************************************/
-#ifndef KDTOOLS_KDTOOLSGLOBAL_H
-#define KDTOOLS_KDTOOLSGLOBAL_H
+#ifndef KDTOOLSGLOBAL_H
+#define KDTOOLSGLOBAL_H
#include <QtCore/QtGlobal>
@@ -46,5 +46,5 @@
# define KDTOOLS_EXPORT
#endif // KDTOOLS_SHARED
-#endif // KDTOOLS_KDTOOLSGLOBAL_H
+#endif // KDTOOLSGLOBAL_H
diff --git a/src/libs/kdtools/kdupdaterapplication.cpp b/src/libs/kdtools/kdupdaterapplication.cpp
deleted file mode 100644
index ec534fafb..000000000
--- a/src/libs/kdtools/kdupdaterapplication.cpp
+++ /dev/null
@@ -1,311 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "kdupdaterapplication.h"
-#include "kdupdaterpackagesinfo.h"
-#include "kdupdaterupdatesourcesinfo.h"
-
-#include <QCoreApplication>
-#include <QDebug>
-#include <QDir>
-
-using namespace KDUpdater;
-
-/*!
- \inmodule kdupdater
- \namespace KDUpdater
- \brief The KDUpdater classes provide functions to automatically detect
- updates to applications, to retrieve them from external repositories, and to
- install them.
-
- KDUpdater classes are a fork of KDAB's general
- \l{http://docs.kdab.com/kdtools/2.2.2/group__kdupdater.html}{KDUpdater module}.
-*/
-
-/*!
- \class KDUpdater::ConfigurationInterface
- \inmodule kdupdater
- \brief The ConfigurationInterface class provides an interface for configuring
- an application.
-*/
-
-/*!
- \fn KDUpdater::ConfigurationInterface::~ConfigurationInterface()
- Destroys the configuration interface.
-*/
-
-/*!
- \fn KDUpdater::ConfigurationInterface::value(const QString &key) const
- Returns the value of the key \a key.
-*/
-
-/*!
- \fn KDUpdater::ConfigurationInterface::setValue(const QString &key, const QVariant &value)
- Sets the value \a value for the key \a key.
-*/
-
-/*!
- \class KDUpdater::Application
- \inmodule kdupdater
- \brief The Application class represents an application that can be updated.
-
- A KDUpdater application is an application that interacts with one or more update servers and
- downloads or installs updates. This class helps in describing an application in terms of:
- \list
- \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:
- \list
- \li Application name
- \li Application version
- \endlist
-*/
-
-struct Application::ApplicationData
-{
- explicit ApplicationData(ConfigurationInterface *config) :
- packagesInfo(0),
- updateSourcesInfo(0),
- 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
- QFile f(i);
- if (f.exists() && !f.remove()) {
- qWarning("Could not delete file %s: %s", qPrintable(i), qPrintable(f.errorString()));
- filesForDelayedDeletion << i; // try again next time
- }
- }
- configurationInterface->setValue(QLatin1String("FilesForDelayedDeletion"), filesForDelayedDeletion);
- }
-
- ~ApplicationData()
- {
- delete packagesInfo;
- delete updateSourcesInfo;
- delete configurationInterface;
- }
-
- static Application *instance;
-
- QString applicationDirectory;
- PackagesInfo *packagesInfo;
- UpdateSourcesInfo *updateSourcesInfo;
- QStringList filesForDelayedDeletion;
- ConfigurationInterface *configurationInterface;
-};
-
-Application *Application::ApplicationData::instance = 0;
-
-/*!
- Constructs an application with the parent \a p and configuration class \a config.
-*/
-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() );
-
- ApplicationData::instance = this;
-}
-
-/*!
- Destroys the application.
-*/
-Application::~Application()
-{
- if (this == ApplicationData::instance)
- ApplicationData::instance = 0;
- delete d;
-}
-
-/*!
- Returns a previously created application instance.
-*/
-Application *Application::instance()
-{
- return ApplicationData::instance;
-}
-
-/*!
- Sets the application directory path directory to \a dir. The installation information and
- update sources XML files found in the new application directory will be used.
-*/
-void Application::setApplicationDirectory(const QString &dir)
-{
- if (d->applicationDirectory == dir)
- return;
-
- QDir dirObj(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));
-}
-
-/*!
- Returns the path to the application directory.
-*/
-QString Application::applicationDirectory() const
-{
- return d->applicationDirectory;
-}
-
-/*!
- Returns the application name. By default, QCoreApplication::applicationName() is returned.
-*/
-QString Application::applicationName() const
-{
- if (d->packagesInfo->isValid())
- return d->packagesInfo->applicationName();
-
- return QCoreApplication::applicationName();
-}
-
-/*!
- Returns the application version.
-*/
-QString Application::applicationVersion() const
-{
- if (d->packagesInfo->isValid())
- return d->packagesInfo->applicationVersion();
-
- 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.
- By default, this is assumed to be Packages.xml in the application directory.
-
- \sa KDUpdater::PackagesInfo::setFileName()
-*/
-void Application::setPackagesXMLFileName(const QString &fileName)
-{
- d->packagesInfo->setFileName(fileName);
-}
-
-/*!
- Returns the installation information XML file name.
-*/
-QString Application::packagesXMLFileName() const
-{
- return d->packagesInfo->fileName();
-}
-
-/*!
- Returns the KDUpdater::PackagesInfo object associated with this application.
-*/
-PackagesInfo* Application::packagesInfo() const
-{
- return d->packagesInfo;
-}
-
-/*!
- 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)
-{
- qDebug() << errorCode << error;
-}
-
-/*!
- Returns a list of files that are scheduled for delayed deletion.
-*/
-QStringList Application::filesForDelayedDeletion() const
-{
- return d->filesForDelayedDeletion;
-}
-
-/*!
- Schedules \a files for delayed deletion.
-*/
-void Application::addFilesForDelayedDeletion(const QStringList &files)
-{
- d->filesForDelayedDeletion << files;
- d->configurationInterface->setValue(QLatin1String("FilesForDelayedDeletion"), d->filesForDelayedDeletion);
-}
diff --git a/src/libs/kdtools/kdupdaterapplication.h b/src/libs/kdtools/kdupdaterapplication.h
deleted file mode 100644
index 8726bc8b3..000000000
--- a/src/libs/kdtools/kdupdaterapplication.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef KD_UPDATER_APPLICATION_H
-#define KD_UPDATER_APPLICATION_H
-
-#include "kdtoolsglobal.h"
-
-#include <QSettings>
-
-namespace KDUpdater {
-
-class PackagesInfo;
-class UpdateSourcesInfo;
-
-class ConfigurationInterface
-{
-public:
- 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
-{
- Q_OBJECT
-
-public:
- explicit Application(ConfigurationInterface *config = 0, QObject *parent = 0);
- ~Application();
-
- static Application *instance();
-
- void setApplicationDirectory(const QString &dir);
- QString applicationDirectory() const;
-
- QString applicationName() const;
- QString applicationVersion() const;
-
- void setPackagesXMLFileName(const QString &fileName);
- 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);
-
-public Q_SLOTS:
- void printError(int errorCode, const QString &error);
-
-private:
- struct ApplicationData;
- ApplicationData *d;
-};
-
-} // namespace KDUpdater
-
-#endif // KD_UPDATER_APPLICATION_H
diff --git a/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
deleted file mode 100644
index a434654db..000000000
--- a/src/libs/kdtools/kdupdaterupdatesourcesinfo.cpp
+++ /dev/null
@@ -1,480 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "kdupdaterupdatesourcesinfo.h"
-
-#include <QtXml/QDomElement>
-#include <QtXml/QDomDocument>
-#include <QtXml/QDomText>
-#include <QtXml/QDomCDATASection>
-#include <QFileInfo>
-#include <QFile>
-#include <QTextStream>
-
-using namespace KDUpdater;
-
-/*!
- \inmodule kdupdater
- \class KDUpdater::UpdateSourcesInfo
- \brief The UpdateSourcesInfo class provides access to information about the update sources set
- for the application.
-
- An update source is a repository that contains updates applicable for the application.
- 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:
-
- \list
- \li Get update sources information via the updateSourceInfoCount() and updateSourceInfo()
- methods.
- \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.
-*/
-
-/*!
- \fn KDUpdater::operator==(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
-
- Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false.
-*/
-
-/*!
- \fn KDUpdater::operator!=(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
-
- 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
-{
- bool operator()(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs) const
- {
- return lhs.priority > rhs.priority;
- }
-};
-
-
-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();
-}
-
-/*!
- Returns the update source info structure at \a index. If an invalid index is passed, the
- function returns a \l{default-constructed value}.
-*/
-UpdateSourceInfo UpdateSourcesInfo::updateSourceInfo(int index) const
-{
- if (index < 0 || index >= d->updateSourceInfoList.count())
- return UpdateSourceInfo();
-
- return d->updateSourceInfoList[index];
-}
-
-/*!
- Adds the given update source info \a info to this class. Upon successful addition, the class
- emits an updateSourceInfoAdded() signal.
-*/
-void UpdateSourcesInfo::addUpdateSourceInfo(const UpdateSourceInfo &info)
-{
- if (d->updateSourceInfoList.contains(info))
- return;
- d->updateSourceInfoList.push_back(info);
- std::sort(d->updateSourceInfoList.begin(), d->updateSourceInfoList.end(), UpdateSourceInfoPriorityHigherThan());
- emit updateSourceInfoAdded(info);
- d->modified = true;
-}
-
-/*!
- Removes the given update source info \a info from this class. Upon successful removal, the class
- emits an updateSourceInfoRemoved() signal.
-*/
-void UpdateSourcesInfo::removeUpdateSourceInfo(const UpdateSourceInfo &info)
-{
- if (!d->updateSourceInfoList.contains(info))
- return;
- d->updateSourceInfoList.removeAll(info);
- emit updateSourceInfoRemoved(info);
- d->modified = true;
-}
-
-/*!
- Reloads the update source information from update sources XML file.
-*/
-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)
-{
- 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);
-}
-
-void UpdateSourcesInfo::UpdateSourcesInfoData::addChildElement(QDomDocument &doc, QDomElement &parentE,
- const QString &tagName, const QString &text, bool htmlText)
-{
- QDomElement childE = doc.createElement(tagName);
- parentE.appendChild(childE);
- childE.appendChild(htmlText ? doc.createCDATASection(text) : doc.createTextNode(text));
-}
-
-/*!
- \inmodule kdupdater
- \class KDUpdater::UpdateSourceInfo
- \brief The UpdateSourceInfo class specifies a single update source.
-
- An update source is a repository that contains updates applicable for the application.
- This structure describes a single update source in terms of name, title, description,
- url, and priority.
-*/
-
-/*!
- \fn UpdateSourceInfo::UpdateSourceInfo()
-
- Constructs an empty update source info object. The object's priority is set to -1. All other
- class members are initialized using a \l{default-constructed value}.
-*/
-
-/*!
- \variable UpdateSourceInfo::name
- \brief The name of the update source.
-*/
-
-/*!
- \variable UpdateSourceInfo::title
- \brief The title of the update source.
-*/
-
-/*!
- \variable UpdateSourceInfo::description
- \brief The description of the update source.
-*/
-
-/*!
- \variable UpdateSourceInfo::url
- \brief The URL of the update source.
-*/
-
-/*!
- \variable UpdateSourceInfo::priority
- \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
- && lhs.url == rhs.url;
-}
-
-} // namespace KDUpdater
diff --git a/src/libs/kdtools/kdupdaterupdatesourcesinfo.h b/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
deleted file mode 100644
index c01805f2c..000000000
--- a/src/libs/kdtools/kdupdaterupdatesourcesinfo.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef KD_UPDATER_UPDATE_SOURCES_INFO_H
-#define KD_UPDATER_UPDATE_SOURCES_INFO_H
-
-#include "kdtoolsglobal.h"
-
-#include <QObject>
-#include <QVariant>
-#include <QUrl>
-
-namespace KDUpdater {
-
-struct KDTOOLS_EXPORT UpdateSourceInfo
-{
- UpdateSourceInfo() : priority(-1) { }
-
- QString name;
- QString title;
- QString description;
- QUrl url;
- int priority;
-};
-
-KDTOOLS_EXPORT bool operator==(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs);
-
-inline bool operator!=(const UpdateSourceInfo &lhs, const UpdateSourceInfo &rhs)
-{
- return !operator==(lhs, rhs);
-}
-
-class KDTOOLS_EXPORT UpdateSourcesInfo : public QObject
-{
- 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();
-
-Q_SIGNALS:
- void reset();
- void updateSourceInfoAdded(const UpdateSourceInfo &info);
- void updateSourceInfoRemoved(const UpdateSourceInfo &info);
-
-private:
- struct UpdateSourcesInfoData;
- QScopedPointer<UpdateSourcesInfoData> d;
-};
-
-} // namespace KDUpdater
-
-Q_DECLARE_METATYPE(KDUpdater::UpdateSourceInfo)
-
-#endif // KD_UPDATER_UPDATE_SOURCES_INFO_H
diff --git a/src/libs/kdtools/kdupdaterpackagesinfo.cpp b/src/libs/kdtools/localpackagehub.cpp
index c880b1d53..dc5ea32c7 100644
--- a/src/libs/kdtools/kdupdaterpackagesinfo.cpp
+++ b/src/libs/kdtools/localpackagehub.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.
@@ -31,20 +32,21 @@
**
****************************************************************************/
-#include "kdupdaterpackagesinfo.h"
+#include "localpackagehub.h"
#include "globals.h"
+#include "constants.h"
+#include <QDomDocument>
+#include <QDomElement>
#include <QFileInfo>
-#include <QtXml/QDomDocument>
-#include <QtXml/QDomElement>
-#include <QVector>
using namespace KDUpdater;
+using namespace QInstaller;
/*!
\inmodule kdupdater
- \class KDUpdater::PackagesInfo
- \brief The PackagesInfo class provides access to information about packages installed on the
+ \class KDUpdater::LocalPackageHub
+ \brief The LocalPackageHub class provides access to information about packages installed on the
application side.
This class parses the \e {installation information} XML file specified via the setFileName()
@@ -55,14 +57,10 @@ using namespace KDUpdater;
\li Get information about the number of packages installed and their meta-data via the
packageInfoCount() and packageInfo() methods.
\endlist
-
- Instances of this class cannot be created. Each instance of KDUpdater::Application has one
- instance of this class associated with it. You can fetch a pointer to an instance of this class
- for an application via the KDUpdater::Application::packagesInfo() method.
*/
/*!
- \enum PackagesInfo::Error
+ \enum LocalPackageHub::Error
Error codes related to retrieving information about installed packages:
\value NoError No error occurred.
@@ -76,64 +74,71 @@ using namespace KDUpdater;
descriptions.
*/
-struct PackagesInfo::PackagesInfoData
+struct LocalPackageHub::PackagesInfoData
{
PackagesInfoData() :
- error(PackagesInfo::NotYetReadError),
+ error(LocalPackageHub::NotYetReadError),
modified(false)
{}
QString errorMessage;
- PackagesInfo::Error error;
+ LocalPackageHub::Error error;
QString fileName;
QString applicationName;
QString applicationVersion;
bool modified;
- QVector<PackageInfo> packageInfoList;
+ QMap<QString, LocalPackage> m_packageInfoMap;
void addPackageFrom(const QDomElement &packageE);
void setInvalidContentError(const QString &detail);
};
-void PackagesInfo::PackagesInfoData::setInvalidContentError(const QString &detail)
+void LocalPackageHub::PackagesInfoData::setInvalidContentError(const QString &detail)
{
- error = PackagesInfo::InvalidContentError;
+ error = LocalPackageHub::InvalidContentError;
errorMessage = tr("%1 contains invalid content: %2").arg(fileName, detail);
}
/*!
- \internal
+ Constructs a local package hub. To fully setup the class you have to call setFileName().
+
+ \sa setFileName
*/
-PackagesInfo::PackagesInfo(QObject *parent)
- : QObject(parent),
- d(new PackagesInfoData())
+LocalPackageHub::LocalPackageHub()
+ : d(new PackagesInfoData())
{
}
/*!
- \internal
+ Destructor
*/
-PackagesInfo::~PackagesInfo()
+LocalPackageHub::~LocalPackageHub()
{
writeToDisk();
delete d;
}
/*!
- Returns \c true if PackagesInfo is valid; otherwise returns \c false. You
+ Returns \c true if LocalPackageHub is valid; otherwise returns \c false. You
can use the errorString() method to receive a descriptive error message.
*/
-bool PackagesInfo::isValid() const
+bool LocalPackageHub::isValid() const
+{
+ return d->error <= NotYetReadError;
+}
+
+/*!
+ Returns a list of all local installed packages.
+*/
+QStringList LocalPackageHub::packageNames() const
{
- if (!d->fileName.isEmpty())
- return d->error <= NotYetReadError;
- return d->error == NoError;
+ return d->m_packageInfoMap.keys();
}
/*!
Returns a human-readable description of the last error that occurred.
*/
-QString PackagesInfo::errorString() const
+QString LocalPackageHub::errorString() const
{
return d->errorMessage;
}
@@ -142,7 +147,7 @@ QString PackagesInfo::errorString() const
Returns the error that was found during the processing of the installation information XML file.
If no error was found, returns NoError.
*/
-PackagesInfo::Error PackagesInfo::error() const
+LocalPackageHub::Error LocalPackageHub::error() const
{
return d->error;
}
@@ -150,10 +155,8 @@ PackagesInfo::Error PackagesInfo::error() const
/*!
Sets the complete file name of the installation information XML file to \a fileName. The function
also issues a call to refresh() to reload installation information from the XML file.
-
- \sa KDUpdater::Application::setPackagesXMLFileName()
*/
-void PackagesInfo::setFileName(const QString &fileName)
+void LocalPackageHub::setFileName(const QString &fileName)
{
if (d->fileName == fileName)
return;
@@ -165,7 +168,7 @@ void PackagesInfo::setFileName(const QString &fileName)
/*!
Returns the name of the installation information XML file that this class refers to.
*/
-QString PackagesInfo::fileName() const
+QString LocalPackageHub::fileName() const
{
return d->fileName;
}
@@ -174,7 +177,7 @@ QString PackagesInfo::fileName() const
Sets the application name to \a name. By default, this is the name specified in the
\c <ApplicationName> element of the installation information XML file.
*/
-void PackagesInfo::setApplicationName(const QString &name)
+void LocalPackageHub::setApplicationName(const QString &name)
{
d->applicationName = name;
}
@@ -182,7 +185,7 @@ void PackagesInfo::setApplicationName(const QString &name)
/*!
Returns the application name.
*/
-QString PackagesInfo::applicationName() const
+QString LocalPackageHub::applicationName() const
{
return d->applicationName;
}
@@ -191,7 +194,7 @@ QString PackagesInfo::applicationName() const
Sets the application version to \a version. By default, this is the version specified in the
\c <ApplicationVersion> element of the installation information XML file.
*/
-void PackagesInfo::setApplicationVersion(const QString &version)
+void LocalPackageHub::setApplicationVersion(const QString &version)
{
d->applicationVersion = version;
}
@@ -199,51 +202,34 @@ void PackagesInfo::setApplicationVersion(const QString &version)
/*!
Returns the application version.
*/
-QString PackagesInfo::applicationVersion() const
+QString LocalPackageHub::applicationVersion() const
{
return d->applicationVersion;
}
/*!
- Returns the number of KDUpdater::PackageInfo objects contained in this class.
+ Returns the number of KDUpdater::LocalPackage objects contained in this class.
*/
-int PackagesInfo::packageInfoCount() const
+int LocalPackageHub::packageInfoCount() const
{
- return d->packageInfoList.count();
+ return d->m_packageInfoMap.count();
}
/*!
- Returns the package info structure at \a index. If an invalid index is passed, the
+ Returns the package info structure whose name is \a pkgName. If no such package was found, this
function returns a \l{default-constructed value}.
*/
-PackageInfo PackagesInfo::packageInfo(int index) const
-{
- if (index < 0 || index >= d->packageInfoList.count())
- return PackageInfo();
-
- return d->packageInfoList.at(index);
-}
-
-/*!
- Returns the index of the package whose name is \a pkgName. If no such package was found, this
- function returns -1.
-*/
-int PackagesInfo::findPackageInfo(const QString &pkgName) const
+LocalPackage LocalPackageHub::packageInfo(const QString &pkgName) const
{
- for (int i = 0; i < d->packageInfoList.count(); i++) {
- if (d->packageInfoList[i].name == pkgName)
- return i;
- }
-
- return -1;
+ return d->m_packageInfoMap.value(pkgName);
}
/*!
Returns all package info structures.
*/
-QVector<PackageInfo> PackagesInfo::packageInfos() const
+QList<LocalPackage> LocalPackageHub::packageInfos() const
{
- return d->packageInfoList;
+ return d->m_packageInfoMap.values();
}
/*!
@@ -251,12 +237,12 @@ QVector<PackageInfo> PackagesInfo::packageInfos() const
and applicationVersion() are lost after this function returns. The function emits a reset()
signal after completion.
*/
-void PackagesInfo::refresh()
+void LocalPackageHub::refresh()
{
// First clear internal variables
d->applicationName.clear();
d->applicationVersion.clear();
- d->packageInfoList.clear();
+ d->m_packageInfoMap.clear();
d->modified = false;
QFile file(d->fileName);
@@ -265,15 +251,13 @@ void PackagesInfo::refresh()
if (!file.exists()) {
d->error = NotYetReadError;
d->errorMessage = tr("The file %1 does not exist.").arg(d->fileName);
- emit reset();
return;
}
// Open Packages.xml
if (!file.open(QFile::ReadOnly)) {
d->error = CouldNotReadPackageFileError;
- d->errorMessage = tr("Could not open %1.").arg(d->fileName);
- emit reset();
+ d->errorMessage = tr("Cannot open %1.").arg(d->fileName);
return;
}
@@ -289,7 +273,6 @@ void PackagesInfo::refresh()
QString::number(parseErrorLine),
QString::number(parseErrorColumn),
parseErrorMessage);
- emit reset();
return;
}
file.close();
@@ -297,8 +280,8 @@ void PackagesInfo::refresh()
// Now populate information from the XML file.
QDomElement rootE = doc.documentElement();
if (rootE.tagName() != QLatin1String("Packages")) {
- d->setInvalidContentError(tr("Root element %1 unexpected, should be 'Packages'.").arg(rootE.tagName()));
- emit reset();
+ d->setInvalidContentError(tr("Root element %1 unexpected, should be 'Packages'.")
+ .arg(rootE.tagName()));
return;
}
@@ -319,74 +302,65 @@ void PackagesInfo::refresh()
d->error = NoError;
d->errorMessage.clear();
- emit reset();
}
/*!
Marks the package specified by \a name as installed. Sets the values of
- \a version, \a title, \a description, \a dependencies, \a forcedInstallation,
- \a virtualComp, \a uncompressedSize, and \a inheritVersionFrom for the
- package.
-
- Returns \c true if the installation information was modified.
-
-*/
-bool PackagesInfo::installPackage(const QString &name, const QString &version,
- const QString &title, const QString &description,
- const QStringList &dependencies, bool forcedInstallation,
- bool virtualComp, quint64 uncompressedSize,
- const QString &inheritVersionFrom)
+ \a version,
+ \a title,
+ \a description,
+ \a dependencies,
+ \a autoDependencies,
+ \a forcedInstallation,
+ \a virtualComp,
+ \a uncompressedSize,
+ \a inheritVersionFrom,
+ and \a checkable for the package.
+*/
+void LocalPackageHub::addPackage(const QString &name,
+ const QString &version,
+ const QString &title,
+ const QString &description,
+ const QStringList &dependencies,
+ const QStringList &autoDependencies,
+ bool forcedInstallation,
+ bool virtualComp,
+ quint64 uncompressedSize,
+ const QString &inheritVersionFrom,
+ bool checkable)
{
- if (findPackageInfo(name) != -1)
- return updatePackage(name, version, QDate::currentDate());
-
- PackageInfo info;
- info.name = name;
- info.version = version;
- info.inheritVersionFrom = inheritVersionFrom;
- info.installDate = QDate::currentDate();
- info.title = title;
- info.description = description;
- info.dependencies = dependencies;
- info.forcedInstallation = forcedInstallation;
- info.virtualComp = virtualComp;
- info.uncompressedSize = uncompressedSize;
- d->packageInfoList.push_back(info);
- d->modified = true;
- return true;
-}
-
-/*!
- Updates the package specified by \a name and sets its version to \a version
- and the last update date to \a date.
-
- Returns \c false if the package is not found.
-*/
-bool PackagesInfo::updatePackage(const QString &name, const QString &version, const QDate &date)
-{
- int index = findPackageInfo(name);
-
- if (index == -1)
- return false;
-
- d->packageInfoList[index].version = version;
- d->packageInfoList[index].lastUpdateDate = date;
+ // TODO: This somewhat unexpected, remove?
+ if (d->m_packageInfoMap.contains(name)) {
+ // TODO: What about the other fields, update?
+ d->m_packageInfoMap[name].version = version;
+ d->m_packageInfoMap[name].lastUpdateDate = QDate::currentDate();
+ } else {
+ LocalPackage info;
+ info.name = name;
+ info.version = version;
+ info.inheritVersionFrom = inheritVersionFrom;
+ info.installDate = QDate::currentDate();
+ info.title = title;
+ info.description = description;
+ info.dependencies = dependencies;
+ info.autoDependencies = autoDependencies;
+ info.forcedInstallation = forcedInstallation;
+ info.virtualComp = virtualComp;
+ info.uncompressedSize = uncompressedSize;
+ info.checkable = checkable;
+ d->m_packageInfoMap.insert(name, info);
+ }
d->modified = true;
- return true;
}
/*!
- Removes the package specified by \a name.
-
- Returns \c false if the package is not found.
+ Removes the package specified by \a name. Returns \c false if the package is not found.
*/
-bool PackagesInfo::removePackage(const QString &name)
+bool LocalPackageHub::removePackage(const QString &name)
{
- const int index = findPackageInfo(name);
- if (index == -1)
+ if (d->m_packageInfoMap.remove(name) <= 0)
return false;
- d->packageInfoList.remove(index);
d->modified = true;
return true;
}
@@ -409,9 +383,9 @@ static void addTextChildHelper(QDomNode *node,
/*!
Writes the installation information file to disk.
*/
-void PackagesInfo::writeToDisk()
+void LocalPackageHub::writeToDisk()
{
- if (d->modified && (!d->packageInfoList.isEmpty() || QFile::exists(d->fileName))) {
+ if (d->modified && (!d->m_packageInfoMap.isEmpty() || QFile::exists(d->fileName))) {
QDomDocument doc;
QDomElement root = doc.createElement(QLatin1String("Packages")) ;
doc.appendChild(root);
@@ -419,11 +393,10 @@ void PackagesInfo::writeToDisk()
addTextChildHelper(&root, QLatin1String("ApplicationName"), d->applicationName);
addTextChildHelper(&root, QLatin1String("ApplicationVersion"), d->applicationVersion);
- Q_FOREACH (const PackageInfo &info, d->packageInfoList) {
+ Q_FOREACH (const LocalPackage &info, d->m_packageInfoMap) {
QDomElement package = doc.createElement(QLatin1String("Package"));
addTextChildHelper(&package, QLatin1String("Name"), info.name);
- addTextChildHelper(&package, QLatin1String("Pixmap"), info.pixmap);
addTextChildHelper(&package, QLatin1String("Title"), info.title);
addTextChildHelper(&package, QLatin1String("Description"), info.description);
if (info.inheritVersionFrom.isEmpty())
@@ -431,20 +404,23 @@ void PackagesInfo::writeToDisk()
else
addTextChildHelper(&package, QLatin1String("Version"), info.version,
QLatin1String("inheritVersionFrom"), info.inheritVersionFrom);
- addTextChildHelper(&package, QLatin1String("LastUpdateDate"), info.lastUpdateDate.toString(Qt::ISODate));
- addTextChildHelper(&package, QLatin1String("InstallDate"), info.installDate.toString(Qt::ISODate));
- addTextChildHelper(&package, QLatin1String("Size"), QString::number(info.uncompressedSize));
- QString assembledDependencies = QLatin1String("");
- Q_FOREACH (const QString & val, info.dependencies) {
- assembledDependencies += val + QLatin1String(",");
- }
- if (info.dependencies.count() > 0)
- assembledDependencies.chop(1);
- addTextChildHelper(&package, QLatin1String("Dependencies"), assembledDependencies);
+ addTextChildHelper(&package, QLatin1String("LastUpdateDate"), info.lastUpdateDate
+ .toString(Qt::ISODate));
+ addTextChildHelper(&package, QLatin1String("InstallDate"), info.installDate
+ .toString(Qt::ISODate));
+ addTextChildHelper(&package, QLatin1String("Size"),
+ QString::number(info.uncompressedSize));
+
+ if (info.dependencies.count())
+ addTextChildHelper(&package, scDependencies, info.dependencies.join(QLatin1String(",")));
+ if (info.autoDependencies.count())
+ addTextChildHelper(&package, scAutoDependOn, info.autoDependencies.join(QLatin1String(",")));
if (info.forcedInstallation)
addTextChildHelper(&package, QLatin1String("ForcedInstallation"), QLatin1String("true"));
if (info.virtualComp)
addTextChildHelper(&package, QLatin1String("Virtual"), QLatin1String("true"));
+ if (info.checkable)
+ addTextChildHelper(&package, QLatin1String("Checkable"), QLatin1String("true"));
root.appendChild(package);
}
@@ -460,7 +436,7 @@ void PackagesInfo::writeToDisk()
}
}
-void PackagesInfo::PackagesInfoData::addPackageFrom(const QDomElement &packageE)
+void LocalPackageHub::PackagesInfoData::addPackageFrom(const QDomElement &packageE)
{
if (packageE.isNull())
return;
@@ -469,9 +445,10 @@ void PackagesInfo::PackagesInfoData::addPackageFrom(const QDomElement &packageE)
if (childNodes.count() == 0)
return;
- PackageInfo info;
+ LocalPackage info;
info.forcedInstallation = false;
info.virtualComp = false;
+ info.checkable = false;
for (int i = 0; i < childNodes.count(); i++) {
QDomNode childNode = childNodes.item(i);
QDomElement childNodeE = childNode.toElement();
@@ -480,8 +457,6 @@ void PackagesInfo::PackagesInfoData::addPackageFrom(const QDomElement &packageE)
if (childNodeE.tagName() == QLatin1String("Name"))
info.name = childNodeE.text();
- else if (childNodeE.tagName() == QLatin1String("Pixmap"))
- info.pixmap = childNodeE.text();
else if (childNodeE.tagName() == QLatin1String("Title"))
info.title = childNodeE.text();
else if (childNodeE.tagName() == QLatin1String("Description"))
@@ -497,38 +472,34 @@ void PackagesInfo::PackagesInfoData::addPackageFrom(const QDomElement &packageE)
else if (childNodeE.tagName() == QLatin1String("Dependencies")) {
info.dependencies = childNodeE.text().split(QInstaller::commaRegExp(),
QString::SkipEmptyParts);
+ } else if (childNodeE.tagName() == QLatin1String("AutoDependOn")) {
+ info.autoDependencies = childNodeE.text().split(QInstaller::commaRegExp(),
+ QString::SkipEmptyParts);
} else if (childNodeE.tagName() == QLatin1String("ForcedInstallation"))
info.forcedInstallation = childNodeE.text().toLower() == QLatin1String( "true" ) ? true : false;
else if (childNodeE.tagName() == QLatin1String("LastUpdateDate"))
info.lastUpdateDate = QDate::fromString(childNodeE.text(), Qt::ISODate);
else if (childNodeE.tagName() == QLatin1String("InstallDate"))
info.installDate = QDate::fromString(childNodeE.text(), Qt::ISODate);
+ else if (childNodeE.tagName() == QLatin1String("Checkable"))
+ info.checkable = childNodeE.text().toLower() == QLatin1String("true") ? true : false;
}
-
- this->packageInfoList.append(info);
+ m_packageInfoMap.insert(info.name, info);
}
/*!
Clears the installed package list.
*/
-void PackagesInfo::clearPackageInfoList()
+void LocalPackageHub::clearPackageInfos()
{
- d->packageInfoList.clear();
+ d->m_packageInfoMap.clear();
d->modified = true;
- emit reset();
}
/*!
- \fn void KDUpdater::PackagesInfo::reset()
-
- This signal is emitted whenever the contents of this class are refreshed, usually from within
- the refresh() slot.
-*/
-
-/*!
\inmodule kdupdater
- \class KDUpdater::PackageInfo
- \brief The PackageInfo class describes a single installed package in the application.
+ \class KDUpdater::LocalPackage
+ \brief The LocalPackage class describes a single installed package in the application.
This class contains information about a single installed package in the application. The
information contained in this class corresponds to the information described by the <Package>
@@ -536,30 +507,30 @@ void PackagesInfo::clearPackageInfoList()
*/
/*!
- \variable PackageInfo::name
+ \variable LocalPackage::name
\brief The name of the package.
*/
/*!
- \variable PackageInfo::pixmap
+ \variable LocalPackage::pixmap
*/
/*!
- \variable PackageInfo::title
+ \variable LocalPackage::title
*/
/*!
- \variable PackageInfo::description
+ \variable LocalPackage::description
*/
/*!
- \variable PackageInfo::version
+ \variable LocalPackage::version
*/
/*!
- \variable PackageInfo::lastUpdateDate
+ \variable LocalPackage::lastUpdateDate
*/
/*!
- \variable PackageInfo::installDate
+ \variable LocalPackage::installDate
*/
diff --git a/src/libs/kdtools/kdupdaterpackagesinfo.h b/src/libs/kdtools/localpackagehub.h
index c53053434..9ddf2548d 100644
--- a/src/libs/kdtools/kdupdaterpackagesinfo.h
+++ b/src/libs/kdtools/localpackagehub.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.
@@ -31,42 +32,42 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_PACKAGES_INFO_H
-#define KD_UPDATER_PACKAGES_INFO_H
+#ifndef LOCALPACKAGEHUB_H
+#define LOCALPACKAGEHUB_H
-#include "kdupdater.h"
+#include "updater.h"
-#include <QObject>
+#include <QCoreApplication>
#include <QDate>
-#include <QString>
#include <QStringList>
-#include <QVariant>
namespace KDUpdater {
-struct KDTOOLS_EXPORT PackageInfo
+struct KDTOOLS_EXPORT LocalPackage
{
QString name;
- QString pixmap;
QString title;
QString description;
QString version;
QString inheritVersionFrom;
QStringList dependencies;
- QStringList translations;
+ QStringList autoDependencies;
QDate lastUpdateDate;
QDate installDate;
bool forcedInstallation;
bool virtualComp;
quint64 uncompressedSize;
+ bool checkable;
};
-class KDTOOLS_EXPORT PackagesInfo : public QObject
+class KDTOOLS_EXPORT LocalPackageHub
{
- Q_OBJECT
+ Q_DISABLE_COPY(LocalPackageHub)
+ Q_DECLARE_TR_FUNCTIONS(LocalPackageHub)
public:
- ~PackagesInfo();
+ LocalPackageHub();
+ ~LocalPackageHub();
enum Error
{
@@ -78,42 +79,41 @@ public:
};
bool isValid() const;
- QString errorString() const;
+ QStringList packageNames() const;
+
Error error() const;
- void clearPackageInfoList();
+ QString errorString() const;
- void setFileName(const QString &fileName);
QString fileName() const;
+ void setFileName(const QString &fileName);
- void setApplicationName(const QString &name);
QString applicationName() const;
+ void setApplicationName(const QString &name);
- void setApplicationVersion(const QString &version);
QString applicationVersion() const;
+ void setApplicationVersion(const QString &version);
+ void clearPackageInfos();
int packageInfoCount() const;
- PackageInfo packageInfo(int index) const;
- int findPackageInfo(const QString &pkgName) const;
- QVector<KDUpdater::PackageInfo> packageInfos() const;
- void writeToDisk();
-
- 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,
- const QString &inheritVersionFrom = QString());
- bool updatePackage(const QString &pkgName, const QString &version, const QDate &date);
+ QList<LocalPackage> packageInfos() const;
+ LocalPackage packageInfo(const QString &pkgName) const;
+
+ void addPackage(const QString &pkgName,
+ const QString &version, // mandatory
+ const QString &title,
+ const QString &description,
+ const QStringList &dependencies,
+ const QStringList &autoDependencies,
+ bool forcedInstallation,
+ bool virtualComp,
+ quint64 uncompressedSize,
+ const QString &inheritVersionFrom,
+ bool checkable);
bool removePackage(const QString &pkgName);
-public Q_SLOTS:
void refresh();
-
-Q_SIGNALS:
- void reset();
-
-protected:
- friend class Application;
- explicit PackagesInfo(QObject *parent = 0);
+ void writeToDisk();
private:
struct PackagesInfoData;
@@ -122,4 +122,4 @@ private:
} // KDUpdater
-#endif // KD_UPDATER_PACKAGES_INFO_H
+#endif // LOCALPACKAGEHUB_H
diff --git a/src/libs/kdtools/kdlockfile.cpp b/src/libs/kdtools/lockfile.cpp
index 476b034f9..a40e68fbe 100644
--- a/src/libs/kdtools/kdlockfile.cpp
+++ b/src/libs/kdtools/lockfile.cpp
@@ -32,30 +32,34 @@
**
****************************************************************************/
-#include "kdlockfile.h"
-#include "kdlockfile_p.h"
+#include "lockfile.h"
+#include "lockfile_p.h"
-KDLockFile::KDLockFile(const QString &name)
+namespace KDUpdater {
+
+LockFile::LockFile(const QString &name)
: d(new Private(name))
{
}
-KDLockFile::~KDLockFile()
+LockFile::~LockFile()
{
delete d;
}
-bool KDLockFile::lock()
+bool LockFile::lock()
{
return d->lock();
}
-QString KDLockFile::errorString() const
+QString LockFile::errorString() const
{
return d->errorString;
}
-bool KDLockFile::unlock()
+bool LockFile::unlock()
{
return d->unlock();
}
+
+} // namespace KDUpdater
diff --git a/src/libs/kdtools/kdlockfile.h b/src/libs/kdtools/lockfile.h
index 2d98c3f6d..13b28dac3 100644
--- a/src/libs/kdtools/kdlockfile.h
+++ b/src/libs/kdtools/lockfile.h
@@ -32,18 +32,20 @@
**
****************************************************************************/
-#ifndef KDLOCKFILE_H
-#define KDLOCKFILE_H
+#ifndef LOCKFILE_H
+#define LOCKFILE_H
-#include <kdtoolsglobal.h>
+#include "kdtoolsglobal.h"
-class KDTOOLS_EXPORT KDLockFile
+namespace KDUpdater {
+
+class KDTOOLS_EXPORT LockFile
{
- Q_DISABLE_COPY(KDLockFile)
+ Q_DISABLE_COPY(LockFile)
public:
- explicit KDLockFile(const QString &name);
- ~KDLockFile();
+ explicit LockFile(const QString &name);
+ ~LockFile();
QString errorString() const;
@@ -55,4 +57,6 @@ private:
Private *d;
};
-#endif // KDLOCKFILE_H
+} // namespace KDUpdater
+
+#endif // LOCKFILE_H
diff --git a/src/libs/kdtools/kdlockfile_p.h b/src/libs/kdtools/lockfile_p.h
index 51258c4ad..b8636aaad 100644
--- a/src/libs/kdtools/kdlockfile_p.h
+++ b/src/libs/kdtools/lockfile_p.h
@@ -32,10 +32,10 @@
**
****************************************************************************/
-#ifndef KDLOCKFILE_P_H
-#define KDLOCKFILE_P_H
+#ifndef LOCKFILE_P_H
+#define LOCKFILE_P_H
-#include "kdlockfile.h"
+#include "lockfile.h"
#include <QString>
@@ -43,7 +43,9 @@
# include <qt_windows.h>
#endif
-class KDLockFile::Private
+namespace KDUpdater {
+
+class LockFile::Private
{
public:
explicit Private(const QString& name)
@@ -67,4 +69,6 @@ private:
bool locked;
};
-#endif // KDLOCKFILE_P_H
+} // namespace KDUpdater
+
+#endif // LOCKFILE_P_H
diff --git a/src/libs/kdtools/kdlockfile_unix.cpp b/src/libs/kdtools/lockfile_unix.cpp
index 152fa5383..a024a842f 100644
--- a/src/libs/kdtools/kdlockfile_unix.cpp
+++ b/src/libs/kdtools/lockfile_unix.cpp
@@ -32,15 +32,18 @@
**
****************************************************************************/
-#include "kdlockfile_p.h"
+#include "lockfile_p.h"
#include <QCoreApplication>
+#include <QDir>
#include <cerrno>
#include <sys/file.h>
#include <unistd.h>
-bool KDLockFile::Private::lock()
+namespace KDUpdater {
+
+bool LockFile::Private::lock()
{
if (locked)
return true;
@@ -49,8 +52,8 @@ bool KDLockFile::Private::lock()
errno = 0;
handle = open(filename.toLatin1().constData(), O_CREAT | O_RDWR | O_NONBLOCK, 0600);
if (handle == -1) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not create lock file '%1': "
- "%2").arg(filename, QString::fromLocal8Bit(strerror(errno)));
+ errorString = QCoreApplication::translate("LockFile", "Cannot create lock file \"%1\": "
+ "%2").arg(QDir::toNativeSeparators(filename), QString::fromLocal8Bit(strerror(errno)));
return false;
}
const QString pid = QString::number(qApp->applicationPid());
@@ -60,8 +63,8 @@ bool KDLockFile::Private::lock()
while (written < data.size()) {
const qint64 n = write(handle, data.constData() + written, data.size() - written);
if (n < 0) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not write PID to lock "
- "file '%1': %2").arg(filename, QString::fromLocal8Bit(strerror(errno)));
+ errorString = QCoreApplication::translate("LockFile", "Cannot write PID to lock "
+ "file \"%1\": %2").arg(QDir::toNativeSeparators(filename), QString::fromLocal8Bit(strerror(errno)));
return false;
}
written += n;
@@ -69,13 +72,13 @@ bool KDLockFile::Private::lock()
errno = 0;
locked = flock(handle, LOCK_NB | LOCK_EX) != -1;
if (!locked) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not obtain the lock for "
- "file '%1': %2").arg(filename, QString::fromLocal8Bit(strerror(errno)));
+ errorString = QCoreApplication::translate("LockFile", "Cannot obtain the lock for "
+ "file \"%1\": %2").arg(QDir::toNativeSeparators(filename), QString::fromLocal8Bit(strerror(errno)));
}
return locked;
}
-bool KDLockFile::Private::unlock()
+bool LockFile::Private::unlock()
{
errorString.clear();
if (!locked)
@@ -84,10 +87,12 @@ bool KDLockFile::Private::unlock()
errno = 0;
locked = flock(handle, LOCK_UN | LOCK_NB) == -1;
if (locked) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not release the lock for "
- "file '%1': %2").arg(filename, QString::fromLocal8Bit(strerror(errno)));
+ errorString = QCoreApplication::translate("LockFile", "Cannot release the lock for "
+ "file \"%1\": %2").arg(QDir::toNativeSeparators(filename), QString::fromLocal8Bit(strerror(errno)));
} else {
unlink(filename.toLatin1());
}
return !locked;
}
+
+} // namespace KDUpdater
diff --git a/src/libs/kdtools/kdlockfile_win.cpp b/src/libs/kdtools/lockfile_win.cpp
index f1914f06a..84c3cc9c9 100644
--- a/src/libs/kdtools/kdlockfile_win.cpp
+++ b/src/libs/kdtools/lockfile_win.cpp
@@ -32,15 +32,18 @@
**
****************************************************************************/
-#include "kdlockfile.h"
-#include "kdlockfile_p.h"
+#include "lockfile.h"
+#include "lockfile_p.h"
-#include <utils.h>
+#include "utils.h"
#include <QCoreApplication>
+#include <QDir>
#include <QFileInfo>
-bool KDLockFile::Private::lock()
+namespace KDUpdater {
+
+bool LockFile::Private::lock()
{
if (locked)
return locked;
@@ -51,41 +54,43 @@ bool KDLockFile::Private::lock()
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
if (handle == INVALID_HANDLE_VALUE) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not create lock file '%1': "
- "%2").arg(filename, QInstaller::windowsErrorString(GetLastError()));
+ errorString = QCoreApplication::translate("LockFile", "Cannot create lock file \"%1\": "
+ "%2").arg(QDir::toNativeSeparators(filename), QInstaller::windowsErrorString(GetLastError()));
return false;
}
DWORD bytesWritten;
const QByteArray pid = QString::number(QCoreApplication::applicationPid()).toLatin1();
if (!WriteFile(handle, pid.data(), pid.size(), &bytesWritten, NULL)) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not write PID to lock file "
- "'%1': %2").arg(filename, QInstaller::windowsErrorString(GetLastError()));
+ errorString = QCoreApplication::translate("LockFile", "Cannot write PID to lock file "
+ "\"%1\": %2").arg(QDir::toNativeSeparators(filename), QInstaller::windowsErrorString(GetLastError()));
return false;
}
FlushFileBuffers(handle);
- if (!LockFile(handle, 0, 0, QFileInfo(filename).size(), 0)) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not obtain the lock for "
- "file '%1': %2").arg(filename, QInstaller::windowsErrorString(GetLastError()));
+ if (!::LockFile(handle, 0, 0, QFileInfo(filename).size(), 0)) {
+ errorString = QCoreApplication::translate("LockFile", "Cannot obtain the lock for "
+ "file \"%1\": %2").arg(QDir::toNativeSeparators(filename), QInstaller::windowsErrorString(GetLastError()));
} else {
locked = true;
}
return locked;
}
-bool KDLockFile::Private::unlock()
+bool LockFile::Private::unlock()
{
errorString.clear();
if (!locked)
return true;
if (!UnlockFile(handle, 0, 0, QFileInfo(filename).size(), 0)) {
- errorString = QCoreApplication::translate("KDLockFile", "Could not release the lock for "
- "file '%1': %2").arg(filename, QInstaller::windowsErrorString(GetLastError()));
+ errorString = QCoreApplication::translate("LockFile", "Cannot release the lock for "
+ "file \"%1\": %2").arg(QDir::toNativeSeparators(filename), QInstaller::windowsErrorString(GetLastError()));
} else {
locked = false;
CloseHandle(handle);
}
return !locked;
}
+
+} // namespace KDUpdater
diff --git a/src/libs/kdtools/kdrunoncechecker.cpp b/src/libs/kdtools/runoncechecker.cpp
index bc71e86c2..21b17ed81 100644
--- a/src/libs/kdtools/kdrunoncechecker.cpp
+++ b/src/libs/kdtools/runoncechecker.cpp
@@ -32,9 +32,9 @@
**
****************************************************************************/
-#include "kdrunoncechecker.h"
-#include "kdlockfile.h"
-#include "kdsysinfo.h"
+#include "runoncechecker.h"
+#include "lockfile.h"
+#include "sysinfo.h"
#include <QCoreApplication>
#include <QDebug>
@@ -46,15 +46,15 @@
using namespace KDUpdater;
-KDRunOnceChecker::KDRunOnceChecker(const QString &filename)
+RunOnceChecker::RunOnceChecker(const QString &filename)
: m_lockfile(filename)
{
}
-KDRunOnceChecker::~KDRunOnceChecker()
+RunOnceChecker::~RunOnceChecker()
{
if (!m_lockfile.unlock())
- qWarning() << m_lockfile.errorString().toUtf8().constData();
+ qWarning().noquote() << m_lockfile.errorString();
}
class ProcessnameEquals
@@ -90,7 +90,7 @@ private:
QString m_name;
};
-bool KDRunOnceChecker::isRunning(KDRunOnceChecker::ConditionFlags flags)
+bool RunOnceChecker::isRunning(RunOnceChecker::ConditionFlags flags)
{
if (flags.testFlag(ConditionFlag::ProcessList)) {
const QList<ProcessInfo> allProcesses = runningProcesses();
@@ -102,7 +102,7 @@ bool KDRunOnceChecker::isRunning(KDRunOnceChecker::ConditionFlags flags)
if (flags.testFlag(ConditionFlag::Lockfile)) {
const bool locked = m_lockfile.lock();
if (!locked)
- qWarning() << m_lockfile.errorString().toUtf8().constData();
+ qWarning().noquote() << m_lockfile.errorString();
return !locked;
}
return false;
diff --git a/src/libs/kdtools/kdrunoncechecker.h b/src/libs/kdtools/runoncechecker.h
index b357d7723..45ed1e50e 100644
--- a/src/libs/kdtools/kdrunoncechecker.h
+++ b/src/libs/kdtools/runoncechecker.h
@@ -32,16 +32,16 @@
**
****************************************************************************/
-#ifndef KDTOOLS_RUNONCECHECKER_H
-#define KDTOOLS_RUNONCECHECKER_H
+#ifndef RUNONCECHECKER_H
+#define RUNONCECHECKER_H
-#include "kdlockfile.h"
+#include "lockfile.h"
#include <QString>
-class KDTOOLS_EXPORT KDRunOnceChecker
+class KDTOOLS_EXPORT RunOnceChecker
{
- Q_DISABLE_COPY(KDRunOnceChecker)
+ Q_DISABLE_COPY(RunOnceChecker)
public:
enum struct ConditionFlag {
@@ -50,13 +50,13 @@ public:
};
Q_DECLARE_FLAGS(ConditionFlags, ConditionFlag)
- explicit KDRunOnceChecker(const QString &filename = QString());
- ~KDRunOnceChecker();
+ explicit RunOnceChecker(const QString &filename = QString());
+ ~RunOnceChecker();
- bool isRunning(KDRunOnceChecker::ConditionFlags flags);
+ bool isRunning(RunOnceChecker::ConditionFlags flags);
private:
- KDLockFile m_lockfile;
+ KDUpdater::LockFile m_lockfile;
};
-#endif // KDTOOLS_RUNONCECHECKER_H
+#endif // RUNONCECHECKER_H
diff --git a/src/libs/kdtools/kdselfrestarter.cpp b/src/libs/kdtools/selfrestarter.cpp
index 934bbf627..6f990cf90 100644
--- a/src/libs/kdtools/kdselfrestarter.cpp
+++ b/src/libs/kdtools/selfrestarter.cpp
@@ -31,13 +31,13 @@
**
****************************************************************************/
-#include "kdselfrestarter.h"
+#include "selfrestarter.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QProcess>
-class KDSelfRestarter::Private
+class SelfRestarter::Private
{
public:
Private(int argc, char *argv[])
@@ -66,33 +66,33 @@ public:
QStringList args;
bool restartOnQuit;
QString workingPath;
- static KDSelfRestarter *instance;
+ static SelfRestarter *instance;
};
-KDSelfRestarter *KDSelfRestarter::Private::instance = 0;
+SelfRestarter *SelfRestarter::Private::instance = 0;
-KDSelfRestarter::KDSelfRestarter(int argc, char *argv[])
+SelfRestarter::SelfRestarter(int argc, char *argv[])
: d(new Private(argc, argv))
{
- Q_ASSERT_X(!Private::instance, Q_FUNC_INFO, "Cannot create more than one KDSelfRestarter instance");
+ Q_ASSERT_X(!Private::instance, Q_FUNC_INFO, "Cannot create more than one SelfRestarter instance");
Private::instance = this;
}
-KDSelfRestarter::~KDSelfRestarter()
+SelfRestarter::~SelfRestarter()
{
- Q_ASSERT_X(Private::instance == this, Q_FUNC_INFO, "Cannot create more than one KDSelfRestarter instance");
+ Q_ASSERT_X(Private::instance == this, Q_FUNC_INFO, "Cannot create more than one SelfRestarter instance");
delete d;
Private::instance = 0;
}
-void KDSelfRestarter::setRestartOnQuit(bool restart)
+void SelfRestarter::setRestartOnQuit(bool restart)
{
- Q_ASSERT_X(Private::instance, Q_FUNC_INFO, "KDSelfRestarter instance must be created in main()");
+ Q_ASSERT_X(Private::instance, Q_FUNC_INFO, "SelfRestarter instance must be created in main()");
if (Private::instance)
Private::instance->d->restartOnQuit = restart;
}
-bool KDSelfRestarter::restartOnQuit()
+bool SelfRestarter::restartOnQuit()
{
return Private::instance ? Private::instance->d->restartOnQuit : false;
}
diff --git a/src/libs/kdtools/kdselfrestarter.h b/src/libs/kdtools/selfrestarter.h
index a095c728a..8d62b0345 100644
--- a/src/libs/kdtools/kdselfrestarter.h
+++ b/src/libs/kdtools/selfrestarter.h
@@ -31,24 +31,24 @@
**
****************************************************************************/
-#ifndef KDTOOLS_KDSELFRESTARTER_H
-#define KDTOOLS_KDSELFRESTARTER_H
+#ifndef SELFRESTARTER_H
+#define SELFRESTARTER_H
#include "kdtoolsglobal.h"
-class KDTOOLS_EXPORT KDSelfRestarter
+class KDTOOLS_EXPORT SelfRestarter
{
public:
- KDSelfRestarter(int argc, char *argv[]);
- ~KDSelfRestarter();
+ SelfRestarter(int argc, char *argv[]);
+ ~SelfRestarter();
static bool restartOnQuit();
static void setRestartOnQuit(bool restart);
private:
- Q_DISABLE_COPY(KDSelfRestarter)
+ Q_DISABLE_COPY(SelfRestarter)
class Private;
Private *d;
};
-#endif // KDTOOLS_KDSELFRESTARTER_H
+#endif // SELFRESTARTER_H
diff --git a/src/libs/kdtools/kdsysinfo.cpp b/src/libs/kdtools/sysinfo.cpp
index 6a2a96ea5..fafa2900e 100644
--- a/src/libs/kdtools/kdsysinfo.cpp
+++ b/src/libs/kdtools/sysinfo.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdsysinfo.h"
+#include "sysinfo.h"
#include <QtCore/QDebug>
#include <QtCore/QDir>
diff --git a/src/libs/kdtools/kdsysinfo.h b/src/libs/kdtools/sysinfo.h
index 276e98e3c..021f26cfd 100644
--- a/src/libs/kdtools/kdsysinfo.h
+++ b/src/libs/kdtools/sysinfo.h
@@ -31,10 +31,10 @@
**
****************************************************************************/
-#ifndef KDSYSINFO_H
-#define KDSYSINFO_H
+#ifndef SYSINFO_H
+#define SYSINFO_H
-#include <kdtoolsglobal.h>
+#include "kdtoolsglobal.h"
#include <QtCore/QString>
@@ -93,4 +93,4 @@ QT_END_NAMESPACE
QDebug operator<<(QDebug dbg, KDUpdater::VolumeInfo volume);
QDebug operator<<(QDebug dbg, KDUpdater::ProcessInfo process);
-#endif // KDSYSINFO_H
+#endif // SYSINFO_H
diff --git a/src/libs/kdtools/kdsysinfo_mac.cpp b/src/libs/kdtools/sysinfo_mac.cpp
index 23b3646fe..f1e3d1786 100644
--- a/src/libs/kdtools/kdsysinfo_mac.cpp
+++ b/src/libs/kdtools/sysinfo_mac.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdsysinfo.h"
+#include "sysinfo.h"
#include <Carbon/Carbon.h>
diff --git a/src/libs/kdtools/kdsysinfo_x11.cpp b/src/libs/kdtools/sysinfo_x11.cpp
index e47734c7c..6fddf895f 100644
--- a/src/libs/kdtools/kdsysinfo_x11.cpp
+++ b/src/libs/kdtools/sysinfo_x11.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdsysinfo.h"
+#include "sysinfo.h"
#include <sys/utsname.h>
#include <sys/statvfs.h>
@@ -75,7 +75,7 @@ QList<VolumeInfo> mountedVolumes()
QFile f(QLatin1String("/etc/mtab"));
if (!f.open(QIODevice::ReadOnly)) {
- qCritical("%s: Could not open %s: %s", Q_FUNC_INFO, qPrintable(f.fileName()), qPrintable(f.errorString()));
+ qCritical("%s: Cannot open %s: %s", Q_FUNC_INFO, qPrintable(f.fileName()), qPrintable(f.errorString()));
return result; //better error-handling?
}
diff --git a/src/libs/kdtools/kdupdatertask.cpp b/src/libs/kdtools/task.cpp
index 38b33da0a..14b774ea9 100644
--- a/src/libs/kdtools/kdupdatertask.cpp
+++ b/src/libs/kdtools/task.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdupdatertask.h"
+#include "task.h"
using namespace KDUpdater;
diff --git a/src/libs/kdtools/kdupdatertask.h b/src/libs/kdtools/task.h
index 51c1458f1..fc528cd66 100644
--- a/src/libs/kdtools/kdupdatertask.h
+++ b/src/libs/kdtools/task.h
@@ -31,10 +31,10 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_TASK_H
-#define KD_UPDATER_TASK_H
+#ifndef TASK_H
+#define TASK_H
-#include "kdupdater.h"
+#include "updater.h"
#include <QObject>
@@ -116,4 +116,4 @@ private:
} // namespace KDUpdater
-#endif // KD_UPDATER_TASK_H
+#endif // TASK_H
diff --git a/src/libs/kdtools/kdupdaterupdate.cpp b/src/libs/kdtools/update.cpp
index 79c5beb94..93e8e91b1 100644
--- a/src/libs/kdtools/kdupdaterupdate.cpp
+++ b/src/libs/kdtools/update.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdupdaterupdate.h"
+#include "update.h"
using namespace KDUpdater;
@@ -51,10 +51,9 @@ using namespace KDUpdater;
/*!
\internal
*/
-Update::Update(int priority, const QUrl &sourceInfoUrl, const QHash<QString, QVariant> &data)
- : m_priority(priority)
- , m_sourceInfoUrl(sourceInfoUrl)
- , m_data(data)
+Update::Update(const QInstaller::PackageSource &packageSource, const UpdateInfo &updateInfo)
+ : m_packageSource(packageSource)
+ , m_updateInfo(updateInfo)
{
}
@@ -64,22 +63,5 @@ Update::Update(int priority, const QUrl &sourceInfoUrl, const QHash<QString, QVa
*/
QVariant Update::data(const QString &name, const QVariant &defaultValue) const
{
- return m_data.value(name, defaultValue);
-}
-
-/*!
- Returns the priority of the update.
-*/
-int Update::priority() const
-{
- return m_priority;
-}
-
-/*!
- Returns the URL of the update source. An update source is a repository that
- contains an update for the application.
-*/
-QUrl Update::sourceInfoUrl() const
-{
- return m_sourceInfoUrl;
+ return m_updateInfo.data.value(name, defaultValue);
}
diff --git a/src/libs/kdtools/kdupdaterupdate.h b/src/libs/kdtools/update.h
index 10e46ad08..dfc52dfa1 100644
--- a/src/libs/kdtools/kdupdaterupdate.h
+++ b/src/libs/kdtools/update.h
@@ -31,11 +31,11 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_H
-#define KD_UPDATER_UPDATE_H
+#ifndef UPDATE_H
+#define UPDATE_H
-#include <QHash>
-#include <QUrl>
+#include "packagesource.h"
+#include "updatesinfo_p.h"
#include <QVariant>
namespace KDUpdater {
@@ -45,19 +45,17 @@ class Update
public:
QVariant data(const QString &name, const QVariant &defaultValue = QVariant()) const;
- int priority() const;
- QUrl sourceInfoUrl() const;
+ QInstaller::PackageSource packageSource() const {return m_packageSource; }
private:
friend class UpdateFinder;
- Update(int p, const QUrl &sourceInfoUrl, const QHash<QString, QVariant> &data);
+ Update(const QInstaller::PackageSource &packageSource, const UpdateInfo &updateInfo);
private:
- int m_priority;
- QUrl m_sourceInfoUrl;
- QHash<QString, QVariant> m_data;
+ QInstaller::PackageSource m_packageSource;
+ UpdateInfo m_updateInfo;
};
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_H
+#endif // UPDATE_H
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.cpp b/src/libs/kdtools/updatefinder.cpp
index a4bfa209c..25e587b17 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.cpp
+++ b/src/libs/kdtools/updatefinder.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.
@@ -31,14 +32,12 @@
**
****************************************************************************/
-#include "kdupdaterupdatefinder.h"
-#include "kdupdaterapplication.h"
-#include "kdupdaterupdatesourcesinfo.h"
-#include "kdupdaterpackagesinfo.h"
-#include "kdupdaterupdate.h"
-#include "kdupdaterfiledownloader.h"
-#include "kdupdaterfiledownloaderfactory.h"
-#include "kdupdaterupdatesinfo_p.h"
+#include "updatefinder.h"
+#include "update.h"
+#include "filedownloader.h"
+#include "filedownloaderfactory.h"
+#include "updatesinfo_p.h"
+#include "localpackagehub.h"
#include "fileutils.h"
#include "globals.h"
@@ -47,16 +46,17 @@
#include <QFileInfo>
using namespace KDUpdater;
+using namespace QInstaller;
/*!
\inmodule kdupdater
\class KDUpdater::UpdateFinder
- \brief The UpdaterFinder class finds updates applicable for a KDUpdater::Application.
+ \brief The UpdaterFinder class finds updates applicable for installed packages.
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.
*/
//
@@ -73,7 +73,6 @@ public:
Private(UpdateFinder *qq)
: q(qq)
- , application(0)
, downloadCompleteCount(0)
, m_downloadsToComplete(0)
{}
@@ -86,14 +85,13 @@ public:
struct Data {
Data()
: downloader(0) {}
- Data(const UpdateSourceInfo &i, FileDownloader *d = 0)
+ Data(const PackageSource &i, FileDownloader *d = 0)
: info(i), downloader(d) {}
- UpdateSourceInfo info;
+ PackageSource info;
FileDownloader *downloader;
};
UpdateFinder *q;
- Application *application;
QHash<QString, Update *> updates;
// Temporary structure that notes down information about updates.
@@ -109,9 +107,12 @@ public:
bool computeApplicableUpdates();
QList<UpdateInfo> applicableUpdates(UpdatesInfo *updatesInfo);
- void createUpdateObjects(const UpdateSourceInfo &sourceInfo, const QList<UpdateInfo> &updateInfoList);
- Resolution checkPriorityAndVersion(const UpdateSourceInfo &sourceInfo, const QVariantHash &data) const;
+ void createUpdateObjects(const PackageSource &source, const QList<UpdateInfo> &updateInfoList);
+ Resolution checkPriorityAndVersion(const PackageSource &source, const QVariantHash &data) const;
void slotDownloadDone();
+
+ QSet<PackageSource> packageSources;
+ std::weak_ptr<LocalPackageHub> m_localPackageHub;
};
@@ -151,7 +152,7 @@ void UpdateFinder::Private::clear()
This method computes the updates that can be applied on the application by
studying the application's KDUpdater::PackagesInfo object and the UpdateXML files
- from each of the update sources described in KDUpdater::UpdateSourcesInfo.
+ from each of the update sources described in QInstaller::PackageSource.
This function can take a long time to complete. The following signals are emitted
during the execution of this function
@@ -159,7 +160,7 @@ void UpdateFinder::Private::clear()
The function creates KDUpdater::Update objects on the stack. All KDUpdater::Update objects
are made children of the application associated with this finder.
- The update sources are fetched from the KDUpdater::UpdateSourcesInfo object associated with
+ The update sources are fetched from the QInstaller::PackageSource object associated with
the application. Package information is extracted from the KDUpdater::PackagesInfo object
associated with the application.
@@ -176,24 +177,20 @@ void UpdateFinder::Private::computeUpdates()
cancel = false;
// First do some quick sanity checks on the packages info
- PackagesInfo *packages = application->packagesInfo();
+ std::shared_ptr<LocalPackageHub> packages = m_localPackageHub.lock();
if (!packages) {
- q->reportError(tr("Could not access the package information of this application."));
+ q->reportError(tr("Cannot access the package information of this application."));
return;
}
+
if (!packages->isValid()) {
q->reportError(packages->errorString());
return;
}
- // 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());
+ // Now do some quick sanity checks on the package sources.
+ if (packageSources.count() <= 0) {
+ q->reportError(tr("No package sources set for this application."));
return;
}
@@ -246,18 +243,9 @@ void UpdateFinder::Private::cancelComputeUpdates()
*/
bool UpdateFinder::Private::downloadUpdateXMLFiles()
{
- if (!application)
- return false;
-
- UpdateSourcesInfo *updateSources = application->updateSourcesInfo();
- if (!updateSources )
- return false;
-
// create UpdatesInfo for each update source
- for (int i = 0; i < updateSources->updateSourceInfoCount(); i++) {
- const UpdateSourceInfo info = updateSources->updateSourceInfo(i);
+ foreach (const PackageSource &info, packageSources) {
const QUrl url = QString::fromLatin1("%1/Updates.xml").arg(info.url.toString());
-
if (url.scheme() != QLatin1String("resource") && url.scheme() != QLatin1String("file")) {
// create FileDownloader (except for local files and resources)
FileDownloader *downloader = FileDownloaderFactory::instance().create(url.scheme(), q);
@@ -305,8 +293,8 @@ bool UpdateFinder::Private::downloadUpdateXMLFiles()
const Data data = m_updatesInfoList.value(updatesInfo);
if (data.downloader) {
if (!data.downloader->isDownloaded()) {
- q->reportError(tr("Could not download update source %1 from ('%2')").arg(data.info
- .name, data.info.url.toString()));
+ q->reportError(tr("Cannot download package source %1 from \"%2\".").arg(data
+ .downloader->url().fileName(), data.info.url.toString()));
} else {
updatesInfo->setFileName(data.downloader->downloadedFileName());
}
@@ -351,7 +339,7 @@ bool UpdateFinder::Private::computeApplicableUpdates()
if (cancel)
return false;
- const UpdateSourceInfo updateSource = m_updatesInfoList.value(updatesInfo).info;
+ const PackageSource updateSource = m_updatesInfoList.value(updatesInfo).info;
// Create Update objects for updates that have a valid
// UpdateFile
@@ -375,7 +363,7 @@ QList<UpdateInfo> UpdateFinder::Private::applicableUpdates(UpdatesInfo *updatesI
if (!updatesInfo || updatesInfo->updateInfoCount() == 0)
return dummy;
- PackagesInfo *packages = this->application->packagesInfo();
+ std::shared_ptr<LocalPackageHub> packages = m_localPackageHub.lock();
if (!packages)
return dummy;
@@ -390,17 +378,19 @@ QList<UpdateInfo> UpdateFinder::Private::applicableUpdates(UpdatesInfo *updatesI
// Catch hold of app names contained updatesInfo->applicationName()
// 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)
+ if (apps.indexOf([&packages] { return packages->isValid() ? packages->applicationName()
+ : QCoreApplication::applicationName(); } ()) < 0) {
return dummy;
+ }
}
return updatesInfo->updatesInfo();
}
-void UpdateFinder::Private::createUpdateObjects(const UpdateSourceInfo &sourceInfo,
+void UpdateFinder::Private::createUpdateObjects(const PackageSource &source,
const QList<UpdateInfo> &updateInfoList)
{
foreach (const UpdateInfo &info, updateInfoList) {
- const Resolution value = checkPriorityAndVersion(sourceInfo, info.data);
+ const Resolution value = checkPriorityAndVersion(source, info.data);
if (value == Resolution::KeepExisting)
continue;
@@ -409,7 +399,7 @@ void UpdateFinder::Private::createUpdateObjects(const UpdateSourceInfo &sourceIn
delete updates.take(name);
// Create and register the update
- updates.insert(name, new Update(sourceInfo.priority, sourceInfo.url, info.data));
+ updates.insert(name, new Update(source, info));
}
}
@@ -419,7 +409,7 @@ void UpdateFinder::Private::createUpdateObjects(const UpdateSourceInfo &sourceIn
priority, use the new new package, otherwise keep the already existing package.
*/
UpdateFinder::Private::Resolution UpdateFinder::Private::checkPriorityAndVersion(
- const UpdateSourceInfo &sourceInfo, const QVariantHash &newPackage) const
+ const PackageSource &source, const QVariantHash &newPackage) const
{
const QString name = newPackage.value(QLatin1String("Name")).toString();
if (Update *existingPackage = updates.value(name)) {
@@ -430,23 +420,23 @@ UpdateFinder::Private::Resolution UpdateFinder::Private::checkPriorityAndVersion
if (match > 0) {
// new package has higher version, use
- qDebug() << QString::fromLatin1("Remove Package 'Name: %1, Version: %2, Source: %3' "
- "found a package with higher version 'Name: %4, Version: %5, Source: %6'")
- .arg(name, existingPackage->data(QLatin1String("Version")).toString(),
- QFileInfo(existingPackage->sourceInfoUrl().toLocalFile()).fileName(),
- name, newPackage.value(QLatin1String("Version")).toString(),
- QFileInfo(sourceInfo.url.toLocalFile()).fileName());
+ qDebug().nospace() << "Remove Package 'Name: " << name << ", Version: "
+ << existingPackage->data(QLatin1String("Version")).toString()
+ << ", Source: " << QFileInfo(existingPackage->packageSource().url.toLocalFile()).fileName()
+ << "' found a package with higher version 'Name: "
+ << name << ", Version: " << newPackage.value(QLatin1String("Version")).toString()
+ << ", Source: " << QFileInfo(source.url.toLocalFile()).fileName() << "'";
return Resolution::RemoveExisting;
}
- if ((match == 0) && (sourceInfo.priority > existingPackage->priority())) {
+ if ((match == 0) && (source.priority > existingPackage->packageSource().priority)) {
// new package version equals but priority is higher, use
- qDebug() << QString::fromLatin1("Remove Package 'Name: %1, Priority: %2, Source: %3' "
- "found a package with higher priority 'Name: %4, Priority: %5, Source: %6'")
- .arg(name, QString::number(existingPackage->priority()),
- QFileInfo(existingPackage->sourceInfoUrl().toLocalFile()).fileName(),
- name, QString::number(sourceInfo.priority),
- QFileInfo(sourceInfo.url.toLocalFile()).fileName());
+ qDebug().nospace() << "Remove Package 'Name: " << name << ", Priority: "
+ << existingPackage->packageSource().priority
+ << ", Source: " << QFileInfo(existingPackage->packageSource().url.toLocalFile()).fileName()
+ << "' found a package with higher priority 'Name: "
+ << name << ", Priority: " << source.priority
+ << ", Source: " << QFileInfo(source.url.toLocalFile()).fileName() << "'";
return Resolution::RemoveExisting;
}
return Resolution::KeepExisting; // otherwise keep existing
@@ -459,14 +449,12 @@ UpdateFinder::Private::Resolution UpdateFinder::Private::checkPriorityAndVersion
//
/*!
- Constructs an update finder for the KDUpdater::Application specified by
- \a application.
+ Constructs an update finder.
*/
-UpdateFinder::UpdateFinder(Application *application)
- : Task(QLatin1String("UpdateFinder"), Stoppable, application),
+UpdateFinder::UpdateFinder()
+ : Task(QLatin1String("UpdateFinder"), Stoppable),
d(new Private(this))
{
- d->application = application;
}
/*!
@@ -478,14 +466,26 @@ UpdateFinder::~UpdateFinder()
}
/*!
- Returns a list of KDUpdater::Update objects. The update objects returned in this list
- are made children of the KDUpdater::Application object associated with this class.
+ Returns a list of KDUpdater::Update objects.
*/
QList<Update *> UpdateFinder::updates() const
{
return d->updates.values();
}
+void UpdateFinder::setLocalPackageHub(std::weak_ptr<LocalPackageHub> hub)
+{
+ d->m_localPackageHub = std::move(hub);
+}
+
+/*!
+ Sets the package sources information to use when searching for applicable packages.
+*/
+void UpdateFinder::setPackageSources(const QSet<PackageSource> &sources)
+{
+ d->packageSources = sources;
+}
+
/*!
\internal
@@ -636,4 +636,4 @@ int KDUpdater::compareVersion(const QString &v1, const QString &v2)
return 0;
}
-#include "moc_kdupdaterupdatefinder.cpp"
+#include "moc_updatefinder.cpp"
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.h b/src/libs/kdtools/updatefinder.h
index ce7fae093..1fbebdd9a 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.h
+++ b/src/libs/kdtools/updatefinder.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.
@@ -31,14 +32,17 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_FINDER_H
-#define KD_UPDATER_UPDATE_FINDER_H
+#ifndef UPDATEFINDER_H
+#define UPDATEFINDER_H
-#include "kdupdatertask.h"
+#include "task.h"
+#include "packagesource.h"
+
+#include <memory>
namespace KDUpdater {
-class Application;
+class LocalPackageHub;
class Update;
class KDTOOLS_EXPORT UpdateFinder : public Task
@@ -47,11 +51,14 @@ class KDTOOLS_EXPORT UpdateFinder : public Task
class Private;
public:
- explicit UpdateFinder(Application *application);
+ UpdateFinder();
~UpdateFinder();
QList<Update *> updates() const;
+ void setLocalPackageHub(std::weak_ptr<LocalPackageHub> hub);
+ void setPackageSources(const QSet<QInstaller::PackageSource> &sources);
+
private:
void doRun();
bool doStop();
@@ -65,4 +72,4 @@ private:
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_FINDER_H
+#endif // UPDATEFINDER_H
diff --git a/src/libs/kdtools/kdupdaterupdateoperation.cpp b/src/libs/kdtools/updateoperation.cpp
index 70c4e7a07..965871fda 100644
--- a/src/libs/kdtools/kdupdaterupdateoperation.cpp
+++ b/src/libs/kdtools/updateoperation.cpp
@@ -31,9 +31,11 @@
**
****************************************************************************/
-#include "kdupdaterupdateoperation.h"
+#include "updateoperation.h"
-#include "kdupdaterapplication.h"
+#include "constants.h"
+#include "fileutils.h"
+#include "packagemanagercore.h"
#include <QDataStream>
#include <QDebug>
@@ -88,17 +90,21 @@ static QString backupFileName(const QString &templateName)
/*!
\internal
*/
-UpdateOperation::UpdateOperation()
+UpdateOperation::UpdateOperation(QInstaller::PackageManagerCore *core)
: m_error(0)
-{}
+ , m_core(core)
+{
+ // Store the value for compatibility reasons.
+ m_values[QLatin1String("installer")] = QVariant::fromValue(core);
+}
/*!
\internal
*/
UpdateOperation::~UpdateOperation()
{
- if (Application *app = Application::instance())
- app->addFilesForDelayedDeletion(filesForDelayedDeletion());
+ if (auto *core = packageManager())
+ core->addFilesForDelayedDeletion(filesForDelayedDeletion());
}
/*!
@@ -180,6 +186,42 @@ QStringList UpdateOperation::arguments() const
return m_arguments;
}
+bool UpdateOperation::checkArgumentCount(int minArgCount, int maxArgCount,
+ const QString &argDescription)
+{
+ const int argCount = arguments().count();
+ if (argCount < minArgCount || argCount > maxArgCount) {
+ setError(InvalidArguments);
+ QString countRange;
+ if (minArgCount == maxArgCount)
+ countRange = tr("exactly %1").arg(minArgCount);
+ else if (maxArgCount == INT_MAX)
+ countRange = tr("at least %1").arg(minArgCount);
+ else if (minArgCount == 0)
+ countRange = tr("not more than %1").arg(maxArgCount);
+ else if (minArgCount == maxArgCount - 1)
+ countRange = tr("%1 or %2").arg(minArgCount).arg(maxArgCount);
+ else
+ countRange = tr("%1 to %2").arg(minArgCount).arg(maxArgCount);
+
+ if (argDescription.isEmpty())
+ setErrorString(tr("Invalid arguments in %1: %n arguments given, "
+ "%2 arguments expected.", 0, argCount)
+ .arg(name(), countRange));
+ else
+ setErrorString(tr("Invalid arguments in %1: %n arguments given, "
+ "%2 arguments expected in the form: %3.", 0, argCount)
+ .arg(name(), countRange, argDescription));
+ return false;
+ }
+ return true;
+}
+
+bool UpdateOperation::checkArgumentCount(int argCount)
+{
+ return checkArgumentCount(argCount, argCount);
+}
+
struct StartsWith
{
StartsWith(const QString &searchTerm)
@@ -211,9 +253,9 @@ QString UpdateOperation::argumentKeyValue(const QString &key, const QString &def
it = std::find_if(++it, tArguments.end(), StartsWith(keySeparater));
if (it != tArguments.end()) {
- qWarning() << QString::fromLatin1("There are multiple keys in the arguments calling"
- " '%1'. Only the first found '%2' is used: '%3'").arg(name(), key, arguments().join(
- QLatin1String("; ")));
+ qWarning().nospace() << "There are multiple keys in the arguments calling " << name() << ". "
+ << "Only the first found " << key << " is used: "
+ << arguments().join(QLatin1String("; "));
}
return value;
}
@@ -276,6 +318,14 @@ QStringList UpdateOperation::filesForDelayedDeletion() const
}
/*!
+ Returns the package manager core this operation belongs to.
+*/
+QInstaller::PackageManagerCore *UpdateOperation::packageManager() const
+{
+ return m_core;
+}
+
+/*!
Registers a list of \a files to be deleted later once the application was restarted and the
file or files are not used anymore.
*/
@@ -302,7 +352,8 @@ bool UpdateOperation::deleteFileNowOrLater(const QString &file, QString *errorSt
QFile f(file);
if (!f.rename(backup)) {
if (errorString)
- *errorString = tr("Renaming %1 into %2 failed with %3.").arg(file, backup, f.errorString());
+ *errorString = tr("Renaming file \"%1\" to \"%2\" failed: %3").arg(
+ QDir::toNativeSeparators(file), QDir::toNativeSeparators(backup), f.errorString());
return false;
}
registerForDelayedDeletion(QStringList(backup));
@@ -340,12 +391,6 @@ bool UpdateOperation::deleteFileNowOrLater(const QString &file, QString *errorSt
*/
/*!
- \fn virtual bool KDUpdater::UpdateOperation::clone() const = 0;
-
- Subclasses must implement this function to clone the current operation.
-*/
-
-/*!
Saves operation arguments and values as an XML document and returns the
document. You can override this method to store your
own extra-data. Extra-data can be any data that you need to store to perform or undo the
@@ -357,10 +402,13 @@ QDomDocument UpdateOperation::toXml() const
QDomDocument doc;
QDomElement root = doc.createElement(QLatin1String("operation"));
doc.appendChild(root);
+
QDomElement args = doc.createElement(QLatin1String("arguments"));
+ const QString target = m_core ? m_core->value(QInstaller::scTargetDir) : QString();
Q_FOREACH (const QString &s, arguments()) {
QDomElement arg = doc.createElement(QLatin1String("argument"));
- arg.appendChild(doc.createTextNode(s));
+ arg.appendChild(doc.createTextNode(QInstaller::replacePath(s, target,
+ QLatin1String(QInstaller::scRelocatable))));
args.appendChild(arg);
}
root.appendChild(args);
@@ -369,18 +417,31 @@ QDomDocument UpdateOperation::toXml() const
// append all values set with setValue
QDomElement values = doc.createElement(QLatin1String("values"));
- for (QVariantMap::const_iterator it = m_values.begin(); it != m_values.end(); ++it) {
+ for (QVariantMap::const_iterator it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
+ // the installer can't be put into XML, ignore
+ if (it.key() == QLatin1String("installer"))
+ continue;
+
QDomElement value = doc.createElement(QLatin1String("value"));
- const QVariant& variant = it.value();
+ QVariant variant = it.value();
value.setAttribute(QLatin1String("name"), it.key());
- value.setAttribute(QLatin1String("type"), QLatin1String( QVariant::typeToName( variant.type())));
+ value.setAttribute(QLatin1String("type"), QLatin1String(variant.typeName()));
if (variant.type() != QVariant::List && variant.type() != QVariant::StringList
&& variant.canConvert(QVariant::String)) {
- // it can convert to string? great!
- value.appendChild( doc.createTextNode(variant.toString()));
+ // it can convert to string? great!
+ value.appendChild(doc.createTextNode(QInstaller::replacePath(variant.toString(),
+ target, QLatin1String(QInstaller::scRelocatable))));
} else {
// no? then we have to go the hard way...
+ if (variant.type() == QVariant::StringList) {
+ QStringList list = variant.toStringList();
+ for (int i = 0; i < list.count(); ++i) {
+ list[i] = QInstaller::replacePath(list.at(i), target,
+ QLatin1String(QInstaller::scRelocatable));
+ }
+ variant = QVariant::fromValue(list);
+ }
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
stream << variant;
@@ -394,18 +455,23 @@ QDomDocument UpdateOperation::toXml() const
/*!
Restores operation arguments and values from the XML document \a doc. Returns \c true on
- success, otherwise \c false.
+ success, otherwise \c false. \note: Clears all previously set values and arguments.
*/
bool UpdateOperation::fromXml(const QDomDocument &doc)
{
+ QString target = QCoreApplication::applicationDirPath();
+ QInstaller::isInBundle(target, &target); // Does not change target on non OSX platforms.
+
QStringList args;
const QDomElement root = doc.documentElement();
const QDomElement argsElem = root.firstChildElement(QLatin1String("arguments"));
Q_ASSERT(! argsElem.isNull());
for (QDomNode n = argsElem.firstChild(); ! n.isNull(); n = n.nextSibling()) {
const QDomElement e = n.toElement();
- if (!e.isNull() && e.tagName() == QLatin1String("argument"))
- args << e.text();
+ if (!e.isNull() && e.tagName() == QLatin1String("argument")) {
+ args << QInstaller::replacePath(e.text(), QLatin1String(QInstaller::scRelocatable),
+ target);
+ }
}
setArguments(args);
@@ -425,6 +491,14 @@ bool UpdateOperation::fromXml(const QDomDocument &doc)
if (t == QVariant::List || t == QVariant::StringList || !var.convert(t)) {
QDataStream stream(QByteArray::fromBase64( value.toLatin1()));
stream >> var;
+ if (t == QVariant::StringList) {
+ QStringList list = var.toStringList();
+ for (int i = 0; i < list.count(); ++i) {
+ list[i] = QInstaller::replacePath(list.at(i),
+ QLatin1String(QInstaller::scRelocatable), target);
+ }
+ var = QVariant::fromValue(list);
+ }
}
m_values[name] = var;
diff --git a/src/libs/kdtools/kdupdaterupdateoperation.h b/src/libs/kdtools/updateoperation.h
index 76fca727d..2216cf8f7 100644
--- a/src/libs/kdtools/kdupdaterupdateoperation.h
+++ b/src/libs/kdtools/updateoperation.h
@@ -31,16 +31,20 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_OPERATION_H
-#define KD_UPDATER_UPDATE_OPERATION_H
+#ifndef UPDATEOPERATION_H
+#define UPDATEOPERATION_H
-#include "kdupdater.h"
+#include "updater.h"
#include <QCoreApplication>
#include <QStringList>
#include <QVariant>
#include <QtXml/QDomDocument>
+namespace QInstaller {
+class PackageManagerCore;
+}
+
namespace KDUpdater {
class KDTOOLS_EXPORT UpdateOperation
@@ -54,7 +58,7 @@ public:
UserDefinedError = 128
};
- UpdateOperation();
+ explicit UpdateOperation(QInstaller::PackageManagerCore *core);
virtual ~UpdateOperation();
QString name() const;
@@ -73,11 +77,12 @@ public:
int error() const;
QStringList filesForDelayedDeletion() const;
+ QInstaller::PackageManagerCore *packageManager() const;
+
virtual void backup() = 0;
virtual bool performOperation() = 0;
virtual bool undoOperation() = 0;
virtual bool testOperation() = 0;
- virtual UpdateOperation *clone() const = 0;
virtual QDomDocument toXml() const;
virtual bool fromXml(const QString &xml);
@@ -89,6 +94,8 @@ protected:
void setError(int error, const QString &errorString = QString());
void registerForDelayedDeletion(const QStringList &files);
bool deleteFileNowOrLater(const QString &file, QString *errorString = 0);
+ bool checkArgumentCount(int minArgCount, int maxArgCount, const QString &argDescription = QString());
+ bool checkArgumentCount(int argCount);
private:
QString m_name;
@@ -97,8 +104,9 @@ private:
int m_error;
QVariantMap m_values;
QStringList m_delayedDeletionFiles;
+ QInstaller::PackageManagerCore *m_core;
};
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_OPERATION_H
+#endif // UPDATEOPERATION_H
diff --git a/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp b/src/libs/kdtools/updateoperationfactory.cpp
index 161acbfd4..1df17d532 100644
--- a/src/libs/kdtools/kdupdaterupdateoperationfactory.cpp
+++ b/src/libs/kdtools/updateoperationfactory.cpp
@@ -31,10 +31,10 @@
**
****************************************************************************/
-#include "kdupdaterupdateoperationfactory.h"
-#include "kdupdaterupdateoperations.h"
+#include "updateoperationfactory.h"
-#include <QHash>
+#include "packagemanagercore.h"
+#include "updateoperations.h"
using namespace KDUpdater;
@@ -62,10 +62,13 @@ using namespace KDUpdater;
*/
/*!
+ \obsolete
\fn void KDUpdater::UpdateOperationFactory::registerUpdateOperation(const QString &name)
Registers a new update operation with the factory based on \a name. When create() is called
with that \a name, the update operation is constructed using its default constructor.
+
+ Deprecated. Use registerProduct() instead.
*/
/*!
diff --git a/src/libs/kdtools/kdupdaterupdateoperationfactory.h b/src/libs/kdtools/updateoperationfactory.h
index e60442277..5e81900fa 100644
--- a/src/libs/kdtools/kdupdaterupdateoperationfactory.h
+++ b/src/libs/kdtools/updateoperationfactory.h
@@ -31,18 +31,23 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_OPERATION_FACTORY_H
-#define KD_UPDATER_UPDATE_OPERATION_FACTORY_H
+#ifndef UPDATEOPERATIONFACTORY_H
+#define UPDATEOPERATIONFACTORY_H
-#include <kdgenericfactory.h>
+#include "genericfactory.h"
-#include "kdupdater.h"
+#include "updater.h"
+
+namespace QInstaller {
+class PackageManagerCore;
+}
namespace KDUpdater {
class UpdateOperation;
-class KDTOOLS_EXPORT UpdateOperationFactory : public KDGenericFactory<UpdateOperation>
+class KDTOOLS_EXPORT UpdateOperationFactory : public GenericFactory<UpdateOperation, QString,
+ QInstaller::PackageManagerCore*>
{
Q_DISABLE_COPY(UpdateOperationFactory)
@@ -55,10 +60,10 @@ public:
registerProduct<T>(name);
}
-protected:
+private:
UpdateOperationFactory();
};
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_OPERATION_FACTORY_H
+#endif // UPDATEOPERATIONFACTORY_H
diff --git a/src/libs/kdtools/kdupdaterupdateoperations.cpp b/src/libs/kdtools/updateoperations.cpp
index ed215e9b9..aeeaffe7b 100644
--- a/src/libs/kdtools/kdupdaterupdateoperations.cpp
+++ b/src/libs/kdtools/updateoperations.cpp
@@ -31,7 +31,7 @@
**
****************************************************************************/
-#include "kdupdaterupdateoperations.h"
+#include "updateoperations.h"
#include "errors.h"
#include "fileutils.h"
@@ -98,7 +98,8 @@ static QString backupFileName(const QString &templateName)
// KDUpdater::CopyOperation
////////////////////////////////////////////////////////////////////////////
-CopyOperation::CopyOperation()
+CopyOperation::CopyOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("Copy"));
}
@@ -138,18 +139,15 @@ void CopyOperation::backup()
// race condition: The backup file could get created by another process right now. But this is the same
// in QFile::copy...
if (!QFile::rename(destination, value(QLatin1String("backupOfExistingDestination")).toString()))
- setError(UserDefinedError, tr("Could not backup file %1.").arg(destination));
+ setError(UserDefinedError, tr("Cannot backup file \"%1\".").arg(QDir::toNativeSeparators(destination)));
}
bool CopyOperation::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
- if (arguments().count() != 2) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(arguments().count()));
+ if (!checkArgumentCount(2))
return false;
- }
QString source = sourcePath();
QString destination = destinationPath();
@@ -157,7 +155,7 @@ bool CopyOperation::performOperation()
QFile sourceFile(source);
if (!sourceFile.exists()) {
setError(UserDefinedError);
- setErrorString(tr("Could not copy a non-existent file: %1").arg(source));
+ setErrorString(tr("Cannot copy a non-existent file: %1").arg(QDir::toNativeSeparators(source)));
return false;
}
// If destination file exists, we cannot use QFile::copy() because it does not overwrite an existing
@@ -166,7 +164,8 @@ bool CopyOperation::performOperation()
if (destinationFile.exists()) {
if (!destinationFile.remove()) {
setError(UserDefinedError);
- setErrorString(tr("Could not remove destination file %1: %2").arg(destination, destinationFile.errorString()));
+ setErrorString(tr("Cannot remove file \"%1\": %2").arg(
+ QDir::toNativeSeparators(destination), destinationFile.errorString()));
return false;
}
}
@@ -174,7 +173,9 @@ bool CopyOperation::performOperation()
const bool copied = sourceFile.copy(destination);
if (!copied) {
setError(UserDefinedError);
- setErrorString(tr("Could not copy %1 to %2: %3").arg(source, destination, sourceFile.errorString()));
+ setErrorString(tr("Cannot copy file \"%1\" to \"%2\": %3").arg(
+ QDir::toNativeSeparators(source), QDir::toNativeSeparators(destination),
+ sourceFile.errorString()));
}
return copied;
}
@@ -191,7 +192,8 @@ bool CopyOperation::undoOperation()
QFile destFile(destination);
// first remove the dest
if (destFile.exists() && !destFile.remove()) {
- setError(UserDefinedError, tr("Could not delete file %1: %2").arg(destination, destFile.errorString()));
+ setError(UserDefinedError, tr("Cannot delete file \"%1\": %2").arg(
+ QDir::toNativeSeparators(destination), destFile.errorString()));
return false;
}
@@ -204,7 +206,8 @@ bool CopyOperation::undoOperation()
// otherwise we have to copy the backup back:
const bool success = backupFile.rename(destination);
if (!success)
- setError(UserDefinedError, tr("Could not restore backup file into %1: %2").arg(destination, backupFile.errorString()));
+ setError(UserDefinedError, tr("Cannot restore backup file into \"%1\": %2").arg(
+ QDir::toNativeSeparators(destination), backupFile.errorString()));
return success;
}
@@ -232,17 +235,13 @@ bool CopyOperation::testOperation()
return true;
}
-CopyOperation *CopyOperation::clone() const
-{
- return new CopyOperation();
-}
-
////////////////////////////////////////////////////////////////////////////
// KDUpdater::MoveOperation
////////////////////////////////////////////////////////////////////////////
-MoveOperation::MoveOperation()
+MoveOperation::MoveOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("Move"));
}
@@ -265,37 +264,36 @@ void MoveOperation::backup()
// race condition: The backup file could get created by another process right now. But this is the same
// in QFile::copy...
if (!QFile::rename(dest, value(QLatin1String("backupOfExistingDestination")).toString()))
- setError(UserDefinedError, tr("Could not backup file %1.").arg(dest));
+ setError(UserDefinedError, tr("Cannot backup file \"%1\".").arg(QDir::toNativeSeparators(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
- const QStringList args = this->arguments();
- if (args.count() != 2) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
+ if (!checkArgumentCount(2))
return false;
- }
- const QString dest = args.last();
+ const QStringList args = arguments();
+ const QString dest = args.at(1);
// 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)) {
setError(UserDefinedError);
- setErrorString(tr("Could not remove destination file %1: %2").arg(dest, file.errorString()));
+ setErrorString(tr("Cannot remove file \"%1\": %2").arg(
+ QDir::toNativeSeparators(dest), file.errorString()));
return false;
}
}
// Copy source to destination.
- QFile file(args.first());
+ QFile file(args.at(0));
if (!file.copy(dest)) {
setError(UserDefinedError);
- setErrorString(tr("Could not copy %1 to %2: %3").arg(file.fileName(), dest, file.errorString()));
+ setErrorString(tr("Cannot copy file \"%1\" to \"%2\": %3").arg(QDir::toNativeSeparators(file.fileName()),
+ QDir::toNativeSeparators(dest), file.errorString()));
return false;
}
return deleteFileNowOrLater(file.fileName());
@@ -308,13 +306,14 @@ bool MoveOperation::undoOperation()
// first: copy back the destination to source
QFile destF(dest);
if (!destF.copy(args.first())) {
- setError(UserDefinedError, tr("Cannot copy %1 to %2: %3").arg(dest, args.first(), destF.errorString()));
+ setError(UserDefinedError, tr("Cannot copy file \"%1\" to \"%2\": %3").arg(
+ QDir::toNativeSeparators(dest), QDir::toNativeSeparators(args.first()), destF.errorString()));
return false;
}
// second: delete the move destination
if (!deleteFileNowOrLater(dest)) {
- setError(UserDefinedError, tr("Cannot remove file %1."));
+ setError(UserDefinedError, tr("Cannot remove file \"%1\".").arg(QDir::toNativeSeparators(dest)));
return false;
}
@@ -327,7 +326,8 @@ bool MoveOperation::undoOperation()
QFile backupF(value(QLatin1String("backupOfExistingDestination")).toString());
const bool success = backupF.rename(dest);
if (!success)
- setError(UserDefinedError, tr("Cannot restore backup file for %1: %2").arg(dest, backupF.errorString()));
+ setError(UserDefinedError, tr("Cannot restore backup file for \"%1\": %2").arg(
+ QDir::toNativeSeparators(dest), backupF.errorString()));
return success;
}
@@ -338,17 +338,13 @@ bool MoveOperation::testOperation()
return true;
}
-MoveOperation *MoveOperation::clone() const
-{
- return new MoveOperation;
-}
-
////////////////////////////////////////////////////////////////////////////
// KDUpdater::DeleteOperation
////////////////////////////////////////////////////////////////////////////
-DeleteOperation::DeleteOperation()
+DeleteOperation::DeleteOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("Delete"));
}
@@ -365,19 +361,17 @@ void DeleteOperation::backup()
QFile file(fileName);
if (!file.copy(value(QLatin1String("backupOfExistingFile")).toString()))
- setError(UserDefinedError, tr("Cannot create backup of %1: %2").arg(fileName, file.errorString()));
+ setError(UserDefinedError, tr("Cannot create backup of file \"%1\": %2").arg(
+ QDir::toNativeSeparators(fileName), file.errorString()));
}
bool DeleteOperation::performOperation()
{
// 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()));
+ if (!checkArgumentCount(1))
return false;
- }
- return deleteFileNowOrLater(args.first());
+
+ return deleteFileNowOrLater(arguments().at(0));
}
bool DeleteOperation::undoOperation()
@@ -389,7 +383,8 @@ bool DeleteOperation::undoOperation()
QFile backupF(value(QLatin1String("backupOfExistingFile")).toString());
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()));
+ setError(UserDefinedError, tr("Cannot restore backup file for \"%1\": %2").arg(
+ QDir::toNativeSeparators(fileName), backupF.errorString()));
return success;
}
@@ -399,11 +394,6 @@ bool DeleteOperation::testOperation()
return true;
}
-DeleteOperation *DeleteOperation::clone() const
-{
- return new DeleteOperation;
-}
-
/*!
\reimp
*/
@@ -426,7 +416,8 @@ QDomDocument DeleteOperation::toXml() const
// KDUpdater::MkdirOperation
////////////////////////////////////////////////////////////////////////////
-MkdirOperation::MkdirOperation()
+MkdirOperation::MkdirOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("Mkdir"));
}
@@ -458,18 +449,15 @@ void MkdirOperation::backup()
bool MkdirOperation::performOperation()
{
// Requires only one parameter. That is the path which should be created
- QStringList args = this->arguments();
- if (args.count() != 1) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count()));
+ if (!checkArgumentCount(1))
return false;
- }
- const QString dirName = args.first();
+ const QString dirName = arguments().at(0);
const bool created = QDir::root().mkpath(dirName);
if (!created) {
setError(UserDefinedError);
- setErrorString(tr("Could not create folder %1: Unknown error.").arg(dirName));
+ setErrorString(tr("Cannot create directory \"%1\": %2").arg(
+ QDir::toNativeSeparators(dirName), tr("Unknown error.")));
}
return created;
}
@@ -501,9 +489,11 @@ bool MkdirOperation::undoOperation()
if (!result) {
if (errorString.isEmpty())
- setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errorString));
+ setError(UserDefinedError, tr("Cannot remove directory \"%1\": %2").arg(
+ QDir::toNativeSeparators(createdDir.path()), errorString));
else
- setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errnoToQString(errno)));
+ setError(UserDefinedError, tr("Cannot remove directory \"%1\": %2").arg(
+ QDir::toNativeSeparators(createdDir.path()), errnoToQString(errno)));
}
return result;
}
@@ -514,16 +504,13 @@ bool KDUpdater::MkdirOperation::testOperation()
return true;
}
-MkdirOperation *MkdirOperation::clone() const
-{
- return new MkdirOperation;
-}
////////////////////////////////////////////////////////////////////////////
// KDUpdater::RmdirOperation
////////////////////////////////////////////////////////////////////////////
-RmdirOperation::RmdirOperation()
+RmdirOperation::RmdirOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("Rmdir"));
setValue(QLatin1String("removed"), false);
@@ -537,26 +524,25 @@ void RmdirOperation::backup()
bool RmdirOperation::performOperation()
{
// 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()));
+ if (!checkArgumentCount(1))
return false;
- }
- QDir dir(args.first());
+ const QString firstArg = arguments().at(0);
+ QDir dir(firstArg);
if (!dir.exists()) {
setError(UserDefinedError);
- setErrorString(tr("Could not remove folder %1: The folder does not exist.").arg(args.first()));
+ setErrorString(tr("Cannot remove directory \"%1\": %2").arg(
+ QDir::toNativeSeparators(firstArg), tr("The directory does not exist.")));
return false;
}
errno = 0;
- const bool removed = dir.rmdir(args.first());
+ const bool removed = dir.rmdir(firstArg);
setValue(QLatin1String("removed"), removed);
if (!removed) {
setError(UserDefinedError);
- setErrorString(tr("Could not remove folder %1: %2").arg(args.first(), errnoToQString(errno)));
+ setErrorString(tr("Cannot remove directory \"%1\": %2").arg(
+ QDir::toNativeSeparators(firstArg), errnoToQString(errno)));
}
return removed;
}
@@ -570,7 +556,8 @@ bool RmdirOperation::undoOperation()
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)));
+ setError(UserDefinedError, tr("Cannot recreate directory \"%1\": %2").arg(
+ QDir::toNativeSeparators(fi.fileName()), errnoToQString(errno)));
return success;
}
@@ -581,17 +568,13 @@ bool RmdirOperation::testOperation()
return true;
}
-RmdirOperation *RmdirOperation::clone() const
-{
- return new RmdirOperation;
-}
-
////////////////////////////////////////////////////////////////////////////
// KDUpdater::AppendFileOperation
////////////////////////////////////////////////////////////////////////////
-AppendFileOperation::AppendFileOperation()
+AppendFileOperation::AppendFileOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("AppendFile"));
}
@@ -606,7 +589,8 @@ void AppendFileOperation::backup()
setValue(QLatin1String("backupOfFile"), backupFileName(filename));
if (!file.copy(value(QLatin1String("backupOfFile")).toString())) {
- setError(UserDefinedError, tr("Cannot backup file %1: %2").arg(filename, file.errorString()));
+ setError(UserDefinedError, tr("Cannot backup file \"%1\": %2").arg(
+ QDir::toNativeSeparators(filename), file.errorString()));
clearValue(QLatin1String("backupOfFile"));
}
}
@@ -615,15 +599,11 @@ 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.
- const QStringList args = this->arguments();
- if (args.count() != 2) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.")
- .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String("")));
+ if (!checkArgumentCount(2))
return false;
- }
- const QString fName = args.first();
+ const QStringList args = this->arguments();
+ const QString fName = args.at(0);
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
@@ -645,14 +625,15 @@ bool AppendFileOperation::performOperation()
if (error) {
setError(UserDefinedError);
- setErrorString(tr("Could not open file '%1' for writing: %2").arg(file.fileName(), file.errorString()));
+ setErrorString(tr("Cannot open file \"%1\" for writing: %2").arg(
+ QDir::toNativeSeparators(file.fileName()), file.errorString()));
return false;
}
deleteFileNowOrLater(newName);
}
QTextStream ts(&file);
- ts << args.last();
+ ts << args.at(1);
file.close();
return true;
@@ -664,13 +645,15 @@ bool AppendFileOperation::undoOperation()
const QString filename = arguments().first();
const QString backupOfFile = value(QLatin1String("backupOfFile")).toString();
if (!backupOfFile.isEmpty() && !QFile::exists(backupOfFile)) {
- setError(UserDefinedError, tr("Cannot find backup file for %1.").arg(filename));
+ setError(UserDefinedError, tr("Cannot find backup file for \"%1\".").arg(
+ QDir::toNativeSeparators(filename)));
return false;
}
const bool removed = deleteFileNowOrLater(filename);
if (!removed) {
- setError(UserDefinedError, tr("Could not restore backup file for %1.").arg(filename));
+ setError(UserDefinedError, tr("Cannot restore backup file for \"%1\".").arg(
+ QDir::toNativeSeparators(filename)));
return false;
}
@@ -681,7 +664,8 @@ bool AppendFileOperation::undoOperation()
QFile backupFile(backupOfFile);
const bool success = backupFile.rename(filename);
if (!success)
- setError(UserDefinedError, tr("Could not restore backup file for %1: %2").arg(filename, backupFile.errorString()));
+ setError(UserDefinedError, tr("Cannot restore backup file for \"%1\": %2").arg(
+ QDir::toNativeSeparators(filename), backupFile.errorString()));
return success;
}
@@ -691,17 +675,13 @@ bool AppendFileOperation::testOperation()
return true;
}
-AppendFileOperation *AppendFileOperation::clone() const
-{
- return new AppendFileOperation;
-}
-
////////////////////////////////////////////////////////////////////////////
// KDUpdater::PrependFileOperation
////////////////////////////////////////////////////////////////////////////
-PrependFileOperation::PrependFileOperation()
+PrependFileOperation::PrependFileOperation(QInstaller::PackageManagerCore *core)
+ : UpdateOperation(core)
{
setName(QLatin1String("PrependFile"));
}
@@ -716,7 +696,8 @@ void PrependFileOperation::backup()
setValue(QLatin1String("backupOfFile"), backupFileName(filename));
if (!file.copy(value(QLatin1String("backupOfFile")).toString())) {
- setError(UserDefinedError, tr("Cannot backup file %1: %2").arg(filename, file.errorString()));
+ setError(UserDefinedError, tr("Cannot backup file \"%1\": %2").arg(
+ QDir::toNativeSeparators(filename), file.errorString()));
clearValue(QLatin1String("backupOfFile"));
}
}
@@ -726,19 +707,17 @@ 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.
- const QStringList args = this->arguments();
- if (args.count() != 2) {
- setError(InvalidArguments);
- setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count()));
+ if (!checkArgumentCount(2))
return false;
- }
- const QString fName = args.first();
+ const QStringList args = this->arguments();
+ const QString fName = args.at(0);
// Load the file first.
QFile file(fName);
if (!file.open(QFile::ReadOnly)) {
setError(UserDefinedError);
- setErrorString(tr("Could not open file %1 for reading: %2").arg(file.fileName(), file.errorString()));
+ setErrorString(tr("Cannot open file \"%1\" for reading: %2").arg(
+ QDir::toNativeSeparators(file.fileName()), file.errorString()));
return false;
}
@@ -747,7 +726,7 @@ bool PrependFileOperation::performOperation()
file.close();
// Prepend text to the file text
- fContents = args.last() + fContents;
+ fContents = args.at(1) + fContents;
// Now re-open the file in write only mode.
if (!file.open(QFile::WriteOnly)) {
@@ -756,7 +735,8 @@ bool PrependFileOperation::performOperation()
if (!QFile::rename(fName, newName) && QFile::copy(newName, fName) && file.open(QFile::WriteOnly)) {
QFile::rename(newName, fName);
setError(UserDefinedError);
- setErrorString(tr("Could not open file %1 for writing: %2").arg(file.fileName(), file.errorString()));
+ setErrorString(tr("Cannot open file \"%1\" for writing: %2").arg(
+ QDir::toNativeSeparators(file.fileName()), file.errorString()));
return false;
}
deleteFileNowOrLater(newName);
@@ -774,12 +754,14 @@ bool PrependFileOperation::undoOperation()
const QString filename = arguments().first();
const QString backupOfFile = value(QLatin1String("backupOfFile")).toString();
if (!backupOfFile.isEmpty() && !QFile::exists(backupOfFile)) {
- setError(UserDefinedError, tr("Cannot find backup file for %1.").arg(filename));
+ setError(UserDefinedError,
+ tr("Cannot find backup file for \"%1\".").arg(QDir::toNativeSeparators(filename)));
return false;
}
if (!deleteFileNowOrLater(filename)) {
- setError(UserDefinedError, tr("Cannot restore backup file for %1.").arg(filename));
+ setError(UserDefinedError,
+ tr("Cannot restore backup file for \"%1\".").arg(QDir::toNativeSeparators(filename)));
return false;
}
@@ -790,7 +772,8 @@ bool PrependFileOperation::undoOperation()
QFile backupF(backupOfFile);
const bool success = backupF.rename(filename);
if (!success)
- setError(UserDefinedError, tr("Cannot restore backup file for %1: %2").arg(filename, backupF.errorString()));
+ setError(UserDefinedError, tr("Cannot restore backup file for \"%1\": %2").arg(
+ QDir::toNativeSeparators(filename), backupF.errorString()));
return success;
}
@@ -800,8 +783,3 @@ bool PrependFileOperation::testOperation()
// TODO
return true;
}
-
-PrependFileOperation *PrependFileOperation::clone() const
-{
- return new PrependFileOperation;
-}
diff --git a/src/libs/kdtools/kdupdaterupdateoperations.h b/src/libs/kdtools/updateoperations.h
index fec24c8c9..1c6c6ea97 100644
--- a/src/libs/kdtools/kdupdaterupdateoperations.h
+++ b/src/libs/kdtools/updateoperations.h
@@ -31,24 +31,23 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_OPERATIONS_H
-#define KD_UPDATER_UPDATE_OPERATIONS_H
+#ifndef UPDATEOPERATIONS_H
+#define UPDATEOPERATIONS_H
-#include "kdupdaterupdateoperation.h"
+#include "updateoperation.h"
namespace KDUpdater {
class KDTOOLS_EXPORT CopyOperation : public UpdateOperation
{
public:
- CopyOperation();
+ explicit CopyOperation(QInstaller::PackageManagerCore *core = 0);
~CopyOperation();
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- CopyOperation *clone() const;
QDomDocument toXml() const;
private:
@@ -59,27 +58,25 @@ private:
class KDTOOLS_EXPORT MoveOperation : public UpdateOperation
{
public:
- MoveOperation();
+ explicit MoveOperation(QInstaller::PackageManagerCore *core = 0);
~MoveOperation();
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- MoveOperation *clone() const;
};
class KDTOOLS_EXPORT DeleteOperation : public UpdateOperation
{
public:
- DeleteOperation();
+ explicit DeleteOperation(QInstaller::PackageManagerCore *core = 0);
~DeleteOperation();
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- DeleteOperation *clone() const;
QDomDocument toXml() const;
};
@@ -87,51 +84,47 @@ public:
class KDTOOLS_EXPORT MkdirOperation : public UpdateOperation
{
public:
- MkdirOperation();
+ explicit MkdirOperation(QInstaller::PackageManagerCore *core = 0);
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- MkdirOperation *clone() const;
};
class KDTOOLS_EXPORT RmdirOperation : public UpdateOperation
{
public:
- RmdirOperation();
+ RmdirOperation(QInstaller::PackageManagerCore *core = 0);
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- RmdirOperation *clone() const;
};
class KDTOOLS_EXPORT AppendFileOperation : public UpdateOperation
{
public:
- AppendFileOperation();
+ explicit AppendFileOperation(QInstaller::PackageManagerCore *core = 0);
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- AppendFileOperation *clone() const;
};
class KDTOOLS_EXPORT PrependFileOperation : public UpdateOperation
{
public:
- PrependFileOperation();
+ explicit PrependFileOperation(QInstaller::PackageManagerCore *core = 0);
void backup();
bool performOperation();
bool undoOperation();
bool testOperation();
- PrependFileOperation *clone() const;
};
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_OPERATIONS_H
+#endif // UPDATEOPERATIONS_H
diff --git a/src/libs/kdtools/kdupdater.h b/src/libs/kdtools/updater.h
index c38bf7de2..89ce0acb4 100644
--- a/src/libs/kdtools/kdupdater.h
+++ b/src/libs/kdtools/updater.h
@@ -31,8 +31,8 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_H
-#define KD_UPDATER_H
+#ifndef UPDATER_H
+#define UPDATER_H
#include "kdtoolsglobal.h"
@@ -50,4 +50,4 @@ namespace KDUpdater
KDTOOLS_EXPORT int compareVersion(const QString &v1, const QString &v2);
}
-#endif
+#endif // UPDATER_H
diff --git a/src/libs/kdtools/kdupdaterupdatesinfo.cpp b/src/libs/kdtools/updatesinfo.cpp
index 7c80e135a..414ba28a7 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfo.cpp
+++ b/src/libs/kdtools/updatesinfo.cpp
@@ -31,9 +31,10 @@
**
****************************************************************************/
-#include "kdupdaterupdatesinfo_p.h"
+#include "updatesinfo_p.h"
#include "utils.h"
+#include <QDomDocument>
#include <QFile>
#include <QLocale>
#include <QPair>
@@ -62,7 +63,7 @@ void UpdatesInfoData::parseFile(const QString &updateXmlFile)
QFile file(updateXmlFile);
if (!file.open(QFile::ReadOnly)) {
error = UpdatesInfo::CouldNotReadUpdateInfoFileError;
- errorMessage = tr("Could not read \"%1\"").arg(updateXmlFile);
+ errorMessage = tr("Cannot read \"%1\"").arg(updateXmlFile);
return;
}
@@ -143,6 +144,8 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
info.data.insert(QLatin1String("inheritVersionFrom"),
childE.attribute(QLatin1String("inheritVersionFrom")));
info.data[childE.tagName()] = childE.text();
+ } else if (childE.tagName() == QLatin1String("DisplayName")) {
+ processLocalizedTag(childE, info.data);
} else if (childE.tagName() == QLatin1String("Description")) {
if (!childE.hasAttribute(QLatin1String("xml:lang")))
info.data[QLatin1String("Description")] = childE.text();
@@ -183,6 +186,17 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
return true;
}
+void UpdatesInfoData::processLocalizedTag(const QDomElement &childE, QHash<QString, QVariant> &info) const
+{
+ QString languageAttribute = childE.attribute(QLatin1String("xml:lang")).toLower();
+ if (!info.contains(childE.tagName()) && (languageAttribute.isEmpty()))
+ info[childE.tagName()] = childE.text();
+
+ // overwrite default if we have a language specific description
+ if (QLocale().name().startsWith(languageAttribute, Qt::CaseInsensitive))
+ info[childE.tagName()] = childE.text();
+}
+
//
// UpdatesInfo
diff --git a/src/libs/kdtools/kdupdaterupdatesinfo_p.h b/src/libs/kdtools/updatesinfo_p.h
index eb841417f..cb98b5a54 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfo_p.h
+++ b/src/libs/kdtools/updatesinfo_p.h
@@ -31,11 +31,11 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_INFO_H
-#define KD_UPDATER_UPDATE_INFO_H
+#ifndef UPDATESINFO_P_H
+#define UPDATESINFO_P_H
-#include "kdupdater.h"
-#include "kdupdaterupdatesinfodata_p.h"
+#include "updater.h"
+#include "updatesinfodata_p.h"
#include <QHash>
#include <QSharedData>
@@ -87,4 +87,4 @@ private:
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_INFO_H
+#endif // UPDATESINFO_P_H
diff --git a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h b/src/libs/kdtools/updatesinfodata_p.h
index be1cc217e..eeac18130 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
+++ b/src/libs/kdtools/updatesinfodata_p.h
@@ -31,13 +31,14 @@
**
****************************************************************************/
-#ifndef KD_UPDATER_UPDATE_INFO_DATA_H
-#define KD_UPDATER_UPDATE_INFO_DATA_H
+#ifndef UPDATESINFODATA_P_H
+#define UPDATESINFODATA_P_H
#include <QCoreApplication>
-#include <QDomElement>
#include <QSharedData>
+QT_FORWARD_DECLARE_CLASS(QDomElement)
+
namespace KDUpdater {
struct UpdateInfo;
@@ -61,8 +62,11 @@ public:
bool parsePackageUpdateElement(const QDomElement &updateE);
void setInvalidContentError(const QString &detail);
+
+private:
+ void processLocalizedTag(const QDomElement &childE, QHash<QString, QVariant> &info) const;
};
} // namespace KDUpdater
-#endif // KD_UPDATER_UPDATE_INFO_DATA_H
+#endif // UPDATESINFODATA_P_H