1 /* 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016-2024, 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 bool DidPopulateUserRatings() const; 125 void SetDidPopulateUserRatings(); 126 127 void ClearUserRatings(); 128 void AddUserRating(const UserRatingRef& rating); 129 int32 CountUserRatings() const; 130 UserRatingRef UserRatingAtIndex(int32 index) const; 131 void SetRatingSummary(const RatingSummary& summary); 132 RatingSummary CalculateRatingSummary() const; 133 134 void SetProminence(int64 prominence); 135 int64 Prominence() const 136 { return fProminence; } 137 bool HasProminence() const 138 { return fProminence != 0; } 139 bool IsProminent() const; 140 141 void ClearScreenshotInfos(); 142 void AddScreenshotInfo( 143 const ScreenshotInfoRef& info); 144 int32 CountScreenshotInfos() const; 145 ScreenshotInfoRef ScreenshotInfoAtIndex(int32 index) const; 146 147 void SetSize(off_t size); 148 off_t Size() const 149 { return fSize; } 150 151 void SetViewed(); 152 bool Viewed() const 153 { return fViewed; } 154 155 void SetVersionCreateTimestamp(uint64 value); 156 uint64 VersionCreateTimestamp() const 157 { return fVersionCreateTimestamp; } 158 159 void SetDepotName(const BString& depotName); 160 const BString& DepotName() const 161 { return fDepotName; } 162 163 bool AddListener( 164 const PackageInfoListenerRef& listener); 165 void RemoveListener( 166 const PackageInfoListenerRef& listener); 167 168 void StartCollatingChanges(); 169 void EndCollatingChanges(); 170 void NotifyChangedIcon(); 171 172 private: 173 void _NotifyListeners(uint32 changes); 174 void _NotifyListenersImmediate(uint32 changes); 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 bool fDidPopulateUserRatings; 190 RatingSummary fCachedRatingSummary; 191 int64 fProminence; 192 std::vector<ScreenshotInfoRef> 193 fScreenshotInfos; 194 195 PackageState fState; 196 PackageInstallationLocationSet 197 fInstallationLocations; 198 float fDownloadProgress; 199 std::vector<PackageInfoListenerRef> 200 fListeners; 201 int32 fFlags; 202 bool fSystemDependency; 203 BString fArchitecture; 204 BString fLocalFilePath; 205 BString fFileName; 206 off_t fSize; 207 BString fDepotName; 208 bool fViewed; 209 210 bool fIsCollatingChanges; 211 uint32 fCollatedChanges; 212 213 uint64 fVersionCreateTimestamp; 214 // milliseconds since epoch 215 }; 216 217 218 typedef BReference<PackageInfo> PackageInfoRef; 219 220 221 #endif // PACKAGE_INFO_H 222