mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
HaikuDepot: Split out Local Info From Pkg
Continued work to normalize the data model in the application. Change-Id: I6dc6d17cff866b18f56431056958092c8bdc3a19 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8524 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com> Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
parent
3a91fe8d4f
commit
c078962803
@ -181,6 +181,7 @@ local applicationSources =
|
||||
PackageFilter.cpp
|
||||
PackageFilterModel.cpp
|
||||
PackageInfo.cpp
|
||||
PackageLocalInfo.cpp
|
||||
PackageLocalizedText.cpp
|
||||
PublisherInfo.cpp
|
||||
ScreenshotInfo.cpp
|
||||
|
@ -25,8 +25,9 @@
|
||||
#include <Path.h>
|
||||
|
||||
#include "HaikuDepotConstants.h"
|
||||
#include "Logger.h"
|
||||
#include "LocaleUtils.h"
|
||||
#include "Logger.h"
|
||||
#include "PackageUtils.h"
|
||||
#include "StorageUtils.h"
|
||||
|
||||
|
||||
@ -237,14 +238,18 @@ Model::SetStateForPackagesByName(BStringList& packageNames, PackageState state)
|
||||
PackageInfoRef packageInfo = PackageForName(packageName);
|
||||
|
||||
if (packageInfo.IsSet()) {
|
||||
packageInfo->SetState(state);
|
||||
HDINFO("did update package [%s] with state [%s]",
|
||||
packageName.String(), package_state_to_string(state));
|
||||
// TODO; make this immutable
|
||||
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(packageInfo);
|
||||
localInfo->SetState(state);
|
||||
packageInfo->SetLocalInfo(localInfo);
|
||||
|
||||
HDINFO("did update package [%s] with state [%s]", packageName.String(),
|
||||
PackageUtils::StateToString(state));
|
||||
}
|
||||
else {
|
||||
HDINFO("was unable to find package [%s] so was not possible to set"
|
||||
" the state to [%s]", packageName.String(),
|
||||
package_state_to_string(state));
|
||||
HDINFO("was unable to find package [%s] so was not possible to set the state to [%s]",
|
||||
packageName.String(), PackageUtils::StateToString(state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ enum {
|
||||
// ^ Covers title, summary, description and changelog.
|
||||
PKG_CHANGED_RATINGS = 1 << 1,
|
||||
PKG_CHANGED_SCREENSHOTS = 1 << 2,
|
||||
PKG_CHANGED_STATE = 1 << 3,
|
||||
PKG_CHANGED_LOCAL_INFO = 1 << 3,
|
||||
// ^ Covers state, download and size.
|
||||
PKG_CHANGED_ICON = 1 << 4,
|
||||
PKG_CHANGED_CHANGELOG = 1 << 5,
|
||||
PKG_CHANGED_CLASSIFICATION = 1 << 6,
|
||||
// ^ This covers categories, prominence and is native desktop
|
||||
PKG_CHANGED_SIZE = 1 << 7,
|
||||
PKG_CHANGED_DEPOT = 1 << 8,
|
||||
PKG_CHANGED_VERSION = 1 << 9,
|
||||
PKG_CHANGED_VERSION_CREATE_TIMESTAMP = 1 << 10
|
||||
|
@ -9,9 +9,11 @@
|
||||
|
||||
#include "AbstractPackageProcess.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Model.h"
|
||||
#include "PackageKitUtils.h"
|
||||
#include "PackageManager.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
|
||||
using namespace BPackageKit;
|
||||
@ -51,3 +53,43 @@ AbstractPackageProcess::FindPackageByName(const BString& name)
|
||||
}
|
||||
|
||||
|
||||
// TODO; will refactor once the models go immutable.
|
||||
void
|
||||
AbstractPackageProcess::SetPackageState(PackageInfoRef& package, PackageState state)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(package);
|
||||
localInfo->SetState(state);
|
||||
package->SetLocalInfo(localInfo);
|
||||
} else {
|
||||
HDERROR("setting state, but the package is not set");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO; will refactor once the models go immutable.
|
||||
void
|
||||
AbstractPackageProcess::SetPackageDownloadProgress(PackageInfoRef& package, float value)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(package);
|
||||
localInfo->SetDownloadProgress(value);
|
||||
package->SetLocalInfo(localInfo);
|
||||
} else {
|
||||
HDERROR("setting progress, but the package is not set");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO; will refactor once the models go immutable.
|
||||
void
|
||||
AbstractPackageProcess::ClearPackageInstallationLocations(PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(package);
|
||||
localInfo->ClearInstallationLocations();
|
||||
package->SetLocalInfo(localInfo);
|
||||
} else {
|
||||
HDERROR("clearing installation locations, but the package is not set");
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ public:
|
||||
protected:
|
||||
PackageInfoRef FindPackageByName(const BString& name);
|
||||
|
||||
void SetPackageState(PackageInfoRef& package, PackageState state);
|
||||
void SetPackageDownloadProgress(PackageInfoRef& package, float value);
|
||||
void ClearPackageInstallationLocations(PackageInfoRef& package);
|
||||
|
||||
protected:
|
||||
PackageManager* fPackageManager;
|
||||
PackageInfoRef fPackage;
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "HaikuDepotConstants.h"
|
||||
#include "Logger.h"
|
||||
#include "PackageManager.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@ -139,17 +140,17 @@ InstallPackageProcess::RunInternal()
|
||||
| BPackageManager::B_ADD_REMOTE_REPOSITORIES
|
||||
| BPackageManager::B_REFRESH_REPOSITORIES);
|
||||
PackageInfoRef ref(fPackage);
|
||||
PackageState state = ref->State();
|
||||
ref->SetState(PENDING);
|
||||
PackageState state = PackageUtils::State(ref);
|
||||
SetPackageState(ref, PENDING);
|
||||
|
||||
fPackageManager->SetCurrentActionPackage(ref, true);
|
||||
fPackageManager->AddProgressListener(this);
|
||||
|
||||
BString packageName;
|
||||
if (ref->IsLocalFile())
|
||||
packageName = ref->LocalFilePath();
|
||||
else
|
||||
packageName = ref->Name();
|
||||
BString packageName = ref->Name();
|
||||
PackageLocalInfoRef localInfo = ref->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet() && localInfo->IsLocalFile())
|
||||
packageName = localInfo->LocalFilePath();
|
||||
|
||||
const char* packageNameString = packageName.String();
|
||||
try {
|
||||
@ -163,13 +164,13 @@ InstallPackageProcess::RunInternal()
|
||||
AppUtils::NotifySimpleError(B_TRANSLATE("Fatal error"), errorString,
|
||||
B_STOP_ALERT);
|
||||
_SetDownloadedPackagesState(NONE);
|
||||
ref->SetState(state);
|
||||
SetPackageState(ref, state);
|
||||
return ex.Error();
|
||||
} catch (BAbortedByUserException& ex) {
|
||||
HDINFO("Installation of package %s is aborted by user: %s",
|
||||
packageNameString, ex.Message().String());
|
||||
_SetDownloadedPackagesState(NONE);
|
||||
ref->SetState(state);
|
||||
SetPackageState(ref, state);
|
||||
return B_OK;
|
||||
} catch (BNothingToDoException& ex) {
|
||||
HDINFO("Nothing to do while installing package %s: %s",
|
||||
@ -179,7 +180,7 @@ InstallPackageProcess::RunInternal()
|
||||
HDERROR("Exception occurred while installing package %s: %s",
|
||||
packageNameString, ex.Message().String());
|
||||
_SetDownloadedPackagesState(NONE);
|
||||
ref->SetState(state);
|
||||
SetPackageState(ref, state);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
@ -209,7 +210,7 @@ InstallPackageProcess::DownloadProgressChanged(
|
||||
}
|
||||
PackageInfoRef ref(FindPackageByName(simplePackageName));
|
||||
if (ref.IsSet()) {
|
||||
ref->SetDownloadProgress(progress);
|
||||
SetPackageDownloadProgress(ref, progress);
|
||||
_SetDownloadProgress(simplePackageName, progress);
|
||||
} else {
|
||||
HDERROR("unable to find the package info for simple package name [%s]",
|
||||
@ -233,7 +234,7 @@ InstallPackageProcess::DownloadProgressComplete(const char* packageName)
|
||||
simplePackageName.String());
|
||||
return;
|
||||
}
|
||||
ref->SetDownloadProgress(1.0);
|
||||
SetPackageDownloadProgress(ref, 1.0);
|
||||
fDownloadedPackages.insert(ref);
|
||||
}
|
||||
|
||||
@ -249,7 +250,7 @@ InstallPackageProcess::ConfirmedChanges(
|
||||
for (int32 i = 0; (package = activationList.ItemAt(i)); i++) {
|
||||
PackageInfoRef ref(FindPackageByName(package->Info().Name()));
|
||||
if (ref.IsSet())
|
||||
ref->SetState(PENDING);
|
||||
SetPackageState(ref, PENDING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,7 +260,8 @@ InstallPackageProcess::_SetDownloadedPackagesState(PackageState state)
|
||||
{
|
||||
for (PackageInfoSet::iterator it = fDownloadedPackages.begin();
|
||||
it != fDownloadedPackages.end(); ++it) {
|
||||
(*it)->SetState(state);
|
||||
PackageInfoRef ref = (*it);
|
||||
SetPackageState(ref, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,10 +142,18 @@ void
|
||||
PackageManager::CollectPackageActions(PackageInfoRef package,
|
||||
Collector<PackageActionRef>& actionList)
|
||||
{
|
||||
if (package->IsSystemPackage() || package->IsSystemDependency())
|
||||
if (!package.IsSet())
|
||||
return;
|
||||
|
||||
switch (package->State()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (!localInfo.IsSet())
|
||||
return;
|
||||
|
||||
if (localInfo->IsSystemPackage() || localInfo->IsSystemDependency())
|
||||
return;
|
||||
|
||||
switch (PackageUtils::State(package)) {
|
||||
case ACTIVATED:
|
||||
case INSTALLED:
|
||||
_CollectPackageActionsForActivatedOrInstalled(package, actionList);
|
||||
@ -489,7 +497,9 @@ BSolverPackage*
|
||||
PackageManager::_GetSolverPackage(PackageInfoRef package)
|
||||
{
|
||||
int32 flags = BSolver::B_FIND_IN_NAME;
|
||||
if (package->State() == ACTIVATED || package->State() == INSTALLED)
|
||||
PackageState state = PackageUtils::State(package);
|
||||
|
||||
if (state == ACTIVATED || state == INSTALLED)
|
||||
flags |= BSolver::B_FIND_INSTALLED_ONLY;
|
||||
|
||||
BObjectList<BSolverPackage> packages;
|
||||
@ -499,9 +509,9 @@ PackageManager::_GetSolverPackage(PackageInfoRef package)
|
||||
BSolverPackage* solverPackage = packages.ItemAt(i);
|
||||
if (solverPackage->Name() != package->Name())
|
||||
continue;
|
||||
else if (package->State() == NONE
|
||||
&& dynamic_cast<BPackageManager::RemoteRepository*>(
|
||||
solverPackage->Repository()) == NULL) {
|
||||
else if (state == NONE
|
||||
&& dynamic_cast<BPackageManager::RemoteRepository*>(solverPackage->Repository())
|
||||
== NULL) {
|
||||
continue;
|
||||
}
|
||||
return solverPackage;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "AppUtils.h"
|
||||
#include "Logger.h"
|
||||
#include "PackageManager.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@ -70,11 +71,14 @@ status_t
|
||||
UninstallPackageProcess::RunInternal()
|
||||
{
|
||||
fPackageManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES);
|
||||
|
||||
PackageInfoRef ref(fPackage);
|
||||
PackageState state = ref->State();
|
||||
PackageState state = PackageUtils::State(fPackage);
|
||||
const char* packageName = ref->Name().String();
|
||||
|
||||
fPackageManager->SetCurrentActionPackage(ref, false);
|
||||
fPackageManager->AddProgressListener(this);
|
||||
const char* packageName = ref->Name().String();
|
||||
|
||||
try {
|
||||
fPackageManager->Uninstall(&packageName, 1);
|
||||
} catch (BFatalErrorException& ex) {
|
||||
@ -85,7 +89,7 @@ UninstallPackageProcess::RunInternal()
|
||||
ex.Details().String());
|
||||
AppUtils::NotifySimpleError(B_TRANSLATE("Fatal error"), errorString,
|
||||
B_STOP_ALERT);
|
||||
ref->SetState(state);
|
||||
SetPackageState(ref, state);
|
||||
return ex.Error();
|
||||
} catch (BAbortedByUserException& ex) {
|
||||
return B_OK;
|
||||
@ -94,15 +98,12 @@ UninstallPackageProcess::RunInternal()
|
||||
} catch (BException& ex) {
|
||||
HDERROR("Exception occurred while uninstalling package %s: %s",
|
||||
packageName, ex.Message().String());
|
||||
ref->SetState(state);
|
||||
SetPackageState(ref, state);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
fPackageManager->RemoveProgressListener(this);
|
||||
|
||||
ref->ClearInstallationLocations();
|
||||
ref->SetState(NONE);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -129,6 +130,7 @@ UninstallPackageProcess::ApplyingChangesDone(
|
||||
std::vector<PackageInfoRef>::iterator it;
|
||||
for (it = fRemovedPackages.begin(); it != fRemovedPackages.end(); it++) {
|
||||
PackageInfoRef packageInfoRef = *it;
|
||||
packageInfoRef->SetState(NONE);
|
||||
SetPackageState(packageInfoRef, NONE);
|
||||
ClearPackageInstallationLocations(packageInfoRef);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "Logger.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
|
||||
// #pragma mark - Sorting Functions
|
||||
@ -170,12 +171,18 @@ DepotInfo::SyncPackagesFromDepot(const DepotInfoRef& other)
|
||||
PackageInfoRef otherPackage = other->PackageAtIndex(i);
|
||||
PackageInfoRef myPackage = PackageByName(otherPackage->Name());
|
||||
|
||||
if (myPackage.Get() != NULL) {
|
||||
myPackage->SetState(otherPackage->State());
|
||||
myPackage->SetLocalFilePath(otherPackage->LocalFilePath());
|
||||
myPackage->SetSystemDependency(otherPackage->IsSystemDependency());
|
||||
}
|
||||
else {
|
||||
if (myPackage.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(myPackage);
|
||||
PackageLocalInfoRef otherLocalInfo = otherPackage->LocalInfo();
|
||||
|
||||
if (otherLocalInfo.IsSet()) {
|
||||
localInfo->SetState(otherLocalInfo->State());
|
||||
localInfo->SetLocalFilePath(otherLocalInfo->LocalFilePath());
|
||||
localInfo->SetSystemDependency(otherLocalInfo->IsSystemDependency());
|
||||
}
|
||||
|
||||
myPackage->SetLocalInfo(localInfo);
|
||||
} else {
|
||||
HDINFO("%s: new package: '%s'", fName.String(),
|
||||
otherPackage->Name().String());
|
||||
AddPackage(otherPackage);
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
#include "PackageFilter.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
|
||||
PackageFilter::~PackageFilter()
|
||||
@ -62,7 +63,7 @@ public:
|
||||
|
||||
virtual bool AcceptsPackage(const PackageInfoRef& package) const
|
||||
{
|
||||
return package->State() == fState;
|
||||
return PackageUtils::State(package) == fState;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -29,16 +29,9 @@ PackageInfo::PackageInfo()
|
||||
fPackageClassificationInfo(),
|
||||
fScreenshotInfos(),
|
||||
fUserRatingInfo(),
|
||||
fState(NONE),
|
||||
fDownloadProgress(0.0),
|
||||
fFlags(0),
|
||||
fSystemDependency(false),
|
||||
fLocalInfo(),
|
||||
fArchitecture(),
|
||||
fLocalFilePath(),
|
||||
fFileName(),
|
||||
fSize(0),
|
||||
fDepotName(""),
|
||||
fViewed(false),
|
||||
fIsCollatingChanges(false),
|
||||
fCollatedChanges(0),
|
||||
fVersionCreateTimestamp(0)
|
||||
@ -54,16 +47,8 @@ PackageInfo::PackageInfo(const BPackageInfo& info)
|
||||
fPackageClassificationInfo(),
|
||||
fScreenshotInfos(),
|
||||
fUserRatingInfo(),
|
||||
fState(NONE),
|
||||
fDownloadProgress(0.0),
|
||||
fFlags(info.Flags()),
|
||||
fSystemDependency(false),
|
||||
fArchitecture(info.ArchitectureName()),
|
||||
fLocalFilePath(),
|
||||
fFileName(info.FileName()),
|
||||
fSize(0), // TODO: Retrieve local file size
|
||||
fDepotName(""),
|
||||
fViewed(false),
|
||||
fIsCollatingChanges(false),
|
||||
fCollatedChanges(0),
|
||||
fVersionCreateTimestamp(0)
|
||||
@ -92,6 +77,11 @@ PackageInfo::PackageInfo(const BPackageInfo& info)
|
||||
fLocalizedText->SetTitle(info.Name());
|
||||
fLocalizedText->SetSummary(info.Summary());
|
||||
fLocalizedText->SetDescription(info.Description());
|
||||
|
||||
// TODO: Retrieve local file size
|
||||
fLocalInfo = PackageLocalInfoRef(new PackageLocalInfo(), true);
|
||||
fLocalInfo->SetFlags(info.Flags());
|
||||
fLocalInfo->SetFileName(info.FileName());
|
||||
}
|
||||
|
||||
|
||||
@ -104,17 +94,9 @@ PackageInfo::PackageInfo(const PackageInfo& other)
|
||||
fPackageClassificationInfo(other.fPackageClassificationInfo),
|
||||
fScreenshotInfos(other.fScreenshotInfos),
|
||||
fUserRatingInfo(other.fUserRatingInfo),
|
||||
fState(other.fState),
|
||||
fInstallationLocations(other.fInstallationLocations),
|
||||
fDownloadProgress(other.fDownloadProgress),
|
||||
fFlags(other.fFlags),
|
||||
fSystemDependency(other.fSystemDependency),
|
||||
fLocalInfo(other.fLocalInfo),
|
||||
fArchitecture(other.fArchitecture),
|
||||
fLocalFilePath(other.fLocalFilePath),
|
||||
fFileName(other.fFileName),
|
||||
fSize(other.fSize),
|
||||
fDepotName(other.fDepotName),
|
||||
fViewed(other.fViewed),
|
||||
fIsCollatingChanges(false),
|
||||
fCollatedChanges(0),
|
||||
fVersionCreateTimestamp(other.fVersionCreateTimestamp)
|
||||
@ -132,18 +114,10 @@ PackageInfo::operator=(const PackageInfo& other)
|
||||
fPackageClassificationInfo = other.fPackageClassificationInfo;
|
||||
fScreenshotInfos = other.fScreenshotInfos;
|
||||
fUserRatingInfo = other.fUserRatingInfo;
|
||||
fState = other.fState;
|
||||
fInstallationLocations = other.fInstallationLocations;
|
||||
fDownloadProgress = other.fDownloadProgress;
|
||||
fFlags = other.fFlags;
|
||||
fSystemDependency = other.fSystemDependency;
|
||||
fArchitecture = other.fArchitecture;
|
||||
fLocalFilePath = other.fLocalFilePath;
|
||||
fFileName = other.fFileName;
|
||||
fSize = other.fSize;
|
||||
fDepotName = other.fDepotName;
|
||||
fViewed = other.fViewed;
|
||||
fVersionCreateTimestamp = other.fVersionCreateTimestamp;
|
||||
fLocalInfo = other.fLocalInfo;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -153,20 +127,14 @@ bool
|
||||
PackageInfo::operator==(const PackageInfo& other) const
|
||||
{
|
||||
return fName == other.fName
|
||||
&& fLocalInfo == other.fLocalInfo
|
||||
&& fVersion == other.fVersion
|
||||
&& fPublisher == other.fPublisher
|
||||
&& fLocalizedText == other.fLocalizedText
|
||||
&& fPackageClassificationInfo == other.fPackageClassificationInfo
|
||||
&& fScreenshotInfos == other.fScreenshotInfos
|
||||
&& fUserRatingInfo == fUserRatingInfo
|
||||
&& fState == other.fState
|
||||
&& fFlags == other.fFlags
|
||||
&& fDownloadProgress == other.fDownloadProgress
|
||||
&& fSystemDependency == other.fSystemDependency
|
||||
&& fArchitecture == other.fArchitecture
|
||||
&& fLocalFilePath == other.fLocalFilePath
|
||||
&& fFileName == other.fFileName
|
||||
&& fSize == other.fSize
|
||||
&& fVersionCreateTimestamp == other.fVersionCreateTimestamp;
|
||||
}
|
||||
|
||||
@ -198,83 +166,8 @@ PackageInfo::SetLocalizedText(PackageLocalizedTextRef value)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackageInfo::IsSystemPackage() const
|
||||
{
|
||||
return (fFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetPackageClassificationInfo(PackageClassificationInfoRef value)
|
||||
{
|
||||
if (value != fPackageClassificationInfo) {
|
||||
fPackageClassificationInfo = value;
|
||||
_NotifyListeners(PKG_CHANGED_CLASSIFICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetSystemDependency(bool isDependency)
|
||||
{
|
||||
fSystemDependency = isDependency;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetState(PackageState state)
|
||||
{
|
||||
if (fState != state) {
|
||||
fState = state;
|
||||
if (fState != DOWNLOADING)
|
||||
fDownloadProgress = 0.0;
|
||||
_NotifyListeners(PKG_CHANGED_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::AddInstallationLocation(int32 location)
|
||||
{
|
||||
fInstallationLocations.insert(location);
|
||||
SetState(ACTIVATED);
|
||||
// TODO: determine how to differentiate between installed and active.
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::ClearInstallationLocations()
|
||||
{
|
||||
fInstallationLocations.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetDownloadProgress(float progress)
|
||||
{
|
||||
fState = DOWNLOADING;
|
||||
fDownloadProgress = progress;
|
||||
_NotifyListeners(PKG_CHANGED_STATE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetLocalFilePath(const char* path)
|
||||
{
|
||||
fLocalFilePath = path;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackageInfo::IsLocalFile() const
|
||||
{
|
||||
return !fLocalFilePath.IsEmpty() && fInstallationLocations.empty();
|
||||
}
|
||||
|
||||
|
||||
UserRatingInfoRef
|
||||
PackageInfo::UserRatingInfo()
|
||||
PackageInfo::UserRatingInfo() const
|
||||
{
|
||||
return fUserRatingInfo;
|
||||
}
|
||||
@ -290,6 +183,33 @@ PackageInfo::SetUserRatingInfo(UserRatingInfoRef value)
|
||||
}
|
||||
|
||||
|
||||
PackageLocalInfoRef
|
||||
PackageInfo::LocalInfo() const
|
||||
{
|
||||
return fLocalInfo;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetLocalInfo(PackageLocalInfoRef& localInfo)
|
||||
{
|
||||
if (fLocalInfo != localInfo) {
|
||||
fLocalInfo = localInfo;
|
||||
_NotifyListeners(PKG_CHANGED_LOCAL_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetPackageClassificationInfo(PackageClassificationInfoRef value)
|
||||
{
|
||||
if (value != fPackageClassificationInfo) {
|
||||
fPackageClassificationInfo = value;
|
||||
_NotifyListeners(PKG_CHANGED_CLASSIFICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::ClearScreenshotInfos()
|
||||
{
|
||||
@ -322,23 +242,6 @@ PackageInfo::AddScreenshotInfo(const ScreenshotInfoRef& info)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetSize(int64 size)
|
||||
{
|
||||
if (fSize != size) {
|
||||
fSize = size;
|
||||
_NotifyListeners(PKG_CHANGED_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetViewed()
|
||||
{
|
||||
fViewed = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageInfo::SetVersionCreateTimestamp(uint64 value)
|
||||
{
|
||||
@ -428,25 +331,3 @@ PackageInfo::_NotifyListenersImmediate(uint32 changes)
|
||||
listener->PackageChanged(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char* package_state_to_string(PackageState state)
|
||||
{
|
||||
switch (state) {
|
||||
case NONE:
|
||||
return "NONE";
|
||||
case INSTALLED:
|
||||
return "INSTALLED";
|
||||
case DOWNLOADING:
|
||||
return "DOWNLOADING";
|
||||
case ACTIVATED:
|
||||
return "ACTIVATED";
|
||||
case UNINSTALLED:
|
||||
return "UNINSTALLED";
|
||||
case PENDING:
|
||||
return "PENDING";
|
||||
default:
|
||||
debugger("unknown package state");
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
#define PACKAGE_INFO_H
|
||||
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include <Referenceable.h>
|
||||
@ -17,28 +16,13 @@
|
||||
#include "List.h"
|
||||
#include "PackageClassificationInfo.h"
|
||||
#include "PackageInfoListener.h"
|
||||
#include "PackageLocalInfo.h"
|
||||
#include "PackageLocalizedText.h"
|
||||
#include "PublisherInfo.h"
|
||||
#include "ScreenshotInfo.h"
|
||||
#include "UserRatingInfo.h"
|
||||
|
||||
|
||||
typedef std::set<int32> PackageInstallationLocationSet;
|
||||
|
||||
|
||||
enum PackageState {
|
||||
NONE = 0,
|
||||
INSTALLED = 1,
|
||||
DOWNLOADING = 2,
|
||||
ACTIVATED = 3,
|
||||
UNINSTALLED = 4,
|
||||
PENDING = 5,
|
||||
};
|
||||
|
||||
|
||||
const char* package_state_to_string(PackageState state);
|
||||
|
||||
|
||||
using BPackageKit::BPackageInfo;
|
||||
using BPackageKit::BPackageVersion;
|
||||
|
||||
@ -66,62 +50,27 @@ public:
|
||||
const PublisherInfo& Publisher() const
|
||||
{ return fPublisher; }
|
||||
|
||||
|
||||
int32 Flags() const
|
||||
{ return fFlags; }
|
||||
bool IsSystemPackage() const;
|
||||
|
||||
bool IsSystemDependency() const
|
||||
{ return fSystemDependency; }
|
||||
void SetSystemDependency(bool isDependency);
|
||||
|
||||
const BString Architecture() const
|
||||
{ return fArchitecture; }
|
||||
|
||||
PackageState State() const
|
||||
{ return fState; }
|
||||
void SetState(PackageState state);
|
||||
|
||||
const PackageInstallationLocationSet&
|
||||
InstallationLocations() const
|
||||
{ return fInstallationLocations; }
|
||||
void AddInstallationLocation(int32 location);
|
||||
void ClearInstallationLocations();
|
||||
|
||||
float DownloadProgress() const
|
||||
{ return fDownloadProgress; }
|
||||
void SetDownloadProgress(float progress);
|
||||
|
||||
void SetLocalFilePath(const char* path);
|
||||
const BString& LocalFilePath() const
|
||||
{ return fLocalFilePath; }
|
||||
bool IsLocalFile() const;
|
||||
const BString& FileName() const
|
||||
{ return fFileName; }
|
||||
|
||||
void SetPackageClassificationInfo(
|
||||
PackageClassificationInfoRef value);
|
||||
PackageClassificationInfoRef
|
||||
PackageClassificationInfo() const
|
||||
{ return fPackageClassificationInfo; }
|
||||
|
||||
UserRatingInfoRef UserRatingInfo();
|
||||
UserRatingInfoRef UserRatingInfo() const;
|
||||
void SetUserRatingInfo(UserRatingInfoRef userRatingInfo);
|
||||
|
||||
PackageLocalInfoRef LocalInfo() const;
|
||||
void SetLocalInfo(PackageLocalInfoRef& localInfo);
|
||||
|
||||
void ClearScreenshotInfos();
|
||||
void AddScreenshotInfo(
|
||||
const ScreenshotInfoRef& info);
|
||||
int32 CountScreenshotInfos() const;
|
||||
ScreenshotInfoRef ScreenshotInfoAtIndex(int32 index) const;
|
||||
|
||||
void SetSize(off_t size);
|
||||
off_t Size() const
|
||||
{ return fSize; }
|
||||
|
||||
void SetViewed();
|
||||
bool Viewed() const
|
||||
{ return fViewed; }
|
||||
|
||||
void SetVersionCreateTimestamp(uint64 value);
|
||||
uint64 VersionCreateTimestamp() const
|
||||
{ return fVersionCreateTimestamp; }
|
||||
@ -154,21 +103,12 @@ private:
|
||||
std::vector<ScreenshotInfoRef>
|
||||
fScreenshotInfos;
|
||||
UserRatingInfoRef fUserRatingInfo;
|
||||
PackageLocalInfoRef fLocalInfo;
|
||||
|
||||
PackageState fState;
|
||||
PackageInstallationLocationSet
|
||||
fInstallationLocations;
|
||||
float fDownloadProgress;
|
||||
std::vector<PackageInfoListenerRef>
|
||||
fListeners;
|
||||
int32 fFlags;
|
||||
bool fSystemDependency;
|
||||
BString fArchitecture;
|
||||
BString fLocalFilePath;
|
||||
BString fFileName;
|
||||
off_t fSize;
|
||||
BString fDepotName;
|
||||
bool fViewed;
|
||||
|
||||
bool fIsCollatingChanges;
|
||||
uint32 fCollatedChanges;
|
||||
|
179
src/apps/haikudepot/packagemodel/PackageLocalInfo.cpp
Normal file
179
src/apps/haikudepot/packagemodel/PackageLocalInfo.cpp
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2024, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "PackageLocalInfo.h"
|
||||
|
||||
#include "Package.h"
|
||||
|
||||
|
||||
PackageLocalInfo::PackageLocalInfo()
|
||||
:
|
||||
fViewed(false),
|
||||
fLocalFilePath(),
|
||||
fFileName(),
|
||||
fSize(0),
|
||||
fFlags(0),
|
||||
fSystemDependency(false),
|
||||
fState(NONE),
|
||||
fInstallationLocations(),
|
||||
fDownloadProgress(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PackageLocalInfo::PackageLocalInfo(const PackageLocalInfo& other)
|
||||
:
|
||||
fViewed(other.fViewed),
|
||||
fLocalFilePath(other.fLocalFilePath),
|
||||
fFileName(other.fFileName),
|
||||
fSize(other.fSize),
|
||||
fFlags(other.fFlags),
|
||||
fSystemDependency(other.fSystemDependency),
|
||||
fState(other.fState),
|
||||
fInstallationLocations(),
|
||||
fDownloadProgress(other.fDownloadProgress)
|
||||
{
|
||||
PackageInstallationLocationSet otherLocations = other.InstallationLocations();
|
||||
PackageInstallationLocationSet::const_iterator it;
|
||||
|
||||
for (it = otherLocations.begin(); it != otherLocations.end(); it++)
|
||||
fInstallationLocations.insert(*it);
|
||||
}
|
||||
|
||||
|
||||
PackageLocalInfo::~PackageLocalInfo()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PackageLocalInfo&
|
||||
PackageLocalInfo::operator=(const PackageLocalInfo& other)
|
||||
{
|
||||
fState = other.fState;
|
||||
fInstallationLocations = other.fInstallationLocations;
|
||||
fDownloadProgress = other.fDownloadProgress;
|
||||
fFlags = other.fFlags;
|
||||
fSystemDependency = other.fSystemDependency;
|
||||
fLocalFilePath = other.fLocalFilePath;
|
||||
fFileName = other.fFileName;
|
||||
fSize = other.fSize;
|
||||
fViewed = other.fViewed;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackageLocalInfo::operator==(const PackageLocalInfo& other) const
|
||||
{
|
||||
return fState == other.fState
|
||||
&& fFlags == other.fFlags
|
||||
&& fInstallationLocations == other.fInstallationLocations
|
||||
&& fDownloadProgress == other.fDownloadProgress
|
||||
&& fSystemDependency == other.fSystemDependency
|
||||
&& fLocalFilePath == other.fLocalFilePath
|
||||
&& fFileName == other.fFileName
|
||||
&& fSize == other.fSize
|
||||
&& fViewed == other.fViewed;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackageLocalInfo::operator!=(const PackageLocalInfo& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackageLocalInfo::IsSystemPackage() const
|
||||
{
|
||||
return (fFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetSystemDependency(bool isDependency)
|
||||
{
|
||||
fSystemDependency = isDependency;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetState(PackageState state)
|
||||
{
|
||||
if (fState != state) {
|
||||
fState = state;
|
||||
if (fState != DOWNLOADING)
|
||||
fDownloadProgress = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::AddInstallationLocation(int32 location)
|
||||
{
|
||||
fInstallationLocations.insert(location);
|
||||
SetState(ACTIVATED);
|
||||
// TODO: determine how to differentiate between installed and active.
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::ClearInstallationLocations()
|
||||
{
|
||||
fInstallationLocations.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetDownloadProgress(float progress)
|
||||
{
|
||||
fState = DOWNLOADING;
|
||||
fDownloadProgress = progress;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetLocalFilePath(const char* path)
|
||||
{
|
||||
fLocalFilePath = path;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PackageLocalInfo::IsLocalFile() const
|
||||
{
|
||||
return !fLocalFilePath.IsEmpty() && fInstallationLocations.empty();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetSize(int64 size)
|
||||
{
|
||||
fSize = size;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetViewed()
|
||||
{
|
||||
fViewed = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetFlags(int32 value)
|
||||
{
|
||||
fFlags = value;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageLocalInfo::SetFileName(const BString& value)
|
||||
{
|
||||
fFileName = value;
|
||||
}
|
100
src/apps/haikudepot/packagemodel/PackageLocalInfo.h
Normal file
100
src/apps/haikudepot/packagemodel/PackageLocalInfo.h
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2024, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef PACKAGE_LOCAL_INFO_H
|
||||
#define PACKAGE_LOCAL_INFO_H
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <Referenceable.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
typedef std::set<int32> PackageInstallationLocationSet;
|
||||
|
||||
|
||||
enum PackageState {
|
||||
NONE = 0,
|
||||
INSTALLED = 1,
|
||||
DOWNLOADING = 2,
|
||||
ACTIVATED = 3,
|
||||
UNINSTALLED = 4,
|
||||
PENDING = 5,
|
||||
};
|
||||
|
||||
|
||||
class PackageLocalInfo : public BReferenceable
|
||||
{
|
||||
public:
|
||||
PackageLocalInfo();
|
||||
PackageLocalInfo(const PackageLocalInfo& other);
|
||||
virtual ~PackageLocalInfo();
|
||||
|
||||
PackageLocalInfo& operator=(const PackageLocalInfo& other);
|
||||
bool operator==(const PackageLocalInfo& other) const;
|
||||
bool operator!=(const PackageLocalInfo& other) const;
|
||||
|
||||
bool IsLocalFile() const;
|
||||
|
||||
void SetViewed();
|
||||
bool Viewed() const
|
||||
{ return fViewed; }
|
||||
|
||||
void SetLocalFilePath(const char* path);
|
||||
const BString& LocalFilePath() const
|
||||
{ return fLocalFilePath; }
|
||||
|
||||
void SetFileName(const BString& value);
|
||||
const BString& FileName() const
|
||||
{ return fFileName; }
|
||||
|
||||
void SetSize(off_t size);
|
||||
off_t Size() const
|
||||
{ return fSize; }
|
||||
|
||||
void SetFlags(int32 value);
|
||||
int32 Flags() const
|
||||
{ return fFlags; }
|
||||
|
||||
bool IsSystemPackage() const;
|
||||
|
||||
void SetSystemDependency(bool isDependency);
|
||||
bool IsSystemDependency() const
|
||||
{ return fSystemDependency; }
|
||||
|
||||
void SetState(PackageState state);
|
||||
PackageState State() const
|
||||
{ return fState; }
|
||||
|
||||
void AddInstallationLocation(int32 location);
|
||||
const PackageInstallationLocationSet&
|
||||
InstallationLocations() const
|
||||
{ return fInstallationLocations; }
|
||||
void ClearInstallationLocations();
|
||||
|
||||
void SetDownloadProgress(float progress);
|
||||
float DownloadProgress() const
|
||||
{ return fDownloadProgress; }
|
||||
|
||||
private:
|
||||
bool fViewed;
|
||||
BString fLocalFilePath;
|
||||
BString fFileName;
|
||||
off_t fSize;
|
||||
int32 fFlags;
|
||||
bool fSystemDependency;
|
||||
PackageState fState;
|
||||
PackageInstallationLocationSet
|
||||
fInstallationLocations;
|
||||
float fDownloadProgress;
|
||||
};
|
||||
|
||||
|
||||
typedef BReference<PackageLocalInfo> PackageLocalInfoRef;
|
||||
|
||||
|
||||
#endif // PACKAGE_LOCAL_INFO_H
|
@ -11,7 +11,8 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class ScreenshotInfo : public BReferenceable {
|
||||
class ScreenshotInfo : public BReferenceable
|
||||
{
|
||||
public:
|
||||
ScreenshotInfo();
|
||||
ScreenshotInfo(const BString& code,
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "Logger.h"
|
||||
#include "PackageInfo.h"
|
||||
#include "PackageManager.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/manager/Exceptions.h>
|
||||
@ -201,6 +202,8 @@ LocalPkgDataLoadProcess::RunInternal()
|
||||
foundPackages[repoPackageInfo.Name()] = modelInfo;
|
||||
}
|
||||
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(modelInfo);
|
||||
|
||||
// The package list here considers those packages that are installed
|
||||
// in the system as well as those that exist in remote repositories.
|
||||
// It is better if the 'depot name' is from the remote repository
|
||||
@ -239,23 +242,21 @@ LocalPkgDataLoadProcess::RunInternal()
|
||||
|
||||
remotePackages[modelInfo->Name()] = modelInfo;
|
||||
} else {
|
||||
if (repository == static_cast<const BSolverRepository*>(
|
||||
manager.SystemRepository())) {
|
||||
modelInfo->AddInstallationLocation(
|
||||
B_PACKAGE_INSTALLATION_LOCATION_SYSTEM);
|
||||
if (!modelInfo->IsSystemPackage()) {
|
||||
systemInstalledPackages[repoPackageInfo.FileName()]
|
||||
= modelInfo;
|
||||
}
|
||||
} else if (repository == static_cast<const BSolverRepository*>(
|
||||
manager.HomeRepository())) {
|
||||
modelInfo->AddInstallationLocation(
|
||||
B_PACKAGE_INSTALLATION_LOCATION_HOME);
|
||||
if (repository == static_cast<const BSolverRepository*>(manager.SystemRepository())) {
|
||||
localInfo->AddInstallationLocation(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM);
|
||||
if (!localInfo->IsSystemPackage())
|
||||
systemInstalledPackages[repoPackageInfo.FileName()] = modelInfo;
|
||||
} else if (repository
|
||||
== static_cast<const BSolverRepository*>(manager.HomeRepository())) {
|
||||
localInfo->AddInstallationLocation(B_PACKAGE_INSTALLATION_LOCATION_HOME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (modelInfo->IsSystemPackage())
|
||||
if (localInfo->IsSystemPackage())
|
||||
systemFlaggedPackages.Add(repoPackageInfo.FileName());
|
||||
|
||||
modelInfo->SetLocalInfo(localInfo);
|
||||
}
|
||||
|
||||
BAutolock lock(fModel->Lock());
|
||||
@ -355,8 +356,13 @@ LocalPkgDataLoadProcess::RunInternal()
|
||||
if (element->Type() == BSolverResultElement::B_TYPE_INSTALL) {
|
||||
PackageInfoMap::iterator it = systemInstalledPackages.find(
|
||||
package->Info().FileName());
|
||||
if (it != systemInstalledPackages.end())
|
||||
it->second->SetSystemDependency(true);
|
||||
if (it != systemInstalledPackages.end()) {
|
||||
PackageInfoRef systemInstalledPackage = it->second;
|
||||
PackageLocalInfoRef localInfo
|
||||
= PackageUtils::NewLocalInfo(systemInstalledPackage);
|
||||
localInfo->SetSystemDependency(true);
|
||||
systemInstalledPackage->SetLocalInfo(localInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (BFatalErrorException& ex) {
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "Logger.h"
|
||||
#include "PackageKitUtils.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@ -61,23 +62,29 @@ PopulatePkgSizesProcess::RunInternal()
|
||||
|
||||
for (int32 p = 0; p < depotInfo->CountPackages(); p++) {
|
||||
PackageInfoRef packageInfo = depotInfo->PackageAtIndex(p);
|
||||
PackageState state = packageInfo->State();
|
||||
|
||||
if (packageInfo->Size() <= 0
|
||||
&& (state == ACTIVATED || state == INSTALLED)) {
|
||||
if (!packageInfo.IsSet())
|
||||
HDFATAL("package is not set");
|
||||
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(packageInfo);
|
||||
PackageState state = localInfo->State();
|
||||
|
||||
if (localInfo->Size() <= 0 && (state == ACTIVATED || state == INSTALLED)) {
|
||||
off_t derivedSize = _DeriveSize(packageInfo);
|
||||
|
||||
if (derivedSize > 0) {
|
||||
packageInfo->SetSize(derivedSize);
|
||||
localInfo->SetSize(derivedSize);
|
||||
countPkgSized++;
|
||||
HDDEBUG("[%s] did derive a size for package [%s]",
|
||||
Name(), packageInfo->Name().String());
|
||||
HDDEBUG("[%s] did derive a size for package [%s]", Name(),
|
||||
packageInfo->Name().String());
|
||||
} else {
|
||||
countPkgUnsized++;
|
||||
HDDEBUG("[%s] unable to derive a size for package [%s]",
|
||||
Name(), packageInfo->Name().String());
|
||||
HDDEBUG("[%s] unable to derive a size for package [%s]", Name(),
|
||||
packageInfo->Name().String());
|
||||
}
|
||||
}
|
||||
|
||||
packageInfo->SetLocalInfo(localInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +100,7 @@ off_t
|
||||
PopulatePkgSizesProcess::_DeriveSize(const PackageInfoRef package) const
|
||||
{
|
||||
BPath path;
|
||||
if (PackageKitUtils::DeriveLocalFilePath(package.Get(), path) == B_OK) {
|
||||
if (PackageKitUtils::DeriveLocalFilePath(package, path) == B_OK) {
|
||||
BEntry entry(path.Path());
|
||||
struct stat s = {};
|
||||
if (entry.GetStat(&s) == B_OK)
|
||||
|
@ -17,15 +17,16 @@
|
||||
#include <StopWatch.h>
|
||||
#include <Url.h>
|
||||
|
||||
#include "Logger.h"
|
||||
#include "ServerSettings.h"
|
||||
#include "StorageUtils.h"
|
||||
#include "DumpExportPkg.h"
|
||||
#include "DumpExportPkgCategory.h"
|
||||
#include "DumpExportPkgJsonListener.h"
|
||||
#include "DumpExportPkgScreenshot.h"
|
||||
#include "DumpExportPkgVersion.h"
|
||||
#include "HaikuDepotConstants.h"
|
||||
#include "Logger.h"
|
||||
#include "PackageUtils.h"
|
||||
#include "ServerSettings.h"
|
||||
#include "StorageUtils.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@ -95,14 +96,8 @@ PackageFillingPkgListener::ConsumePackage(const PackageInfoRef& package,
|
||||
|
||||
PackageClassificationInfoRef packageClassificationInfo(new PackageClassificationInfo(), true);
|
||||
|
||||
PackageLocalizedTextRef localizedText = package->LocalizedText();
|
||||
|
||||
if (localizedText.IsSet()) {
|
||||
localizedText
|
||||
= PackageLocalizedTextRef(new PackageLocalizedText(*(localizedText.Get())), true);
|
||||
} else {
|
||||
localizedText = PackageLocalizedTextRef(new PackageLocalizedText(), true);
|
||||
}
|
||||
PackageLocalizedTextRef localizedText = PackageUtils::NewLocalizedText(package);
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(package);
|
||||
|
||||
localizedText->SetHasChangelog(pkg->HasChangelog());
|
||||
|
||||
@ -123,7 +118,7 @@ PackageFillingPkgListener::ConsumePackage(const PackageInfoRef& package,
|
||||
localizedText->SetDescription(*(pkgVersion->Description()));
|
||||
|
||||
if (!pkgVersion->PayloadLengthIsNull())
|
||||
package->SetSize(static_cast<off_t>(pkgVersion->PayloadLength()));
|
||||
localInfo->SetSize(static_cast<off_t>(pkgVersion->PayloadLength()));
|
||||
|
||||
if (!pkgVersion->CreateTimestampIsNull())
|
||||
package->SetVersionCreateTimestamp(pkgVersion->CreateTimestamp());
|
||||
@ -171,6 +166,7 @@ PackageFillingPkgListener::ConsumePackage(const PackageInfoRef& package,
|
||||
}
|
||||
|
||||
package->SetLocalizedText(localizedText);
|
||||
package->SetLocalInfo(localInfo);
|
||||
|
||||
HDTRACE("did populate data for [%s] (%s)", pkg->Name()->String(),
|
||||
fDepotName.String());
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "AppUtils.h"
|
||||
#include "Logger.h"
|
||||
#include "MainWindow.h"
|
||||
#include "PackageUtils.h"
|
||||
#include "ServerHelper.h"
|
||||
#include "ServerSettings.h"
|
||||
#include "SharedIcons.h"
|
||||
@ -385,7 +386,8 @@ App::_Open(const BEntry& entry)
|
||||
return;
|
||||
}
|
||||
|
||||
package->SetLocalFilePath(path.Path());
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(package);
|
||||
localInfo->SetLocalFilePath(path.Path());
|
||||
|
||||
// Set if the package is active
|
||||
//
|
||||
@ -412,9 +414,10 @@ App::_Open(const BEntry& entry)
|
||||
}
|
||||
}
|
||||
|
||||
if (active) {
|
||||
package->SetState(ACTIVATED);
|
||||
}
|
||||
if (active)
|
||||
localInfo->SetState(ACTIVATED);
|
||||
|
||||
package->SetLocalInfo(localInfo);
|
||||
|
||||
BMessage settings;
|
||||
_LoadSettings(settings);
|
||||
|
@ -661,7 +661,7 @@ public:
|
||||
|
||||
DrawString(renderedText, pt);
|
||||
|
||||
if (pkg->State() == ACTIVATED) {
|
||||
if (PackageUtils::State(pkg) == ACTIVATED) {
|
||||
float stringWidth = StringWidth(title);
|
||||
BRect iconRect = BRect(
|
||||
BPoint(textRect.left + stringWidth + (installedIconBitmap->Bounds().Width() / 2.0),
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "PackageInfoView.h"
|
||||
#include "PackageListView.h"
|
||||
#include "PackageManager.h"
|
||||
#include "PackageUtils.h"
|
||||
#include "ProcessCoordinator.h"
|
||||
#include "ProcessCoordinatorFactory.h"
|
||||
#include "RatePackageWindow.h"
|
||||
@ -720,7 +721,7 @@ MainWindow::Consume(ProcessCoordinator *item)
|
||||
void
|
||||
MainWindow::PackageChanged(const PackageInfoEvent& event)
|
||||
{
|
||||
uint32 watchedChanges = PKG_CHANGED_STATE | PKG_CHANGED_CLASSIFICATION;
|
||||
uint32 watchedChanges = PKG_CHANGED_LOCAL_INFO | PKG_CHANGED_CLASSIFICATION;
|
||||
if ((event.Changes() & watchedChanges) != 0) {
|
||||
PackageInfoRef ref(event.Package());
|
||||
BMessage message(MSG_PACKAGE_CHANGED);
|
||||
@ -1051,8 +1052,10 @@ MainWindow::_IncrementViewCounter(const PackageInfoRef package)
|
||||
{
|
||||
AutoLocker<BLocker> modelLocker(fModel.Lock());
|
||||
bool canShareAnonymousUsageData = fModel.CanShareAnonymousUsageData();
|
||||
if (canShareAnonymousUsageData && !package->Viewed()) {
|
||||
package->SetViewed();
|
||||
if (canShareAnonymousUsageData && !PackageUtils::Viewed(package)) {
|
||||
PackageLocalInfoRef localInfo = PackageUtils::NewLocalInfo(package);
|
||||
localInfo->SetViewed();
|
||||
package->SetLocalInfo(localInfo);
|
||||
shouldIncrementViewCounter = true;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "GeneralContentScrollView.h"
|
||||
#include "Logger.h"
|
||||
#include "PackageKitUtils.h"
|
||||
#include "PackageUtils.h"
|
||||
|
||||
#include <package/PackageDefs.h>
|
||||
#include <package/hpkg/NoErrorOutput.h>
|
||||
@ -244,30 +245,28 @@ PackageContentsView::AllAttached()
|
||||
void
|
||||
PackageContentsView::SetPackage(const PackageInfoRef& package)
|
||||
{
|
||||
PackageState packageState = PackageUtils::State(package);
|
||||
|
||||
// When getting a ref to the same package, don't return when the
|
||||
// package state has changed, since in that case, we may now be able
|
||||
// to read contents where we previously could not. (For example, the
|
||||
// package has been installed.)
|
||||
if (fPackage == package
|
||||
&& (!package.IsSet() || package->State() == fLastPackageState)) {
|
||||
if (fPackage == package && (!package.IsSet() || packageState == fLastPackageState))
|
||||
return;
|
||||
}
|
||||
|
||||
Clear();
|
||||
|
||||
{
|
||||
BAutolock lock(&fPackageLock);
|
||||
fPackage = package;
|
||||
fLastPackageState = package.IsSet() ? package->State() : NONE;
|
||||
fLastPackageState = packageState;
|
||||
}
|
||||
|
||||
// if the package is not installed and is not a local file on disk then
|
||||
// there is no point in attempting to populate data for it.
|
||||
|
||||
if (package.IsSet()
|
||||
&& (package->State() == ACTIVATED || package->IsLocalFile())) {
|
||||
if (PackageUtils::IsActivatedOrLocalFile(package))
|
||||
release_sem_etc(fContentPopulatorSem, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -313,7 +312,7 @@ PackageContentsView::_ContentPopulatorThread(void* arg)
|
||||
}
|
||||
|
||||
if (package.IsSet()) {
|
||||
if (!view->_PopulatePackageContents(*package.Get())) {
|
||||
if (!view->_PopulatePackageContents(package)) {
|
||||
if (view->LockLooperWithTimeout(1000000) == B_OK) {
|
||||
view->fContentListView->AddItem(
|
||||
new BStringItem(B_TRANSLATE("<Package contents not "
|
||||
@ -329,11 +328,11 @@ PackageContentsView::_ContentPopulatorThread(void* arg)
|
||||
|
||||
|
||||
bool
|
||||
PackageContentsView::_PopulatePackageContents(const PackageInfo& package)
|
||||
PackageContentsView::_PopulatePackageContents(const PackageInfoRef& package)
|
||||
{
|
||||
BPath packagePath;
|
||||
|
||||
if (PackageKitUtils::DeriveLocalFilePath(&package, packagePath) != B_OK) {
|
||||
if (PackageKitUtils::DeriveLocalFilePath(package, packagePath) != B_OK) {
|
||||
HDDEBUG("unable to obtain local file path");
|
||||
return false;
|
||||
}
|
||||
@ -351,8 +350,7 @@ PackageContentsView::_PopulatePackageContents(const PackageInfo& package)
|
||||
}
|
||||
|
||||
// Scan package contents and populate list
|
||||
PackageContentOutliner contentHandler(fContentListView, &package,
|
||||
fPackageLock, fPackage);
|
||||
PackageContentOutliner contentHandler(fContentListView, package.Get(), fPackageLock, fPackage);
|
||||
status = reader.ParseContent(&contentHandler);
|
||||
if (status != B_OK) {
|
||||
HDINFO("PackageContentsView::_PopulatePackageContents(): "
|
||||
|
@ -28,8 +28,7 @@ public:
|
||||
private:
|
||||
void _InitContentPopulator();
|
||||
static int32 _ContentPopulatorThread(void* arg);
|
||||
bool _PopulatePackageContents(
|
||||
const PackageInfo& package);
|
||||
bool _PopulatePackageContents(const PackageInfoRef& package);
|
||||
|
||||
private:
|
||||
BOutlineListView* fContentListView;
|
||||
|
@ -499,7 +499,7 @@ public:
|
||||
|
||||
void SetPackage(const PackageInfoRef package)
|
||||
{
|
||||
if (package->State() == DOWNLOADING) {
|
||||
if (PackageUtils::State(package) == DOWNLOADING) {
|
||||
AdoptDownloadProgress(package);
|
||||
} else {
|
||||
AdoptActions(package);
|
||||
@ -544,7 +544,7 @@ public:
|
||||
fLayout->AddView(fStatusBar);
|
||||
}
|
||||
|
||||
fStatusBar->SetTo(package->DownloadProgress() * 100.0);
|
||||
fStatusBar->SetTo(PackageUtils::DownloadProgress(package) * 100.0);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
@ -1229,7 +1229,7 @@ public:
|
||||
if (localizedText.IsSet())
|
||||
enableChangelogTab = localizedText->HasChangelog();
|
||||
|
||||
enableContentsTab = package->State() == ACTIVATED || package->IsLocalFile();
|
||||
enableContentsTab = PackageUtils::IsActivatedOrLocalFile(package);
|
||||
}
|
||||
|
||||
TabAt(TAB_CHANGELOG)->SetEnabled(enableChangelogTab);
|
||||
@ -1352,7 +1352,7 @@ PackageInfoView::MessageReceived(BMessage* message)
|
||||
if ((changes & PKG_CHANGED_LOCALIZED_TEXT) != 0
|
||||
|| (changes & PKG_CHANGED_SCREENSHOTS) != 0
|
||||
|| (changes & PKG_CHANGED_RATINGS) != 0
|
||||
|| (changes & PKG_CHANGED_STATE) != 0
|
||||
|| (changes & PKG_CHANGED_LOCAL_INFO) != 0
|
||||
|| (changes & PKG_CHANGED_CHANGELOG) != 0) {
|
||||
fPagesView->SetPackage(package, false);
|
||||
}
|
||||
@ -1360,7 +1360,7 @@ PackageInfoView::MessageReceived(BMessage* message)
|
||||
if ((changes & PKG_CHANGED_LOCALIZED_TEXT) != 0 || (changes & PKG_CHANGED_RATINGS) != 0)
|
||||
fTitleView->SetPackage(package);
|
||||
|
||||
if ((changes & PKG_CHANGED_STATE) != 0)
|
||||
if ((changes & PKG_CHANGED_LOCAL_INFO) != 0)
|
||||
fPackageActionView->SetPackage(package);
|
||||
|
||||
break;
|
||||
|
@ -43,11 +43,11 @@ static const char* skPackageStatePending = B_TRANSLATE_MARK(
|
||||
|
||||
|
||||
inline BString
|
||||
package_state_to_string(PackageInfoRef ref)
|
||||
package_state_to_string(PackageInfoRef package)
|
||||
{
|
||||
static BNumberFormat numberFormat;
|
||||
|
||||
switch (ref->State()) {
|
||||
switch (PackageUtils::State(package)) {
|
||||
case NONE:
|
||||
return B_TRANSLATE(skPackageStateAvailable);
|
||||
case INSTALLED:
|
||||
@ -59,7 +59,7 @@ package_state_to_string(PackageInfoRef ref)
|
||||
case DOWNLOADING:
|
||||
{
|
||||
BString data;
|
||||
float fraction = ref->DownloadProgress();
|
||||
float fraction = PackageUtils::DownloadProgress(package);
|
||||
if (numberFormat.FormatPercent(data, fraction) != B_OK) {
|
||||
HDERROR("unable to format the percentage");
|
||||
data = "???";
|
||||
@ -681,7 +681,8 @@ PackageRow::UpdateIconAndTitle()
|
||||
PackageUtils::TitleOrName(fPackage, title);
|
||||
|
||||
BField* field
|
||||
= new PackageIconAndTitleField(fPackage->Name(), title, fPackage->State() == ACTIVATED);
|
||||
= new PackageIconAndTitleField(fPackage->Name(), title,
|
||||
PackageUtils::State(fPackage) == ACTIVATED);
|
||||
SetField(field, kTitleColumn);
|
||||
}
|
||||
|
||||
@ -734,7 +735,7 @@ PackageRow::UpdateSize()
|
||||
{
|
||||
if (!fPackage.IsSet())
|
||||
return;
|
||||
SetField(new SizeField(fPackage->Size()), kSizeColumn);
|
||||
SetField(new SizeField(PackageUtils::Size(fPackage)), kSizeColumn);
|
||||
}
|
||||
|
||||
|
||||
@ -987,16 +988,16 @@ PackageListView::MessageReceived(BMessage* message)
|
||||
PackageRow* row = _FindRow(name);
|
||||
if (row != NULL) {
|
||||
if ((changes & PKG_CHANGED_LOCALIZED_TEXT) != 0
|
||||
|| (changes & PKG_CHANGED_STATE) != 0) {
|
||||
|| (changes & PKG_CHANGED_LOCAL_INFO) != 0) {
|
||||
row->UpdateIconAndTitle();
|
||||
row->UpdateSummary();
|
||||
}
|
||||
if ((changes & PKG_CHANGED_RATINGS) != 0)
|
||||
row->UpdateRating();
|
||||
if ((changes & PKG_CHANGED_STATE) != 0)
|
||||
if ((changes & PKG_CHANGED_LOCAL_INFO) != 0) {
|
||||
row->UpdateState();
|
||||
if ((changes & PKG_CHANGED_SIZE) != 0)
|
||||
row->UpdateSize();
|
||||
}
|
||||
if ((changes & PKG_CHANGED_ICON) != 0)
|
||||
row->UpdateIconAndTitle();
|
||||
if ((changes & PKG_CHANGED_DEPOT) != 0)
|
||||
|
@ -10,10 +10,15 @@ using namespace BPackageKit;
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
PackageKitUtils::DeriveLocalFilePath(const PackageInfo* package, BPath& path)
|
||||
PackageKitUtils::DeriveLocalFilePath(const PackageInfoRef package, BPath& path)
|
||||
{
|
||||
if (package->IsLocalFile()) {
|
||||
path.SetTo(package->LocalFilePath());
|
||||
if (!package.IsSet())
|
||||
return B_ERROR;
|
||||
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet() && localInfo->IsLocalFile()) {
|
||||
path.SetTo(localInfo->LocalFilePath());
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -26,7 +31,7 @@ PackageKitUtils::DeriveLocalFilePath(const PackageInfo* package, BPath& path)
|
||||
result = find_directory(which, &path);
|
||||
|
||||
if (result == B_OK)
|
||||
path.Append(package->FileName());
|
||||
path.Append(localInfo->FileName());
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -52,13 +57,20 @@ PackageKitUtils::_DeriveDirectoryWhich(BPackageInstallationLocation location,
|
||||
|
||||
|
||||
/*static*/ BPackageInstallationLocation
|
||||
PackageKitUtils::DeriveInstallLocation(const PackageInfo* package)
|
||||
PackageKitUtils::DeriveInstallLocation(const PackageInfoRef package)
|
||||
{
|
||||
const PackageInstallationLocationSet& locations = package->InstallationLocations();
|
||||
if (package.IsSet()) {
|
||||
|
||||
// If the package is already installed, return its first installed location
|
||||
if (locations.size() != 0)
|
||||
return static_cast<BPackageInstallationLocation>(*locations.begin());
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet()) {
|
||||
const PackageInstallationLocationSet& locations = localInfo->InstallationLocations();
|
||||
|
||||
// If the package is already installed, return its first installed location
|
||||
if (locations.size() != 0)
|
||||
return static_cast<BPackageInstallationLocation>(*locations.begin());
|
||||
}
|
||||
}
|
||||
|
||||
return B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
|
||||
}
|
||||
|
@ -17,16 +17,14 @@
|
||||
class PackageKitUtils
|
||||
{
|
||||
public:
|
||||
static status_t DeriveLocalFilePath(const PackageInfo* package,
|
||||
BPath& result);
|
||||
static status_t DeriveLocalFilePath(const PackageInfoRef package, BPath& result);
|
||||
|
||||
static BPackageKit::BPackageInstallationLocation
|
||||
DeriveInstallLocation(const PackageInfo* package);
|
||||
DeriveInstallLocation(const PackageInfoRef package);
|
||||
|
||||
private:
|
||||
static status_t _DeriveDirectoryWhich(
|
||||
BPackageKit::BPackageInstallationLocation
|
||||
location,
|
||||
BPackageKit::BPackageInstallationLocation location,
|
||||
directory_which* which);
|
||||
};
|
||||
|
||||
|
@ -5,13 +5,14 @@
|
||||
|
||||
#include "PackageUtils.h"
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
/*! This method will obtain the title from the package if this is possible or
|
||||
otherwise it will return the name of the package.
|
||||
*/
|
||||
|
||||
/*static*/ void
|
||||
PackageUtils::TitleOrName(const PackageInfoRef package, BString& title)
|
||||
PackageUtils::TitleOrName(const PackageInfoRef& package, BString& title)
|
||||
{
|
||||
PackageUtils::Title(package, title);
|
||||
if (title.IsEmpty() && package.IsSet())
|
||||
@ -20,7 +21,7 @@ PackageUtils::TitleOrName(const PackageInfoRef package, BString& title)
|
||||
|
||||
|
||||
/*static*/ void
|
||||
PackageUtils::Title(const PackageInfoRef package, BString& title)
|
||||
PackageUtils::Title(const PackageInfoRef& package, BString& title)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalizedTextRef localizedText = package->LocalizedText();
|
||||
@ -36,7 +37,7 @@ PackageUtils::Title(const PackageInfoRef package, BString& title)
|
||||
|
||||
|
||||
/*static*/ void
|
||||
PackageUtils::Summary(const PackageInfoRef package, BString& summary)
|
||||
PackageUtils::Summary(const PackageInfoRef& package, BString& summary)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalizedTextRef localizedText = package->LocalizedText();
|
||||
@ -49,3 +50,140 @@ PackageUtils::Summary(const PackageInfoRef package, BString& summary)
|
||||
summary.SetTo("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*static*/ PackageLocalizedTextRef
|
||||
PackageUtils::NewLocalizedText(const PackageInfoRef& package)
|
||||
{
|
||||
if (!package.IsSet())
|
||||
HDFATAL("it is not possible to get the `LocalizedText` from a not-existing package");
|
||||
|
||||
PackageLocalizedTextRef localizedText = package->LocalizedText();
|
||||
|
||||
if (localizedText.IsSet())
|
||||
return PackageLocalizedTextRef(new PackageLocalizedText(*(localizedText.Get())), true);
|
||||
|
||||
return PackageLocalizedTextRef(new PackageLocalizedText(), true);
|
||||
}
|
||||
|
||||
|
||||
/*static*/ PackageState
|
||||
PackageUtils::State(const PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return localInfo->State();
|
||||
}
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ off_t
|
||||
PackageUtils::Size(const PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return localInfo->Size();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ bool
|
||||
PackageUtils::Viewed(const PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return localInfo->Viewed();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ bool
|
||||
PackageUtils::IsActivatedOrLocalFile(const PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return localInfo->IsLocalFile() || localInfo->State() == ACTIVATED;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ float
|
||||
PackageUtils::DownloadProgress(const PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return localInfo->DownloadProgress();
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ int32
|
||||
PackageUtils::Flags(const PackageInfoRef& package)
|
||||
{
|
||||
if (package.IsSet()) {
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return localInfo->Flags();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ PackageLocalInfoRef
|
||||
PackageUtils::NewLocalInfo(const PackageInfoRef& package)
|
||||
{
|
||||
if (!package.IsSet())
|
||||
HDFATAL("it is not possible to get the `LocalInfo` from a not-existing package");
|
||||
|
||||
PackageLocalInfoRef localInfo = package->LocalInfo();
|
||||
|
||||
if (localInfo.IsSet())
|
||||
return PackageLocalInfoRef(new PackageLocalInfo(*(localInfo.Get())), true);
|
||||
|
||||
return PackageLocalInfoRef(new PackageLocalInfo(), true);
|
||||
}
|
||||
|
||||
|
||||
/*static*/ const char*
|
||||
PackageUtils::StateToString(PackageState state)
|
||||
{
|
||||
switch (state) {
|
||||
case NONE:
|
||||
return "NONE";
|
||||
case INSTALLED:
|
||||
return "INSTALLED";
|
||||
case DOWNLOADING:
|
||||
return "DOWNLOADING";
|
||||
case ACTIVATED:
|
||||
return "ACTIVATED";
|
||||
case UNINSTALLED:
|
||||
return "UNINSTALLED";
|
||||
case PENDING:
|
||||
return "PENDING";
|
||||
default:
|
||||
debugger("unknown package state");
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,25 @@
|
||||
|
||||
class PackageUtils {
|
||||
public:
|
||||
static void TitleOrName(const PackageInfoRef package, BString& title);
|
||||
static void Title(const PackageInfoRef package, BString& title);
|
||||
static void Summary(const PackageInfoRef package, BString& summary);
|
||||
static void TitleOrName(const PackageInfoRef& package, BString& title);
|
||||
static void Title(const PackageInfoRef& package, BString& title);
|
||||
static void Summary(const PackageInfoRef& package, BString& summary);
|
||||
|
||||
static PackageLocalizedTextRef
|
||||
NewLocalizedText(const PackageInfoRef& package);
|
||||
|
||||
static bool Viewed(const PackageInfoRef& package);
|
||||
static PackageState State(const PackageInfoRef& package);
|
||||
static float DownloadProgress(const PackageInfoRef& package);
|
||||
static bool IsActivatedOrLocalFile(const PackageInfoRef& package);
|
||||
static off_t Size(const PackageInfoRef& package);
|
||||
static int32 Flags(const PackageInfoRef& package);
|
||||
|
||||
static PackageLocalInfoRef
|
||||
NewLocalInfo(const PackageInfoRef& package);
|
||||
|
||||
static const char* StateToString(PackageState state);
|
||||
|
||||
};
|
||||
|
||||
#endif // PACKAGE_UTILS_H
|
||||
|
Loading…
Reference in New Issue
Block a user