diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index 460fab9f98..6bb1967d43 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -248,26 +248,34 @@ BrowserApp::ReadyToRun() fLaunchRefsMessage = NULL; } - // If no refs led to a new open page, restore previous session. + // If no refs led to a new open page, open new session if set if (fSession->InitCheck() == B_OK && pagesCreated == 0) { - BMessage archivedWindow; - for (int i = 0; fSession->FindMessage("window", i, &archivedWindow) == B_OK; - i++) { - BRect frame = archivedWindow.FindRect("window frame"); - BString url; - archivedWindow.FindString("tab", 0, &url); - BrowserWindow* window = new(std::nothrow) BrowserWindow(frame, - fSettings, url, fContext); + const char* kSettingsKeyStartUpPolicy = "start up policy"; + uint32 fStartUpPolicy = fSettings->GetValue(kSettingsKeyStartUpPolicy, + (uint32)ResumePriorSession); + if (fStartUpPolicy == StartNewSession) { + PostMessage(NEW_WINDOW); + } else { + // otherwise, restore previous session + BMessage archivedWindow; + for (int i = 0; fSession->FindMessage("window", i, &archivedWindow) + == B_OK; i++) { + BRect frame = archivedWindow.FindRect("window frame"); + BString url; + archivedWindow.FindString("tab", 0, &url); + BrowserWindow* window = new(std::nothrow) BrowserWindow(frame, + fSettings, url, fContext); - if (window != NULL) { - window->Show(); - pagesCreated++; - - for (int j = 1; archivedWindow.FindString("tab", j, &url) == B_OK; - j++) { - printf("Create %d:%d\n", i, j); - _CreateNewTab(window, url, false); + if (window != NULL) { + window->Show(); pagesCreated++; + + for (int j = 1; archivedWindow.FindString("tab", j, &url) + == B_OK; j++) { + printf("Create %d:%d\n", i, j); + _CreateNewTab(window, url, false); + pagesCreated++; + } } } } diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index dcc85f2133..20597974ad 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -76,6 +76,11 @@ enum NewPagePolicy { CloneCurrentPage = 3 }; +enum StartUpPolicy { + ResumePriorSession = 0, + StartNewSession = 1 +}; + enum { NEW_WINDOW = 'nwnd', NEW_TAB = 'ntab', diff --git a/src/apps/webpositive/SettingsKeys.cpp b/src/apps/webpositive/SettingsKeys.cpp index 1cb2a3777b..36786e3efe 100644 --- a/src/apps/webpositive/SettingsKeys.cpp +++ b/src/apps/webpositive/SettingsKeys.cpp @@ -23,10 +23,10 @@ const char* kSettingsKeyShowHomeButton = "show home button"; const char* kSettingsKeyNewWindowPolicy = "new window policy"; const char* kSettingsKeyNewTabPolicy = "new tab policy"; +const char* kSettingsKeyStartUpPolicy = "start up policy"; const char* kSettingsKeyStartPageURL = "start page url"; const char* kSettingsKeySearchPageURL = "search page url"; - const char* kDefaultDownloadPath = "/boot/home/Desktop/"; const char* kDefaultStartPageURL = "file:///boot/home/config/settings/WebPositive/LoaderPages/Welcome"; diff --git a/src/apps/webpositive/SettingsKeys.h b/src/apps/webpositive/SettingsKeys.h index 21cbeb95c0..2d1a1f65f6 100644 --- a/src/apps/webpositive/SettingsKeys.h +++ b/src/apps/webpositive/SettingsKeys.h @@ -21,6 +21,7 @@ extern const char* kSettingsKeyAutoHideInterfaceInFullscreenMode; extern const char* kSettingsKeyAutoHidePointer; extern const char* kSettingsKeyShowHomeButton; +extern const char* kSettingsKeyStartUpPolicy; extern const char* kSettingsKeyNewWindowPolicy; extern const char* kSettingsKeyNewTabPolicy; extern const char* kSettingsKeyStartPageURL; diff --git a/src/apps/webpositive/SettingsWindow.cpp b/src/apps/webpositive/SettingsWindow.cpp index 03fc38e7f5..bdd3cbd85e 100644 --- a/src/apps/webpositive/SettingsWindow.cpp +++ b/src/apps/webpositive/SettingsWindow.cpp @@ -51,6 +51,7 @@ enum { MSG_DOWNLOAD_FOLDER_CHANGED = 'dnfc', MSG_NEW_WINDOWS_BEHAVIOR_CHANGED = 'nwbc', MSG_NEW_TABS_BEHAVIOR_CHANGED = 'ntbc', + MSG_START_UP_BEHAVIOR_CHANGED = 'subc', MSG_HISTORY_MENU_DAYS_CHANGED = 'digm', MSG_TAB_DISPLAY_BEHAVIOR_CHANGED = 'tdbc', MSG_AUTO_HIDE_INTERFACE_BEHAVIOR_CHANGED = 'ahic', @@ -194,6 +195,7 @@ SettingsWindow::MessageReceived(BMessage* message) case MSG_START_PAGE_CHANGED: case MSG_SEARCH_PAGE_CHANGED: case MSG_DOWNLOAD_FOLDER_CHANGED: + case MSG_START_UP_BEHAVIOR_CHANGED: case MSG_NEW_WINDOWS_BEHAVIOR_CHANGED: case MSG_NEW_TABS_BEHAVIOR_CHANGED: case MSG_HISTORY_MENU_DAYS_CHANGED: @@ -276,6 +278,13 @@ SettingsWindow::_CreateGeneralPage(float spacing) fDownloadFolderControl->SetText( fSettings->GetValue(kSettingsKeyDownloadPath, kDefaultDownloadPath)); + fStartUpBehaviorResumePriorSession = new BMenuItem( + B_TRANSLATE("Resume prior session"), + new BMessage(MSG_START_UP_BEHAVIOR_CHANGED)); + fStartUpBehaviorStartNewSession = new BMenuItem( + B_TRANSLATE("Start new session"), + new BMessage(MSG_START_UP_BEHAVIOR_CHANGED)); + fNewWindowBehaviorOpenHomeItem = new BMenuItem( B_TRANSLATE("Open start page"), new BMessage(MSG_NEW_WINDOWS_BEHAVIOR_CHANGED)); @@ -303,6 +312,14 @@ SettingsWindow::_CreateGeneralPage(float spacing) fNewWindowBehaviorOpenHomeItem->SetMarked(true); fNewTabBehaviorOpenBlankItem->SetMarked(true); + fStartUpBehaviorResumePriorSession->SetMarked(true); + + BPopUpMenu* startUpBehaviorMenu = new BPopUpMenu("Start up"); + startUpBehaviorMenu->AddItem(fStartUpBehaviorResumePriorSession); + startUpBehaviorMenu->AddItem(fStartUpBehaviorStartNewSession); + fStartUpBehaviorMenu = new BMenuField("start up behavior", + B_TRANSLATE("Start up:"), startUpBehaviorMenu); + BPopUpMenu* newWindowBehaviorMenu = new BPopUpMenu("New windows"); newWindowBehaviorMenu->AddItem(fNewWindowBehaviorOpenHomeItem); @@ -354,15 +371,18 @@ SettingsWindow::_CreateGeneralPage(float spacing) .Add(fSearchPageControl->CreateLabelLayoutItem(), 0, 1) .Add(fSearchPageControl->CreateTextViewLayoutItem(), 1, 1) - .Add(fNewWindowBehaviorMenu->CreateLabelLayoutItem(), 0, 2) - .Add(fNewWindowBehaviorMenu->CreateMenuBarLayoutItem(), 1, 2) + .Add(fStartUpBehaviorMenu->CreateLabelLayoutItem(), 0, 2) + .Add(fStartUpBehaviorMenu->CreateMenuBarLayoutItem(), 1, 2) - .Add(fDownloadFolderControl->CreateLabelLayoutItem(), 0, 3) - .Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 1, 3) + .Add(fNewWindowBehaviorMenu->CreateLabelLayoutItem(), 0, 3) + .Add(fNewWindowBehaviorMenu->CreateMenuBarLayoutItem(), 1, 3) + + .Add(fDownloadFolderControl->CreateLabelLayoutItem(), 0, 4) + .Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 1, 4) .Add(fChooseButton, 2, 3) - .Add(fNewTabBehaviorMenu->CreateLabelLayoutItem(), 0, 4) - .Add(fNewTabBehaviorMenu->CreateMenuBarLayoutItem(), 1, 4) + .Add(fNewTabBehaviorMenu->CreateLabelLayoutItem(), 0, 5) + .Add(fNewTabBehaviorMenu->CreateMenuBarLayoutItem(), 1, 5) ) .Add(BSpaceLayoutItem::CreateVerticalStrut(spacing)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) @@ -552,6 +572,11 @@ SettingsWindow::_CanApplySettings() const canApply = canApply || (fDaysInHistory->Value() != BrowsingHistory::DefaultInstance()->MaxHistoryItemAge()); + // Start up policy + canApply = canApply || (_StartUpPolicy() + != fSettings->GetValue(kSettingsKeyStartUpPolicy, + (uint32)ResumePriorSession)); + // New window policy canApply = canApply || (_NewWindowPolicy() != fSettings->GetValue(kSettingsKeyNewWindowPolicy, @@ -623,6 +648,7 @@ SettingsWindow::_ApplySettings() fShowHomeButton->Value() == B_CONTROL_ON); // New page policies + fSettings->SetValue(kSettingsKeyStartUpPolicy, _StartUpPolicy()); fSettings->SetValue(kSettingsKeyNewWindowPolicy, _NewWindowPolicy()); fSettings->SetValue(kSettingsKeyNewTabPolicy, _NewTabPolicy()); @@ -705,6 +731,19 @@ SettingsWindow::_RevertSettings() fDaysInHistory->SetValue( BrowsingHistory::DefaultInstance()->MaxHistoryItemAge()); + // Start Up policy + uint32 startUpPolicy = fSettings->GetValue(kSettingsKeyStartUpPolicy, + (uint32)ResumePriorSession); + switch (startUpPolicy) { + default: + case ResumePriorSession: + fStartUpBehaviorResumePriorSession->SetMarked(true); + break; + case StartNewSession: + fStartUpBehaviorStartNewSession->SetMarked(true); + break; + } + // New window policy uint32 newWindowPolicy = fSettings->GetValue(kSettingsKeyNewWindowPolicy, (uint32)OpenStartPage); @@ -827,6 +866,16 @@ SettingsWindow::_ValidateControlsEnabledStatus() // #pragma mark - +uint32 +SettingsWindow::_StartUpPolicy() const +{ + uint32 startUpPolicy = ResumePriorSession; + BMenuItem* markedItem = fStartUpBehaviorMenu->Menu()->FindMarked(); + if (markedItem == fStartUpBehaviorStartNewSession) + startUpPolicy = StartNewSession; + return startUpPolicy; +} + uint32 SettingsWindow::_NewWindowPolicy() const { diff --git a/src/apps/webpositive/SettingsWindow.h b/src/apps/webpositive/SettingsWindow.h index aff8d3b03b..f6de2c88f8 100644 --- a/src/apps/webpositive/SettingsWindow.h +++ b/src/apps/webpositive/SettingsWindow.h @@ -49,6 +49,7 @@ private: const BMessage* message); void _ValidateControlsEnabledStatus(); + uint32 _StartUpPolicy() const; uint32 _NewWindowPolicy() const; uint32 _NewTabPolicy() const; @@ -74,6 +75,10 @@ private: BMenuItem* fNewTabBehaviorOpenSearchItem; BMenuItem* fNewTabBehaviorOpenBlankItem; + BMenuField* fStartUpBehaviorMenu; + BMenuItem* fStartUpBehaviorResumePriorSession; + BMenuItem* fStartUpBehaviorStartNewSession; + BSpinner* fDaysInHistory; BCheckBox* fShowTabsIfOnlyOnePage; BCheckBox* fAutoHideInterfaceInFullscreenMode;