summaryrefslogtreecommitdiffstats
path: root/src/libs/installer
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@digia.com>2013-02-28 13:24:58 +0100
committerTim Jenssen <tim.jenssen@digia.com>2013-02-28 13:25:47 +0100
commit2b821012f37784b6e4fa9c572b50bebf9b5e660a (patch)
treece2c5fff34ba7e756526c8e0d97abf09b9317c97 /src/libs/installer
parentae11e205d25a1294bb2c127debebde08ac4575c1 (diff)
parente094c0c0fa72d6b51e3d583374985efb614804db (diff)
Merge remote-tracking branch 'origin/1.3'
Diffstat (limited to 'src/libs/installer')
-rw-r--r--src/libs/installer/fakestopprocessforupdateoperation.cpp80
-rw-r--r--src/libs/installer/fakestopprocessforupdateoperation.h4
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp28
-rw-r--r--src/libs/installer/repository.h8
4 files changed, 52 insertions, 68 deletions
diff --git a/src/libs/installer/fakestopprocessforupdateoperation.cpp b/src/libs/installer/fakestopprocessforupdateoperation.cpp
index 47d21c39f..ead887118 100644
--- a/src/libs/installer/fakestopprocessforupdateoperation.cpp
+++ b/src/libs/installer/fakestopprocessforupdateoperation.cpp
@@ -41,53 +41,10 @@
#include "fakestopprocessforupdateoperation.h"
-#include <kdsysinfo.h>
-#include <QtCore/QDir>
-
-#include <algorithm>
+#include "messageboxhandler.h"
+#include "packagemanagercore.h"
using namespace KDUpdater;
-
-/*!
- Copied from QInstaller with some adjustments
- Return true, if a process with \a name is running. On Windows, the comparision is case-insensitive.
-*/
-static bool isProcessRunning(const QString &name, const QList<ProcessInfo> &processes)
-{
- for (QList<ProcessInfo>::const_iterator it = processes.constBegin(); it != processes.constEnd(); ++it) {
- if (it->name.isEmpty())
- continue;
-
-#ifndef Q_OS_WIN
- if (it->name == name)
- return true;
- const QFileInfo fi(it->name);
- if (fi.fileName() == name || fi.baseName() == name)
- return true;
-#else
- if (it->name.toLower() == name.toLower())
- return true;
- if (it->name.toLower() == QDir::toNativeSeparators(name.toLower()))
- return true;
- const QFileInfo fi(it->name);
- if (fi.fileName().toLower() == name.toLower() || fi.baseName().toLower() == name.toLower())
- return true;
-#endif
- }
- return false;
-}
-
-static QStringList checkRunningProcessesFromList(const QStringList &processList)
-{
- const QList<ProcessInfo> allProcesses = runningProcesses();
- QStringList stillRunningProcesses;
- foreach (const QString &process, processList) {
- if (!process.isEmpty() && isProcessRunning(process, allProcesses))
- stillRunningProcesses.append(process);
- }
- return stillRunningProcesses;
-}
-
using namespace QInstaller;
FakeStopProcessForUpdateOperation::FakeStopProcessForUpdateOperation()
@@ -113,18 +70,31 @@ bool FakeStopProcessForUpdateOperation::undoOperation()
return false;
}
- QStringList processList = arguments()[0].split(QLatin1String(","), QString::SkipEmptyParts);
- qSort(processList);
- processList.erase(std::unique(processList.begin(), processList.end()), processList.end());
- if (!processList.isEmpty()) {
- const QStringList processes = checkRunningProcessesFromList(processList);
- if (!processes.isEmpty()) {
- setError(KDUpdater::UpdateOperation::UserDefinedError, tr("These processes should be stopped to "
- "continue:\n\n%1").arg(QDir::toNativeSeparators(processes.join(QLatin1String("\n")))));
- }
+ PackageManagerCore *const core = value(QLatin1String("installer")).value<PackageManagerCore*>();
+ if (!core) {
+ setError(KDUpdater::UpdateOperation::UserDefinedError, QObject::tr("Could not get package manager "
+ "core."));
return false;
}
- return true;
+
+ QStringList processes = arguments().at(0).split(QLatin1Char(','), QString::SkipEmptyParts);
+ for (int i = processes.count() - 1; i >= 0; --i) {
+ if (!core->isProcessRunning(processes.at(i)))
+ processes.removeAt(i);
+ }
+
+ if (processes.isEmpty())
+ return true;
+
+ if (processes.count() == 1) {
+ setError(UpdateOperation::UserDefinedError, QObject::tr("This process should be stopped before "
+ "continuing: %1").arg(processes.first()));
+ } else {
+ const QString sep = QString::fromWCharArray(L"\n \u2022 "); // Unicode bullet
+ setError(UpdateOperation::UserDefinedError, QObject::tr("These processes should be stopped before "
+ "continuing: %1").arg(sep + processes.join(sep)));
+ }
+ return false;
}
bool FakeStopProcessForUpdateOperation::testOperation()
diff --git a/src/libs/installer/fakestopprocessforupdateoperation.h b/src/libs/installer/fakestopprocessforupdateoperation.h
index 228d5df03..ca7ba3ccc 100644
--- a/src/libs/installer/fakestopprocessforupdateoperation.h
+++ b/src/libs/installer/fakestopprocessforupdateoperation.h
@@ -46,8 +46,10 @@
namespace QInstaller {
-class FakeStopProcessForUpdateOperation : public Operation
+class INSTALLER_EXPORT FakeStopProcessForUpdateOperation : public QObject, public Operation
{
+ Q_OBJECT
+
public:
FakeStopProcessForUpdateOperation();
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 04faa051a..4a7452cd4 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -82,30 +82,42 @@ namespace QInstaller {
class OperationTracer
{
public:
- OperationTracer() {}
- void trace(Operation *operation, const QString &state)
+ OperationTracer(Operation *operation) : m_operation(0)
{
- qDebug() << state << " operation: " << operation->name();
- qDebug() << " - arguments: " << operation->arguments().join(QLatin1String(", "));
+ // don't create output for that hacky pseudo operation
+ if (operation->name() != QLatin1String("MinimumProgress"))
+ m_operation = operation;
+ }
+ void trace(const QString &state)
+ {
+ if (!m_operation)
+ return;
+ qDebug() << QString::fromLatin1("%1 operation: %2").arg(state, m_operation->name());
+ qDebug() << QString::fromLatin1("\t- arguments: %1").arg(m_operation->arguments()
+ .join(QLatin1String(", ")));
}
~OperationTracer() {
+ if (!m_operation)
+ return;
qDebug() << "Done";
}
+private:
+ Operation *m_operation;
};
static bool runOperation(Operation *operation, PackageManagerCorePrivate::OperationType type)
{
- OperationTracer tracer;
+ OperationTracer tracer(operation);
switch (type) {
case PackageManagerCorePrivate::Backup:
- tracer.trace(operation, QLatin1String("backup"));
+ tracer.trace(QLatin1String("backup"));
operation->backup();
return true;
case PackageManagerCorePrivate::Perform:
- tracer.trace(operation, QLatin1String("perform"));
+ tracer.trace(QLatin1String("perform"));
return operation->performOperation();
case PackageManagerCorePrivate::Undo:
- tracer.trace(operation, QLatin1String("undo"));
+ tracer.trace(QLatin1String("undo"));
return operation->undoOperation();
default:
Q_ASSERT(!"unexpected operation type");
diff --git a/src/libs/installer/repository.h b/src/libs/installer/repository.h
index c1a979615..967cae75d 100644
--- a/src/libs/installer/repository.h
+++ b/src/libs/installer/repository.h
@@ -79,8 +79,8 @@ public:
uint qHash(const Repository &repository);
const Repository &operator=(const Repository &other);
- friend QDataStream &operator>>(QDataStream &istream, Repository &repository);
- friend QDataStream &operator<<(QDataStream &ostream, const Repository &repository);
+ friend INSTALLER_EXPORT QDataStream &operator>>(QDataStream &istream, Repository &repository);
+ friend INSTALLER_EXPORT QDataStream &operator<<(QDataStream &ostream, const Repository &repository);
private:
void registerMetaType();
@@ -98,8 +98,8 @@ inline uint qHash(const Repository &repository)
return qHash(repository.url());
}
-QDataStream &operator>>(QDataStream &istream, Repository &repository);
-QDataStream &operator<<(QDataStream &ostream, const Repository &repository);
+INSTALLER_EXPORT QDataStream &operator>>(QDataStream &istream, Repository &repository);
+INSTALLER_EXPORT QDataStream &operator<<(QDataStream &ostream, const Repository &repository);
} // namespace QInstaller