HaikuDepot: Re-activated Size-column

Noticed that HaikuDepotServer info now contains "payloadLength", which is
the package size. Populate that in the list view.
This commit is contained in:
Stephan Aßmus 2015-04-04 22:43:49 +02:00
parent 53094e2fa1
commit f67071b98c
5 changed files with 58 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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;
};

View File

@ -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
// ...
};

View File

@ -13,6 +13,7 @@
#include <Catalog.h>
#include <MessageFormat.h>
#include <ScrollBar.h>
#include <StringForSize.h>
#include <Window.h>
#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();
}