summaryrefslogtreecommitdiffstats
path: root/src/manager-lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/manager-lib')
-rw-r--r--src/manager-lib/applicationmanager.cpp25
-rw-r--r--src/manager-lib/applicationmanager.h2
-rw-r--r--src/manager-lib/installationtask.cpp48
3 files changed, 45 insertions, 30 deletions
diff --git a/src/manager-lib/applicationmanager.cpp b/src/manager-lib/applicationmanager.cpp
index 49e578a0..e950e10a 100644
--- a/src/manager-lib/applicationmanager.cpp
+++ b/src/manager-lib/applicationmanager.cpp
@@ -564,6 +564,17 @@ QVector<Application *> ApplicationManager::mimeTypeHandlers(const QString &mimeT
return handlers;
}
+QVariantMap ApplicationManager::get(Application *app) const
+{
+ QVariantMap map;
+ if (app) {
+ const QHash<int, QByteArray> roles = roleNames();
+ for (auto it = roles.begin(); it != roles.end(); ++it)
+ map.insert(QString::fromLatin1(it.value()), dataForRole(app, it.key()));
+ }
+ return map;
+}
+
void ApplicationManager::registerMimeTypes()
{
#if defined(QT_GUI_LIB)
@@ -1254,7 +1265,11 @@ QVariant ApplicationManager::data(const QModelIndex &index, int role) const
return QVariant();
Application *app = d->apps.at(index.row());
+ return dataForRole(app, role);
+}
+QVariant ApplicationManager::dataForRole(Application *app, int role) const
+{
switch (role) {
case AMRoles::Id:
return app->id();
@@ -1325,12 +1340,7 @@ QVariantMap ApplicationManager::get(int index) const
qCWarning(LogSystem) << "ApplicationManager::get(index): invalid index:" << index;
return QVariantMap();
}
-
- QVariantMap map;
- QHash<int, QByteArray> roles = roleNames();
- for (auto it = roles.begin(); it != roles.end(); ++it)
- map.insert(qL1S(it.value()), data(this->index(index), it.key()));
- return map;
+ return get(d->apps.at(index));
}
/*!
@@ -1421,8 +1431,7 @@ QStringList ApplicationManager::applicationIds() const
*/
QVariantMap ApplicationManager::get(const QString &id) const
{
- int index = indexOfApplication(id);
- return (index < 0) ? QVariantMap{} : get(index);
+ return get(application(id));
}
Am::RunState ApplicationManager::applicationRunState(const QString &id) const
diff --git a/src/manager-lib/applicationmanager.h b/src/manager-lib/applicationmanager.h
index 3b69b7d2..9fd37edd 100644
--- a/src/manager-lib/applicationmanager.h
+++ b/src/manager-lib/applicationmanager.h
@@ -72,6 +72,7 @@ public:
Application *fromSecurityToken(const QByteArray &securityToken) const;
QVector<Application *> schemeHandlers(const QString &scheme) const;
QVector<Application *> mimeTypeHandlers(const QString &mimeType) const;
+ QVariantMap get(Application *app) const;
bool startApplicationInternal(const QString &appId, const QString &documentUrl = QString(),
const QString &documentMimeType = QString(),
@@ -95,6 +96,7 @@ public:
// the item model part
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
+ QVariant dataForRole(Application *app, int role) const;
QHash<int, QByteArray> roleNames() const override;
int count() const;
diff --git a/src/manager-lib/installationtask.cpp b/src/manager-lib/installationtask.cpp
index 69ebdace..eda70995 100644
--- a/src/manager-lib/installationtask.cpp
+++ b/src/manager-lib/installationtask.cpp
@@ -150,8 +150,7 @@ void InstallationTask::execute()
connect(m_extractor, &PackageExtractor::progress, this, &AsynchronousTask::progress);
- m_extractor->setFileExtractedCallback(std::bind(&InstallationTask::checkExtractedFile,
- this, std::placeholders::_1));
+ m_extractor->setFileExtractedCallback([this](const QString &f) { checkExtractedFile(f); });
if (!m_extractor->extract())
throw Exception(m_extractor->errorCode(), m_extractor->errorString());
@@ -291,6 +290,9 @@ void InstallationTask::checkExtractedFile(const QString &file) Q_DECL_NOEXCEPT_E
}
if (m_foundIcon && m_foundInfo) {
+ // we're not interested in any other files from here on...
+ m_extractor->setFileExtractedCallback(nullptr);
+
bool doubleInstallation = false;
QMetaObject::invokeMethod(PackageManager::instance(), [this, &doubleInstallation]() {
doubleInstallation = PackageManager::instance()->isPackageInstallationActive(m_packageId);
@@ -298,22 +300,6 @@ void InstallationTask::checkExtractedFile(const QString &file) Q_DECL_NOEXCEPT_E
if (doubleInstallation)
throw Exception(Error::Package, "Cannot install the same package %1 multiple times in parallel").arg(m_packageId);
- qCDebug(LogInstaller) << "emit taskRequestingInstallationAcknowledge" << id() << "for package" << m_package->id();
-
- // this is a temporary just for the signal emission below
- m_tempPackageForAcknowledge.reset(new Package(m_package.get(), Package::BeingInstalled));
- m_tempPackageForAcknowledge->moveToThread(m_pm->thread());
- const auto &applicationInfos = m_package.get()->applications();
- for (const auto &applicationInfo : applicationInfos) {
- auto tempApp = new Application(applicationInfo, m_tempPackageForAcknowledge.get());
- tempApp->moveToThread(m_pm->thread());
- m_tempPackageForAcknowledge->addApplication(tempApp);
- m_tempApplicationsForAcknowledge.emplace_back(tempApp);
- }
- emit m_pm->taskRequestingInstallationAcknowledge(id(), m_tempPackageForAcknowledge.get(),
- m_extractor->installationReport().extraMetaData(),
- m_extractor->installationReport().extraSignedMetaData());
-
QDir oldDestinationDirectory = m_extractor->destinationDirectory();
startInstallation();
@@ -346,6 +332,28 @@ void InstallationTask::checkExtractedFile(const QString &file) Q_DECL_NOEXCEPT_E
if (!m_managerApproval)
throw Exception("PackageManager declined the installation of %1").arg(packageId);
+ qCDebug(LogInstaller) << "emit taskRequestingInstallationAcknowledge" << id() << "for package" << packageId;
+
+ // Create temporary objects for QML just for the signal emission.
+ // The problem here is that the PackageInfo instance backing the Package object is also
+ // temporary and the ownership is with the C++ side of the PackageManager.
+ // Ideally we should have kept the 'package' parameter as a dumb QVariantMap, but changing
+ // that back would be a huge API break nowadays as the QML APIs are fully typed.
+ // At least we have to make sure NOT to change anything in the PackageInfo instance after
+ // the signal emission below.
+ m_tempPackageForAcknowledge.reset(new Package(newPackage->info(), Package::BeingInstalled));
+ m_tempPackageForAcknowledge->moveToThread(m_pm->thread());
+ const auto &applicationInfos = newPackage->info()->applications();
+ for (const auto &applicationInfo : applicationInfos) {
+ auto tempApp = new Application(applicationInfo, m_tempPackageForAcknowledge.get());
+ tempApp->moveToThread(m_pm->thread());
+ m_tempPackageForAcknowledge->addApplication(tempApp);
+ m_tempApplicationsForAcknowledge.emplace_back(tempApp);
+ }
+ emit m_pm->taskRequestingInstallationAcknowledge(id(), m_tempPackageForAcknowledge.get(),
+ m_extractor->installationReport().extraMetaData(),
+ m_extractor->installationReport().extraSignedMetaData());
+
// if any of the apps in the package were running before, we now need to wait until all of
// them have actually stopped
while (!m_canceled && newPackage && !newPackage->areAllApplicationsStoppedDueToBlock())
@@ -353,9 +361,6 @@ void InstallationTask::checkExtractedFile(const QString &file) Q_DECL_NOEXCEPT_E
if (m_canceled || newPackage.isNull())
throw Exception(Error::Canceled, "canceled");
-
- // we're not interested in any other files from here on...
- m_extractor->setFileExtractedCallback(nullptr);
}
}
@@ -429,7 +434,6 @@ void InstallationTask::finishInstallation() Q_DECL_NOEXCEPT_EXPR(false)
// POSIX cannot atomically rename directories, if the destination directory exists
// and is non-empty. We need to do a double-rename in this case, which might fail!
- // The image is a file, so this limitation does not apply!
ScopedRenamer renameApplication;