/* * Copyright 2013-2014, Stephan Aßmus . * Copyright 2016-2025, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef MODEL_H #define MODEL_H #include #include #include #include "AbstractProcess.h" #include "DepotInfo.h" #include "PackageFilter.h" #include "PackageFilterSpecification.h" #include "PackageIconDefaultRepository.h" #include "PackageInfo.h" #include "PackageInfoListener.h" #include "PackageScreenshotRepository.h" #include "RatingStability.h" #include "ScreenshotCoordinate.h" #include "WebAppInterface.h" class BFile; class BMessage; class BPath; typedef enum package_list_view_mode { PROMINENT, ALL } package_list_view_mode; class ModelListener : public BReferenceable { public: virtual ~ModelListener(); virtual void AuthorizationChanged() = 0; virtual void CategoryListChanged() = 0; virtual void ScreenshotCached(const ScreenshotCoordinate& coordinate) = 0; virtual void IconsChanged() = 0; virtual void PackageFilterChanged() = 0; }; typedef BReference ModelListenerRef; class PackageConsumer { public: virtual bool ConsumePackage( const PackageInfoRef& packageInfoRef, void* context) = 0; }; /*! This class conveys summary information about all the packages that are stored in the model. */ class PackagesSummary { public: PackagesSummary(); PackagesSummary( bool anyProminentPackages, bool anyNativeDesktop, bool anyDesktop); virtual ~PackagesSummary(); PackagesSummary& operator=(const PackagesSummary& other); bool HasAnyProminentPackages() const; bool HasAnyNativeDesktop() const; bool HasAnyDesktop() const; private: bool fAnyProminentPackages; bool fAnyNativeDesktop; bool fAnyDesktop; }; class Model : public PackageScreenshotRepositoryListener { public: Model(); virtual ~Model(); void Clear(); void AddListener(const ModelListenerRef& listener); void AddPackageListener(const PackageInfoListenerRef& packageListener); PackageScreenshotRepository* GetPackageScreenshotRepository(); void SetFilterSpecification(const PackageFilterSpecificationRef& value); const PackageFilterSpecificationRef FilterSpecification() const; PackageFilterRef Filter() const; PackageIconRepositoryRef IconRepository(); void SetIconRepository(PackageIconRepositoryRef value); const std::vector Packages() const; const std::vector FilteredPackages() const; void AddPackage(const PackageInfoRef& package); void AddPackages(const std::vector& packages); void AddPackagesWithChange(const std::vector& packages, uint32 changesMask); const PackageInfoRef PackageForName(const BString& name) const; bool HasPackage(const BString& packageName) const; const PackagesSummary GeneratePackagesSummary() const; const LanguageRef PreferredLanguage() const; void SetPreferredLanguage(const LanguageRef& value); const std::vector Languages() const; void SetLanguagesAndPreferred(const std::vector& value, const LanguageRef& preferred); void SetDepots(const DepotInfoRef& depot); void SetDepots(const std::vector& depots); const std::vector Depots() const; const DepotInfoRef DepotForName(const BString& name) const; const DepotInfoRef DepotForIdentifier(const BString& identifier) const; const std::vector Categories() const; void SetCategories(const std::vector value); bool HasCategories(); const std::vector RatingStabilities() const; void SetRatingStabilities(const std::vector value); void SetPackageListViewMode( package_list_view_mode mode); package_list_view_mode PackageListViewMode() const; void SetCanShareAnonymousUsageData(bool value); bool CanShareAnonymousUsageData() const; bool CanPopulatePackage(const PackageInfoRef& package); void SetCredentials(const UserCredentials& credentials); const BString& Nickname(); WebAppInterfaceRef WebApp(); // PackageScreenshotRepositoryListener virtual void ScreenshotCached(const ScreenshotCoordinate& coord); private: uint32 _ChangeDiff(const PackageInfoRef& package); void _AddRatingStability( const RatingStabilityRef& value); void _MaybeLogJsonRpcError( const BMessage &responsePayload, const char *sourceDescription) const; void _NotifyPackageFilterChanged(); void _NotifyIconsChanged(); void _NotifyAuthorizationChanged(); void _NotifyCategoryListChanged(); void _NotifyPackageChange(const PackageChangeEvent& event); void _NotifyPackageChanges(const PackageChangeEvents& events); private: mutable BLocker fLock; LanguageRef fPreferredLanguage; std::map fDepots; std::map fPackages; std::vector fCategories; std::vector fRatingStabilities; package_list_view_mode fPackageListViewMode; bool fCanShareAnonymousUsageData; WebAppInterfaceRef fWebApp; PackageFilterSpecificationRef fFilterSpecification; PackageFilterRef fFilter; std::vector fLanguages; PackageIconRepositoryRef fIconRepository; PackageScreenshotRepository* fPackageScreenshotRepository; std::vector fListeners; std::vector fPackageListeners; }; #endif // MODEL_H