[haiku-commits] haiku: hrev47956 - in src/apps/haikudepot: ui model

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 2 Oct 2014 22:54:23 +0200 (CEST)

hrev47956 adds 2 changesets to branch 'master'
old head: f262f1b66e32205eff6725ae88a0541bc78fc4f2
new head: b5b717785e8d8d696455844d561f3b47f36a2f9c
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=b5b7177+%5Ef262f1b

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

f532d96: HaikuDepot: Escape strings in the JSON builder
  
  Fixes uploading comments which use any char that needs to be escaped.
  Such as line-breaks, " or \.

b5b7177: HaikuDepot: Specific error for untracked packages
  
  The web service currently only synchronizes with HaikuPorts. Packages
  from 3rd party repositories which were added by the user cannot be rated.
  
  Also, use a warning alert for errors in the UserLoginWindow and
  RatePackageWindow.

                                      [ Stephan Aßmus <superstippi@xxxxxx> ]

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

3 files changed, 32 insertions(+), 13 deletions(-)
src/apps/haikudepot/model/WebAppInterface.cpp | 23 +++++++++++++++++------
src/apps/haikudepot/ui/RatePackageWindow.cpp  | 16 +++++++++++-----
src/apps/haikudepot/ui/UserLoginWindow.cpp    |  6 ++++--

############################################################################

Commit:      f532d965bf9858fabe9681ba20c3e73bf97d26d3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f532d96
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Thu Oct  2 20:41:45 2014 UTC

HaikuDepot: Escape strings in the JSON builder

Fixes uploading comments which use any char that needs to be escaped.
Such as line-breaks, " or \.

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

diff --git a/src/apps/haikudepot/model/WebAppInterface.cpp 
b/src/apps/haikudepot/model/WebAppInterface.cpp
index 9bf7bc7..0fb21f4 100644
--- a/src/apps/haikudepot/model/WebAppInterface.cpp
+++ b/src/apps/haikudepot/model/WebAppInterface.cpp
@@ -91,8 +91,7 @@ public:
                                fString << ",\"";
                        else
                                fString << '"';
-                       // TODO: Escape item
-                       fString << item;
+                       fString << _EscapeString(item);
                        fString << '"';
                }
                fInList = true;
@@ -112,8 +111,7 @@ public:
                        fString << "null";
                } else {
                        fString << '"';
-                       // TODO: Escape value
-                       fString << value;
+                       fString << _EscapeString(value);
                        fString << '"';
                }
                fInList = true;
@@ -152,11 +150,24 @@ private:
                        fString << ",\"";
                else
                        fString << '"';
-               // TODO: Escape name
-               fString << name;
+               fString << _EscapeString(name);
                fString << "\":";
        }
 
+       BString _EscapeString(const char* original) const
+       {
+               BString string(original);
+               string.ReplaceAll("\\", "\\\\");
+               string.ReplaceAll("\"", "\\\"");
+               string.ReplaceAll("/", "\\/");
+               string.ReplaceAll("\b", "\\b");
+               string.ReplaceAll("\f", "\\f");
+               string.ReplaceAll("\n", "\\n");
+               string.ReplaceAll("\r", "\\r");
+               string.ReplaceAll("\t", "\\t");
+               return string;
+       }
+
 private:
        BString         fString;
        bool            fInList;

############################################################################

Revision:    hrev47956
Commit:      b5b717785e8d8d696455844d561f3b47f36a2f9c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b5b7177
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Thu Oct  2 20:55:35 2014 UTC

HaikuDepot: Specific error for untracked packages

The web service currently only synchronizes with HaikuPorts. Packages
from 3rd party repositories which were added by the user cannot be rated.

Also, use a warning alert for errors in the UserLoginWindow and
RatePackageWindow.

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

diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp 
b/src/apps/haikudepot/ui/RatePackageWindow.cpp
index f83e7aa..2f7b908 100644
--- a/src/apps/haikudepot/ui/RatePackageWindow.cpp
+++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp
@@ -503,8 +503,6 @@ RatePackageWindow::_SendRatingThread()
                languageCode, comment, stability, rating, info);
        }
 
-       info.PrintToStream();
-
        BString error = B_TRANSLATE(
                "There was a puzzling response from the web service.");
 
@@ -516,8 +514,15 @@ RatePackageWindow::_SendRatingThread()
                        result.PrintToStream();
                        BString message;
                        if (result.FindString("message", &message) == B_OK) {
-                               error << B_TRANSLATE(" It responded with: ");
-                               error << message;
+                               if (message == "objectnotfound") {
+                                       error = B_TRANSLATE("The package was 
not found by the "
+                                               "web service. This probably 
means that it comes "
+                                               "from a depot which is not 
tracked there. Rating "
+                                               "such packages is unfortunately 
not supported.");
+                               } else {
+                                       error << B_TRANSLATE(" It responded 
with: ");
+                                       error << message;
+                               }
                        }
                }
        } else {
@@ -535,7 +540,8 @@ RatePackageWindow::_SendRatingThread()
                BAlert* alert = new(std::nothrow) BAlert(
                        failedTitle,
                        error,
-                       B_TRANSLATE("Close"));
+                       B_TRANSLATE("Close"), NULL, NULL,
+                       B_WIDTH_AS_USUAL, B_WARNING_ALERT);
 
                if (alert != NULL)
                        alert->Go();
diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp 
b/src/apps/haikudepot/ui/UserLoginWindow.cpp
index 09fda03..f2598e5 100644
--- a/src/apps/haikudepot/ui/UserLoginWindow.cpp
+++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp
@@ -427,7 +427,8 @@ UserLoginWindow::_AuthenticateThread()
                BAlert* alert = new(std::nothrow) BAlert(
                        B_TRANSLATE("Authentication failed"),
                        error,
-                       B_TRANSLATE("Close"));
+                       B_TRANSLATE("Close"), NULL, NULL,
+                       B_WIDTH_AS_USUAL, B_WARNING_ALERT);
 
                if (alert != NULL)
                        alert->Go();
@@ -556,7 +557,8 @@ UserLoginWindow::_CreateAccountThread()
                BAlert* alert = new(std::nothrow) BAlert(
                        B_TRANSLATE("Failed to create account"),
                        error,
-                       B_TRANSLATE("Close"));
+                       B_TRANSLATE("Close"), NULL, NULL,
+                       B_WIDTH_AS_USUAL, B_WARNING_ALERT);
 
                if (alert != NULL)
                        alert->Go();


Other related posts:

  • » [haiku-commits] haiku: hrev47956 - in src/apps/haikudepot: ui model - superstippi