From 8c6ebdec76f5f8edc4869da292a59214fac6fe0a Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Wed, 20 May 2020 22:49:47 +1200 Subject: [PATCH] HaikuDepot: Changelog & Contents Tabs Disable the changelog tab in the case that a package has no changelog. Also disable the contents tab and do not attempt to load the package contents in the case where a package is not installed on the host. Resolves #15299 Change-Id: Id17daf46aba6709f35438db2ee30f3485fc251ea Reviewed-on: https://review.haiku-os.org/c/haiku/+/2749 Reviewed-by: humdinger Reviewed-by: waddlesplash --- src/apps/haikudepot/model/Model.cpp | 2 +- src/apps/haikudepot/model/PackageInfo.cpp | 15 +- src/apps/haikudepot/model/PackageInfo.h | 7 +- .../server/ServerPkgDataUpdateProcess.cpp | 4 +- .../server/schema/dumpexportpkg.json | 3 + .../server/schema/dumpexportreference.json | 129 +++++++++--------- .../haikudepot/ui/PackageContentsView.cpp | 21 +-- src/apps/haikudepot/ui/PackageContentsView.h | 3 +- src/apps/haikudepot/ui/PackageInfoView.cpp | 30 +++- 9 files changed, 130 insertions(+), 84 deletions(-) diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index de427d082a..110817c1ab 100644 --- a/src/apps/haikudepot/model/Model.cpp +++ b/src/apps/haikudepot/model/Model.cpp @@ -605,7 +605,7 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) fPopulatedPackages.Add(package); } - if ((flags & POPULATE_CHANGELOG) != 0) { + if ((flags & POPULATE_CHANGELOG) != 0 && package->HasChangelog()) { _PopulatePackageChangelog(package); } diff --git a/src/apps/haikudepot/model/PackageInfo.cpp b/src/apps/haikudepot/model/PackageInfo.cpp index 855d193d7f..3fc39d31ca 100644 --- a/src/apps/haikudepot/model/PackageInfo.cpp +++ b/src/apps/haikudepot/model/PackageInfo.cpp @@ -1,7 +1,7 @@ /* * Copyright 2013-2014, Stephan Aßmus . * Copyright 2013, Rene Gollent . - * Copyright 2016-2019, Andrew Lindesay . + * Copyright 2016-2020, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -471,6 +471,7 @@ PackageInfo::PackageInfo() fPublisher(), fShortDescription(), fFullDescription(), + fHasChangelog(false), fChangelog(), fUserRatings(), fCachedRatingSummary(), @@ -501,6 +502,7 @@ PackageInfo::PackageInfo(const BPackageInfo& info) fPublisher(), fShortDescription(info.Summary()), fFullDescription(info.Description()), + fHasChangelog(false), fChangelog(), fUserRatings(), fCachedRatingSummary(), @@ -547,6 +549,7 @@ PackageInfo::PackageInfo(const BString& name, fPublisher(publisher), fShortDescription(shortDescription), fFullDescription(fullDescription), + fHasChangelog(false), fChangelog(), fCategories(), fUserRatings(), @@ -578,6 +581,7 @@ PackageInfo::PackageInfo(const PackageInfo& other) fPublisher(other.fPublisher), fShortDescription(other.fShortDescription), fFullDescription(other.fFullDescription), + fHasChangelog(other.fHasChangelog), fChangelog(other.fChangelog), fCategories(other.fCategories), fUserRatings(other.fUserRatings), @@ -611,6 +615,7 @@ PackageInfo::operator=(const PackageInfo& other) fPublisher = other.fPublisher; fShortDescription = other.fShortDescription; fFullDescription = other.fFullDescription; + fHasChangelog = other.fHasChangelog; fChangelog = other.fChangelog; fCategories = other.fCategories; fUserRatings = other.fUserRatings; @@ -642,6 +647,7 @@ PackageInfo::operator==(const PackageInfo& other) const && fPublisher == other.fPublisher && fShortDescription == other.fShortDescription && fFullDescription == other.fFullDescription + && fHasChangelog == other.fHasChangelog && fChangelog == other.fChangelog && fCategories == other.fCategories && fUserRatings == other.fUserRatings @@ -714,6 +720,13 @@ PackageInfo::SetIcon(const BitmapRef& icon) } +void +PackageInfo::SetHasChangelog(bool value) +{ + fHasChangelog = value; +} + + void PackageInfo::SetChangelog(const BString& changelog) { diff --git a/src/apps/haikudepot/model/PackageInfo.h b/src/apps/haikudepot/model/PackageInfo.h index 512b6a4bb4..89d1fb61ed 100644 --- a/src/apps/haikudepot/model/PackageInfo.h +++ b/src/apps/haikudepot/model/PackageInfo.h @@ -1,6 +1,6 @@ /* * Copyright 2013-2014, Stephan Aßmus . - * Copyright 2016-2019, Andrew Lindesay . + * Copyright 2016-2020, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PACKAGE_INFO_H @@ -286,6 +286,10 @@ public: void SetIcon(const BitmapRef& icon); const BitmapRef& Icon() const { return fIcon; } + + void SetHasChangelog(bool value); + bool HasChangelog() const + { return fHasChangelog; } void SetChangelog(const BString& changelog); const BString& Changelog() const { return fChangelog; } @@ -380,6 +384,7 @@ private: PublisherInfo fPublisher; BString fShortDescription; BString fFullDescription; + bool fHasChangelog; BString fChangelog; CategoryList fCategories; UserRatingList fUserRatings; diff --git a/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp b/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp index fc6cc9c11c..ed62557074 100644 --- a/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp +++ b/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019, Andrew Lindesay . + * Copyright 2017-2020, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -159,6 +159,8 @@ PackageFillingPkgListener::ConsumePackage(const PackageInfoRef& package, package->SetRatingSummary(summary); + package->SetHasChangelog(pkg->HasChangelog()); + if (!pkg->ProminenceOrderingIsNull()) package->SetProminence(pkg->ProminenceOrdering()); diff --git a/src/apps/haikudepot/server/schema/dumpexportpkg.json b/src/apps/haikudepot/server/schema/dumpexportpkg.json index 7130418385..653d76fa41 100644 --- a/src/apps/haikudepot/server/schema/dumpexportpkg.json +++ b/src/apps/haikudepot/server/schema/dumpexportpkg.json @@ -17,6 +17,9 @@ "derivedRating": { "type": "number" }, + "hasChangelog": { + "type": "boolean" + }, "pkgScreenshots": { "type": "array", "items": { diff --git a/src/apps/haikudepot/server/schema/dumpexportreference.json b/src/apps/haikudepot/server/schema/dumpexportreference.json index 08eb684863..cd171f35b4 100644 --- a/src/apps/haikudepot/server/schema/dumpexportreference.json +++ b/src/apps/haikudepot/server/schema/dumpexportreference.json @@ -5,68 +5,71 @@ "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReference", "type": "object", "properties": { - "naturalLanguages": { - "type": "array", - "items": { - "type": "object", - "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferenceNaturalLanguage", - "properties": { - "code": { - "type": "string" - }, - "name": { - "type": "string" - }, - "isPopular": { - "type": "boolean" - } - } - } - }, - "pkgCategories": { - "type": "array", - "items": { - "type": "object", - "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferencePkgCategory", - "properties": { - "code": { - "type": "string" - }, - "name": { - "type": "string" - } - } - } - }, - "userRatingStabilities": { - "type": "array", - "items": { - "type": "object", - "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferenceUserRatingStability", - "properties": { - "code": { - "type": "string" - }, - "name": { - "type": "string" - } - } - } - }, - "countries": { - "type": "array", - "items": { - "type": "object", - "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferenceCountry", - "properties": { - "code": { - "type": "string" - }, - "name": { - "type": "string" - } - } - } - } + "naturalLanguages": { + "type": "array", + "items": { + "type": "object", + "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferenceNaturalLanguage", + "properties": { + "code": { + "type": "string" + }, + "name": { + "type": "string" + }, + "isPopular": { + "type": "boolean" + } + } + } + }, + "pkgCategories": { + "type": "array", + "items": { + "type": "object", + "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferencePkgCategory", + "properties": { + "code": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + }, + "userRatingStabilities": { + "type": "array", + "items": { + "type": "object", + "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferenceUserRatingStability", + "properties": { + "code": { + "type": "string" + }, + "name": { + "type": "string" + }, + "ordering": { + "type": "integer" + } + } + } + }, + "countries": { + "type": "array", + "items": { + "type": "object", + "javaType": "org.haiku.haikudepotserver.reference.model.dumpexport.DumpExportReferenceCountry", + "properties": { + "code": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + } } } \ No newline at end of file diff --git a/src/apps/haikudepot/ui/PackageContentsView.cpp b/src/apps/haikudepot/ui/PackageContentsView.cpp index 5d2e0c86af..0a29ce0fec 100644 --- a/src/apps/haikudepot/ui/PackageContentsView.cpp +++ b/src/apps/haikudepot/ui/PackageContentsView.cpp @@ -1,5 +1,6 @@ /* * Copyright 2015, TigerKid001. + * Copyright 2020, Andrew Lindesay * All rights reserved. Distributed under the terms of the MIT License. */ @@ -293,9 +294,6 @@ PackageContentsView::SetPackage(const PackageInfoRef& package) return; } -// printf("PackageContentsView::SetPackage(%s)\n", -// package.Get() != NULL ? package->Name().String() : "NULL"); - Clear(); { @@ -303,7 +301,12 @@ PackageContentsView::SetPackage(const PackageInfoRef& package) fPackage = package; fLastPackageState = package.Get() != NULL ? package->State() : NONE; } - release_sem_etc(fContentPopulatorSem, 1, 0); + + // if the package is not installed then there is no point in attempting to + // populate data for it. + + if (package.Get() != NULL && package->State() == ACTIVATED) + release_sem_etc(fContentPopulatorSem, 1, 0); } @@ -349,7 +352,7 @@ PackageContentsView::_ContentPopulatorThread(void* arg) } if (package.Get() != NULL) { - if (!view->_PopuplatePackageContens(*package.Get())) { + if (!view->_PopulatePackageContents(*package.Get())) { if (view->LockLooperWithTimeout(1000000) == B_OK) { view->fContentListView->AddItem( new BStringItem(B_TRANSLATE(" * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PACKAGE_CONTENTS_VIEW_H @@ -27,7 +28,7 @@ public: private: void _InitContentPopulator(); static int32 _ContentPopulatorThread(void* arg); - bool _PopuplatePackageContens( + bool _PopulatePackageContents( const PackageInfo& package); int32 _InstallLocation( const PackageInfo& package) const; diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp b/src/apps/haikudepot/ui/PackageInfoView.cpp index bcf22bd077..8816593f42 100644 --- a/src/apps/haikudepot/ui/PackageInfoView.cpp +++ b/src/apps/haikudepot/ui/PackageInfoView.cpp @@ -1,6 +1,6 @@ /* * Copyright 2013-2014, Stephan Aßmus . - * Copyright 2018-2019, Andrew Lindesay . + * Copyright 2018-2020, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -54,6 +54,14 @@ #define B_TRANSLATION_CONTEXT "PackageInfoView" +enum { + TAB_ABOUT = 0, + TAB_RATINGS = 1, + TAB_CHANGELOG = 2, + TAB_CONTENTS = 3 +}; + + static const float kContentTint = (B_NO_TINT + B_LIGHTEN_1_TINT) / 2.0f; @@ -1222,12 +1230,12 @@ public: AddTab(fChangelogView); AddTab(fContentsView); - TabAt(0)->SetLabel(B_TRANSLATE("About")); - TabAt(1)->SetLabel(B_TRANSLATE("Ratings")); - TabAt(2)->SetLabel(B_TRANSLATE("Changelog")); - TabAt(3)->SetLabel(B_TRANSLATE("Contents")); + TabAt(TAB_ABOUT)->SetLabel(B_TRANSLATE("About")); + TabAt(TAB_RATINGS)->SetLabel(B_TRANSLATE("Ratings")); + TabAt(TAB_CHANGELOG)->SetLabel(B_TRANSLATE("Changelog")); + TabAt(TAB_CONTENTS)->SetLabel(B_TRANSLATE("Contents")); - Select(0); + Select(TAB_ABOUT); } virtual ~PagesView() @@ -1238,7 +1246,15 @@ public: void SetPackage(const PackageInfoRef& package, bool switchToDefaultTab) { if (switchToDefaultTab) - Select(0); + Select(TAB_ABOUT); + + TabAt(TAB_CHANGELOG)->SetEnabled( + package.Get() != NULL && package->HasChangelog()); + TabAt(TAB_CONTENTS)->SetEnabled( + package.Get() != NULL && package->State() == ACTIVATED); + Invalidate(TabFrame(TAB_CHANGELOG)); + Invalidate(TabFrame(TAB_CONTENTS)); + fAboutView->SetPackage(*package.Get()); fUserRatingsView->SetPackage(*package.Get()); fChangelogView->SetPackage(*package.Get());