diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index 81fcce7b28..aaffc30a1e 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -32,6 +32,7 @@ #include "BrowserWindow.h" #include "BrowsingHistory.h" #include "DownloadWindow.h" +#include "SettingsMessage.h" #include "SettingsWindow.h" #include "WebPage.h" #include "WebSettings.h" @@ -40,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -59,6 +59,7 @@ BrowserApp::BrowserApp() fLastWindowFrame(100, 100, 700, 750), fLaunchRefsMessage(0), fInitialized(false), + fSettings(NULL), fDownloadWindow(NULL), fSettingsWindow(NULL) { @@ -68,6 +69,7 @@ BrowserApp::BrowserApp() BrowserApp::~BrowserApp() { delete fLaunchRefsMessage; + delete fSettings; } @@ -109,31 +111,28 @@ BrowserApp::ReadyToRun() BWebPage::InitializeOnce(); BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); - BWebSettings::SetPersistentStoragePath("/boot/home/config/settings/WebPositive"); + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK + && path.Append(kApplicationName) == B_OK + && create_directory(path.Path(), 0777) == B_OK) { - BFile settingsFile; - BRect windowFrameFromSettings = fLastWindowFrame; - BRect downloadWindowFrame(100, 100, 300, 250); - BRect settingsWindowFrame; - bool showDownloads = false; - if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) { - BMessage settingsArchive; - settingsArchive.Unflatten(&settingsFile); - BRect rect; - if (settingsArchive.FindRect("window frame", &rect) == B_OK) - windowFrameFromSettings = rect; - if (settingsArchive.FindRect("downloads window frame", &rect) == B_OK) - downloadWindowFrame = rect; - if (settingsArchive.FindRect("settings window frame", &rect) == B_OK) - settingsWindowFrame = rect; - bool flag; - if (settingsArchive.FindBool("show downloads", &flag) == B_OK) - showDownloads = flag; + BWebSettings::SetPersistentStoragePath(path.Path()); } - fLastWindowFrame = windowFrameFromSettings; + + BString mainSettingsPath(kApplicationName); + mainSettingsPath << "/Application"; + fSettings = new SettingsMessage(B_USER_SETTINGS_DIRECTORY, + mainSettingsPath.String()); + + fLastWindowFrame = fSettings->GetValue("window frame", fLastWindowFrame); + BRect downloadWindowFrame = fSettings->GetValue("downloads window frame", + BRect(100, 100, 300, 250)); + BRect settingsWindowFrame = fSettings->GetValue("settings window frame", + BRect()); + bool showDownloads = fSettings->GetValue("show downloads", false); fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads); - fSettingsWindow = new SettingsWindow(settingsWindowFrame); + fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings); fInitialized = true; @@ -249,41 +248,21 @@ BrowserApp::QuitRequested() } } - BFile settingsFile; - if (_OpenSettingsFile(settingsFile, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) { - BMessage settingsArchive; - settingsArchive.AddRect("window frame", fLastWindowFrame); - if (fDownloadWindow->Lock()) { - settingsArchive.AddRect("downloads window frame", fDownloadWindow->Frame()); - settingsArchive.AddBool("show downloads", !fDownloadWindow->IsHidden()); - fDownloadWindow->Unlock(); - } - if (fSettingsWindow->Lock()) { - settingsArchive.AddRect("settings window frame", fSettingsWindow->Frame()); - fSettingsWindow->Unlock(); - } - settingsArchive.Flatten(&settingsFile); + fSettings->SetValue("window frame", fLastWindowFrame); + if (fDownloadWindow->Lock()) { + fSettings->SetValue("downloads window frame", fDownloadWindow->Frame()); + fSettings->SetValue("show downloads", !fDownloadWindow->IsHidden()); + fDownloadWindow->Unlock(); + } + if (fSettingsWindow->Lock()) { + fSettings->SetValue("settings window frame", fSettingsWindow->Frame()); + fSettingsWindow->Unlock(); } return true; } -bool -BrowserApp::_OpenSettingsFile(BFile& file, uint32 mode) -{ - BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK - || path.Append(kApplicationName) != B_OK - || create_directory(path.Path(), 0777) != B_OK - || path.Append("Application") != B_OK) { - return false; - } - - return file.SetTo(path.Path(), mode) == B_OK; -} - - void BrowserApp::_CreateNewPage(const BString& url) { diff --git a/src/apps/webpositive/BrowserApp.h b/src/apps/webpositive/BrowserApp.h index 6b5402ba9a..531a88ffe0 100644 --- a/src/apps/webpositive/BrowserApp.h +++ b/src/apps/webpositive/BrowserApp.h @@ -32,9 +32,9 @@ #include #include -class BFile; class DownloadWindow; class BrowserWindow; +class SettingsMessage; class SettingsWindow; @@ -51,7 +51,6 @@ public: virtual bool QuitRequested(); private: - bool _OpenSettingsFile(BFile& file, uint32 mode); void _CreateNewPage(const BString& url); void _CreateNewWindow(const BString& url); void _CreateNewTab(BrowserWindow* window, @@ -65,6 +64,8 @@ private: BMessage* fLaunchRefsMessage; bool fInitialized; + SettingsMessage* fSettings; + DownloadWindow* fDownloadWindow; SettingsWindow* fSettingsWindow; }; diff --git a/src/apps/webpositive/SettingsWindow.cpp b/src/apps/webpositive/SettingsWindow.cpp index 77364539fe..42c4492883 100644 --- a/src/apps/webpositive/SettingsWindow.cpp +++ b/src/apps/webpositive/SettingsWindow.cpp @@ -40,6 +40,8 @@ #include #include +#include "SettingsMessage.h" + enum { MSG_OK = 'aply', @@ -48,10 +50,11 @@ enum { }; -SettingsWindow::SettingsWindow(BRect frame) +SettingsWindow::SettingsWindow(BRect frame, SettingsMessage* settings) : BWindow(frame, "Settings", 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), + fSettings(settings) { SetLayout(new BGroupLayout(B_VERTICAL)); diff --git a/src/apps/webpositive/SettingsWindow.h b/src/apps/webpositive/SettingsWindow.h index 22ff3f7c10..76b215b03e 100644 --- a/src/apps/webpositive/SettingsWindow.h +++ b/src/apps/webpositive/SettingsWindow.h @@ -30,11 +30,13 @@ #include class BButton; +class SettingsMessage; class SettingsWindow : public BWindow { public: - SettingsWindow(BRect frame); + SettingsWindow(BRect frame, + SettingsMessage* settings); virtual ~SettingsWindow(); virtual void MessageReceived(BMessage* message); @@ -45,6 +47,8 @@ private: void _RevertSettings(); private: + SettingsMessage* fSettings; + BButton* fOkButton; BButton* fCancelButton; BButton* fRevertButton;