2 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
4 * All rights reserved. Distributed under the terms of the MIT License.
6 #include "SettingsWindow.h"
10 #include <ControlLook.h>
11 #include <GridLayoutBuilder.h>
12 #include <GroupLayout.h>
13 #include <GroupLayoutBuilder.h>
14 #include <LayoutBuilder.h>
17 #include <MenuField.h>
19 #include <PopUpMenu.h>
20 #include <ScrollView.h>
21 #include <SeparatorView.h>
22 #include <SpaceLayoutItem.h>
25 #include <TextControl.h>
31 #include "BrowserApp.h"
32 #include "BrowsingHistory.h"
33 #include "BrowserWindow.h"
34 #include "FontSelectionView.h"
35 #include "SettingsKeys.h"
36 #include "SettingsMessage.h"
37 #include "WebSettings.h"
40 #undef B_TRANSLATION_CONTEXT
41 #define B_TRANSLATION_CONTEXT "Settings Window"
48 MSG_START_PAGE_CHANGED
= 'hpch',
49 MSG_SEARCH_PAGE_CHANGED
= 'spch',
50 MSG_DOWNLOAD_FOLDER_CHANGED
= 'dnfc',
51 MSG_NEW_WINDOWS_BEHAVIOR_CHANGED
= 'nwbc',
52 MSG_NEW_TABS_BEHAVIOR_CHANGED
= 'ntbc',
53 MSG_HISTORY_MENU_DAYS_CHANGED
= 'digm',
54 MSG_TAB_DISPLAY_BEHAVIOR_CHANGED
= 'tdbc',
55 MSG_AUTO_HIDE_INTERFACE_BEHAVIOR_CHANGED
= 'ahic',
56 MSG_AUTO_HIDE_POINTER_BEHAVIOR_CHANGED
= 'ahpc',
57 MSG_SHOW_HOME_BUTTON_CHANGED
= 'shbc',
59 MSG_STANDARD_FONT_CHANGED
= 'stfc',
60 MSG_SERIF_FONT_CHANGED
= 'sefc',
61 MSG_SANS_SERIF_FONT_CHANGED
= 'ssfc',
62 MSG_FIXED_FONT_CHANGED
= 'ffch',
64 MSG_STANDARD_FONT_SIZE_SELECTED
= 'sfss',
65 MSG_FIXED_FONT_SIZE_SELECTED
= 'ffss',
67 MSG_USE_PROXY_CHANGED
= 'upsc',
68 MSG_PROXY_ADDRESS_CHANGED
= 'psac',
69 MSG_PROXY_PORT_CHANGED
= 'pspc',
70 MSG_USE_PROXY_AUTH_CHANGED
= 'upsa',
71 MSG_PROXY_USERNAME_CHANGED
= 'psuc',
72 MSG_PROXY_PASSWORD_CHANGED
= 'pswc',
75 static const int32 kDefaultFontSize
= 14;
78 SettingsWindow::SettingsWindow(BRect frame
, SettingsMessage
* settings
)
80 BWindow(frame
, B_TRANSLATE("Settings"), B_TITLED_WINDOW_LOOK
,
81 B_NORMAL_WINDOW_FEEL
, B_AUTO_UPDATE_SIZE_LIMITS
82 | B_ASYNCHRONOUS_CONTROLS
| B_NOT_ZOOMABLE
),
85 fApplyButton
= new BButton(B_TRANSLATE("Apply"), new BMessage(MSG_APPLY
));
86 fCancelButton
= new BButton(B_TRANSLATE("Cancel"),
87 new BMessage(MSG_CANCEL
));
88 fRevertButton
= new BButton(B_TRANSLATE("Revert"),
89 new BMessage(MSG_REVERT
));
91 float spacing
= be_control_look
->DefaultItemSpacing();
93 BTabView
* tabView
= new BTabView("settings pages", B_WIDTH_FROM_LABEL
);
94 tabView
->SetBorder(B_NO_BORDER
);
96 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
97 .SetInsets(0, B_USE_DEFAULT_SPACING
, 0, B_USE_WINDOW_SPACING
)
99 .Add(new BSeparatorView(B_HORIZONTAL
))
100 .AddGroup(B_HORIZONTAL
)
101 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
,
102 B_USE_WINDOW_SPACING
, 0)
108 tabView
->AddTab(_CreateGeneralPage(spacing
));
109 tabView
->AddTab(_CreateFontsPage(spacing
));
110 tabView
->AddTab(_CreateProxyPage(spacing
));
112 _SetupFontSelectionView(fStandardFontView
,
113 new BMessage(MSG_STANDARD_FONT_CHANGED
));
114 _SetupFontSelectionView(fSerifFontView
,
115 new BMessage(MSG_SERIF_FONT_CHANGED
));
116 _SetupFontSelectionView(fSansSerifFontView
,
117 new BMessage(MSG_SANS_SERIF_FONT_CHANGED
));
118 _SetupFontSelectionView(fFixedFontView
,
119 new BMessage(MSG_FIXED_FONT_CHANGED
));
121 fApplyButton
->MakeDefault(true);
123 if (!frame
.IsValid())
126 // load settings from disk
137 SettingsWindow::~SettingsWindow()
139 RemoveHandler(fStandardFontView
);
140 delete fStandardFontView
;
141 RemoveHandler(fSerifFontView
);
142 delete fSerifFontView
;
143 RemoveHandler(fSansSerifFontView
);
144 delete fSansSerifFontView
;
145 RemoveHandler(fFixedFontView
);
146 delete fFixedFontView
;
151 SettingsWindow::MessageReceived(BMessage
* message
)
153 switch (message
->what
) {
159 PostMessage(B_QUIT_REQUESTED
);
165 case MSG_STANDARD_FONT_SIZE_SELECTED
:
167 int32 size
= _SizesMenuValue(fStandardSizesMenu
->Menu());
168 fStandardFontView
->SetSize(size
);
169 fSerifFontView
->SetSize(size
);
170 fSansSerifFontView
->SetSize(size
);
171 _ValidateControlsEnabledStatus();
174 case MSG_FIXED_FONT_SIZE_SELECTED
:
176 int32 size
= _SizesMenuValue(fFixedSizesMenu
->Menu());
177 fFixedFontView
->SetSize(size
);
178 _ValidateControlsEnabledStatus();
182 case MSG_START_PAGE_CHANGED
:
183 case MSG_SEARCH_PAGE_CHANGED
:
184 case MSG_DOWNLOAD_FOLDER_CHANGED
:
185 case MSG_NEW_WINDOWS_BEHAVIOR_CHANGED
:
186 case MSG_NEW_TABS_BEHAVIOR_CHANGED
:
187 case MSG_HISTORY_MENU_DAYS_CHANGED
:
188 case MSG_TAB_DISPLAY_BEHAVIOR_CHANGED
:
189 case MSG_AUTO_HIDE_INTERFACE_BEHAVIOR_CHANGED
:
190 case MSG_AUTO_HIDE_POINTER_BEHAVIOR_CHANGED
:
191 case MSG_SHOW_HOME_BUTTON_CHANGED
:
192 case MSG_STANDARD_FONT_CHANGED
:
193 case MSG_SERIF_FONT_CHANGED
:
194 case MSG_SANS_SERIF_FONT_CHANGED
:
195 case MSG_FIXED_FONT_CHANGED
:
196 case MSG_USE_PROXY_CHANGED
:
197 case MSG_PROXY_ADDRESS_CHANGED
:
198 case MSG_PROXY_PORT_CHANGED
:
199 case MSG_USE_PROXY_AUTH_CHANGED
:
200 case MSG_PROXY_USERNAME_CHANGED
:
201 case MSG_PROXY_PASSWORD_CHANGED
:
202 // TODO: Some settings could change live, some others not?
203 _ValidateControlsEnabledStatus();
207 BWindow::MessageReceived(message
);
214 SettingsWindow::QuitRequested()
223 SettingsWindow::Show()
225 // When showing the window, the this is always the
226 // point to which we can revert the settings.
232 // #pragma mark - private
236 SettingsWindow::_CreateGeneralPage(float spacing
)
238 fStartPageControl
= new BTextControl("start page",
239 B_TRANSLATE("Start page:"), "", new BMessage(MSG_START_PAGE_CHANGED
));
240 fStartPageControl
->SetModificationMessage(
241 new BMessage(MSG_START_PAGE_CHANGED
));
242 fStartPageControl
->SetText(
243 fSettings
->GetValue(kSettingsKeyStartPageURL
, kDefaultStartPageURL
));
245 fSearchPageControl
= new BTextControl("search page",
246 B_TRANSLATE("Search page:"), "",
247 new BMessage(MSG_SEARCH_PAGE_CHANGED
));
248 fSearchPageControl
->SetModificationMessage(
249 new BMessage(MSG_SEARCH_PAGE_CHANGED
));
250 BString searchURL
= fSettings
->GetValue(kSettingsKeySearchPageURL
,
251 kDefaultSearchPageURL
);
252 if (searchURL
== "http://www.google.com") {
253 // Migrate old settings files.
254 searchURL
= kDefaultSearchPageURL
;
255 fSettings
->SetValue(kSettingsKeySearchPageURL
, kDefaultSearchPageURL
);
257 fSearchPageControl
->SetText(searchURL
);
259 fDownloadFolderControl
= new BTextControl("download folder",
260 B_TRANSLATE("Download folder:"), "",
261 new BMessage(MSG_DOWNLOAD_FOLDER_CHANGED
));
262 fDownloadFolderControl
->SetModificationMessage(
263 new BMessage(MSG_DOWNLOAD_FOLDER_CHANGED
));
264 fDownloadFolderControl
->SetText(
265 fSettings
->GetValue(kSettingsKeyDownloadPath
, kDefaultDownloadPath
));
267 fNewWindowBehaviorOpenHomeItem
= new BMenuItem(
268 B_TRANSLATE("Open start page"),
269 new BMessage(MSG_NEW_WINDOWS_BEHAVIOR_CHANGED
));
270 fNewWindowBehaviorOpenSearchItem
= new BMenuItem(
271 B_TRANSLATE("Open search page"),
272 new BMessage(MSG_NEW_WINDOWS_BEHAVIOR_CHANGED
));
273 fNewWindowBehaviorOpenBlankItem
= new BMenuItem(
274 B_TRANSLATE("Open blank page"),
275 new BMessage(MSG_NEW_WINDOWS_BEHAVIOR_CHANGED
));
277 fNewTabBehaviorCloneCurrentItem
= new BMenuItem(
278 B_TRANSLATE("Clone current page"),
279 new BMessage(MSG_NEW_TABS_BEHAVIOR_CHANGED
));
280 fNewTabBehaviorOpenHomeItem
= new BMenuItem(
281 B_TRANSLATE("Open start page"),
282 new BMessage(MSG_NEW_TABS_BEHAVIOR_CHANGED
));
283 fNewTabBehaviorOpenSearchItem
= new BMenuItem(
284 B_TRANSLATE("Open search page"),
285 new BMessage(MSG_NEW_TABS_BEHAVIOR_CHANGED
));
286 fNewTabBehaviorOpenBlankItem
= new BMenuItem(
287 B_TRANSLATE("Open blank page"),
288 new BMessage(MSG_NEW_TABS_BEHAVIOR_CHANGED
));
290 fNewWindowBehaviorOpenHomeItem
->SetMarked(true);
291 fNewTabBehaviorOpenBlankItem
->SetMarked(true);
293 BPopUpMenu
* newWindowBehaviorMenu
= new BPopUpMenu("New windows");
294 newWindowBehaviorMenu
->AddItem(fNewWindowBehaviorOpenHomeItem
);
295 newWindowBehaviorMenu
->AddItem(fNewWindowBehaviorOpenSearchItem
);
296 newWindowBehaviorMenu
->AddItem(fNewWindowBehaviorOpenBlankItem
);
297 fNewWindowBehaviorMenu
= new BMenuField("new window behavior",
298 B_TRANSLATE("New windows:"), newWindowBehaviorMenu
);
300 BPopUpMenu
* newTabBehaviorMenu
= new BPopUpMenu("New tabs");
301 newTabBehaviorMenu
->AddItem(fNewTabBehaviorOpenBlankItem
);
302 newTabBehaviorMenu
->AddItem(fNewTabBehaviorOpenHomeItem
);
303 newTabBehaviorMenu
->AddItem(fNewTabBehaviorOpenSearchItem
);
304 newTabBehaviorMenu
->AddItem(fNewTabBehaviorCloneCurrentItem
);
305 fNewTabBehaviorMenu
= new BMenuField("new tab behavior",
306 B_TRANSLATE("New tabs:"), newTabBehaviorMenu
);
308 fDaysInHistory
= new BSpinner("days in history",
309 B_TRANSLATE("Number of days to keep links in History menu:"),
310 new BMessage(MSG_HISTORY_MENU_DAYS_CHANGED
));
311 fDaysInHistory
->SetRange(1, 35);
312 fDaysInHistory
->SetValue(
313 BrowsingHistory::DefaultInstance()->MaxHistoryItemAge());
315 fShowTabsIfOnlyOnePage
= new BCheckBox("show tabs if only one page",
316 B_TRANSLATE("Show tabs if only one page is open"),
317 new BMessage(MSG_TAB_DISPLAY_BEHAVIOR_CHANGED
));
318 fShowTabsIfOnlyOnePage
->SetValue(B_CONTROL_ON
);
320 fAutoHideInterfaceInFullscreenMode
= new BCheckBox("auto-hide interface",
321 B_TRANSLATE("Auto-hide interface in full screen mode"),
322 new BMessage(MSG_AUTO_HIDE_INTERFACE_BEHAVIOR_CHANGED
));
323 fAutoHideInterfaceInFullscreenMode
->SetValue(B_CONTROL_OFF
);
325 fAutoHidePointer
= new BCheckBox("auto-hide pointer",
326 B_TRANSLATE("Auto-hide mouse pointer"),
327 new BMessage(MSG_AUTO_HIDE_POINTER_BEHAVIOR_CHANGED
));
328 fAutoHidePointer
->SetValue(B_CONTROL_OFF
);
330 fShowHomeButton
= new BCheckBox("show home button",
331 B_TRANSLATE("Show home button"),
332 new BMessage(MSG_SHOW_HOME_BUTTON_CHANGED
));
333 fShowHomeButton
->SetValue(B_CONTROL_ON
);
335 BView
* view
= BGroupLayoutBuilder(B_VERTICAL
, 0)
336 .Add(BGridLayoutBuilder(spacing
/ 2, spacing
/ 2)
337 .Add(fStartPageControl
->CreateLabelLayoutItem(), 0, 0)
338 .Add(fStartPageControl
->CreateTextViewLayoutItem(), 1, 0)
340 .Add(fSearchPageControl
->CreateLabelLayoutItem(), 0, 1)
341 .Add(fSearchPageControl
->CreateTextViewLayoutItem(), 1, 1)
343 .Add(fDownloadFolderControl
->CreateLabelLayoutItem(), 0, 2)
344 .Add(fDownloadFolderControl
->CreateTextViewLayoutItem(), 1, 2)
346 .Add(fNewWindowBehaviorMenu
->CreateLabelLayoutItem(), 0, 3)
347 .Add(fNewWindowBehaviorMenu
->CreateMenuBarLayoutItem(), 1, 3)
349 .Add(fNewTabBehaviorMenu
->CreateLabelLayoutItem(), 0, 4)
350 .Add(fNewTabBehaviorMenu
->CreateMenuBarLayoutItem(), 1, 4)
352 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
))
353 .Add(new BSeparatorView(B_HORIZONTAL
, B_PLAIN_BORDER
))
354 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
))
355 .Add(fShowTabsIfOnlyOnePage
)
356 .Add(fAutoHideInterfaceInFullscreenMode
)
357 .Add(fAutoHidePointer
)
358 .Add(fShowHomeButton
)
359 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
))
362 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
,
363 B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
)
367 view
->SetName(B_TRANSLATE("General"));
373 SettingsWindow::_CreateFontsPage(float spacing
)
375 fStandardFontView
= new FontSelectionView("standard",
376 B_TRANSLATE("Standard font:"), true, be_plain_font
);
377 BFont defaultSerifFont
= _FindDefaultSerifFont();
378 fSerifFontView
= new FontSelectionView("serif",
379 B_TRANSLATE("Serif font:"), true, &defaultSerifFont
);
380 fSansSerifFontView
= new FontSelectionView("sans serif",
381 B_TRANSLATE("Sans serif font:"), true, be_plain_font
);
382 fFixedFontView
= new FontSelectionView("fixed",
383 B_TRANSLATE("Fixed font:"), true, be_fixed_font
);
385 fStandardSizesMenu
= new BMenuField("standard font size",
386 B_TRANSLATE("Default standard font size:"), new BPopUpMenu("sizes"),
388 _BuildSizesMenu(fStandardSizesMenu
->Menu(),
389 MSG_STANDARD_FONT_SIZE_SELECTED
);
391 fFixedSizesMenu
= new BMenuField("fixed font size",
392 B_TRANSLATE("Default fixed font size:"), new BPopUpMenu("sizes"),
394 _BuildSizesMenu(fFixedSizesMenu
->Menu(), MSG_FIXED_FONT_SIZE_SELECTED
);
396 BView
* view
= BGridLayoutBuilder(spacing
/ 2, spacing
/ 2)
397 .Add(fStandardFontView
->CreateFontsLabelLayoutItem(), 0, 0)
398 .Add(fStandardFontView
->CreateFontsMenuBarLayoutItem(), 1, 0)
399 .Add(fStandardFontView
->PreviewBox(), 0, 1, 2)
400 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
), 0, 2, 2)
402 .Add(fSerifFontView
->CreateFontsLabelLayoutItem(), 0, 3)
403 .Add(fSerifFontView
->CreateFontsMenuBarLayoutItem(), 1, 3)
404 .Add(fSerifFontView
->PreviewBox(), 0, 4, 2)
405 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
), 0, 5, 2)
407 .Add(fSansSerifFontView
->CreateFontsLabelLayoutItem(), 0, 6)
408 .Add(fSansSerifFontView
->CreateFontsMenuBarLayoutItem(), 1, 6)
409 .Add(fSansSerifFontView
->PreviewBox(), 0, 7, 2)
410 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
), 0, 8, 2)
412 .Add(fFixedFontView
->CreateFontsLabelLayoutItem(), 0, 9)
413 .Add(fFixedFontView
->CreateFontsMenuBarLayoutItem(), 1, 9)
414 .Add(fFixedFontView
->PreviewBox(), 0, 10, 2)
415 .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing
), 0, 11, 2)
417 .Add(fStandardSizesMenu
->CreateLabelLayoutItem(), 0, 12)
418 .Add(fStandardSizesMenu
->CreateMenuBarLayoutItem(), 1, 12)
419 .Add(fFixedSizesMenu
->CreateLabelLayoutItem(), 0, 13)
420 .Add(fFixedSizesMenu
->CreateMenuBarLayoutItem(), 1, 13)
422 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
,
423 B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
)
428 view
->SetName(B_TRANSLATE("Fonts"));
434 SettingsWindow::_CreateProxyPage(float spacing
)
436 fUseProxyCheckBox
= new BCheckBox("use proxy",
437 B_TRANSLATE("Use proxy server to connect to the internet"),
438 new BMessage(MSG_USE_PROXY_CHANGED
));
439 fUseProxyCheckBox
->SetValue(B_CONTROL_ON
);
441 fProxyAddressControl
= new BTextControl("proxy address",
442 B_TRANSLATE("Proxy server address:"), "",
443 new BMessage(MSG_PROXY_ADDRESS_CHANGED
));
444 fProxyAddressControl
->SetModificationMessage(
445 new BMessage(MSG_PROXY_ADDRESS_CHANGED
));
446 fProxyAddressControl
->SetText(
447 fSettings
->GetValue(kSettingsKeyProxyAddress
, ""));
449 fProxyPortControl
= new BTextControl("proxy port",
450 B_TRANSLATE("Proxy server port:"), "",
451 new BMessage(MSG_PROXY_PORT_CHANGED
));
452 fProxyPortControl
->SetModificationMessage(
453 new BMessage(MSG_PROXY_PORT_CHANGED
));
454 fProxyPortControl
->SetText(
455 fSettings
->GetValue(kSettingsKeyProxyPort
, ""));
457 fUseProxyAuthCheckBox
= new BCheckBox("use authentication",
458 B_TRANSLATE("Proxy server requires authentication"),
459 new BMessage(MSG_USE_PROXY_AUTH_CHANGED
));
460 fUseProxyAuthCheckBox
->SetValue(B_CONTROL_ON
);
462 fProxyUsernameControl
= new BTextControl("proxy username",
463 B_TRANSLATE("Proxy username:"), "",
464 new BMessage(MSG_PROXY_USERNAME_CHANGED
));
465 fProxyUsernameControl
->SetModificationMessage(
466 new BMessage(MSG_PROXY_USERNAME_CHANGED
));
467 fProxyUsernameControl
->SetText(
468 fSettings
->GetValue(kSettingsKeyProxyUsername
, ""));
470 fProxyPasswordControl
= new BTextControl("proxy password",
471 B_TRANSLATE("Proxy password:"), "",
472 new BMessage(MSG_PROXY_PASSWORD_CHANGED
));
473 fProxyPasswordControl
->SetModificationMessage(
474 new BMessage(MSG_PROXY_PASSWORD_CHANGED
));
475 fProxyPasswordControl
->TextView()->HideTyping(true);
476 fProxyPasswordControl
->SetText(
477 fSettings
->GetValue(kSettingsKeyProxyPassword
, ""));
479 BView
* view
= BGroupLayoutBuilder(B_VERTICAL
, 0)
480 .Add(fUseProxyCheckBox
)
481 .Add(BGridLayoutBuilder(spacing
/ 2, spacing
/ 2)
482 .Add(fProxyAddressControl
->CreateLabelLayoutItem(), 0, 0)
483 .Add(fProxyAddressControl
->CreateTextViewLayoutItem(), 1, 0)
485 .Add(fProxyPortControl
->CreateLabelLayoutItem(), 0, 1)
486 .Add(fProxyPortControl
->CreateTextViewLayoutItem(), 1, 1)
488 .Add(BSpaceLayoutItem::CreateVerticalStrut(spacing
))
489 .Add(fUseProxyAuthCheckBox
)
490 .Add(BGridLayoutBuilder(spacing
/ 2, spacing
/ 2)
491 .Add(fProxyUsernameControl
->CreateLabelLayoutItem(), 0, 0)
492 .Add(fProxyUsernameControl
->CreateTextViewLayoutItem(), 1, 0)
494 .Add(fProxyPasswordControl
->CreateLabelLayoutItem(), 0, 1)
495 .Add(fProxyPasswordControl
->CreateTextViewLayoutItem(), 1, 1)
497 .Add(BSpaceLayoutItem::CreateGlue())
499 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_WINDOW_SPACING
,
500 B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
)
504 view
->SetName(B_TRANSLATE("Proxy server"));
510 SettingsWindow::_BuildSizesMenu(BMenu
* menu
, uint32 messageWhat
)
512 const float kMinSize
= 8.0;
513 const float kMaxSize
= 18.0;
515 const int32 kSizes
[] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 21, 24, 0};
517 for (int32 i
= 0; kSizes
[i
]; i
++) {
518 int32 size
= kSizes
[i
];
519 if (size
< kMinSize
|| size
> kMaxSize
)
523 snprintf(label
, sizeof(label
), "%" B_PRId32
, size
);
525 BMessage
* message
= new BMessage(messageWhat
);
526 message
->AddInt32("size", size
);
528 BMenuItem
* item
= new BMenuItem(label
, message
);
531 item
->SetTarget(this);
537 SettingsWindow::_SetupFontSelectionView(FontSelectionView
* view
,
541 view
->AttachedToLooper();
542 view
->SetMessage(message
);
543 view
->SetTarget(this);
551 SettingsWindow::_CanApplySettings() const
553 bool canApply
= false;
556 canApply
= canApply
|| (strcmp(fStartPageControl
->Text(),
557 fSettings
->GetValue(kSettingsKeyStartPageURL
,
558 kDefaultStartPageURL
)) != 0);
560 canApply
= canApply
|| (strcmp(fSearchPageControl
->Text(),
561 fSettings
->GetValue(kSettingsKeySearchPageURL
,
562 kDefaultSearchPageURL
)) != 0);
564 canApply
= canApply
|| (strcmp(fDownloadFolderControl
->Text(),
565 fSettings
->GetValue(kSettingsKeyDownloadPath
,
566 kDefaultDownloadPath
)) != 0);
568 canApply
= canApply
|| ((fShowTabsIfOnlyOnePage
->Value() == B_CONTROL_ON
)
569 != fSettings
->GetValue(kSettingsKeyShowTabsIfSinglePageOpen
, true));
571 canApply
= canApply
|| (
572 (fAutoHideInterfaceInFullscreenMode
->Value() == B_CONTROL_ON
)
573 != fSettings
->GetValue(kSettingsKeyAutoHideInterfaceInFullscreenMode
,
576 canApply
= canApply
|| (
577 (fAutoHidePointer
->Value() == B_CONTROL_ON
)
578 != fSettings
->GetValue(kSettingsKeyAutoHidePointer
, false));
580 canApply
= canApply
|| ((fShowHomeButton
->Value() == B_CONTROL_ON
)
581 != fSettings
->GetValue(kSettingsKeyShowHomeButton
, true));
583 canApply
= canApply
|| (fDaysInHistory
->Value()
584 != BrowsingHistory::DefaultInstance()->MaxHistoryItemAge());
587 canApply
= canApply
|| (_NewWindowPolicy()
588 != fSettings
->GetValue(kSettingsKeyNewWindowPolicy
,
589 (uint32
)OpenStartPage
));
592 canApply
= canApply
|| (_NewTabPolicy()
593 != fSettings
->GetValue(kSettingsKeyNewTabPolicy
,
594 (uint32
)OpenBlankPage
));
597 canApply
= canApply
|| (fStandardFontView
->Font()
598 != fSettings
->GetValue("standard font", *be_plain_font
));
600 canApply
= canApply
|| (fSerifFontView
->Font()
601 != fSettings
->GetValue("serif font", _FindDefaultSerifFont()));
603 canApply
= canApply
|| (fSansSerifFontView
->Font()
604 != fSettings
->GetValue("sans serif font", *be_plain_font
));
606 canApply
= canApply
|| (fFixedFontView
->Font()
607 != fSettings
->GetValue("fixed font", *be_fixed_font
));
609 canApply
= canApply
|| (_SizesMenuValue(fStandardSizesMenu
->Menu())
610 != fSettings
->GetValue("standard font size", kDefaultFontSize
));
612 canApply
= canApply
|| (_SizesMenuValue(fFixedSizesMenu
->Menu())
613 != fSettings
->GetValue("fixed font size", kDefaultFontSize
));
616 canApply
= canApply
|| ((fUseProxyCheckBox
->Value() == B_CONTROL_ON
)
617 != fSettings
->GetValue(kSettingsKeyUseProxy
, false));
619 canApply
= canApply
|| (strcmp(fProxyAddressControl
->Text(),
620 fSettings
->GetValue(kSettingsKeyProxyAddress
, "")) != 0);
622 canApply
= canApply
|| (_ProxyPort()
623 != fSettings
->GetValue(kSettingsKeyProxyPort
, (uint32
)0));
625 canApply
= canApply
|| ((fUseProxyAuthCheckBox
->Value() == B_CONTROL_ON
)
626 != fSettings
->GetValue(kSettingsKeyUseProxyAuth
, false));
628 canApply
= canApply
|| (strcmp(fProxyUsernameControl
->Text(),
629 fSettings
->GetValue(kSettingsKeyProxyUsername
, "")) != 0);
631 canApply
= canApply
|| (strcmp(fProxyPasswordControl
->Text(),
632 fSettings
->GetValue(kSettingsKeyProxyPassword
, "")) != 0);
639 SettingsWindow::_ApplySettings()
641 // Store general settings
642 BrowsingHistory::DefaultInstance()->SetMaxHistoryItemAge(
643 (uint32
)fDaysInHistory
->Value());
644 fSettings
->SetValue(kSettingsKeyStartPageURL
, fStartPageControl
->Text());
645 fSettings
->SetValue(kSettingsKeySearchPageURL
, fSearchPageControl
->Text());
646 fSettings
->SetValue(kSettingsKeyDownloadPath
, fDownloadFolderControl
->Text());
647 fSettings
->SetValue(kSettingsKeyShowTabsIfSinglePageOpen
,
648 fShowTabsIfOnlyOnePage
->Value() == B_CONTROL_ON
);
649 fSettings
->SetValue(kSettingsKeyAutoHideInterfaceInFullscreenMode
,
650 fAutoHideInterfaceInFullscreenMode
->Value() == B_CONTROL_ON
);
651 fSettings
->SetValue(kSettingsKeyAutoHidePointer
,
652 fAutoHidePointer
->Value() == B_CONTROL_ON
);
653 fSettings
->SetValue(kSettingsKeyShowHomeButton
,
654 fShowHomeButton
->Value() == B_CONTROL_ON
);
657 fSettings
->SetValue(kSettingsKeyNewWindowPolicy
, _NewWindowPolicy());
658 fSettings
->SetValue(kSettingsKeyNewTabPolicy
, _NewTabPolicy());
660 // Store fond settings
661 fSettings
->SetValue("standard font", fStandardFontView
->Font());
662 fSettings
->SetValue("serif font", fSerifFontView
->Font());
663 fSettings
->SetValue("sans serif font", fSansSerifFontView
->Font());
664 fSettings
->SetValue("fixed font", fFixedFontView
->Font());
665 int32 standardFontSize
= _SizesMenuValue(fStandardSizesMenu
->Menu());
666 int32 fixedFontSize
= _SizesMenuValue(fFixedSizesMenu
->Menu());
667 fSettings
->SetValue("standard font size", standardFontSize
);
668 fSettings
->SetValue("fixed font size", fixedFontSize
);
670 // Store proxy settings
672 fSettings
->SetValue(kSettingsKeyUseProxy
,
673 fUseProxyCheckBox
->Value() == B_CONTROL_ON
);
674 fSettings
->SetValue(kSettingsKeyProxyAddress
,
675 fProxyAddressControl
->Text());
676 uint32 proxyPort
= _ProxyPort();
677 fSettings
->SetValue(kSettingsKeyProxyPort
, proxyPort
);
678 fSettings
->SetValue(kSettingsKeyUseProxyAuth
,
679 fUseProxyAuthCheckBox
->Value() == B_CONTROL_ON
);
680 fSettings
->SetValue(kSettingsKeyProxyUsername
,
681 fProxyUsernameControl
->Text());
682 fSettings
->SetValue(kSettingsKeyProxyPassword
,
683 fProxyPasswordControl
->Text());
687 // Apply settings to default web page settings.
688 BWebSettings::Default()->SetStandardFont(fStandardFontView
->Font());
689 BWebSettings::Default()->SetSerifFont(fSerifFontView
->Font());
690 BWebSettings::Default()->SetSansSerifFont(fSansSerifFontView
->Font());
691 BWebSettings::Default()->SetFixedFont(fFixedFontView
->Font());
692 BWebSettings::Default()->SetDefaultStandardFontSize(standardFontSize
);
693 BWebSettings::Default()->SetDefaultFixedFontSize(fixedFontSize
);
695 if (fUseProxyCheckBox
->Value() == B_CONTROL_ON
) {
696 if (fUseProxyAuthCheckBox
->Value() == B_CONTROL_ON
) {
697 BWebSettings::Default()->SetProxyInfo(fProxyAddressControl
->Text(),
698 proxyPort
, B_PROXY_TYPE_HTTP
, fProxyUsernameControl
->Text(),
699 fProxyPasswordControl
->Text());
701 BWebSettings::Default()->SetProxyInfo(fProxyAddressControl
->Text(),
702 proxyPort
, B_PROXY_TYPE_HTTP
, "", "");
705 BWebSettings::Default()->SetProxyInfo();
707 // This will find all currently instantiated page settings and apply
708 // the default values, unless the page settings have local overrides.
709 BWebSettings::Default()->Apply();
711 _ValidateControlsEnabledStatus();
716 SettingsWindow::_RevertSettings()
718 fStartPageControl
->SetText(
719 fSettings
->GetValue(kSettingsKeyStartPageURL
, kDefaultStartPageURL
));
721 fSearchPageControl
->SetText(
722 fSettings
->GetValue(kSettingsKeySearchPageURL
, kDefaultSearchPageURL
));
724 fDownloadFolderControl
->SetText(
725 fSettings
->GetValue(kSettingsKeyDownloadPath
, kDefaultDownloadPath
));
726 fShowTabsIfOnlyOnePage
->SetValue(
727 fSettings
->GetValue(kSettingsKeyShowTabsIfSinglePageOpen
, true));
728 fAutoHideInterfaceInFullscreenMode
->SetValue(
729 fSettings
->GetValue(kSettingsKeyAutoHideInterfaceInFullscreenMode
,
731 fAutoHidePointer
->SetValue(
732 fSettings
->GetValue(kSettingsKeyAutoHidePointer
, false));
733 fShowHomeButton
->SetValue(
734 fSettings
->GetValue(kSettingsKeyShowHomeButton
, true));
736 fDaysInHistory
->SetValue(
737 BrowsingHistory::DefaultInstance()->MaxHistoryItemAge());
740 uint32 newWindowPolicy
= fSettings
->GetValue(kSettingsKeyNewWindowPolicy
,
741 (uint32
)OpenStartPage
);
742 switch (newWindowPolicy
) {
745 fNewWindowBehaviorOpenHomeItem
->SetMarked(true);
748 fNewWindowBehaviorOpenSearchItem
->SetMarked(true);
751 fNewWindowBehaviorOpenBlankItem
->SetMarked(true);
756 uint32 newTabPolicy
= fSettings
->GetValue(kSettingsKeyNewTabPolicy
,
757 (uint32
)OpenBlankPage
);
758 switch (newTabPolicy
) {
761 fNewTabBehaviorOpenBlankItem
->SetMarked(true);
764 fNewTabBehaviorOpenHomeItem
->SetMarked(true);
767 fNewTabBehaviorOpenSearchItem
->SetMarked(true);
769 case CloneCurrentPage
:
770 fNewTabBehaviorCloneCurrentItem
->SetMarked(true);
775 int32 defaultFontSize
= fSettings
->GetValue("standard font size",
777 int32 defaultFixedFontSize
= fSettings
->GetValue("fixed font size",
780 _SetSizesMenuValue(fStandardSizesMenu
->Menu(), defaultFontSize
);
781 _SetSizesMenuValue(fFixedSizesMenu
->Menu(), defaultFixedFontSize
);
783 fStandardFontView
->SetFont(fSettings
->GetValue("standard font",
784 *be_plain_font
), defaultFontSize
);
785 fSerifFontView
->SetFont(fSettings
->GetValue("serif font",
786 _FindDefaultSerifFont()), defaultFontSize
);
787 fSansSerifFontView
->SetFont(fSettings
->GetValue("sans serif font",
788 *be_plain_font
), defaultFontSize
);
789 fFixedFontView
->SetFont(fSettings
->GetValue("fixed font",
790 *be_fixed_font
), defaultFixedFontSize
);
793 fUseProxyCheckBox
->SetValue(fSettings
->GetValue(kSettingsKeyUseProxy
,
795 fProxyAddressControl
->SetText(fSettings
->GetValue(kSettingsKeyProxyAddress
,
797 BString keyProxyPort
;
798 keyProxyPort
<< fSettings
->GetValue(kSettingsKeyProxyPort
, (uint32
)0);
799 fProxyPortControl
->SetText(keyProxyPort
.String());
800 fUseProxyAuthCheckBox
->SetValue(fSettings
->GetValue(kSettingsKeyUseProxyAuth
,
802 fProxyUsernameControl
->SetText(fSettings
->GetValue(kSettingsKeyProxyUsername
,
804 fProxyPasswordControl
->SetText(fSettings
->GetValue(kSettingsKeyProxyPassword
,
807 _ValidateControlsEnabledStatus();
812 SettingsWindow::_ValidateControlsEnabledStatus()
814 bool canApply
= _CanApplySettings();
815 fApplyButton
->SetEnabled(canApply
);
816 fRevertButton
->SetEnabled(canApply
);
817 // Let the Cancel button be enabled always, as another way to close the
819 fCancelButton
->SetEnabled(true);
821 bool useProxy
= fUseProxyCheckBox
->Value() == B_CONTROL_ON
;
822 fProxyAddressControl
->SetEnabled(useProxy
);
823 fProxyPortControl
->SetEnabled(useProxy
);
824 fUseProxyAuthCheckBox
->SetEnabled(useProxy
);
825 bool useProxyAuth
= useProxy
&& fUseProxyAuthCheckBox
->Value() == B_CONTROL_ON
;
826 fProxyUsernameControl
->SetEnabled(useProxyAuth
);
827 fProxyPasswordControl
->SetEnabled(useProxyAuth
);
835 SettingsWindow::_NewWindowPolicy() const
837 uint32 newWindowPolicy
= OpenStartPage
;
838 BMenuItem
* markedItem
= fNewWindowBehaviorMenu
->Menu()->FindMarked();
839 if (markedItem
== fNewWindowBehaviorOpenSearchItem
)
840 newWindowPolicy
= OpenSearchPage
;
841 else if (markedItem
== fNewWindowBehaviorOpenBlankItem
)
842 newWindowPolicy
= OpenBlankPage
;
843 return newWindowPolicy
;
848 SettingsWindow::_NewTabPolicy() const
850 uint32 newTabPolicy
= OpenBlankPage
;
851 BMenuItem
* markedItem
= fNewTabBehaviorMenu
->Menu()->FindMarked();
852 if (markedItem
== fNewTabBehaviorCloneCurrentItem
)
853 newTabPolicy
= CloneCurrentPage
;
854 else if (markedItem
== fNewTabBehaviorOpenHomeItem
)
855 newTabPolicy
= OpenStartPage
;
856 else if (markedItem
== fNewTabBehaviorOpenSearchItem
)
857 newTabPolicy
= OpenSearchPage
;
863 SettingsWindow::_SetSizesMenuValue(BMenu
* menu
, int32 value
)
865 for (int32 i
= 0; BMenuItem
* item
= menu
->ItemAt(i
); i
++) {
867 if (BMessage
* message
= item
->Message()) {
869 if (message
->FindInt32("size", &size
) == B_OK
&& size
== value
)
872 item
->SetMarked(marked
);
878 SettingsWindow::_SizesMenuValue(BMenu
* menu
) const
880 if (BMenuItem
* item
= menu
->FindMarked()) {
881 if (BMessage
* message
= item
->Message()) {
883 if (message
->FindInt32("size", &size
) == B_OK
)
887 return kDefaultFontSize
;
892 SettingsWindow::_FindDefaultSerifFont() const
894 // Default to the first "serif" font we find.
895 BFont
serifFont(*be_plain_font
);
897 int32 familyCount
= count_font_families();
898 for (int32 i
= 0; i
< familyCount
; i
++) {
899 if (get_font_family(i
, &family
) == B_OK
) {
900 BString
familyString(family
);
901 if (familyString
.IFindFirst("sans") >= 0)
903 if (familyString
.IFindFirst("serif") >= 0) {
904 serifFont
.SetFamilyAndFace(family
, B_REGULAR_FACE
);
914 SettingsWindow::_ProxyPort() const
916 return atoul(fProxyPortControl
->Text());