[haiku-commits] haiku: hrev49009 - in src: apps/haikudepot/ui bin/desklink apps/haikudepot/ui_generic apps/haikudepot/model

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 8 Apr 2015 11:16:52 +0200 (CEST)

hrev49009 adds 5 changesets to branch 'master'
old head: 6ea53cb5bbd588a1c417fedfc4208c108cb63a50
new head: 2a36368bda35aed7210c3285019b286581fc8786
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=2a36368bda35+%5E6ea53cb5bbd5

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

77c35db9a9c8: desklink: Whitespace cleanup only.

5c7707fc3450: desklink: Use early return, no functional change.

8708474567be: HaikuDepot: Clean up trailing whitespace.

3525a370d459: HaikuDepot: Add missing init of fSize in default constructor.

2a36368bda35: HaikuDepot: Make BitmapView use SharedBitmaps directly.

Instead of extracting a BBitmap out of the SharedBitmap and giving that
to BitmapView, set SharedBitmaps directly. When using BBitmaps we
circumvent the reference counting of the SharedBitmaps and it would be
possible for the SharedBitmap and its BBitmaps to get deleted while
one of them was still used in a BitmapView.

Fixes use-after-free when icons are updated that are already used in
BitmapViews.

[ Michael Lotz <mmlr@xxxxxxxx> ]

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

29 files changed, 274 insertions(+), 248 deletions(-)
src/apps/haikudepot/List.h | 2 +-
src/apps/haikudepot/model/Model.cpp | 44 +++++++-------
src/apps/haikudepot/model/PackageInfo.cpp | 9 +--
src/apps/haikudepot/model/PackageInfo.h | 2 +-
src/apps/haikudepot/model/WebAppInterface.cpp | 40 ++++++-------
.../haikudepot/textview/CharacterStyleData.h | 2 +-
src/apps/haikudepot/textview/Paragraph.cpp | 8 +--
src/apps/haikudepot/textview/ParagraphLayout.cpp | 4 +-
src/apps/haikudepot/textview/TextDocument.cpp | 26 ++++----
.../haikudepot/textview/TextDocumentLayout.cpp | 18 +++---
.../haikudepot/textview/TextDocumentView.cpp | 20 +++----
src/apps/haikudepot/textview/TextEditor.cpp | 12 ++--
src/apps/haikudepot/ui/App.cpp | 10 ++--
src/apps/haikudepot/ui/FeaturedPackagesView.cpp | 31 +++++-----
src/apps/haikudepot/ui/FeaturedPackagesView.h | 2 +-
src/apps/haikudepot/ui/FilterView.cpp | 6 +-
src/apps/haikudepot/ui/MainWindow.cpp | 18 +++---
.../haikudepot/ui/MessagePackageListener.cpp | 2 +-
src/apps/haikudepot/ui/PackageContentsView.cpp | 16 ++---
src/apps/haikudepot/ui/PackageInfoView.cpp | 63 ++++++++++----------
src/apps/haikudepot/ui/RatePackageWindow.cpp | 28 ++++-----
src/apps/haikudepot/ui/ScreenshotWindow.cpp | 14 ++---
src/apps/haikudepot/ui/UserLoginWindow.cpp | 45 +++++++-------
src/apps/haikudepot/ui_generic/BitmapView.cpp | 22 ++++++-
src/apps/haikudepot/ui_generic/BitmapView.h | 9 ++-
src/apps/haikudepot/ui_generic/LinkView.cpp | 2 +-
.../ui_generic/ScrollableGroupView.cpp | 4 +-
src/apps/haikudepot/ui_generic/SharedBitmap.cpp | 8 +--
src/bin/desklink/VolumeControl.cpp | 55 ++++++++---------

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

Commit: 77c35db9a9c877f78426cde33b0614ccbc6e2927
URL: http://cgit.haiku-os.org/haiku/commit/?id=77c35db9a9c8
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Sun Apr 5 19:24:22 2015 UTC

desklink: Whitespace cleanup only.

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

diff --git a/src/bin/desklink/VolumeControl.cpp
b/src/bin/desklink/VolumeControl.cpp
index 8983830..db2e1a4 100644
--- a/src/bin/desklink/VolumeControl.cpp
+++ b/src/bin/desklink/VolumeControl.cpp
@@ -300,33 +300,33 @@ VolumeControl::MessageReceived(BMessage* msg)
if (msg->FindString("be:signature", &signature) != B_OK)
break;

- bool isMediaServer = !strcmp(signature, kMediaServerSignature);
- bool isAddOnServer = !strcmp(signature, kAddOnServerSignature);
- if (isMediaServer)
- fMediaServerRunning = msg->what == B_SOME_APP_LAUNCHED;
- if (isAddOnServer)
- fAddOnServerRunning = msg->what == B_SOME_APP_LAUNCHED;
-
- if (isMediaServer || isAddOnServer) {
- if (!fMediaServerRunning && !fAddOnServerRunning) {
+ bool isMediaServer = !strcmp(signature,
kMediaServerSignature);
+ bool isAddOnServer = !strcmp(signature,
kAddOnServerSignature);
+ if (isMediaServer)
+ fMediaServerRunning = msg->what ==
B_SOME_APP_LAUNCHED;
+ if (isAddOnServer)
+ fAddOnServerRunning = msg->what ==
B_SOME_APP_LAUNCHED;
+
+ if (isMediaServer || isAddOnServer) {
+ if (!fMediaServerRunning &&
!fAddOnServerRunning) {
// No media server around
SetLabel(B_TRANSLATE("No media server
running"));
SetEnabled(false);
- } else if (fMediaServerRunning && fAddOnServerRunning) {
- // HACK!
- // quit our now invalid instance of the media roster
- // so that before new nodes are created,
- // we get a new roster
- BMediaRoster* roster = BMediaRoster::CurrentRoster();
- if (roster != NULL) {
- roster->Lock();
- roster->Quit();
- }
+ } else if (fMediaServerRunning &&
fAddOnServerRunning) {
+ // HACK!
+ // quit our now invalid instance of the
media roster
+ // so that before new nodes are created,
+ // we get a new roster
+ BMediaRoster* roster =
BMediaRoster::CurrentRoster();
+ if (roster != NULL) {
+ roster->Lock();
+ roster->Quit();
+ }

BMessage reconnect(kMsgReconnectVolume);
BMessageRunner::StartSending(this,
&reconnect, 1000000LL, 1);
fConnectRetries = 3;
- }
+ }
}
break;
}

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

Commit: 5c7707fc3450712f2465ad0d59d54066869387bb
URL: http://cgit.haiku-os.org/haiku/commit/?id=5c7707fc3450
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Sun Apr 5 19:25:09 2015 UTC

desklink: Use early return, no functional change.

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

diff --git a/src/bin/desklink/VolumeControl.cpp
b/src/bin/desklink/VolumeControl.cpp
index db2e1a4..bcb8f75 100644
--- a/src/bin/desklink/VolumeControl.cpp
+++ b/src/bin/desklink/VolumeControl.cpp
@@ -302,31 +302,32 @@ VolumeControl::MessageReceived(BMessage* msg)

bool isMediaServer = !strcmp(signature,
kMediaServerSignature);
bool isAddOnServer = !strcmp(signature,
kAddOnServerSignature);
+ if (!isMediaServer && !isAddOnServer)
+ break;
+
if (isMediaServer)
fMediaServerRunning = msg->what ==
B_SOME_APP_LAUNCHED;
if (isAddOnServer)
fAddOnServerRunning = msg->what ==
B_SOME_APP_LAUNCHED;

- if (isMediaServer || isAddOnServer) {
- if (!fMediaServerRunning &&
!fAddOnServerRunning) {
- // No media server around
- SetLabel(B_TRANSLATE("No media server
running"));
- SetEnabled(false);
- } else if (fMediaServerRunning &&
fAddOnServerRunning) {
- // HACK!
- // quit our now invalid instance of the
media roster
- // so that before new nodes are created,
- // we get a new roster
- BMediaRoster* roster =
BMediaRoster::CurrentRoster();
- if (roster != NULL) {
- roster->Lock();
- roster->Quit();
- }
-
- BMessage reconnect(kMsgReconnectVolume);
- BMessageRunner::StartSending(this,
&reconnect, 1000000LL, 1);
- fConnectRetries = 3;
+ if (!fMediaServerRunning && !fAddOnServerRunning) {
+ // No media server around
+ SetLabel(B_TRANSLATE("No media server
running"));
+ SetEnabled(false);
+ } else if (fMediaServerRunning && fAddOnServerRunning) {
+ // HACK!
+ // quit our now invalid instance of the media
roster
+ // so that before new nodes are created,
+ // we get a new roster
+ BMediaRoster* roster =
BMediaRoster::CurrentRoster();
+ if (roster != NULL) {
+ roster->Lock();
+ roster->Quit();
}
+
+ BMessage reconnect(kMsgReconnectVolume);
+ BMessageRunner::StartSending(this, &reconnect,
1000000LL, 1);
+ fConnectRetries = 3;
}
break;
}

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

Commit: 8708474567be756984f35cd6c5bfcc2c9546dc1e
URL: http://cgit.haiku-os.org/haiku/commit/?id=8708474567be
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Tue Apr 7 18:50:57 2015 UTC

HaikuDepot: Clean up trailing whitespace.

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

diff --git a/src/apps/haikudepot/List.h b/src/apps/haikudepot/List.h
index bf31048..a8d2829 100644
--- a/src/apps/haikudepot/List.h
+++ b/src/apps/haikudepot/List.h
@@ -99,7 +99,7 @@ public:
{
_Resize(0);
}
-
+
inline bool IsEmpty() const
{
return fCount == 0;
diff --git a/src/apps/haikudepot/model/Model.cpp
b/src/apps/haikudepot/model/Model.cpp
index 74b0f45..5ad94c6 100644
--- a/src/apps/haikudepot/model/Model.cpp
+++ b/src/apps/haikudepot/model/Model.cpp
@@ -660,13 +660,13 @@ Model::PopulatePackage(const PackageInfoRef& package,
uint32 flags)
BMessage info;

BString packageName;
- BString architecture;
+ BString architecture;
{
BAutolock locker(&fLock);
packageName = package->Name();
architecture = package->Architecture();
}
-
+
status_t status =
fWebAppInterface.RetrieveUserRatings(packageName,
architecture, 0, 50, info);
if (status == B_OK) {
@@ -683,7 +683,7 @@ Model::PopulatePackage(const PackageInfoRef& package,
uint32 flags)
while (true) {
BString name;
name << index++;
-
+
BMessage item;
if (items.FindMessage(name, &item) !=
B_OK)
break;
@@ -831,7 +831,7 @@ Model::_UpdateIsFeaturedFilter()
{
if (fShowFeaturedPackages && SearchTerms().IsEmpty())
fIsFeaturedFilter = PackageFilterRef(new IsFeaturedFilter(),
true);
- else
+ else
fIsFeaturedFilter = PackageFilterRef(new AnyFilter(), true);
}

@@ -860,7 +860,7 @@ Model::_PopulateAllPackagesThread(bool fromCacheOnly)
PackageInfoRef package;
{
BAutolock locker(&fLock);
-
+
if (depotIndex >= fDepots.CountItems())
break;
const DepotInfo& depot = fDepots.ItemAt(depotIndex);
@@ -872,14 +872,14 @@ Model::_PopulateAllPackagesThread(bool fromCacheOnly)
depotIndex++;
continue;
}
-
+
package = packages.ItemAt(packageIndex);
packageIndex++;
}
-
+
if (package.Get() == NULL)
continue;
-
+
//_PopulatePackageInfo(package, fromCacheOnly);
bulkPackageList.Add(package);
if (bulkPackageList.CountItems() == 50) {
@@ -954,7 +954,7 @@ Model::_PopulatePackageInfos(PackageList& packages, bool
fromCacheOnly,
{
if (fStopPopulatingAllPackages)
return;
-
+
// See if there are cached info files
for (int i = packages.CountItems() - 1; i >= 0; i--) {
if (fStopPopulatingAllPackages)
@@ -978,10 +978,10 @@ Model::_PopulatePackageInfos(PackageList& packages, bool
fromCacheOnly,
}
}
}
-
+
if (fromCacheOnly || packages.IsEmpty())
return;
-
+
// Retrieve info from web-app
BMessage info;

@@ -1011,11 +1011,11 @@ Model::_PopulatePackageInfos(PackageList& packages,
bool fromCacheOnly,
BMessage pkgInfo;
if (pkgs.FindMessage(name, &pkgInfo) != B_OK)
break;
-
+
BString pkgName;
if (pkgInfo.FindString("name", &pkgName) !=
B_OK)
continue;
-
+
// Find the PackageInfoRef
bool found = false;
for (int i = 0; i < packages.CountItems(); i++)
{
@@ -1082,7 +1082,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef&
package, bool fromCacheOnly)
{
if (fromCacheOnly)
return;
-
+
// Retrieve info from web-app
BMessage info;

@@ -1104,7 +1104,7 @@ append_word_list(BString& words, const char* word)
if (words.Length() > 0)
words << ", ";
words << word;
-}
+}


void
@@ -1173,7 +1173,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef&
package, const BMessage& data)
if (foundCategory)
append_word_list(foundInfo, "categories");
}
-
+
double derivedRating;
if (data.FindDouble("derivedRating", &derivedRating) == B_OK) {
RatingSummary summary;
@@ -1182,14 +1182,14 @@ Model::_PopulatePackageInfo(const PackageInfoRef&
package, const BMessage& data)

append_word_list(foundInfo, "rating");
}
-
+
double prominenceOrdering;
if (data.FindDouble("prominenceOrdering", &prominenceOrdering) == B_OK)
{
package->SetProminence(prominenceOrdering);

append_word_list(foundInfo, "prominence");
}
-
+
BMessage screenshots;
if (data.FindMessage("pkgScreenshots", &screenshots) == B_OK) {
package->ClearScreenshotInfos();
@@ -1198,7 +1198,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef&
package, const BMessage& data)
while (true) {
BString name;
name << index++;
-
+
BMessage screenshot;
if (screenshots.FindMessage(name, &screenshot) != B_OK)
break;
@@ -1219,7 +1219,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef&
package, const BMessage& data)
if (foundScreenshot)
append_word_list(foundInfo, "screenshots");
}
-
+
if (foundInfo.Length() > 0) {
printf("Populated package info for %s: %s\n",
package->Name().String(), foundInfo.String());
@@ -1346,11 +1346,11 @@ Model::_HasNativeIcon(const BMessage& message) const
while (true) {
BString name;
name << index++;
-
+
BMessage typeCodeInfo;
if (pkgIcons.FindMessage(name, &typeCodeInfo) != B_OK)
break;
-
+
BString mediaTypeCode;
if (typeCodeInfo.FindString("mediaTypeCode", &mediaTypeCode) ==
B_OK
&& mediaTypeCode == "application/x-vnd.haiku-icon") {
diff --git a/src/apps/haikudepot/model/PackageInfo.cpp
b/src/apps/haikudepot/model/PackageInfo.cpp
index a628156..e976b3c 100644
--- a/src/apps/haikudepot/model/PackageInfo.cpp
+++ b/src/apps/haikudepot/model/PackageInfo.cpp
@@ -196,7 +196,7 @@ RatingSummary::operator==(const RatingSummary& other) const
if (ratingCountByStar[i] != other.ratingCountByStar[i])
return false;
}
-
+
return true;
}

@@ -818,7 +818,7 @@ PackageInfo::CalculateRatingSummary() const
{
if (fUserRatings.CountItems() == 0)
return fCachedRatingSummary;
-
+
RatingSummary summary;
summary.ratingCount = fUserRatings.CountItems();
summary.averageRating = 0.0f;
@@ -1037,7 +1037,7 @@ void
DepotInfo::SyncPackages(const PackageList& otherPackages)
{
PackageList packages(fPackages);
-
+
for (int32 i = otherPackages.CountItems() - 1; i >= 0; i--) {
const PackageInfoRef& otherPackage =
otherPackages.ItemAtFast(i);
bool found = false;
diff --git a/src/apps/haikudepot/model/PackageInfo.h
b/src/apps/haikudepot/model/PackageInfo.h
index 40de3f2..61480fa 100644
--- a/src/apps/haikudepot/model/PackageInfo.h
+++ b/src/apps/haikudepot/model/PackageInfo.h
@@ -306,7 +306,7 @@ public:
bool IsLocalFile() const;
const BString& FileName() const
{
return fFileName; }
-
+
void ClearCategories();
bool AddCategory(const
CategoryRef& category);
const CategoryList& Categories() const
diff --git a/src/apps/haikudepot/model/WebAppInterface.cpp
b/src/apps/haikudepot/model/WebAppInterface.cpp
index ddb2b1b..22a0a43db 100644
--- a/src/apps/haikudepot/model/WebAppInterface.cpp
+++ b/src/apps/haikudepot/model/WebAppInterface.cpp
@@ -187,24 +187,24 @@ public:
{
// printf("ConnectionOpened(%p)\n", caller);
}
-
+
virtual void HostnameResolved(BUrlRequest* caller, const char* ip)
{
// printf("HostnameResolved(%p): %s\n", caller, ip);
}
-
+
virtual void ResponseStarted(BUrlRequest* caller)
{
if (fDebug)
printf("ResponseStarted(%p)\n", caller);
}
-
+
virtual void HeadersReceived(BUrlRequest* caller)
{
if (fDebug)
printf("HeadersReceived(%p)\n", caller);
}
-
+
virtual void DataReceived(BUrlRequest* caller, const char* data,
off_t position, ssize_t size)
{
@@ -216,27 +216,27 @@ public:
if (fDownloadIO != NULL)
fDownloadIO->Write(data, size);
}
-
+
virtual void DownloadProgress(BUrlRequest* caller, ssize_t
bytesReceived,
ssize_t bytesTotal)
{
// printf("DownloadProgress(%p): %ld/%ld\n", caller, bytesReceived,
// bytesTotal);
}
-
+
virtual void UploadProgress(BUrlRequest* caller, ssize_t bytesSent,
ssize_t bytesTotal)
{
if (fDebug)
printf("UploadProgress(%p): %ld/%ld\n", caller,
bytesSent, bytesTotal);
}
-

+
virtual void RequestCompleted(BUrlRequest* caller, bool success)
{
if (fDebug)
printf("RequestCompleted(%p): %d\n", caller, success);
}
-
+
virtual void DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type, const char* text)
{
@@ -295,11 +295,11 @@ WebAppInterface::operator=(const WebAppInterface& other)
{
if (this == &other)
return *this;
-
+
fUsername = other.fUsername;
fPassword = other.fPassword;
fLanguage = other.fLanguage;
-
+
return *this;
}

@@ -380,12 +380,12 @@ WebAppInterface::RetrievePackageIcon(const BString&
packageName,
{
BString urlString = "https://depot.haiku-os.org/pkgicon/";;
urlString << packageName << ".hvif";
-
+
BUrl url(urlString);
-
+
ProtocolListener listener;
listener.SetDownloadIO(stream);
-
+
BHttpRequest request(url, true, "HTTP", &listener);
request.SetMethod(B_HTTP_GET);

@@ -396,7 +396,7 @@ WebAppInterface::RetrievePackageIcon(const BString&
packageName,
request.Result());

int32 statusCode = result.StatusCode();
-
+
if (statusCode == 200)
return B_OK;

@@ -523,15 +523,15 @@ WebAppInterface::RetrieveScreenshot(const BString& code,
BString urlString = "https://depot.haiku-os.org/pkgscreenshot/";;
urlString << code << ".png"
<< "?tw=" << width << "&th=" << height;
-
+
BUrl url(urlString);
-
+
ProtocolListener listener;
listener.SetDownloadIO(stream);

- BHttpHeaders headers;
+ BHttpHeaders headers;
headers.AddHeader("User-Agent", "X-HDS-Client");
-
+
BHttpRequest request(url, true, "HTTP", &listener);
request.SetMethod(B_HTTP_GET);
request.SetHeaders(headers);
@@ -543,7 +543,7 @@ WebAppInterface::RetrieveScreenshot(const BString& code,
request.Result());

int32 statusCode = result.StatusCode();
-
+
if (statusCode == 200)
return B_OK;

@@ -588,7 +588,7 @@ WebAppInterface::CreateUser(const BString& nickName,

if (!email.IsEmpty())
builder.AddValue("email", email);
-
+
builder.AddValue("captchaToken", captchaToken)
.AddValue("captchaResponse", captchaResponse)
.AddValue("naturalLanguageCode", languageCode)
diff --git a/src/apps/haikudepot/textview/CharacterStyleData.h
b/src/apps/haikudepot/textview/CharacterStyleData.h
index 14c47be..ad58241 100644
--- a/src/apps/haikudepot/textview/CharacterStyleData.h
+++ b/src/apps/haikudepot/textview/CharacterStyleData.h
@@ -49,7 +49,7 @@ public:
{
return fFont; }

CharacterStyleDataRef SetAscent(float ascent);
-
+
// Returns the ascent of the configured font, unless
the ascent
// has been overridden by a fixed value with
SetAscent().
float Ascent() const;
diff --git a/src/apps/haikudepot/textview/Paragraph.cpp
b/src/apps/haikudepot/textview/Paragraph.cpp
index 377bca9..907394d 100644
--- a/src/apps/haikudepot/textview/Paragraph.cpp
+++ b/src/apps/haikudepot/textview/Paragraph.cpp
@@ -286,12 +286,12 @@ Paragraph::SubParagraph(int32 start, int32 length) const
{
if (start < 0)
start = 0;
-
+
if (start == 0 && length == Length())
return *this;
-
+
Paragraph result(fStyle);
-
+
int32 count = fTextSpans.CountItems();
for (int32 i = 0; i < count; i++) {
const TextSpan& span = fTextSpans.ItemAtFast(i);
@@ -312,7 +312,7 @@ Paragraph::SubParagraph(int32 start, int32 length) const
result.Append(span);
else
result.Append(span.SubSpan(start, copyLength));
-
+
length -= copyLength;
if (length == 0)
break;
diff --git a/src/apps/haikudepot/textview/ParagraphLayout.cpp
b/src/apps/haikudepot/textview/ParagraphLayout.cpp
index eebc22f..864bd16 100644
--- a/src/apps/haikudepot/textview/ParagraphLayout.cpp
+++ b/src/apps/haikudepot/textview/ParagraphLayout.cpp
@@ -301,7 +301,7 @@ ParagraphLayout::LineIndexForOffset(int32 textOffset)

if (textOffset < 0)
textOffset = 0;
-
+
const GlyphInfo& glyph = fGlyphInfos.ItemAtFast(textOffset);
return glyph.lineIndex;
}
@@ -396,7 +396,7 @@ ParagraphLayout::GetTextBounds(int32 textOffset, float& x1,
float& y1,

if (textOffset < 0)
textOffset = 0;
-
+
const GlyphInfo& glyph = fGlyphInfos.ItemAtFast(textOffset);
const LineInfo& line = fLineInfos.ItemAt(glyph.lineIndex);

diff --git a/src/apps/haikudepot/textview/TextDocument.cpp
b/src/apps/haikudepot/textview/TextDocument.cpp
index e222d99..3e2f115 100644
--- a/src/apps/haikudepot/textview/TextDocument.cpp
+++ b/src/apps/haikudepot/textview/TextDocument.cpp
@@ -133,7 +133,7 @@ TextDocument::Insert(int32 textOffset, const BString& text,
chunkEnd++;
else
chunkEnd = length;
-
+
BString chunk;
text.CopyCharsInto(chunk, chunkStart, chunkEnd -
chunkStart);
TextSpan span(chunk, characterStyle);
@@ -171,7 +171,7 @@ TextDocument::Insert(int32 textOffset, const BString& text,
if (!fParagraphs.Replace(index, paragraph))
return B_NO_MEMORY;
}
-
+
return B_OK;
}

@@ -214,7 +214,7 @@ TextDocument::Remove(int32 textOffset, int32 length)
&& index + 1 < fParagraphs.CountItems()) {
// Line break between paragraphs got removed. Shift the next
// paragraph's text spans into the resulting one.
-
+
const TextSpanList& textSpans = ParagraphAt(index +
1).TextSpans();
int32 spanCount = textSpans.CountItems();
for (int32 i = 0; i < spanCount; i++) {
@@ -225,7 +225,7 @@ TextDocument::Remove(int32 textOffset, int32 length)
}

textOffset = 0;
-
+
while (length > 0 && index + 1 < fParagraphs.CountItems()) {
const Paragraph& paragraph = ParagraphAt(index + 1);
paragraphLength = paragraph.Length();
@@ -251,7 +251,7 @@ TextDocument::Remove(int32 textOffset, int32 length)
const TextSpan& span = textSpans.ItemAtFast(i);
resultParagraph.Append(span);
}
-
+
break;
}
}
@@ -288,7 +288,7 @@ TextDocument::Replace(int32 textOffset, int32 length, const
BString& text,
status_t ret = Remove(textOffset, length);
if (ret != B_OK)
return ret;
-
+
return Insert(textOffset, text, characterStyle, paragraphStyle);
}

@@ -405,9 +405,9 @@ TextDocument::Text(int32 start, int32 length) const
{
if (start < 0)
start = 0;
-
+
BString text;
-
+
int32 count = fParagraphs.CountItems();
for (int32 i = 0; i < count; i++) {
const Paragraph& paragraph = fParagraphs.ItemAtFast(i);
@@ -423,9 +423,9 @@ TextDocument::Text(int32 start, int32 length) const
// Remaining paragraph length after start
paragraphLength -= start;
int32 copyLength = std::min(paragraphLength, length);
-
+
text << paragraph.Text(start, copyLength);
-
+
length -= copyLength;
if (length == 0)
break;
@@ -443,10 +443,10 @@ TextDocument::SubDocument(int32 start, int32 length) const
{
TextDocumentRef result(new(std::nothrow) TextDocument(
fDefaultCharacterStyle, fEmptyLastParagraph.Style()), true);
-
+
if (result.Get() == NULL)
return result;
-
+
if (start < 0)
start = 0;

@@ -465,7 +465,7 @@ TextDocument::SubDocument(int32 start, int32 length) const
// Remaining paragraph length after start
paragraphLength -= start;
int32 copyLength = std::min(paragraphLength, length);
-
+
result->Append(paragraph.SubParagraph(start, copyLength));

length -= copyLength;
diff --git a/src/apps/haikudepot/textview/TextDocumentLayout.cpp
b/src/apps/haikudepot/textview/TextDocumentLayout.cpp
index 1e1b8d6..6ed09b4 100644
--- a/src/apps/haikudepot/textview/TextDocumentLayout.cpp
+++ b/src/apps/haikudepot/textview/TextDocumentLayout.cpp
@@ -97,7 +97,7 @@ TextDocumentLayout::InvalidateParagraphs(int32 start, int32
count)
start);
info.layout->SetParagraph(paragraph);
}
-
+
start++;
count--;
}
@@ -161,11 +161,11 @@ TextDocumentLayout::LineIndexForOffset(int32 textOffset)
for (int32 i = 0; i < index; i++) {
lineIndex +=
fParagraphLayouts.ItemAtFast(i).layout->CountLines();
}
-
+
const ParagraphLayoutInfo& info =
fParagraphLayouts.ItemAtFast(index);
return lineIndex + info.layout->LineIndexForOffset(textOffset);
}
-
+
return 0;
}

@@ -275,7 +275,7 @@ TextDocumentLayout::TextOffsetAt(float x, float y, bool&
rightOfCenter)
textOffset += info.layout->TextOffsetAt(x, y - info.y,
rightOfCenter);
break;
}
-
+
return textOffset;
}

@@ -342,16 +342,16 @@ TextDocumentLayout::_ParagraphLayoutIndexForOffset(int32&
textOffset)
int32 paragraphs = fParagraphLayouts.CountItems();
for (int32 i = 0; i < paragraphs - 1; i++) {
const ParagraphLayoutInfo& info =
fParagraphLayouts.ItemAtFast(i);
-
+
int32 length = info.layout->CountGlyphs();
if (textOffset >= length) {
textOffset -= length;
continue;
}
-
+
return i;
}
-
+
if (paragraphs > 0) {
const ParagraphLayoutInfo& info = fParagraphLayouts.LastItem();

@@ -361,7 +361,7 @@ TextDocumentLayout::_ParagraphLayoutIndexForOffset(int32&
textOffset)
if (textOffset <= length)
return paragraphs - 1;
}
-
+
return -1;
}

@@ -382,7 +382,7 @@
TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex,
paragraphOffset += info.layout->CountGlyphs();
continue;
}
-
+
return i;
}

diff --git a/src/apps/haikudepot/textview/TextDocumentView.cpp
b/src/apps/haikudepot/textview/TextDocumentView.cpp
index cfd3898..bd8fe7b 100644
--- a/src/apps/haikudepot/textview/TextDocumentView.cpp
+++ b/src/apps/haikudepot/textview/TextDocumentView.cpp
@@ -30,7 +30,7 @@ TextDocumentView::TextDocumentView(const char* name)
fMouseDown(false)
{
fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width()));
-
+
// Set default TextEditor
SetTextEditor(TextEditorRef(new(std::nothrow) TextEditor(), true));

@@ -142,10 +142,10 @@ TextDocumentView::MouseDown(BPoint where)
int32 modifiers = 0;
if (Window() != NULL && Window()->CurrentMessage() != NULL)
Window()->CurrentMessage()->FindInt32("modifiers", &modifiers);
-
+
fMouseDown = true;
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
-
+
bool extendSelection = (modifiers & B_SHIFT_KEY) != 0;
SetCaret(where, extendSelection);
}
@@ -184,7 +184,7 @@ TextDocumentView::KeyDown(const char* bytes, int32 numBytes)
event.length = numBytes;
event.key = 0;
event.modifiers = modifiers();
-
+
if (Window() != NULL && Window()->CurrentMessage() != NULL) {
BMessage* message = Window()->CurrentMessage();
message->FindInt32("raw_char", &event.key);
@@ -391,10 +391,10 @@ TextDocumentView::Copy(BClipboard* clipboard)
// Nothing to copy, don't clear clipboard contents for now
reason.
return;
}
-
+
if (clipboard == NULL || !clipboard->Lock())
return;
-
+
clipboard->Clear();

BMessage* clip = clipboard->Data();
@@ -402,13 +402,13 @@ TextDocumentView::Copy(BClipboard* clipboard)
int32 start;
int32 end;
GetSelection(start, end);
-
+
BString text = fTextDocument->Text(start, end - start);
clip->AddData("text/plain", B_MIME_TYPE, text.String(),
text.Length());
-
+
// TODO: Support for "application/x-vnd.Be-text_run_array"
-
+
clipboard->Commit();
}

@@ -585,7 +585,7 @@ TextDocumentView::_GetSelectionShape(BShape& shape, int32
start, int32 end)
} else {
// Selection over multiple lines
float width = ceilf(fTextDocumentLayout.Width());
-
+
shape.MoveTo(BPoint(startX1, startY1));
shape.LineTo(BPoint(width, startY1));
shape.LineTo(BPoint(width, endY1));
diff --git a/src/apps/haikudepot/textview/TextEditor.cpp
b/src/apps/haikudepot/textview/TextEditor.cpp
index 865db3e..fd57c7e 100644
--- a/src/apps/haikudepot/textview/TextEditor.cpp
+++ b/src/apps/haikudepot/textview/TextEditor.cpp
@@ -239,11 +239,11 @@ TextEditor::KeyDown(KeyEvent event)
if (event.bytes != NULL && event.length > 0) {
// Handle null-termintating the string
BString text(event.bytes, event.length);
-
+
// Remove selection, if any
if (HasSelection())
Remove(SelectionStart(),
SelectionLength());
-
+
Insert(fSelection.Caret(), text);
}
break;
@@ -262,9 +262,9 @@ TextEditor::Insert(int32 offset, const BString& string)
if (ret == B_OK) {
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
-
+
_SetCaretOffset(offset + string.CountChars(), true, false,
true);
-
+
fDocument->PrintToStream();
}

@@ -283,7 +283,7 @@ TextEditor::Remove(int32 offset, int32 length)
if (ret == B_OK) {
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
-
+
_SetCaretOffset(offset, true, false, true);

fDocument->PrintToStream();
@@ -437,7 +437,7 @@ TextEditor::_SetSelection(int32 caret, int32 anchor, bool
updateAnchor,
{
if (fLayout.Get() == NULL)
return;
-
+
if (caret == fSelection.Caret() && anchor == fSelection.Anchor())
return;

diff --git a/src/apps/haikudepot/ui/App.cpp b/src/apps/haikudepot/ui/App.cpp
index b520fec..cce042d 100644
--- a/src/apps/haikudepot/ui/App.cpp
+++ b/src/apps/haikudepot/ui/App.cpp
@@ -69,10 +69,10 @@ App::ReadyToRun()
{
if (fWindowCount > 0)
return;
-
+
BMessage settings;
_LoadSettings(settings);
-
+
fMainWindow = new MainWindow(_GetNextWindowFrame(false), settings);
_ShowWindow(fMainWindow);
}
@@ -152,7 +152,7 @@ App::_Open(const BEntry& entry)
fprintf(stderr, "Could not allocate PackageInfo\n");
return;
}
-
+
package->SetLocalFilePath(path.Path());

BMessage settings;
@@ -258,7 +258,7 @@ App::_CheckPackageDaemonRuns()

if (!_LaunchPackageDaemon())
break;
- }
+ }
}


@@ -270,7 +270,7 @@ App::_LaunchPackageDaemon()
BString errorMessage
= B_TRANSLATE("Starting the package daemon
failed:\n\n%Error%");
errorMessage.ReplaceAll("%Error%", strerror(ret));
-
+
BAlert* alert = new BAlert("package_daemon_problem",
errorMessage,
B_TRANSLATE("Quit HaikuDepot"),
diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
index 3b59cbc..80904ec 100644
--- a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
+++ b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
@@ -46,7 +46,7 @@ public:
{
SetViewColor(255, 255, 255);
SetEventMask(B_POINTER_EVENTS);
-
+
fIconView = new BitmapView("package icon view");
fInstalledIconView = new BitmapView("installed icon view");
fTitleView = new BStringView("package title view", "");
@@ -131,14 +131,14 @@ public:
break;
}
}
-
+
virtual void MouseDown(BPoint where)
{
BRect bounds = Bounds();
BRect parentBounds = Parent()->Bounds();
ConvertFromParent(&parentBounds);
bounds = bounds & parentBounds;
-
+
if (bounds.Contains(where) && Window()->IsActive()) {
BMessage message(MSG_PACKAGE_SELECTED);
message.AddString("name", PackageName());
@@ -227,13 +227,13 @@ public:
if (fSelected == selected)
return;
fSelected = selected;
-
+
rgb_color bgColor;
if (fSelected)
bgColor = ui_color(B_LIST_SELECTED_BACKGROUND_COLOR);
else
bgColor = (rgb_color){ 255, 255, 255, 255 };
-
+
List<BView*, true> views;

views.Add(this);
@@ -245,10 +245,10 @@ public:
views.Add(fRatingView);
views.Add(fAvgRating);
views.Add(fVoteInfo);
-
+
for (int32 i = 0; i < views.CountItems(); i++) {
BView* view = views.ItemAtFast(i);
-
+
view->SetViewColor(bgColor);
view->SetLowColor(bgColor);
view->Invalidate();
@@ -376,7 +376,7 @@ FeaturedPackagesView::SelectPackage(const PackageInfoRef&
package)
BString selectedName;
if (package.Get() != NULL)
selectedName = package->Name();
-
+
for (int32 i = 0; BLayoutItem* item = fPackageListLayout->ItemAt(i);
i++) {
PackageView* view = dynamic_cast<PackageView*>(item->View());
if (view == NULL)
diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.h
b/src/apps/haikudepot/ui/FeaturedPackagesView.h
index b400eec..83a8540 100644
--- a/src/apps/haikudepot/ui/FeaturedPackagesView.h
+++ b/src/apps/haikudepot/ui/FeaturedPackagesView.h
@@ -23,7 +23,7 @@ public:
void AddPackage(const
PackageInfoRef& package);
void RemovePackage(const
PackageInfoRef& package);
void Clear();
-
+
void SelectPackage(const
PackageInfoRef& package);

static void CleanupIcons();
diff --git a/src/apps/haikudepot/ui/FilterView.cpp
b/src/apps/haikudepot/ui/FilterView.cpp
index 7d429f5..e8eb056 100644
--- a/src/apps/haikudepot/ui/FilterView.cpp
+++ b/src/apps/haikudepot/ui/FilterView.cpp
@@ -138,7 +138,7 @@ FilterView::AdoptModel(const Model& model)
message->AddString("name", depot.Name());
BMenuItem* item = new BMenuItem(depot.Name(), message);
repositoryMenu->AddItem(item);
-
+
if (depot.Name() == model.Depot()) {
item->SetMarked(true);
foundSelectedDepot = true;
@@ -146,7 +146,7 @@ FilterView::AdoptModel(const Model& model)
}

if (!foundSelectedDepot)
- repositoryMenu->ItemAt(0)->SetMarked(true);
+ repositoryMenu->ItemAt(0)->SetMarked(true);

// Adopt categories
BMenu* showMenu = fShowField->Menu();
@@ -174,6 +174,6 @@ FilterView::AdoptModel(const Model& model)
}
}
if (!foundSelectedCategory)
- showMenu->ItemAt(0)->SetMarked(true);
+ showMenu->ItemAt(0)->SetMarked(true);
}

diff --git a/src/apps/haikudepot/ui/MainWindow.cpp
b/src/apps/haikudepot/ui/MainWindow.cpp
index 4565b7f..80307b4 100644
--- a/src/apps/haikudepot/ui/MainWindow.cpp
+++ b/src/apps/haikudepot/ui/MainWindow.cpp
@@ -101,7 +101,7 @@ public:
fMessenger(messenger)
{
}
-
+
virtual void AuthorizationChanged()
{
if (fMessenger.IsValid())
@@ -315,7 +315,7 @@ MainWindow::MessageReceived(BMessage* message)

case B_PACKAGE_UPDATE:
// TODO: We should do a more selective update depending
on the
- // "event", "location", and "change count" fields!
+ // "event", "location", and "change count" fields!
_StartRefreshWorker(false);
break;

@@ -514,9 +514,9 @@ MainWindow::StoreSettings(BMessage& settings) const

BMessage columnSettings;
fPackageListView->SaveState(&columnSettings);
-
+
settings.AddMessage("column settings", &columnSettings);
-
+
settings.AddBool("show featured packages",
fModel.ShowFeaturedPackages());
settings.AddBool("show available packages",
@@ -660,7 +660,7 @@ MainWindow::_AdoptModel()
fPackageListView->Clear();
for (int32 i = 0; i < fVisiblePackages.CountItems(); i++) {
BAutolock locker(fModel.Lock());
-
+
const PackageInfoRef& package = fVisiblePackages.ItemAtFast(i);
fPackageListView->AddPackage(package);

@@ -697,7 +697,7 @@ MainWindow::_AdoptPackage(const PackageInfoRef& package)
{
BAutolock locker(fModel.Lock());
fPackageInfoView->SetPackage(package);
-
+
if (fFeaturedPackagesView != NULL)
fFeaturedPackagesView->SelectPackage(package);
if (fPackageListView != NULL)
@@ -890,7 +890,7 @@ MainWindow::_RefreshPackageList(bool force)
fModel.StopPopulatingAllPackages();

BAutolock lock(fModel.Lock());
-
+
if (force)
fModel.Clear();

@@ -1160,13 +1160,13 @@ MainWindow::_RatePackage()

if (alert == NULL)
return;
-
+
int32 choice = alert->Go();
if (choice == 1)
_OpenLoginWindow(BMessage(MSG_RATE_PACKAGE));
return;
}
-
+
// TODO: Allow only one RatePackageWindow
// TODO: Mechanism for remembering the window frame
RatePackageWindow* window = new RatePackageWindow(this,
diff --git a/src/apps/haikudepot/ui/MessagePackageListener.cpp
b/src/apps/haikudepot/ui/MessagePackageListener.cpp
index e7678fb..382f8cd 100644
--- a/src/apps/haikudepot/ui/MessagePackageListener.cpp
+++ b/src/apps/haikudepot/ui/MessagePackageListener.cpp
@@ -33,7 +33,7 @@ MessagePackageListener::PackageChanged(const
PackageInfoEvent& event)
{
if ((event.Changes() & fChangesMask) == 0)
return;
-
+
BMessenger messenger(fTarget);
if (!messenger.IsValid())
return;
diff --git a/src/apps/haikudepot/ui/PackageContentsView.cpp
b/src/apps/haikudepot/ui/PackageContentsView.cpp
index 48ebd1d..6e6b08c 100644
--- a/src/apps/haikudepot/ui/PackageContentsView.cpp
+++ b/src/apps/haikudepot/ui/PackageContentsView.cpp
@@ -87,7 +87,7 @@ public:
fPath.Append("/");
fPath.Append(entry->Name());
}
-
+
inline const BString& EntryPath() const
{
return fPath;
@@ -213,11 +213,11 @@ public:
{
return B_OK;
}
-
+
virtual void HandleErrorOccurred()
{
}
-
+
private:
BOutlineListView* fListView;

@@ -241,12 +241,12 @@ PackageContentsView::PackageContentsView(const char* name)
BView("package_contents_view", B_WILL_DRAW),
fPackageLock("package contents populator lock")
{
- fContentListView = new BOutlineListView("content list view",
+ fContentListView = new BOutlineListView("content list view",
B_SINGLE_SELECTION_LIST);
-
- BScrollView* scrollView = new CustomScrollView("contents scroll view",
+
+ BScrollView* scrollView = new CustomScrollView("contents scroll view",
fContentListView);
-

+
BLayoutBuilder::Group<>(this)
.Add(scrollView, 1.0f)
.SetInsets(0.0f, -1.0f, -1.0f, -1.0f)
@@ -299,7 +299,7 @@ PackageContentsView::SetPackage(const PackageInfoRef&
package)
}


-void
+void
PackageContentsView::Clear()
{
{
diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp
b/src/apps/haikudepot/ui/PackageInfoView.cpp
index 7bf088a..4e0db2f 100644
--- a/src/apps/haikudepot/ui/PackageInfoView.cpp
+++ b/src/apps/haikudepot/ui/PackageInfoView.cpp
@@ -215,7 +215,7 @@ public:
const BMessage* dragMessage)
{
BButton::MouseMoved(point, transit, dragMessage);
-
+
if (fTransitMessage != NULL && transit == B_EXITED_VIEW)
Invoke(fTransitMessage);
}
@@ -251,7 +251,7 @@ public:
const BMessage* dragMessage)
{
RatingView::MouseMoved(point, transit, dragMessage);
-
+
if (fTransitMessage != NULL && transit == B_ENTERED_VIEW)
Invoke(fTransitMessage);
}
@@ -564,12 +564,12 @@ public:
{
if (fButtons.CountItems() > 0)
Clear();
-
+
if (fStatusBar == NULL) {
fStatusLabel = new BStringView("progress label",
B_TRANSLATE("Downloading:"));
fLayout->AddView(fStatusLabel);
-
+
fStatusBar = new BStatusBar("progress");
fStatusBar->SetMaxValue(100.0);
fStatusBar->SetExplicitMinSize(
@@ -577,7 +577,7 @@ public:

fLayout->AddView(fStatusBar);
}
-
+
fStatusBar->SetTo(package.DownloadProgress() * 100.0);
}

@@ -769,7 +769,7 @@ public:
Window()->PostMessage(message, Window());
break;
}
-
+
case MSG_EMAIL_PUBLISHER:
{
// TODO: Implement. If memory serves, there is a
@@ -1068,7 +1068,7 @@ public:
.Add(scrollView, 1.0f)
.SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f)
;
-
+
_InitPreferredLanguages();
}

@@ -1144,7 +1144,7 @@ private:
return;

BMessage preferredLanguages;
- if (localeRoster->GetPreferredLanguages(&preferredLanguages) !=
B_OK)
+ if (localeRoster->GetPreferredLanguages(&preferredLanguages) !=
B_OK)
return;

BString language;
@@ -1280,7 +1280,7 @@ public:
AddTab(fUserRatingsView);
AddTab(fChangelogView);
AddTab(fContentsView);
-
+
TabAt(0)->SetLabel(B_TRANSLATE("About"));
TabAt(1)->SetLabel(B_TRANSLATE("Ratings"));
TabAt(2)->SetLabel(B_TRANSLATE("Changelog"));
@@ -1334,7 +1334,7 @@ PackageInfoView::PackageInfoView(BLocker* modelLock,
{
fCardLayout = new BCardLayout();
SetLayout(fCardLayout);
-
+
BGroupView* noPackageCard = new BGroupView("no package card",
B_VERTICAL);
AddChild(noPackageCard);

@@ -1459,7 +1459,7 @@ PackageInfoView::SetPackage(const PackageInfoRef&
packageRef)
// same package as before the refresh.
switchToDefaultTab = false;
}
-
+
const PackageInfo& package = *packageRef.Get();

fTitleView->SetPackage(package);
diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp
b/src/apps/haikudepot/ui/RatePackageWindow.cpp
index 118c1a2..2d0bca6 100644
--- a/src/apps/haikudepot/ui/RatePackageWindow.cpp
+++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp
@@ -108,13 +108,13 @@ public:
{
if (dragMessage != NULL)
return;
-
+
if ((transit != B_INSIDE_VIEW && transit != B_ENTERED_VIEW)
|| where.x > MinSize().width) {
SetRating(fPermanentRating);
return;
}
-
+
float hoverRating = _RatingForMousePos(where);
SetRating(hoverRating);
}
@@ -126,7 +126,7 @@ public:
message.AddFloat("rating", fPermanentRating);
Window()->PostMessage(&message, Window());
}
-
+
void SetPermanentRating(float rating)
{
fPermanentRating = rating;
@@ -187,7 +187,7 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect
frame,
BStringView* ratingLabel = new BStringView("rating label",
B_TRANSLATE("Your rating:"));

- fSetRatingView = new SetRatingView();
+ fSetRatingView = new SetRatingView();

fTextView = new TextDocumentView();
ScrollView* textScrollView = new ScrollView(
@@ -218,10 +218,10 @@ RatePackageWindow::RatePackageWindow(BWindow* parent,
BRect frame,
B_TRANSLATE("Very unstable"), "veryunstable"));
fStabilityCodes.Add(StabilityRating(
B_TRANSLATE("Does not start"), "nostart"));
-
+
add_stabilities_to_menu(fStabilityCodes, stabilityMenu);
stabilityMenu->SetTargetForItems(this);
-
+
fStability = fStabilityCodes.ItemAt(0).Name();
stabilityMenu->ItemAt(0)->SetMarked(true);

@@ -237,14 +237,14 @@ RatePackageWindow::RatePackageWindow(BWindow* parent,
BRect frame,
fModel.SupportedLanguages().IndexOf(fCommentLanguage));
if (defaultItem != NULL)
defaultItem->SetMarked(true);
-
+
fRatingActiveCheckBox = new BCheckBox("rating active",
B_TRANSLATE("Other users can see this rating"),
new BMessage(MSG_RATING_ACTIVE_CHANGED));
// Hide the check mark by default, it will be made visible when
// the user already made a rating and it is loaded
fRatingActiveCheckBox->Hide();
-
+
// Construct buttons
fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED));
@@ -297,7 +297,7 @@ RatePackageWindow::MessageReceived(BMessage* message)
case MSG_LANGUAGE_SELECTED:
message->FindString("code", &fCommentLanguage);
break;
-
+
case MSG_RATING_ACTIVE_CHANGED:
{
int32 value;
@@ -355,7 +355,7 @@ RatePackageWindow::_SetWorkerThread(thread_id thread)
{
if (!Lock())
return;
-
+
bool enabled = thread < 0;

// fTextEditor->SetEnabled(enabled);
@@ -363,7 +363,7 @@ RatePackageWindow::_SetWorkerThread(thread_id thread)
fStabilityField->SetEnabled(enabled);
fCommentLanguageField->SetEnabled(enabled);
fSendButton->SetEnabled(enabled);
-
+
if (thread >= 0) {
fWorkerThread = thread;
resume_thread(fWorkerThread);
@@ -418,7 +418,7 @@ RatePackageWindow::_QueryRatingThread()
BMessage result;
if (status == B_OK && info.FindMessage("result", &result) == B_OK
&& Lock()) {
-
+
result.FindString("code", &fRatingID);
result.FindBool("active", &fRatingActive);
BString comment;
@@ -454,7 +454,7 @@ RatePackageWindow::_QueryRatingThread()
fRating = (float)rating;
fSetRatingView->SetPermanentRating(fRating);
}
-
+
fRatingActiveCheckBox->SetValue(fRatingActive);
fRatingActiveCheckBox->Show();

@@ -541,7 +541,7 @@ RatePackageWindow::_SendRatingThread()
error = B_TRANSLATE(
"It was not possible to contact the web service.");
}
-
+
if (!error.IsEmpty()) {
BString failedTitle;
if (ratingID.Length() > 0)
diff --git a/src/apps/haikudepot/ui/ScreenshotWindow.cpp
b/src/apps/haikudepot/ui/ScreenshotWindow.cpp
index da01928..175e132 100644
--- a/src/apps/haikudepot/ui/ScreenshotWindow.cpp
+++ b/src/apps/haikudepot/ui/ScreenshotWindow.cpp
@@ -53,7 +53,7 @@ ScreenshotWindow::ScreenshotWindow(BWindow* parent, BRect
frame)
ScreenshotWindow::~ScreenshotWindow()
{
BAutolock locker(&fLock);
-
+
if (fWorkerThread >= 0)
wait_for_thread(fWorkerThread, NULL);
}
@@ -114,7 +114,7 @@ void
ScreenshotWindow::_DownloadScreenshot()
{
BAutolock locker(&fLock);
-
+
if (fWorkerThread >= 0) {
fDownloadPending = true;
return;
@@ -132,13 +132,13 @@ ScreenshotWindow::_SetWorkerThread(thread_id thread)
{
if (!Lock())
return;
-
+
// bool enabled = thread < 0;
//
// fPreviewsButton->SetEnabled(enabled);
// fNextButton->SetEnabled(enabled);
// fCloseButton->SetEnabled(enabled);
-
+
if (thread >= 0) {
fWorkerThread = thread;
resume_thread(fWorkerThread);
diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp
b/src/apps/haikudepot/ui/UserLoginWindow.cpp
index 5a24fb2..8836922 100644
--- a/src/apps/haikudepot/ui/UserLoginWindow.cpp
+++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp
@@ -102,7 +102,7 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect
frame, Model& model)
fRepeatPasswordField = new BTextControl(B_TRANSLATE("Repeat pass
phrase:"),
"", new BMessage(MSG_VALIDATE_FIELDS));
fRepeatPasswordField->TextView()->HideTyping(true);
-
+
// Construct languages popup
BPopUpMenu* languagesMenu = new BPopUpMenu(B_TRANSLATE("Language"));
fLanguageCodeField = new BMenuField("language",
@@ -115,8 +115,8 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect
frame, Model& model)
fModel.SupportedLanguages().IndexOf(fPreferredLanguage));
if (defaultItem != NULL)
defaultItem->SetMarked(true);
-
-
+
+
fEmailField = new BTextControl(B_TRANSLATE("Email address:"), "", NULL);
fCaptchaView = new BitmapView("captcha view");
fCaptchaResultField = new BTextControl("", "", NULL);
@@ -133,7 +133,7 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect
frame, Model& model)
new BMessage(MSG_VALIDATE_FIELDS));
fCaptchaResultField->SetModificationMessage(
new BMessage(MSG_VALIDATE_FIELDS));
-
+
fTabView = new TabView(BMessenger(this),
BMessage(MSG_TAB_SELECTED));

@@ -178,7 +178,7 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect
frame, Model& model)
;

SetDefaultButton(fSendButton);
-
+
_SetMode(LOGIN);

CenterIn(parent->Frame());
@@ -188,7 +188,7 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect
frame, Model& model)
UserLoginWindow::~UserLoginWindow()
{
BAutolock locker(&fLock);
-
+
if (fWorkerThread >= 0)
wait_for_thread(fWorkerThread, NULL);
}
@@ -331,13 +331,13 @@ UserLoginWindow::_ValidateCreateAccountFields(bool
alertProblems)
// TODO: Use the same validation as the web-serivce
bool validUserName = nickName.Length() >= 3;
fNewUsernameField->MarkAsInvalid(!validUserName);
-
+
bool validPassword = password1.Length() >= 8
&& count_digits(password1) >= 2
&& count_upper_case_letters(password1) >= 2;
fNewPasswordField->MarkAsInvalid(!validPassword);
fRepeatPasswordField->MarkAsInvalid(password1 != password2);
-
+
bool validCaptcha = captcha.Length() > 0;
fCaptchaResultField->MarkAsInvalid(!validCaptcha);

@@ -399,7 +399,7 @@ UserLoginWindow::_ValidateCreateAccountFields(bool
alertProblems)
return false;
}
}
-
+
return valid;
}

@@ -408,7 +408,7 @@ void
UserLoginWindow::_Login()
{
BAutolock locker(&fLock);
-
+
if (fWorkerThread >= 0)
return;

@@ -424,9 +424,9 @@ UserLoginWindow::_CreateAccount()
{
if (!_ValidateCreateAccountFields(true))
return;
-
+
BAutolock locker(&fLock);
-
+
if (fWorkerThread >= 0)
return;

@@ -448,7 +448,7 @@ UserLoginWindow::_RequestCaptcha()
}

BAutolock locker(&fLock);
-
+
if (fWorkerThread >= 0)
return;

@@ -466,7 +466,7 @@ UserLoginWindow::_LoginSuccessful(const BString& message)
// (This method is executd from another thread.)
BMessenger onSuccessTarget(fOnSuccessTarget);
BMessage onSuccessMessage(fOnSuccessMessage);
-
+
BMessenger(this).SendMessage(B_QUIT_REQUESTED);

BAlert* alert = new(std::nothrow) BAlert(
@@ -489,7 +489,7 @@ UserLoginWindow::_SetWorkerThread(thread_id thread)
{
if (!Lock())
return;
-
+
bool enabled = thread < 0;

fUsernameField->SetEnabled(enabled);
@@ -501,7 +501,7 @@ UserLoginWindow::_SetWorkerThread(thread_id thread)
fLanguageCodeField->SetEnabled(enabled);
fCaptchaResultField->SetEnabled(enabled);
fSendButton->SetEnabled(enabled);
-
+
if (thread >= 0) {
fWorkerThread = thread;
resume_thread(fWorkerThread);
@@ -620,7 +620,7 @@ UserLoginWindow::_RequestCaptchaThread()
}
delete[] buffer;
}
- }
+ }
} else {
fprintf(stderr, "Failed to obtain captcha: %s\n",
strerror(status));
}
@@ -738,7 +738,7 @@ UserLoginWindow::_CollectValidationFailures(const BMessage&
result,
BMessage failure;
if (failures.FindMessage(name, &failure) != B_OK)
break;
-
+
BString property;
BString message;
if (failure.FindString("property", &property) == B_OK
@@ -764,7 +764,7 @@ UserLoginWindow::_CollectValidationFailures(const BMessage&
result,
}
}
}
-
+
if (!found) {
error << B_TRANSLATE("But none could be listed here, sorry.");
}
diff --git a/src/apps/haikudepot/ui_generic/LinkView.cpp
b/src/apps/haikudepot/ui_generic/LinkView.cpp
index 673c5d5..5d337fc 100644
--- a/src/apps/haikudepot/ui_generic/LinkView.cpp
+++ b/src/apps/haikudepot/ui_generic/LinkView.cpp
@@ -65,7 +65,7 @@ LinkView::Draw(BRect updateRect)
float y = (bounds.top + bounds.bottom - ceilf(fontHeight.ascent)
- ceilf(fontHeight.descent)) / 2.0 + ceilf(fontHeight.ascent);
float x = 0.0f;
-
+
BString text(Text());
TruncateString(&text, B_TRUNCATE_END, bounds.Width());
DrawString(text, BPoint(x, y));
diff --git a/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp
b/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp
index 9be7cf4..f876e46 100644
--- a/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp
+++ b/src/apps/haikudepot/ui_generic/ScrollableGroupView.cpp
@@ -30,9 +30,9 @@ void
ScrollableGroupView::DoLayout()
{
BGroupView::DoLayout();
-
+
BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
-
+
if (scrollBar == NULL)
return;

diff --git a/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
b/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
index 9382c1e..42d3263 100644
--- a/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
+++ b/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
@@ -76,7 +76,7 @@ SharedBitmap::SharedBitmap(BPositionIO& data)
fBuffer = new(std::nothrow) uint8[fSize];
if (fBuffer != NULL) {
data.Seek(0, SEEK_SET);
-
+
off_t bytesRead = 0;
size_t chunkSize = std::min((off_t)4096, fSize);
while (bytesRead < fSize) {
@@ -86,7 +86,7 @@ SharedBitmap::SharedBitmap(BPositionIO& data)
else
break;
}
-
+
if (bytesRead != fSize) {
delete[] fBuffer;
fBuffer = NULL;
@@ -177,7 +177,7 @@ BBitmap*
SharedBitmap::_CreateBitmapFromBuffer(int32 size) const
{
BBitmap* bitmap = _LoadIconFromBuffer(fBuffer, fSize, size);
-
+
if (bitmap == NULL)
bitmap = _LoadBitmapFromBuffer(fBuffer, fSize);

@@ -214,7 +214,7 @@ SharedBitmap::_LoadBitmapFromBuffer(const void* buffer,
size_t size) const

// Try to read as an archived bitmap.
BBitmap* bitmap = _LoadArchivedBitmapFromStream(stream);
-
+
if (bitmap == NULL) {
// Try to read as a translator bitmap
stream.Seek(0, SEEK_SET);

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

Commit: 3525a370d459f1285ce3178a45992bf7151d7531
URL: http://cgit.haiku-os.org/haiku/commit/?id=3525a370d459
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Wed Apr 8 09:13:50 2015 UTC

HaikuDepot: Add missing init of fSize in default constructor.

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

diff --git a/src/apps/haikudepot/model/PackageInfo.cpp
b/src/apps/haikudepot/model/PackageInfo.cpp
index e976b3c..4befa8f 100644
--- a/src/apps/haikudepot/model/PackageInfo.cpp
+++ b/src/apps/haikudepot/model/PackageInfo.cpp
@@ -473,7 +473,8 @@ PackageInfo::PackageInfo()
fSystemDependency(false),
fArchitecture(),
fLocalFilePath(),
- fFileName()
+ fFileName(),
+ fSize(0)
{
}


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

Revision: hrev49009
Commit: 2a36368bda35aed7210c3285019b286581fc8786
URL: http://cgit.haiku-os.org/haiku/commit/?id=2a36368bda35
Author: Michael Lotz <mmlr@xxxxxxxx>
Date: Wed Apr 8 08:16:54 2015 UTC

HaikuDepot: Make BitmapView use SharedBitmaps directly.

Instead of extracting a BBitmap out of the SharedBitmap and giving that
to BitmapView, set SharedBitmaps directly. When using BBitmaps we
circumvent the reference counting of the SharedBitmaps and it would be
possible for the SharedBitmap and its BBitmaps to get deleted while
one of them was still used in a BitmapView.

Fixes use-after-free when icons are updated that are already used in
BitmapViews.

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

diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
index 80904ec..fc3e33e 100644
--- a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
+++ b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
@@ -151,16 +151,15 @@ public:
fPackageListener->SetPackage(package);

if (package->Icon().Get() != NULL) {
- fIconView->SetBitmap(
- package->Icon()->Bitmap(SharedBitmap::SIZE_64));
+ fIconView->SetBitmap(package->Icon(),
SharedBitmap::SIZE_64);
} else
- fIconView->SetBitmap(NULL);
+ fIconView->UnsetBitmap();

if (package->State() == ACTIVATED) {
- fInstalledIconView->SetBitmap(
- sInstalledIcon->Bitmap(SharedBitmap::SIZE_16));
+ fInstalledIconView->SetBitmap(sInstalledIcon,
+ SharedBitmap::SIZE_16);
} else
- fInstalledIconView->SetBitmap(NULL);
+ fInstalledIconView->UnsetBitmap();

fTitleView->SetText(package->Title());

@@ -199,8 +198,8 @@ public:
{
fPackageListener->SetPackage(PackageInfoRef(NULL));

- fIconView->SetBitmap(NULL);
- fInstalledIconView->SetBitmap(NULL);
+ fIconView->UnsetBitmap();
+ fInstalledIconView->UnsetBitmap();
fTitleView->SetText("");
fPublisherView->SetText("");
fSummaryView->SetText("");
diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp
b/src/apps/haikudepot/ui/PackageInfoView.cpp
index 4e0db2f..5d95ce4 100644
--- a/src/apps/haikudepot/ui/PackageInfoView.cpp
+++ b/src/apps/haikudepot/ui/PackageInfoView.cpp
@@ -391,9 +391,9 @@ public:
void SetPackage(const PackageInfo& package)
{
if (package.Icon().Get() != NULL)
-
fIconView->SetBitmap(package.Icon()->Bitmap(SharedBitmap::SIZE_32));
+ fIconView->SetBitmap(package.Icon(),
SharedBitmap::SIZE_32);
else
- fIconView->SetBitmap(NULL);
+ fIconView->UnsetBitmap();

fTitleView->SetText(package.Title());

@@ -431,7 +431,7 @@ public:

void Clear()
{
- fIconView->SetBitmap(NULL);
+ fIconView->UnsetBitmap();
fTitleView->SetText("");
fPublisherView->SetText("");
fVersionInfo->SetText("");
@@ -797,31 +797,36 @@ public:
fDescriptionView->SetText(package.ShortDescription(),
package.FullDescription());

-
fEmailIconView->SetBitmap(fEmailIcon.Bitmap(SharedBitmap::SIZE_16));
+ fEmailIconView->SetBitmap(&fEmailIcon, SharedBitmap::SIZE_16);
_SetContactInfo(fEmailLinkView, package.Publisher().Email());
-
fWebsiteIconView->SetBitmap(fWebsiteIcon.Bitmap(SharedBitmap::SIZE_16));
+ fWebsiteIconView->SetBitmap(&fWebsiteIcon,
SharedBitmap::SIZE_16);
_SetContactInfo(fWebsiteLinkView,
package.Publisher().Website());

- const BBitmap* screenshot = NULL;
+ bool hasScreenshot = false;
const BitmapList& screenShots = package.Screenshots();
if (screenShots.CountItems() > 0) {
const BitmapRef& bitmapRef = screenShots.ItemAtFast(0);
- if (bitmapRef.Get() != NULL)
- screenshot =
bitmapRef->Bitmap(SharedBitmap::SIZE_ANY);
+ if (bitmapRef.Get() != NULL) {
+ hasScreenshot = true;
+ fScreenshotView->SetBitmap(bitmapRef);
+ }
}
- fScreenshotView->SetBitmap(screenshot);
- fScreenshotView->SetEnabled(screenshot != NULL);
+
+ if (!hasScreenshot)
+ fScreenshotView->UnsetBitmap();
+
+ fScreenshotView->SetEnabled(hasScreenshot);
}

void Clear()
{
fDescriptionView->SetText("");
- fEmailIconView->SetBitmap(NULL);
+ fEmailIconView->UnsetBitmap();
fEmailLinkView->SetText("");
- fWebsiteIconView->SetBitmap(NULL);
+ fWebsiteIconView->UnsetBitmap();
fWebsiteLinkView->SetText("");

- fScreenshotView->SetBitmap(NULL);
+ fScreenshotView->UnsetBitmap();
fScreenshotView->SetEnabled(false);
}

@@ -867,8 +872,8 @@ public:

fAvatarView = new BitmapView("avatar view");
if (rating.User().Avatar().Get() != NULL) {
- fAvatarView->SetBitmap(
-
rating.User().Avatar()->Bitmap(SharedBitmap::SIZE_16));
+ fAvatarView->SetBitmap(rating.User().Avatar(),
+ SharedBitmap::SIZE_16);
}
fAvatarView->SetExplicitMinSize(BSize(16.0f, 16.0f));

@@ -908,10 +913,8 @@ public:
// fVoteDownIconView = new BitmapButton("vote down icon",
voteDownMessage);
// fDownVoteCountView = new BStringView("up vote count", "");
//
-// fVoteUpIconView->SetBitmap(
-// voteUpIcon->Bitmap(SharedBitmap::SIZE_16));
-// fVoteDownIconView->SetBitmap(
-// voteDownIcon->Bitmap(SharedBitmap::SIZE_16));
+// fVoteUpIconView->SetBitmap(voteUpIcon, SharedBitmap::SIZE_16);
+// fVoteDownIconView->SetBitmap(voteDownIcon,
SharedBitmap::SIZE_16);
//
// fUpVoteCountView->SetFont(&versionFont);
// fUpVoteCountView->SetHighColor(kLightBlack);
diff --git a/src/apps/haikudepot/ui/ScreenshotWindow.cpp
b/src/apps/haikudepot/ui/ScreenshotWindow.cpp
index 175e132..5e6eb7c 100644
--- a/src/apps/haikudepot/ui/ScreenshotWindow.cpp
+++ b/src/apps/haikudepot/ui/ScreenshotWindow.cpp
@@ -175,8 +175,8 @@ ScreenshotWindow::_DownloadThread()
return;
}

- fScreenshotView->SetBitmap(NULL);
-
+ fScreenshotView->UnsetBitmap();
+
ScreenshotInfoList screenshotInfos;
if (fPackage.Get() != NULL)
screenshotInfos = fPackage->ScreenshotInfos();
@@ -202,7 +202,7 @@ ScreenshotWindow::_DownloadThread()
if (status == B_OK && Lock()) {
printf("got screenshot");
fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer),
true);
-
fScreenshotView->SetBitmap(fScreenshot->Bitmap(SharedBitmap::SIZE_ANY));
+ fScreenshotView->SetBitmap(fScreenshot);
_ResizeToFitAndCenter();
Unlock();
} else {
diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp
b/src/apps/haikudepot/ui/UserLoginWindow.cpp
index 8836922..89cfd85 100644
--- a/src/apps/haikudepot/ui/UserLoginWindow.cpp
+++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp
@@ -235,10 +235,9 @@ UserLoginWindow::MessageReceived(BMessage* message)

case MSG_CAPTCHA_OBTAINED:
if (fCaptchaImage.Get() != NULL) {
- fCaptchaView->SetBitmap(
-
fCaptchaImage->Bitmap(SharedBitmap::SIZE_ANY));
+ fCaptchaView->SetBitmap(fCaptchaImage);
} else {
- fCaptchaView->SetBitmap(NULL);
+ fCaptchaView->UnsetBitmap();
}
fCaptchaResultField->SetText("");
break;
@@ -442,7 +441,7 @@ UserLoginWindow::_RequestCaptcha()
{
if (Lock()) {
fCaptchaToken = "";
- fCaptchaView->SetBitmap(NULL);
+ fCaptchaView->UnsetBitmap();
fCaptchaImage.Unset();
Unlock();
}
diff --git a/src/apps/haikudepot/ui_generic/BitmapView.cpp
b/src/apps/haikudepot/ui_generic/BitmapView.cpp
index 0c7f77e..0bb8597 100644
--- a/src/apps/haikudepot/ui_generic/BitmapView.cpp
+++ b/src/apps/haikudepot/ui_generic/BitmapView.cpp
@@ -131,14 +131,16 @@ BitmapView::MaxSize()


void
-BitmapView::SetBitmap(const BBitmap* bitmap)
+BitmapView::SetBitmap(SharedBitmap* bitmap, SharedBitmap::Size bitmapSize)
{
- if (bitmap == fBitmap)
+ if (bitmap == fReference && bitmapSize == fBitmapSize)
return;

BSize size = MinSize();

- fBitmap = bitmap;
+ fReference.SetTo(bitmap);
+ fBitmapSize = bitmapSize;
+ fBitmap = bitmap->Bitmap(bitmapSize);

BSize newSize = MinSize();
if (size != newSize)
@@ -149,6 +151,20 @@ BitmapView::SetBitmap(const BBitmap* bitmap)


void
+BitmapView::UnsetBitmap()
+{
+ if (fReference.Get() == NULL)
+ return;
+
+ fBitmap = NULL;
+ fReference.Unset();
+
+ InvalidateLayout();
+ Invalidate();
+}
+
+
+void
BitmapView::SetScaleBitmap(bool scaleBitmap)
{
if (scaleBitmap == fScaleBitmap)
diff --git a/src/apps/haikudepot/ui_generic/BitmapView.h
b/src/apps/haikudepot/ui_generic/BitmapView.h
index ba7ddc5..327f35f 100644
--- a/src/apps/haikudepot/ui_generic/BitmapView.h
+++ b/src/apps/haikudepot/ui_generic/BitmapView.h
@@ -6,6 +6,8 @@
#define BITMAP_VIEW_H


+#include "SharedBitmap.h"
+
#include <View.h>


@@ -22,7 +24,10 @@ public:
virtual BSize PreferredSize();
virtual BSize MaxSize();

- void SetBitmap(const
BBitmap* bitmap);
+ void SetBitmap(SharedBitmap*
bitmap,
+
SharedBitmap::Size bitmapSize
+
= SharedBitmap::SIZE_ANY);
+ void UnsetBitmap();
void SetScaleBitmap(bool
scaleBitmap);

protected:
@@ -30,6 +35,8 @@ protected:
BRect
updateRect);

private:
+ BitmapRef fReference;
+ SharedBitmap::Size fBitmapSize;
const BBitmap* fBitmap;
bool fScaleBitmap;
};


Other related posts:

  • » [haiku-commits] haiku: hrev49009 - in src: apps/haikudepot/ui bin/desklink apps/haikudepot/ui_generic apps/haikudepot/model - mmlr