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