HaikuDepot: Classes to interface with the Package Kit

* Non functional
 * Basically allows to retrieve applicable actions for
   a given package.
This commit is contained in:
Stephan Aßmus 2013-08-03 22:32:42 +02:00
parent 3aac7049ba
commit 3e2a7aa5ce
2 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,88 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "PackageManager.h"
#include <stdio.h>
#include <Catalog.h>
#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;
}

View File

@ -0,0 +1,45 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_MANAGER_H
#define PACKAGE_MANAGER_H
#include <Referenceable.h>
#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<PackageAction> PackageActionRef;
typedef List<PackageActionRef, false> PackageActionList;
class PackageManager {
public:
PackageManager();
virtual ~PackageManager();
virtual PackageActionList GetPackageActions(const PackageInfo& package);
};
#endif // PACKAGE_MANAGER_H