summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-10-16 12:18:30 +0200
committerAleix Pol <[email protected]>2016-10-21 00:49:42 +0200
commite039607c0fd7fc6d3b5b225a4315464684d23f04 (patch)
tree1a7d0c1b481071abe96394e1d8819900911e0158
parent159a9324ed45d5c03ccb20b3af57895240a67db2 (diff)
Implement un/installing
-rw-r--r--libdiscover/backends/SnapBackend/SnapBackend.cpp21
-rw-r--r--libdiscover/backends/SnapBackend/SnapTransaction.cpp45
-rw-r--r--libdiscover/backends/SnapBackend/SnapTransaction.h43
3 files changed, 101 insertions, 8 deletions
diff --git a/libdiscover/backends/SnapBackend/SnapBackend.cpp b/libdiscover/backends/SnapBackend/SnapBackend.cpp
index 8ba0a3b..08d6b9d 100644
--- a/libdiscover/backends/SnapBackend/SnapBackend.cpp
+++ b/libdiscover/backends/SnapBackend/SnapBackend.cpp
@@ -19,6 +19,7 @@
***************************************************************************/
#include "SnapBackend.h"
+#include "SnapTransaction.h"
#include "SnapResource.h"
#include "SnapReviewsBackend.h"
#include <resources/StandardBackendUpdater.h>
@@ -127,20 +128,24 @@ AbstractReviewsBackend* SnapBackend::reviewsBackend() const
void SnapBackend::installApplication(AbstractResource* app, const AddonList& addons)
{
-// TransactionModel *transModel = TransactionModel::global();
-// transModel->addTransaction(new SnapTransaction(qobject_cast<SnapResource*>(app), addons, Transaction::InstallRole));
+ Q_ASSERT(addons.isEmpty());
+ installApplication(app);
}
-void SnapBackend::installApplication(AbstractResource* app)
+void SnapBackend::installApplication(AbstractResource* _app)
{
-// TransactionModel *transModel = TransactionModel::global();
-// transModel->addTransaction(new SnapTransaction(qobject_cast<SnapResource*>(app), Transaction::InstallRole));
+ TransactionModel *transModel = TransactionModel::global();
+ auto app = qobject_cast<SnapResource*>(_app);
+ auto job = m_socket.snapAction(app->packageName(), SnapSocket::Install);
+ transModel->addTransaction(new SnapTransaction(app, job, Transaction::InstallRole));
}
-void SnapBackend::removeApplication(AbstractResource* app)
+void SnapBackend::removeApplication(AbstractResource* _app)
{
-// TransactionModel *transModel = TransactionModel::global();
-// transModel->addTransaction(new SnapTransaction(qobject_cast<SnapResource*>(app), Transaction::RemoveRole));
+ TransactionModel *transModel = TransactionModel::global();
+ auto app = qobject_cast<SnapResource*>(_app);
+ auto job = m_socket.snapAction(app->packageName(), SnapSocket::Install);
+ transModel->addTransaction(new SnapTransaction(app, job, Transaction::RemoveRole));
}
#include "SnapBackend.moc"
diff --git a/libdiscover/backends/SnapBackend/SnapTransaction.cpp b/libdiscover/backends/SnapBackend/SnapTransaction.cpp
new file mode 100644
index 0000000..d639213
--- /dev/null
+++ b/libdiscover/backends/SnapBackend/SnapTransaction.cpp
@@ -0,0 +1,45 @@
+/***************************************************************************
+ * Copyright © 2013 Aleix Pol Gonzalez <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License or (at your option) version 3 or any later version *
+ * accepted by the membership of KDE e.V. (or its successor approved *
+ * by the membership of KDE e.V.), which shall act as a proxy *
+ * defined in Section 14 of version 3 of the license. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#include "SnapTransaction.h"
+#include "SnapBackend.h"
+#include "SnapResource.h"
+#include <Transaction/TransactionModel.h>
+
+SnapTransaction::SnapTransaction(SnapResource* app, SnapJob* job, Role role)
+ : Transaction(app, app, role)
+ , m_app(app)
+{
+ setStatus(DownloadingStatus);
+ setCancellable(false);
+ connect(job, &SnapJob::finished, this, &SnapTransaction::finishTransaction);
+}
+
+void SnapTransaction::cancel()
+{
+ Q_UNREACHABLE();
+}
+
+void SnapTransaction::finishTransaction()
+{
+ setStatus(DoneStatus);
+ TransactionModel::global()->removeTransaction(this);
+ deleteLater();
+}
diff --git a/libdiscover/backends/SnapBackend/SnapTransaction.h b/libdiscover/backends/SnapBackend/SnapTransaction.h
new file mode 100644
index 0000000..adcfd27
--- /dev/null
+++ b/libdiscover/backends/SnapBackend/SnapTransaction.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright © 2013 Aleix Pol Gonzalez <[email protected]> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License or (at your option) version 3 or any later version *
+ * accepted by the membership of KDE e.V. (or its successor approved *
+ * by the membership of KDE e.V.), which shall act as a proxy *
+ * defined in Section 14 of version 3 of the license. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#ifndef SNAPTRANSACTION_H
+#define SNAPTRANSACTION_H
+
+#include <Transaction/Transaction.h>
+
+class SnapJob;
+class SnapResource;
+class SnapTransaction : public Transaction
+{
+ Q_OBJECT
+ public:
+ SnapTransaction(SnapResource* app, SnapJob* job, Role role);
+
+ void cancel() override;
+
+ private Q_SLOTS:
+ void finishTransaction();
+
+ private:
+ SnapResource const * m_app;
+};
+
+#endif // SNAPTRANSACTION_H