From 80a272eed817288ae41b91444ae524da57d7c43c Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Sun, 28 Jan 2018 12:13:41 +0100 Subject: [PATCH] HaikuDepot : Changelog, Remove old API and Version Bump This change re-instates the change-log function (TRAC#13827) that was dropped in earlier changes. Also now-disused API handling logic is removed. A small code-style fix is made and the version of the application has been incremented so that this version's logic can later be detected by the HDS application server. --- src/apps/haikudepot/HaikuDepot.rdef | 4 +- src/apps/haikudepot/model/Model.cpp | 74 ++++++++++++++++++- src/apps/haikudepot/model/Model.h | 9 ++- src/apps/haikudepot/model/PackageInfo.cpp | 5 +- .../haikudepot/server/WebAppInterface.cpp | 74 +------------------ src/apps/haikudepot/server/WebAppInterface.h | 16 +--- 6 files changed, 89 insertions(+), 93 deletions(-) diff --git a/src/apps/haikudepot/HaikuDepot.rdef b/src/apps/haikudepot/HaikuDepot.rdef index 8893e5a2e0..e69fcb0688 100644 --- a/src/apps/haikudepot/HaikuDepot.rdef +++ b/src/apps/haikudepot/HaikuDepot.rdef @@ -8,13 +8,13 @@ resource app_flags B_SINGLE_LAUNCH; resource app_version { major = 0, middle = 0, - minor = 1, + minor = 2, variety = B_APPV_ALPHA, internal = 1, short_info = "HaikuDepot", - long_info = "HaikuDepot ©2013-2014 Haiku" + long_info = "HaikuDepot ©2013-2018 Haiku" }; resource file_types message { diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index 3188b24189..d4bb7b3a4b 100644 --- a/src/apps/haikudepot/model/Model.cpp +++ b/src/apps/haikudepot/model/Model.cpp @@ -1,7 +1,7 @@ /* * Copyright 2013-2014, Stephan Aßmus . * Copyright 2014, Axel Dörfler . - * Copyright 2016-2017, Andrew Lindesay . + * Copyright 2016-2018, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -669,6 +669,10 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) fPopulatedPackages.Add(package); } + if ((flags & POPULATE_CHANGELOG) != 0) { + _PopulatePackageChangelog(package); + } + if ((flags & POPULATE_USER_RATINGS) != 0) { // Retrieve info from web-app BMessage info; @@ -746,8 +750,8 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) comment, languageCode, versionString, 0, 0) ); } - } else if (info.FindMessage("error", &result) == B_OK) { - result.PrintToStream(); + } else { + _MaybeLogJsonRpcError(info, "retrieve user ratings"); } } } @@ -767,6 +771,48 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) } +void +Model::_PopulatePackageChangelog(const PackageInfoRef& package) +{ + BMessage info; + BString packageName; + + { + BAutolock locker(&fLock); + packageName = package->Name(); + } + + status_t status = fWebAppInterface.GetChangelog(packageName, info); + + if (status == B_OK) { + // Parse message + BMessage result; + BString content; + if (info.FindMessage("result", &result) == B_OK) { + if (result.FindString("content", &content) == B_OK + && 0 != content.Length()) { + BAutolock locker(&fLock); + package->SetChangelog(content); + if (Logger::IsDebugEnabled()) { + fprintf(stdout, "changelog populated for [%s]\n", + packageName.String()); + } + } else { + if (Logger::IsDebugEnabled()) { + fprintf(stdout, "no changelog present for [%s]\n", + packageName.String()); + } + } + } else { + _MaybeLogJsonRpcError(info, "populate package changelog"); + } + } else { + fprintf(stdout, "unable to obtain the changelog for the package" + "[%s]\n", packageName.String()); + } +} + + void Model::SetUsername(BString username) { @@ -1080,4 +1126,24 @@ Model::LogDepotsWithNoWebAppRepositoryCode() const "depot server system\n"); } } -} \ No newline at end of file +} + + +void +Model::_MaybeLogJsonRpcError(const BMessage &responsePayload, + const char *sourceDescription) const +{ + BMessage error; + BString errorMessage; + double errorCode; + + if (responsePayload.FindMessage("error", &error) == B_OK + && error.FindString("message", &errorMessage) == B_OK + && error.FindDouble("code", &errorCode) == B_OK) { + printf("[%s] --> error : [%s] (%f)\n", sourceDescription, + errorMessage.String(), errorCode); + + } else { + printf("[%s] --> an undefined error has occurred\n", sourceDescription); + } +} diff --git a/src/apps/haikudepot/model/Model.h b/src/apps/haikudepot/model/Model.h index a4baa39841..986e70840d 100644 --- a/src/apps/haikudepot/model/Model.h +++ b/src/apps/haikudepot/model/Model.h @@ -1,6 +1,6 @@ /* * Copyright 2013-2014, Stephan Aßmus . - * Copyright 2016-2017, Andrew Lindesay . + * Copyright 2016-2018, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef MODEL_H @@ -193,10 +193,17 @@ public: void LogDepotsWithNoWebAppRepositoryCode() const; private: + void _MaybeLogJsonRpcError( + const BMessage &responsePayload, + const char *sourceDescription) const; + void _UpdateIsFeaturedFilter(); static int32 _PopulateAllPackagesEntry(void* cookie); + void _PopulatePackageChangelog( + const PackageInfoRef& package); + void _PopulatePackageScreenshot( const PackageInfoRef& package, const ScreenshotInfo& info, diff --git a/src/apps/haikudepot/model/PackageInfo.cpp b/src/apps/haikudepot/model/PackageInfo.cpp index e783f8bfda..904f3dbfec 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-2017, Andrew Lindesay . + * Copyright 2016-2018, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -1064,7 +1064,8 @@ DepotInfo::AddPackage(const PackageInfoRef& package) } -static int32 PackageFixedNameCompare(const void* context, +static int32 +PackageFixedNameCompare(const void* context, const PackageInfoRef& package) { const BString* packageName = static_cast(context); diff --git a/src/apps/haikudepot/server/WebAppInterface.cpp b/src/apps/haikudepot/server/WebAppInterface.cpp index f439b28708..c3e02ede50 100644 --- a/src/apps/haikudepot/server/WebAppInterface.cpp +++ b/src/apps/haikudepot/server/WebAppInterface.cpp @@ -1,6 +1,6 @@ /* * Copyright 2014, Stephan Aßmus . - * Copyright 2016-2017, Andrew Lindesay . + * Copyright 2016-2018, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -315,81 +315,15 @@ WebAppInterface::SetPreferredLanguage(const BString& language) status_t -WebAppInterface::RetrieveRepositoriesForSourceBaseURLs( - const StringList& repositorySourceBaseURLs, - BMessage& message) +WebAppInterface::GetChangelog(const BString& packageName, BMessage& message) { BString jsonString = JsonBuilder() .AddValue("jsonrpc", "2.0") .AddValue("id", ++fRequestIndex) - .AddValue("method", "searchRepositories") + .AddValue("method", "getPkgChangelog") .AddArray("params") .AddObject() - .AddArray("repositorySourceSearchUrls") - .AddStrings(repositorySourceBaseURLs) - .EndArray() - .AddValue("offset", 0) - .AddValue("limit", 1000) // effectively a safety limit - .EndObject() - .EndArray() - .End(); - - return _SendJsonRequest("repository", jsonString, 0, message); -} - - -status_t -WebAppInterface::RetrievePackageInfo(const BString& packageName, - const BString& architecture, const BString& repositoryCode, - BMessage& message) -{ - BString jsonString = JsonBuilder() - .AddValue("jsonrpc", "2.0") - .AddValue("id", ++fRequestIndex) - .AddValue("method", "getPkg") - .AddArray("params") - .AddObject() - .AddValue("name", packageName) - .AddValue("architectureCode", architecture) - .AddValue("naturalLanguageCode", fLanguage) - .AddValue("repositoryCode", repositoryCode) - .AddValue("versionType", "NONE") - .EndObject() - .EndArray() - .End(); - - return _SendJsonRequest("pkg", jsonString, 0, message); -} - - -status_t -WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames, - const StringList& packageArchitectures, - const StringList& repositoryCodes, BMessage& message) -{ - BString jsonString = JsonBuilder() - .AddValue("jsonrpc", "2.0") - .AddValue("id", ++fRequestIndex) - .AddValue("method", "getBulkPkg") - .AddArray("params") - .AddObject() - .AddArray("pkgNames") - .AddStrings(packageNames) - .EndArray() - .AddArray("architectureCodes") - .AddStrings(packageArchitectures) - .EndArray() - .AddArray("repositoryCodes") - .AddStrings(repositoryCodes) - .EndArray() - .AddValue("naturalLanguageCode", fLanguage) - .AddValue("versionType", "LATEST") - .AddArray("filter") - .AddItem("PKGCATEGORIES") - .AddItem("PKGSCREENSHOTS") - .AddItem("PKGVERSIONLOCALIZATIONDESCRIPTIONS") - .AddItem("PKGCHANGELOG") - .EndArray() + .AddValue("pkgName", packageName) .EndObject() .EndArray() .End(); diff --git a/src/apps/haikudepot/server/WebAppInterface.h b/src/apps/haikudepot/server/WebAppInterface.h index 377ccf2f21..62b46b3f40 100644 --- a/src/apps/haikudepot/server/WebAppInterface.h +++ b/src/apps/haikudepot/server/WebAppInterface.h @@ -1,6 +1,6 @@ /* * Copyright 2014, Stephan Aßmus . - * Copyright 2016-2017, Andrew Lindesay . + * Copyright 2016-2018, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef WEB_APP_INTERFACE_H @@ -37,20 +37,8 @@ public: void SetPreferredLanguage(const BString& language); void SetArchitecture(const BString& architecture); - status_t RetrieveRepositoriesForSourceBaseURLs( - const StringList& repositorySourceBaseURL, - BMessage& message); - - status_t RetrievePackageInfo( + status_t GetChangelog( const BString& packageName, - const BString& architecture, - const BString& repositoryCode, - BMessage& message); - - status_t RetrieveBulkPackageInfo( - const StringList& packageNames, - const StringList& packageArchitectures, - const StringList& repositoryCodes, BMessage& message); status_t RetrieveUserRatings(