DiskUsage: reuse string_for_size in libshared.a

This commit is contained in:
Philippe Saint-Pierre
2013-07-13 14:19:09 -04:00
parent 3fe416173c
commit fffc0e2a7b
5 changed files with 7 additions and 35 deletions
-31
View File
@@ -20,37 +20,6 @@
entry_ref helpFileRef;
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
main()
{
+2 -1
View File
@@ -17,6 +17,7 @@
#include <vector>
#include <Catalog.h>
#include <StringForSize.h>
#include <StringView.h>
#include <Bitmap.h>
#include <NodeInfo.h>
@@ -77,7 +78,7 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent)
// Size
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) {
// This is a directory.
char str[64];
+1 -1
View File
@@ -14,7 +14,7 @@ Application DiskUsage :
Snapshot.cpp
StatusView.cpp
VolumeView.cpp
: be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++)
: be libshared.a $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++)
: DiskUsage.rdef
;
+2 -1
View File
@@ -26,6 +26,7 @@
#include <PopUpMenu.h>
#include <Roster.h>
#include <String.h>
#include <StringForSize.h>
#include <Volume.h>
#include <tracker_private.h>
@@ -456,7 +457,7 @@ PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan,
// Show total volume capacity.
char label[B_PATH_NAME_LENGTH];
size_to_string(volCapacity, label, sizeof(label));
string_for_size(volCapacity, label, sizeof(label));
SetHighColor(kPieBGColor);
SetDrawingMode(B_OP_OVER);
DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
+2 -1
View File
@@ -19,6 +19,7 @@
#include <Button.h>
#include <Node.h>
#include <String.h>
#include <StringForSize.h>
#include <StringView.h>
#include <LayoutBuilder.h>
@@ -145,7 +146,7 @@ StatusView::ShowInfo(const FileInfo* info)
fPathView->SetText(pathLabel.String());
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);
if (info->count > 0) {