From f67071b98ca57efd722b4603fcfe1c899fd2c4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 4 Apr 2015 22:43:49 +0200 Subject: [PATCH] HaikuDepot: Re-activated Size-column Noticed that HaikuDepotServer info now contains "payloadLength", which is the package size. Populate that in the list view. --- src/apps/haikudepot/model/Model.cpp | 6 +++- src/apps/haikudepot/model/PackageInfo.cpp | 23 ++++++++++--- src/apps/haikudepot/model/PackageInfo.h | 5 +++ .../haikudepot/model/PackageInfoListener.h | 3 +- src/apps/haikudepot/ui/PackageListView.cpp | 34 +++++++++++++++---- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index 284a31764a..74b0f4551a 100644 --- a/src/apps/haikudepot/model/Model.cpp +++ b/src/apps/haikudepot/model/Model.cpp @@ -1113,7 +1113,6 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data) BAutolock locker(&fLock); BString foundInfo; - data.PrintToStream(); BMessage versions; if (data.FindMessage("versions", &versions) == B_OK) { @@ -1141,6 +1140,11 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data) package->SetFullDescription(description); append_word_list(foundInfo, "description"); } + double payloadLength; + if (version.FindDouble("payloadLength", &payloadLength) == B_OK) { + package->SetSize((int64)payloadLength); + append_word_list(foundInfo, "size"); + } break; } } diff --git a/src/apps/haikudepot/model/PackageInfo.cpp b/src/apps/haikudepot/model/PackageInfo.cpp index 28cbb41a11..a6281567a7 100644 --- a/src/apps/haikudepot/model/PackageInfo.cpp +++ b/src/apps/haikudepot/model/PackageInfo.cpp @@ -499,7 +499,8 @@ PackageInfo::PackageInfo(const BPackageInfo& info) fSystemDependency(false), fArchitecture(info.ArchitectureName()), fLocalFilePath(), - fFileName(info.FileName()) + fFileName(info.FileName()), + fSize(0) // TODO: Retrieve local file size { BString publisherURL; if (info.URLList().CountStrings() > 0) @@ -541,7 +542,8 @@ PackageInfo::PackageInfo(const BString& name, fSystemDependency(false), fArchitecture(architecture), fLocalFilePath(), - fFileName() + fFileName(), + fSize(0) { } @@ -569,7 +571,8 @@ PackageInfo::PackageInfo(const PackageInfo& other) fSystemDependency(other.fSystemDependency), fArchitecture(other.fArchitecture), fLocalFilePath(other.fLocalFilePath), - fFileName(other.fFileName) + fFileName(other.fFileName), + fSize(other.fSize) { } @@ -599,6 +602,7 @@ PackageInfo::operator=(const PackageInfo& other) fArchitecture = other.fArchitecture; fLocalFilePath = other.fLocalFilePath; fFileName = other.fFileName; + fSize = other.fSize; return *this; } @@ -627,7 +631,8 @@ PackageInfo::operator==(const PackageInfo& other) const && fSystemDependency == other.fSystemDependency && fArchitecture == other.fArchitecture && fLocalFilePath == other.fLocalFilePath - && fFileName == other.fFileName; + && fFileName == other.fFileName + && fSize == other.fSize; } @@ -915,6 +920,16 @@ PackageInfo::AddScreenshot(const BitmapRef& screenshot) } +void +PackageInfo::SetSize(int64 size) +{ + if (fSize != size) { + fSize = size; + _NotifyListeners(PKG_CHANGED_SIZE); + } +} + + bool PackageInfo::AddListener(const PackageInfoListenerRef& listener) { diff --git a/src/apps/haikudepot/model/PackageInfo.h b/src/apps/haikudepot/model/PackageInfo.h index b363fc72b8..40de3f2e7c 100644 --- a/src/apps/haikudepot/model/PackageInfo.h +++ b/src/apps/haikudepot/model/PackageInfo.h @@ -336,6 +336,10 @@ public: const BitmapList& Screenshots() const { return fScreenshots; } + void SetSize(int64 size); + int64 Size() const + { return fSize; } + bool AddListener( const PackageInfoListenerRef& listener); void RemoveListener( @@ -371,6 +375,7 @@ private: BString fArchitecture; BString fLocalFilePath; BString fFileName; + int64 fSize; static BitmapRef sDefaultIcon; }; diff --git a/src/apps/haikudepot/model/PackageInfoListener.h b/src/apps/haikudepot/model/PackageInfoListener.h index 9d89a47b42..748b2b34c3 100644 --- a/src/apps/haikudepot/model/PackageInfoListener.h +++ b/src/apps/haikudepot/model/PackageInfoListener.h @@ -19,7 +19,8 @@ enum { PKG_CHANGED_ICON = 1 << 6, PKG_CHANGED_CHANGELOG = 1 << 7, PKG_CHANGED_CATEGORIES = 1 << 8, - PKG_CHANGED_PROMINENCE = 1 << 9 + PKG_CHANGED_PROMINENCE = 1 << 9, + PKG_CHANGED_SIZE = 1 << 10 // ... }; diff --git a/src/apps/haikudepot/ui/PackageListView.cpp b/src/apps/haikudepot/ui/PackageListView.cpp index 88907d72b7..f9c2a13935 100644 --- a/src/apps/haikudepot/ui/PackageListView.cpp +++ b/src/apps/haikudepot/ui/PackageListView.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "MainWindow.h" @@ -130,6 +131,7 @@ public: void UpdateSummary(); void UpdateState(); void UpdateRating(); + void UpdateSize(); private: PackageInfoRef fPackage; @@ -451,7 +453,7 @@ enum { kTitleColumn, kRatingColumn, kDescriptionColumn, -// kSizeColumn, + kSizeColumn, kStatusColumn, }; @@ -479,12 +481,10 @@ PackageRow::PackageRow(const PackageInfoRef& packageRef, UpdateSummary(); // Size - // TODO: Store package size -// SetField(new BStringField("0 KiB"), kSizeColumn); + UpdateSize(); // Status - SetField(new BStringField(package_state_to_string(fPackage)), - kStatusColumn); + UpdateState(); package.AddListener(fPackageListener); } @@ -542,6 +542,22 @@ PackageRow::UpdateRating() } +void +PackageRow::UpdateSize() +{ + if (fPackage.Get() == NULL) + return; + BString size; + if (fPackage->Size() == 0) { + size = B_TRANSLATE_CONTEXT("-", "no package size"); + } else { + char buffer[256]; + size = string_for_size(fPackage->Size(), buffer, sizeof(buffer)); + } + SetField(new BStringField(size), kSizeColumn); +} + + // #pragma mark - ItemCountView @@ -640,8 +656,10 @@ PackageListView::PackageListView(BLocker* modelLock) B_TRUNCATE_MIDDLE), kRatingColumn); AddColumn(new PackageColumn(B_TRANSLATE("Description"), 300, 80, 1000, B_TRUNCATE_MIDDLE), kDescriptionColumn); -// AddColumn(new PackageColumn(B_TRANSLATE("Size"), 60, 50, 100, -// B_TRUNCATE_END), kSizeColumn); + PackageColumn* sizeColumn = new PackageColumn(B_TRANSLATE("Size"), + 60, 50, 100, B_TRUNCATE_END); + sizeColumn->SetAlignment(B_ALIGN_RIGHT); + AddColumn(sizeColumn, kSizeColumn); AddColumn(new PackageColumn(B_TRANSLATE("Status"), 60, 60, 100, B_TRUNCATE_END), kStatusColumn); @@ -700,6 +718,8 @@ PackageListView::MessageReceived(BMessage* message) row->UpdateRating(); if ((changes & PKG_CHANGED_STATE) != 0) row->UpdateState(); + if ((changes & PKG_CHANGED_SIZE) != 0) + row->UpdateSize(); if ((changes & PKG_CHANGED_ICON) != 0) row->UpdateTitle(); }