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 #include "PackageUtils.h" 7 8 9 /*! This method will obtain the title from the package if this is possible or 10 otherwise it will return the name of the package. 11 */ 12 13 /*static*/ void 14 PackageUtils::TitleOrName(const PackageInfoRef package, BString& title) 15 { 16 PackageUtils::Title(package, title); 17 if (title.IsEmpty() && package.IsSet()) 18 title.SetTo(package->Name()); 19 } 20 21 22 /*static*/ void 23 PackageUtils::Title(const PackageInfoRef package, BString& title) 24 { 25 if (package.IsSet()) { 26 PackageLocalizedTextRef localizedText = package->LocalizedText(); 27 28 if (localizedText.IsSet()) 29 title.SetTo(localizedText->Title()); 30 else 31 title.SetTo(""); 32 } else { 33 title.SetTo(""); 34 } 35 } 36 37 38 /*static*/ void 39 PackageUtils::Summary(const PackageInfoRef package, BString& summary) 40 { 41 if (package.IsSet()) { 42 PackageLocalizedTextRef localizedText = package->LocalizedText(); 43 44 if (localizedText.IsSet()) 45 summary.SetTo(localizedText->Summary()); 46 else 47 summary.SetTo(""); 48 } else { 49 summary.SetTo(""); 50 } 51 } 52