[haiku-commits] haiku: hrev47802 - src/apps/haikudepot

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 3 Sep 2014 22:53:59 +0200 (CEST)

hrev47802 adds 1 changeset to branch 'master'
old head: 5fa80ab69177a235fb4cb9cb71922bca5211799e
new head: 2b411c028e4ad624ed34805f3d76d327c5190211
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=2b411c0+%5E5fa80ab

----------------------------------------------------------------------------

2b411c0: HaikuDepot: Update for web-app API changes.
  
   * Category identifyers are lower-case, we can use the "name" facility which
     already existed for this purpose and simply iterate the list of known
     categories.
   * The getBulkPkg method now takes the architectures as a list as well,
     helps with finding the right package in case there is a mix of
     architectures across the requested package names.

                                      [ Stephan Aßmus <superstippi@xxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47802
Commit:      2b411c028e4ad624ed34805f3d76d327c5190211
URL:         http://cgit.haiku-os.org/haiku/commit/?id=2b411c0
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Wed Sep  3 20:54:04 2014 UTC

----------------------------------------------------------------------------

3 files changed, 21 insertions(+), 31 deletions(-)
src/apps/haikudepot/Model.cpp           | 45 ++++++++++-------------------
src/apps/haikudepot/WebAppInterface.cpp |  6 ++--
src/apps/haikudepot/WebAppInterface.h   |  1 +

----------------------------------------------------------------------------

diff --git a/src/apps/haikudepot/Model.cpp b/src/apps/haikudepot/Model.cpp
index 80623d5..b0259bc 100644
--- a/src/apps/haikudepot/Model.cpp
+++ b/src/apps/haikudepot/Model.cpp
@@ -321,6 +321,10 @@ Model::Model()
        fCategories.Add(fCategoryInternetAndNetwork);
        fCategories.Add(fCategoryDevelopment);
        fCategories.Add(fCategoryScienceAndMathematics);
+       // TODO: The server will eventually support an API to
+       // get the defined categories and their translated names.
+       // This should then be used instead of hard-coded
+       // categories and translations in the app.
 
        // A category for packages that the user installed.
        fUserCategories.Add(CategoryRef(new PackageCategory(
@@ -688,12 +692,15 @@ Model::_PopulatePackageInfos(PackageList& packages, bool 
fromCacheOnly,
        BMessage info;
 
        StringList packageNames;
+       StringList packageArchitectures;
        for (int i = 0; i < packages.CountItems(); i++) {
                const PackageInfoRef& package = packages.ItemAtFast(i);
                packageNames.Add(package->Title());
+               packageArchitectures.Add(package->Architecture());
        }
 
-       status_t status = interface.RetrieveBulkPackageInfo(packageNames, info);
+       status_t status = interface.RetrieveBulkPackageInfo(packageNames,
+               packageArchitectures, info);
        if (status == B_OK) {
                // Parse message
 //             info.PrintToStream();
@@ -835,34 +842,14 @@ Model::_PopulatePackageInfo(const PackageInfoRef& 
package, const BMessage& data)
                        if (categories.FindString(name, &category) != B_OK)
                                break;
 
-                       if (category == "AUDIO")
-                               package->AddCategory(CategoryAudio());
-                       else if (category == "BUSINESS")
-                               package->AddCategory(CategoryBusiness());
-                       else if (category == "DEVELOPMENT")
-                               package->AddCategory(CategoryDevelopment());
-                       else if (category == "EDUCATION")
-                               package->AddCategory(CategoryEducation());
-                       else if (category == "GAMES")
-                               package->AddCategory(CategoryGames());
-                       else if (category == "GRAPHICS")
-                               package->AddCategory(CategoryGraphics());
-                       else if (category == "INTERNETANDNETWORK")
-                               
package->AddCategory(CategoryInternetAndNetwork());
-                       else if (category == "PRODUCTIVITY")
-                               package->AddCategory(CategoryProductivity());
-                       else if (category == "SCIENCEANDMATHEMATICS")
-                               
package->AddCategory(CategoryScienceAndMathematics());
-                       else if (category == "SYSTEMANDUTILITIES")
-                               
package->AddCategory(CategorySystemAndUtilities());
-                       else if (category == "VIDEO")
-                               package->AddCategory(CategoryVideo());
-                       // TODO: The server will eventually support an API to
-                       // get the defined categories and their translated 
names.
-                       // This should then be used instead of hard-coded
-                       // categories and translations in the app.
-               
-                       foundCategory = true;
+                       for (int i = fCategories.CountItems() - 1; i >= 0; i--) 
{
+                               const CategoryRef& categoryRef = 
fCategories.ItemAtFast(i);
+                               if (categoryRef->Name() == category) {
+                                       package->AddCategory(categoryRef);
+                                       foundCategory = true;
+                                       break;
+                               }
+                       }
                }
                if (foundCategory)
                        append_word_list(foundInfo, "categories");
diff --git a/src/apps/haikudepot/WebAppInterface.cpp 
b/src/apps/haikudepot/WebAppInterface.cpp
index 1160f2c..1461cca 100644
--- a/src/apps/haikudepot/WebAppInterface.cpp
+++ b/src/apps/haikudepot/WebAppInterface.cpp
@@ -285,7 +285,7 @@ WebAppInterface::RetrievePackageInfo(const BString& 
packageName,
 
 status_t
 WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames,
-       BMessage& message)
+       const StringList& packageArchitectures, BMessage& message)
 {
        BString jsonString = JsonBuilder()
                .AddValue("jsonrpc", "2.0")
@@ -296,7 +296,9 @@ WebAppInterface::RetrieveBulkPackageInfo(const StringList& 
packageNames,
                                .AddArray("pkgNames")
                                        .AddStrings(packageNames)
                                .EndArray()
-                               .AddValue("architectureCode", "x86_gcc2")
+                               .AddArray("architectureCodes")
+                                       .AddStrings(packageArchitectures)
+                               .EndArray()
                                .AddValue("naturalLanguageCode", fLanguage)
                                .AddValue("versionType", "LATEST")
                                .AddArray("filter")
diff --git a/src/apps/haikudepot/WebAppInterface.h 
b/src/apps/haikudepot/WebAppInterface.h
index e829f08..3a034d2 100644
--- a/src/apps/haikudepot/WebAppInterface.h
+++ b/src/apps/haikudepot/WebAppInterface.h
@@ -35,6 +35,7 @@ public:
 
                        status_t                        RetrieveBulkPackageInfo(
                                                                        const 
StringList& packageNames,
+                                                                       const 
StringList& packageArchitectures,
                                                                        
BMessage& message);
 
                        status_t                        RetrievePackageIcon(


Other related posts:

  • » [haiku-commits] haiku: hrev47802 - src/apps/haikudepot - superstippi