More work-in-progress towards getting settings saved/restored.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43067 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent 2011-11-01 15:45:31 +00:00
parent 71f92c6439
commit 76ce2c7ef7
7 changed files with 128 additions and 3 deletions

View File

@ -140,10 +140,11 @@ Application Debugger :
# settings
BreakpointSetting.cpp
GUITeamUISettings.cpp
SettingsManager.cpp
TeamSettings.cpp
TeamUISettings.cpp
GUITeamUISettings.cpp
TeamUISettingsFactory.cpp
# settings/generic
Setting.cpp

View File

@ -7,6 +7,11 @@
#include <Message.h>
GUITeamUISettings::GUITeamUISettings()
{
}
GUITeamUISettings::GUITeamUISettings(const char* settingsID)
:
fID(settingsID)
@ -25,6 +30,13 @@ GUITeamUISettings::~GUITeamUISettings()
}
team_ui_settings_type
GUITeamUISettings::Type() const
{
return TEAM_UI_SETTINGS_TYPE_GUI;
}
const char*
GUITeamUISettings::ID() const
{
@ -45,6 +57,10 @@ status_t
GUITeamUISettings::WriteTo(BMessage& archive) const
{
status_t error = archive.AddString("ID", fID);
if (error != B_OK)
return error;
error = archive.AddInt32("type", Type());
return error;
}

View File

@ -17,12 +17,14 @@ class BMessage;
class GUITeamUISettings : public TeamUISettings {
public:
GUITeamUISettings();
GUITeamUISettings(const char* settingsID);
GUITeamUISettings(const GUITeamUISettings&
other);
// throws std::bad_alloc
~GUITeamUISettings();
virtual team_ui_settings_type Type() const;
virtual const char* ID() const;
virtual status_t SetTo(const BMessage& archive);
virtual status_t WriteTo(BMessage& archive) const;

View File

@ -16,6 +16,7 @@
#include "BreakpointSetting.h"
#include "Team.h"
#include "TeamUISettings.h"
#include "TeamUISettingsFactory.h"
#include "UserBreakpoint.h"
@ -103,7 +104,14 @@ TeamSettings::SetTo(const BMessage& archive)
// add UI settings
for (int32 i = 0; archive.FindMessage("uisettings", i, &childArchive)
== B_OK; i++) {
TeamUISettings* setting = NULL;
error = TeamUISettingsFactory::Create(childArchive, setting);
if (error == B_OK && !fUISettings.AddItem(setting))
error = B_NO_MEMORY;
if (error != B_OK) {
delete setting;
return error;
}
}
return B_OK;
@ -117,9 +125,9 @@ TeamSettings::WriteTo(BMessage& archive) const
if (error != B_OK)
return error;
BMessage childArchive;
for (int32 i = 0; BreakpointSetting* breakpoint = fBreakpoints.ItemAt(i);
i++) {
BMessage childArchive;
error = breakpoint->WriteTo(childArchive);
if (error != B_OK)
return error;
@ -128,6 +136,17 @@ TeamSettings::WriteTo(BMessage& archive) const
if (error != B_OK)
return error;
}
for (int32 i = 0; TeamUISettings* uiSetting = fUISettings.ItemAt(i);
i++) {
error = uiSetting->WriteTo(childArchive);
if (error != B_OK)
return error;
error = archive.AddMessage("uisettings", &childArchive);
if (error != B_OK)
return error;
}
return B_OK;
}

View File

@ -12,11 +12,18 @@
class BMessage;
enum team_ui_settings_type {
TEAM_UI_SETTINGS_TYPE_GUI,
TEAM_UI_SETTINGS_TYPE_CLI
};
class TeamUISettings {
public:
TeamUISettings();
virtual ~TeamUISettings();
virtual team_ui_settings_type Type() const = 0;
virtual const char* ID() const = 0;
virtual status_t SetTo(const BMessage& archive) = 0;
virtual status_t WriteTo(BMessage& archive) const = 0;

View File

@ -0,0 +1,56 @@
/*
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "TeamUISettingsFactory.h"
#include <Message.h>
#include "GUITeamUISettings.h"
TeamUISettingsFactory::TeamUISettingsFactory()
{
}
TeamUISettingsFactory::~TeamUISettingsFactory()
{
}
status_t
TeamUISettingsFactory::Create(const BMessage& archive, TeamUISettings*&
settings)
{
int32 type;
status_t error = archive.FindInt32("type", &type);
if (error != B_OK)
return error;
switch (type) {
case TEAM_UI_SETTINGS_TYPE_GUI:
settings = new(std::nothrow) GUITeamUISettings();
if (settings == NULL)
return B_NO_MEMORY;
error = settings->SetTo(archive);
if (error != B_OK) {
delete settings;
settings = NULL;
return error;
}
break;
case TEAM_UI_SETTINGS_TYPE_CLI:
// TODO: implement once we have a CLI interface
// (and corresponding settings)
return B_UNSUPPORTED;
default:
return B_BAD_DATA;
}
return B_OK;
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2011, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TEAM_UI_SETTINGS_FACTORY_H
#define TEAM_UI_SETTINGS_FACTORY_H
#include <SupportDefs.h>
class BMessage;
class TeamUISettings;
class TeamUISettingsFactory {
public:
TeamUISettingsFactory();
~TeamUISettingsFactory();
static status_t Create(const BMessage& archive,
TeamUISettings*& settings);
};
#endif // TEAM_UI_SETTINGS_FACTORY_H