DiskUsage: reuse string_for_size in libshared.a
This commit is contained in:
@@ -20,37 +20,6 @@
|
|||||||
entry_ref helpFileRef;
|
entry_ref helpFileRef;
|
||||||
bool helpFileWasFound = false;
|
bool helpFileWasFound = false;
|
||||||
|
|
||||||
void
|
|
||||||
size_to_string(off_t byteCount, char* name, int maxLength)
|
|
||||||
{
|
|
||||||
struct {
|
|
||||||
off_t limit;
|
|
||||||
float divisor;
|
|
||||||
const char* format;
|
|
||||||
} scale[] = {
|
|
||||||
{ 0x100000, 1024.0,
|
|
||||||
B_TRANSLATE("%.2f KiB") },
|
|
||||||
{ 0x40000000, 1048576.0,
|
|
||||||
B_TRANSLATE("%.2f MiB") },
|
|
||||||
{ 0x10000000000ull, 1073741824.0,
|
|
||||||
B_TRANSLATE("%.2f GiB") },
|
|
||||||
{ 0x4000000000000ull, 1.09951162778e+12,
|
|
||||||
B_TRANSLATE("%.2f TiB") }
|
|
||||||
};
|
|
||||||
|
|
||||||
if (byteCount < 1024) {
|
|
||||||
snprintf(name, maxLength, B_TRANSLATE("%lld bytes"),
|
|
||||||
byteCount);
|
|
||||||
} else {
|
|
||||||
int i = 0;
|
|
||||||
while (byteCount >= scale[i].limit)
|
|
||||||
i++;
|
|
||||||
|
|
||||||
snprintf(name, maxLength, scale[i].format,
|
|
||||||
byteCount / scale[i].divisor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
|
#include <StringForSize.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
@@ -77,7 +78,7 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
|
|||||||
|
|
||||||
// Size
|
// Size
|
||||||
char name[B_PATH_NAME_LENGTH] = { 0 };
|
char name[B_PATH_NAME_LENGTH] = { 0 };
|
||||||
size_to_string(f->size, name, sizeof(name));
|
string_for_size(f->size, name, sizeof(name));
|
||||||
if (f->count > 0) {
|
if (f->count > 0) {
|
||||||
// This is a directory.
|
// This is a directory.
|
||||||
char str[64];
|
char str[64];
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Application DiskUsage :
|
|||||||
Snapshot.cpp
|
Snapshot.cpp
|
||||||
StatusView.cpp
|
StatusView.cpp
|
||||||
VolumeView.cpp
|
VolumeView.cpp
|
||||||
: be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++)
|
: be libshared.a $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++)
|
||||||
: DiskUsage.rdef
|
: DiskUsage.rdef
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <StringForSize.h>
|
||||||
#include <Volume.h>
|
#include <Volume.h>
|
||||||
|
|
||||||
#include <tracker_private.h>
|
#include <tracker_private.h>
|
||||||
@@ -456,7 +457,7 @@ PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan,
|
|||||||
|
|
||||||
// Show total volume capacity.
|
// Show total volume capacity.
|
||||||
char label[B_PATH_NAME_LENGTH];
|
char label[B_PATH_NAME_LENGTH];
|
||||||
size_to_string(volCapacity, label, sizeof(label));
|
string_for_size(volCapacity, label, sizeof(label));
|
||||||
SetHighColor(kPieBGColor);
|
SetHighColor(kPieBGColor);
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
|
DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <StringForSize.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
|
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
@@ -145,7 +146,7 @@ StatusView::ShowInfo(const FileInfo* info)
|
|||||||
fPathView->SetText(pathLabel.String());
|
fPathView->SetText(pathLabel.String());
|
||||||
|
|
||||||
char label[B_PATH_NAME_LENGTH];
|
char label[B_PATH_NAME_LENGTH];
|
||||||
size_to_string(info->size, label, sizeof(label));
|
string_for_size(info->size, label, sizeof(label));
|
||||||
fSizeView->SetText(label);
|
fSizeView->SetText(label);
|
||||||
|
|
||||||
if (info->count > 0) {
|
if (info->count > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user