Move SettingsMessage to a central location

* Move SettingsMessage
* Remove SettingsMessage from MediaPlayer and WebPositive
* Use the central SettingsMessage in MediaPlayer and WebPositive (Later Bluetooth)
* Fix a Jam file.

Change-Id: I3bb82a40082c5ece5c2aea2468a77bcd9f15ce77
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3856
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Fredrik Modéen 2021-04-10 22:15:12 +02:00
parent 4a2870fcf2
commit 6375ef053d
10 changed files with 4 additions and 423 deletions

View File

@ -105,7 +105,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
ListenerAdapter.cpp
MessageEvent.cpp
Notifier.cpp
SettingsMessage.cpp
StackBlurFilter.cpp
# .

View File

@ -11,9 +11,9 @@
#include <Entry.h>
#include <Locker.h>
#include <SettingsMessage.h>
#include "Notifier.h"
#include "SettingsMessage.h"
#define SETTINGS_FILENAME "MediaPlayer"

View File

@ -1,336 +0,0 @@
/*
* Copyright 2008, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 1998, Eric Shepherd.
* All rights reserved. Distributed under the terms of the Be Sample Code
* license.
*/
//! Be Newsletter Volume II, Issue 35; September 2, 1998 (Eric Shepherd)
#include "SettingsMessage.h"
#include <Entry.h>
#include <File.h>
#include <String.h>
SettingsMessage::SettingsMessage(directory_which directory,
const char* filename)
: BMessage('pref')
{
fStatus = find_directory(directory, &fPath);
if (fStatus == B_OK)
fStatus = fPath.Append(filename);
if (fStatus == B_OK)
fStatus = Load();
}
SettingsMessage::~SettingsMessage()
{
Save();
}
status_t
SettingsMessage::InitCheck() const
{
return fStatus;
}
status_t
SettingsMessage::Load()
{
BFile file(fPath.Path(), B_READ_ONLY);
status_t status = file.InitCheck();
if (status == B_OK)
status = Unflatten(&file);
return status;
}
status_t
SettingsMessage::Save() const
{
BFile file(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
status_t status = file.InitCheck();
if (status == B_OK)
status = Flatten(&file);
return status;
}
// #pragma mark -
status_t
SettingsMessage::SetValue(const char* name, bool value)
{
if (ReplaceBool(name, value) == B_OK)
return B_OK;
return AddBool(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, int8 value)
{
if (ReplaceInt8(name, value) == B_OK)
return B_OK;
return AddInt8(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, int16 value)
{
if (ReplaceInt16(name, value) == B_OK)
return B_OK;
return AddInt16(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, int32 value)
{
if (ReplaceInt32(name, value) == B_OK)
return B_OK;
return AddInt32(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, uint32 value)
{
if (ReplaceInt32(name, (int32)value) == B_OK)
return B_OK;
return AddInt32(name, (int32)value);
}
status_t
SettingsMessage::SetValue(const char* name, int64 value)
{
if (ReplaceInt64(name, value) == B_OK)
return B_OK;
return AddInt64(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, float value)
{
if (ReplaceFloat(name, value) == B_OK)
return B_OK;
return AddFloat(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, double value)
{
if (ReplaceDouble(name, value) == B_OK)
return B_OK;
return AddDouble(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, const char* value)
{
if (ReplaceString(name, value) == B_OK)
return B_OK;
return AddString(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, const BString& value)
{
return SetValue(name, value.String());
}
status_t
SettingsMessage::SetValue(const char* name, const BPoint& value)
{
if (ReplacePoint(name, value) == B_OK)
return B_OK;
return AddPoint(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, const BRect& value)
{
if (ReplaceRect(name, value) == B_OK)
return B_OK;
return AddRect(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, const entry_ref& value)
{
if (ReplaceRef(name, &value) == B_OK)
return B_OK;
return AddRef(name, &value);
}
status_t
SettingsMessage::SetValue(const char* name, const BMessage* value)
{
if (ReplaceMessage(name, value) == B_OK)
return B_OK;
return AddMessage(name, value);
}
status_t
SettingsMessage::SetValue(const char* name, const BFlattenable* value)
{
if (ReplaceFlat(name, const_cast<BFlattenable*>(value)) == B_OK)
return B_OK;
return AddFlat(name, const_cast<BFlattenable*>(value));
}
// #pragma mark -
bool
SettingsMessage::GetValue(const char* name, bool defaultValue) const
{
bool value;
if (FindBool(name, &value) != B_OK)
return defaultValue;
return value;
}
int8
SettingsMessage::GetValue(const char* name, int8 defaultValue) const
{
int8 value;
if (FindInt8(name, &value) != B_OK)
return defaultValue;
return value;
}
int16
SettingsMessage::GetValue(const char* name, int16 defaultValue) const
{
int16 value;
if (FindInt16(name, &value) != B_OK)
return defaultValue;
return value;
}
int32
SettingsMessage::GetValue(const char* name, int32 defaultValue) const
{
int32 value;
if (FindInt32(name, &value) != B_OK)
return defaultValue;
return value;
}
uint32
SettingsMessage::GetValue(const char* name, uint32 defaultValue) const
{
int32 value;
if (FindInt32(name, &value) != B_OK)
return defaultValue;
return (uint32)value;
}
int64
SettingsMessage::GetValue(const char* name, int64 defaultValue) const
{
int64 value;
if (FindInt64(name, &value) != B_OK)
return defaultValue;
return value;
}
float
SettingsMessage::GetValue(const char* name, float defaultValue) const
{
float value;
if (FindFloat(name, &value) != B_OK)
return defaultValue;
return value;
}
double
SettingsMessage::GetValue(const char* name, double defaultValue) const
{
double value;
if (FindDouble(name, &value) != B_OK)
return defaultValue;
return value;
}
BString
SettingsMessage::GetValue(const char* name, const BString& defaultValue) const
{
BString value;
if (FindString(name, &value) != B_OK)
return defaultValue;
return value;
}
BPoint
SettingsMessage::GetValue(const char *name, BPoint defaultValue) const
{
BPoint value;
if (FindPoint(name, &value) != B_OK)
return defaultValue;
return value;
}
BRect
SettingsMessage::GetValue(const char* name, BRect defaultValue) const
{
BRect value;
if (FindRect(name, &value) != B_OK)
return defaultValue;
return value;
}
entry_ref
SettingsMessage::GetValue(const char* name, const entry_ref& defaultValue) const
{
entry_ref value;
if (FindRef(name, &value) != B_OK)
return defaultValue;
return value;
}
BMessage
SettingsMessage::GetValue(const char* name, const BMessage& defaultValue) const
{
BMessage value;
if (FindMessage(name, &value) != B_OK)
return defaultValue;
return value;
}

View File

@ -1,79 +0,0 @@
/*
* Copyright 2008 Stephan Aßmus <superstippi@gmx.de>.
* Copyright 1998 Eric Shepherd.
* All rights reserved. Distributed under the terms of the Be Sample Code
* license.
*/
#ifndef SETTINGS_MESSAGE_H
#define SETTINGS_MESSAGE_H
#include <FindDirectory.h>
#include <Message.h>
#include <Path.h>
class BString;
class SettingsMessage : public BMessage {
public:
SettingsMessage(directory_which directory,
const char* filename);
virtual ~SettingsMessage();
status_t InitCheck() const;
status_t Load();
status_t Save() const;
status_t SetValue(const char* name, bool value);
status_t SetValue(const char* name, int8 value);
status_t SetValue(const char* name, int16 value);
status_t SetValue(const char* name, int32 value);
status_t SetValue(const char* name, uint32 value);
status_t SetValue(const char* name, int64 value);
status_t SetValue(const char* name, float value);
status_t SetValue(const char* name, double value);
status_t SetValue(const char* name,
const char* value);
status_t SetValue(const char* name,
const BString& value);
status_t SetValue(const char *name, const BPoint& value);
status_t SetValue(const char* name, const BRect& value);
status_t SetValue(const char* name, const entry_ref& value);
status_t SetValue(const char* name,
const BMessage* value);
status_t SetValue(const char* name,
const BFlattenable* value);
bool GetValue(const char* name,
bool defaultValue) const;
int8 GetValue(const char* name,
int8 defaultValue) const;
int16 GetValue(const char* name,
int16 defaultValue) const;
int32 GetValue(const char* name,
int32 defaultValue) const;
uint32 GetValue(const char* name,
uint32 defaultValue) const;
int64 GetValue(const char* name,
int64 defaultValue) const;
float GetValue(const char* name,
float defaultValue) const;
double GetValue(const char* name,
double defaultValue) const;
BString GetValue(const char* name,
const BString& defaultValue) const;
BPoint GetValue(const char *name,
BPoint defaultValue) const;
BRect GetValue(const char* name,
BRect defaultValue) const;
entry_ref GetValue(const char* name,
const entry_ref& defaultValue) const;
BMessage GetValue(const char* name,
const BMessage& defaultValue) const;
private:
BPath fPath;
status_t fStatus;
};
#endif // SETTINGS_MESSAGE_H

View File

@ -23,7 +23,6 @@ local sources =
BaseURL.cpp
BookmarkBar.cpp
FontSelectionView.cpp
SettingsMessage.cpp
# tabview
TabContainerView.cpp

View File

@ -25,6 +25,7 @@
#include <TabView.h>
#include <TextControl.h>
#include <debugger.h>
#include <SettingsMessage.h>
#include <stdio.h>
#include <stdlib.h>
@ -34,7 +35,6 @@
#include "BrowserWindow.h"
#include "FontSelectionView.h"
#include "SettingsKeys.h"
#include "SettingsMessage.h"
#include "WebSettings.h"

View File

@ -54,6 +54,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
RWLocker.cpp
RWLockManager.cpp
SettingsHandler.cpp
SettingsMessage.cpp
ShakeTrackingFilter.cpp
StringForRate.cpp
StringForSize.cpp

View File

@ -22,7 +22,7 @@ SettingsMessage::SettingsMessage(directory_which directory,
const char* filename)
:
BMessage('pref'),
fListeners(4)
fListeners(0)
{
fStatus = find_directory(directory, &fPath);

View File

@ -161,7 +161,6 @@ BluetoothSettingsView::MessageReceived(BMessage* message)
int32 policy;
if (message->FindInt32("be:value", (int32*)&policy) == B_OK) {
fSettings.Data.Policy = policy;
printf("Policy = %d\n", fSettings.Data.Policy);
}
break;
}
@ -181,8 +180,6 @@ BluetoothSettingsView::MessageReceived(BMessage* message)
if (message->FindInt32("be:value",
(int32*)&deviceClass) == B_OK) {
printf("deviceClass = %d\n", deviceClass);
if (deviceClass == 5)
_SetDeviceClass(2, 3, 0x72);
else