xref: /haiku/src/apps/haikudepot/packagemodel/PackageLocalInfo.h (revision 344ded80d400028c8f561b4b876257b94c12db4a)
1 /*
2  * Copyright 2024, Andrew Lindesay <apl@lindesay.co.nz>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef PACKAGE_LOCAL_INFO_H
6 #define PACKAGE_LOCAL_INFO_H
7 
8 
9 #include <sys/types.h>
10 
11 #include <set>
12 
13 #include <Referenceable.h>
14 #include <String.h>
15 
16 
17 typedef std::set<int32> PackageInstallationLocationSet;
18 
19 
20 enum PackageState {
21 	NONE		= 0,
22 	INSTALLED	= 1,
23 	DOWNLOADING	= 2,
24 	ACTIVATED	= 3,
25 	UNINSTALLED	= 4,
26 	PENDING		= 5,
27 };
28 
29 
30 class PackageLocalInfo : public BReferenceable
31 {
32 public:
33 								PackageLocalInfo();
34 								PackageLocalInfo(const PackageLocalInfo& other);
35 	virtual						~PackageLocalInfo();
36 
37 			PackageLocalInfo&	operator=(const PackageLocalInfo& other);
38 			bool				operator==(const PackageLocalInfo& other) const;
39 			bool				operator!=(const PackageLocalInfo& other) const;
40 
41 			bool				IsLocalFile() const;
42 
43 			void				SetViewed();
44 			bool				Viewed() const
45 									{ return fViewed; }
46 
47 			void				SetLocalFilePath(const char* path);
48 			const BString&		LocalFilePath() const
49 									{ return fLocalFilePath; }
50 
51 			void				SetFileName(const BString& value);
52 			const BString&		FileName() const
53 									{ return fFileName; }
54 
55 			void				SetSize(off_t size);
56 			off_t				Size() const
57 									{ return fSize; }
58 
59 			void				SetFlags(int32 value);
60 			int32				Flags() const
61 									{ return fFlags; }
62 
63 			bool				IsSystemPackage() const;
64 
65 			void				SetSystemDependency(bool isDependency);
66 			bool				IsSystemDependency() const
67 									{ return fSystemDependency; }
68 
69 			void				SetState(PackageState state);
70 			PackageState		State() const
71 									{ return fState; }
72 
73 			void				AddInstallationLocation(int32 location);
74 			const PackageInstallationLocationSet&
75 								InstallationLocations() const
76 									{ return fInstallationLocations; }
77 			void				ClearInstallationLocations();
78 
79 			void				SetDownloadProgress(float progress);
80 			float				DownloadProgress() const
81 									{ return fDownloadProgress; }
82 
83 private:
84 			bool				fViewed;
85 			BString				fLocalFilePath;
86 			BString				fFileName;
87 			off_t				fSize;
88 			int32				fFlags;
89 			bool				fSystemDependency;
90 			PackageState		fState;
91 			PackageInstallationLocationSet
92 								fInstallationLocations;
93 			float				fDownloadProgress;
94 };
95 
96 
97 typedef BReference<PackageLocalInfo> PackageLocalInfoRef;
98 
99 
100 #endif // PACKAGE_LOCAL_INFO_H
101