Ticket #12793: 0001-HaikuDepot-populate-the-web-app-repository-code-into-b2.patch
File 0001-HaikuDepot-populate-the-web-app-repository-code-into-b2.patch, 28.5 KB (added by , 8 years ago) |
---|
-
src/apps/haikudepot/model/Model.cpp
From ec266dd83d237da3fe2461438f380e6317a0f40b Mon Sep 17 00:00:00 2001 From: Andrew Lindesay <apl@lindesay.co.nz> Date: Mon, 5 Sep 2016 23:07:50 +1200 Subject: [PATCH 1/1] HaikuDepot: populate the web app repository code into data structures and use it when making api calls to the web app --- src/apps/haikudepot/model/Model.cpp | 255 ++++++++++++++++++-------- src/apps/haikudepot/model/Model.h | 5 + src/apps/haikudepot/model/PackageInfo.cpp | 33 +++- src/apps/haikudepot/model/PackageInfo.h | 16 ++ src/apps/haikudepot/model/WebAppInterface.cpp | 49 +++-- src/apps/haikudepot/model/WebAppInterface.h | 9 + src/apps/haikudepot/ui/MainWindow.cpp | 27 ++- src/apps/haikudepot/ui/RatePackageWindow.cpp | 128 +++++++------ 8 files changed, 374 insertions(+), 148 deletions(-) diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index 289e5e9..342d5ef 100644
a b 1 1 /* 2 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 3 * Copyright 2014, Axel Dörfler <axeld@pinc-software.de>. 4 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 4 5 * All rights reserved. Distributed under the terms of the MIT License. 5 6 */ 6 7 … … Model::AddDepot(const DepotInfo& depot) 464 465 bool 465 466 Model::HasDepot(const BString& name) const 466 467 { 468 return NULL != DepotForName(name); 469 } 470 471 472 const DepotInfo* 473 Model::DepotForName(const BString& name) const 474 { 467 475 for (int32 i = fDepots.CountItems() - 1; i >= 0; i--) { 468 476 if (fDepots.ItemAtFast(i).Name() == name) 469 return true;477 return &fDepots.ItemAtFast(i); 470 478 } 471 return false;479 return NULL; 472 480 } 473 481 474 482 … … Model::SetAuthorization(const BString& username, const BString& password, 827 835 828 836 829 837 void 838 Model::PopulateWebAppRepositoryCode(DepotInfo& depotInfo) 839 { 840 if (depotInfo.BaseURL().Length() > 0) { 841 842 BMessage repositoriesEnvelope; 843 BMessage result; 844 double total; 845 StringList repositorySourceBaseURLs; 846 847 repositorySourceBaseURLs.Add(depotInfo.BaseURL()); 848 849 // TODO; better API call handling around errors. 850 851 if (fWebAppInterface.RetrieveRepositoriesForSourceBaseURLs( 852 repositorySourceBaseURLs, repositoriesEnvelope) == B_OK 853 && repositoriesEnvelope.FindMessage("result", &result) == B_OK 854 && result.FindDouble("total", &total) == B_OK) { 855 856 if ((int64) total > 0) { 857 BMessage repositories; 858 BMessage repository; 859 BString repositoryCode; 860 861 if (result.FindMessage("items", &repositories) == B_OK 862 && repositories.FindMessage("0", &repository) == B_OK 863 && repository.FindString("code", &repositoryCode) == B_OK) { 864 865 depotInfo.SetWebAppRepositoryCode(repositoryCode); 866 867 printf("did assign web app repository code '%s' to local " 868 "depot '%s'\n", 869 depotInfo.WebAppRepositoryCode().String(), 870 depotInfo.Name().String()); 871 } else { 872 printf("unable to find the 'code' in the api response for local depot '%s'\n", 873 depotInfo.Name().String()); 874 } 875 } else { 876 printf("unable to find a repository code for '%s'\n", 877 depotInfo.BaseURL().String()); 878 } 879 } else { 880 printf("unexpected result obtaining repository code for '%s'\n", 881 depotInfo.BaseURL().String()); 882 } 883 } else { 884 printf("missing base url for depot info %s --> will not obtain web app repository code\n", 885 depotInfo.Name().String()); 886 } 887 } 888 889 890 void 830 891 Model::_UpdateIsFeaturedFilter() 831 892 { 832 893 if (fShowFeaturedPackages && SearchTerms().IsEmpty()) … … Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly, 987 1048 988 1049 StringList packageNames; 989 1050 StringList packageArchitectures; 1051 StringList repositoryCodes; 1052 990 1053 for (int i = 0; i < packages.CountItems(); i++) { 991 1054 const PackageInfoRef& package = packages.ItemAtFast(i); 992 1055 packageNames.Add(package->Name()); 993 packageArchitectures.Add(package->Architecture());994 }995 1056 996 status_t status = fWebAppInterface.RetrieveBulkPackageInfo(packageNames, 997 packageArchitectures, info); 998 if (status == B_OK) { 999 // Parse message 1000 // info.PrintToStream(); 1001 BMessage result; 1002 BMessage pkgs; 1003 if (info.FindMessage("result", &result) == B_OK 1004 && result.FindMessage("pkgs", &pkgs) == B_OK) { 1005 int32 index = 0; 1006 while (true) { 1007 if (fStopPopulatingAllPackages) 1008 return; 1009 BString name; 1010 name << index++; 1011 BMessage pkgInfo; 1012 if (pkgs.FindMessage(name, &pkgInfo) != B_OK) 1013 break; 1057 if (!packageArchitectures.Contains(package->Architecture())) 1058 packageArchitectures.Add(package->Architecture()); 1014 1059 1015 BString pkgName; 1016 if (pkgInfo.FindString("name", &pkgName) != B_OK) 1017 continue; 1018 1019 // Find the PackageInfoRef 1020 bool found = false; 1021 for (int i = 0; i < packages.CountItems(); i++) { 1022 const PackageInfoRef& package = packages.ItemAtFast(i); 1023 if (pkgName == package->Name()) { 1024 _PopulatePackageInfo(package, pkgInfo); 1025 if (_HasNativeIcon(pkgInfo)) 1026 packagesWithIcons.Add(package); 1027 1028 // Store in cache 1029 BFile file; 1030 BPath path; 1031 BString fileName(package->Name()); 1032 fileName << ".info"; 1033 if (_GetCacheFile(path, file, B_USER_CACHE_DIRECTORY, 1034 "HaikuDepot", fileName, 1035 B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)) { 1036 pkgInfo.Flatten(&file); 1037 } 1060 const DepotInfo *depot = DepotForName(package->DepotName()); 1061 1062 if (depot != NULL) { 1063 BString repositoryCode = depot->WebAppRepositoryCode(); 1038 1064 1039 packages.Remove(i); 1040 found = true; 1065 if (repositoryCode.Length() != 0 1066 && !repositoryCodes.Contains(repositoryCode)) { 1067 repositoryCodes.Add(repositoryCode); 1068 } 1069 } 1070 } 1071 1072 if (repositoryCodes.CountItems() != 0) { 1073 status_t status = fWebAppInterface.RetrieveBulkPackageInfo(packageNames, 1074 packageArchitectures, repositoryCodes, info); 1075 1076 if (status == B_OK) { 1077 // Parse message 1078 // info.PrintToStream(); 1079 BMessage result; 1080 BMessage pkgs; 1081 if (info.FindMessage("result", &result) == B_OK 1082 && result.FindMessage("pkgs", &pkgs) == B_OK) { 1083 int32 index = 0; 1084 while (true) { 1085 if (fStopPopulatingAllPackages) 1086 return; 1087 BString name; 1088 name << index++; 1089 BMessage pkgInfo; 1090 if (pkgs.FindMessage(name, &pkgInfo) != B_OK) 1041 1091 break; 1092 1093 BString pkgName; 1094 if (pkgInfo.FindString("name", &pkgName) != B_OK) 1095 continue; 1096 1097 // Find the PackageInfoRef 1098 bool found = false; 1099 for (int i = 0; i < packages.CountItems(); i++) { 1100 const PackageInfoRef& package = packages.ItemAtFast(i); 1101 if (pkgName == package->Name()) { 1102 _PopulatePackageInfo(package, pkgInfo); 1103 if (_HasNativeIcon(pkgInfo)) 1104 packagesWithIcons.Add(package); 1105 1106 // Store in cache 1107 BFile file; 1108 BPath path; 1109 BString fileName(package->Name()); 1110 fileName << ".info"; 1111 if (_GetCacheFile(path, file, B_USER_CACHE_DIRECTORY, 1112 "HaikuDepot", fileName, 1113 B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)) { 1114 pkgInfo.Flatten(&file); 1115 } 1116 1117 packages.Remove(i); 1118 found = true; 1119 break; 1120 } 1042 1121 } 1122 if (!found) 1123 printf("No matching package for %s\n", pkgName.String()); 1043 1124 } 1044 if (!found)1045 printf("No matching package for %s\n", pkgName.String());1046 1125 } 1047 }1048 } else {1049 printf("Error sending request: %s\n", strerror(status));1050 int count = packages.CountItems();1051 if (count >= 4) {1052 // Retry in smaller chunks1053 PackageList firstHalf;1054 PackageList secondHalf;1055 for (int i = 0; i < count / 2; i++)1056 firstHalf.Add(packages.ItemAtFast(i));1057 for (int i = count / 2; i < count; i++)1058 secondHalf.Add(packages.ItemAtFast(i));1059 packages.Clear();1060 _PopulatePackageInfos(firstHalf, fromCacheOnly, packagesWithIcons);1061 _PopulatePackageInfos(secondHalf, fromCacheOnly, packagesWithIcons);1062 1126 } else { 1063 while (packages.CountItems() > 0) { 1064 const PackageInfoRef& package = packages.ItemAtFast(0); 1065 _PopulatePackageInfo(package, fromCacheOnly); 1066 packages.Remove(0); 1127 printf("Error sending request: %s\n", strerror(status)); 1128 int count = packages.CountItems(); 1129 if (count >= 4) { 1130 // Retry in smaller chunks 1131 PackageList firstHalf; 1132 PackageList secondHalf; 1133 for (int i = 0; i < count / 2; i++) 1134 firstHalf.Add(packages.ItemAtFast(i)); 1135 for (int i = count / 2; i < count; i++) 1136 secondHalf.Add(packages.ItemAtFast(i)); 1137 packages.Clear(); 1138 _PopulatePackageInfos(firstHalf, fromCacheOnly, packagesWithIcons); 1139 _PopulatePackageInfos(secondHalf, fromCacheOnly, packagesWithIcons); 1140 } else { 1141 while (packages.CountItems() > 0) { 1142 const PackageInfoRef& package = packages.ItemAtFast(0); 1143 _PopulatePackageInfo(package, fromCacheOnly); 1144 packages.Remove(0); 1145 } 1067 1146 } 1068 1147 } 1069 1148 } … … Model::_PopulatePackageInfo(const PackageInfoRef& package, bool fromCacheOnly) 1083 1162 if (fromCacheOnly) 1084 1163 return; 1085 1164 1086 // Retrieve info from web-app1087 BMessage info;1165 BString repositoryCode; 1166 const DepotInfo* depot = DepotForName(package->DepotName()); 1088 1167 1089 status_t status = fWebAppInterface.RetrievePackageInfo(package->Name(), 1090 package->Architecture(), info); 1091 if (status == B_OK) { 1092 // Parse message 1093 // info.PrintToStream(); 1094 BMessage result; 1095 if (info.FindMessage("result", &result) == B_OK) 1096 _PopulatePackageInfo(package, result); 1168 if (depot != NULL) { 1169 repositoryCode = depot->WebAppRepositoryCode(); 1170 1171 if (repositoryCode.Length() > 0) { 1172 // Retrieve info from web-app 1173 BMessage info; 1174 1175 status_t status = fWebAppInterface.RetrievePackageInfo( 1176 package->Name(), package->Architecture(), repositoryCode, 1177 info); 1178 1179 if (status == B_OK) { 1180 // Parse message 1181 // info.PrintToStream(); 1182 BMessage result; 1183 if (info.FindMessage("result", &result) == B_OK) 1184 _PopulatePackageInfo(package, result); 1185 } 1186 } else { 1187 printf("unable to find the web app repository code for depot; %s\n", 1188 package->DepotName().String()); 1189 } 1190 } else { 1191 printf("no depot for name; %s\n", 1192 package->DepotName().String()); 1097 1193 } 1098 1194 } 1099 1195 … … Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data) 1189 1285 1190 1286 append_word_list(foundInfo, "prominence"); 1191 1287 } 1192 1288 1193 1289 BString changelog; 1194 1290 if (data.FindString("pkgChangelogContent", &changelog) == B_OK) { 1195 1291 package->SetChangelog(changelog); … … Model::_NotifyAuthorizationChanged() 1380 1476 listener->AuthorizationChanged(); 1381 1477 } 1382 1478 } 1383 -
src/apps/haikudepot/model/Model.h
diff --git a/src/apps/haikudepot/model/Model.h b/src/apps/haikudepot/model/Model.h index 36454a9..253cc43 100644
a b 1 1 /* 2 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 3 4 * All rights reserved. Distributed under the terms of the MIT License. 4 5 */ 5 6 #ifndef MODEL_H … … public: 56 57 bool HasDepot(const BString& name) const; 57 58 const DepotList& Depots() const 58 59 { return fDepots; } 60 const DepotInfo* DepotForName(const BString& name) const; 59 61 bool SyncDepot(const DepotInfo& depot); 60 62 61 63 void Clear(); … … public: 115 117 bool ShowDevelopPackages() const 116 118 { return fShowDevelopPackages; } 117 119 120 void PopulateWebAppRepositoryCode( 121 DepotInfo& depotInfo); 122 118 123 // Retrieve package information 119 124 static const uint32 POPULATE_CACHED_RATING = 1 << 0; 120 125 static const uint32 POPULATE_CACHED_ICON = 1 << 1; -
src/apps/haikudepot/model/PackageInfo.cpp
diff --git a/src/apps/haikudepot/model/PackageInfo.cpp b/src/apps/haikudepot/model/PackageInfo.cpp index 4befa8f..973daf8 100644
a b 1 1 /* 2 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 3 * Copyright 2013, Rene Gollent <rene@gollent.com>. 4 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 4 5 * All rights reserved. Distributed under the terms of the MIT License. 5 6 */ 6 7 … … PackageInfo::SetSize(int64 size) 931 932 } 932 933 933 934 935 void 936 PackageInfo::SetDepotName(const BString& depotName) 937 { 938 fDepotName = depotName; 939 } 940 941 934 942 bool 935 943 PackageInfo::AddListener(const PackageInfoListenerRef& listener) 936 944 { … … PackageInfo::_NotifyListeners(uint32 changes) 982 990 DepotInfo::DepotInfo() 983 991 : 984 992 fName(), 985 fPackages() 993 fPackages(), 994 fWebAppRepositoryCode() 986 995 { 987 996 } 988 997 … … DepotInfo::DepotInfo() 990 999 DepotInfo::DepotInfo(const BString& name) 991 1000 : 992 1001 fName(name), 993 fPackages() 1002 fPackages(), 1003 fWebAppRepositoryCode() 994 1004 { 995 1005 } 996 1006 … … DepotInfo::DepotInfo(const BString& name) 998 1008 DepotInfo::DepotInfo(const DepotInfo& other) 999 1009 : 1000 1010 fName(other.fName), 1001 fPackages(other.fPackages) 1011 fPackages(other.fPackages), 1012 fWebAppRepositoryCode(other.fWebAppRepositoryCode), 1013 fBaseURL(other.fBaseURL) 1002 1014 { 1003 1015 } 1004 1016 … … DepotInfo::operator=(const DepotInfo& other) 1008 1020 { 1009 1021 fName = other.fName; 1010 1022 fPackages = other.fPackages; 1023 fBaseURL = other.fBaseURL; 1024 fWebAppRepositoryCode = other.fWebAppRepositoryCode; 1011 1025 return *this; 1012 1026 } 1013 1027 … … DepotInfo::SyncPackages(const PackageList& otherPackages) 1071 1085 } 1072 1086 } 1073 1087 1088 1089 void 1090 DepotInfo::SetBaseURL(const BString& baseURL) 1091 { 1092 fBaseURL = baseURL; 1093 } 1094 1095 1096 void 1097 DepotInfo::SetWebAppRepositoryCode(const BString& code) 1098 { 1099 fWebAppRepositoryCode = code; 1100 } -
src/apps/haikudepot/model/PackageInfo.h
diff --git a/src/apps/haikudepot/model/PackageInfo.h b/src/apps/haikudepot/model/PackageInfo.h index 61480fa..c611e0b 100644
a b 1 1 /* 2 2 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 3 4 * All rights reserved. Distributed under the terms of the MIT License. 4 5 */ 5 6 #ifndef PACKAGE_INFO_H … … public: 340 341 int64 Size() const 341 342 { return fSize; } 342 343 344 void SetDepotName(const BString& depotName); 345 const BString& DepotName() const 346 { return fDepotName; } 347 343 348 bool AddListener( 344 349 const PackageInfoListenerRef& listener); 345 350 void RemoveListener( … … private: 376 381 BString fLocalFilePath; 377 382 BString fFileName; 378 383 int64 fSize; 384 BString fDepotName; 379 385 380 386 static BitmapRef sDefaultIcon; 381 387 }; … … public: 407 413 408 414 void SyncPackages(const PackageList& packages); 409 415 416 void SetBaseURL(const BString& baseURL); 417 const BString& BaseURL() const 418 { return fBaseURL; } 419 420 void SetWebAppRepositoryCode(const BString& code); 421 const BString& WebAppRepositoryCode() const 422 { return fWebAppRepositoryCode; } 423 410 424 private: 411 425 BString fName; 412 426 PackageList fPackages; 427 BString fWebAppRepositoryCode; 428 BString fBaseURL; 413 429 }; 414 430 415 431 -
src/apps/haikudepot/model/WebAppInterface.cpp
diff --git a/src/apps/haikudepot/model/WebAppInterface.cpp b/src/apps/haikudepot/model/WebAppInterface.cpp index 3469ec1..1fabbe5 100644
a b 1 1 /* 2 2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 3 4 * All rights reserved. Distributed under the terms of the MIT License. 4 5 */ 5 6 … … 26 27 #include "PackageInfo.h" 27 28 28 29 29 #define CODE_REPOSITORY_DEFAULT "haikuports"30 30 #define BASEURL_DEFAULT "https://depot.haiku-os.org" 31 31 #define USERAGENT_FALLBACK_VERSION "0.0.0" 32 32 … … WebAppInterface::SetPreferredLanguage(const BString& language) 437 437 438 438 439 439 status_t 440 WebAppInterface::RetrieveRepositoriesForSourceBaseURLs( 441 const StringList& repositorySourceBaseURLs, 442 BMessage& message) 443 { 444 BString jsonString = JsonBuilder() 445 .AddValue("jsonrpc", "2.0") 446 .AddValue("id", ++fRequestIndex) 447 .AddValue("method", "searchRepositories") 448 .AddArray("params") 449 .AddObject() 450 .AddArray("repositorySourceSearchUrls") 451 .AddStrings(repositorySourceBaseURLs) 452 .EndArray() 453 .AddValue("offset", 0) 454 .AddValue("limit", 1000) // effectively a safety limit 455 .EndObject() 456 .EndArray() 457 .End(); 458 459 return _SendJsonRequest("repository", jsonString, 0, message); 460 } 461 462 463 status_t 440 464 WebAppInterface::RetrievePackageInfo(const BString& packageName, 441 const BString& architecture, BMessage& message) 465 const BString& architecture, const BString& repositoryCode, 466 BMessage& message) 442 467 { 443 468 BString jsonString = JsonBuilder() 444 469 .AddValue("jsonrpc", "2.0") … … WebAppInterface::RetrievePackageInfo(const BString& packageName, 449 474 .AddValue("name", packageName) 450 475 .AddValue("architectureCode", architecture) 451 476 .AddValue("naturalLanguageCode", fLanguage) 452 .AddValue("repositoryCode", CODE_REPOSITORY_DEFAULT)477 .AddValue("repositoryCode", repositoryCode) 453 478 .AddValue("versionType", "NONE") 454 479 .EndObject() 455 480 .EndArray() … … WebAppInterface::RetrievePackageInfo(const BString& packageName, 461 486 462 487 status_t 463 488 WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames, 464 const StringList& packageArchitectures, BMessage& message) 489 const StringList& packageArchitectures, 490 const StringList& repositoryCodes, BMessage& message) 465 491 { 466 492 BString jsonString = JsonBuilder() 467 493 .AddValue("jsonrpc", "2.0") … … WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames, 476 502 .AddStrings(packageArchitectures) 477 503 .EndArray() 478 504 .AddArray("repositoryCodes") 479 .Add Item(CODE_REPOSITORY_DEFAULT)505 .AddStrings(repositoryCodes) 480 506 .EndArray() 481 507 .AddValue("naturalLanguageCode", fLanguage) 482 508 .AddValue("versionType", "LATEST") … … WebAppInterface::RetrieveUserRatings(const BString& packageName, 552 578 status_t 553 579 WebAppInterface::RetrieveUserRating(const BString& packageName, 554 580 const BPackageVersion& version, const BString& architecture, 555 const BString& username, BMessage& message) 581 const BString &repositoryCode, const BString& username, 582 BMessage& message) 556 583 { 557 584 BString jsonString = JsonBuilder() 558 585 .AddValue("jsonrpc", "2.0") … … WebAppInterface::RetrieveUserRating(const BString& packageName, 568 595 .AddValue("pkgVersionMicro", version.Micro(), true) 569 596 .AddValue("pkgVersionPreRelease", version.PreRelease(), true) 570 597 .AddValue("pkgVersionRevision", (int)version.Revision()) 571 .AddValue("repositoryCode", CODE_REPOSITORY_DEFAULT)598 .AddValue("repositoryCode", repositoryCode) 572 599 .EndObject() 573 600 .EndArray() 574 601 .End(); … … WebAppInterface::RetrieveUserRating(const BString& packageName, 579 606 580 607 status_t 581 608 WebAppInterface::CreateUserRating(const BString& packageName, 582 const BString& architecture, const BString& languageCode,583 const BString& comment, const BString& stability, int rating,584 BMessage& message)609 const BString& architecture, const BString& repositoryCode, 610 const BString& languageCode, const BString& comment, 611 const BString& stability, int rating, BMessage& message) 585 612 { 586 613 BString jsonString = JsonBuilder() 587 614 .AddValue("jsonrpc", "2.0") … … WebAppInterface::CreateUserRating(const BString& packageName, 596 623 .AddValue("rating", rating) 597 624 .AddValue("userRatingStabilityCode", stability, true) 598 625 .AddValue("comment", comment) 599 .AddValue("repositoryCode", CODE_REPOSITORY_DEFAULT)626 .AddValue("repositoryCode", repositoryCode) 600 627 .AddValue("naturalLanguageCode", languageCode) 601 628 .EndObject() 602 629 .EndArray() -
src/apps/haikudepot/model/WebAppInterface.h
diff --git a/src/apps/haikudepot/model/WebAppInterface.h b/src/apps/haikudepot/model/WebAppInterface.h index f5fffec..04cf67f 100644
a b 1 1 /* 2 2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 3 4 * All rights reserved. Distributed under the terms of the MIT License. 4 5 */ 5 6 #ifndef WEB_APP_INTERFACE_H … … public: 37 38 void SetPreferredLanguage(const BString& language); 38 39 void SetArchitecture(const BString& architecture); 39 40 41 status_t RetrieveRepositoriesForSourceBaseURLs( 42 const StringList& repositorySourceBaseURL, 43 BMessage& message); 44 40 45 status_t RetrievePackageInfo( 41 46 const BString& packageName, 42 47 const BString& architecture, 48 const BString& repositoryCode, 43 49 BMessage& message); 44 50 45 51 status_t RetrieveBulkPackageInfo( 46 52 const StringList& packageNames, 47 53 const StringList& packageArchitectures, 54 const StringList& repositoryCodes, 48 55 BMessage& message); 49 56 50 57 status_t RetrievePackageIcon( … … public: 61 68 const BString& packageName, 62 69 const BPackageVersion& version, 63 70 const BString& architecture, 71 const BString& repositoryCode, 64 72 const BString& username, 65 73 BMessage& message); 66 74 67 75 status_t CreateUserRating( 68 76 const BString& packageName, 69 77 const BString& architecture, 78 const BString& repositoryCode, 70 79 const BString& languageCode, 71 80 const BString& comment, 72 81 const BString& stability, -
src/apps/haikudepot/ui/MainWindow.cpp
diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index b9f7529..8884f54 100644
a b 3 3 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. 4 4 * Copyright 2013, Rene Gollent, rene@gollent.com. 5 5 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. 6 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 6 7 * All rights reserved. Distributed under the terms of the MIT License. 7 8 */ 8 9 … … MainWindow::_RefreshPackageList(bool force) 834 835 DepotInfoMap depots; 835 836 for (int32 i = 0; i < repositoryNames.CountStrings(); i++) { 836 837 const BString& repoName = repositoryNames.StringAt(i); 837 depots[repoName] = DepotInfo(repoName); 838 DepotInfo depotInfo = DepotInfo(repoName); 839 840 BRepositoryConfig repoConfig; 841 status_t getRepositoryConfigStatus = roster.GetRepositoryConfig( 842 repoName, &repoConfig); 843 844 if (getRepositoryConfigStatus == B_OK) { 845 depotInfo.SetBaseURL(repoConfig.BaseURL()); 846 847 // it would be nice if this could be more logically located such as 848 // when the repository is added to the model, but that is probably 849 // a bigger change. 850 851 fModel.PopulateWebAppRepositoryCode(depotInfo); 852 } else { 853 printf("unable to obtain the repository config for local " 854 "repository '%s'; %s\n", 855 repoName.String(), strerror(getRepositoryConfigStatus)); 856 } 857 858 depots[repoName] = depotInfo; 838 859 } 839 860 840 861 PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME); … … MainWindow::_RefreshPackageList(bool force) 891 912 for (int32 i = 0; i < packages.CountItems(); i++) { 892 913 BSolverPackage* package = packages.ItemAt(i); 893 914 const BPackageInfo& repoPackageInfo = package->Info(); 915 const BString repositoryName = package->Repository()->Name(); 894 916 PackageInfoRef modelInfo; 895 917 PackageInfoMap::iterator it = foundPackages.find( 896 918 repoPackageInfo.Name()); … … MainWindow::_RefreshPackageList(bool force) 904 926 if (modelInfo.Get() == NULL) 905 927 return; 906 928 929 modelInfo->SetDepotName(repositoryName); 930 907 931 foundPackages[repoPackageInfo.Name()] = modelInfo; 908 932 } 909 933 … … MainWindow::_ShowScreenshot() 1244 1268 1245 1269 fScreenshotWindow->Unlock(); 1246 1270 } 1247 -
src/apps/haikudepot/ui/RatePackageWindow.cpp
diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp b/src/apps/haikudepot/ui/RatePackageWindow.cpp index 2d0bca6..7ce247b 100644
a b 1 1 /* 2 2 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>. 3 4 * All rights reserved. Distributed under the terms of the MIT License. 4 5 */ 5 6 … … RatePackageWindow::_QueryRatingThread() 408 409 409 410 WebAppInterface interface; 410 411 BMessage info; 412 const DepotInfo* depot = fModel.DepotForName(package->DepotName()); 413 BString repositoryCode; 411 414 412 status_t status = interface.RetrieveUserRating( 413 package->Name(), package->Version(), package->Architecture(), 414 username, info); 415 if (depot != NULL) 416 repositoryCode = depot->WebAppRepositoryCode(); 415 417 416 // info.PrintToStream(); 417 418 BMessage result; 419 if (status == B_OK && info.FindMessage("result", &result) == B_OK 420 && Lock()) { 421 422 result.FindString("code", &fRatingID); 423 result.FindBool("active", &fRatingActive); 424 BString comment; 425 if (result.FindString("comment", &comment) == B_OK) { 426 MarkupParser parser; 427 fRatingText = parser.CreateDocumentFromMarkup(comment); 428 fTextView->SetTextDocument(fRatingText); 429 } 430 if (result.FindString("userRatingStabilityCode", 431 &fStability) == B_OK) { 432 int32 index = 0; 433 for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) { 434 const StabilityRating& stability 435 = fStabilityCodes.ItemAtFast(i); 436 if (stability.Name() == fStability) { 437 index = i; 438 break; 418 if (repositoryCode.Length() == 0) { 419 printf("unable to obtain the repository code for depot; %s\n", 420 package->DepotName().String()); 421 } else { 422 status_t status = interface.RetrieveUserRating( 423 package->Name(), package->Version(), package->Architecture(), 424 repositoryCode, username, info); 425 426 // info.PrintToStream(); 427 428 BMessage result; 429 if (status == B_OK && info.FindMessage("result", &result) == B_OK 430 && Lock()) { 431 432 result.FindString("code", &fRatingID); 433 result.FindBool("active", &fRatingActive); 434 BString comment; 435 if (result.FindString("comment", &comment) == B_OK) { 436 MarkupParser parser; 437 fRatingText = parser.CreateDocumentFromMarkup(comment); 438 fTextView->SetTextDocument(fRatingText); 439 } 440 if (result.FindString("userRatingStabilityCode", 441 &fStability) == B_OK) { 442 int32 index = 0; 443 for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) { 444 const StabilityRating& stability 445 = fStabilityCodes.ItemAtFast(i); 446 if (stability.Name() == fStability) { 447 index = i; 448 break; 449 } 439 450 } 451 BMenuItem* item = fStabilityField->Menu()->ItemAt(index); 452 if (item != NULL) 453 item->SetMarked(true); 454 } 455 if (result.FindString("naturalLanguageCode", 456 &fCommentLanguage) == B_OK) { 457 BMenuItem* item = fCommentLanguageField->Menu()->ItemAt( 458 fModel.SupportedLanguages().IndexOf(fCommentLanguage)); 459 if (item != NULL) 460 item->SetMarked(true); 461 } 462 double rating; 463 if (result.FindDouble("rating", &rating) == B_OK) { 464 fRating = (float)rating; 465 fSetRatingView->SetPermanentRating(fRating); 440 466 } 441 BMenuItem* item = fStabilityField->Menu()->ItemAt(index);442 if (item != NULL)443 item->SetMarked(true);444 }445 if (result.FindString("naturalLanguageCode",446 &fCommentLanguage) == B_OK) {447 BMenuItem* item = fCommentLanguageField->Menu()->ItemAt(448 fModel.SupportedLanguages().IndexOf(fCommentLanguage));449 if (item != NULL)450 item->SetMarked(true);451 }452 double rating;453 if (result.FindDouble("rating", &rating) == B_OK) {454 fRating = (float)rating;455 fSetRatingView->SetPermanentRating(fRating);456 }457 467 458 fRatingActiveCheckBox->SetValue(fRatingActive);459 fRatingActiveCheckBox->Show();468 fRatingActiveCheckBox->SetValue(fRatingActive); 469 fRatingActiveCheckBox->Show(); 460 470 461 fSendButton->SetLabel(B_TRANSLATE("Update"));471 fSendButton->SetLabel(B_TRANSLATE("Update")); 462 472 463 Unlock(); 464 } else { 465 fprintf(stderr, "rating query: Failed response: %s\n", 466 strerror(status)); 467 if (!info.IsEmpty()) 468 info.PrintToStream(); 473 Unlock(); 474 } else { 475 fprintf(stderr, "rating query: Failed response: %s\n", 476 strerror(status)); 477 if (!info.IsEmpty()) 478 info.PrintToStream(); 479 } 469 480 } 470 481 471 482 _SetWorkerThread(-1); … … RatePackageWindow::_SendRatingThread() 491 502 492 503 BString package = fPackage->Name(); 493 504 BString architecture = fPackage->Architecture(); 505 BString repositoryCode; 494 506 int rating = (int)fRating; 495 507 BString stability = fStability; 496 508 BString comment = fRatingText->Text(); … … RatePackageWindow::_SendRatingThread() 498 510 BString ratingID = fRatingID; 499 511 bool active = fRatingActive; 500 512 513 const DepotInfo* depot = fModel.DepotForName(fPackage->DepotName()); 514 515 if (depot != NULL) 516 repositoryCode = depot->WebAppRepositoryCode(); 517 501 518 WebAppInterface interface = fModel.GetWebAppInterface(); 502 519 503 520 Unlock(); 504 521 522 if (repositoryCode.Length() == 0) { 523 printf("unable to find the web app repository code for the local " 524 "depot %s\n", 525 fPackage->DepotName().String()); 526 return; 527 } 528 505 529 if (stability == "unspecified") 506 530 stability = ""; 507 531 … … RatePackageWindow::_SendRatingThread() 512 536 languageCode, comment, stability, rating, active, info); 513 537 } else { 514 538 status = interface.CreateUserRating(package, architecture, 515 languageCode, comment, stability, rating, info);539 repositoryCode, languageCode, comment, stability, rating, info); 516 540 } 517 541 518 542 BString error = B_TRANSLATE(