[haiku-commits] haiku: hrev52860 - src/apps/webpositive

  • From: Stephan Aßmus <superstippi@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 12 Feb 2019 04:56:42 -0500 (EST)

hrev52860 adds 1 changeset to branch 'master'
old head: 2f1a930a4a6670a029dc50684c42881d84261790
new head: 41ddfe2a44cfd077483c9bf8fa80912431f772a3
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=41ddfe2a44cf+%5E2f1a930a4a66

----------------------------------------------------------------------------

41ddfe2a44cf: WebPositive Add option to start new session on startup
  
   * Add settings file entry "start up policy", with two options:
     resume prior session, and start new session
  
   * Add dropdown to settings window to select option (defaulting
     to "resume prior session", which is the behaviour prior to
     this patch)
  
   * Add code to check setting on launch and open a new session,
     or reload the prior session as specified.
  
   * The "Start new session" option behaves in the same manner as
     opening a new window, following the user's already specified
     new window option
  
   * Related comment 2 of bug #14890
  
  Change-Id: I46c33977bf3e9b943841f70050f890f51ac73bff
  Reviewed-on: https://review.haiku-os.org/c/1035
  Reviewed-by: Stephan Aßmus <superstippi@xxxxxx>

                                      [ Rob Gill <rrobgill@xxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev52860
Commit:      41ddfe2a44cfd077483c9bf8fa80912431f772a3
URL:         https://git.haiku-os.org/haiku/commit/?id=41ddfe2a44cf
Author:      Rob Gill <rrobgill@xxxxxxxxxxxxxx>
Date:        Tue Feb 12 09:07:53 2019 UTC
Committer:   Stephan Aßmus <superstippi@xxxxxx>
Commit-Date: Tue Feb 12 09:56:39 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/14890

----------------------------------------------------------------------------

6 files changed, 93 insertions(+), 25 deletions(-)
src/apps/webpositive/BrowserApp.cpp     | 44 ++++++++++++---------
src/apps/webpositive/BrowserWindow.h    |  5 +++
src/apps/webpositive/SettingsKeys.cpp   |  2 +-
src/apps/webpositive/SettingsKeys.h     |  1 +
src/apps/webpositive/SettingsWindow.cpp | 61 ++++++++++++++++++++++++++---
src/apps/webpositive/SettingsWindow.h   |  5 +++

----------------------------------------------------------------------------

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);
-
-                       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);
+               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);
+                                               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(fNewWindowBehaviorMenu->CreateLabelLayoutItem(), 
0, 3)
+                       .Add(fNewWindowBehaviorMenu->CreateMenuBarLayoutItem(), 
1, 3)
 
-                       .Add(fDownloadFolderControl->CreateLabelLayoutItem(), 
0, 3)
-                       
.Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 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;


Other related posts:

  • » [haiku-commits] haiku: hrev52860 - src/apps/webpositive - Stephan Aßmus