From 3e2a7aa5ce6fa70a47364902153f922a8415b83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 3 Aug 2013 22:32:42 +0200 Subject: [PATCH] HaikuDepot: Classes to interface with the Package Kit * Non functional * Basically allows to retrieve applicable actions for a given package. --- src/apps/haiku-depot/PackageManager.cpp | 88 +++++++++++++++++++++++++ src/apps/haiku-depot/PackageManager.h | 45 +++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/apps/haiku-depot/PackageManager.cpp create mode 100644 src/apps/haiku-depot/PackageManager.h diff --git a/src/apps/haiku-depot/PackageManager.cpp b/src/apps/haiku-depot/PackageManager.cpp new file mode 100644 index 0000000000..06345d5138 --- /dev/null +++ b/src/apps/haiku-depot/PackageManager.cpp @@ -0,0 +1,88 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "PackageManager.h" + +#include + +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "PackageManager" + + +// #pragma mark - PackageAction + + +PackageAction::PackageAction(const PackageInfo& package) + : + fPackage(package) +{ +} + + +PackageAction::~PackageAction() +{ +} + + +// #pragma mark - InstallPackageAction + + +class InstallPackageAction : public PackageAction { +public: + InstallPackageAction(const PackageInfo& package) + : + PackageAction(package) + { + } + + virtual const char* Label() const + { + return B_TRANSLATE("Install"); + } + + virtual status_t Perform() + { + // TODO: Trigger asynchronous installation of the package + return B_ERROR; + } +}; + + +// #pragma mark - PackageManager + + +PackageManager::PackageManager() +{ +} + + +PackageManager::~PackageManager() +{ +} + + +PackageActionList +PackageManager::GetPackageActions(const PackageInfo& package) +{ + PackageActionList actionList; + + // TODO: Actually fetch applicable actions for this package. + // If the package is installed and active, it can be + // * uninstalled + // * deactivated + // If the package is installed and inactive, it can be + // * uninstalled + // * activated + // If the package is not installed, it can be + // * installed (and it will be automatically activated) + actionList.Add(PackageActionRef(new InstallPackageAction(package), true)); + + return actionList; +} + + diff --git a/src/apps/haiku-depot/PackageManager.h b/src/apps/haiku-depot/PackageManager.h new file mode 100644 index 0000000000..ee1326c9b2 --- /dev/null +++ b/src/apps/haiku-depot/PackageManager.h @@ -0,0 +1,45 @@ +/* + * Copyright 2013, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef PACKAGE_MANAGER_H +#define PACKAGE_MANAGER_H + + +#include + +#include "List.h" +#include "PackageInfo.h" + + +class PackageAction : public BReferenceable { +public: + PackageAction(const PackageInfo& package); + virtual ~PackageAction(); + + virtual const char* Label() const = 0; + + // TODO: Perform() needs to be passed a progress listener + // and it needs a mechanism to report and react to errors. The + // Package Kit supports this stuff already. + virtual status_t Perform() = 0; + +protected: + PackageInfo fPackage; +}; + + +typedef BReference PackageActionRef; +typedef List PackageActionList; + + +class PackageManager { +public: + PackageManager(); + virtual ~PackageManager(); + + virtual PackageActionList GetPackageActions(const PackageInfo& package); +}; + + +#endif // PACKAGE_MANAGER_H