|
|
@@ -3,6 +3,7 @@
|
|
|
|
* Copyright (C) 2007 Ryan Leavengood <[email protected]>
|
|
|
|
* Copyright (C) 2007 Ryan Leavengood <[email protected]>
|
|
|
|
* Copyright (C) 2009 Maxime Simon <[email protected]>
|
|
|
|
* Copyright (C) 2009 Maxime Simon <[email protected]>
|
|
|
|
* Copyright (C) 2010 Stephan Aßmus <[email protected]>
|
|
|
|
* Copyright (C) 2010 Stephan Aßmus <[email protected]>
|
|
|
|
|
|
|
|
* Copyright (C) 2010 Michael Lotz <[email protected]>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
@@ -57,9 +58,9 @@ enum {
|
|
|
|
GOTO_URL = 'goul',
|
|
|
|
GOTO_URL = 'goul',
|
|
|
|
RELOAD = 'reld',
|
|
|
|
RELOAD = 'reld',
|
|
|
|
|
|
|
|
|
|
|
|
TEXT_SIZE_INCREASE = 'tsin',
|
|
|
|
TEXT_SIZE_INCREASE = 'tsin',
|
|
|
|
TEXT_SIZE_DECREASE = 'tsdc',
|
|
|
|
TEXT_SIZE_DECREASE = 'tsdc',
|
|
|
|
TEXT_SIZE_RESET = 'tsrs',
|
|
|
|
TEXT_SIZE_RESET = 'tsrs',
|
|
|
|
|
|
|
|
|
|
|
|
TEXT_SHOW_FIND_GROUP = 'sfnd',
|
|
|
|
TEXT_SHOW_FIND_GROUP = 'sfnd',
|
|
|
|
TEXT_HIDE_FIND_GROUP = 'hfnd',
|
|
|
|
TEXT_HIDE_FIND_GROUP = 'hfnd',
|
|
|
@@ -73,9 +74,9 @@ using namespace WebCore;
|
|
|
|
|
|
|
|
|
|
|
|
static BLayoutItem* layoutItemFor(BView* view)
|
|
|
|
static BLayoutItem* layoutItemFor(BView* view)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BLayout* layout = view->Parent()->GetLayout();
|
|
|
|
BLayout* layout = view->Parent()->GetLayout();
|
|
|
|
int32 index = layout->IndexOfView(view);
|
|
|
|
int32 index = layout->IndexOfView(view);
|
|
|
|
return layout->ItemAt(index);
|
|
|
|
return layout->ItemAt(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
|
LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
@@ -85,30 +86,30 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
|
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS)
|
|
|
|
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (toolbarPolicy == HaveToolbar) {
|
|
|
|
if (toolbarPolicy == HaveToolbar) {
|
|
|
|
// Menu
|
|
|
|
// Menu
|
|
|
|
m_menuBar = new BMenuBar("Main menu");
|
|
|
|
m_menuBar = new BMenuBar("Main menu");
|
|
|
|
BMenu* menu = new BMenu("Window");
|
|
|
|
BMenu* menu = new BMenu("Window");
|
|
|
|
BMessage* newWindowMessage = new BMessage(NEW_WINDOW);
|
|
|
|
BMessage* newWindowMessage = new BMessage(NEW_WINDOW);
|
|
|
|
newWindowMessage->AddString("url", "");
|
|
|
|
newWindowMessage->AddString("url", "");
|
|
|
|
BMenuItem* newItem = new BMenuItem("New", newWindowMessage, 'N');
|
|
|
|
BMenuItem* newItem = new BMenuItem("New", newWindowMessage, 'N');
|
|
|
|
menu->AddItem(newItem);
|
|
|
|
menu->AddItem(newItem);
|
|
|
|
newItem->SetTarget(be_app);
|
|
|
|
newItem->SetTarget(be_app);
|
|
|
|
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
|
|
|
|
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
menu->AddItem(new BMenuItem("Show Downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
|
|
|
|
menu->AddItem(new BMenuItem("Show Downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q');
|
|
|
|
BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q');
|
|
|
|
menu->AddItem(quitItem);
|
|
|
|
menu->AddItem(quitItem);
|
|
|
|
quitItem->SetTarget(be_app);
|
|
|
|
quitItem->SetTarget(be_app);
|
|
|
|
m_menuBar->AddItem(menu);
|
|
|
|
m_menuBar->AddItem(menu);
|
|
|
|
|
|
|
|
|
|
|
|
menu = new BMenu("Text");
|
|
|
|
menu = new BMenu("Text");
|
|
|
|
menu->AddItem(new BMenuItem("Find", new BMessage(TEXT_SHOW_FIND_GROUP), 'F'));
|
|
|
|
menu->AddItem(new BMenuItem("Find", new BMessage(TEXT_SHOW_FIND_GROUP), 'F'));
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
menu->AddItem(new BMenuItem("Increase size", new BMessage(TEXT_SIZE_INCREASE), '+'));
|
|
|
|
menu->AddItem(new BMenuItem("Increase size", new BMessage(TEXT_SIZE_INCREASE), '+'));
|
|
|
|
menu->AddItem(new BMenuItem("Decrease size", new BMessage(TEXT_SIZE_DECREASE), '-'));
|
|
|
|
menu->AddItem(new BMenuItem("Decrease size", new BMessage(TEXT_SIZE_DECREASE), '-'));
|
|
|
|
menu->AddItem(new BMenuItem("Reset size", new BMessage(TEXT_SIZE_RESET), '0'));
|
|
|
|
menu->AddItem(new BMenuItem("Reset size", new BMessage(TEXT_SIZE_RESET), '0'));
|
|
|
|
m_menuBar->AddItem(menu);
|
|
|
|
m_menuBar->AddItem(menu);
|
|
|
|
|
|
|
|
|
|
|
|
// Back & Forward
|
|
|
|
// Back & Forward
|
|
|
|
m_BackButton = new BButton("", "Back", new BMessage(GO_BACK));
|
|
|
|
m_BackButton = new BButton("", "Back", new BMessage(GO_BACK));
|
|
|
@@ -126,16 +127,16 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
|
m_statusText->SetAlignment(B_ALIGN_LEFT);
|
|
|
|
m_statusText->SetAlignment(B_ALIGN_LEFT);
|
|
|
|
m_statusText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
|
|
|
m_statusText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
|
|
|
m_statusText->SetExplicitMinSize(BSize(150, 16));
|
|
|
|
m_statusText->SetExplicitMinSize(BSize(150, 16));
|
|
|
|
// Prevent the window from growing to fit a long status message...
|
|
|
|
// Prevent the window from growing to fit a long status message...
|
|
|
|
BFont font(be_plain_font);
|
|
|
|
BFont font(be_plain_font);
|
|
|
|
font.SetSize(ceilf(font.Size() * 0.8));
|
|
|
|
font.SetSize(ceilf(font.Size() * 0.8));
|
|
|
|
m_statusText->SetFont(&font, B_FONT_SIZE);
|
|
|
|
m_statusText->SetFont(&font, B_FONT_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
// Loading progress bar
|
|
|
|
// Loading progress bar
|
|
|
|
m_loadingProgressBar = new BStatusBar("progress");
|
|
|
|
m_loadingProgressBar = new BStatusBar("progress");
|
|
|
|
m_loadingProgressBar->SetMaxValue(100);
|
|
|
|
m_loadingProgressBar->SetMaxValue(100);
|
|
|
|
m_loadingProgressBar->Hide();
|
|
|
|
m_loadingProgressBar->Hide();
|
|
|
|
m_loadingProgressBar->SetBarHeight(10);
|
|
|
|
m_loadingProgressBar->SetBarHeight(10);
|
|
|
|
|
|
|
|
|
|
|
|
const float kInsetSpacing = 5;
|
|
|
|
const float kInsetSpacing = 5;
|
|
|
|
const float kElementSpacing = 7;
|
|
|
|
const float kElementSpacing = 7;
|
|
|
@@ -158,7 +159,7 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
|
;
|
|
|
|
;
|
|
|
|
// Layout
|
|
|
|
// Layout
|
|
|
|
AddChild(BGroupLayoutBuilder(B_VERTICAL)
|
|
|
|
AddChild(BGroupLayoutBuilder(B_VERTICAL)
|
|
|
|
.Add(m_menuBar)
|
|
|
|
.Add(m_menuBar)
|
|
|
|
.Add(BGridLayoutBuilder(kElementSpacing, kElementSpacing)
|
|
|
|
.Add(BGridLayoutBuilder(kElementSpacing, kElementSpacing)
|
|
|
|
.Add(m_BackButton, 0, 0)
|
|
|
|
.Add(m_BackButton, 0, 0)
|
|
|
|
.Add(m_ForwardButton, 1, 0)
|
|
|
|
.Add(m_ForwardButton, 1, 0)
|
|
|
@@ -181,8 +182,8 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
|
|
|
|
|
|
|
|
|
m_findGroup = layoutItemFor(findGroup);
|
|
|
|
m_findGroup = layoutItemFor(findGroup);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
m_BackButton = 0;
|
|
|
|
m_BackButton = 0;
|
|
|
|
m_ForwardButton = 0;
|
|
|
|
m_ForwardButton = 0;
|
|
|
|
m_url = 0;
|
|
|
|
m_url = 0;
|
|
|
|
m_menuBar = 0;
|
|
|
|
m_menuBar = 0;
|
|
|
|
m_statusText = 0;
|
|
|
|
m_statusText = 0;
|
|
|
@@ -205,7 +206,7 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
|
|
|
|
|
|
|
|
|
|
|
|
navigationCapabilitiesChanged(false, false, false);
|
|
|
|
navigationCapabilitiesChanged(false, false, false);
|
|
|
|
|
|
|
|
|
|
|
|
be_app->PostMessage(WINDOW_OPENED);
|
|
|
|
be_app->PostMessage(WINDOW_OPENED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LauncherWindow::~LauncherWindow()
|
|
|
|
LauncherWindow::~LauncherWindow()
|
|
|
@@ -262,23 +263,6 @@ void LauncherWindow::MessageReceived(BMessage* message)
|
|
|
|
be_app->PostMessage(message);
|
|
|
|
be_app->PostMessage(message);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TEST_AUTHENTICATION_PANEL: {
|
|
|
|
|
|
|
|
BString realm("Realm");
|
|
|
|
|
|
|
|
BString method("Method");
|
|
|
|
|
|
|
|
BString previousUser;
|
|
|
|
|
|
|
|
BString previousPass;
|
|
|
|
|
|
|
|
bool rememberCredentials = false;
|
|
|
|
|
|
|
|
bool badPassword = true;
|
|
|
|
|
|
|
|
BString user;
|
|
|
|
|
|
|
|
BString pass;
|
|
|
|
|
|
|
|
AuthenticationPanel* panel = new AuthenticationPanel(Frame());
|
|
|
|
|
|
|
|
bool success = panel->getAuthentication(realm, method, previousUser,
|
|
|
|
|
|
|
|
previousPass, rememberCredentials, badPassword, user, pass,
|
|
|
|
|
|
|
|
&rememberCredentials);
|
|
|
|
|
|
|
|
printf("success: %d\n", success);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
WebViewWindow::MessageReceived(message);
|
|
|
|
WebViewWindow::MessageReceived(message);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@@ -288,8 +272,8 @@ void LauncherWindow::MessageReceived(BMessage* message)
|
|
|
|
bool LauncherWindow::QuitRequested()
|
|
|
|
bool LauncherWindow::QuitRequested()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (WebViewWindow::QuitRequested()) {
|
|
|
|
if (WebViewWindow::QuitRequested()) {
|
|
|
|
BMessage message(WINDOW_CLOSED);
|
|
|
|
BMessage message(WINDOW_CLOSED);
|
|
|
|
message.AddRect("window frame", Frame());
|
|
|
|
message.AddRect("window frame", Frame());
|
|
|
|
be_app->PostMessage(&message);
|
|
|
|
be_app->PostMessage(&message);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -300,86 +284,113 @@ bool LauncherWindow::QuitRequested()
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::navigationRequested(const BString& url)
|
|
|
|
void LauncherWindow::navigationRequested(const BString& url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_loadedURL = url;
|
|
|
|
m_loadedURL = url;
|
|
|
|
if (m_url)
|
|
|
|
if (m_url)
|
|
|
|
m_url->SetText(url.String());
|
|
|
|
m_url->SetText(url.String());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::newWindowRequested(const BString& url)
|
|
|
|
void LauncherWindow::newWindowRequested(const BString& url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Always open new windows in the application thread, since
|
|
|
|
// Always open new windows in the application thread, since
|
|
|
|
// creating a WebView will try to grab the application lock.
|
|
|
|
// creating a WebView will try to grab the application lock.
|
|
|
|
// But our own WebProcess may already try to lock us from within
|
|
|
|
// But our own WebProcess may already try to lock us from within
|
|
|
|
// the application thread -> dead-lock.
|
|
|
|
// the application thread -> dead-lock.
|
|
|
|
BMessage message(NEW_WINDOW);
|
|
|
|
BMessage message(NEW_WINDOW);
|
|
|
|
message.AddString("url", url);
|
|
|
|
message.AddString("url", url);
|
|
|
|
be_app->PostMessage(&message);
|
|
|
|
be_app->PostMessage(&message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::loadNegociating(const BString& url)
|
|
|
|
void LauncherWindow::loadNegociating(const BString& url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BString status("Requesting: ");
|
|
|
|
BString status("Requesting: ");
|
|
|
|
status << url;
|
|
|
|
status << url;
|
|
|
|
statusChanged(status);
|
|
|
|
statusChanged(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::loadTransfering(const BString& url)
|
|
|
|
void LauncherWindow::loadTransfering(const BString& url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BString status("Loading: ");
|
|
|
|
BString status("Loading: ");
|
|
|
|
status << url;
|
|
|
|
status << url;
|
|
|
|
statusChanged(status);
|
|
|
|
statusChanged(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::loadProgress(float progress)
|
|
|
|
void LauncherWindow::loadProgress(float progress)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_loadingProgressBar) {
|
|
|
|
if (m_loadingProgressBar) {
|
|
|
|
if (progress < 100 && m_loadingProgressBar->IsHidden())
|
|
|
|
if (progress < 100 && m_loadingProgressBar->IsHidden())
|
|
|
|
m_loadingProgressBar->Show();
|
|
|
|
m_loadingProgressBar->Show();
|
|
|
|
m_loadingProgressBar->SetTo(progress);
|
|
|
|
m_loadingProgressBar->SetTo(progress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::loadFailed(const BString& url)
|
|
|
|
void LauncherWindow::loadFailed(const BString& url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BString status(url);
|
|
|
|
BString status(url);
|
|
|
|
status << " failed.";
|
|
|
|
status << " failed.";
|
|
|
|
statusChanged(status);
|
|
|
|
statusChanged(status);
|
|
|
|
if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden())
|
|
|
|
if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden())
|
|
|
|
m_loadingProgressBar->Hide();
|
|
|
|
m_loadingProgressBar->Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::loadFinished(const BString& url)
|
|
|
|
void LauncherWindow::loadFinished(const BString& url)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_loadedURL = url;
|
|
|
|
m_loadedURL = url;
|
|
|
|
BString status(url);
|
|
|
|
BString status(url);
|
|
|
|
status << " finished.";
|
|
|
|
status << " finished.";
|
|
|
|
statusChanged(status);
|
|
|
|
statusChanged(status);
|
|
|
|
if (m_url)
|
|
|
|
if (m_url)
|
|
|
|
m_url->SetText(url.String());
|
|
|
|
m_url->SetText(url.String());
|
|
|
|
if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden())
|
|
|
|
if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden())
|
|
|
|
m_loadingProgressBar->Hide();
|
|
|
|
m_loadingProgressBar->Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::titleChanged(const BString& title)
|
|
|
|
void LauncherWindow::titleChanged(const BString& title)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BString windowTitle = title;
|
|
|
|
BString windowTitle = title;
|
|
|
|
if (windowTitle.Length() > 0)
|
|
|
|
if (windowTitle.Length() > 0)
|
|
|
|
windowTitle << " - ";
|
|
|
|
windowTitle << " - ";
|
|
|
|
windowTitle << "HaikuLauncher";
|
|
|
|
windowTitle << "HaikuLauncher";
|
|
|
|
SetTitle(windowTitle.String());
|
|
|
|
SetTitle(windowTitle.String());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::statusChanged(const BString& statusText)
|
|
|
|
void LauncherWindow::statusChanged(const BString& statusText)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_statusText)
|
|
|
|
if (m_statusText)
|
|
|
|
m_statusText->SetText(statusText.String());
|
|
|
|
m_statusText->SetText(statusText.String());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::navigationCapabilitiesChanged(bool canGoBackward,
|
|
|
|
void LauncherWindow::navigationCapabilitiesChanged(bool canGoBackward,
|
|
|
|
bool canGoForward, bool canStop)
|
|
|
|
bool canGoForward, bool canStop)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (m_BackButton)
|
|
|
|
if (m_BackButton)
|
|
|
|
m_BackButton->SetEnabled(canGoBackward);
|
|
|
|
m_BackButton->SetEnabled(canGoBackward);
|
|
|
|
if (m_ForwardButton)
|
|
|
|
if (m_ForwardButton)
|
|
|
|
m_ForwardButton->SetEnabled(canGoForward);
|
|
|
|
m_ForwardButton->SetEnabled(canGoForward);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LauncherWindow::authenticationChallenge(BMessage* message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BString text;
|
|
|
|
|
|
|
|
bool rememberCredentials = false;
|
|
|
|
|
|
|
|
uint32 failureCount = 0;
|
|
|
|
|
|
|
|
BString user;
|
|
|
|
|
|
|
|
BString password;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message->FindString("text", &text);
|
|
|
|
|
|
|
|
message->FindString("user", &user);
|
|
|
|
|
|
|
|
message->FindString("password", &password);
|
|
|
|
|
|
|
|
message->FindUInt32("failureCount", &failureCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AuthenticationPanel* panel = new AuthenticationPanel(Frame());
|
|
|
|
|
|
|
|
if (!panel->getAuthentication(text, user, password, rememberCredentials,
|
|
|
|
|
|
|
|
failureCount > 0, user, password, &rememberCredentials)) {
|
|
|
|
|
|
|
|
message->SendReply((uint32)0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BMessage reply;
|
|
|
|
|
|
|
|
reply.AddString("user", user);
|
|
|
|
|
|
|
|
reply.AddString("password", password);
|
|
|
|
|
|
|
|
reply.AddBool("rememberCredentials", rememberCredentials);
|
|
|
|
|
|
|
|
message->SendReply(&reply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|