HaikuDepot: notify work status from main window
[haiku.git] / src / apps / haikudepot / model / PackageInfo.h
blob99d508a2e71acdb0f0f5ad3bc8bc20b9c256b256
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 PACKAGE_INFO_H
7 #define PACKAGE_INFO_H
10 #include <set>
12 #include <Referenceable.h>
13 #include <package/PackageInfo.h>
15 #include "List.h"
16 #include "PackageInfoListener.h"
17 #include "SharedBitmap.h"
20 class BPath;
23 class UserInfo {
24 public:
25 UserInfo();
26 UserInfo(const BString& nickName);
27 UserInfo(const BitmapRef& avatar,
28 const BString& nickName);
29 UserInfo(const UserInfo& other);
31 UserInfo& operator=(const UserInfo& other);
32 bool operator==(const UserInfo& other) const;
33 bool operator!=(const UserInfo& other) const;
35 const BitmapRef& Avatar() const
36 { return fAvatar; }
37 const BString& NickName() const
38 { return fNickName; }
40 private:
41 BitmapRef fAvatar;
42 BString fNickName;
46 class UserRating {
47 public:
48 UserRating();
49 UserRating(const UserInfo& userInfo,
50 float rating,
51 const BString& comment,
52 const BString& language,
53 const BString& packageVersion,
54 int32 upVotes, int32 downVotes);
55 UserRating(const UserRating& other);
57 UserRating& operator=(const UserRating& other);
58 bool operator==(const UserRating& other) const;
59 bool operator!=(const UserRating& other) const;
61 const UserInfo& User() const
62 { return fUserInfo; }
63 const BString& Comment() const
64 { return fComment; }
65 const BString& Language() const
66 { return fLanguage; }
67 const float Rating() const
68 { return fRating; }
69 const BString& PackageVersion() const
70 { return fPackageVersion; }
72 int32 UpVotes() const
73 { return fUpVotes; }
74 int32 DownVotes() const
75 { return fDownVotes; }
76 private:
77 UserInfo fUserInfo;
78 float fRating;
79 BString fComment;
80 BString fLanguage;
81 BString fPackageVersion;
82 int32 fUpVotes;
83 int32 fDownVotes;
87 typedef List<UserRating, false> UserRatingList;
90 class RatingSummary {
91 public:
92 RatingSummary();
93 RatingSummary(const RatingSummary& other);
95 RatingSummary& operator=(const RatingSummary& other);
96 bool operator==(const RatingSummary& other) const;
97 bool operator!=(const RatingSummary& other) const;
99 public:
100 float averageRating;
101 int ratingCount;
103 int ratingCountByStar[5];
107 class StabilityRating {
108 public:
109 StabilityRating();
110 StabilityRating(
111 const BString& label,
112 const BString& name);
113 StabilityRating(const StabilityRating& other);
115 StabilityRating& operator=(const StabilityRating& other);
116 bool operator==(const StabilityRating& other) const;
117 bool operator!=(const StabilityRating& other) const;
119 const BString& Label() const
120 { return fLabel; }
121 const BString& Name() const
122 { return fName; }
123 private:
124 BString fLabel;
125 BString fName;
129 typedef List<StabilityRating, false> StabilityRatingList;
132 class PublisherInfo {
133 public:
134 PublisherInfo();
135 PublisherInfo(const BitmapRef& logo,
136 const BString& name,
137 const BString& email,
138 const BString& website);
139 PublisherInfo(const PublisherInfo& other);
141 PublisherInfo& operator=(const PublisherInfo& other);
142 bool operator==(const PublisherInfo& other) const;
143 bool operator!=(const PublisherInfo& other) const;
145 const BitmapRef& Logo() const
146 { return fLogo; }
147 const BString& Name() const
148 { return fName; }
149 const BString& Email() const
150 { return fEmail; }
151 const BString& Website() const
152 { return fWebsite; }
154 private:
155 BitmapRef fLogo;
156 BString fName;
157 BString fEmail;
158 BString fWebsite;
162 class PackageCategory : public BReferenceable {
163 public:
164 PackageCategory();
165 PackageCategory(const BitmapRef& icon,
166 const BString& label,
167 const BString& name);
168 PackageCategory(const PackageCategory& other);
170 PackageCategory& operator=(const PackageCategory& other);
171 bool operator==(const PackageCategory& other) const;
172 bool operator!=(const PackageCategory& other) const;
174 const BitmapRef& Icon() const
175 { return fIcon; }
176 const BString& Label() const
177 { return fLabel; }
178 const BString& Name() const
179 { return fName; }
180 private:
181 BitmapRef fIcon;
182 BString fLabel;
183 BString fName;
187 typedef BReference<PackageCategory> CategoryRef;
188 typedef List<CategoryRef, false> CategoryList;
191 class ScreenshotInfo {
192 public:
193 ScreenshotInfo();
194 ScreenshotInfo(const BString& code,
195 int32 width, int32 height, int32 dataSize);
196 ScreenshotInfo(const ScreenshotInfo& other);
198 ScreenshotInfo& operator=(const ScreenshotInfo& other);
199 bool operator==(const ScreenshotInfo& other) const;
200 bool operator!=(const ScreenshotInfo& other) const;
202 const BString& Code() const
203 { return fCode; }
204 int32 Width() const
205 { return fWidth; }
206 int32 Height() const
207 { return fHeight; }
208 int32 DataSize() const
209 { return fDataSize; }
211 private:
212 BString fCode;
213 int32 fWidth;
214 int32 fHeight;
215 int32 fDataSize;
219 typedef List<ScreenshotInfo, false, 2> ScreenshotInfoList;
222 typedef List<PackageInfoListenerRef, false, 2> PackageListenerList;
223 typedef std::set<int32> PackageInstallationLocationSet;
226 enum PackageState {
227 NONE = 0,
228 INSTALLED = 1,
229 DOWNLOADING = 2,
230 ACTIVATED = 3,
231 UNINSTALLED = 4,
232 PENDING = 5,
236 using BPackageKit::BPackageInfo;
237 using BPackageKit::BPackageVersion;
240 class PackageInfo : public BReferenceable {
241 public:
242 PackageInfo();
243 PackageInfo(const BPackageInfo& info);
244 PackageInfo(
245 const BString& name,
246 const BPackageVersion& version,
247 const PublisherInfo& publisher,
248 const BString& shortDescription,
249 const BString& fullDescription,
250 int32 packageFlags,
251 const char* architecture);
252 PackageInfo(const PackageInfo& other);
254 PackageInfo& operator=(const PackageInfo& other);
255 bool operator==(const PackageInfo& other) const;
256 bool operator!=(const PackageInfo& other) const;
258 const BString& Name() const
259 { return fName; }
260 void SetTitle(const BString& title);
261 const BString& Title() const;
262 const BPackageVersion& Version() const
263 { return fVersion; }
264 void SetShortDescription(const BString& description);
265 const BString& ShortDescription() const
266 { return fShortDescription; }
267 void SetFullDescription(const BString& description);
268 const BString& FullDescription() const
269 { return fFullDescription; }
270 const PublisherInfo& Publisher() const
271 { return fPublisher; }
273 void SetIcon(const BitmapRef& icon);
274 const BitmapRef& Icon() const
275 { return fIcon; }
276 void SetChangelog(const BString& changelog);
277 const BString& Changelog() const
278 { return fChangelog; }
280 int32 Flags() const
281 { return fFlags; }
282 bool IsSystemPackage() const;
284 bool IsSystemDependency() const
285 { return fSystemDependency; }
286 void SetSystemDependency(bool isDependency);
288 const BString Architecture() const
289 { return fArchitecture; }
291 PackageState State() const
292 { return fState; }
293 void SetState(PackageState state);
295 const PackageInstallationLocationSet&
296 InstallationLocations() const
297 { return fInstallationLocations; }
298 void AddInstallationLocation(int32 location);
300 float DownloadProgress() const
301 { return fDownloadProgress; }
302 void SetDownloadProgress(float progress);
304 void SetLocalFilePath(const char* path);
305 const BString& LocalFilePath() const
306 { return fLocalFilePath; }
307 bool IsLocalFile() const;
308 const BString& FileName() const
309 { return fFileName; }
311 void ClearCategories();
312 bool AddCategory(const CategoryRef& category);
313 const CategoryList& Categories() const
314 { return fCategories; }
316 void ClearUserRatings();
317 bool AddUserRating(const UserRating& rating);
318 const UserRatingList& UserRatings() const
319 { return fUserRatings; }
320 void SetRatingSummary(const RatingSummary& summary);
321 RatingSummary CalculateRatingSummary() const;
323 void SetProminence(float prominence);
324 float Prominence() const
325 { return fProminence; }
326 bool HasProminence() const
327 { return fProminence != 0.0f; }
328 bool IsProminent() const;
330 void ClearScreenshotInfos();
331 bool AddScreenshotInfo(const ScreenshotInfo& info);
332 const ScreenshotInfoList& ScreenshotInfos() const
333 { return fScreenshotInfos; }
335 void ClearScreenshots();
336 bool AddScreenshot(const BitmapRef& screenshot);
337 const BitmapList& Screenshots() const
338 { return fScreenshots; }
340 void SetSize(int64 size);
341 int64 Size() const
342 { return fSize; }
344 void SetDepotName(const BString& depotName);
345 const BString& DepotName() const
346 { return fDepotName; }
348 bool AddListener(
349 const PackageInfoListenerRef& listener);
350 void RemoveListener(
351 const PackageInfoListenerRef& listener);
353 static void CleanupDefaultIcon();
355 private:
356 void _NotifyListeners(uint32 changes);
358 private:
359 BitmapRef fIcon;
360 BString fName;
361 BString fTitle;
362 BPackageVersion fVersion;
363 PublisherInfo fPublisher;
364 BString fShortDescription;
365 BString fFullDescription;
366 BString fChangelog;
367 CategoryList fCategories;
368 UserRatingList fUserRatings;
369 RatingSummary fCachedRatingSummary;
370 float fProminence;
371 ScreenshotInfoList fScreenshotInfos;
372 BitmapList fScreenshots;
373 PackageState fState;
374 PackageInstallationLocationSet
375 fInstallationLocations;
376 float fDownloadProgress;
377 PackageListenerList fListeners;
378 int32 fFlags;
379 bool fSystemDependency;
380 BString fArchitecture;
381 BString fLocalFilePath;
382 BString fFileName;
383 int64 fSize;
384 BString fDepotName;
386 static BitmapRef sDefaultIcon;
390 typedef BReference<PackageInfo> PackageInfoRef;
393 typedef List<PackageInfoRef, false> PackageList;
396 class DepotInfo {
397 public:
398 DepotInfo();
399 DepotInfo(const BString& name);
400 DepotInfo(const DepotInfo& other);
402 DepotInfo& operator=(const DepotInfo& other);
403 bool operator==(const DepotInfo& other) const;
404 bool operator!=(const DepotInfo& other) const;
406 const BString& Name() const
407 { return fName; }
409 const PackageList& Packages() const
410 { return fPackages; }
412 bool AddPackage(const PackageInfoRef& package);
414 int32 PackageIndexByName(const BString& packageName);
416 void SyncPackages(const PackageList& packages);
418 void SetBaseURL(const BString& baseURL);
419 const BString& BaseURL() const
420 { return fBaseURL; }
422 void SetWebAppRepositoryCode(const BString& code);
423 const BString& WebAppRepositoryCode() const
424 { return fWebAppRepositoryCode; }
426 void SetWebAppRepositorySourceCode(
427 const BString& code);
428 const BString& WebAppRepositorySourceCode() const
429 { return fWebAppRepositorySourceCode; }
431 private:
432 BString fName;
433 PackageList fPackages;
434 BString fWebAppRepositoryCode;
435 BString fWebAppRepositorySourceCode;
436 BString fBaseURL;
440 typedef List<DepotInfo, false> DepotList;
443 typedef List<BString, false> StringList;
446 #endif // PACKAGE_INFO_H