示例#1
0
PackageRow::PackageRow(const PackageInfoRef& packageRef,
		PackageListener* packageListener)
	:
	Inherited(ceilf(be_plain_font->Size() * 1.8f)),
	fPackage(packageRef),
	fPackageListener(packageListener)
{
	if (packageRef.Get() == NULL)
		return;

	PackageInfo& package = *packageRef.Get();

	// Package icon and title
	// NOTE: The icon BBitmap is referenced by the fPackage member.
	UpdateTitle();

	// Rating
	UpdateRating();

	// Summary
	UpdateSummary();

	// Size
	UpdateSize();

	// Status
	UpdateState();

	package.AddListener(fPackageListener);
}
示例#2
0
PackageActionList
PackageManager::GetPackageActions(PackageInfoRef package, Model* model)
{
	PackageActionList actionList;
	if (package->IsSystemPackage() || package->IsSystemDependency())
		return actionList;

	int32 state = package->State();
	if (state == ACTIVATED || state == INSTALLED) {
		actionList.Add(PackageActionRef(new UninstallPackageAction(
			package, model), true));
		
		// Add OpenPackageActions for each deskbar link found in the
		// package
		DeskbarLinkList foundLinks;
		if (OpenPackageAction::FindAppToLaunch(package, foundLinks)
			&& foundLinks.CountItems() < 4) {
			for (int32 i = 0; i < foundLinks.CountItems(); i++) {
				const DeskbarLink& link = foundLinks.ItemAtFast(i);
				actionList.Add(PackageActionRef(new OpenPackageAction(
					package, model, link), true));
			}
		}
	} else if (state == NONE || state == UNINSTALLED) {
		actionList.Add(PackageActionRef(new InstallPackageAction(package,
				model),	true));
	}
	// TODO: activation status

	return actionList;
}
status_t
ServerIconExportUpdateProcess::PopulateForPkg(const PackageInfoRef& package)
{
	BPath bestIconPath;

	if ( fLocalIconStore->TryFindIconPath(
		package->Name(), bestIconPath) == B_OK) {

		BFile bestIconFile(bestIconPath.Path(), O_RDONLY);
		BitmapRef bitmapRef(new(std::nothrow)SharedBitmap(bestIconFile), true);
		package->SetIcon(bitmapRef);

		if (Logger::IsDebugEnabled()) {
			printf("[%s] have set the package icon for [%s] from [%s]\n",
				Name(), package->Name().String(), bestIconPath.Path());
		}

		fCountIconsSet++;

		return B_OK;
	}

	if (Logger::IsDebugEnabled()) {
		printf("[%s] did not set the package icon for [%s]; no data\n",
			Name(), package->Name().String());
	}

	return B_FILE_NOT_FOUND;
}
示例#4
0
void
PackageRow::UpdateSize()
{
	if (fPackage.Get() == NULL)
		return;

	SetField(new SizeField(fPackage->Size()), kSizeColumn);
}
示例#5
0
void
PackageRow::UpdateRating()
{
    if (fPackage.Get() == NULL)
        return;
    RatingSummary summary = fPackage->CalculateRatingSummary();
    SetField(new RatingField(summary.averageRating), kRatingColumn);
}
示例#6
0
void
PackageRow::UpdateSummary()
{
	if (fPackage.Get() == NULL)
		return;

	SetField(new BStringField(fPackage->ShortDescription()),
		kDescriptionColumn);
}
示例#7
0
void
PackageRow::UpdateTitle()
{
	if (fPackage.Get() == NULL)
		return;

	SetField(new SharedBitmapStringField(fPackage->Icon(),
			SharedBitmap::SIZE_16, fPackage->Title()), kTitleColumn);
}
示例#8
0
	static bool FindAppToLaunch(const PackageInfoRef& package,
		DeskbarLinkList& foundLinks)
	{
		if (package.Get() == NULL)
			return false;

		int32 installLocation = InstallLocation(package);

		BPath packagePath;
		if (installLocation == B_PACKAGE_INSTALLATION_LOCATION_SYSTEM) {
			if (find_directory(B_SYSTEM_PACKAGES_DIRECTORY, &packagePath)
				!= B_OK) {
				return false;
			}
		} else if (installLocation == B_PACKAGE_INSTALLATION_LOCATION_HOME) {
			if (find_directory(B_USER_PACKAGES_DIRECTORY, &packagePath)
				!= B_OK) {
				return false;
			}
		} else {
			printf("OpenPackageAction::FindAppToLaunch(): "
				"unknown install location");
			return false;
		}

		packagePath.Append(package->FileName());
		
		BNoErrorOutput errorOutput;
		BPackageReader reader(&errorOutput);

		status_t status = reader.Init(packagePath.Path());
		if (status != B_OK) {
			printf("OpenPackageAction::FindAppToLaunch(): "
				"failed to init BPackageReader(%s): %s\n",
				packagePath.Path(), strerror(status));
			return false;
		}
		
		// Scan package contents for Deskbar links
		DeskbarLinkFinder contentHandler(foundLinks);
		status = reader.ParseContent(&contentHandler);
		if (status != B_OK) {
			printf("OpenPackageAction::FindAppToLaunch(): "
				"failed parse package contents (%s): %s\n",
				packagePath.Path(), strerror(status));
			return false;
		}
		
		return foundLinks.CountItems() > 0;
	}
示例#9
0
void
ScreenshotWindow::SetPackage(const PackageInfoRef& package)
{
	if (fPackage == package)
		return;

	fPackage = package;

	BString title = B_TRANSLATE("Screenshot");
	if (package.Get() != NULL) {
		title = package->Title();
		_DownloadScreenshot();
	}
	SetTitle(title);
}
示例#10
0
	virtual bool AcceptsPackage(const PackageInfoRef& package) const
	{
		if (package.Get() == NULL)
			return false;

		const CategoryList& categories = package->Categories();
		for (int i = categories.CountItems() - 1; i >= 0; i--) {
			const CategoryRef& category = categories.ItemAtFast(i);
			if (category.Get() == NULL)
				continue;
			if (category->Name() == fCategory)
				return true;
		}
		return false;
	}
示例#11
0
	virtual bool AcceptsPackage(const PackageInfoRef& package) const
	{
		if (package.Get() == NULL)
			return false;

		printf("TEST %s\n", package->Name().String());

		for (int32 i = 0; i < fPackageLists.CountItems(); i++) {
			if (fPackageLists.ItemAtFast(i)->Contains(package)) {
				printf("  contained in %" B_PRId32 "\n", i);
				return false;
			}
		}
		return true;
	}
示例#12
0
PackageInfoRef
PackageAction::FindPackageByName(const BString& name)
{
	Model* model = GetModel();
	const DepotList& depots = model->Depots();
	// TODO: optimize!
	for (int32 i = 0; i < depots.CountItems(); i++) {
		const DepotInfo& depot = depots.ItemAtFast(i);
		const PackageList& packages = depot.Packages();
		for (int32 j = 0; j < packages.CountItems(); j++) {
			PackageInfoRef info = packages.ItemAtFast(j);
			if (info->Name() == name)
				return info;
		}
	}

	return PackageInfoRef();
}
示例#13
0
void
PackageRow::UpdateState()
{
    if (fPackage.Get() == NULL)
        return;

    SetField(new BStringField(package_state_to_string(fPackage)),
             kStatusColumn);
}
示例#14
0
void
ScreenshotWindow::SetPackage(const PackageInfoRef& package)
{
	if (fPackage == package)
		return;

	fPackage = package;

	BString title = B_TRANSLATE("Screenshot");
	if (package.Get() != NULL) {
		title = package->Title();
		_DownloadScreenshot();
	}
	SetTitle(title);

	atomic_set(&fCurrentScreenshotIndex, 0);

	_UpdateToolBar();
}
示例#15
0
PackageActionList
PackageManager::GetPackageActions(PackageInfoRef package, Model* model)
{
	PackageActionList actionList;
	if (package->IsSystemPackage() || package->IsSystemDependency())
		return actionList;

	int32 state = package->State();
	if (state == ACTIVATED || state == INSTALLED) {
		actionList.Add(PackageActionRef(new UninstallPackageAction(
			package, model), true));
	} else {
		actionList.Add(PackageActionRef(new InstallPackageAction(package,
				model),	true));
	}
	// TODO: activation status

	return actionList;
}
示例#16
0
status_t
MainWindow::_PopulatePackageWorker(void* arg)
{
	MainWindow* window = reinterpret_cast<MainWindow*>(arg);

	while (acquire_sem(window->fPackageToPopulateSem) == B_OK) {
		PackageInfoRef package;
		{
			AutoLocker<BLocker> lock(&window->fPackageToPopulateLock);
			package = window->fPackageToPopulate;
		}

		if (package.Get() != NULL) {
			window->fModel.PopulatePackage(package,
				Model::POPULATE_USER_RATINGS | Model::POPULATE_SCREEN_SHOTS
					| Model::POPULATE_CHANGELOG);
		}
	}

	return 0;
}
示例#17
0
int32
PackageAction::InstallLocation(const PackageInfoRef& package)
{
	const PackageInstallationLocationSet& locations
		= package->InstallationLocations();

	// If the package is already installed, return its first installed location
	if (locations.size() != 0)
		return *locations.begin();

	return B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
}
示例#18
0
PackageRow::PackageRow(const PackageInfoRef& packageRef,
                       PackageListener* packageListener)
    :
    Inherited(ceilf(be_plain_font->Size() * 1.8f)),
    fPackage(packageRef),
    fPackageListener(packageListener)
{
    if (packageRef.Get() == NULL)
        return;

    PackageInfo& package = *packageRef.Get();

    // Package icon and title
    // NOTE: The icon BBitmap is referenced by the fPackage member.
    const BBitmap* icon = NULL;
    if (package.Icon().Get() != NULL)
        icon = package.Icon()->Bitmap(SharedBitmap::SIZE_16);
    SetField(new BBitmapStringField(icon, package.Title()), kTitleColumn);

    // Rating
    UpdateRating();

    // Description
    SetField(new BStringField(package.ShortDescription()), kDescriptionColumn);

    // Size
    // TODO: Store package size
    SetField(new BStringField("0 KiB"), kSizeColumn);

    // Status
    // TODO: Fetch info about installed/deactivated/uninstalled/...
    SetField(new BStringField(package_state_to_string(fPackage)),
             kStatusColumn);

    package.AddListener(fPackageListener);
}
示例#19
0
inline BString
package_state_to_string(PackageInfoRef ref)
{
    switch (ref->State()) {
    case NONE:
        return B_TRANSLATE(skPackageStateAvailable);
    case INSTALLED:
        return B_TRANSLATE(skPackageStateInactive);
    case ACTIVATED:
        return B_TRANSLATE(skPackageStateActive);
    case UNINSTALLED:
        return B_TRANSLATE(skPackageStateUninstalled);
    case DOWNLOADING:
    {
        BString data;
        data.SetToFormat("%3.2f%%", ref->DownloadProgress() * 100.0);
        return data;
    }
    case PENDING:
        return B_TRANSLATE(skPackageStatePending);
    }

    return B_TRANSLATE("Unknown");
}
示例#20
0
void
RatePackageWindow::SetPackage(const PackageInfoRef& package)
{
	BAutolock locker(this);
	if (!locker.IsLocked() || fWorkerThread >= 0)
		return;

	fPackage = package;

	BString windowTitle(B_TRANSLATE("Rate %Package%"));
	windowTitle.ReplaceAll("%Package%", package->Title());
	SetTitle(windowTitle);

	// See if the user already made a rating for this package,
	// pre-fill the UI with that rating. (When sending the rating, the
	// old one will be replaced.)
	thread_id thread = spawn_thread(&_QueryRatingThreadEntry,
		"Query rating", B_NORMAL_PRIORITY, this);
	if (thread >= 0)
		_SetWorkerThread(thread);
}
示例#21
0
PackageAction::PackageAction(int32 type, PackageInfoRef package, Model* model)
	:
	fPackage(package),
	fType(type),
	fModel(model)
{
	const PackageInstallationLocationSet& locations
		= package->InstallationLocations();

	int32 location = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
	// if the package is already installed, use its first installed location
	// to initialize the manager.
	// TODO: ideally if the package is installed at multiple locations,
	// the user should be able to pick which one to remove.
	if (locations.size() != 0)
		location = *locations.begin();

	// TODO: allow configuring the installation location
	fPackageManager = new(std::nothrow) PackageManager(
		(BPackageInstallationLocation)location);
}
示例#22
0
void
MainWindow::_RefreshPackageList()
{
	BPackageRoster roster;
	BStringList repositoryNames;

	status_t result = roster.GetRepositoryNames(repositoryNames);
	if (result != B_OK)
		return;

	DepotInfoMap depots;
	for (int32 i = 0; i < repositoryNames.CountStrings(); i++) {
		const BString& repoName = repositoryNames.StringAt(i);
		depots[repoName] = DepotInfo(repoName);
	}

	PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME);
	try {
		manager.Init(PackageManager::B_ADD_INSTALLED_REPOSITORIES
			| PackageManager::B_ADD_REMOTE_REPOSITORIES);
	} catch (BException ex) {
		BString message(B_TRANSLATE("An error occurred while "
			"initializing the package manager: %message%"));
		message.ReplaceFirst("%message%", ex.Message());
		_NotifyUser("Error", message.String());
		return;
	}

	BObjectList<BSolverPackage> packages;
	result = manager.Solver()->FindPackages("",
		BSolver::B_FIND_CASE_INSENSITIVE | BSolver::B_FIND_IN_NAME
			| BSolver::B_FIND_IN_SUMMARY | BSolver::B_FIND_IN_DESCRIPTION
			| BSolver::B_FIND_IN_PROVIDES,
		packages);
	if (result != B_OK) {
		// TODO: notify user
		return;
	}

	if (packages.IsEmpty())
		return;

	PackageInfoMap foundPackages;
		// if a given package is installed locally, we will potentially
		// get back multiple entries, one for each local installation
		// location, and one for each remote repository the package
		// is available in. The above map is used to ensure that in such
		// cases we consolidate the information, rather than displaying
		// duplicates
	PackageInfoMap remotePackages;
		// any package that we find in a remote repository goes in this map.
		// this is later used to discern which packages came from a local
		// installation only, as those must be handled a bit differently
		// upon uninstallation, since we'd no longer be able to pull them
		// down remotely.
	BStringList systemFlaggedPackages;
		// any packages flagged as a system package are added to this list.
		// such packages cannot be uninstalled, nor can any of their deps.
	PackageInfoMap systemInstalledPackages;
		// any packages installed in system are added to this list.
		// This is later used for dependency resolution of the actual
		// system packages in order to compute the list of protected
		// dependencies indicated above.

	BitmapRef defaultIcon(new(std::nothrow) SharedBitmap(
		"application/x-vnd.haiku-package"), true);

	for (int32 i = 0; i < packages.CountItems(); i++) {
		BSolverPackage* package = packages.ItemAt(i);
		const BPackageInfo& repoPackageInfo = package->Info();
		PackageInfoRef modelInfo;
		PackageInfoMap::iterator it = foundPackages.find(
			repoPackageInfo.Name());
		if (it != foundPackages.end())
			modelInfo.SetTo(it->second);
		else {
			// Add new package info
			BString publisherURL;
			if (repoPackageInfo.URLList().CountStrings() > 0)
				publisherURL = repoPackageInfo.URLList().StringAt(0);

			BString publisherName = repoPackageInfo.Vendor();
			const BStringList& rightsList = repoPackageInfo.CopyrightList();
			if (rightsList.CountStrings() > 0)
				publisherName = rightsList.StringAt(0);

			modelInfo.SetTo(new(std::nothrow) PackageInfo(
					repoPackageInfo.Name(),
					repoPackageInfo.Version().ToString(),
					PublisherInfo(BitmapRef(), publisherName,
					"", publisherURL), repoPackageInfo.Summary(),
					repoPackageInfo.Description(),
					repoPackageInfo.Flags()),
				true);

			if (modelInfo.Get() == NULL)
				return;

			foundPackages[repoPackageInfo.Name()] = modelInfo;
		}

		modelInfo->SetIcon(defaultIcon);
		modelInfo->AddListener(this);

		BSolverRepository* repository = package->Repository();
		if (dynamic_cast<BPackageManager::RemoteRepository*>(repository)
				!= NULL) {
			depots[repository->Name()].AddPackage(modelInfo);
			remotePackages[modelInfo->Title()] = 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 (modelInfo->IsSystemPackage())
			systemFlaggedPackages.Add(repoPackageInfo.FileName());
	}

	BAutolock lock(fModel.Lock());

	fModel.Clear();

	// filter remote packages from the found list
	// any packages remaining will be locally installed packages
	// that weren't acquired from a repository
	for (PackageInfoMap::iterator it = remotePackages.begin();
			it != remotePackages.end(); it++) {
		foundPackages.erase(it->first);
	}

	if (!foundPackages.empty()) {
		BString repoName = B_TRANSLATE("Local");
		depots[repoName] = DepotInfo(repoName);
		DepotInfoMap::iterator depot = depots.find(repoName);
		for (PackageInfoMap::iterator it = foundPackages.begin();
				it != foundPackages.end(); ++it) {
			depot->second.AddPackage(it->second);
		}
	}

	for (DepotInfoMap::iterator it = depots.begin(); it != depots.end(); it++) {
		fModel.AddDepot(it->second);
	}

	// start retrieving package icons and average ratings
	fModel.PopulateAllPackages();

	// compute the OS package dependencies
	try {
		// create the solver
		BSolver* solver;
		status_t error = BSolver::Create(solver);
		if (error != B_OK)
			throw BFatalErrorException(error, "Failed to create solver.");

		ObjectDeleter<BSolver> solverDeleter(solver);
		BPath systemPath;
		error = find_directory(B_SYSTEM_PACKAGES_DIRECTORY, &systemPath);
		if (error != B_OK) {
			throw BFatalErrorException(error,
				"Unable to retrieve system packages directory.");
		}

		// add the "installed" repository with the given packages
		BSolverRepository installedRepository;
		{
			BRepositoryBuilder installedRepositoryBuilder(installedRepository,
				"installed");
			for (int32 i = 0; i < systemFlaggedPackages.CountStrings(); i++) {
				BPath packagePath(systemPath);
				packagePath.Append(systemFlaggedPackages.StringAt(i));
				installedRepositoryBuilder.AddPackage(packagePath.Path());
			}
			installedRepositoryBuilder.AddToSolver(solver, true);
		}

		// add system repository
		BSolverRepository systemRepository;
		{
			BRepositoryBuilder systemRepositoryBuilder(systemRepository,
				"system");
			for (PackageInfoMap::iterator it = systemInstalledPackages.begin();
					it != systemInstalledPackages.end(); it++) {
				BPath packagePath(systemPath);
				packagePath.Append(it->first);
				systemRepositoryBuilder.AddPackage(packagePath.Path());
			}
			systemRepositoryBuilder.AddToSolver(solver, false);
		}

		// solve
		error = solver->VerifyInstallation();
		if (error != B_OK) {
			throw BFatalErrorException(error, "Failed to compute packages to "
				"install.");
		}

		BSolverResult solverResult;
		error = solver->GetResult(solverResult);
		if (error != B_OK) {
			throw BFatalErrorException(error, "Failed to retrieve system "
				"package dependency list.");
		}

		for (int32 i = 0; const BSolverResultElement* element
				= solverResult.ElementAt(i); i++) {
			BSolverPackage* package = element->Package();
			if (element->Type() == BSolverResultElement::B_TYPE_INSTALL) {
				PackageInfoMap::iterator it = systemInstalledPackages.find(
					package->Info().FileName());
				if (it != systemInstalledPackages.end())
					it->second->SetSystemDependency(true);
			}
		}
	} catch (BFatalErrorException ex) {
		printf("Fatal exception occurred while resolving system dependencies: "
			"%s, details: %s\n", strerror(ex.Error()), ex.Details().String());
	} catch (BNothingToDoException) {
		// do nothing
	} catch (BException ex) {
		printf("Exception occurred while resolving system dependencies: %s\n",
			ex.Message().String());
	} catch (...) {
		printf("Unknown exception occurred while resolving system "
			"dependencies.\n");
	}
}