Patch by Jorma Karvonen: Localization of the PackageInstaller. Thanks a lot!

Contains small coding style corrections by myself. Closes ticket #5907.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36618 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2010-05-05 08:00:57 +00:00
parent da0e57ba62
commit 091440e004
11 changed files with 266 additions and 190 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ Application PackageInstaller :
PackageTextViewer.cpp PackageTextViewer.cpp
PackageImageViewer.cpp PackageImageViewer.cpp
InstalledPackageInfo.cpp InstalledPackageInfo.cpp
: be tracker translation z $(TARGET_LIBSUPC++) : be locale tracker translation z $(TARGET_LIBSUPC++)
: PackageInstaller.rdef : PackageInstaller.rdef
; ;
@@ -10,23 +10,24 @@
#include "PackageImageViewer.h" #include "PackageImageViewer.h"
#include <BitmapStream.h> #include <BitmapStream.h>
#include <Catalog.h>
#include <Locale.h>
#include <Message.h> #include <Message.h>
#include <Screen.h> #include <Screen.h>
#include <TranslatorRoster.h> #include <TranslatorRoster.h>
// Reserved #undef TR_CONTEXT
#define T(x) x #define TR_CONTEXT "PackageImageViewer"
enum { enum {
P_MSG_CLOSE = 'pmic' P_MSG_CLOSE = 'pmic'
}; };
ImageView::ImageView(BPositionIO *image) ImageView::ImageView(BPositionIO *image)
: BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW), :
BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW),
fSuccess(true) fSuccess(true)
{ {
if (!image) { if (!image) {
@@ -64,12 +65,10 @@ ImageView::AttachedToWindow()
BRect frame = screen.Frame(); BRect frame = screen.Frame();
BRect image = fImage->Bounds(); BRect image = fImage->Bounds();
if (image.Width() > (frame.Width() - 100.0f)) { if (image.Width() > (frame.Width() - 100.0f))
image.right = frame.Width() - 100.0f; image.right = frame.Width() - 100.0f;
} if (image.Height() > (frame.Height() - 100.0f))
if (image.Height() > (frame.Height() - 100.0f)) {
image.bottom = frame.Height() - 100.f; image.bottom = frame.Height() - 100.f;
}
ResizeTo(image.Width(), image.Height()); ResizeTo(image.Width(), image.Height());
} }
@@ -81,8 +80,8 @@ ImageView::Draw(BRect updateRect)
if (fSuccess) if (fSuccess)
DrawBitmapAsync(fImage, Bounds()); DrawBitmapAsync(fImage, Bounds());
else { else {
float length = StringWidth(T("Image not loaded correctly")); float length = StringWidth(TR("Image not loaded correctly"));
DrawString(T("Image not loaded correctly"), DrawString(TR("Image not loaded correctly"),
BPoint((Bounds().Width() - length) / 2.0f, 30.0f)); BPoint((Bounds().Width() - length) / 2.0f, 30.0f));
} }
} }
@@ -101,8 +100,9 @@ ImageView::MouseUp(BPoint point)
PackageImageViewer::PackageImageViewer(BPositionIO *image) PackageImageViewer::PackageImageViewer(BPositionIO *image)
: BWindow(BRect(100, 100, 100, 100), "", B_MODAL_WINDOW, :
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE) BWindow(BRect(100, 100, 100, 100), "", B_MODAL_WINDOW,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE)
{ {
fBackground = new ImageView(image); fBackground = new ImageView(image);
AddChild(fBackground); AddChild(fBackground);
@@ -168,8 +168,7 @@ PackageImageViewer::MessageReceived(BMessage *msg)
delete_sem(fSemaphore); delete_sem(fSemaphore);
fSemaphore = -1; fSemaphore = -1;
} }
} } else
else
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
} }
+12 -11
View File
@@ -1,23 +1,24 @@
/* /*
* Copyright (c) 2007-2009, Haiku, Inc. * Copyright (c) 2007-2010, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Author: * Author:
* Łukasz 'Sil2100' Zemczak <[email protected]> * Łukasz 'Sil2100' Zemczak <[email protected]>
*/ */
#include "PackageInfo.h" #include "PackageInfo.h"
#include <Alert.h> #include <Alert.h>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <Catalog.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Locale.h>
#include <Path.h> #include <Path.h>
#include <kernel/OS.h> #include <kernel/OS.h>
// Macro reserved for later localization #undef TR_CONTEXT
#define T(x) x #define TR_CONTEXT "PackageInfo"
#define RETURN_AND_SET_STATUS(err) fStatus = err; \ #define RETURN_AND_SET_STATUS(err) fStatus = err; \
fprintf(stderr, "err at %s():%d: %x\n", __FUNCTION__, __LINE__, err); \ fprintf(stderr, "err at %s():%d: %x\n", __FUNCTION__, __LINE__, err); \
@@ -48,7 +49,7 @@ PackageInfo::PackageInfo()
: :
fStatus(B_NO_INIT), fStatus(B_NO_INIT),
fPackageFile(0), fPackageFile(0),
fDescription(T("No package available.")), fDescription(TR("No package available.")),
fProfiles(2), fProfiles(2),
fHasImage(false) fHasImage(false)
{ {
@@ -59,7 +60,7 @@ PackageInfo::PackageInfo(const entry_ref *ref)
: :
fStatus(B_NO_INIT), fStatus(B_NO_INIT),
fPackageFile(new BFile(ref, B_READ_ONLY)), fPackageFile(new BFile(ref, B_READ_ONLY)),
fDescription(T("No package selected.")), fDescription(TR("No package selected.")),
fProfiles(2), fProfiles(2),
fHasImage(false) fHasImage(false)
{ {
@@ -1027,7 +1028,7 @@ PackageInfo::Parse()
parser_debug("PtcI\n"); parser_debug("PtcI\n");
break; break;
} else { } else {
fprintf(stderr, "Unknown file tag %s\n", buffer); fprintf(stderr, TR("Unknown file tag %s\n"), buffer);
RETURN_AND_SET_STATUS(B_ERROR); RETURN_AND_SET_STATUS(B_ERROR);
} }
} }
@@ -1035,11 +1036,11 @@ PackageInfo::Parse()
if (static_cast<uint64>(actualSize) != fileSize) { if (static_cast<uint64>(actualSize) != fileSize) {
// Inform the user of a possible error // Inform the user of a possible error
int32 selection; int32 selection;
BAlert *warning = new BAlert(T("filesize_wrong"), BAlert *warning = new BAlert("filesize_wrong",
T("There seems to be a file size mismatch in the package file. " TR("There seems to be a file size mismatch in the package file. "
"The package might be corrupted or have been modified after its " "The package might be corrupted or have been modified after its "
"creation. Do you still wish to continue?"), T("Continue"), "creation. Do you still wish to continue?"), TR("Continue"),
T("Abort"), NULL, TR("Abort"), NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_WARNING_ALERT);
selection = warning->Go(); selection = warning->Go();
+25 -20
View File
@@ -6,7 +6,6 @@
* Łukasz 'Sil2100' Zemczak <[email protected]> * Łukasz 'Sil2100' Zemczak <[email protected]>
*/ */
#include "PackageInstall.h" #include "PackageInstall.h"
#include "InstalledPackageInfo.h" #include "InstalledPackageInfo.h"
@@ -14,13 +13,17 @@
#include "PackageView.h" #include "PackageView.h"
#include <Alert.h> #include <Alert.h>
#include <Catalog.h>
#include <Locale.h>
#include <stdio.h> #include <stdio.h>
// Macro reserved for later localization #undef TR_CONTEXT
#define T(x) x #define TR_CONTEXT "PackageInstall"
static int32 install_function(void *data)
static int32
install_function(void *data)
{ {
// TODO: Inform if already one thread is running // TODO: Inform if already one thread is running
PackageInstall *install = static_cast<PackageInstall *>(data); PackageInstall *install = static_cast<PackageInstall *>(data);
@@ -100,13 +103,14 @@ uint32
PackageInstall::_Install() PackageInstall::_Install()
{ {
PackageInfo *info = fParent->GetPackageInfo(); PackageInfo *info = fParent->GetPackageInfo();
pkg_profile *type = static_cast<pkg_profile *>(info->GetProfile(fParent->GetCurrentType())); pkg_profile *type = static_cast<pkg_profile *>(info->GetProfile(
fParent->GetCurrentType()));
uint32 n = type->items.CountItems(), m = info->GetScriptCount(); uint32 n = type->items.CountItems(), m = info->GetScriptCount();
PackageStatus *progress = fParent->GetStatusWindow(); PackageStatus *progress = fParent->GetStatusWindow();
progress->Reset(n + m + 5); progress->Reset(n + m + 5);
progress->StageStep(1, T("Preparing package")); progress->StageStep(1, TR("Preparing package"));
InstalledPackageInfo packageInfo(info->GetName(), info->GetVersion()); InstalledPackageInfo packageInfo(info->GetName(), info->GetVersion());
@@ -114,21 +118,21 @@ PackageInstall::_Install()
if (err == B_OK) { if (err == B_OK) {
// The package is already installed, inform the user // The package is already installed, inform the user
BAlert *reinstall = new BAlert("reinstall", BAlert *reinstall = new BAlert("reinstall",
T("The given package seems to be already installed on your system. " TR("The given package seems to be already installed on your "
"Would you like to uninstall the existing one and continue the " "system. Would you like to uninstall the existing one and "
"installation?"), T("Continue"), T("Abort")); "continue the installation?"), TR("Continue"), TR("Abort"));
if (reinstall->Go() == 0) { if (reinstall->Go() == 0) {
// Uninstall the package // Uninstall the package
err = packageInfo.Uninstall(); err = packageInfo.Uninstall();
if (err != B_OK) { if (err != B_OK) {
fprintf(stderr, "Error on uninstall\n"); fprintf(stderr, TR("Error on uninstall\n"));
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
} }
err = packageInfo.SetTo(info->GetName(), info->GetVersion(), true); err = packageInfo.SetTo(info->GetName(), info->GetVersion(), true);
if (err != B_OK) { if (err != B_OK) {
fprintf(stderr, "Error on SetTo\n"); fprintf(stderr, TR("Error on SetTo\n"));
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
} }
} else { } else {
@@ -138,17 +142,17 @@ PackageInstall::_Install()
} else if (err == B_ENTRY_NOT_FOUND) { } else if (err == B_ENTRY_NOT_FOUND) {
err = packageInfo.SetTo(info->GetName(), info->GetVersion(), true); err = packageInfo.SetTo(info->GetName(), info->GetVersion(), true);
if (err != B_OK) { if (err != B_OK) {
fprintf(stderr, "Error on SetTo\n"); fprintf(stderr, TR("Error on SetTo\n"));
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
} }
} else if (progress->Stopped()) { } else if (progress->Stopped()) {
return P_MSG_I_ABORT; return P_MSG_I_ABORT;
} else { } else {
fprintf(stderr, "returning on error\n"); fprintf(stderr, TR("returning on error\n"));
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
} }
progress->StageStep(1, T("Installing files and folders")); progress->StageStep(1, TR("Installing files and folders"));
// Install files and directories // Install files and directories
PackageItem *iter; PackageItem *iter;
@@ -181,7 +185,8 @@ PackageInstall::_Install()
if (err == B_FILE_EXISTS) { if (err == B_FILE_EXISTS) {
// Writing to path failed because path already exists - ask the user // Writing to path failed because path already exists - ask the user
// what to do and retry the writing process // what to do and retry the writing process
choice = fParent->ItemExists(*iter, state.destination, fItemExistsPolicy); choice = fParent->ItemExists(*iter, state.destination,
fItemExistsPolicy);
if (choice != P_EXISTS_ABORT) { if (choice != P_EXISTS_ABORT) {
state.policy = choice; state.policy = choice;
err = iter->DoInstall(installPath, &state); err = iter->DoInstall(installPath, &state);
@@ -189,7 +194,7 @@ PackageInstall::_Install()
} }
if (err != B_OK) { if (err != B_OK) {
fprintf(stderr, "Error while writing path\n"); fprintf(stderr, TR("Error while writing path\n"));
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
} }
@@ -202,7 +207,7 @@ PackageInstall::_Install()
packageInfo.AddItem(state.destination.Path()); packageInfo.AddItem(state.destination.Path());
} }
progress->StageStep(1, T("Running post-installation scripts"), ""); progress->StageStep(1, TR("Running post-installation scripts"), "");
PackageScript *scr; PackageScript *scr;
status_t status; status_t status;
@@ -214,7 +219,7 @@ PackageInstall::_Install()
fCurrentScript = scr; fCurrentScript = scr;
if (scr->DoInstall() != B_OK) { if (scr->DoInstall() != B_OK) {
fprintf(stderr, "Error while running script\n"); fprintf(stderr, TR("Error while running script\n"));
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
} }
fCurrentScriptLocker.Unlock(); fCurrentScriptLocker.Unlock();
@@ -232,13 +237,13 @@ PackageInstall::_Install()
progress->StageStep(1, NULL, label.String()); progress->StageStep(1, NULL, label.String());
} }
progress->StageStep(1, T("Finishing installation"), ""); progress->StageStep(1, TR("Finishing installation"), "");
err = packageInfo.Save(); err = packageInfo.Save();
if (err != B_OK) if (err != B_OK)
return P_MSG_I_ERROR; return P_MSG_I_ERROR;
progress->StageStep(1, T("Done")); progress->StageStep(1, TR("Done"));
// Inform our parent that we finished // Inform our parent that we finished
return P_MSG_I_FINISHED; return P_MSG_I_FINISHED;
+13 -11
View File
@@ -6,15 +6,16 @@
* Łukasz 'Sil2100' Zemczak <[email protected]> * Łukasz 'Sil2100' Zemczak <[email protected]>
*/ */
#include "PackageItem.h" #include "PackageItem.h"
#include <string.h> #include <string.h>
#include <Alert.h> #include <Alert.h>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <Catalog.h>
#include <Directory.h> #include <Directory.h>
#include <fs_info.h> #include <fs_info.h>
#include <Locale.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <OS.h> #include <OS.h>
#include <SymLink.h> #include <SymLink.h>
@@ -23,8 +24,8 @@
#include "zlib.h" #include "zlib.h"
// Macro reserved for later localization #undef TR_CONTEXT
#define T(x) x #define TR_CONTEXT "PackageItem"
enum { enum {
P_CHUNK_SIZE = 256 P_CHUNK_SIZE = 256
@@ -561,10 +562,10 @@ PackageScript::DoInstall(const char *path, ItemState *state)
} }
const char* const uint32
PackageScript::ItemKind() PackageScript::ItemKind()
{ {
return "script"; return P_KIND_SCRIPT;
} }
@@ -737,10 +738,10 @@ PackageDirectory::DoInstall(const char *path, ItemState *state)
} }
const char* const uint32
PackageDirectory::ItemKind() PackageDirectory::ItemKind()
{ {
return "directory"; return P_KIND_DIRECTORY;
} }
@@ -903,10 +904,10 @@ PackageFile::DoInstall(const char *path, ItemState *state)
} }
const char* const uint32
PackageFile::ItemKind() PackageFile::ItemKind()
{ {
return "file"; return P_KIND_FILE;
} }
@@ -1038,8 +1039,9 @@ PackageLink::DoInstall(const char *path, ItemState *state)
} }
const char* const uint32
PackageLink::ItemKind() PackageLink::ItemKind()
{ {
return "symbolic link"; return P_KIND_SYM_LINK;
} }
+11 -5
View File
@@ -42,6 +42,12 @@ enum {
P_EXISTS_NONE P_EXISTS_NONE
}; };
const uint32 P_NO_KIND = 0;
const uint32 P_KIND_SCRIPT = 1;
const uint32 P_KIND_FILE = 2;
const uint32 P_KIND_DIRECTORY = 3;
const uint32 P_KIND_SYM_LINK = 4;
extern status_t inflate_data(uint8* in, uint32 inSize, uint8* out, extern status_t inflate_data(uint8* in, uint32 inSize, uint8* out,
uint32 outSize); uint32 outSize);
@@ -77,7 +83,7 @@ public:
virtual void SetTo(BFile* parent, const BString& path, virtual void SetTo(BFile* parent, const BString& path,
uint8 type, uint32 ctime, uint32 mtime, uint8 type, uint32 ctime, uint32 mtime,
uint64 offset = 0, uint64 size = 0); uint64 offset = 0, uint64 size = 0);
virtual const char* ItemKind() = 0; virtual const uint32 ItemKind() {return P_NO_KIND;};
protected: protected:
status_t InitPath(const char* path, BPath* destination); status_t InitPath(const char* path, BPath* destination);
@@ -115,7 +121,7 @@ public:
virtual status_t DoInstall(const char* path = NULL, virtual status_t DoInstall(const char* path = NULL,
ItemState *state = NULL); ItemState *state = NULL);
virtual const char* ItemKind(); virtual const uint32 ItemKind();
}; };
@@ -126,7 +132,7 @@ public:
virtual status_t DoInstall(const char* path = NULL, virtual status_t DoInstall(const char* path = NULL,
ItemState *state = NULL); ItemState *state = NULL);
virtual const char* ItemKind(); virtual const uint32 ItemKind();
thread_id GetThreadId() { return fThreadId; } thread_id GetThreadId() { return fThreadId; }
void SetThreadId(thread_id id) { fThreadId = id; } void SetThreadId(thread_id id) { fThreadId = id; }
@@ -151,7 +157,7 @@ public:
virtual status_t DoInstall(const char* path = NULL, virtual status_t DoInstall(const char* path = NULL,
ItemState *state = NULL); ItemState *state = NULL);
virtual const char* ItemKind(); virtual const uint32 ItemKind();
private: private:
uint64 fOriginalSize; uint64 fOriginalSize;
@@ -172,7 +178,7 @@ public:
virtual status_t DoInstall(const char* path = NULL, virtual status_t DoInstall(const char* path = NULL,
ItemState *state = NULL); ItemState *state = NULL);
virtual const char* ItemKind(); virtual const uint32 ItemKind();
private: private:
uint32 fMode; uint32 fMode;
+12 -10
View File
@@ -6,23 +6,23 @@
* Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
*/ */
#include "PackageStatus.h" #include "PackageStatus.h"
#include <Autolock.h> #include <Autolock.h>
#include <Catalog.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <Locale.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
// Macro reserved for later localization #undef TR_CONTEXT
#define T(x) x #define TR_CONTEXT "PackageStatus"
StopButton::StopButton() StopButton::StopButton()
: BButton(BRect(0, 0, 22, 18), "stop", "", new BMessage(P_MSG_STOP)) :
BButton(BRect(0, 0, 22, 18), "stop", TR("Stop"), new BMessage(P_MSG_STOP))
{ {
} }
@@ -33,7 +33,8 @@ StopButton::Draw(BRect updateRect)
BButton::Draw(updateRect); BButton::Draw(updateRect);
updateRect = Bounds(); updateRect = Bounds();
updateRect.InsetBy((updateRect.Width() - 4) / 2, (updateRect.Height() - 4) / 2); updateRect.InsetBy((updateRect.Width() - 4) / 2,
(updateRect.Height() - 4) / 2);
//updateRect.InsetBy(9, 7); //updateRect.InsetBy(9, 7);
SetHighColor(0, 0, 0); SetHighColor(0, 0, 0);
FillRect(updateRect); FillRect(updateRect);
@@ -93,14 +94,15 @@ StopButton::Draw(BRect updateRect)
PackageStatus::PackageStatus(const char *title, const char *label, PackageStatus::PackageStatus(const char *title, const char *label,
const char *trailing, BHandler *parent) const char *trailing, BHandler *parent)
: BWindow(BRect(200, 200, 550, 255), title, B_TITLED_WINDOW, :
B_NOT_CLOSABLE | B_NOT_RESIZABLE | B_NOT_ZOOMABLE, 0), BWindow(BRect(200, 200, 550, 255), title, B_TITLED_WINDOW,
B_NOT_CLOSABLE | B_NOT_RESIZABLE | B_NOT_ZOOMABLE, 0),
fIsStopped(false), fIsStopped(false),
fParent(parent) fParent(parent)
{ {
SetLayout(new BGroupLayout(B_VERTICAL)); SetLayout(new BGroupLayout(B_VERTICAL));
fStatus = new BStatusBar("status_bar", T("Installing package")); fStatus = new BStatusBar("status_bar", TR("Installing package"));
fStatus->SetBarHeight(12); fStatus->SetBarHeight(12);
fButton = new StopButton(); fButton = new StopButton();
+22 -23
View File
@@ -1,15 +1,16 @@
/* /*
* Copyright (c) 2007, Haiku, Inc. * Copyright (c) 2007-2010, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Author: * Author:
* Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
*/ */
#include "PackageTextViewer.h" #include "PackageTextViewer.h"
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <Locale.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <GroupLayout.h> #include <GroupLayout.h>
@@ -21,14 +22,15 @@ enum {
P_MSG_DECLINE P_MSG_DECLINE
}; };
// Reserved #undef TR_CONTEXT
#define T(x) x #define TR_CONTEXT "PackageTextViewer"
PackageTextViewer::PackageTextViewer(const char *text, bool disclaimer) PackageTextViewer::PackageTextViewer(const char *text, bool disclaimer)
: BWindow(BRect(125, 125, 675, 475), T("Disclaimer"), B_MODAL_WINDOW, :
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE), BWindow(BRect(125, 125, 675, 475), TR("Disclaimer"), B_MODAL_WINDOW,
fValue(0) B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE),
fValue(0)
{ {
_InitView(text, disclaimer); _InitView(text, disclaimer);
} }
@@ -90,15 +92,13 @@ PackageTextViewer::MessageReceived(BMessage *msg)
delete_sem(fSemaphore); delete_sem(fSemaphore);
fSemaphore = -1; fSemaphore = -1;
} }
} } else if (msg->what == P_MSG_DECLINE) {
else if (msg->what == P_MSG_DECLINE) {
if (fSemaphore >= B_OK) { if (fSemaphore >= B_OK) {
fValue = 0; fValue = 0;
delete_sem(fSemaphore); delete_sem(fSemaphore);
fSemaphore = -1; fSemaphore = -1;
} }
} } else
else
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
} }
@@ -115,8 +115,8 @@ PackageTextViewer::_InitView(const char *text, bool disclaimer)
BRect bounds; BRect bounds;
BRect rect = Bounds(); BRect rect = Bounds();
if (disclaimer) { if (disclaimer) {
BButton *button = new BButton(BRect(0, 0, 1, 1), "accept", T("Accept"), BButton *button = new BButton(BRect(0, 0, 1, 1), "accept",
new BMessage(P_MSG_ACCEPT)); TR("Accept"), new BMessage(P_MSG_ACCEPT));
button->ResizeToPreferred(); button->ResizeToPreferred();
bounds = button->Bounds(); bounds = button->Bounds();
@@ -128,7 +128,7 @@ PackageTextViewer::_InitView(const char *text, bool disclaimer)
button->MakeDefault(true); button->MakeDefault(true);
fBackground->AddChild(button); fBackground->AddChild(button);
button = new BButton(BRect(0, 0, 1, 1), "decline", T("Decline"), button = new BButton(BRect(0, 0, 1, 1), "decline", TR("Decline"),
new BMessage(P_MSG_DECLINE)); new BMessage(P_MSG_DECLINE));
button->ResizeToPreferred(); button->ResizeToPreferred();
@@ -136,10 +136,9 @@ PackageTextViewer::_InitView(const char *text, bool disclaimer)
rect.left -= bounds.right + 7.0f; rect.left -= bounds.right + 7.0f;
button->MoveTo(rect.LeftTop()); button->MoveTo(rect.LeftTop());
fBackground->AddChild(button); fBackground->AddChild(button);
} } else {
else { BButton *button = new BButton(BRect(0, 0, 1, 1), "accept",
BButton *button = new BButton(BRect(0, 0, 1, 1), "accept", T("Continue"), TR("Continue"), new BMessage(P_MSG_ACCEPT));
new BMessage(P_MSG_ACCEPT));
button->ResizeToPreferred(); button->ResizeToPreferred();
bounds = button->Bounds(); bounds = button->Bounds();
@@ -157,13 +156,13 @@ PackageTextViewer::_InitView(const char *text, bool disclaimer)
bounds.right -= B_V_SCROLL_BAR_WIDTH; bounds.right -= B_V_SCROLL_BAR_WIDTH;
fText = new BTextView(bounds, "text_view", BRect(0, 0, bounds.Width(), fText = new BTextView(bounds, "text_view", BRect(0, 0, bounds.Width(),
bounds.Height()), B_FOLLOW_NONE, B_WILL_DRAW); bounds.Height()), B_FOLLOW_NONE, B_WILL_DRAW);
fText->MakeEditable(false); fText->MakeEditable(false);
fText->MakeSelectable(true); fText->MakeSelectable(true);
fText->SetText(text); fText->SetText(text);
BScrollView *scroll = new BScrollView("scroll_view", fText, BScrollView *scroll = new BScrollView("scroll_view", fText,
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true); B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true);
fBackground->AddChild(scroll); fBackground->AddChild(scroll);
@@ -184,10 +183,10 @@ PackageTextViewer::_InitView(const char *text, bool disclaimer)
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true); B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true);
if (disclaimer) { if (disclaimer) {
BButton *accept = new BButton("accept", T("Accept"), BButton *accept = new BButton("accept", TR("Accept"),
new BMessage(P_MSG_ACCEPT)); new BMessage(P_MSG_ACCEPT));
BButton *decline = new BButton("decline", T("Decline"), BButton *decline = new BButton("decline", TR("Decline"),
new BMessage(P_MSG_DECLINE)); new BMessage(P_MSG_DECLINE));
fBackground = BGroupLayoutBuilder(B_VERTICAL) fBackground = BGroupLayoutBuilder(B_VERTICAL)
@@ -199,7 +198,7 @@ PackageTextViewer::_InitView(const char *text, bool disclaimer)
.End(); .End();
} }
else { else {
BButton *button = new BButton("accept", T("Continue"), BButton *button = new BButton("accept", TR("Continue"),
new BMessage(P_MSG_ACCEPT)); new BMessage(P_MSG_ACCEPT));
fBackground = BGroupLayoutBuilder(B_VERTICAL) fBackground = BGroupLayoutBuilder(B_VERTICAL)
+127 -76
View File
@@ -1,12 +1,11 @@
/* /*
* Copyright 2007-2009, Haiku, Inc. * Copyright 2007-2010, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Author: * Author:
* Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
*/ */
#include "InstalledPackageInfo.h" #include "InstalledPackageInfo.h"
#include "PackageImageViewer.h" #include "PackageImageViewer.h"
#include "PackageTextViewer.h" #include "PackageTextViewer.h"
@@ -14,8 +13,10 @@
#include <Alert.h> #include <Alert.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <Directory.h> #include <Directory.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Path.h> #include <Path.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
@@ -32,25 +33,27 @@
#include <fs_info.h> #include <fs_info.h>
#include <stdio.h> // For debugging #include <stdio.h> // For debugging
// Macro reserved for later localization
#define T(x) x #undef TR_CONTEXT
#define TR_CONTEXT "PackageView"
const float kMaxDescHeight = 125.0f; const float kMaxDescHeight = 125.0f;
const uint32 kSeparatorIndex = 3; const uint32 kSeparatorIndex = 3;
static void static void
convert_size(uint64 size, char *buffer, uint32 n) convert_size(uint64 size, char *buffer, uint32 n)
{ {
if (size < 1024) if (size < 1024)
snprintf(buffer, n, "%llu bytes", size); snprintf(buffer, n, TR("%llu bytes"), size);
else if (size < 1024 * 1024) else if (size < 1024 * 1024)
snprintf(buffer, n, "%.1f KiB", size / 1024.0f); snprintf(buffer, n, TR("%.1f KiB"), size / 1024.0f);
else if (size < 1024 * 1024 * 1024) else if (size < 1024 * 1024 * 1024)
snprintf(buffer, n, "%.1f MiB", size / (1024.0f*1024.0f)); snprintf(buffer, n, TR("%.1f MiB"), size / (1024.0f * 1024.0f));
else else {
snprintf(buffer, n, "%.1f GiB", size / (1024.0f*1024.0f*1024.0f)); snprintf(buffer, n, TR("%.1f GiB"), size
/ (1024.0f * 1024.0f * 1024.0f));
}
} }
@@ -59,10 +62,10 @@ convert_size(uint64 size, char *buffer, uint32 n)
PackageView::PackageView(BRect frame, const entry_ref *ref) PackageView::PackageView(BRect frame, const entry_ref *ref)
: BView(frame, "package_view", B_FOLLOW_NONE, 0), :
//BView("package_view", B_WILL_DRAW, new BGroupLayout(B_HORIZONTAL)), BView(frame, "package_view", B_FOLLOW_NONE, 0),
fOpenPanel(new BFilePanel(B_OPEN_PANEL, NULL, NULL, fOpenPanel(new BFilePanel(B_OPEN_PANEL, NULL, NULL, B_DIRECTORY_NODE,
B_DIRECTORY_NODE, false)), false)),
fInfo(ref), fInfo(ref),
fInstallProcess(this) fInstallProcess(this)
{ {
@@ -88,11 +91,11 @@ PackageView::AttachedToWindow()
{ {
status_t ret = fInfo.InitCheck(); status_t ret = fInfo.InitCheck();
if (ret != B_OK && ret != B_NO_INIT) { if (ret != B_OK && ret != B_NO_INIT) {
BAlert *warning = new BAlert(T("parsing_failed"), BAlert *warning = new BAlert("parsing_failed",
T("The package file is not readable.\nOne of the possible " TR("The package file is not readable.\nOne of the possible "
"reasons for this might be that the requested file is not a valid " "reasons for this might be that the requested file is not a "
"BeOS .pkg package."), T("OK"), NULL, NULL, B_WIDTH_AS_USUAL, "valid BeOS .pkg package."), TR("OK"), NULL, NULL,
B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_WARNING_ALERT);
warning->Go(); warning->Go();
Window()->PostMessage(B_QUIT_REQUESTED); Window()->PostMessage(B_QUIT_REQUESTED);
@@ -104,10 +107,10 @@ PackageView::AttachedToWindow()
BString title; BString title;
BString name = fInfo.GetName(); BString name = fInfo.GetName();
if (name.CountChars() == 0) { if (name.CountChars() == 0) {
title = T("Package installer"); title = TR("Package installer");
} }
else { else {
title = T("Install "); title = TR("Install ");
title += name; title += name;
} }
parent->SetTitle(title.String()); parent->SetTitle(title.String());
@@ -122,8 +125,8 @@ PackageView::AttachedToWindow()
// attaching the view to the window // attaching the view to the window
_GroupChanged(0); _GroupChanged(0);
fStatusWindow = new PackageStatus(T("Installation progress"), NULL, NULL, fStatusWindow = new PackageStatus(TR("Installation progress"), NULL,
this); NULL, this);
// Show the splash screen, if present // Show the splash screen, if present
BMallocIO *image = fInfo.GetSplashScreen(); BMallocIO *image = fInfo.GetSplashScreen();
@@ -135,9 +138,11 @@ PackageView::AttachedToWindow()
// Show the disclaimer/info text popup, if present // Show the disclaimer/info text popup, if present
BString disclaimer = fInfo.GetDisclaimer(); BString disclaimer = fInfo.GetDisclaimer();
if (disclaimer.Length() != 0) { if (disclaimer.Length() != 0) {
PackageTextViewer *text = new PackageTextViewer(disclaimer.String()); PackageTextViewer *text = new PackageTextViewer(
disclaimer.String());
int32 selection = text->Go(); int32 selection = text->Go();
// The user didn't accept our disclaimer, this means we cannot continue. // The user didn't accept our disclaimer, this means we cannot
// continue.
if (selection == 0) { if (selection == 0) {
BWindow *parent = Window(); BWindow *parent = Window();
if (parent && parent->Lock()) if (parent && parent->Lock())
@@ -184,8 +189,8 @@ PackageView::MessageReceived(BMessage *msg)
case P_MSG_I_FINISHED: case P_MSG_I_FINISHED:
{ {
BAlert *notify = new BAlert("installation_success", BAlert *notify = new BAlert("installation_success",
T("The package you requested has been successfully installed " TR("The package you requested has been successfully installed "
"on your system."), T("OK")); "on your system."), TR("OK"));
notify->Go(); notify->Go();
fStatusWindow->Hide(); fStatusWindow->Hide();
@@ -202,7 +207,8 @@ PackageView::MessageReceived(BMessage *msg)
case P_MSG_I_ABORT: case P_MSG_I_ABORT:
{ {
BAlert *notify = new BAlert("installation_aborted", BAlert *notify = new BAlert("installation_aborted",
T("The installation of the package has been aborted."), T("OK")); TR("The installation of the package has been aborted."),
TR("OK"));
notify->Go(); notify->Go();
fStatusWindow->Hide(); fStatusWindow->Hide();
fInstall->SetEnabled(true); fInstall->SetEnabled(true);
@@ -213,12 +219,13 @@ PackageView::MessageReceived(BMessage *msg)
} }
case P_MSG_I_ERROR: case P_MSG_I_ERROR:
{ {
BAlert *notify = new BAlert("installation_failed", // TODO: Review this // TODO: Review this
T("The requested package failed to install on your system. This " BAlert *notify = new BAlert("installation_failed",
"might be a problem with the target package file. Please consult " TR("The requested package failed to install on your system. "
"this issue with the package distributor."), T("OK"), NULL, "This might be a problem with the target package file. Please "
NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); "consult this issue with the package distributor."),
fprintf(stderr, "Error while installing the package\n"); TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
fprintf(stderr, TR("Error while installing the package\n"));
notify->Go(); notify->Go();
fStatusWindow->Hide(); fStatusWindow->Hide();
fInstall->SetEnabled(true); fInstall->SetEnabled(true);
@@ -253,10 +260,12 @@ PackageView::MessageReceived(BMessage *msg)
break; break;
BString name = path.Path(); BString name = path.Path();
char sizeString[32]; char sizeString[48];
convert_size(volume.FreeBytes(), sizeString, 32); convert_size(volume.FreeBytes(), sizeString, 48);
name << " (" << sizeString << " free)"; char buffer[512];
snprintf(buffer, sizeof(buffer), "(%s free)", sizeString);
name << buffer;
item->SetLabel(name.String()); item->SetLabel(name.String());
fCurrentPath.SetTo(path.Path()); fCurrentPath.SetTo(path.Path());
@@ -300,14 +309,41 @@ PackageView::ItemExists(PackageItem &item, BPath &path, int32 &policy)
case P_EXISTS_ASK: case P_EXISTS_ASK:
case P_EXISTS_NONE: case P_EXISTS_NONE:
{ {
BString alertString = T("The "); const char* formatString;
switch (item.ItemKind()){
alertString << item.ItemKind() << T(" named \'") << path.Leaf() << "\' "; case P_KIND_SCRIPT:
alertString << T("already exists in the given path.\nReplace the file with " formatString = TR("The script named \'%s\' already exits "
"the one from this package or skip it?"); "in the given path.\nReplace the script with the one "
"from this package or skip it?");
BAlert *alert = new BAlert(T("file_exists"), alertString.String(), break;
T("Replace"), T("Skip"), T("Abort")); case P_KIND_FILE:
formatString = TR("The file named \'%s\' already exits "
"in the given path.\nReplace the file with the one "
"from this package or skip it?");
break;
case P_KIND_DIRECTORY:
formatString = TR("The directory named \'%s\' already "
"exits in the given path.\nReplace the directory with "
"one from this package or skip it?");
break;
case P_KIND_SYM_LINK:
formatString = TR("The symbolic link named \'%s\' already "
"exists in the give path.\nReplace the link with the "
"one from this package or skip it?");
break;
default:
formatString = TR("The item named \'%s\' already exits "
"in the given path.\nReplace the item with the one "
"from this package or skip it?");
break;
}
char buffer[512];
snprintf(buffer, sizeof(buffer), formatString, path.Leaf());
BString alertString = buffer;
BAlert *alert = new BAlert("file_exists", alertString.String(),
TR("Replace"), TR("Skip"), TR("Abort"));
choice = alert->Go(); choice = alert->Go();
switch (choice) { switch (choice) {
@@ -323,13 +359,14 @@ PackageView::ItemExists(PackageItem &item, BPath &path, int32 &policy)
if (policy == P_EXISTS_NONE) { if (policy == P_EXISTS_NONE) {
// TODO: Maybe add 'No, but ask again' type of choice as well? // TODO: Maybe add 'No, but ask again' type of choice as well?
alertString = T("Do you want to remember this decision for the rest of " alertString = TR("Do you want to remember this decision for "
"this installation?\nAll existing files will be "); "the rest of this installation?\n");
alertString << ((choice == P_EXISTS_OVERWRITE) alertString << ((choice == P_EXISTS_OVERWRITE)
? T("replaced?") : T("skipped?")); ? TR("All existing files will be replaced?")
: TR("All existing files will be skipped?"));
alert = new BAlert(T("policy_decision"), alertString.String(), alert = new BAlert("policy_decision", alertString.String(),
T("Yes"), T("No")); TR("Replace all"), TR("Ask again"));
int32 decision = alert->Go(); int32 decision = alert->Go();
if (decision == 0) if (decision == 0)
@@ -361,7 +398,7 @@ PackageView::_InitView()
fInstallTypes = new BPopUpMenu("none"); fInstallTypes = new BPopUpMenu("none");
BMenuField *installType = new BMenuField("install_type", BMenuField *installType = new BMenuField("install_type",
T("Installation type:"), fInstallTypes, 0); TR("Installation type:"), fInstallTypes, 0);
installType->SetAlignment(B_ALIGN_RIGHT); installType->SetAlignment(B_ALIGN_RIGHT);
installType->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); installType->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE));
@@ -370,10 +407,10 @@ PackageView::_InitView()
fInstallDesc->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fInstallDesc->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fInstallDesc->MakeEditable(false); fInstallDesc->MakeEditable(false);
fInstallDesc->MakeSelectable(false); fInstallDesc->MakeSelectable(false);
fInstallDesc->SetText(T("No installation type selected")); fInstallDesc->SetText(TR("No installation type selected"));
fInstallDesc->TextHeight(0, fInstallDesc->TextLength()); fInstallDesc->TextHeight(0, fInstallDesc->TextLength());
fInstall = new BButton("install_button", T("Install"), fInstall = new BButton("install_button", TR("Install"),
new BMessage(P_MSG_INSTALL)); new BMessage(P_MSG_INSTALL));
BView *installField = BGroupLayoutBuilder(B_VERTICAL, 5.0f) BView *installField = BGroupLayoutBuilder(B_VERTICAL, 5.0f)
@@ -416,9 +453,11 @@ PackageView::_InitView()
float length = description->TextHeight(0, description->TextLength()) + 5; float length = description->TextHeight(0, description->TextLength()) + 5;
if (length > kMaxDescHeight) { if (length > kMaxDescHeight) {
// Set a scroller for the description. // Set a scroller for the description.
description->ResizeTo(rect.Width() - B_V_SCROLL_BAR_WIDTH, kMaxDescHeight); description->ResizeTo(rect.Width() - B_V_SCROLL_BAR_WIDTH,
kMaxDescHeight);
BScrollView *scroller = new BScrollView("desciption_view", description, BScrollView *scroller = new BScrollView("desciption_view", description,
B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_NO_BORDER); B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, false, true,
B_NO_BORDER);
AddChild(scroller); AddChild(scroller);
rect = scroller->Frame(); rect = scroller->Frame();
@@ -435,8 +474,8 @@ PackageView::_InitView()
fInstallTypes = new BPopUpMenu("none"); fInstallTypes = new BPopUpMenu("none");
BMenuField *installType = new BMenuField(BRect(2, 2, 100, 50), "install_type", BMenuField *installType = new BMenuField(BRect(2, 2, 100, 50),
T("Installation type:"), fInstallTypes, false); "install_type", TR("Installation type:"), fInstallTypes, false);
installType->SetDivider(installType->StringWidth(installType->Label()) + 8); installType->SetDivider(installType->StringWidth(installType->Label()) + 8);
installType->SetAlignment(B_ALIGN_RIGHT); installType->SetAlignment(B_ALIGN_RIGHT);
installType->ResizeToPreferred(); installType->ResizeToPreferred();
@@ -450,12 +489,12 @@ PackageView::_InitView()
B_WILL_DRAW); B_WILL_DRAW);
fInstallDesc->MakeEditable(false); fInstallDesc->MakeEditable(false);
fInstallDesc->MakeSelectable(false); fInstallDesc->MakeSelectable(false);
fInstallDesc->SetText(T("No installation type selected")); fInstallDesc->SetText(TR("No installation type selected"));
fInstallDesc->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fInstallDesc->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fInstallDesc->ResizeTo(rect.Width() - B_V_SCROLL_BAR_WIDTH, 60); fInstallDesc->ResizeTo(rect.Width() - B_V_SCROLL_BAR_WIDTH, 60);
BScrollView *scroller = new BScrollView("desciption_view", fInstallDesc, BScrollView *scroller = new BScrollView("desciption_view", fInstallDesc,
B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_NO_BORDER); B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_NO_BORDER);
installBox->ResizeTo(installBox->Bounds().Width(), installBox->ResizeTo(installBox->Bounds().Width(),
scroller->Frame().bottom + 10); scroller->Frame().bottom + 10);
@@ -469,7 +508,7 @@ PackageView::_InitView()
rect = installBox->Frame(); rect = installBox->Frame();
rect.top = rect.bottom + 5; rect.top = rect.bottom + 5;
rect.bottom += 35; rect.bottom += 35;
fDestField = new BMenuField(rect, "install_to", T("Install to:"), fDestField = new BMenuField(rect, "install_to", TR("Install to:"),
fDestination, false); fDestination, false);
fDestField->SetDivider(fDestField->StringWidth(fDestField->Label()) + 8); fDestField->SetDivider(fDestField->StringWidth(fDestField->Label()) + 8);
fDestField->SetAlignment(B_ALIGN_RIGHT); fDestField->SetAlignment(B_ALIGN_RIGHT);
@@ -477,11 +516,12 @@ PackageView::_InitView()
AddChild(fDestField); AddChild(fDestField);
fInstall = new BButton(rect, "install_button", T("Install"), fInstall = new BButton(rect, "install_button", TR("Install"),
new BMessage(P_MSG_INSTALL)); new BMessage(P_MSG_INSTALL));
fInstall->ResizeToPreferred(); fInstall->ResizeToPreferred();
AddChild(fInstall); AddChild(fInstall);
fInstall->MoveTo(Bounds().Width() - fInstall->Bounds().Width() - 10, rect.top + 2); fInstall->MoveTo(Bounds().Width() - fInstall->Bounds().Width() - 10,
rect.top + 2);
fInstall->MakeDefault(true); fInstall->MakeDefault(true);
} }
@@ -493,14 +533,16 @@ PackageView::_InitProfiles()
int i = 0, num = fInfo.GetProfileCount(); int i = 0, num = fInfo.GetProfileCount();
pkg_profile *prof; pkg_profile *prof;
BMenuItem *item = 0; BMenuItem *item = 0;
char sizeString[32]; char sizeString[48];
BString name = ""; BString name = "";
BMessage *message; BMessage *message;
if (num > 0) { // Add the default item if (num > 0) { // Add the default item
prof = fInfo.GetProfile(0); prof = fInfo.GetProfile(0);
convert_size(prof->space_needed, sizeString, 32); convert_size(prof->space_needed, sizeString, 48);
name << prof->name << " (" << sizeString << ")"; char buffer[512];
snprintf(buffer, sizeof(buffer), "(%s)", sizeString);
name << prof->name << buffer;
message = new BMessage(P_MSG_GROUP_CHANGED); message = new BMessage(P_MSG_GROUP_CHANGED);
message->AddInt32("index", 0); message->AddInt32("index", 0);
@@ -514,9 +556,11 @@ PackageView::_InitProfiles()
prof = fInfo.GetProfile(i); prof = fInfo.GetProfile(i);
if (prof) { if (prof) {
convert_size(prof->space_needed, sizeString, 32); convert_size(prof->space_needed, sizeString, 48);
name = prof->name; name = prof->name;
name << " (" << sizeString << ")"; char buffer[512];
snprintf(buffer, sizeof(buffer), "(%s)", sizeString);
name << buffer;
message = new BMessage(P_MSG_GROUP_CHANGED); message = new BMessage(P_MSG_GROUP_CHANGED);
message->AddInt32("index", i); message->AddInt32("index", i);
@@ -554,11 +598,13 @@ PackageView::_GroupChanged(int32 index)
BPath path; BPath path;
BMessage *temp; BMessage *temp;
BVolume volume; BVolume volume;
char buffer[512];
const char *tmp = TR("(%s free)");
if (prof->path_type == P_INSTALL_PATH) { if (prof->path_type == P_INSTALL_PATH) {
dev_t device; dev_t device;
BString name; BString name;
char sizeString[32]; char sizeString[48];
if (find_directory(B_BEOS_APPS_DIRECTORY, &path) == B_OK) { if (find_directory(B_BEOS_APPS_DIRECTORY, &path) == B_OK) {
device = dev_for_path(path.Path()); device = dev_for_path(path.Path());
@@ -566,9 +612,10 @@ PackageView::_GroupChanged(int32 index)
temp = new BMessage(P_MSG_PATH_CHANGED); temp = new BMessage(P_MSG_PATH_CHANGED);
temp->AddString("path", BString(path.Path())); temp->AddString("path", BString(path.Path()));
convert_size(volume.FreeBytes(), sizeString, 32); convert_size(volume.FreeBytes(), sizeString, 48);
name = path.Path(); name = path.Path();
name << " (" << sizeString << " free)"; snprintf(buffer, sizeof(buffer), tmp, sizeString);
name << buffer;
item = new BMenuItem(name.String(), temp); item = new BMenuItem(name.String(), temp);
item->SetTarget(this); item->SetTarget(this);
fDestination->AddItem(item); fDestination->AddItem(item);
@@ -580,9 +627,11 @@ PackageView::_GroupChanged(int32 index)
temp = new BMessage(P_MSG_PATH_CHANGED); temp = new BMessage(P_MSG_PATH_CHANGED);
temp->AddString("path", BString(path.Path())); temp->AddString("path", BString(path.Path()));
convert_size(volume.FreeBytes(), sizeString, 32); convert_size(volume.FreeBytes(), sizeString, 48);
char buffer[512];
snprintf(buffer, sizeof(buffer), tmp, sizeString);
name = path.Path(); name = path.Path();
name << " (" << sizeString << " free)"; name << buffer;
item = new BMenuItem(name.String(), temp); item = new BMenuItem(name.String(), temp);
item->SetTarget(this); item->SetTarget(this);
fDestination->AddItem(item); fDestination->AddItem(item);
@@ -595,7 +644,8 @@ PackageView::_GroupChanged(int32 index)
} }
fDestination->AddSeparatorItem(); fDestination->AddSeparatorItem();
item = new BMenuItem("Other" B_UTF8_ELLIPSIS, new BMessage(P_MSG_OPEN_PANEL)); item = new BMenuItem(TR("Other" B_UTF8_ELLIPSIS),
new BMessage(P_MSG_OPEN_PANEL));
item->SetTarget(this); item->SetTarget(this);
fDestination->AddItem(item); fDestination->AddItem(item);
@@ -603,7 +653,7 @@ PackageView::_GroupChanged(int32 index)
} else if (prof->path_type == P_USER_PATH) { } else if (prof->path_type == P_USER_PATH) {
BString name; BString name;
bool defaultPathSet = false; bool defaultPathSet = false;
char sizeString[32], volumeName[B_FILE_NAME_LENGTH]; char sizeString[48], volumeName[B_FILE_NAME_LENGTH];
BVolumeRoster roster; BVolumeRoster roster;
BDirectory mountPoint; BDirectory mountPoint;
@@ -619,10 +669,11 @@ PackageView::_GroupChanged(int32 index)
temp = new BMessage(P_MSG_PATH_CHANGED); temp = new BMessage(P_MSG_PATH_CHANGED);
temp->AddString("path", BString(path.Path())); temp->AddString("path", BString(path.Path()));
convert_size(volume.FreeBytes(), sizeString, 32); convert_size(volume.FreeBytes(), sizeString, 48);
volume.GetName(volumeName); volume.GetName(volumeName);
name = volumeName; name = volumeName;
name << " (" << sizeString << " free)"; snprintf(buffer, sizeof(buffer), tmp, sizeString);
name << buffer;
item = new BMenuItem(name.String(), temp); item = new BMenuItem(name.String(), temp);
item->SetTarget(this); item->SetTarget(this);
fDestination->AddItem(item); fDestination->AddItem(item);
+9 -7
View File
@@ -1,25 +1,27 @@
/* /*
* Copyright (c) 2007-2009, Haiku, Inc. All rights reserved. * Copyright (c) 2007-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Author: * Author:
* Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
*/ */
#include "PackageWindow.h" #include "PackageWindow.h"
#include <Application.h> #include <Application.h>
#include <Catalog.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <Locale.h>
// Macro reserved for later localization
#define T(x) x #undef TR_CONTEXT
#define TR_CONTEXT "PackageWindow"
PackageWindow::PackageWindow(const entry_ref *ref) PackageWindow::PackageWindow(const entry_ref *ref)
: BWindow(BRect(100, 100, 600, 300), T("PackageInstaller"), B_TITLED_WINDOW, :
B_NOT_ZOOMABLE | B_NOT_RESIZABLE) BWindow(BRect(100, 100, 600, 300), TR("PackageInstaller"),
B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{ {
//SetLayout(new BGroupLayout(B_HORIZONTAL)); //SetLayout(new BGroupLayout(B_HORIZONTAL));
+20 -11
View File
@@ -9,15 +9,20 @@
#include "PackageWindow.h" #include "PackageWindow.h"
#include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Autolock.h>
#include <Catalog.h>
#include <Entry.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <List.h> #include <List.h>
#include <Alert.h> #include <Locale.h>
#include <TextView.h> #include <TextView.h>
#include <Entry.h>
#include <Autolock.h>
#include <stdio.h> #include <stdio.h>
#undef TR_CONTEXT
#define TR_CONTEXT "Packageinstaller main"
class PackageInstaller : public BApplication { class PackageInstaller : public BApplication {
public: public:
@@ -33,16 +38,20 @@ class PackageInstaller : public BApplication {
void AboutRequested(); void AboutRequested();
private: private:
BFilePanel *fOpen; BFilePanel *fOpen;
uint32 fWindowCount; uint32 fWindowCount;
BCatalog fAppCatalog;
}; };
PackageInstaller::PackageInstaller() PackageInstaller::PackageInstaller()
: BApplication("application/x-vnd.Haiku-PackageInstaller"), : BApplication("application/x-vnd.Haiku-PackageInstaller"),
fWindowCount(0) fOpen(NULL),
fWindowCount(0),
fAppCatalog(NULL)
{ {
fOpen = new BFilePanel(B_OPEN_PANEL); fOpen = new BFilePanel(B_OPEN_PANEL);
be_locale->GetAppCatalog(&fAppCatalog);
} }
@@ -94,13 +103,13 @@ PackageInstaller::ArgvReceived(int32 argc, char **argv)
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (path.SetTo(argv[i]) != B_OK) { if (path.SetTo(argv[i]) != B_OK) {
fprintf(stderr, "Error! \"%s\" is not a valid path.\n", argv[i]); fprintf(stderr, TR("Error! \"%s\" is not a valid path.\n"), argv[i]);
continue; continue;
} }
ret = get_ref_for_path(path.Path(), &ref); ret = get_ref_for_path(path.Path(), &ref);
if (ret != B_OK) { if (ret != B_OK) {
fprintf(stderr, "Error (%s)! Could not open \"%s\".\n", strerror(ret), fprintf(stderr, TR("Error (%s)! Could not open \"%s\".\n"), strerror(ret),
argv[i]); argv[i]);
continue; continue;
} }
@@ -135,11 +144,11 @@ void
PackageInstaller::AboutRequested() PackageInstaller::AboutRequested()
{ {
BAlert *about = new BAlert("about", BAlert *about = new BAlert("about",
"PackageInstaller\n" TR("PackageInstaller\n"
"BeOS legacy .pkg file installer for Haiku.\n\n" "BeOS legacy .pkg file installer for Haiku.\n\n"
"Copyright 2007,\nŁukasz 'Sil2100' Zemczak\n\n" "Copyright 2007,\nŁukasz 'Sil2100' Zemczak\n\n"
"Copyright (c) 2007 Haiku, Inc. \n", "Copyright (c) 2007 Haiku, Inc. \n"),
"OK"); TR("OK"));
BTextView *view = about->TextView(); BTextView *view = about->TextView();
BFont font; BFont font;