/* * Copyright 2013-2014, Stephan Aßmus . * Copyright 2016-2024, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef MODEL_H #define MODEL_H #include #include #include "AbstractProcess.h" #include "DepotInfo.h" #include "LanguageRepository.h" #include "PackageFilterModel.h" #include "PackageIconTarRepository.h" #include "PackageInfo.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; }; typedef BReference ModelListenerRef; class PackageConsumer { public: virtual bool ConsumePackage( const PackageInfoRef& packageInfoRef, void* context) = 0; }; class Model : public PackageScreenshotRepositoryListener { public: Model(); virtual ~Model(); PackageFilterModel* PackageFilter(); PackageIconRepository& GetPackageIconRepository(); status_t InitPackageIconRepository(); PackageScreenshotRepository* GetPackageScreenshotRepository(); BLocker* Lock() { return &fLock; } void AddListener(const ModelListenerRef& listener); LanguageRef PreferredLanguage() const; void SetPreferredLanguage(LanguageRef value); LanguageRepository* Languages(); PackageInfoRef PackageForName(const BString& name); void MergeOrAddDepot(const DepotInfoRef& depot); bool HasDepot(const BString& name) const; int32 CountDepots() const; DepotInfoRef DepotAtIndex(int32 index) const; const DepotInfoRef DepotForName(const BString& name) const; bool HasAnyProminentPackages(); void Clear(); int32 CountCategories() const; CategoryRef CategoryByCode(BString& code) const; CategoryRef CategoryAtIndex(int32 index) const; void AddCategories( std::vector& values); int32 CountRatingStabilities() const; RatingStabilityRef RatingStabilityByCode(BString& code) const; RatingStabilityRef RatingStabilityAtIndex(int32 index) const; void AddRatingStabilities( std::vector& values); void SetStateForPackagesByName( BStringList& packageNames, PackageState state); void SetPackageListViewMode( package_list_view_mode mode); package_list_view_mode PackageListViewMode() const { return fPackageListViewMode; } void SetCanShareAnonymousUsageData(bool value); bool CanShareAnonymousUsageData() const { return fCanShareAnonymousUsageData; } bool CanPopulatePackage( const PackageInfoRef& package); void SetNickname(BString nickname); const BString& Nickname(); void SetCredentials(const BString& nickname, const BString& passwordClear, bool storePassword); WebAppInterface* GetWebAppInterface() { return &fWebAppInterface; } // PackageScreenshotRepositoryListener virtual void ScreenshotCached(const ScreenshotCoordinate& coord); private: void _AddCategory(const CategoryRef& category); void _AddRatingStability( const RatingStabilityRef& value); void _MaybeLogJsonRpcError( const BMessage &responsePayload, const char *sourceDescription) const; void _NotifyAuthorizationChanged(); void _NotifyCategoryListChanged(); private: BLocker fLock; LanguageRef fPreferredLanguage; std::vector fDepots; std::vector fCategories; std::vector fRatingStabilities; BStringList fPopulatedPackageNames; package_list_view_mode fPackageListViewMode; bool fCanShareAnonymousUsageData; WebAppInterface fWebAppInterface; PackageFilterModel* fPackageFilterModel; LanguageRepository* fLanguageRepository; PackageIconTarRepository fPackageIconRepository; PackageScreenshotRepository* fPackageScreenshotRepository; std::vector fListeners; }; #endif // PACKAGE_INFO_H