summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2017-02-08 10:00:38 +0100
committerJan Grulich <[email protected]>2017-02-08 10:00:38 +0100
commit01d4234fae276ca46d18ce78f42075bd126e1965 (patch)
tree8f52ae8f724698dc4ff7c548e1aa0f840111fd76
parent0fd62048c747729f7ff4ef9b470ed3d206e49a6f (diff)
Automatically install required runtime when it's not installed
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp13
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakTransaction.cpp92
-rw-r--r--libdiscover/backends/FlatpakBackend/FlatpakTransaction.h21
3 files changed, 107 insertions, 19 deletions
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
index c79d774..83b7def 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
@@ -661,12 +661,21 @@ FlatpakInstallation * FlatpakBackend::flatpakInstallationForAppScope(FlatpakReso
void FlatpakBackend::installApplication(AbstractResource *app, const AddonList &addons)
{
+ FlatpakTransaction *transaction = nullptr;
FlatpakResource *resource = qobject_cast<FlatpakResource*>(app);
FlatpakInstallation *installation = resource->scope() == FlatpakResource::System ? m_flatpakInstallationSystem : m_flatpakInstallationUser;
- // TODO: Check if the runtime needed by the application is installed
+ FlatpakResource *runtime = getRuntimeForApp(resource);
+ if (runtime) {
+ if (!runtime->isInstalled()) {
+ transaction = new FlatpakTransaction(installation, resource, runtime, addons, Transaction::InstallRole);
+ }
+ }
+
+ if (!transaction) {
+ transaction = new FlatpakTransaction(installation, resource, addons, Transaction::InstallRole);
+ }
- FlatpakTransaction *transaction = new FlatpakTransaction(installation, resource, addons, Transaction::InstallRole);
connect(transaction, &FlatpakTransaction::statusChanged, [this, installation, resource] (Transaction::Status status) {
if (status == Transaction::Status::DoneStatus) {
updateAppState(installation, resource);
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakTransaction.cpp b/libdiscover/backends/FlatpakBackend/FlatpakTransaction.cpp
index b185ad9..b8a574f 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakTransaction.cpp
+++ b/libdiscover/backends/FlatpakBackend/FlatpakTransaction.cpp
@@ -30,13 +30,28 @@
#include <QTimer>
FlatpakTransaction::FlatpakTransaction(FlatpakInstallation *installation, FlatpakResource *app, Role role)
- : FlatpakTransaction(installation, app, {}, role)
+ : FlatpakTransaction(installation, app, nullptr, {}, role)
+{
+}
+
+FlatpakTransaction::FlatpakTransaction(FlatpakInstallation* installation, FlatpakResource *app, FlatpakResource *runtime, Transaction::Role role)
+ : FlatpakTransaction(installation, app, runtime, {}, role)
{
}
FlatpakTransaction::FlatpakTransaction(FlatpakInstallation *installation, FlatpakResource *app, const AddonList &addons, Transaction::Role role)
- : Transaction(app->backend(), app, role, addons)
+ : FlatpakTransaction(installation, app, nullptr, addons, role)
+{
+}
+
+FlatpakTransaction::FlatpakTransaction(FlatpakInstallation* installation, FlatpakResource *app, FlatpakResource *runtime, const AddonList &list, Transaction::Role role)
+ : Transaction(app->backend(), app, role, list)
+ , m_appJobFinished(false)
+ , m_runtimeJobFinished(false)
+ , m_appJobProgress(0)
+ , m_runtimeJobProgress(0)
, m_app(app)
+ , m_runtime(runtime)
, m_installation(installation)
{
setCancellable(true);
@@ -48,33 +63,81 @@ FlatpakTransaction::FlatpakTransaction(FlatpakInstallation *installation, Flatpa
FlatpakTransaction::~FlatpakTransaction()
{
- delete m_job;
+ delete m_appJob;
+ if (m_runtimeJob) {
+ delete m_runtimeJob;
+ }
}
void FlatpakTransaction::cancel()
{
- m_job->cancel();
+ m_appJob->cancel();
+ if (m_runtime) {
+ m_runtimeJob->cancel();
+ }
TransactionModel::global()->cancelTransaction(this);
}
void FlatpakTransaction::start()
{
- m_job = new FlatpakTransactionJob(m_installation, m_app, role());
- connect(m_job, &FlatpakTransactionJob::jobFinished, this, &FlatpakTransaction::onJobFinished);
- connect(m_job, &FlatpakTransactionJob::progressChanged, this, &FlatpakTransaction::onJobProgressChanged);
- m_job->start();
+ if (m_runtime) {
+ m_runtimeJob = new FlatpakTransactionJob(m_installation, m_runtime, role());
+ connect(m_runtimeJob, &FlatpakTransactionJob::jobFinished, this, &FlatpakTransaction::onRuntimeJobFinished);
+ connect(m_runtimeJob, &FlatpakTransactionJob::progressChanged, this, &FlatpakTransaction::onAppJobProgressChanged);
+ m_runtimeJob->start();
+ } else {
+ // We can mark runtime job as finished as we don't need to start it
+ m_runtimeJobFinished = true;
+ }
+
+ // App job will be started everytime
+ m_appJob = new FlatpakTransactionJob(m_installation, m_app, role());
+ connect(m_appJob, &FlatpakTransactionJob::jobFinished, this, &FlatpakTransaction::onAppJobFinished);
+ connect(m_appJob, &FlatpakTransactionJob::progressChanged, this, &FlatpakTransaction::onRuntimeJobProgressChanged);
+ m_appJob->start();
}
-void FlatpakTransaction::onJobFinished(bool success)
+void FlatpakTransaction::onAppJobFinished(bool success)
{
- if (success) {
+ m_appJobFinished = true;
+ m_appJobProgress = 100;
+
+ if (success && m_runtimeJobFinished) {
finishTransaction();
}
}
-void FlatpakTransaction::onJobProgressChanged(int progress)
+void FlatpakTransaction::onAppJobProgressChanged(int progress)
{
- setProgress(progress);
+ m_appJobProgress = progress;
+
+ updateProgress();
+}
+
+void FlatpakTransaction::onRuntimeJobFinished(bool success)
+{
+ m_runtimeJobFinished = true;
+ m_runtimeJobProgress = 100;
+
+ if (success && m_appJobFinished) {
+ finishTransaction();
+ }
+}
+
+void FlatpakTransaction::onRuntimeJobProgressChanged(int progress)
+{
+ m_runtimeJobProgress = progress;
+
+ updateProgress();
+}
+
+void FlatpakTransaction::updateProgress()
+{
+ if (m_runtime) {
+ setProgress((m_appJobProgress + m_runtimeJobProgress) / 2);
+ } else {
+ setProgress(m_appJobProgress);
+ }
}
void FlatpakTransaction::finishTransaction()
@@ -91,7 +154,10 @@ void FlatpakTransaction::finishTransaction()
break;
}
m_app->setState(newState);
-// m_app->setAddons(addons());
+ if (m_runtime && role() == InstallRole) {
+ m_runtime->setState(newState);
+ }
+ // m_app->setAddons(addons());
TransactionModel::global()->removeTransaction(this);
deleteLater();
}
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakTransaction.h b/libdiscover/backends/FlatpakBackend/FlatpakTransaction.h
index f437a39..a12c144 100644
--- a/libdiscover/backends/FlatpakBackend/FlatpakTransaction.h
+++ b/libdiscover/backends/FlatpakBackend/FlatpakTransaction.h
@@ -37,21 +37,34 @@ class FlatpakTransaction : public Transaction
Q_OBJECT
public:
FlatpakTransaction(FlatpakInstallation *installation, FlatpakResource *app, Role role);
+ FlatpakTransaction(FlatpakInstallation *installation, FlatpakResource *app, FlatpakResource *runtime, Role role);
+ // TODO will be these two ever needed?
FlatpakTransaction(FlatpakInstallation *installation, FlatpakResource *app, const AddonList &list, Role role);
+ FlatpakTransaction(FlatpakInstallation *installation, FlatpakResource *app, FlatpakResource *runtime, const AddonList &list, Role role);
~FlatpakTransaction();
void cancel() override;
public Q_SLOTS:
- void onJobFinished(bool success);
- void onJobProgressChanged(int progress);
+ void onAppJobFinished(bool success);
+ void onAppJobProgressChanged(int progress);
+ void onRuntimeJobFinished(bool success);
+ void onRuntimeJobProgressChanged(int progress);
void finishTransaction();
void start();
private:
- FlatpakResource* m_app;
+ void updateProgress();
+
+ bool m_appJobFinished;
+ bool m_runtimeJobFinished;
+ int m_appJobProgress;
+ int m_runtimeJobProgress;
+ FlatpakResource *m_app;
+ FlatpakResource *m_runtime;
FlatpakInstallation *m_installation;
- FlatpakTransactionJob *m_job;
+ FlatpakTransactionJob *m_appJob;
+ FlatpakTransactionJob *m_runtimeJob;
};
#endif // FLATPAKTRANSACTION_H