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 "BrowserWindow.h"
#include "BrowsingHistory.h" #include "BrowsingHistory.h"
#include "DownloadWindow.h" #include "DownloadWindow.h"
#include "SettingsMessage.h"
#include "SettingsWindow.h" #include "SettingsWindow.h"
#include "WebPage.h" #include "WebPage.h"
#include "WebSettings.h" #include "WebSettings.h"
@ -40,7 +41,6 @@
#include <Autolock.h> #include <Autolock.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Path.h> #include <Path.h>
#include <Screen.h> #include <Screen.h>
@ -59,6 +59,7 @@ BrowserApp::BrowserApp()
fLastWindowFrame(100, 100, 700, 750), fLastWindowFrame(100, 100, 700, 750),
fLaunchRefsMessage(0), fLaunchRefsMessage(0),
fInitialized(false), fInitialized(false),
fSettings(NULL),
fDownloadWindow(NULL), fDownloadWindow(NULL),
fSettingsWindow(NULL) fSettingsWindow(NULL)
{ {
@ -68,6 +69,7 @@ BrowserApp::BrowserApp()
BrowserApp::~BrowserApp() BrowserApp::~BrowserApp()
{ {
delete fLaunchRefsMessage; delete fLaunchRefsMessage;
delete fSettings;
} }
@ -109,31 +111,28 @@ BrowserApp::ReadyToRun()
BWebPage::InitializeOnce(); BWebPage::InitializeOnce();
BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); 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; BWebSettings::SetPersistentStoragePath(path.Path());
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;
} }
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); fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads);
fSettingsWindow = new SettingsWindow(settingsWindowFrame); fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings);
fInitialized = true; fInitialized = true;
@ -249,41 +248,21 @@ BrowserApp::QuitRequested()
} }
} }
BFile settingsFile; fSettings->SetValue("window frame", fLastWindowFrame);
if (_OpenSettingsFile(settingsFile, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) { if (fDownloadWindow->Lock()) {
BMessage settingsArchive; fSettings->SetValue("downloads window frame", fDownloadWindow->Frame());
settingsArchive.AddRect("window frame", fLastWindowFrame); fSettings->SetValue("show downloads", !fDownloadWindow->IsHidden());
if (fDownloadWindow->Lock()) { fDownloadWindow->Unlock();
settingsArchive.AddRect("downloads window frame", fDownloadWindow->Frame()); }
settingsArchive.AddBool("show downloads", !fDownloadWindow->IsHidden()); if (fSettingsWindow->Lock()) {
fDownloadWindow->Unlock(); fSettings->SetValue("settings window frame", fSettingsWindow->Frame());
} fSettingsWindow->Unlock();
if (fSettingsWindow->Lock()) {
settingsArchive.AddRect("settings window frame", fSettingsWindow->Frame());
fSettingsWindow->Unlock();
}
settingsArchive.Flatten(&settingsFile);
} }
return true; 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 void
BrowserApp::_CreateNewPage(const BString& url) BrowserApp::_CreateNewPage(const BString& url)
{ {

View File

@ -32,9 +32,9 @@
#include <Application.h> #include <Application.h>
#include <Rect.h> #include <Rect.h>
class BFile;
class DownloadWindow; class DownloadWindow;
class BrowserWindow; class BrowserWindow;
class SettingsMessage;
class SettingsWindow; class SettingsWindow;
@ -51,7 +51,6 @@ public:
virtual bool QuitRequested(); virtual bool QuitRequested();
private: private:
bool _OpenSettingsFile(BFile& file, uint32 mode);
void _CreateNewPage(const BString& url); void _CreateNewPage(const BString& url);
void _CreateNewWindow(const BString& url); void _CreateNewWindow(const BString& url);
void _CreateNewTab(BrowserWindow* window, void _CreateNewTab(BrowserWindow* window,
@ -65,6 +64,8 @@ private:
BMessage* fLaunchRefsMessage; BMessage* fLaunchRefsMessage;
bool fInitialized; bool fInitialized;
SettingsMessage* fSettings;
DownloadWindow* fDownloadWindow; DownloadWindow* fDownloadWindow;
SettingsWindow* fSettingsWindow; SettingsWindow* fSettingsWindow;
}; };

View File

@ -40,6 +40,8 @@
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <stdio.h> #include <stdio.h>
#include "SettingsMessage.h"
enum { enum {
MSG_OK = 'aply', 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, 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)); SetLayout(new BGroupLayout(B_VERTICAL));

View File

@ -30,11 +30,13 @@
#include <Window.h> #include <Window.h>
class BButton; class BButton;
class SettingsMessage;
class SettingsWindow : public BWindow { class SettingsWindow : public BWindow {
public: public:
SettingsWindow(BRect frame); SettingsWindow(BRect frame,
SettingsMessage* settings);
virtual ~SettingsWindow(); virtual ~SettingsWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@ -45,6 +47,8 @@ private:
void _RevertSettings(); void _RevertSettings();
private: private:
SettingsMessage* fSettings;
BButton* fOkButton; BButton* fOkButton;
BButton* fCancelButton; BButton* fCancelButton;
BButton* fRevertButton; BButton* fRevertButton;