[haiku-webkit-commits] r279 - webkit/trunk/WebKit/haiku/WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Wed, 03 Mar 2010 11:23:07 +0000

Author: stippi
Date: Wed Mar  3 11:23:06 2010
New Revision: 279
URL: http://mmlr.dyndns.org/changeset/279

Log:
Reworked BrowserApp to use SettingsMessage.

Modified:
   webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp
   webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h
   webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp
   webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp        Wed Mar  3 
11:08:50 2010        (r278)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp        Wed Mar  3 
11:23:06 2010        (r279)
@@ -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 @@
        fLastWindowFrame(100, 100, 700, 750),
        fLaunchRefsMessage(0),
        fInitialized(false),
+       fSettings(NULL),
        fDownloadWindow(NULL),
        fSettingsWindow(NULL)
 {
@@ -68,6 +69,7 @@
 BrowserApp::~BrowserApp()
 {
        delete fLaunchRefsMessage;
+       delete fSettings;
 }
 
 
@@ -109,31 +111,28 @@
        BWebPage::InitializeOnce();
        BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER);
 
-       
BWebSettings::SetPersistentStoragePath("/boot/home/config/settings/WebPositive");
-
-       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;
-       }
-       fLastWindowFrame = windowFrameFromSettings;
+       BPath path;
+       if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK
+               && path.Append(kApplicationName) == B_OK
+               && create_directory(path.Path(), 0777) == B_OK) {
+
+               BWebSettings::SetPersistentStoragePath(path.Path());
+       }
+       
+       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 @@
                }
        }
 
-       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)
 {

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h  Wed Mar  3 11:08:50 
2010        (r278)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h  Wed Mar  3 11:23:06 
2010        (r279)
@@ -32,9 +32,9 @@
 #include <Application.h>
 #include <Rect.h>
 
-class BFile;
 class DownloadWindow;
 class BrowserWindow;
+class SettingsMessage;
 class SettingsWindow;
 
 
@@ -51,7 +51,6 @@
        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 @@
                        BMessage*                       fLaunchRefsMessage;
                        bool                            fInitialized;
 
+                       SettingsMessage*        fSettings;
+
                        DownloadWindow*         fDownloadWindow;
                        SettingsWindow*         fSettingsWindow;
 };

Modified: webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp    Wed Mar  3 
11:08:50 2010        (r278)
+++ webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp    Wed Mar  3 
11:23:06 2010        (r279)
@@ -40,6 +40,8 @@
 #include <SpaceLayoutItem.h>
 #include <stdio.h>
 
+#include "SettingsMessage.h"
+
 
 enum {
        MSG_OK                  = 'aply',
@@ -48,10 +50,11 @@
 };
 
 
-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));
 

Modified: webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h      Wed Mar  3 
11:08:50 2010        (r278)
+++ webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h      Wed Mar  3 
11:23:06 2010        (r279)
@@ -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 @@
                        void                            _RevertSettings();
 
 private:
+                       SettingsMessage*        fSettings;
+
                        BButton*                        fOkButton;
                        BButton*                        fCancelButton;
                        BButton*                        fRevertButton;

Other related posts:

  • » [haiku-webkit-commits] r279 - webkit/trunk/WebKit/haiku/WebPositive - webkit