xref: /haiku/src/apps/haikudepot/packagemodel/PackageLocalInfo.cpp (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 
6 
7 #include "PackageLocalInfo.h"
8 
9 #include "Package.h"
10 
11 
12 PackageLocalInfo::PackageLocalInfo()
13 	:
14 	fViewed(false),
15 	fLocalFilePath(),
16 	fFileName(),
17 	fSize(0),
18 	fFlags(0),
19 	fSystemDependency(false),
20 	fState(NONE),
21 	fInstallationLocations(),
22 	fDownloadProgress(0.0)
23 {
24 }
25 
26 
27 PackageLocalInfo::PackageLocalInfo(const PackageLocalInfo& other)
28 	:
29 	fViewed(other.fViewed),
30 	fLocalFilePath(other.fLocalFilePath),
31 	fFileName(other.fFileName),
32 	fSize(other.fSize),
33 	fFlags(other.fFlags),
34 	fSystemDependency(other.fSystemDependency),
35 	fState(other.fState),
36 	fInstallationLocations(),
37 	fDownloadProgress(other.fDownloadProgress)
38 {
39 	PackageInstallationLocationSet otherLocations = other.InstallationLocations();
40 	PackageInstallationLocationSet::const_iterator it;
41 
42 	for (it = otherLocations.begin(); it != otherLocations.end(); it++)
43 		fInstallationLocations.insert(*it);
44 }
45 
46 
47 PackageLocalInfo::~PackageLocalInfo()
48 {
49 }
50 
51 
52 PackageLocalInfo&
53 PackageLocalInfo::operator=(const PackageLocalInfo& other)
54 {
55 	fState = other.fState;
56 	fInstallationLocations = other.fInstallationLocations;
57 	fDownloadProgress = other.fDownloadProgress;
58 	fFlags = other.fFlags;
59 	fSystemDependency = other.fSystemDependency;
60 	fLocalFilePath = other.fLocalFilePath;
61 	fFileName = other.fFileName;
62 	fSize = other.fSize;
63 	fViewed = other.fViewed;
64 
65 	return *this;
66 }
67 
68 
69 bool
70 PackageLocalInfo::operator==(const PackageLocalInfo& other) const
71 {
72 	return fState == other.fState
73 		&& fFlags == other.fFlags
74 		&& fInstallationLocations == other.fInstallationLocations
75 		&& fDownloadProgress == other.fDownloadProgress
76 		&& fSystemDependency == other.fSystemDependency
77 		&& fLocalFilePath == other.fLocalFilePath
78 		&& fFileName == other.fFileName
79 		&& fSize == other.fSize
80 		&& fViewed == other.fViewed;
81 }
82 
83 
84 bool
85 PackageLocalInfo::operator!=(const PackageLocalInfo& other) const
86 {
87 	return !(*this == other);
88 }
89 
90 
91 bool
92 PackageLocalInfo::IsSystemPackage() const
93 {
94 	return (fFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0;
95 }
96 
97 
98 void
99 PackageLocalInfo::SetSystemDependency(bool isDependency)
100 {
101 	fSystemDependency = isDependency;
102 }
103 
104 
105 void
106 PackageLocalInfo::SetState(PackageState state)
107 {
108 	if (fState != state) {
109 		fState = state;
110 		if (fState != DOWNLOADING)
111 			fDownloadProgress = 0.0;
112 	}
113 }
114 
115 
116 void
117 PackageLocalInfo::AddInstallationLocation(int32 location)
118 {
119 	fInstallationLocations.insert(location);
120 	SetState(ACTIVATED);
121 		// TODO: determine how to differentiate between installed and active.
122 }
123 
124 
125 void
126 PackageLocalInfo::ClearInstallationLocations()
127 {
128 	fInstallationLocations.clear();
129 }
130 
131 
132 void
133 PackageLocalInfo::SetDownloadProgress(float progress)
134 {
135 	fState = DOWNLOADING;
136 	fDownloadProgress = progress;
137 }
138 
139 
140 void
141 PackageLocalInfo::SetLocalFilePath(const char* path)
142 {
143 	fLocalFilePath = path;
144 }
145 
146 
147 bool
148 PackageLocalInfo::IsLocalFile() const
149 {
150 	return !fLocalFilePath.IsEmpty() && fInstallationLocations.empty();
151 }
152 
153 
154 void
155 PackageLocalInfo::SetSize(int64 size)
156 {
157 	fSize = size;
158 }
159 
160 
161 void
162 PackageLocalInfo::SetViewed()
163 {
164 	fViewed = true;
165 }
166 
167 
168 void
169 PackageLocalInfo::SetFlags(int32 value)
170 {
171 	fFlags = value;
172 }
173 
174 
175 void
176 PackageLocalInfo::SetFileName(const BString& value)
177 {
178 	fFileName = value;
179 }
180