Ticket #12793: 0001-HaikuDepot-populate-the-web-app-repository-code-into-b.patch

File 0001-HaikuDepot-populate-the-web-app-repository-code-into-b.patch, 28.5 KB (added by apl-haiku, 8 years ago)
  • src/apps/haikudepot/model/Model.cpp

    From ba29c92634a0b9ab1a112c00a2f5b7339c14701f 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           | 254 ++++++++++++++++++--------
     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  | 127 +++++++------
     8 files changed, 371 insertions(+), 148 deletions(-)
    
    diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp
    index 289e5e9..8ffa544 100644
    a b  
    11/*
    22 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
    33 * Copyright 2014, Axel Dörfler <axeld@pinc-software.de>.
     4 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    45 * All rights reserved. Distributed under the terms of the MIT License.
    56 */
    67
    Model::AddDepot(const DepotInfo& depot)  
    464465bool
    465466Model::HasDepot(const BString& name) const
    466467{
     468    return NULL != DepotForName(name);
     469}
     470
     471
     472const DepotInfo*
     473Model::DepotForName(const BString& name) const
     474{
    467475    for (int32 i = fDepots.CountItems() - 1; i >= 0; i--) {
    468476        if (fDepots.ItemAtFast(i).Name() == name)
    469             return true;
     477            return &fDepots.ItemAtFast(i);
    470478    }
    471     return false;
     479    return NULL;
    472480}
    473481
    474482
    Model::SetAuthorization(const BString& username, const BString& password,  
    827835
    828836
    829837void
     838Model::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 depot '%s'\n",
     868                        depotInfo.WebAppRepositoryCode().String(),
     869                        depotInfo.Name().String());
     870                } else {
     871                    printf("unable to find the 'code' in the api response for local depot '%s'\n",
     872                        depotInfo.Name().String());
     873                }
     874            } else {
     875                printf("unable to find a repository code for '%s'\n",
     876                    depotInfo.BaseURL().String());
     877            }
     878        } else {
     879            printf("unexpected result obtaining repository code for '%s'\n",
     880                depotInfo.BaseURL().String());
     881        }
     882    } else {
     883        printf("missing base url for depot info %s --> will not obtain web app repository code\n",
     884            depotInfo.Name().String());
     885    }
     886}
     887
     888
     889void
    830890Model::_UpdateIsFeaturedFilter()
    831891{
    832892    if (fShowFeaturedPackages && SearchTerms().IsEmpty())
    Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly,  
    9871047
    9881048    StringList packageNames;
    9891049    StringList packageArchitectures;
     1050    StringList repositoryCodes;
     1051
    9901052    for (int i = 0; i < packages.CountItems(); i++) {
    9911053        const PackageInfoRef& package = packages.ItemAtFast(i);
    9921054        packageNames.Add(package->Name());
    993         packageArchitectures.Add(package->Architecture());
    994     }
    9951055
    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;
     1056        if (!packageArchitectures.Contains(package->Architecture()))
     1057            packageArchitectures.Add(package->Architecture());
    10141058
    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                         }
     1059        const DepotInfo *depot = DepotForName(package->DepotName());
     1060
     1061        if (depot != NULL) {
     1062            BString repositoryCode = depot->WebAppRepositoryCode();
    10381063
    1039                         packages.Remove(i);
    1040                         found = true;
     1064            if (repositoryCode.Length() != 0
     1065                && !repositoryCodes.Contains(repositoryCode)) {
     1066                repositoryCodes.Add(repositoryCode);
     1067            }
     1068        }
     1069    }
     1070
     1071    if (repositoryCodes.CountItems() != 0) {
     1072        status_t status = fWebAppInterface.RetrieveBulkPackageInfo(packageNames,
     1073            packageArchitectures, repositoryCodes, info);
     1074
     1075        if (status == B_OK) {
     1076            // Parse message
     1077    //      info.PrintToStream();
     1078            BMessage result;
     1079            BMessage pkgs;
     1080            if (info.FindMessage("result", &result) == B_OK
     1081                && result.FindMessage("pkgs", &pkgs) == B_OK) {
     1082                int32 index = 0;
     1083                while (true) {
     1084                    if (fStopPopulatingAllPackages)
     1085                        return;
     1086                    BString name;
     1087                    name << index++;
     1088                    BMessage pkgInfo;
     1089                    if (pkgs.FindMessage(name, &pkgInfo) != B_OK)
    10411090                        break;
     1091
     1092                    BString pkgName;
     1093                    if (pkgInfo.FindString("name", &pkgName) != B_OK)
     1094                        continue;
     1095
     1096                    // Find the PackageInfoRef
     1097                    bool found = false;
     1098                    for (int i = 0; i < packages.CountItems(); i++) {
     1099                        const PackageInfoRef& package = packages.ItemAtFast(i);
     1100                        if (pkgName == package->Name()) {
     1101                            _PopulatePackageInfo(package, pkgInfo);
     1102                            if (_HasNativeIcon(pkgInfo))
     1103                                packagesWithIcons.Add(package);
     1104
     1105                            // Store in cache
     1106                            BFile file;
     1107                            BPath path;
     1108                            BString fileName(package->Name());
     1109                            fileName << ".info";
     1110                            if (_GetCacheFile(path, file, B_USER_CACHE_DIRECTORY,
     1111                                    "HaikuDepot", fileName,
     1112                                    B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)) {
     1113                                pkgInfo.Flatten(&file);
     1114                            }
     1115
     1116                            packages.Remove(i);
     1117                            found = true;
     1118                            break;
     1119                        }
    10421120                    }
     1121                    if (!found)
     1122                        printf("No matching package for %s\n", pkgName.String());
    10431123                }
    1044                 if (!found)
    1045                     printf("No matching package for %s\n", pkgName.String());
    10461124            }
    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 chunks
    1053             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);
    10621125        } else {
    1063             while (packages.CountItems() > 0) {
    1064                 const PackageInfoRef& package = packages.ItemAtFast(0);
    1065                 _PopulatePackageInfo(package, fromCacheOnly);
    1066                 packages.Remove(0);
     1126            printf("Error sending request: %s\n", strerror(status));
     1127            int count = packages.CountItems();
     1128            if (count >= 4) {
     1129                // Retry in smaller chunks
     1130                PackageList firstHalf;
     1131                PackageList secondHalf;
     1132                for (int i = 0; i < count / 2; i++)
     1133                    firstHalf.Add(packages.ItemAtFast(i));
     1134                for (int i = count / 2; i < count; i++)
     1135                    secondHalf.Add(packages.ItemAtFast(i));
     1136                packages.Clear();
     1137                _PopulatePackageInfos(firstHalf, fromCacheOnly, packagesWithIcons);
     1138                _PopulatePackageInfos(secondHalf, fromCacheOnly, packagesWithIcons);
     1139            } else {
     1140                while (packages.CountItems() > 0) {
     1141                    const PackageInfoRef& package = packages.ItemAtFast(0);
     1142                    _PopulatePackageInfo(package, fromCacheOnly);
     1143                    packages.Remove(0);
     1144                }
    10671145            }
    10681146        }
    10691147    }
    Model::_PopulatePackageInfo(const PackageInfoRef& package, bool fromCacheOnly)  
    10831161    if (fromCacheOnly)
    10841162        return;
    10851163
    1086     // Retrieve info from web-app
    1087     BMessage info;
     1164    BString repositoryCode;
     1165    const DepotInfo* depot = DepotForName(package->DepotName());
    10881166
    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);
     1167    if (depot != NULL) {
     1168        repositoryCode = depot->WebAppRepositoryCode();
     1169
     1170        if (repositoryCode.Length() > 0) {
     1171            // Retrieve info from web-app
     1172            BMessage info;
     1173
     1174            status_t status = fWebAppInterface.RetrievePackageInfo(
     1175                package->Name(), package->Architecture(), repositoryCode,
     1176                info);
     1177
     1178            if (status == B_OK) {
     1179                // Parse message
     1180        //      info.PrintToStream();
     1181                BMessage result;
     1182                if (info.FindMessage("result", &result) == B_OK)
     1183                    _PopulatePackageInfo(package, result);
     1184            }
     1185        } else {
     1186            printf("unable to find the web app repository code for depot; %s\n",
     1187                package->DepotName().String());
     1188        }
     1189    } else {
     1190        printf("no depot for name; %s\n",
     1191            package->DepotName().String());
    10971192    }
    10981193}
    10991194
    Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)  
    11891284
    11901285        append_word_list(foundInfo, "prominence");
    11911286    }
    1192    
     1287
    11931288    BString changelog;
    11941289    if (data.FindString("pkgChangelogContent", &changelog) == B_OK) {
    11951290        package->SetChangelog(changelog);
    Model::_NotifyAuthorizationChanged()  
    13801475            listener->AuthorizationChanged();
    13811476    }
    13821477}
    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  
    11/*
    22 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
     3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56#ifndef MODEL_H
    public:  
    5657            bool                HasDepot(const BString& name) const;
    5758            const DepotList&    Depots() const
    5859                                    { return fDepots; }
     60            const DepotInfo*    DepotForName(const BString& name) const;
    5961            bool                SyncDepot(const DepotInfo& depot);
    6062
    6163            void                Clear();
    public:  
    115117            bool                ShowDevelopPackages() const
    116118                                    { return fShowDevelopPackages; }
    117119
     120            void                PopulateWebAppRepositoryCode(
     121                                    DepotInfo& depotInfo);
     122
    118123            // Retrieve package information
    119124    static  const uint32        POPULATE_CACHED_RATING  = 1 << 0;
    120125    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  
    11/*
    22 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
    33 * Copyright 2013, Rene Gollent <rene@gollent.com>.
     4 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    45 * All rights reserved. Distributed under the terms of the MIT License.
    56 */
    67
    PackageInfo::SetSize(int64 size)  
    931932}
    932933
    933934
     935void
     936PackageInfo::SetDepotName(const BString& depotName)
     937{
     938    fDepotName = depotName;
     939}
     940
     941
    934942bool
    935943PackageInfo::AddListener(const PackageInfoListenerRef& listener)
    936944{
    PackageInfo::_NotifyListeners(uint32 changes)  
    982990DepotInfo::DepotInfo()
    983991    :
    984992    fName(),
    985     fPackages()
     993    fPackages(),
     994    fWebAppRepositoryCode()
    986995{
    987996}
    988997
    DepotInfo::DepotInfo()  
    990999DepotInfo::DepotInfo(const BString& name)
    9911000    :
    9921001    fName(name),
    993     fPackages()
     1002    fPackages(),
     1003    fWebAppRepositoryCode()
    9941004{
    9951005}
    9961006
    DepotInfo::DepotInfo(const BString& name)  
    9981008DepotInfo::DepotInfo(const DepotInfo& other)
    9991009    :
    10001010    fName(other.fName),
    1001     fPackages(other.fPackages)
     1011    fPackages(other.fPackages),
     1012    fWebAppRepositoryCode(other.fWebAppRepositoryCode),
     1013    fBaseURL(other.fBaseURL)
    10021014{
    10031015}
    10041016
    DepotInfo::operator=(const DepotInfo& other)  
    10081020{
    10091021    fName = other.fName;
    10101022    fPackages = other.fPackages;
     1023    fBaseURL = other.fBaseURL;
     1024    fWebAppRepositoryCode = other.fWebAppRepositoryCode;
    10111025    return *this;
    10121026}
    10131027
    DepotInfo::SyncPackages(const PackageList& otherPackages)  
    10711085    }
    10721086}
    10731087
     1088
     1089void
     1090DepotInfo::SetBaseURL(const BString& baseURL)
     1091{
     1092    fBaseURL = baseURL;
     1093}
     1094
     1095
     1096void
     1097DepotInfo::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  
    11/*
    22 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
     3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56#ifndef PACKAGE_INFO_H
    public:  
    340341            int64               Size() const
    341342                                    { return fSize; }
    342343
     344            void                SetDepotName(const BString& depotName);
     345            const BString&      DepotName() const
     346                                    { return fDepotName; }
     347
    343348            bool                AddListener(
    344349                                    const PackageInfoListenerRef& listener);
    345350            void                RemoveListener(
    private:  
    376381            BString             fLocalFilePath;
    377382            BString             fFileName;
    378383            int64               fSize;
     384            BString             fDepotName;
    379385
    380386    static  BitmapRef           sDefaultIcon;
    381387};
    public:  
    407413
    408414            void                SyncPackages(const PackageList& packages);
    409415
     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
    410424private:
    411425            BString             fName;
    412426            PackageList         fPackages;
     427            BString             fWebAppRepositoryCode;
     428            BString             fBaseURL;
    413429};
    414430
    415431
  • 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  
    11/*
    22 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
     3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56
     
    2627#include "PackageInfo.h"
    2728
    2829
    29 #define CODE_REPOSITORY_DEFAULT "haikuports"
    3030#define BASEURL_DEFAULT "https://depot.haiku-os.org"
    3131#define USERAGENT_FALLBACK_VERSION "0.0.0"
    3232
    WebAppInterface::SetPreferredLanguage(const BString& language)  
    437437
    438438
    439439status_t
     440WebAppInterface::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
     463status_t
    440464WebAppInterface::RetrievePackageInfo(const BString& packageName,
    441     const BString& architecture, BMessage& message)
     465    const BString& architecture, const BString& repositoryCode,
     466    BMessage& message)
    442467{
    443468    BString jsonString = JsonBuilder()
    444469        .AddValue("jsonrpc", "2.0")
    WebAppInterface::RetrievePackageInfo(const BString& packageName,  
    449474                .AddValue("name", packageName)
    450475                .AddValue("architectureCode", architecture)
    451476                .AddValue("naturalLanguageCode", fLanguage)
    452                 .AddValue("repositoryCode", CODE_REPOSITORY_DEFAULT)
     477                .AddValue("repositoryCode", repositoryCode)
    453478                .AddValue("versionType", "NONE")
    454479            .EndObject()
    455480        .EndArray()
    WebAppInterface::RetrievePackageInfo(const BString& packageName,  
    461486
    462487status_t
    463488WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames,
    464     const StringList& packageArchitectures, BMessage& message)
     489    const StringList& packageArchitectures,
     490    const StringList& repositoryCodes, BMessage& message)
    465491{
    466492    BString jsonString = JsonBuilder()
    467493        .AddValue("jsonrpc", "2.0")
    WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames,  
    476502                    .AddStrings(packageArchitectures)
    477503                .EndArray()
    478504                .AddArray("repositoryCodes")
    479                     .AddItem(CODE_REPOSITORY_DEFAULT)
     505                    .AddStrings(repositoryCodes)
    480506                .EndArray()
    481507                .AddValue("naturalLanguageCode", fLanguage)
    482508                .AddValue("versionType", "LATEST")
    WebAppInterface::RetrieveUserRatings(const BString& packageName,  
    552578status_t
    553579WebAppInterface::RetrieveUserRating(const BString& packageName,
    554580    const BPackageVersion& version, const BString& architecture,
    555     const BString& username, BMessage& message)
     581    const BString &repositoryCode, const BString& username,
     582    BMessage& message)
    556583{
    557584    BString jsonString = JsonBuilder()
    558585        .AddValue("jsonrpc", "2.0")
    WebAppInterface::RetrieveUserRating(const BString& packageName,  
    568595                .AddValue("pkgVersionMicro", version.Micro(), true)
    569596                .AddValue("pkgVersionPreRelease", version.PreRelease(), true)
    570597                .AddValue("pkgVersionRevision", (int)version.Revision())
    571                 .AddValue("repositoryCode", CODE_REPOSITORY_DEFAULT)
     598                .AddValue("repositoryCode", repositoryCode)
    572599            .EndObject()
    573600        .EndArray()
    574601    .End();
    WebAppInterface::RetrieveUserRating(const BString& packageName,  
    579606
    580607status_t
    581608WebAppInterface::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)
    585612{
    586613    BString jsonString = JsonBuilder()
    587614        .AddValue("jsonrpc", "2.0")
    WebAppInterface::CreateUserRating(const BString& packageName,  
    596623                .AddValue("rating", rating)
    597624                .AddValue("userRatingStabilityCode", stability, true)
    598625                .AddValue("comment", comment)
    599                 .AddValue("repositoryCode", CODE_REPOSITORY_DEFAULT)
     626                .AddValue("repositoryCode", repositoryCode)
    600627                .AddValue("naturalLanguageCode", languageCode)
    601628            .EndObject()
    602629        .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  
    11/*
    22 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
     3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56#ifndef WEB_APP_INTERFACE_H
    public:  
    3738            void                SetPreferredLanguage(const BString& language);
    3839            void                SetArchitecture(const BString& architecture);
    3940
     41            status_t            RetrieveRepositoriesForSourceBaseURLs(
     42                                    const StringList& repositorySourceBaseURL,
     43                                    BMessage& message);
     44
    4045            status_t            RetrievePackageInfo(
    4146                                    const BString& packageName,
    4247                                    const BString& architecture,
     48                                    const BString& repositoryCode,
    4349                                    BMessage& message);
    4450
    4551            status_t            RetrieveBulkPackageInfo(
    4652                                    const StringList& packageNames,
    4753                                    const StringList& packageArchitectures,
     54                                    const StringList& repositoryCodes,
    4855                                    BMessage& message);
    4956
    5057            status_t            RetrievePackageIcon(
    public:  
    6168                                    const BString& packageName,
    6269                                    const BPackageVersion& version,
    6370                                    const BString& architecture,
     71                                    const BString& repositoryCode,
    6472                                    const BString& username,
    6573                                    BMessage& message);
    6674
    6775            status_t            CreateUserRating(
    6876                                    const BString& packageName,
    6977                                    const BString& architecture,
     78                                    const BString& repositoryCode,
    7079                                    const BString& languageCode,
    7180                                    const BString& comment,
    7281                                    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  
    33 * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
    44 * Copyright 2013, Rene Gollent, rene@gollent.com.
    55 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
     6 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    67 * All rights reserved. Distributed under the terms of the MIT License.
    78 */
    89
    MainWindow::_RefreshPackageList(bool force)  
    834835    DepotInfoMap depots;
    835836    for (int32 i = 0; i < repositoryNames.CountStrings(); i++) {
    836837        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;
    838858    }
    839859
    840860    PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME);
    MainWindow::_RefreshPackageList(bool force)  
    891911    for (int32 i = 0; i < packages.CountItems(); i++) {
    892912        BSolverPackage* package = packages.ItemAt(i);
    893913        const BPackageInfo& repoPackageInfo = package->Info();
     914        const BString repositoryName = package->Repository()->Name();
    894915        PackageInfoRef modelInfo;
    895916        PackageInfoMap::iterator it = foundPackages.find(
    896917            repoPackageInfo.Name());
    MainWindow::_RefreshPackageList(bool force)  
    904925            if (modelInfo.Get() == NULL)
    905926                return;
    906927
     928            modelInfo->SetDepotName(repositoryName);
     929
    907930            foundPackages[repoPackageInfo.Name()] = modelInfo;
    908931        }
    909932
    MainWindow::_ShowScreenshot()  
    12441267
    12451268    fScreenshotWindow->Unlock();
    12461269}
    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..a90ea12 100644
    a b  
    11/*
    22 * Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
     3 * Copyright 2016, Andrew Lindesay <apl@lindesay.co.nz>.
    34 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56
    RatePackageWindow::_QueryRatingThread()  
    408409
    409410    WebAppInterface interface;
    410411    BMessage info;
     412    const DepotInfo* depot = fModel.DepotForName(package->DepotName());
     413    BString repositoryCode;
    411414
    412     status_t status = interface.RetrieveUserRating(
    413         package->Name(), package->Version(), package->Architecture(),
    414         username, info);
     415    if (depot != NULL)
     416        repositoryCode = depot->WebAppRepositoryCode();
    415417
    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                    }
    439450                }
     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);
    440466            }
    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         }
    457467
    458         fRatingActiveCheckBox->SetValue(fRatingActive);
    459         fRatingActiveCheckBox->Show();
     468            fRatingActiveCheckBox->SetValue(fRatingActive);
     469            fRatingActiveCheckBox->Show();
    460470
    461         fSendButton->SetLabel(B_TRANSLATE("Update"));
     471            fSendButton->SetLabel(B_TRANSLATE("Update"));
    462472
    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        }
    469480    }
    470481
    471482    _SetWorkerThread(-1);
    RatePackageWindow::_SendRatingThread()  
    491502
    492503    BString package = fPackage->Name();
    493504    BString architecture = fPackage->Architecture();
     505    BString repositoryCode;
    494506    int rating = (int)fRating;
    495507    BString stability = fStability;
    496508    BString comment = fRatingText->Text();
    RatePackageWindow::_SendRatingThread()  
    498510    BString ratingID = fRatingID;
    499511    bool active = fRatingActive;
    500512
     513    const DepotInfo* depot = fModel.DepotForName(fPackage->DepotName());
     514
     515    if (depot != NULL)
     516        repositoryCode = depot->WebAppRepositoryCode();
     517
    501518    WebAppInterface interface = fModel.GetWebAppInterface();
    502519
    503520    Unlock();
    504521
     522    if (repositoryCode.Length() == 0) {
     523        printf("unable to find the web app repository code for the local depot %s\n",
     524            fPackage->DepotName().String());
     525        return;
     526    }
     527
    505528    if (stability == "unspecified")
    506529        stability = "";
    507530
    RatePackageWindow::_SendRatingThread()  
    512535        languageCode, comment, stability, rating, active, info);
    513536    } else {
    514537        status = interface.CreateUserRating(package, architecture,
    515         languageCode, comment, stability, rating, info);
     538            repositoryCode, languageCode, comment, stability, rating, info);
    516539    }
    517540
    518541    BString error = B_TRANSLATE(