Add localization support to WebPositive, patch by Humdinger

* Includes style fixes
* Functional fixes by myself, patch wouldn't build
This commit is contained in:
Alexandre Deckner
2012-07-12 00:47:46 +02:00
parent f190d7d580
commit 2218c029a5
6 changed files with 354 additions and 255 deletions
+83 -60
View File
@@ -28,10 +28,12 @@
#include "AuthenticationPanel.h" #include "AuthenticationPanel.h"
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <GridLayoutBuilder.h> #include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <Message.h> #include <Message.h>
#include <Screen.h> #include <Screen.h>
#include <SeparatorView.h> #include <SeparatorView.h>
@@ -44,28 +46,41 @@ static const uint32 kMsgPanelOK = 'pnok';
static const uint32 kMsgJitter = 'jitr'; static const uint32 kMsgJitter = 'jitr';
static const uint32 kHidePassword = 'hdpw'; static const uint32 kHidePassword = 'hdpw';
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Authentication Panel"
AuthenticationPanel::AuthenticationPanel(BRect parentFrame) AuthenticationPanel::AuthenticationPanel(BRect parentFrame)
: BWindow(BRect(-1000, -1000, -900, -900), "Authentication Required", :
B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, BWindow(BRect(-1000, -1000, -900, -900),
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE B_TRANSLATE("Authentication Required"), B_TITLED_WINDOW_LOOK,
| B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS) B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE
, m_parentWindowFrame(parentFrame) | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS),
, m_usernameTextControl(new BTextControl("user", "Username:", "", NULL)) m_parentWindowFrame(parentFrame),
, m_passwordTextControl(new BTextControl("pass", "Password:", "", NULL)) m_usernameTextControl(new BTextControl("user", B_TRANSLATE("Username:"),
, m_hidePasswordCheckBox(new BCheckBox("hide", "Hide password text", new BMessage(kHidePassword))) "", NULL)),
, m_rememberCredentialsCheckBox(new BCheckBox("remember", "Remember username and password for this site", NULL)) m_passwordTextControl(new BTextControl("pass", B_TRANSLATE("Password:"),
, m_okButton(new BButton("ok", "OK", new BMessage(kMsgPanelOK))) "", NULL)),
, m_cancelButton(new BButton("cancel", "Cancel", new BMessage(B_QUIT_REQUESTED))) m_hidePasswordCheckBox(new BCheckBox("hide", B_TRANSLATE("Hide password "
, m_cancelled(false) "text"), new BMessage(kHidePassword))),
, m_exitSemaphore(create_sem(0, "Authentication Panel")) m_rememberCredentialsCheckBox(new BCheckBox("remember",
B_TRANSLATE("Remember username and password for this site"), NULL)),
m_okButton(new BButton("ok", B_TRANSLATE("OK"),
new BMessage(kMsgPanelOK))),
m_cancelButton(new BButton("cancel", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED))),
m_cancelled(false),
m_exitSemaphore(create_sem(0, "Authentication Panel"))
{ {
} }
AuthenticationPanel::~AuthenticationPanel() AuthenticationPanel::~AuthenticationPanel()
{ {
delete_sem(m_exitSemaphore); delete_sem(m_exitSemaphore);
} }
bool bool
AuthenticationPanel::QuitRequested() AuthenticationPanel::QuitRequested()
{ {
@@ -74,6 +89,7 @@ AuthenticationPanel::QuitRequested()
return false; return false;
} }
void void
AuthenticationPanel::MessageReceived(BMessage* message) AuthenticationPanel::MessageReceived(BMessage* message)
{ {
@@ -81,21 +97,23 @@ AuthenticationPanel::MessageReceived(BMessage* message)
case kMsgPanelOK: case kMsgPanelOK:
release_sem(m_exitSemaphore); release_sem(m_exitSemaphore);
break; break;
case kHidePassword: { case kHidePassword: {
// TODO: Toggling this is broken in BTextView. Workaround is to // TODO: Toggling this is broken in BTextView. Workaround is to
// set the text and selection again. // set the text and selection again.
BString text = m_passwordTextControl->Text(); BString text = m_passwordTextControl->Text();
int32 selectionStart; int32 selectionStart;
int32 selectionEnd; int32 selectionEnd;
m_passwordTextControl->TextView()->GetSelection(&selectionStart, &selectionEnd); m_passwordTextControl->TextView()->GetSelection(&selectionStart,
&selectionEnd);
m_passwordTextControl->TextView()->HideTyping( m_passwordTextControl->TextView()->HideTyping(
m_hidePasswordCheckBox->Value() == B_CONTROL_ON); m_hidePasswordCheckBox->Value() == B_CONTROL_ON);
m_passwordTextControl->SetText(text.String()); m_passwordTextControl->SetText(text.String());
m_passwordTextControl->TextView()->Select(selectionStart, selectionEnd); m_passwordTextControl->TextView()->Select(selectionStart,
break; selectionEnd);
} break;
case kMsgJitter: { }
UpdateIfNeeded(); case kMsgJitter: {
UpdateIfNeeded();
BPoint leftTop = Frame().LeftTop(); BPoint leftTop = Frame().LeftTop();
const float jitterOffsets[] = { -10, 0, 10, 0 }; const float jitterOffsets[] = { -10, 0, 10, 0 };
const int32 jitterOffsetCount = sizeof(jitterOffsets) / sizeof(float); const int32 jitterOffsetCount = sizeof(jitterOffsets) / sizeof(float);
@@ -106,14 +124,15 @@ AuthenticationPanel::MessageReceived(BMessage* message)
} }
MoveTo(leftTop); MoveTo(leftTop);
break; break;
} }
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
} }
} }
bool AuthenticationPanel::getAuthentication(const BString& text, bool AuthenticationPanel::getAuthentication(const BString& text,
const BString& previousUser, const BString& previousPass, const BString& previousUser, const BString& previousPass,
bool previousRememberCredentials, bool badPassword, bool previousRememberCredentials, bool badPassword,
BString& user, BString& pass, bool* rememberCredentials) BString& user, BString& pass, bool* rememberCredentials)
{ {
@@ -121,17 +140,18 @@ bool AuthenticationPanel::getAuthentication(const BString& text,
rgb_color infoColor = ui_color(B_PANEL_TEXT_COLOR); rgb_color infoColor = ui_color(B_PANEL_TEXT_COLOR);
BRect textBounds(0, 0, 250, 200); BRect textBounds(0, 0, 250, 200);
BTextView* textView = new BTextView(textBounds, "text", textBounds, BTextView* textView = new BTextView(textBounds, "text", textBounds,
be_plain_font, &infoColor, B_FOLLOW_NONE, B_WILL_DRAW | B_SUPPORTS_LAYOUT); be_plain_font, &infoColor, B_FOLLOW_NONE, B_WILL_DRAW
| B_SUPPORTS_LAYOUT);
textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
textView->SetText(text.String()); textView->SetText(text.String());
textView->MakeEditable(false); textView->MakeEditable(false);
textView->MakeSelectable(false); textView->MakeSelectable(false);
m_usernameTextControl->SetText(previousUser.String()); m_usernameTextControl->SetText(previousUser.String());
m_passwordTextControl->TextView()->HideTyping(true); m_passwordTextControl->TextView()->HideTyping(true);
// Ignore the previous password, if it didn't work. // Ignore the previous password, if it didn't work.
if (!badPassword) if (!badPassword)
m_passwordTextControl->SetText(previousPass.String()); m_passwordTextControl->SetText(previousPass.String());
m_hidePasswordCheckBox->SetValue(B_CONTROL_ON); m_hidePasswordCheckBox->SetValue(B_CONTROL_ON);
m_rememberCredentialsCheckBox->SetValue(previousRememberCredentials); m_rememberCredentialsCheckBox->SetValue(previousRememberCredentials);
@@ -139,24 +159,24 @@ bool AuthenticationPanel::getAuthentication(const BString& text,
SetLayout(new BGroupLayout(B_VERTICAL, 0.0)); SetLayout(new BGroupLayout(B_VERTICAL, 0.0));
float spacing = be_control_look->DefaultItemSpacing(); float spacing = be_control_look->DefaultItemSpacing();
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0.0) AddChild(BGroupLayoutBuilder(B_VERTICAL, 0.0)
.Add(BGridLayoutBuilder(0, spacing) .Add(BGridLayoutBuilder(0, spacing)
.Add(textView, 0, 0, 2) .Add(textView, 0, 0, 2)
.Add(m_usernameTextControl->CreateLabelLayoutItem(), 0, 1) .Add(m_usernameTextControl->CreateLabelLayoutItem(), 0, 1)
.Add(m_usernameTextControl->CreateTextViewLayoutItem(), 1, 1) .Add(m_usernameTextControl->CreateTextViewLayoutItem(), 1, 1)
.Add(m_passwordTextControl->CreateLabelLayoutItem(), 0, 2) .Add(m_passwordTextControl->CreateLabelLayoutItem(), 0, 2)
.Add(m_passwordTextControl->CreateTextViewLayoutItem(), 1, 2) .Add(m_passwordTextControl->CreateTextViewLayoutItem(), 1, 2)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 3) .Add(BSpaceLayoutItem::CreateGlue(), 0, 3)
.Add(m_hidePasswordCheckBox, 1, 3) .Add(m_hidePasswordCheckBox, 1, 3)
.Add(m_rememberCredentialsCheckBox, 0, 4, 2) .Add(m_rememberCredentialsCheckBox, 0, 4, 2)
.SetInsets(spacing, spacing, spacing, spacing) .SetInsets(spacing, spacing, spacing, spacing)
) )
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, spacing) .Add(BGroupLayoutBuilder(B_HORIZONTAL, spacing)
.AddGlue() .AddGlue()
.Add(m_cancelButton) .Add(m_cancelButton)
.Add(m_okButton) .Add(m_okButton)
.SetInsets(spacing, spacing, spacing, spacing) .SetInsets(spacing, spacing, spacing, spacing)
) )
); );
float textHeight = textView->LineHeight(0) * textView->CountLines(); float textHeight = textView->LineHeight(0) * textView->CountLines();
@@ -164,14 +184,14 @@ bool AuthenticationPanel::getAuthentication(const BString& text,
SetDefaultButton(m_okButton); SetDefaultButton(m_okButton);
if (badPassword && previousUser.Length()) if (badPassword && previousUser.Length())
m_passwordTextControl->MakeFocus(true); m_passwordTextControl->MakeFocus(true);
else else
m_usernameTextControl->MakeFocus(true); m_usernameTextControl->MakeFocus(true);
if (m_parentWindowFrame.IsValid()) if (m_parentWindowFrame.IsValid())
CenterIn(m_parentWindowFrame); CenterIn(m_parentWindowFrame);
else else
CenterOnScreen(); CenterOnScreen();
// Start AuthenticationPanel window thread // Start AuthenticationPanel window thread
Show(); Show();
@@ -182,12 +202,14 @@ bool AuthenticationPanel::getAuthentication(const BString& text,
// Block calling thread // Block calling thread
// Get the originating window, if it exists, to let it redraw itself. // Get the originating window, if it exists, to let it redraw itself.
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL))); BWindow* window = dynamic_cast<BWindow*>
(BLooper::LooperForThread(find_thread(NULL)));
if (window) { if (window) {
status_t err; status_t err;
for (;;) { for (;;) {
do { do {
err = acquire_sem_etc(m_exitSemaphore, 1, B_RELATIVE_TIMEOUT, 10000); err = acquire_sem_etc(m_exitSemaphore, 1, B_RELATIVE_TIMEOUT,
10000);
// We've (probably) had our time slice taken away from us // We've (probably) had our time slice taken away from us
} while (err == B_INTERRUPTED); } while (err == B_INTERRUPTED);
@@ -209,9 +231,10 @@ bool AuthenticationPanel::getAuthentication(const BString& text,
user = m_usernameTextControl->Text(); user = m_usernameTextControl->Text();
pass = m_passwordTextControl->Text(); pass = m_passwordTextControl->Text();
if (rememberCredentials) if (rememberCredentials)
*rememberCredentials = m_rememberCredentialsCheckBox->Value() == B_CONTROL_ON; *rememberCredentials = m_rememberCredentialsCheckBox->Value()
== B_CONTROL_ON;
bool canceled = m_cancelled; bool canceled = m_cancelled;
Quit(); Quit();
// AuthenticationPanel object is TOAST here. // AuthenticationPanel object is TOAST here.
return !canceled; return !canceled;
+27 -17
View File
@@ -28,6 +28,19 @@
#include "BrowserApp.h" #include "BrowserApp.h"
#include <Alert.h>
#include <Autolock.h>
#include <Catalog.h>
#include <Directory.h>
#include <Entry.h>
#include <FindDirectory.h>
#include <Locale.h>
#include <Path.h>
#include <Screen.h>
#include <debugger.h>
#include <stdio.h>
#include "BrowserWindow.h" #include "BrowserWindow.h"
#include "BrowsingHistory.h" #include "BrowsingHistory.h"
#include "DownloadWindow.h" #include "DownloadWindow.h"
@@ -39,20 +52,13 @@
#include "WebPage.h" #include "WebPage.h"
#include "WebSettings.h" #include "WebSettings.h"
#include "WebView.h" #include "WebView.h"
#include <Alert.h>
#include <Autolock.h>
#include <Directory.h>
#include <Entry.h>
#include <FindDirectory.h>
#include <Locale.h>
#include <Path.h>
#include <Screen.h>
#include <debugger.h>
#include <stdio.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "WebPositive"
const char* kApplicationSignature = "application/x-vnd.Haiku-WebPositive"; const char* kApplicationSignature = "application/x-vnd.Haiku-WebPositive";
const char* kApplicationName = "WebPositive"; const char* kApplicationName = B_TRANSLATE_SYSTEM_NAME("WebPositive");
static const uint32 PRELOAD_BROWSING_HISTORY = 'plbh'; static const uint32 PRELOAD_BROWSING_HISTORY = 'plbh';
#define ENABLE_NATIVE_COOKIES 0 #define ENABLE_NATIVE_COOKIES 0
@@ -174,8 +180,10 @@ BrowserApp::ReadyToRun()
float borderWidth = 0; float borderWidth = 0;
if (decoratorSettings.FindFloat("border width", &borderWidth) != B_OK) if (decoratorSettings.FindFloat("border width", &borderWidth) != B_OK)
borderWidth = 5; borderWidth = 5;
fDownloadWindow->MoveTo(screenFrame.Width() - fDownloadWindow->Frame().Width() - borderWidth, fDownloadWindow->MoveTo(screenFrame.Width()
screenFrame.Height() - fDownloadWindow->Frame().Height() - borderWidth); - fDownloadWindow->Frame().Width() - borderWidth,
screenFrame.Height() - fDownloadWindow->Frame().Height()
- borderWidth);
} }
fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings); fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings);
@@ -217,7 +225,8 @@ BrowserApp::MessageReceived(BMessage* message)
} }
case NEW_TAB: { case NEW_TAB: {
BrowserWindow* window; BrowserWindow* window;
if (message->FindPointer("window", reinterpret_cast<void**>(&window)) != B_OK) if (message->FindPointer("window",
reinterpret_cast<void**>(&window)) != B_OK)
break; break;
BString url; BString url;
message->FindString("url", &url); message->FindString("url", &url);
@@ -268,9 +277,10 @@ bool
BrowserApp::QuitRequested() BrowserApp::QuitRequested()
{ {
if (fDownloadWindow->DownloadsInProgress()) { if (fDownloadWindow->DownloadsInProgress()) {
BAlert* alert = new BAlert("Downloads in progress", BAlert* alert = new BAlert(B_TRANSLATE("Downloads in progress"),
"There are still downloads in progress, do you really want to " B_TRANSLATE("There are still downloads in progress, do you really "
"quit WebPositive now?", "Quit", "Continue downloads"); "want to quit WebPositive now?"), B_TRANSLATE("Quit"),
B_TRANSLATE("Continue downloads"));
int32 choice = alert->Go(); int32 choice = alert->Go();
if (choice == 1) { if (choice == 1) {
if (fWindowCount == 0) { if (fWindowCount == 0) {
+149 -120
View File
@@ -32,6 +32,37 @@
#include "BrowserWindow.h" #include "BrowserWindow.h"
#include <Alert.h>
#include <Application.h>
#include <Bitmap.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <Clipboard.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FindDirectory.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>
#include <Locale.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <MessageRunner.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Roster.h>
#include <Screen.h>
#include <SeparatorView.h>
#include <SpaceLayoutItem.h>
#include <StatusBar.h>
#include <StringView.h>
#include <TextControl.h>
#include <stdio.h>
#include "AuthenticationPanel.h" #include "AuthenticationPanel.h"
#include "BaseURL.h" #include "BaseURL.h"
#include "BitmapButton.h" #include "BitmapButton.h"
@@ -48,35 +79,10 @@
#include "WebView.h" #include "WebView.h"
#include "WebViewConstants.h" #include "WebViewConstants.h"
#include "WindowIcon.h" #include "WindowIcon.h"
#include <Alert.h>
#include <Application.h>
#include <Bitmap.h>
#include <Button.h>
#include <CheckBox.h>
#include <Clipboard.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FindDirectory.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <MessageRunner.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Roster.h>
#include <Screen.h>
#include <SeparatorView.h>
#include <SpaceLayoutItem.h>
#include <StatusBar.h>
#include <StringView.h>
#include <TextControl.h>
#include <stdio.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "WebPositive Window"
enum { enum {
OPEN_LOCATION = 'open', OPEN_LOCATION = 'open',
@@ -148,9 +154,9 @@ public:
private: private:
void _AddStaticItems() void _AddStaticItems()
{ {
AddItem(new BMenuItem("Manage bookmarks", AddItem(new BMenuItem(B_TRANSLATE("Manage bookmarks"),
new BMessage(SHOW_BOOKMARKS), 'M'), 0); new BMessage(SHOW_BOOKMARKS), 'M'), 0);
AddItem(new BMenuItem("Bookmark this page", AddItem(new BMenuItem(B_TRANSLATE("Bookmark this page"),
new BMessage(CREATE_BOOKMARK), 'B'), 0); new BMessage(CREATE_BOOKMARK), 'B'), 0);
} }
}; };
@@ -281,82 +287,88 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
#else #else
BMenu* mainMenu = new BMenuBar("Main menu"); BMenu* mainMenu = new BMenuBar("Main menu");
#endif #endif
BMenu* menu = new BMenu("Window"); BMenu* menu = new BMenu(B_TRANSLATE("Window"));
BMessage* newWindowMessage = new BMessage(NEW_WINDOW); BMessage* newWindowMessage = new BMessage(NEW_WINDOW);
newWindowMessage->AddString("url", ""); newWindowMessage->AddString("url", "");
BMenuItem* newItem = new BMenuItem("New window", newWindowMessage, 'N'); BMenuItem* newItem = new BMenuItem(B_TRANSLATE("New window"),
newWindowMessage, 'N');
menu->AddItem(newItem); menu->AddItem(newItem);
newItem->SetTarget(be_app); newItem->SetTarget(be_app);
newItem = new BMenuItem("New tab", new BMessage(*newTabMessage), 'T'); newItem = new BMenuItem(B_TRANSLATE("New tab"),
new BMessage(*newTabMessage), 'T');
menu->AddItem(newItem); menu->AddItem(newItem);
newItem->SetTarget(be_app); newItem->SetTarget(be_app);
menu->AddItem(new BMenuItem("Open location", new BMessage(OPEN_LOCATION), menu->AddItem(new BMenuItem(B_TRANSLATE("Open location"),
'L')); new BMessage(OPEN_LOCATION), 'L'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Close window", new BMessage(B_QUIT_REQUESTED), menu->AddItem(new BMenuItem(B_TRANSLATE("Close window"),
'W', B_SHIFT_KEY)); new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY));
menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); menu->AddItem(new BMenuItem(B_TRANSLATE("Close tab"),
new BMessage(CLOSE_TAB), 'W'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Downloads", menu->AddItem(new BMenuItem(B_TRANSLATE("Downloads"),
new BMessage(SHOW_DOWNLOAD_WINDOW), 'D')); new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
menu->AddItem(new BMenuItem("Settings", menu->AddItem(new BMenuItem(B_TRANSLATE("Settings"),
new BMessage(SHOW_SETTINGS_WINDOW))); new BMessage(SHOW_SETTINGS_WINDOW)));
BMenuItem* aboutItem = new BMenuItem("About", BMenuItem* aboutItem = new BMenuItem(B_TRANSLATE("About"),
new BMessage(B_ABOUT_REQUESTED)); new BMessage(B_ABOUT_REQUESTED));
menu->AddItem(aboutItem); menu->AddItem(aboutItem);
aboutItem->SetTarget(be_app); aboutItem->SetTarget(be_app);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
BMenuItem* quitItem = new BMenuItem("Quit", BMenuItem* quitItem = new BMenuItem(B_TRANSLATE("Quit"),
new BMessage(B_QUIT_REQUESTED), 'Q'); new BMessage(B_QUIT_REQUESTED), 'Q');
menu->AddItem(quitItem); menu->AddItem(quitItem);
quitItem->SetTarget(be_app); quitItem->SetTarget(be_app);
mainMenu->AddItem(menu); mainMenu->AddItem(menu);
menu = new BMenu("Edit"); menu = new BMenu(B_TRANSLATE("Edit"));
menu->AddItem(fCutMenuItem = new BMenuItem("Cut", new BMessage(B_CUT), menu->AddItem(fCutMenuItem = new BMenuItem(B_TRANSLATE("Cut"),
'X')); new BMessage(B_CUT), 'X'));
menu->AddItem(fCopyMenuItem = new BMenuItem("Copy", new BMessage(B_COPY), menu->AddItem(fCopyMenuItem = new BMenuItem(B_TRANSLATE("Copy"),
'C')); new BMessage(B_COPY), 'C'));
menu->AddItem(fPasteMenuItem = new BMenuItem("Paste", new BMessage(B_PASTE), menu->AddItem(fPasteMenuItem = new BMenuItem(B_TRANSLATE("Paste"),
'V')); new BMessage(B_PASTE), 'V'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Find", new BMessage(EDIT_SHOW_FIND_GROUP), menu->AddItem(new BMenuItem(B_TRANSLATE("Find"),
'F')); new BMessage(EDIT_SHOW_FIND_GROUP), 'F'));
menu->AddItem(fFindPreviousMenuItem = new BMenuItem("Find previous", menu->AddItem(fFindPreviousMenuItem
= new BMenuItem(B_TRANSLATE("Find previous"),
new BMessage(EDIT_FIND_PREVIOUS), 'G', B_SHIFT_KEY)); new BMessage(EDIT_FIND_PREVIOUS), 'G', B_SHIFT_KEY));
menu->AddItem(fFindNextMenuItem = new BMenuItem("Find next", menu->AddItem(fFindNextMenuItem = new BMenuItem(B_TRANSLATE("Find next"),
new BMessage(EDIT_FIND_NEXT), 'G')); new BMessage(EDIT_FIND_NEXT), 'G'));
mainMenu->AddItem(menu); mainMenu->AddItem(menu);
fFindPreviousMenuItem->SetEnabled(false); fFindPreviousMenuItem->SetEnabled(false);
fFindNextMenuItem->SetEnabled(false); fFindNextMenuItem->SetEnabled(false);
menu = new BMenu("View"); menu = new BMenu(B_TRANSLATE("View"));
menu->AddItem(new BMenuItem("Reload", new BMessage(RELOAD), 'R')); menu->AddItem(new BMenuItem(B_TRANSLATE("Reload"), new BMessage(RELOAD),
'R'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Increase size", menu->AddItem(new BMenuItem(B_TRANSLATE("Increase size"),
new BMessage(ZOOM_FACTOR_INCREASE), '+')); new BMessage(ZOOM_FACTOR_INCREASE), '+'));
menu->AddItem(new BMenuItem("Decrease size", menu->AddItem(new BMenuItem(B_TRANSLATE("Decrease size"),
new BMessage(ZOOM_FACTOR_DECREASE), '-')); new BMessage(ZOOM_FACTOR_DECREASE), '-'));
menu->AddItem(new BMenuItem("Reset size", menu->AddItem(new BMenuItem(B_TRANSLATE("Reset size"),
new BMessage(ZOOM_FACTOR_RESET), '0')); new BMessage(ZOOM_FACTOR_RESET), '0'));
fZoomTextOnlyMenuItem = new BMenuItem("Zoom text only", fZoomTextOnlyMenuItem = new BMenuItem(B_TRANSLATE("Zoom text only"),
new BMessage(ZOOM_TEXT_ONLY)); new BMessage(ZOOM_TEXT_ONLY));
fZoomTextOnlyMenuItem->SetMarked(fZoomTextOnly); fZoomTextOnlyMenuItem->SetMarked(fZoomTextOnly);
menu->AddItem(fZoomTextOnlyMenuItem); menu->AddItem(fZoomTextOnlyMenuItem);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
fFullscreenItem = new BMenuItem("Fullscreen", fFullscreenItem = new BMenuItem(B_TRANSLATE("Fullscreen"),
new BMessage(TOGGLE_FULLSCREEN), B_RETURN); new BMessage(TOGGLE_FULLSCREEN), B_RETURN);
menu->AddItem(fFullscreenItem); menu->AddItem(fFullscreenItem);
menu->AddItem(new BMenuItem("Page source", menu->AddItem(new BMenuItem(B_TRANSLATE("Page source"),
new BMessage(SHOW_PAGE_SOURCE), 'U')); new BMessage(SHOW_PAGE_SOURCE), 'U'));
mainMenu->AddItem(menu); mainMenu->AddItem(menu);
fHistoryMenu = new BMenu("History"); fHistoryMenu = new BMenu(B_TRANSLATE("History"));
fHistoryMenu->AddItem(fBackMenuItem = new BMenuItem("Back", fHistoryMenu->AddItem(fBackMenuItem = new BMenuItem(B_TRANSLATE("Back"),
new BMessage(GO_BACK), B_LEFT_ARROW)); new BMessage(GO_BACK), B_LEFT_ARROW));
fHistoryMenu->AddItem(fForwardMenuItem = new BMenuItem("Forward", fHistoryMenu->AddItem(fForwardMenuItem
new BMessage(GO_FORWARD), B_RIGHT_ARROW)); = new BMenuItem(B_TRANSLATE("Forward"), new BMessage(GO_FORWARD),
B_RIGHT_ARROW));
fHistoryMenu->AddSeparatorItem(); fHistoryMenu->AddSeparatorItem();
fHistoryMenuFixedItemCount = fHistoryMenu->CountItems(); fHistoryMenuFixedItemCount = fHistoryMenu->CountItems();
mainMenu->AddItem(fHistoryMenu); mainMenu->AddItem(fHistoryMenu);
@@ -366,7 +378,7 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
if (_BookmarkPath(bookmarkPath) == B_OK if (_BookmarkPath(bookmarkPath) == B_OK
&& get_ref_for_path(bookmarkPath.Path(), &bookmarkRef) == B_OK) { && get_ref_for_path(bookmarkPath.Path(), &bookmarkRef) == B_OK) {
BMenu* bookmarkMenu BMenu* bookmarkMenu
= new BookmarkMenu("Bookmarks", this, &bookmarkRef); = new BookmarkMenu(B_TRANSLATE("Bookmarks"), this, &bookmarkRef);
mainMenu->AddItem(bookmarkMenu); mainMenu->AddItem(bookmarkMenu);
} }
@@ -412,15 +424,16 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
const float kElementSpacing = 5; const float kElementSpacing = 5;
// Find group // Find group
fFindTextControl = new BTextControl("find", "Find:", "", fFindTextControl = new BTextControl("find", B_TRANSLATE("Find:"), "",
new BMessage(EDIT_FIND_NEXT)); new BMessage(EDIT_FIND_NEXT));
fFindTextControl->SetModificationMessage(new BMessage(FIND_TEXT_CHANGED)); fFindTextControl->SetModificationMessage(new BMessage(FIND_TEXT_CHANGED));
fFindPreviousButton = new BButton("Previous", fFindPreviousButton = new BButton(B_TRANSLATE("Previous"),
new BMessage(EDIT_FIND_PREVIOUS)); new BMessage(EDIT_FIND_PREVIOUS));
fFindNextButton = new BButton("Next", new BMessage(EDIT_FIND_NEXT)); fFindNextButton = new BButton(B_TRANSLATE("Next"),
fFindCloseButton = new BButton("Close", new BMessage(EDIT_FIND_NEXT));
fFindCloseButton = new BButton(B_TRANSLATE("Close"),
new BMessage(EDIT_HIDE_FIND_GROUP)); new BMessage(EDIT_HIDE_FIND_GROUP));
fFindCaseSensitiveCheckBox = new BCheckBox("Match case"); fFindCaseSensitiveCheckBox = new BCheckBox(B_TRANSLATE("Match case"));
BGroupLayout* findGroup = BLayoutBuilder::Group<>(B_VERTICAL, 0.0) BGroupLayout* findGroup = BLayoutBuilder::Group<>(B_VERTICAL, 0.0)
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing)
@@ -511,7 +524,7 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
// Add shortcuts to select a particular tab // Add shortcuts to select a particular tab
for (int32 i = 1; i <= 9; i++) { for (int32 i = 1; i <= 9; i++) {
BMessage *selectTab = new BMessage(SELECT_TAB); BMessage* selectTab = new BMessage(SELECT_TAB);
selectTab->AddInt32("tab index", i - 1); selectTab->AddInt32("tab index", i - 1);
char numStr[2]; char numStr[2];
snprintf(numStr, sizeof(numStr), "%d", (int) i); snprintf(numStr, sizeof(numStr), "%d", (int) i);
@@ -603,10 +616,10 @@ BrowserWindow::DispatchMessage(BMessage* message, BHandler* target)
// Only do this when the mouse is over the web view // Only do this when the mouse is over the web view
if (CurrentWebView()->Bounds().Contains(where)) { if (CurrentWebView()->Bounds().Contains(where)) {
// Zoom and unzoom text on Command + mouse wheel. // Zoom and unzoom text on Command + mouse wheel.
// This could of course (and maybe should be) implemented in the WebView, but there // This could of course (and maybe should be) implemented in the
// would need to be a way for the WebView to know the setting of the // WebView, but there would need to be a way for the WebView to
// fZoomTextOnly member here. Plus other clients of the API may not want // know the setting of the fZoomTextOnly member here. Plus other
// this feature. // clients of the API may not want this feature.
if ((modifiers() & B_COMMAND_KEY) != 0) { if ((modifiers() & B_COMMAND_KEY) != 0) {
float dy; float dy;
if (message->FindFloat("be:wheel_delta_y", &dy) == B_OK) { if (message->FindFloat("be:wheel_delta_y", &dy) == B_OK) {
@@ -667,8 +680,10 @@ BrowserWindow::MessageReceived(BMessage* message)
BrowsingHistory* history = BrowsingHistory::DefaultInstance(); BrowsingHistory* history = BrowsingHistory::DefaultInstance();
if (history->CountItems() == 0) if (history->CountItems() == 0)
break; break;
BAlert* alert = new BAlert("Confirmation", "Do you really want to " BAlert* alert = new BAlert(B_TRANSLATE("Confirmation"),
"clear the browsing history?", "Clear", "Cancel"); B_TRANSLATE("Do you really want to "
"clear the browsing history?"), B_TRANSLATE("Clear"),
B_TRANSLATE("Cancel"));
if (alert->Go() == 0) if (alert->Go() == 0)
history->Clear(); history->Clear();
break; break;
@@ -715,11 +730,12 @@ BrowserWindow::MessageReceived(BMessage* message)
} }
message->RemoveName("refs"); message->RemoveName("refs");
if (addedCount > 10) { if (addedCount > 10) {
BString string; BString string(B_TRANSLATE_COMMENT("Do you want to open %addedCount "
string << "Do you want to open " << addedCount; "bookmarks all at once?", "Don't translate variable %addedCount."));
string << " bookmarks all at once?"; string.ReplaceFirst("%addedCount", BString() << addedCount);
BAlert* alert = new BAlert("Open bookmarks confirmation",
string.String(), "Cancel", "Open all"); BAlert* alert = new BAlert(B_TRANSLATE("Open bookmarks confirmation"),
string.String(), B_TRANSLATE("Cancel"), B_TRANSLATE("Open all"));
if (alert->Go() == 0) if (alert->Go() == 0)
break; break;
} }
@@ -1100,7 +1116,7 @@ BrowserWindow::CreateNewTab(const BString& _url, bool select, BWebView* webView)
bool isNewWindow = fTabManager->CountTabs() == 0; bool isNewWindow = fTabManager->CountTabs() == 0;
fTabManager->AddTab(webView, "New tab"); fTabManager->AddTab(webView, B_TRANSLATE("New tab"));
BString url(_url); BString url(_url);
if (applyNewPagePolicy && url.Length() == 0) if (applyNewPagePolicy && url.Length() == 0)
@@ -1185,7 +1201,7 @@ BrowserWindow::NewWindowRequested(const BString& url, bool primaryAction)
void void
BrowserWindow::NewPageCreated(BWebView* view, BRect windowFrame, BrowserWindow::NewPageCreated(BWebView* view, BRect windowFrame,
bool modalDialog, bool resizable, bool activate) bool modalDialog, bool resizable, bool activate)
{ {
if (windowFrame.IsValid()) { if (windowFrame.IsValid()) {
BrowserWindow* window = new BrowserWindow(windowFrame, fAppSettings, BrowserWindow* window = new BrowserWindow(windowFrame, fAppSettings,
@@ -1218,7 +1234,7 @@ BrowserWindow::LoadNegotiating(const BString& url, BWebView* view)
fURLInputGroup->SetText(url.String()); fURLInputGroup->SetText(url.String());
BString status("Requesting: "); BString status(B_TRANSLATE("Requesting: "));
status << url; status << url;
view->WebPage()->SetStatusMessage(status); view->WebPage()->SetStatusMessage(status);
} }
@@ -1233,7 +1249,7 @@ BrowserWindow::LoadCommitted(const BString& url, BWebView* view)
// This hook is invoked when the load is commited. // This hook is invoked when the load is commited.
fURLInputGroup->SetText(url.String()); fURLInputGroup->SetText(url.String());
BString status("Loading: "); BString status(B_TRANSLATE("Loading: "));
status << url; status << url;
view->WebPage()->SetStatusMessage(status); view->WebPage()->SetStatusMessage(status);
} }
@@ -1259,8 +1275,9 @@ BrowserWindow::LoadFailed(const BString& url, BWebView* view)
if (view != CurrentWebView()) if (view != CurrentWebView())
return; return;
BString status(url); BString status(B_TRANSLATE_COMMENT("%url failed.", "Loading URL failed. "
status << " failed."; "Don't translate variable %url."));
status.ReplaceFirst("%url", url);
view->WebPage()->SetStatusMessage(status); view->WebPage()->SetStatusMessage(status);
if (!fLoadingProgressBar->IsHidden()) if (!fLoadingProgressBar->IsHidden())
fLoadingProgressBar->Hide(); fLoadingProgressBar->Hide();
@@ -1273,8 +1290,9 @@ BrowserWindow::LoadFinished(const BString& url, BWebView* view)
if (view != CurrentWebView()) if (view != CurrentWebView())
return; return;
BString status(url); BString status(B_TRANSLATE_COMMENT("%url finished.", "Loading URL "
status << " finished."; "finished. Don't translate variable %url."));
status.ReplaceFirst("%url", url);
view->WebPage()->SetStatusMessage(status); view->WebPage()->SetStatusMessage(status);
if (!fLoadingProgressBar->IsHidden()) if (!fLoadingProgressBar->IsHidden())
fLoadingProgressBar->Hide(); fLoadingProgressBar->Hide();
@@ -1283,8 +1301,9 @@ BrowserWindow::LoadFinished(const BString& url, BWebView* view)
fForwardButton->IsEnabled(), false, view); fForwardButton->IsEnabled(), false, view);
int32 tabIndex = fTabManager->TabForView(view); int32 tabIndex = fTabManager->TabForView(view);
if (tabIndex > 0 && strcmp("New tab", fTabManager->TabLabel(tabIndex)) == 0) if (tabIndex > 0 && strcmp(B_TRANSLATE("New tab"),
fTabManager->SetTabLabel(tabIndex, url); fTabManager->TabLabel(tabIndex)) == 0)
fTabManager->SetTabLabel(tabIndex, url);
} }
@@ -1447,8 +1466,8 @@ BrowserWindow::UpdateGlobalHistory(const BString& url)
bool bool
BrowserWindow::AuthenticationChallenge(BString message, BString& inOutUser, BrowserWindow::AuthenticationChallenge(BString message, BString& inOutUser,
BString& inOutPassword, bool& inOutRememberCredentials, uint32 failureCount, BString& inOutPassword, bool& inOutRememberCredentials,
BWebView* view) uint32 failureCount, BWebView* view)
{ {
CredentialsStorage* persistentStorage CredentialsStorage* persistentStorage
= CredentialsStorage::PersistentInstance(); = CredentialsStorage::PersistentInstance();
@@ -1571,11 +1590,13 @@ BrowserWindow::_CreateBookmark()
BPath path; BPath path;
status_t status = _BookmarkPath(path); status_t status = _BookmarkPath(path);
if (status != B_OK) { if (status != B_OK) {
BString message("There was an error retrieving the bookmark " BString message(B_TRANSLATE_COMMENT("There was an error retrieving "
"folder.\n\n"); "the bookmark folder.\n\nError: %error", "Don't translate the "
message << "Error: " << strerror(status); "variable %error"));
BAlert* alert = new BAlert("Bookmark error", message.String(), "OK", message.ReplaceFirst("%error", strerror(status));
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); BAlert* alert = new BAlert(B_TRANSLATE("Bookmark error"),
message.String(), B_TRANSLATE("OK"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go(); alert->Go();
return; return;
} }
@@ -1599,10 +1620,12 @@ BrowserWindow::_CreateBookmark()
// URLs, only for matching file names. // URLs, only for matching file names.
BDirectory directory(path.Path()); BDirectory directory(path.Path());
if (status == B_OK && _CheckBookmarkExists(directory, bookmarkName, url)) { if (status == B_OK && _CheckBookmarkExists(directory, bookmarkName, url)) {
BString message("A bookmark for this page ("); BString message(B_TRANSLATE_COMMENT("A bookmark for this page "
message << bookmarkName; "(%bookmarkName) already exists.", "Don't translate variable "
message << ") already exists."; "%bookmarkName"));
BAlert* alert = new BAlert("Bookmark info", message.String(), "OK"); message.ReplaceFirst("%bookmarkName", bookmarkName);
BAlert* alert = new BAlert(B_TRANSLATE("Bookmark info"),
message.String(), B_TRANSLATE("OK"));
alert->Go(); alert->Go();
return; return;
} }
@@ -1690,11 +1713,13 @@ BrowserWindow::_CreateBookmark()
} }
if (status != B_OK) { if (status != B_OK) {
BString message("There was an error creating the bookmark " BString message(B_TRANSLATE_COMMENT("There was an error creating the "
"file.\n\n"); "bookmark file.\n\nError: %error", "Don't translate variable "
message << "Error: " << strerror(status); "%error"));
BAlert* alert = new BAlert("Bookmark error", message.String(), "OK", message.ReplaceFirst("%error", strerror(status));
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); BAlert* alert = new BAlert(B_TRANSLATE("Bookmark error"),
message.String(), B_TRANSLATE("OK"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go(); alert->Go();
return; return;
} }
@@ -1713,11 +1738,13 @@ BrowserWindow::_ShowBookmarks()
status = be_roster->Launch(&ref); status = be_roster->Launch(&ref);
if (status != B_OK && status != B_ALREADY_RUNNING) { if (status != B_OK && status != B_ALREADY_RUNNING) {
BString message("There was an error trying to show the Bookmarks " BString message(B_TRANSLATE_COMMENT("There was an error trying to "
"folder.\n\n"); "show the Bookmarks folder.\n\nError: %error", "Don't translate variable "
message << "Error: " << strerror(status); "%error"));
BAlert* alert = new BAlert("Bookmark error", message.String(), "OK", message.ReplaceFirst("%error", strerror(status));
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); BAlert* alert = new BAlert(B_TRANSLATE("Bookmark error"),
message.String(), B_TRANSLATE("OK"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->Go(); alert->Go();
return; return;
} }
@@ -1857,7 +1884,7 @@ BrowserWindow::_UpdateHistoryMenu()
return; return;
int32 count = history->CountItems(); int32 count = history->CountItems();
BMenuItem* clearHistoryItem = new BMenuItem("Clear history", BMenuItem* clearHistoryItem = new BMenuItem(B_TRANSLATE("Clear history"),
new BMessage(CLEAR_HISTORY)); new BMessage(CLEAR_HISTORY));
clearHistoryItem->SetEnabled(count > 0); clearHistoryItem->SetEnabled(count > 0);
fHistoryMenu->AddItem(clearHistoryItem); fHistoryMenu->AddItem(clearHistoryItem);
@@ -1885,8 +1912,8 @@ BrowserWindow::_UpdateHistoryMenu()
BDateTime fiveDaysAgoStart = fourDaysAgoStart; BDateTime fiveDaysAgoStart = fourDaysAgoStart;
fiveDaysAgoStart.Date().AddDays(-1); fiveDaysAgoStart.Date().AddDays(-1);
BMenu* todayMenu = new BMenu("Today"); BMenu* todayMenu = new BMenu(B_TRANSLATE("Today"));
BMenu* yesterdayMenu = new BMenu("Yesterday"); BMenu* yesterdayMenu = new BMenu(B_TRANSLATE("Yesterday"));
BMenu* twoDaysAgoMenu = new BMenu( BMenu* twoDaysAgoMenu = new BMenu(
twoDaysAgoStart.Date().LongDayName().String()); twoDaysAgoStart.Date().LongDayName().String());
BMenu* threeDaysAgoMenu = new BMenu( BMenu* threeDaysAgoMenu = new BMenu(
@@ -1895,7 +1922,7 @@ BrowserWindow::_UpdateHistoryMenu()
fourDaysAgoStart.Date().LongDayName().String()); fourDaysAgoStart.Date().LongDayName().String());
BMenu* fiveDaysAgoMenu = new BMenu( BMenu* fiveDaysAgoMenu = new BMenu(
fiveDaysAgoStart.Date().LongDayName().String()); fiveDaysAgoStart.Date().LongDayName().String());
BMenu* earlierMenu = new BMenu("Earlier"); BMenu* earlierMenu = new BMenu(B_TRANSLATE("Earlier"));
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
BrowsingHistoryItem historyItem = history->HistoryItemAt(i); BrowsingHistoryItem historyItem = history->HistoryItemAt(i);
@@ -2075,8 +2102,9 @@ void
BrowserWindow::_ShowProgressBar(bool show) BrowserWindow::_ShowProgressBar(bool show)
{ {
if (show) { if (show) {
if (!fStatusGroup->IsVisible() && (fVisibleInterfaceElements & INTERFACE_ELEMENT_STATUS) != 0) if (!fStatusGroup->IsVisible() && (fVisibleInterfaceElements
fStatusGroup->SetVisible(true); & INTERFACE_ELEMENT_STATUS) != 0)
fStatusGroup->SetVisible(true);
fLoadingProgressBar->Show(); fLoadingProgressBar->Show();
} else { } else {
if (!fInterfaceVisible) if (!fInterfaceVisible)
@@ -2207,7 +2235,8 @@ BrowserWindow::_HandlePageSourceResult(const BMessage* message)
char buffer[1024]; char buffer[1024];
snprintf(buffer, sizeof(buffer), "Failed to show the " snprintf(buffer, sizeof(buffer), "Failed to show the "
"page source: %s\n", strerror(ret)); "page source: %s\n", strerror(ret));
BAlert* alert = new BAlert("Page source error", buffer, "OK"); BAlert* alert = new BAlert(B_TRANSLATE("Page source error"), buffer,
B_TRANSLATE("OK"));
alert->Go(NULL); alert->Go(NULL);
} }
} }
+55 -36
View File
@@ -32,11 +32,13 @@
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <NodeMonitor.h> #include <NodeMonitor.h>
@@ -51,6 +53,9 @@
#include "StringForSize.h" #include "StringForSize.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Download Window"
enum { enum {
OPEN_DOWNLOAD = 'opdn', OPEN_DOWNLOAD = 'opdn',
RESTART_DOWNLOAD = 'rsdn', RESTART_DOWNLOAD = 'rsdn',
@@ -143,7 +148,8 @@ public:
virtual BSize MinSize() virtual BSize MinSize()
{ {
return BSize(fIconBitmap.Bounds().Width(), fIconBitmap.Bounds().Height()); return BSize(fIconBitmap.Bounds().Width(),
fIconBitmap.Bounds().Height());
} }
virtual BSize PreferredSize() virtual BSize PreferredSize()
@@ -218,8 +224,8 @@ DownloadProgressView::Init(BMessage* archive)
fLastSpeedReferenceSize = 0; fLastSpeedReferenceSize = 0;
fEstimatedFinishReferenceSize = 0; fEstimatedFinishReferenceSize = 0;
fProcessStartTime = fLastSpeedReferenceTime = fEstimatedFinishReferenceTime fProcessStartTime = fLastSpeedReferenceTime
= system_time(); = fEstimatedFinishReferenceTime = system_time();
SetViewColor(245, 245, 245); SetViewColor(245, 245, 245);
SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW); SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW);
@@ -245,16 +251,20 @@ DownloadProgressView::Init(BMessage* archive)
} else } else
fIconView = new IconView(); fIconView = new IconView();
if (!fDownload && (fStatusBar->CurrentValue() < 100 || !entry.Exists())) if (!fDownload && (fStatusBar->CurrentValue() < 100 || !entry.Exists())) {
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD)); fTopButton = new SmallButton(B_TRANSLATE("Restart"),
else { new BMessage(RESTART_DOWNLOAD));
fTopButton = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD)); } else {
fTopButton = new SmallButton(B_TRANSLATE("Open"),
new BMessage(OPEN_DOWNLOAD));
fTopButton->SetEnabled(fDownload == NULL); fTopButton->SetEnabled(fDownload == NULL);
} }
if (fDownload) if (fDownload) {
fBottomButton = new SmallButton("Cancel", new BMessage(CANCEL_DOWNLOAD)); fBottomButton = new SmallButton(B_TRANSLATE("Cancel"),
else { new BMessage(CANCEL_DOWNLOAD));
fBottomButton = new SmallButton("Remove", new BMessage(REMOVE_DOWNLOAD)); } else {
fBottomButton = new SmallButton(B_TRANSLATE("Remove"),
new BMessage(REMOVE_DOWNLOAD));
fBottomButton->SetEnabled(fDownload == NULL); fBottomButton->SetEnabled(fDownload == NULL);
} }
@@ -399,8 +409,9 @@ DownloadProgressView::MessageReceived(BMessage* message)
if (status == B_OK) if (status == B_OK)
status = be_roster->Launch(&ref); status = be_roster->Launch(&ref);
if (status != B_OK && status != B_ALREADY_RUNNING) { if (status != B_OK && status != B_ALREADY_RUNNING) {
BAlert* alert = new BAlert("Open download error", BAlert* alert = new BAlert(B_TRANSLATE("Open download error"),
"The download could not be opened.", "OK"); B_TRANSLATE("The download could not be opened."),
B_TRANSLATE("OK"));
alert->Go(NULL); alert->Go(NULL);
} }
break; break;
@@ -572,11 +583,11 @@ DownloadProgressView::ShowContextMenu(BPoint screenWhere)
screenWhere += BPoint(2, 2); screenWhere += BPoint(2, 2);
BPopUpMenu* contextMenu = new BPopUpMenu("download context"); BPopUpMenu* contextMenu = new BPopUpMenu("download context");
BMenuItem* copyURL = new BMenuItem("Copy URL to clipboard", BMenuItem* copyURL = new BMenuItem(B_TRANSLATE("Copy URL to clipboard"),
new BMessage(COPY_URL_TO_CLIPBOARD)); new BMessage(COPY_URL_TO_CLIPBOARD));
copyURL->SetEnabled(fURL.Length() > 0); copyURL->SetEnabled(fURL.Length() > 0);
contextMenu->AddItem(copyURL); contextMenu->AddItem(copyURL);
BMenuItem* openFolder = new BMenuItem("Open containing folder", BMenuItem* openFolder = new BMenuItem(B_TRANSLATE("Open containing folder"),
new BMessage(OPEN_CONTAINING_FOLDER)); new BMessage(OPEN_CONTAINING_FOLDER));
contextMenu->AddItem(openFolder); contextMenu->AddItem(openFolder);
@@ -622,7 +633,7 @@ DownloadProgressView::DownloadFinished()
fExpectedSize = fCurrentSize; fExpectedSize = fCurrentSize;
} }
fTopButton->SetEnabled(true); fTopButton->SetEnabled(true);
fBottomButton->SetLabel("Remove"); fBottomButton->SetLabel(B_TRANSLATE("Remove"));
fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD)); fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD));
fBottomButton->SetEnabled(true); fBottomButton->SetEnabled(true);
fInfoView->SetText(""); fInfoView->SetText("");
@@ -633,10 +644,10 @@ void
DownloadProgressView::DownloadCanceled() DownloadProgressView::DownloadCanceled()
{ {
fDownload = NULL; fDownload = NULL;
fTopButton->SetLabel("Restart"); fTopButton->SetLabel(B_TRANSLATE("Restart"));
fTopButton->SetMessage(new BMessage(RESTART_DOWNLOAD)); fTopButton->SetMessage(new BMessage(RESTART_DOWNLOAD));
fTopButton->SetEnabled(true); fTopButton->SetEnabled(true);
fBottomButton->SetLabel("Remove"); fBottomButton->SetLabel(B_TRANSLATE("Remove"));
fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD)); fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD));
fBottomButton->SetEnabled(true); fBottomButton->SetEnabled(true);
fInfoView->SetText(""); fInfoView->SetText("");
@@ -726,12 +737,14 @@ DownloadProgressView::_UpdateStatusText()
currentSize.Truncate(currentSizeUnitPos); currentSize.Truncate(currentSizeUnitPos);
} }
buffer << currentSize; buffer << currentSize;
buffer << " of "; buffer << " ";
buffer << B_TRANSLATE_COMMENT("of", "...as in '12kB of 256kB'");
buffer << " ";
buffer << expectedSize; buffer << expectedSize;
buffer << ", "; buffer << ", ";
buffer << string_for_size(fBytesPerSecond, sizeBuffer, buffer << string_for_size(fBytesPerSecond, sizeBuffer,
sizeof(sizeBuffer)); sizeof(sizeBuffer));
buffer << "/s)"; buffer << B_TRANSLATE_COMMENT("/s)", "...as in 'per second'");
float stringWidth = fInfoView->StringWidth(buffer.String()); float stringWidth = fInfoView->StringWidth(buffer.String());
if (stringWidth < fInfoView->Bounds().Width()) if (stringWidth < fInfoView->Bounds().Width())
fInfoView->SetText(buffer.String()); fInfoView->SetText(buffer.String());
@@ -739,7 +752,7 @@ DownloadProgressView::_UpdateStatusText()
// complete string too wide, try with shorter version // complete string too wide, try with shorter version
buffer << string_for_size(fBytesPerSecond, sizeBuffer, buffer << string_for_size(fBytesPerSecond, sizeBuffer,
sizeof(sizeBuffer)); sizeof(sizeBuffer));
buffer << "/s"; buffer << B_TRANSLATE_COMMENT("/s)", "...as in 'per second'");
stringWidth = fInfoView->StringWidth(buffer.String()); stringWidth = fInfoView->StringWidth(buffer.String());
if (stringWidth < fInfoView->Bounds().Width()) if (stringWidth < fInfoView->Bounds().Width())
fInfoView->SetText(buffer.String()); fInfoView->SetText(buffer.String());
@@ -770,7 +783,7 @@ DownloadProgressView::_UpdateStatusText()
2, time->tm_hour, 2, time->tm_min); 2, time->tm_hour, 2, time->tm_min);
} }
BString buffer1("Finish: "); BString buffer1(B_TRANSLATE_COMMENT("Finish: ", "Finishing time"));
buffer1 << timeText; buffer1 << timeText;
finishTime -= now; finishTime -= now;
time = gmtime(&finishTime); time = gmtime(&finishTime);
@@ -779,30 +792,36 @@ DownloadProgressView::_UpdateStatusText()
if (finishTime > secondsPerDay) { if (finishTime > secondsPerDay) {
int64 days = finishTime / secondsPerDay; int64 days = finishTime / secondsPerDay;
if (days == 1) if (days == 1)
buffer2 << "Over 1 day"; buffer2 << B_TRANSLATE("Over 1 day left");
else else {
buffer2 << "Over " << days << " days"; buffer2 << B_TRANSLATE("Over %days days left");
buffer2.ReplaceFirst("%days", BString() << days);
}
} else if (finishTime > 60 * 60) { } else if (finishTime > 60 * 60) {
int64 hours = finishTime / (60 * 60); int64 hours = finishTime / (60 * 60);
if (hours == 1) if (hours == 1)
buffer2 << "Over 1 hour"; buffer2 << B_TRANSLATE("Over 1 hour left");
else else {
buffer2 << "Over " << hours << " hours"; buffer2 << B_TRANSLATE("Over %hours hours left");
buffer2.ReplaceFirst("%hours", BString() << hours);
}
} else if (finishTime > 60) { } else if (finishTime > 60) {
int64 minutes = finishTime / 60; int64 minutes = finishTime / 60;
if (minutes == 1) if (minutes == 1)
buffer2 << "Over 1 minute"; buffer2 << B_TRANSLATE("Over 1 minute left");
else else {
buffer2 << minutes << " minutes"; buffer2 << B_TRANSLATE("%minutes minutes");
buffer2.ReplaceFirst("%minutes", BString() << minutes);
}
} else { } else {
if (finishTime == 1) if (finishTime == 1)
buffer2 << "1 second"; buffer2 << B_TRANSLATE("1 second left");
else else {
buffer2 << finishTime << " seconds"; buffer2 << B_TRANSLATE("%seconds seconds left");
buffer2.ReplaceFirst("%seconds", BString() << finishTime);
}
} }
buffer2 << " left";
buffer = "("; buffer = "(";
buffer << buffer1 << " - " << buffer2 << ")"; buffer << buffer1 << " - " << buffer2 << ")";
+23 -15
View File
@@ -31,12 +31,14 @@
#include <Alert.h> #include <Alert.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Path.h> #include <Path.h>
@@ -54,6 +56,9 @@
#include "WebPage.h" #include "WebPage.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Download Window"
enum { enum {
INIT = 'init', INIT = 'init',
OPEN_DOWNLOADS_FOLDER = 'odnf', OPEN_DOWNLOADS_FOLDER = 'odnf',
@@ -134,7 +139,7 @@ protected:
DownloadWindow::DownloadWindow(BRect frame, bool visible, DownloadWindow::DownloadWindow(BRect frame, bool visible,
SettingsMessage* settings) SettingsMessage* settings)
: BWindow(frame, "Downloads", : BWindow(frame, B_TRANSLATE("Downloads"),
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE), B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE),
fMinimizeOnClose(false) fMinimizeOnClose(false)
@@ -155,26 +160,27 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible,
fDownloadViewsLayout = downloadsGroupView->GroupLayout(); fDownloadViewsLayout = downloadsGroupView->GroupLayout();
BMenuBar* menuBar = new BMenuBar("Menu bar"); BMenuBar* menuBar = new BMenuBar("Menu bar");
BMenu* menu = new BMenu("Downloads"); BMenu* menu = new BMenu(B_TRANSLATE("Downloads"));
menu->AddItem(new BMenuItem("Open downloads folder", menu->AddItem(new BMenuItem(B_TRANSLATE("Open downloads folder"),
new BMessage(OPEN_DOWNLOADS_FOLDER))); new BMessage(OPEN_DOWNLOADS_FOLDER)));
BMessage* newWindowMessage = new BMessage(NEW_WINDOW); BMessage* newWindowMessage = new BMessage(NEW_WINDOW);
newWindowMessage->AddString("url", ""); newWindowMessage->AddString("url", "");
BMenuItem* newWindowItem = new BMenuItem("New browser window", BMenuItem* newWindowItem = new BMenuItem(B_TRANSLATE("New browser window"),
newWindowMessage, 'N'); newWindowMessage, 'N');
menu->AddItem(newWindowItem); menu->AddItem(newWindowItem);
newWindowItem->SetTarget(be_app); newWindowItem->SetTarget(be_app);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Hide", new BMessage(B_QUIT_REQUESTED), 'D')); menu->AddItem(new BMenuItem(B_TRANSLATE("Hide"),
new BMessage(B_QUIT_REQUESTED), 'D'));
menuBar->AddItem(menu); menuBar->AddItem(menu);
fDownloadsScrollView = new DownloadContainerScrollView(downloadsGroupView); fDownloadsScrollView = new DownloadContainerScrollView(downloadsGroupView);
fRemoveFinishedButton = new BButton("Remove finished", fRemoveFinishedButton = new BButton(B_TRANSLATE("Remove finished"),
new BMessage(REMOVE_FINISHED_DOWNLOADS)); new BMessage(REMOVE_FINISHED_DOWNLOADS));
fRemoveFinishedButton->SetEnabled(false); fRemoveFinishedButton->SetEnabled(false);
fRemoveMissingButton = new BButton("Remove missing", fRemoveMissingButton = new BButton(B_TRANSLATE("Remove missing"),
new BMessage(REMOVE_MISSING_DOWNLOADS)); new BMessage(REMOVE_MISSING_DOWNLOADS));
fRemoveMissingButton->SetEnabled(false); fRemoveMissingButton->SetEnabled(false);
@@ -274,11 +280,12 @@ DownloadWindow::MessageReceived(BMessage* message)
if (status == B_OK) if (status == B_OK)
status = be_roster->Launch(&ref); status = be_roster->Launch(&ref);
if (status != B_OK && status != B_ALREADY_RUNNING) { if (status != B_OK && status != B_ALREADY_RUNNING) {
BString errorString("The downloads folder could not be " BString errorString(B_TRANSLATE_COMMENT("The downloads folder could "
"opened.\n\n"); "not be opened.\n\nError: %error", "Don't translate "
errorString << "Error: " << strerror(status); "variable %error"));
BAlert* alert = new BAlert("Error opening downloads folder", errorString.ReplaceFirst("%error", strerror(status));
errorString.String(), "OK"); BAlert* alert = new BAlert(B_TRANSLATE("Error opening downloads "
"folder"), errorString.String(), B_TRANSLATE("OK"));
alert->Go(NULL); alert->Go(NULL);
} }
break; break;
@@ -528,9 +535,10 @@ DownloadWindow::_SaveSettings()
item->View()); item->View());
if (!view) if (!view)
continue; continue;
BMessage downloadArchive;
if (view->SaveSettings(&downloadArchive) == B_OK) BMessage downloadArchive;
message.AddMessage("download", &downloadArchive); if (view->SaveSettings(&downloadArchive) == B_OK)
message.AddMessage("download", &downloadArchive);
} }
message.Flatten(&file); message.Flatten(&file);
} }
+16 -6
View File
@@ -7,10 +7,12 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
@@ -28,6 +30,10 @@
#include "TextViewCompleter.h" #include "TextViewCompleter.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "URL Bar"
class URLChoice : public BAutoCompleter::Choice { class URLChoice : public BAutoCompleter::Choice {
public: public:
URLChoice(const BString& choiceText, const BString& displayText, URLChoice(const BString& choiceText, const BString& displayText,
@@ -235,10 +241,14 @@ URLInputGroup::URLTextView::MouseDown(BPoint where)
be_clipboard->Unlock(); be_clipboard->Unlock();
} }
BMenuItem* cutItem = new BMenuItem("Cut", new BMessage(B_CUT)); BMenuItem* cutItem = new BMenuItem(B_TRANSLATE("Cut"),
BMenuItem* copyItem = new BMenuItem("Copy", new BMessage(B_COPY)); new BMessage(B_CUT));
BMenuItem* pasteItem = new BMenuItem("Paste", new BMessage(B_PASTE)); BMenuItem* copyItem = new BMenuItem(B_TRANSLATE("Copy"),
BMenuItem* clearItem = new BMenuItem("Clear", new BMessage(MSG_CLEAR)); new BMessage(B_COPY));
BMenuItem* pasteItem = new BMenuItem(B_TRANSLATE("Paste"),
new BMessage(B_PASTE));
BMenuItem* clearItem = new BMenuItem(B_TRANSLATE("Clear"),
new BMessage(MSG_CLEAR));
cutItem->SetEnabled(canCutOrCopy); cutItem->SetEnabled(canCutOrCopy);
copyItem->SetEnabled(canCutOrCopy); copyItem->SetEnabled(canCutOrCopy);
pasteItem->SetEnabled(canPaste); pasteItem->SetEnabled(canPaste);
@@ -362,8 +372,8 @@ URLInputGroup::URLTextView::InsertText(const char* inText, int32 inLength,
baseUrlEnd = TextLength(); baseUrlEnd = TextLength();
BFont font; BFont font;
GetFont(&font); GetFont(&font);
const rgb_color black = (rgb_color){ 0, 0, 0, 255 }; const rgb_color black = (rgb_color) { 0, 0, 0, 255 };
const rgb_color gray = (rgb_color){ 60, 60, 60, 255 }; const rgb_color gray = (rgb_color) { 60, 60, 60, 255 };
if (baseUrlStart > 0) if (baseUrlStart > 0)
SetFontAndColor(0, baseUrlStart - 1, &font, B_FONT_ALL, &gray); SetFontAndColor(0, baseUrlStart - 1, &font, B_FONT_ALL, &gray);
if (baseUrlEnd > baseUrlStart) { if (baseUrlEnd > baseUrlStart) {