Ticket #12793: 0001-HaikuDepot-populate-the-web-app-repository-code-into.patch
File 0001-HaikuDepot-populate-the-web-app-repository-code-into.patch, 28.6 KB (added by , 8 years ago) |
---|
-
src/apps/haikudepot/model/Model.cpp
From f4623ea684a747fe175683c7fb57682840ae85e3 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] 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 | 263 ++++++++++++++++++-------- 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 | 26 ++- src/apps/haikudepot/ui/RatePackageWindow.cpp | 128 ++++++++----- 8 files changed, 381 insertions(+), 148 deletions(-) diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index 289e5e9..2fed66c 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 859 if (result.FindMessage("items", &repositories) == B_OK) { 860 int32 index = 0; 861 while (true) { 862 BString name; 863 name << index++; 864 BMessage repository; 865 if (repositories.FindMessage(name, &repository) != B_OK) 866 break; 867 868 BString repositoryCode; 869 if (repository.FindString("code", &repositoryCode) != B_OK) 870 continue; 871 872 depotInfo.SetWebAppRepositoryCode(repositoryCode); 873 874 printf("did assign web app repository code '%s' to local depot '%s'\n", 875 depotInfo.WebAppRepositoryCode().String(), 876 depotInfo.Name().String()); 877 } 878 } else { 879 printf("unable to find the 'items' in the api response for local depot '%s'\n", 880 depotInfo.Name().String()); 881 } 882 } else { 883 printf("unable to find a repository code for '%s'\n", 884 depotInfo.BaseURL().String()); 885 } 886 } else { 887 printf("unexpected result obtaining repository code for '%s'\n", 888 depotInfo.BaseURL().String()); 889 } 890 } else { 891 printf("missing base url for depot info %s --> will not obtain web app repository code\n", 892 depotInfo.Name().String()); 893 } 894 } 895 896 897 void 830 898 Model::_UpdateIsFeaturedFilter() 831 899 { 832 900 if (fShowFeaturedPackages && SearchTerms().IsEmpty()) … … Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly, 987 1055 988 1056 StringList packageNames; 989 1057 StringList packageArchitectures; 1058 StringList repositoryCodes; 1059 990 1060 for (int i = 0; i < packages.CountItems(); i++) { 991 1061 const PackageInfoRef& package = packages.ItemAtFast(i); 992 1062 packageNames.Add(package->Name()); 993 packageArchitectures.Add(package->Architecture());994 }995 1063 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; 1064 if (!packageArchitectures.Contains(package->Architecture())) 1065 packageArchitectures.Add(package->Architecture()); 1014 1066 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 } 1067 const DepotInfo *depot = DepotForName(package->DepotName()); 1038 1068 1039 packages.Remove(i); 1040 found = true; 1069 if (NULL != depot) { 1070 BString repositoryCode = depot->WebAppRepositoryCode(); 1071 1072 if (0 != repositoryCode.Length() 1073 && !repositoryCodes.Contains(repositoryCode)) { 1074 repositoryCodes.Add(repositoryCode); 1075 } 1076 } 1077 } 1078 1079 if (0 != repositoryCodes.CountItems()) { 1080 status_t status = fWebAppInterface.RetrieveBulkPackageInfo(packageNames, 1081 packageArchitectures, repositoryCodes, info); 1082 1083 if (status == B_OK) { 1084 // Parse message 1085 // info.PrintToStream(); 1086 BMessage result; 1087 BMessage pkgs; 1088 if (info.FindMessage("result", &result) == B_OK 1089 && result.FindMessage("pkgs", &pkgs) == B_OK) { 1090 int32 index = 0; 1091 while (true) { 1092 if (fStopPopulatingAllPackages) 1093 return; 1094 BString name; 1095 name << index++; 1096 BMessage pkgInfo; 1097 if (pkgs.FindMessage(name, &pkgInfo) != B_OK) 1041 1098 break; 1099 1100 BString pkgName; 1101 if (pkgInfo.FindString("name", &pkgName) != B_OK) 1102 continue; 1103 1104 // Find the PackageInfoRef 1105 bool found = false; 1106 for (int i = 0; i < packages.CountItems(); i++) { 1107 const PackageInfoRef& package = packages.ItemAtFast(i); 1108 if (pkgName == package->Name()) { 1109 _PopulatePackageInfo(package, pkgInfo); 1110 if (_HasNativeIcon(pkgInfo)) 1111 packagesWithIcons.Add(package); 1112 1113 // Store in cache 1114 BFile file; 1115 BPath path; 1116 BString fileName(package->Name()); 1117 fileName << ".info"; 1118 if (_GetCacheFile(path, file, B_USER_CACHE_DIRECTORY, 1119 "HaikuDepot", fileName, 1120 B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)) { 1121 pkgInfo.Flatten(&file); 1122 } 1123 1124 packages.Remove(i); 1125 found = true; 1126 break; 1127 } 1042 1128 } 1129 if (!found) 1130 printf("No matching package for %s\n", pkgName.String()); 1043 1131 } 1044 if (!found)1045 printf("No matching package for %s\n", pkgName.String());1046 1132 } 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 1133 } else { 1063 while (packages.CountItems() > 0) { 1064 const PackageInfoRef& package = packages.ItemAtFast(0); 1065 _PopulatePackageInfo(package, fromCacheOnly); 1066 packages.Remove(0); 1134 printf("Error sending request: %s\n", strerror(status)); 1135 int count = packages.CountItems(); 1136 if (count >= 4) { 1137 // Retry in smaller chunks 1138 PackageList firstHalf; 1139 PackageList secondHalf; 1140 for (int i = 0; i < count / 2; i++) 1141 firstHalf.Add(packages.ItemAtFast(i)); 1142 for (int i = count / 2; i < count; i++) 1143 secondHalf.Add(packages.ItemAtFast(i)); 1144 packages.Clear(); 1145 _PopulatePackageInfos(firstHalf, fromCacheOnly, packagesWithIcons); 1146 _PopulatePackageInfos(secondHalf, fromCacheOnly, packagesWithIcons); 1147 } else { 1148 while (packages.CountItems() > 0) { 1149 const PackageInfoRef& package = packages.ItemAtFast(0); 1150 _PopulatePackageInfo(package, fromCacheOnly); 1151 packages.Remove(0); 1152 } 1067 1153 } 1068 1154 } 1069 1155 } … … Model::_PopulatePackageInfo(const PackageInfoRef& package, bool fromCacheOnly) 1083 1169 if (fromCacheOnly) 1084 1170 return; 1085 1171 1086 // Retrieve info from web-app1087 BMessage info;1172 BString repositoryCode; 1173 const DepotInfo* depot = DepotForName(package->DepotName()); 1088 1174 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); 1175 if (NULL != depot) { 1176 repositoryCode = depot->WebAppRepositoryCode(); 1177 1178 if (repositoryCode.Length() > 0) { 1179 // Retrieve info from web-app 1180 BMessage info; 1181 1182 status_t status = fWebAppInterface.RetrievePackageInfo( 1183 package->Name(), package->Architecture(), repositoryCode, 1184 info); 1185 1186 if (status == B_OK) { 1187 // Parse message 1188 // info.PrintToStream(); 1189 BMessage result; 1190 if (info.FindMessage("result", &result) == B_OK) 1191 _PopulatePackageInfo(package, result); 1192 } 1193 } 1194 else { 1195 printf("unable to find the web app repository code for depot; %s\n", 1196 package->DepotName().String()); 1197 } 1198 } else { 1199 printf("no depot for name; %s\n", 1200 package->DepotName().String()); 1097 1201 } 1098 1202 } 1099 1203 … … Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data) 1189 1293 1190 1294 append_word_list(foundInfo, "prominence"); 1191 1295 } 1192 1296 1193 1297 BString changelog; 1194 1298 if (data.FindString("pkgChangelogContent", &changelog) == B_OK) { 1195 1299 package->SetChangelog(changelog); … … Model::_NotifyAuthorizationChanged() 1380 1484 listener->AuthorizationChanged(); 1381 1485 } 1382 1486 } 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..addf626 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 repository '%s'; %s\n", 854 repoName.String(), strerror(getRepositoryConfigStatus)); 855 } 856 857 depots[repoName] = depotInfo; 838 858 } 839 859 840 860 PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME); … … MainWindow::_RefreshPackageList(bool force) 891 911 for (int32 i = 0; i < packages.CountItems(); i++) { 892 912 BSolverPackage* package = packages.ItemAt(i); 893 913 const BPackageInfo& repoPackageInfo = package->Info(); 914 const BString repositoryName = package->Repository()->Name(); 894 915 PackageInfoRef modelInfo; 895 916 PackageInfoMap::iterator it = foundPackages.find( 896 917 repoPackageInfo.Name()); … … MainWindow::_RefreshPackageList(bool force) 904 925 if (modelInfo.Get() == NULL) 905 926 return; 906 927 928 modelInfo->SetDepotName(repositoryName); 929 907 930 foundPackages[repoPackageInfo.Name()] = modelInfo; 908 931 } 909 932 … … MainWindow::_ShowScreenshot() 1244 1267 1245 1268 fScreenshotWindow->Unlock(); 1246 1269 } 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..090cf09 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 (0 == repositoryCode.Length()) { 419 printf("unable to obtain the repository code for depot; %s\n", 420 package->DepotName().String()); 421 } 422 else { 423 status_t status = interface.RetrieveUserRating( 424 package->Name(), package->Version(), package->Architecture(), 425 repositoryCode, username, info); 426 427 // info.PrintToStream(); 428 429 BMessage result; 430 if (status == B_OK && info.FindMessage("result", &result) == B_OK 431 && Lock()) { 432 433 result.FindString("code", &fRatingID); 434 result.FindBool("active", &fRatingActive); 435 BString comment; 436 if (result.FindString("comment", &comment) == B_OK) { 437 MarkupParser parser; 438 fRatingText = parser.CreateDocumentFromMarkup(comment); 439 fTextView->SetTextDocument(fRatingText); 440 } 441 if (result.FindString("userRatingStabilityCode", 442 &fStability) == B_OK) { 443 int32 index = 0; 444 for (int32 i = fStabilityCodes.CountItems() - 1; i >= 0; i--) { 445 const StabilityRating& stability 446 = fStabilityCodes.ItemAtFast(i); 447 if (stability.Name() == fStability) { 448 index = i; 449 break; 450 } 439 451 } 452 BMenuItem* item = fStabilityField->Menu()->ItemAt(index); 453 if (item != NULL) 454 item->SetMarked(true); 455 } 456 if (result.FindString("naturalLanguageCode", 457 &fCommentLanguage) == B_OK) { 458 BMenuItem* item = fCommentLanguageField->Menu()->ItemAt( 459 fModel.SupportedLanguages().IndexOf(fCommentLanguage)); 460 if (item != NULL) 461 item->SetMarked(true); 462 } 463 double rating; 464 if (result.FindDouble("rating", &rating) == B_OK) { 465 fRating = (float)rating; 466 fSetRatingView->SetPermanentRating(fRating); 440 467 } 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 468 458 fRatingActiveCheckBox->SetValue(fRatingActive);459 fRatingActiveCheckBox->Show();469 fRatingActiveCheckBox->SetValue(fRatingActive); 470 fRatingActiveCheckBox->Show(); 460 471 461 fSendButton->SetLabel(B_TRANSLATE("Update"));472 fSendButton->SetLabel(B_TRANSLATE("Update")); 462 473 463 Unlock(); 464 } else { 465 fprintf(stderr, "rating query: Failed response: %s\n", 466 strerror(status)); 467 if (!info.IsEmpty()) 468 info.PrintToStream(); 474 Unlock(); 475 } else { 476 fprintf(stderr, "rating query: Failed response: %s\n", 477 strerror(status)); 478 if (!info.IsEmpty()) 479 info.PrintToStream(); 480 } 469 481 } 470 482 471 483 _SetWorkerThread(-1); … … RatePackageWindow::_SendRatingThread() 491 503 492 504 BString package = fPackage->Name(); 493 505 BString architecture = fPackage->Architecture(); 506 BString repositoryCode; 494 507 int rating = (int)fRating; 495 508 BString stability = fStability; 496 509 BString comment = fRatingText->Text(); … … RatePackageWindow::_SendRatingThread() 498 511 BString ratingID = fRatingID; 499 512 bool active = fRatingActive; 500 513 514 const DepotInfo* depot = fModel.DepotForName(fPackage->DepotName()); 515 516 if (NULL != depot) 517 repositoryCode = depot->WebAppRepositoryCode(); 518 501 519 WebAppInterface interface = fModel.GetWebAppInterface(); 502 520 503 521 Unlock(); 504 522 523 if (repositoryCode.Length() == 0) { 524 printf("unable to find the web app repository code for the local 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(