From 973f8e214d612688c4a30fd48572a7eb57c902be Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Mon, 14 Feb 2011 18:26:15 +0000 Subject: [PATCH] Applied yet another localization patch from Jorma Karvonen. Fixes #7169. Beside of localization task some refactoring was performed: - strings, stored previously in resources were moved from resource definition file to cpp files at the place of using; - cleanup of resource definitions and Common.cpp/Common.h. Additionall tasks, made by S.Zharski: - the rests of resource handling tasks were purged out from Common.cpp/Common.h; - Common.h renamed to DiskUsage.h; - the rests of code from Common.cpp merged into DiskUsage.cpp; - the preprocessor tricks and magics targeted mainly for resources support were removed; - some code style fixes and "internationalization style" fixes were made. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40493 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskusage/App.cpp | 15 ++- src/apps/diskusage/App.h | 1 - src/apps/diskusage/Common.cpp | 151 ---------------------------- src/apps/diskusage/Common.h | 107 -------------------- src/apps/diskusage/ControlsView.cpp | 2 +- src/apps/diskusage/DiskUsage.cpp | 41 +++++++- src/apps/diskusage/DiskUsage.h | 77 ++++++++++++++ src/apps/diskusage/DiskUsage.rdef | 39 +------ src/apps/diskusage/InfoWindow.cpp | 50 +++++---- src/apps/diskusage/Jamfile | 14 ++- src/apps/diskusage/MainWindow.cpp | 10 +- src/apps/diskusage/PieView.cpp | 31 +++--- src/apps/diskusage/Scanner.cpp | 24 +++-- src/apps/diskusage/StatusView.cpp | 18 ++-- src/apps/diskusage/VolumeView.cpp | 10 +- 15 files changed, 234 insertions(+), 356 deletions(-) delete mode 100644 src/apps/diskusage/Common.cpp delete mode 100644 src/apps/diskusage/Common.h create mode 100644 src/apps/diskusage/DiskUsage.h diff --git a/src/apps/diskusage/App.cpp b/src/apps/diskusage/App.cpp index 9a165d3097..4c2c97ef72 100644 --- a/src/apps/diskusage/App.cpp +++ b/src/apps/diskusage/App.cpp @@ -12,27 +12,36 @@ #include +#include #include #include #include #include -#include "Common.h" +#include "DiskUsage.h" #include "MainWindow.h" App::App() : BApplication(kAppSignature), - fResources(read_resources(kAppSignature)), fMainWindow(NULL), fSavedRefsReceived(NULL) { + // Get a reference to the help file. + BPath path; + if (find_directory(B_BEOS_DOCUMENTATION_DIRECTORY, &path) == B_OK + && path.Append(kHelpFileName) == B_OK) { + printf("help file =? %s\n", path.Path()); + BEntry entry(path.Path()); + helpFileWasFound = entry.Exists(); + entry.GetRef(&helpFileRef); + } else + helpFileWasFound = false; } App::~App() { - delete fResources; delete fSavedRefsReceived; } diff --git a/src/apps/diskusage/App.h b/src/apps/diskusage/App.h index cc3b3f6392..0cb32780c6 100644 --- a/src/apps/diskusage/App.h +++ b/src/apps/diskusage/App.h @@ -27,7 +27,6 @@ public: virtual bool QuitRequested(); private: - BResources* fResources; MainWindow* fMainWindow; BMessage* fSavedRefsReceived; }; diff --git a/src/apps/diskusage/Common.cpp b/src/apps/diskusage/Common.cpp deleted file mode 100644 index 68b4f17d5a..0000000000 --- a/src/apps/diskusage/Common.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2008 Stephan Aßmus . All rights reserved. - * Distributed under the terms of the MIT/X11 license. - * - * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software - * as long as it is accompanied by it's documentation and this copyright notice. - * The software comes with no warranty, etc. - */ - - -#define ASSIGN_RESOURCES -#include "Common.h" -#undef ASSIGN_RESOURCES - -#include -#include -#include - -#include -#include -#include -#include - - -const char* kAppSignature = "application/x-vnd.Haiku-DiskUsage"; -const char* kHelpFileName = "userguide/en/applications/diskusage.html"; -const char* kPieRectAttrName = "mainrect"; - -const char* kHelpBtnLabel = "?"; -const char* kEmptyStr = ""; -const char* kNameVolPtr = "vol"; -const char* kNameFilePtr = "file"; - -const float kSmallHMargin = 5.0; -const float kSmallVMargin = 2.0; -const float kButtonMargin = 20.0; -const float kMinButtonWidth = 60.0; - -const float kProgBarWidth = 150.0; -const float kProgBarHeight = 16.0; -const float kReportInterval = 2.5; - -const float kDefaultPieSize = 400.0; -const float kPieCenterSize = 80.0; -const float kPieRingSize = 20.0; -const float kPieInnerMargin = 10.0; -const float kPieOuterMargin = 10.0; -const float kMinSegmentSpan = 2.0; -const int kLightenFactor = 0x12; -const float kDragThreshold = 5.0; - - -BResources* -read_resources(const char* appSignature) -{ - status_t ret = be_app->GetAppInfo(&kAppInfo); - if (ret != B_OK) { - fprintf(stderr, "Failed to init application info: %s\n", - strerror(ret)); - exit(1); - } - - BFile file(&kAppInfo.ref, O_RDONLY); - ret = file.InitCheck(); - if (ret != B_OK) { - fprintf(stderr, "Failed to init application file to read resources: " - "%s\n", strerror(ret)); - exit(1); - } - - BResources* r = new BResources(&file); - -#define LoadString(n) (char*)r->LoadResource(B_STRING_TYPE, n, &ignore) -#define LoadColor(n) *(rgb_color*)r->LoadResource(B_RGB_COLOR_TYPE, n, &ignore) -#define LoadUint8(n) *(uint8*)r->LoadResource(B_UINT8_TYPE, n, &ignore) - - size_t ignore; - kVolMenuLabel = LoadString("STR_VM_LABEL"); - kOneFile = LoadString("STR_1_FILE"); - kManyFiles = LoadString("STR_N_FILES"); - kStrScan = LoadString("STR_SCAN"); - kStrRescan = LoadString("STR_RESCAN"); - kStrScanningX = LoadString("STR_SCN_X"); - kStrUnavail = LoadString("STR_UNAVAIL"); - kVolMenuDefault = LoadString("STR_VM_DFLT"); - kVolPrompt = LoadString("STR_VPROMPT"); - kMenuGetInfo = LoadString("STR_M_INFO"); - kMenuOpen = LoadString("STR_M_OPEN"); - kMenuOpenWith = LoadString("STR_M_OPENW"); - kMenuNoApps = LoadString("STR_M_NAPPS"); - kInfoSize = LoadString("STR_SIZE"); - kInfoInFiles = LoadString("STR_INFILES"); - kInfoCreated = LoadString("STR_MADE"); - kInfoModified = LoadString("STR_MOD"); - kInfoTimeFmt = LoadString("STR_TIMEFMT"); - kInfoKind = LoadString("STR_KIND"); - kInfoPath = LoadString("STR_PATH"); - kOutdatedStr = LoadString("STR_OUTDATED"); - - kWindowColor = ui_color(B_PANEL_BACKGROUND_COLOR); - kOutlineColor = LoadColor("RGB_PIE_OL"); - kPieBGColor = LoadColor("RGB_PIE_BG"); - kEmptySpcColor = LoadColor("RGB_PIE_MT"); - - kBasePieColorCount = LoadUint8("N_PIE_COLORS"); - kBasePieColor = new rgb_color[kBasePieColorCount]; - for (int i = 0; i < kBasePieColorCount; i++) { - char colorName[16] = "RGB_PIE_n"; - colorName[8] = '1' + i; - kBasePieColor[i] = LoadColor(colorName); - } - - // Get a reference to the help file. - BPath path; - if (find_directory(B_BEOS_DOCUMENTATION_DIRECTORY, &path) == B_OK - && path.Append(kHelpFileName) == B_OK) { - printf("help file =? %s\n", path.Path()); - BEntry entry(path.Path()); - kFoundHelpFile = entry.Exists(); - entry.GetRef(&kHelpFileRef); - } else - kFoundHelpFile = false; - - return r; -} - - -void -size_to_string(off_t byteCount, char* name) -{ - struct { - off_t limit; - float divisor; - const char* format; - } scale[] = { - { 0x100000, 1024.0, "%.2f KiB" }, - { 0x40000000, 1048576.0, "%.2f MiB" }, - { 0x10000000000ull, 1073741824.0, "%.2f GiB" }, - { 0x4000000000000ull, 1.09951162778e+12, "%.2f TiB" } - }; - - if (byteCount < 1024) { - sprintf(name, "%lld bytes", byteCount); - } else { - int i = 0; - while (byteCount >= scale[i].limit) - i++; - - sprintf(name, scale[i].format, byteCount / scale[i].divisor); - } -} diff --git a/src/apps/diskusage/Common.h b/src/apps/diskusage/Common.h deleted file mode 100644 index 1280419040..0000000000 --- a/src/apps/diskusage/Common.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2008 Stephan Aßmus . All rights reserved. - * Distributed under the terms of the MIT/X11 license. - * - * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software - * as long as it is accompanied by it's documentation and this copyright notice. - * The software comes with no warranty, etc. - */ -#ifndef COMMON_H -#define COMMON_H - - -#include -#include -#include -#include - - -#ifdef ASSIGN_RESOURCES -# define EXTERN -# define EQ(x) -#else -# define EXTERN extern -# define EQ(x) -#endif - -#define EXTERN_CONST extern const - - -// Resources -EXTERN char* kStrScan; -EXTERN char* kStrRescan; -EXTERN char* kOutdatedStr; -EXTERN char* kStrScanningX; -EXTERN char* kStrUnavail; -EXTERN char* kVolMenuLabel; -EXTERN char* kVolMenuDefault; -EXTERN char* kVolPrompt; -EXTERN char* kOneFile; -EXTERN char* kManyFiles; -EXTERN char* kMenuGetInfo; -EXTERN char* kMenuOpen; -EXTERN char* kMenuOpenWith; -EXTERN char* kMenuNoApps; -EXTERN char* kInfoSize; -EXTERN char* kInfoInFiles; -EXTERN char* kInfoCreated; -EXTERN char* kInfoModified; -EXTERN char* kInfoTimeFmt; -EXTERN char* kInfoKind; -EXTERN char* kInfoPath; - -EXTERN rgb_color kWindowColor; -EXTERN rgb_color kOutlineColor; -EXTERN rgb_color kPieBGColor; -EXTERN rgb_color kEmptySpcColor; -EXTERN int kBasePieColorCount; -EXTERN rgb_color *kBasePieColor; - -// Non-resources :) -EXTERN_CONST char* kAppSignature; -EXTERN_CONST char* kHelpFileName; -EXTERN_CONST char* kPieRectAttrName; - -EXTERN_CONST char* kHelpBtnLabel; -EXTERN_CONST char* kEmptyStr; -EXTERN_CONST char* kNameVolPtr; -EXTERN_CONST char* kNameFilePtr; - -EXTERN_CONST float kSmallHMargin; -EXTERN_CONST float kSmallVMargin; -EXTERN_CONST float kButtonMargin; -EXTERN_CONST float kMinButtonWidth; - -EXTERN_CONST float kProgBarWidth; -EXTERN_CONST float kProgBarHeight; -EXTERN_CONST float kReportInterval; - -EXTERN_CONST float kDefaultPieSize; -EXTERN_CONST float kPieCenterSize; -EXTERN_CONST float kPieRingSize; -EXTERN_CONST float kPieInnerMargin; -EXTERN_CONST float kPieOuterMargin; -EXTERN_CONST float kMinSegmentSpan; -EXTERN_CONST int kLightenFactor; -EXTERN_CONST float kDragThreshold; - -EXTERN app_info kAppInfo; -EXTERN entry_ref kHelpFileRef; -EXTERN bool kFoundHelpFile; - -#define kMenuSelectVol 'gMSV' -#define kBtnRescan 'gBRF' -#define kBtnHelp 'gHLP' -#define kScanRefresh 'gSRF' -#define kScanProgress 'gSPR' -#define kScanDone 'gSDN' -#define kOutdatedMsg 'gOUT' - -#define deg2rad(x) (2.0 * M_PI * (x) / 360.0) -#define rad2deg(x) (360.0 * (x) / (2.0 * M_PI)) - -BResources* read_resources(const char* appSignature); -void size_to_string(off_t byteCount, char* name); - - -#endif // COMMON_H diff --git a/src/apps/diskusage/ControlsView.cpp b/src/apps/diskusage/ControlsView.cpp index 8d1d31208b..35903a0c7f 100644 --- a/src/apps/diskusage/ControlsView.cpp +++ b/src/apps/diskusage/ControlsView.cpp @@ -23,7 +23,7 @@ #include -#include "Common.h" +#include "DiskUsage.h" #include "VolumeView.h" diff --git a/src/apps/diskusage/DiskUsage.cpp b/src/apps/diskusage/DiskUsage.cpp index bc3d8670e7..28d37e86a7 100644 --- a/src/apps/diskusage/DiskUsage.cpp +++ b/src/apps/diskusage/DiskUsage.cpp @@ -6,8 +6,46 @@ #include "App.h" -#include +#include +#include + +#include "DiskUsage.h" + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "DiskUsage" + +entry_ref helpFileRef; +bool helpFileWasFound = false; + +void +size_to_string(off_t byteCount, char* name) +{ + 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) { + sprintf(name, B_TRANSLATE("%lld bytes"), byteCount); + } else { + int i = 0; + while (byteCount >= scale[i].limit) + i++; + + sprintf(name, scale[i].format, byteCount / scale[i].divisor); + } +} int main() @@ -16,3 +54,4 @@ main() app.Run(); return 0; } + diff --git a/src/apps/diskusage/DiskUsage.h b/src/apps/diskusage/DiskUsage.h new file mode 100644 index 0000000000..729d9604f1 --- /dev/null +++ b/src/apps/diskusage/DiskUsage.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2008 Stephan Aßmus . All rights reserved. + * Distributed under the terms of the MIT/X11 license. + * + * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software + * as long as it is accompanied by it's documentation and this copyright notice. + * The software comes with no warranty, etc. + */ +#ifndef DISKUSAGE_H +#define DISKUSAGE_H + + +#include +#include + + +const rgb_color RGB_WIN = { 0xDE, 0xDB, 0xDE, 0xFF }; +const rgb_color RGB_PIE_OL = { 0x80, 0x80, 0x80, 0xFF }; +const rgb_color RGB_PIE_BG = { 0xFF, 0xFF, 0xFF, 0xFF }; +const rgb_color RGB_PIE_MT = { 0xA0, 0xA0, 0xA0, 0xFF }; +const rgb_color RGB_PIE_1 = { 0x00, 0x60, 0x60, 0xFF }; +const rgb_color RGB_PIE_2 = { 0x00, 0x00, 0x68, 0xFF }; +const rgb_color RGB_PIE_3 = { 0x60, 0x00, 0x60, 0xFF }; +const rgb_color RGB_PIE_4 = { 0x68, 0x00, 0x00, 0xFF }; + +const int kBasePieColorCount = 4; +const rgb_color kBasePieColor[kBasePieColorCount] + = { RGB_PIE_1, RGB_PIE_2, RGB_PIE_3, RGB_PIE_4 }; + +const rgb_color kWindowColor = ui_color(B_PANEL_BACKGROUND_COLOR); +const rgb_color kOutlineColor = RGB_PIE_OL; +const rgb_color kPieBGColor = RGB_PIE_BG; +const rgb_color kEmptySpcColor = RGB_PIE_MT; + +const char* const kAppSignature = "application/x-vnd.Haiku-DiskUsage"; +const char* const kHelpFileName = "userguide/en/applications/diskusage.html"; + +const char* const kEmptyStr = ""; +const char* const kNameFilePtr = "file"; + +const float kSmallHMargin = 5.0; +const float kSmallVMargin = 2.0; +const float kButtonMargin = 20.0; +const float kMinButtonWidth = 60.0; + +const float kProgBarWidth = 150.0; +const float kProgBarHeight = 16.0; +const float kReportInterval = 2.5; + +const float kDefaultPieSize = 400.0; +const float kPieCenterSize = 80.0; +const float kPieRingSize = 20.0; +const float kPieInnerMargin = 10.0; +const float kPieOuterMargin = 10.0; +const float kMinSegmentSpan = 2.0; +const int kLightenFactor = 0x12; +const float kDragThreshold = 5.0; + +extern entry_ref helpFileRef; +extern bool helpFileWasFound; + +#define kMenuSelectVol 'gMSV' +#define kBtnRescan 'gBRF' +#define kBtnHelp 'gHLP' +#define kScanRefresh 'gSRF' +#define kScanProgress 'gSPR' +#define kScanDone 'gSDN' +#define kOutdatedMsg 'gOUT' + +#define deg2rad(x) (2.0 * M_PI * (x) / 360.0) +#define rad2deg(x) (360.0 * (x) / (2.0 * M_PI)) + +void size_to_string(off_t byteCount, char* name); + + +#endif // DISKUSAGE_H + diff --git a/src/apps/diskusage/DiskUsage.rdef b/src/apps/diskusage/DiskUsage.rdef index 2ee4c8c839..1e18e39aca 100644 --- a/src/apps/diskusage/DiskUsage.rdef +++ b/src/apps/diskusage/DiskUsage.rdef @@ -3,13 +3,13 @@ resource app_signature "application/x-vnd.Haiku-DiskUsage"; resource app_version { major = 1, middle = 0, - minor = 0, + minor = 2, variety = B_APPV_FINAL, internal = 0, - short_info = "1.0.1", - long_info = "1.0.1 ©1999 Mike Steed, ©2008-2009 Haiku" + short_info = "1.0.2", + long_info = "1.0.2 ©1999 Mike Steed, ©2008-2011 Haiku" }; resource app_flags B_MULTIPLE_LAUNCH; @@ -47,36 +47,3 @@ resource vector_icon { $"18001501178600040A01010B1815FF01178400040A08010C000A09010D000A0A" $"010E00" }; - -resource(101, "RGB_WIN") rgb_color { 0xDE, 0xDB, 0xDE, 0xFF }; -resource(102, "RGB_PIE_OL") rgb_color { 0x80, 0x80, 0x80, 0xFF }; -resource(103, "RGB_PIE_BG") rgb_color { 0xFF, 0xFF, 0xFF, 0xFF }; -resource(104, "RGB_PIE_MT") rgb_color { 0xA0, 0xA0, 0xA0, 0xFF }; -resource(105, "RGB_PIE_1") rgb_color { 0x00, 0x60, 0x60, 0xFF }; -resource(106, "RGB_PIE_2") rgb_color { 0x00, 0x00, 0x68, 0xFF }; -resource(107, "RGB_PIE_3") rgb_color { 0x60, 0x00, 0x60, 0xFF }; -resource(108, "RGB_PIE_4") rgb_color { 0x68, 0x00, 0x00, 0xFF }; - -resource(101, "N_PIE_COLORS") (uint8)4; - -resource(103, "STR_N_FILES") "%d files"; -resource(102, "STR_1_FILE") "%d file"; -resource(101, "STR_VM_LABEL") "Volume:"; -resource(120, "STR_SCAN") "Scan"; -resource(104, "STR_RESCAN") "Rescan"; -resource(105, "STR_SCN_X") "Scanning "; -resource(106, "STR_UNAVAIL") "file unavailable"; -resource(107, "STR_VM_DFLT") "(Select)"; -resource(108, "STR_VPROMPT") "Select a volume to scan"; -resource(109, "STR_M_INFO") "Get Info"; -resource(110, "STR_M_OPEN") "Open"; -resource(111, "STR_M_OPENW") "Open With"; -resource(112, "STR_M_NAPPS") "no supporting apps"; -resource(113, "STR_SIZE") "Size"; -resource(114, "STR_INFILES") " in %d files"; -resource(115, "STR_MADE") "Created"; -resource(116, "STR_MOD") "Modified"; -resource(117, "STR_TIMEFMT") "%a, %d %b %Y, %r"; -resource(118, "STR_KIND") "Kind"; -resource(119, "STR_PATH") "Path"; -resource(121, "STR_OUTDATED") "Outdated view"; diff --git a/src/apps/diskusage/InfoWindow.cpp b/src/apps/diskusage/InfoWindow.cpp index 7a0a80afa3..619c206476 100644 --- a/src/apps/diskusage/InfoWindow.cpp +++ b/src/apps/diskusage/InfoWindow.cpp @@ -16,17 +16,20 @@ #include #include +#include #include #include #include -#include "Common.h" +#include "DiskUsage.h" #include "Snapshot.h" using std::string; using std::vector; using std::pair; +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Info Window" LeftView::LeftView(BRect frame, BBitmap* icon) : @@ -65,44 +68,44 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent) typedef pair Item; typedef vector InfoList; - char name[B_PATH_NAME_LENGTH]; - strcpy(name, f->ref.name); - strcat(name, " info"); - SetTitle(name); + BString stringTitle("%refName% info"); + stringTitle.ReplaceFirst("%refName%", f->ref.name); + SetTitle(stringTitle.String()); InfoList info; Item item; // Size + char name[B_PATH_NAME_LENGTH] = { 0 }; size_to_string(f->size, name); if (f->count > 0) { // This is a directory. char str[64]; - sprintf(str, kInfoInFiles, f->count); + sprintf(str, B_TRANSLATE(" in %d files"), f->count); strcat(name, str); } - info.push_back(Item(kInfoSize, name)); + info.push_back(Item(B_TRANSLATE_MARK("Size"), name)); // Created & modified dates BEntry entry(&f->ref); time_t t; entry.GetCreationTime(&t); - strftime(name, 64, kInfoTimeFmt, localtime(&t)); - info.push_back(Item(kInfoCreated, name)); + strftime(name, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t)); + info.push_back(Item(B_TRANSLATE("Created"), name)); entry.GetModificationTime(&t); - strftime(name, 64, kInfoTimeFmt, localtime(&t)); - info.push_back(Item(kInfoModified, name)); + strftime(name, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t)); + info.push_back(Item(B_TRANSLATE("Modified"), name)); // Kind BMimeType* type = f->Type(); type->GetShortDescription(name); - info.push_back(Item(kInfoKind, name)); + info.push_back(Item(B_TRANSLATE("Kind"), name)); delete type; // Path string path; f->GetPath(path); - info.push_back(Item(kInfoPath, path)); + info.push_back(Item(B_TRANSLATE("Path"), path)); // Icon BBitmap *icon = new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32); @@ -122,18 +125,21 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent) float rightWidth = 0.0; InfoList::iterator i = info.begin(); while (i != info.end()) { - float w = smallFont.StringWidth((*i).first.c_str()) + 2.0 * kSmallHMargin; + float w = smallFont.StringWidth((*i).first.c_str()) + + 2.0 * kSmallHMargin; leftWidth = max_c(leftWidth, w); w = smallFont.StringWidth((*i).second.c_str()) + 2.0 * kSmallHMargin; rightWidth = max_c(rightWidth, w); i++; } - float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight + kSmallVMargin); + float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight + + kSmallVMargin); float winWidth = leftWidth + rightWidth; ResizeTo(winWidth, winHeight); - LeftView *leftView = new LeftView(BRect(0.0, 0.0, leftWidth, winHeight), icon); + LeftView *leftView = new LeftView(BRect(0.0, 0.0, leftWidth, winHeight), + icon); BView *rightView = new BView( BRect(leftWidth + 1.0, 0.0, winWidth, winHeight), NULL, B_FOLLOW_NONE, B_WILL_DRAW); @@ -142,8 +148,8 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent) AddChild(rightView); BStringView *sv = new BStringView( - BRect(kSmallHMargin, kSmallVMargin, rightView->Bounds().Width(), kSmallVMargin + 30.0), - NULL, f->ref.name, B_FOLLOW_ALL); + BRect(kSmallHMargin, kSmallVMargin, rightView->Bounds().Width(), + kSmallVMargin + 30.0), NULL, f->ref.name, B_FOLLOW_ALL); BFont largeFont(be_plain_font); largeFont.SetSize(ceilf(largeFont.Size() * 1.1)); @@ -154,16 +160,16 @@ InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent) i = info.begin(); while (i != info.end()) { sv = new BStringView( - BRect(kSmallHMargin, y, leftView->Bounds().Width(), y + fontHeight), - NULL, (*i).first.c_str()); + BRect(kSmallHMargin, y, leftView->Bounds().Width(), + y + fontHeight), NULL, (*i).first.c_str()); sv->SetFont(&smallFont); sv->SetAlignment(B_ALIGN_RIGHT); sv->SetHighColor(kBasePieColor[1]); // arbitrary leftView->AddChild(sv); sv = new BStringView( - BRect(kSmallHMargin, y, rightView->Bounds().Width(), y + fontHeight), - NULL, (*i).second.c_str()); + BRect(kSmallHMargin, y, rightView->Bounds().Width(), + y + fontHeight), NULL, (*i).second.c_str()); sv->SetFont(&smallFont); rightView->AddChild(sv); diff --git a/src/apps/diskusage/Jamfile b/src/apps/diskusage/Jamfile index edd802ac8d..37d3effac1 100644 --- a/src/apps/diskusage/Jamfile +++ b/src/apps/diskusage/Jamfile @@ -5,7 +5,6 @@ SubDirHdrs $(HAIKU_TOP) src kits tracker ; Application DiskUsage : App.cpp - Common.cpp ControlsView.cpp DiskUsage.cpp InfoWindow.cpp @@ -15,7 +14,18 @@ Application DiskUsage : Snapshot.cpp StatusView.cpp VolumeView.cpp - : be $(TARGET_LIBSTDC++) + : be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++) : DiskUsage.rdef ; +DoCatalogs DiskUsage : + x-vnd.Haiku-DiskUsage + : + MainWindow.cpp + InfoWindow.cpp + PieView.cpp + Scanner.cpp + StatusView.cpp + VolumeView.cpp +; + diff --git a/src/apps/diskusage/MainWindow.cpp b/src/apps/diskusage/MainWindow.cpp index fc439a5e69..2b9f8ec8e7 100644 --- a/src/apps/diskusage/MainWindow.cpp +++ b/src/apps/diskusage/MainWindow.cpp @@ -10,19 +10,22 @@ #include "MainWindow.h" #include +#include #include #include #include #include -#include "Common.h" +#include "DiskUsage.h" #include "ControlsView.h" +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "MainWindow" MainWindow::MainWindow(BRect pieRect) : - BWindow(pieRect, "DiskUsage", B_TITLED_WINDOW, + BWindow(pieRect, B_TRANSLATE("DiskUsage"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS) { @@ -57,7 +60,8 @@ MainWindow::MessageReceived(BMessage* message) break; case kBtnHelp: - be_roster->Launch(&kHelpFileRef); + if (helpFileWasFound) + be_roster->Launch(&helpFileRef); break; default: diff --git a/src/apps/diskusage/PieView.cpp b/src/apps/diskusage/PieView.cpp index a325ca65d0..9052420d65 100644 --- a/src/apps/diskusage/PieView.cpp +++ b/src/apps/diskusage/PieView.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -29,11 +30,13 @@ #include #include "Commands.h" -#include "Common.h" +#include "DiskUsage.h" #include "InfoWindow.h" #include "MainWindow.h" #include "Scanner.h" +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Pie View" static const int32 kIdxGetInfo = 0; static const int32 kIdxOpen = 1; @@ -96,7 +99,8 @@ void AppMenuItem::GetContentSize(float* _width, float* _height) { if (_width) - *_width = fIcon->Bounds().Width() + be_plain_font->StringWidth(Label()); + *_width = fIcon->Bounds().Width() + + be_plain_font->StringWidth(Label()); if (_height) { struct font_height fh; @@ -134,11 +138,13 @@ PieView::PieView(BVolume* volume) fOutdated(false) { fMouseOverMenu = new BPopUpMenu(kEmptyStr, false, false); - fMouseOverMenu->AddItem(new BMenuItem(kMenuGetInfo, NULL), kIdxGetInfo); - fMouseOverMenu->AddItem(new BMenuItem(kMenuOpen, NULL), kIdxOpen); + fMouseOverMenu->AddItem(new BMenuItem(B_TRANSLATE("Get Info"), NULL), + kIdxGetInfo); + fMouseOverMenu->AddItem(new BMenuItem(B_TRANSLATE("Open"), NULL), + kIdxOpen); fFileUnavailableMenu = new BPopUpMenu(kEmptyStr, false, false); - BMenuItem* item = new BMenuItem(kStrUnavail, NULL); + BMenuItem* item = new BMenuItem(B_TRANSLATE("file unavailable"), NULL); item->SetEnabled(false); fFileUnavailableMenu->AddItem(item); @@ -424,14 +430,14 @@ PieView::_DrawPieChart(BRect updateRect) parent = parent->parent; colorIdx++; } - _DrawDirectory(pieRect, currentDir, 0.0, 0.0, colorIdx % kBasePieColorCount, - 0); + _DrawDirectory(pieRect, currentDir, 0.0, 0.0, + colorIdx % kBasePieColorCount, 0); if (fOutdated) { BRect b = Bounds(); - float strWidth = StringWidth(kOutdatedStr); + float strWidth = StringWidth(B_TRANSLATE("Outdated view")); float bx = (b.Width() - strWidth - kSmallHMargin); struct font_height fh; @@ -439,7 +445,7 @@ PieView::_DrawPieChart(BRect updateRect) float by = (b.Height() - ceil(fh.descent) - kSmallVMargin); SetHighColor(0x00, 0x00, 0x00); - DrawString(kOutdatedStr, BPoint(bx, by)); + DrawString(B_TRANSLATE("Outdated view"), BPoint(bx, by)); } } @@ -711,10 +717,11 @@ PieView::_BuildOpenWithMenu(FileInfo* info) delete type; - BMenu* openWith = new BMenu(kMenuOpenWith); + BMenu* openWith = new BMenu(B_TRANSLATE("Open With")); if (appList.size() == 0) { - BMenuItem* item = new BMenuItem(kMenuNoApps, NULL); + BMenuItem* item = new BMenuItem(B_TRANSLATE("no supporting apps"), + NULL); item->SetEnabled(false); openWith->AddItem(item); } else { @@ -749,7 +756,7 @@ PieView::_ShowContextMenu(FileInfo* info, BPoint p) // Add a "Rescan" option for folders. BMenuItem* rescan = NULL; if (info->children.size() > 0) { - rescan = new BMenuItem(kStrRescan, NULL); + rescan = new BMenuItem(B_TRANSLATE("Rescan"), NULL); fMouseOverMenu->AddItem(rescan, kIdxRescan); } diff --git a/src/apps/diskusage/Scanner.cpp b/src/apps/diskusage/Scanner.cpp index 8054a8f30a..c1e15e0520 100644 --- a/src/apps/diskusage/Scanner.cpp +++ b/src/apps/diskusage/Scanner.cpp @@ -13,10 +13,14 @@ #include #include +#include #include #include -#include "Common.h" +#include "DiskUsage.h" + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Scanner" using std::vector; @@ -63,7 +67,8 @@ Scanner::MessageReceived(BMessage* message) case kScanRefresh: { FileInfo* startInfo; - if (message->FindPointer(kNameFilePtr, (void **)&startInfo) == B_OK) + if (message->FindPointer(kNameFilePtr, (void **)&startInfo) + == B_OK) _RunScan(startInfo); break; } @@ -200,10 +205,13 @@ Scanner::_DirectoryContains(FileInfo* currentDir, entry_ref* ref) void Scanner::_RunScan(FileInfo* startInfo) { + BString stringScan(B_TRANSLATE("Scanning %refName%")); + if (startInfo == NULL || startInfo == fSnapshot->rootDir) { delete fSnapshot; fSnapshot = new VolumeSnapshot(fVolume); - fTask = kStrScanningX + fSnapshot->name; + stringScan.ReplaceFirst("%refName%", fSnapshot->name.c_str()); + fTask = stringScan.String(); fVolumeBytesInUse = fSnapshot->capacity - fSnapshot->freeBytes; fVolumeBytesScanned = 0; fProgress = 0.0; @@ -215,8 +223,9 @@ Scanner::_RunScan(FileInfo* startInfo) FileInfo* freeSpace = new FileInfo; freeSpace->pseudo = true; - string s = "Free on " + fSnapshot->name; - freeSpace->ref.set_name(s.c_str()); + BString string(B_TRANSLATE("Free on %refName%")); + string.ReplaceFirst("%refName%", fSnapshot->name.c_str()); + freeSpace->ref.set_name(string.String()); freeSpace->size = fSnapshot->freeBytes; fSnapshot->freeSpace = freeSpace; @@ -225,9 +234,10 @@ Scanner::_RunScan(FileInfo* startInfo) } else { fSnapshot->capacity = fVolume->Capacity(); fSnapshot->freeBytes = fVolume->FreeBytes(); - fTask = kStrScanningX + string(startInfo->ref.name); + stringScan.ReplaceFirst("%refName%", startInfo->ref.name); + fTask = stringScan.String(); fVolumeBytesInUse = fSnapshot->capacity - fSnapshot->freeBytes; - fVolumeBytesScanned = fVolumeBytesInUse - startInfo->size; // best guess + fVolumeBytesScanned = fVolumeBytesInUse - startInfo->size; //best guess fProgress = 100.0 * fVolumeBytesScanned / fVolumeBytesInUse; fLastReport = -100.0; diff --git a/src/apps/diskusage/StatusView.cpp b/src/apps/diskusage/StatusView.cpp index 66669b330b..421bf4bcc7 100644 --- a/src/apps/diskusage/StatusView.cpp +++ b/src/apps/diskusage/StatusView.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -22,9 +23,11 @@ #include -#include "Common.h" +#include "DiskUsage.h" #include "Scanner.h" +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Status View" StatusView::StatusView() : @@ -35,13 +38,13 @@ StatusView::StatusView() SetLowColor(kPieBGColor); fSizeView = new BStringView(NULL, kEmptyStr); - fSizeView->SetExplicitMinSize(BSize(StringWidth("9999.99 GB"), + fSizeView->SetExplicitMinSize(BSize(StringWidth(B_TRANSLATE("9999.99 GB")), B_SIZE_UNSET)); - fSizeView->SetExplicitMaxSize(BSize(StringWidth("9999.99 GB"), + fSizeView->SetExplicitMaxSize(BSize(StringWidth(B_TRANSLATE("9999.99 GB")), B_SIZE_UNSET)); char testLabel[256]; - sprintf(testLabel, kManyFiles, 999999); + sprintf(testLabel, B_TRANSLATE("%d files"), 999999); fCountView = new BStringView(NULL, kEmptyStr); fCountView->SetExplicitMinSize(BSize(StringWidth(testLabel), B_SIZE_UNSET)); @@ -50,7 +53,7 @@ StatusView::StatusView() fPathView = new BStringView(NULL, kEmptyStr); fPathView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); - fRefreshBtn = new BButton(NULL, kStrScan, new BMessage(kBtnRescan)); + fRefreshBtn = new BButton(NULL, B_TRANSLATE("Scan"), new BMessage(kBtnRescan)); fRefreshBtn->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)); @@ -119,7 +122,7 @@ StatusView::ShowInfo(const FileInfo* info) if (!info->pseudo) { BNode node(&info->ref); if (node.InitCheck() != B_OK) { - fPathView->SetText(kStrUnavail); + fPathView->SetText(B_TRANSLATE("file unavailable")); fSizeView->SetText(kEmptyStr); fCountView->SetText(kEmptyStr); return; @@ -139,7 +142,8 @@ StatusView::ShowInfo(const FileInfo* info) if (info->count > 0) { char label[256]; - sprintf(label, (info->count == 1) ? kOneFile : kManyFiles, info->count); + sprintf(label, (info->count == 1) ? B_TRANSLATE("%d file") : + B_TRANSLATE("%d files"), info->count); fCountView->SetText(label); } else { fCountView->SetText(kEmptyStr); diff --git a/src/apps/diskusage/VolumeView.cpp b/src/apps/diskusage/VolumeView.cpp index 7b56282235..eb504b1e78 100644 --- a/src/apps/diskusage/VolumeView.cpp +++ b/src/apps/diskusage/VolumeView.cpp @@ -8,6 +8,7 @@ */ +#include #include #include #include @@ -16,13 +17,16 @@ #include -#include "Common.h" +#include "DiskUsage.h" #include "MainWindow.h" #include "PieView.h" #include "StatusView.h" #include "VolumeView.h" +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Volume View" + const float kMinWinSize = 275.0; VolumeView::VolumeView(const char* name, BVolume* volume) @@ -58,7 +62,7 @@ void VolumeView::SetPath(BPath path) { fPieView->SetPath(path); - fStatusView->SetBtnLabel(kStrRescan); + fStatusView->SetBtnLabel(B_TRANSLATE("Rescan")); } @@ -69,7 +73,7 @@ VolumeView::MessageReceived(BMessage* msg) switch(msg->what) { case kBtnRescan: fPieView->MessageReceived(msg); - fStatusView->SetBtnLabel(kStrRescan); + fStatusView->SetBtnLabel(B_TRANSLATE("Rescan")); break; default: