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