1/*
2 * Copyright 2013-2014, Stephan A��mus <superstippi@gmx.de>.
3 * Copyright 2016-2019, 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
8
9
10#include <set>
11
12#include <Language.h>
13#include <Referenceable.h>
14#include <package/PackageInfo.h>
15
16#include "List.h"
17#include "PackageInfoListener.h"
18#include "SharedBitmap.h"
19
20
21class BPath;
22
23
24/*! This class represents a language that is supported by the Haiku
25    Depot Server system.  This may differ from the set of languages
26    that are supported in the platform itself.
27*/
28
29class Language : public BReferenceable, public BLanguage {
30public:
31								Language(const char* language,
32									const BString& serverName,
33									bool isPopular);
34								Language(const Language& other);
35
36			status_t			GetName(BString& name,
37									const BLanguage* displayLanguage = NULL
38									) const;
39			bool				IsPopular() const
40									{ return fIsPopular; }
41
42private:
43			BString				fServerName;
44			bool				fIsPopular;
45};
46
47
48class UserInfo {
49public:
50								UserInfo();
51								UserInfo(const BString& nickName);
52								UserInfo(const UserInfo& other);
53
54			UserInfo&			operator=(const UserInfo& other);
55			bool				operator==(const UserInfo& other) const;
56			bool				operator!=(const UserInfo& other) const;
57
58			const BString&		NickName() const
59									{ return fNickName; }
60
61private:
62			BString				fNickName;
63};
64
65
66class UserRating {
67public:
68								UserRating();
69								UserRating(const UserInfo& userInfo,
70									float rating,
71									const BString& comment,
72									const BString& language,
73									const BString& packageVersion,
74									uint64 createTimestamp);
75								UserRating(const UserRating& other);
76
77			UserRating&			operator=(const UserRating& other);
78			bool				operator==(const UserRating& other) const;
79			bool				operator!=(const UserRating& other) const;
80
81			const UserInfo&		User() const
82									{ return fUserInfo; }
83			const BString&		Comment() const
84									{ return fComment; }
85			const BString&		Language() const
86									{ return fLanguage; }
87			const float			Rating() const
88									{ return fRating; }
89			const BString&		PackageVersion() const
90									{ return fPackageVersion; }
91			const uint64		CreateTimestamp() const
92									{ return fCreateTimestamp; }
93private:
94			UserInfo			fUserInfo;
95			float				fRating;
96			BString				fComment;
97			BString				fLanguage;
98			BString				fPackageVersion;
99			uint64				fCreateTimestamp;
100				// milliseconds since epoc
101};
102
103
104typedef List<UserRating, false> UserRatingList;
105
106
107class RatingSummary {
108public:
109								RatingSummary();
110								RatingSummary(const RatingSummary& other);
111
112			RatingSummary&		operator=(const RatingSummary& other);
113			bool				operator==(const RatingSummary& other) const;
114			bool				operator!=(const RatingSummary& other) const;
115
116public:
117			float				averageRating;
118			int					ratingCount;
119
120			int					ratingCountByStar[5];
121};
122
123
124class StabilityRating {
125public:
126								StabilityRating();
127								StabilityRating(
128									const BString& label,
129									const BString& name);
130								StabilityRating(const StabilityRating& other);
131
132			StabilityRating&	operator=(const StabilityRating& other);
133			bool				operator==(const StabilityRating& other) const;
134			bool				operator!=(const StabilityRating& other) const;
135
136			const BString&		Label() const
137									{ return fLabel; }
138			const BString&		Name() const
139									{ return fName; }
140private:
141			BString				fLabel;
142			BString				fName;
143};
144
145
146typedef List<StabilityRating, false> StabilityRatingList;
147
148
149class PublisherInfo {
150public:
151								PublisherInfo();
152								PublisherInfo(const BitmapRef& logo,
153									const BString& name,
154									const BString& email,
155									const BString& website);
156								PublisherInfo(const PublisherInfo& other);
157
158			PublisherInfo&		operator=(const PublisherInfo& other);
159			bool				operator==(const PublisherInfo& other) const;
160			bool				operator!=(const PublisherInfo& other) const;
161
162			const BitmapRef&	Logo() const
163									{ return fLogo; }
164			const BString&		Name() const
165									{ return fName; }
166			const BString&		Email() const
167									{ return fEmail; }
168			const BString&		Website() const
169									{ return fWebsite; }
170
171private:
172			BitmapRef			fLogo;
173			BString				fName;
174			BString				fEmail;
175			BString				fWebsite;
176};
177
178
179class PackageCategory : public BReferenceable {
180public:
181								PackageCategory();
182								PackageCategory(const BString& code,
183									const BString& name);
184								PackageCategory(const PackageCategory& other);
185
186			PackageCategory&	operator=(const PackageCategory& other);
187			bool				operator==(const PackageCategory& other) const;
188			bool				operator!=(const PackageCategory& other) const;
189
190			const BString&		Code() const
191									{ return fCode; }
192			const BString&		Name() const
193									{ return fName; }
194private:
195			BString				fCode;
196			BString				fName;
197};
198
199
200typedef BReference<PackageCategory> CategoryRef;
201typedef List<CategoryRef, false> CategoryList;
202
203
204class ScreenshotInfo {
205public:
206								ScreenshotInfo();
207								ScreenshotInfo(const BString& code,
208									int32 width, int32 height, int32 dataSize);
209								ScreenshotInfo(const ScreenshotInfo& other);
210
211			ScreenshotInfo&		operator=(const ScreenshotInfo& other);
212			bool				operator==(const ScreenshotInfo& other) const;
213			bool				operator!=(const ScreenshotInfo& other) const;
214
215			const BString&		Code() const
216									{ return fCode; }
217			int32				Width() const
218									{ return fWidth; }
219			int32				Height() const
220									{ return fHeight; }
221			int32				DataSize() const
222									{ return fDataSize; }
223
224private:
225			BString				fCode;
226			int32				fWidth;
227			int32				fHeight;
228			int32				fDataSize;
229};
230
231
232typedef List<ScreenshotInfo, false, 2> ScreenshotInfoList;
233
234
235typedef List<PackageInfoListenerRef, false, 2> PackageListenerList;
236typedef std::set<int32> PackageInstallationLocationSet;
237
238
239enum PackageState {
240	NONE		= 0,
241	INSTALLED	= 1,
242	DOWNLOADING	= 2,
243	ACTIVATED	= 3,
244	UNINSTALLED	= 4,
245	PENDING		= 5,
246};
247
248
249using BPackageKit::BPackageInfo;
250using BPackageKit::BPackageVersion;
251
252
253class PackageInfo : public BReferenceable {
254public:
255								PackageInfo();
256								PackageInfo(const BPackageInfo& info);
257								PackageInfo(
258									const BString& name,
259									const BPackageVersion& version,
260									const PublisherInfo& publisher,
261									const BString& shortDescription,
262									const BString& fullDescription,
263									int32 packageFlags,
264									const char* architecture);
265								PackageInfo(const PackageInfo& other);
266
267			PackageInfo&		operator=(const PackageInfo& other);
268			bool				operator==(const PackageInfo& other) const;
269			bool				operator!=(const PackageInfo& other) const;
270
271			const BString&		Name() const
272									{ return fName; }
273			void				SetTitle(const BString& title);
274			const BString&		Title() const;
275			const BPackageVersion& Version() const
276									{ return fVersion; }
277			void				SetShortDescription(const BString& description);
278			const BString&		ShortDescription() const
279									{ return fShortDescription; }
280			void				SetFullDescription(const BString& description);
281			const BString&		FullDescription() const
282									{ return fFullDescription; }
283			const PublisherInfo& Publisher() const
284									{ return fPublisher; }
285
286			void				SetIcon(const BitmapRef& icon);
287			const BitmapRef&	Icon() const
288									{ return fIcon; }
289			void				SetChangelog(const BString& changelog);
290			const BString&		Changelog() const
291									{ return fChangelog; }
292
293			int32				Flags() const
294									{ return fFlags; }
295			bool				IsSystemPackage() const;
296
297			bool				IsSystemDependency() const
298									{ return fSystemDependency; }
299			void				SetSystemDependency(bool isDependency);
300
301			const BString		Architecture() const
302									{ return fArchitecture; }
303
304			PackageState		State() const
305									{ return fState; }
306			void				SetState(PackageState state);
307
308			const PackageInstallationLocationSet&
309								InstallationLocations() const
310									{ return fInstallationLocations; }
311			void				AddInstallationLocation(int32 location);
312
313			float				DownloadProgress() const
314									{ return fDownloadProgress; }
315			void				SetDownloadProgress(float progress);
316
317			void				SetLocalFilePath(const char* path);
318			const BString&		LocalFilePath() const
319									{ return fLocalFilePath; }
320			bool				IsLocalFile() const;
321			const BString&		FileName() const
322									{ return fFileName; }
323
324			void				ClearCategories();
325			bool				AddCategory(const CategoryRef& category);
326			const CategoryList&	Categories() const
327									{ return fCategories; }
328
329			void				ClearUserRatings();
330			bool				AddUserRating(const UserRating& rating);
331			const UserRatingList& UserRatings() const
332									{ return fUserRatings; }
333			void				SetRatingSummary(const RatingSummary& summary);
334			RatingSummary		CalculateRatingSummary() const;
335
336			void				SetProminence(float prominence);
337			float				Prominence() const
338									{ return fProminence; }
339			bool				HasProminence() const
340									{ return fProminence != 0.0f; }
341			bool				IsProminent() const;
342
343			void				ClearScreenshotInfos();
344			bool				AddScreenshotInfo(const ScreenshotInfo& info);
345			const ScreenshotInfoList& ScreenshotInfos() const
346									{ return fScreenshotInfos; }
347
348			void				ClearScreenshots();
349			bool				AddScreenshot(const BitmapRef& screenshot);
350			const BitmapList&	Screenshots() const
351									{ return fScreenshots; }
352
353			void				SetSize(int64 size);
354			int64				Size() const
355									{ return fSize; }
356
357			void				SetDepotName(const BString& depotName);
358			const BString&		DepotName() const
359									{ return fDepotName; }
360
361			bool				AddListener(
362									const PackageInfoListenerRef& listener);
363			void				RemoveListener(
364									const PackageInfoListenerRef& listener);
365
366	static	void				CleanupDefaultIcon();
367
368			void				StartCollatingChanges();
369			void				EndCollatingChanges();
370
371private:
372			void				_NotifyListeners(uint32 changes);
373			void				_NotifyListenersImmediate(uint32 changes);
374
375private:
376			BitmapRef			fIcon;
377			BString				fName;
378			BString				fTitle;
379			BPackageVersion		fVersion;
380			PublisherInfo		fPublisher;
381			BString				fShortDescription;
382			BString				fFullDescription;
383			BString				fChangelog;
384			CategoryList		fCategories;
385			UserRatingList		fUserRatings;
386			RatingSummary		fCachedRatingSummary;
387			float				fProminence;
388			ScreenshotInfoList	fScreenshotInfos;
389			BitmapList			fScreenshots;
390			PackageState		fState;
391			PackageInstallationLocationSet
392								fInstallationLocations;
393			float				fDownloadProgress;
394			PackageListenerList	fListeners;
395			int32				fFlags;
396			bool				fSystemDependency;
397			BString				fArchitecture;
398			BString				fLocalFilePath;
399			BString				fFileName;
400			int64				fSize;
401			BString				fDepotName;
402
403			bool				fIsCollatingChanges;
404			uint32				fCollatedChanges;
405
406	static	BitmapRef			sDefaultIcon;
407};
408
409
410typedef BReference<PackageInfo> PackageInfoRef;
411
412
413typedef List<PackageInfoRef, false> PackageList;
414
415
416class DepotInfo {
417public:
418								DepotInfo();
419								DepotInfo(const BString& name);
420								DepotInfo(const DepotInfo& other);
421
422			DepotInfo&			operator=(const DepotInfo& other);
423			bool				operator==(const DepotInfo& other) const;
424			bool				operator!=(const DepotInfo& other) const;
425
426			const BString&		Name() const
427									{ return fName; }
428
429			const PackageList&	Packages() const
430									{ return fPackages; }
431
432			bool				AddPackage(const PackageInfoRef& package);
433
434			int32				PackageIndexByName(const BString& packageName)
435									const;
436
437			void				SyncPackages(const PackageList& packages);
438
439			void				SetURL(const BString& URL);
440			const BString&		URL() const
441									{ return fURL; }
442
443			void				SetWebAppRepositoryCode(const BString& code);
444			const BString&		WebAppRepositoryCode() const
445									{ return fWebAppRepositoryCode; }
446
447			void				SetWebAppRepositorySourceCode(
448									const BString& code);
449			const BString&		WebAppRepositorySourceCode() const
450									{ return fWebAppRepositorySourceCode; }
451
452private:
453			BString				fName;
454			PackageList			fPackages;
455			BString				fWebAppRepositoryCode;
456			BString				fWebAppRepositorySourceCode;
457			BString				fURL;
458				// this is actually a unique identifier for the repository.
459};
460
461
462typedef List<DepotInfo, false> DepotList;
463
464
465typedef List<BString, false> StringList;
466
467
468#endif // PACKAGE_INFO_H
469