HaikuDepot: notify work status from main window
[haiku.git] / src / apps / haikudepot / model / Model.h
bloba4baa39841928bc5ca9fe6f4fd9368c476ad761c
1 /*
2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3 * Copyright 2016-2017, Andrew Lindesay <apl@lindesay.co.nz>.
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6 #ifndef MODEL_H
7 #define MODEL_H
9 #include <FindDirectory.h>
10 #include <Locker.h>
12 #include "AbstractServerProcess.h"
13 #include "LocalIconStore.h"
14 #include "BulkLoadContext.h"
15 #include "PackageInfo.h"
16 #include "WebAppInterface.h"
19 class BFile;
20 class BMessage;
21 class BPath;
24 class PackageFilter : public BReferenceable {
25 public:
26 virtual ~PackageFilter();
28 virtual bool AcceptsPackage(
29 const PackageInfoRef& package) const = 0;
32 typedef BReference<PackageFilter> PackageFilterRef;
35 class ModelListener : public BReferenceable {
36 public:
37 virtual ~ModelListener();
39 virtual void AuthorizationChanged() = 0;
43 class DepotMapper {
44 public:
45 virtual DepotInfo MapDepot(const DepotInfo& depot,
46 void* context) = 0;
50 class PackageConsumer {
51 public:
52 virtual bool ConsumePackage(
53 const PackageInfoRef& packageInfoRef,
54 void* context) = 0;
58 typedef BReference<ModelListener> ModelListenerRef;
59 typedef List<ModelListenerRef, false> ModelListenerList;
62 class Model {
63 public:
64 Model();
65 virtual ~Model();
67 BLocker* Lock()
68 { return &fLock; }
70 bool AddListener(const ModelListenerRef& listener);
72 // !Returns new PackageInfoList from current parameters
73 PackageList CreatePackageList() const;
75 bool MatchesFilter(
76 const PackageInfoRef& package) const;
78 bool AddDepot(const DepotInfo& depot);
79 bool HasDepot(const BString& name) const;
80 const DepotList& Depots() const
81 { return fDepots; }
82 const DepotInfo* DepotForName(const BString& name) const;
83 bool SyncDepot(const DepotInfo& depot);
85 void Clear();
87 // Access to global categories
88 const CategoryRef& CategoryAudio() const
89 { return fCategoryAudio; }
90 const CategoryRef& CategoryBusiness() const
91 { return fCategoryBusiness; }
92 const CategoryRef& CategoryDevelopment() const
93 { return fCategoryDevelopment; }
94 const CategoryRef& CategoryEducation() const
95 { return fCategoryEducation; }
96 const CategoryRef& CategoryInternetAndNetwork() const
97 { return fCategoryInternetAndNetwork; }
98 const CategoryRef& CategoryGames() const
99 { return fCategoryGames; }
100 const CategoryRef& CategoryGraphics() const
101 { return fCategoryGraphics; }
102 const CategoryRef& CategoryProductivity() const
103 { return fCategoryProductivity; }
104 const CategoryRef& CategoryScienceAndMathematics() const
105 { return fCategoryScienceAndMathematics; }
106 const CategoryRef& CategorySystemAndUtilities() const
107 { return fCategorySystemAndUtilities; }
108 const CategoryRef& CategoryVideo() const
109 { return fCategoryVideo; }
111 const CategoryList& Categories() const
112 { return fCategories; }
114 void SetPackageState(
115 const PackageInfoRef& package,
116 PackageState state);
118 // Configure PackageFilters
119 void SetCategory(const BString& category);
120 BString Category() const;
121 void SetDepot(const BString& depot);
122 BString Depot() const;
123 void SetSearchTerms(const BString& searchTerms);
124 BString SearchTerms() const;
126 void SetShowFeaturedPackages(bool show);
127 bool ShowFeaturedPackages() const
128 { return fShowFeaturedPackages; }
129 void SetShowAvailablePackages(bool show);
130 bool ShowAvailablePackages() const
131 { return fShowAvailablePackages; }
132 void SetShowInstalledPackages(bool show);
133 bool ShowInstalledPackages() const
134 { return fShowInstalledPackages; }
135 void SetShowSourcePackages(bool show);
136 bool ShowSourcePackages() const
137 { return fShowSourcePackages; }
138 void SetShowDevelopPackages(bool show);
139 bool ShowDevelopPackages() const
140 { return fShowDevelopPackages; }
142 // Retrieve package information
143 static const uint32 POPULATE_CACHED_RATING = 1 << 0;
144 static const uint32 POPULATE_CACHED_ICON = 1 << 1;
145 static const uint32 POPULATE_USER_RATINGS = 1 << 2;
146 static const uint32 POPULATE_SCREEN_SHOTS = 1 << 3;
147 static const uint32 POPULATE_CHANGELOG = 1 << 4;
148 static const uint32 POPULATE_CATEGORIES = 1 << 5;
149 static const uint32 POPULATE_FORCE = 1 << 6;
151 void PopulatePackage(const PackageInfoRef& package,
152 uint32 flags);
154 const StringList& SupportedLanguages() const
155 { return fSupportedLanguages; }
157 const BString& PreferredLanguage() const
158 { return fPreferredLanguage; }
160 void SetUsername(BString username);
161 const BString& Username() const;
162 void SetAuthorization(const BString& username,
163 const BString& password,
164 bool storePassword);
166 const WebAppInterface& GetWebAppInterface() const
167 { return fWebAppInterface; }
169 void ReplaceDepotByUrl(
170 const BString& url,
171 DepotMapper* depotMapper,
172 void* context);
174 void ForAllDepots(
175 void (*func)(const DepotInfo& depot,
176 void* context),
177 void* context);
179 void ForAllPackages(PackageConsumer* packageConsumer,
180 void* context);
182 void ForPackageByNameInDepot(
183 const BString& depotName,
184 const BString& packageName,
185 PackageConsumer* packageConsumer,
186 void* context);
188 status_t IconStoragePath(BPath& path) const;
189 status_t DumpExportRepositoryDataPath(BPath& path) const;
190 status_t DumpExportPkgDataPath(BPath& path,
191 const BString& repositorySourceCode) const;
193 void LogDepotsWithNoWebAppRepositoryCode() const;
195 private:
196 void _UpdateIsFeaturedFilter();
198 static int32 _PopulateAllPackagesEntry(void* cookie);
200 void _PopulatePackageScreenshot(
201 const PackageInfoRef& package,
202 const ScreenshotInfo& info,
203 int32 scaledWidth, bool fromCacheOnly);
205 bool _GetCacheFile(BPath& path, BFile& file,
206 directory_which directory,
207 const char* relativeLocation,
208 const char* fileName,
209 uint32 openMode) const;
210 bool _GetCacheFile(BPath& path, BFile& file,
211 directory_which directory,
212 const char* relativeLocation,
213 const char* fileName,
214 bool ignoreAge, time_t maxAge) const;
216 void _NotifyAuthorizationChanged();
218 private:
219 BLocker fLock;
221 DepotList fDepots;
223 CategoryRef fCategoryAudio;
224 CategoryRef fCategoryBusiness;
225 CategoryRef fCategoryDevelopment;
226 CategoryRef fCategoryEducation;
227 CategoryRef fCategoryGames;
228 CategoryRef fCategoryGraphics;
229 CategoryRef fCategoryInternetAndNetwork;
230 CategoryRef fCategoryProductivity;
231 CategoryRef fCategoryScienceAndMathematics;
232 CategoryRef fCategorySystemAndUtilities;
233 CategoryRef fCategoryVideo;
234 // TODO: Dynamic categories retrieved from web-app
236 CategoryList fCategories;
238 PackageList fInstalledPackages;
239 PackageList fActivatedPackages;
240 PackageList fUninstalledPackages;
241 PackageList fDownloadingPackages;
242 PackageList fUpdateablePackages;
243 PackageList fPopulatedPackages;
245 PackageFilterRef fCategoryFilter;
246 BString fDepotFilter;
247 PackageFilterRef fSearchTermsFilter;
248 PackageFilterRef fIsFeaturedFilter;
250 bool fShowFeaturedPackages;
251 bool fShowAvailablePackages;
252 bool fShowInstalledPackages;
253 bool fShowSourcePackages;
254 bool fShowDevelopPackages;
256 StringList fSupportedLanguages;
257 BString fPreferredLanguage;
259 WebAppInterface fWebAppInterface;
261 ModelListenerList fListeners;
265 #endif // PACKAGE_INFO_H