Moved some utility stuff into new subfolder "support". Some of these needs to be
removed too, once WebPositive is moved into Haiku. SettingsMessage comes straight from MediaPlayer. Should be moved into src/kits/shared eventually. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@278 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
d0417c565a
commit
75c44a83ca
@@ -0,0 +1,336 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008, Stephan Aßmus <[email protected]>.
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Stephan Aßmus <[email protected]>.
|
||||||
|
* 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
|
||||||
Reference in New Issue
Block a user