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