xref: /haiku/src/apps/haikudepot/packagemodel/PackageInfo.h (revision 1978089f7cec856677e46204e992c7273d70b9af)
1 /*
2  * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2016-2023, 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 #include <vector>
12 
13 #include <Referenceable.h>
14 #include <package/PackageInfo.h>
15 
16 #include "Language.h"
17 #include "List.h"
18 #include "PackageCategory.h"
19 #include "PackageInfoListener.h"
20 #include "PublisherInfo.h"
21 #include "RatingSummary.h"
22 #include "ScreenshotInfo.h"
23 #include "SharedBitmap.h"
24 #include "UserRating.h"
25 
26 
27 typedef std::set<int32> PackageInstallationLocationSet;
28 
29 
30 enum PackageState {
31 	NONE		= 0,
32 	INSTALLED	= 1,
33 	DOWNLOADING	= 2,
34 	ACTIVATED	= 3,
35 	UNINSTALLED	= 4,
36 	PENDING		= 5,
37 };
38 
39 
40 const char* package_state_to_string(PackageState state);
41 
42 
43 using BPackageKit::BPackageInfo;
44 using BPackageKit::BPackageVersion;
45 
46 
47 class PackageInfo : public BReferenceable {
48 public:
49 								PackageInfo();
50 								PackageInfo(const BPackageInfo& info);
51 								PackageInfo(
52 									const BString& name,
53 									const BPackageVersion& version,
54 									const PublisherInfo& publisher,
55 									const BString& shortDescription,
56 									const BString& fullDescription,
57 									int32 packageFlags,
58 									const char* architecture);
59 								PackageInfo(const PackageInfo& other);
60 
61 			PackageInfo&		operator=(const PackageInfo& other);
62 			bool				operator==(const PackageInfo& other) const;
63 			bool				operator!=(const PackageInfo& other) const;
64 
65 			const BString&		Name() const
66 									{ return fName; }
67 			void				SetTitle(const BString& title);
68 			const BString&		Title() const;
69 			const BPackageVersion&
70 								Version() const
71 									{ return fVersion; }
72 			void				SetShortDescription(const BString& description);
73 			const BString&		ShortDescription() const
74 									{ return fShortDescription; }
75 			void				SetFullDescription(const BString& description);
76 			const BString&		FullDescription() const
77 									{ return fFullDescription; }
78 			const PublisherInfo& Publisher() const
79 									{ return fPublisher; }
80 
81 			void				SetHasChangelog(bool value);
82 			bool				HasChangelog() const
83 									{ return fHasChangelog; }
84 			void				SetChangelog(const BString& changelog);
85 			const BString&		Changelog() const
86 									{ return fChangelog; }
87 
88 			int32				Flags() const
89 									{ return fFlags; }
90 			bool				IsSystemPackage() const;
91 
92 			bool				IsSystemDependency() const
93 									{ return fSystemDependency; }
94 			void				SetSystemDependency(bool isDependency);
95 
96 			const BString		Architecture() const
97 									{ return fArchitecture; }
98 
99 			PackageState		State() const
100 									{ return fState; }
101 			void				SetState(PackageState state);
102 
103 			const PackageInstallationLocationSet&
104 								InstallationLocations() const
105 									{ return fInstallationLocations; }
106 			void				AddInstallationLocation(int32 location);
107 			void				ClearInstallationLocations();
108 
109 			float				DownloadProgress() const
110 									{ return fDownloadProgress; }
111 			void				SetDownloadProgress(float progress);
112 
113 			void				SetLocalFilePath(const char* path);
114 			const BString&		LocalFilePath() const
115 									{ return fLocalFilePath; }
116 			bool				IsLocalFile() const;
117 			const BString&		FileName() const
118 									{ return fFileName; }
119 
120 			void				ClearCategories();
121 			bool				AddCategory(const CategoryRef& category);
122 			int32				CountCategories() const;
123 			CategoryRef			CategoryAtIndex(int32 index) const;
124 
125 			void				ClearUserRatings();
126 			void				AddUserRating(const UserRatingRef& rating);
127 			int32				CountUserRatings() const;
128 			UserRatingRef		UserRatingAtIndex(int32 index) const;
129 			void				SetRatingSummary(const RatingSummary& summary);
130 			RatingSummary		CalculateRatingSummary() const;
131 
132 			void				SetProminence(int64 prominence);
133 			int64				Prominence() const
134 									{ return fProminence; }
135 			bool				HasProminence() const
136 									{ return fProminence != 0; }
137 			bool				IsProminent() const;
138 
139 			void				ClearScreenshotInfos();
140 			void				AddScreenshotInfo(
141 									const ScreenshotInfoRef& info);
142 			int32				CountScreenshotInfos() const;
143 			ScreenshotInfoRef	ScreenshotInfoAtIndex(int32 index) const;
144 
145 			void				SetSize(off_t size);
146 			off_t				Size() const
147 									{ return fSize; }
148 
149 			void				SetViewed();
150 			bool				Viewed() const
151 									{ return fViewed; }
152 
153 			void				SetVersionCreateTimestamp(uint64 value);
154 			uint64				VersionCreateTimestamp() const
155 									{ return fVersionCreateTimestamp; }
156 
157 			void				SetDepotName(const BString& depotName);
158 			const BString&		DepotName() const
159 									{ return fDepotName; }
160 
161 			bool				AddListener(
162 									const PackageInfoListenerRef& listener);
163 			void				RemoveListener(
164 									const PackageInfoListenerRef& listener);
165 
166 			void				StartCollatingChanges();
167 			void				EndCollatingChanges();
168 			void				NotifyChangedIcon();
169 
170 private:
171 			void				_NotifyListeners(uint32 changes);
172 			void				_NotifyListenersImmediate(uint32 changes);
173 
174 			bool				_HasScreenshot(const BitmapRef& screenshot);
175 
176 private:
177 			BString				fName;
178 			BString				fTitle;
179 			BPackageVersion		fVersion;
180 			PublisherInfo		fPublisher;
181 			BString				fShortDescription;
182 			BString				fFullDescription;
183 			bool				fHasChangelog;
184 			BString				fChangelog;
185 			std::vector<CategoryRef>
186 								fCategories;
187 			std::vector<UserRatingRef>
188 								fUserRatings;
189 			RatingSummary		fCachedRatingSummary;
190 			int64				fProminence;
191 			std::vector<ScreenshotInfoRef>
192 								fScreenshotInfos;
193 
194 			PackageState		fState;
195 			PackageInstallationLocationSet
196 								fInstallationLocations;
197 			float				fDownloadProgress;
198 			std::vector<PackageInfoListenerRef>
199 								fListeners;
200 			int32				fFlags;
201 			bool				fSystemDependency;
202 			BString				fArchitecture;
203 			BString				fLocalFilePath;
204 			BString				fFileName;
205 			off_t				fSize;
206 			BString				fDepotName;
207 			bool				fViewed;
208 
209 			bool				fIsCollatingChanges;
210 			uint32				fCollatedChanges;
211 
212 			uint64				fVersionCreateTimestamp;
213 				// milliseconds since epoch
214 };
215 
216 
217 typedef BReference<PackageInfo> PackageInfoRef;
218 
219 
220 #endif // PACKAGE_INFO_H
221