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 ClearScreenshots(); 146 bool AddScreenshot(const BitmapRef& screenshot); 147 int32 CountScreenshots() const; 148 const BitmapRef ScreenshotAtIndex(int32 index) const; 149 150 void SetSize(off_t size); 151 off_t Size() const 152 { return fSize; } 153 154 void SetViewed(); 155 bool Viewed() const 156 { return fViewed; } 157 158 void SetVersionCreateTimestamp(uint64 value); 159 uint64 VersionCreateTimestamp() const 160 { return fVersionCreateTimestamp; } 161 162 void SetDepotName(const BString& depotName); 163 const BString& DepotName() const 164 { return fDepotName; } 165 166 bool AddListener( 167 const PackageInfoListenerRef& listener); 168 void RemoveListener( 169 const PackageInfoListenerRef& listener); 170 171 void StartCollatingChanges(); 172 void EndCollatingChanges(); 173 void NotifyChangedIcon(); 174 175 private: 176 void _NotifyListeners(uint32 changes); 177 void _NotifyListenersImmediate(uint32 changes); 178 179 bool _HasScreenshot(const BitmapRef& screenshot); 180 181 private: 182 BString fName; 183 BString fTitle; 184 BPackageVersion fVersion; 185 PublisherInfo fPublisher; 186 BString fShortDescription; 187 BString fFullDescription; 188 bool fHasChangelog; 189 BString fChangelog; 190 std::vector<CategoryRef> 191 fCategories; 192 std::vector<UserRatingRef> 193 fUserRatings; 194 RatingSummary fCachedRatingSummary; 195 int64 fProminence; 196 std::vector<ScreenshotInfoRef> 197 fScreenshotInfos; 198 std::vector<BitmapRef> 199 fScreenshots; 200 PackageState fState; 201 PackageInstallationLocationSet 202 fInstallationLocations; 203 float fDownloadProgress; 204 std::vector<PackageInfoListenerRef> 205 fListeners; 206 int32 fFlags; 207 bool fSystemDependency; 208 BString fArchitecture; 209 BString fLocalFilePath; 210 BString fFileName; 211 off_t fSize; 212 BString fDepotName; 213 bool fViewed; 214 215 bool fIsCollatingChanges; 216 uint32 fCollatedChanges; 217 218 uint64 fVersionCreateTimestamp; 219 // milliseconds since epoch 220 }; 221 222 223 typedef BReference<PackageInfo> PackageInfoRef; 224 225 226 #endif // PACKAGE_INFO_H 227