Reworked BrowserApp to use SettingsMessage.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@279 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi 2010-03-03 11:23:06 +00:00 committed by Alexandre Deckner
parent 75c44a83ca
commit b5cd3e842f
4 changed files with 43 additions and 56 deletions

View File

@ -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 <Autolock.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
#include <Screen.h>
@ -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)
{

View File

@ -32,9 +32,9 @@
#include <Application.h>
#include <Rect.h>
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;
};

View File

@ -40,6 +40,8 @@
#include <SpaceLayoutItem.h>
#include <stdio.h>
#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));

View File

@ -30,11 +30,13 @@
#include <Window.h>
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;