1/*
2 * Copyright 2011, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "GuiTeamUiSettings.h"
8
9#include <Message.h>
10
11
12GuiTeamUiSettings::GuiTeamUiSettings()
13{
14}
15
16
17GuiTeamUiSettings::GuiTeamUiSettings(const char* settingsID)
18	:
19	fID(settingsID)
20{
21}
22
23
24GuiTeamUiSettings::GuiTeamUiSettings(const GuiTeamUiSettings& other)
25{
26	if (_SetTo(other) != B_OK)
27		throw std::bad_alloc();
28}
29
30
31GuiTeamUiSettings::~GuiTeamUiSettings()
32{
33	_Unset();
34}
35
36
37team_ui_settings_type
38GuiTeamUiSettings::Type() const
39{
40	return TEAM_UI_SETTINGS_TYPE_GUI;
41}
42
43
44const char*
45GuiTeamUiSettings::ID() const
46{
47	return fID.String();
48}
49
50
51status_t
52GuiTeamUiSettings::SetTo(const BMessage& archive)
53{
54	status_t error = archive.FindString("ID", &fID);
55	if (error != B_OK)
56		return error;
57
58	error = archive.FindMessage("values", &fValues);
59
60	return error;
61}
62
63
64status_t
65GuiTeamUiSettings::WriteTo(BMessage& archive) const
66{
67	archive.MakeEmpty();
68	status_t error = archive.AddString("ID", fID);
69	if (error != B_OK)
70		return error;
71
72	error = archive.AddInt32("type", Type());
73	if (error != B_OK)
74		return error;
75
76	error = archive.AddMessage("values", &fValues);
77
78	return error;
79}
80
81
82TeamUiSettings*
83GuiTeamUiSettings::Clone() const
84{
85	GuiTeamUiSettings* settings = new(std::nothrow) GuiTeamUiSettings(fID);
86
87	if (settings == NULL)
88		return NULL;
89
90	if (settings->_SetTo(*this) != B_OK) {
91		delete settings;
92		return NULL;
93	}
94
95	return settings;
96}
97
98
99bool
100GuiTeamUiSettings::AddSettings(const char* settingID, const BMessage& data)
101{
102	fValues.RemoveName(settingID);
103
104	return fValues.AddMessage(settingID, &data) == B_OK;
105}
106
107
108status_t
109GuiTeamUiSettings::Settings(const char* settingID, BMessage &data) const
110{
111	return fValues.FindMessage(settingID, &data);
112}
113
114
115const BMessage&
116GuiTeamUiSettings::Values() const
117{
118	return fValues;
119}
120
121
122GuiTeamUiSettings&
123GuiTeamUiSettings::operator=(const GuiTeamUiSettings& other)
124{
125	if (_SetTo(other) != B_OK)
126		throw std::bad_alloc();
127
128	return *this;
129}
130
131
132status_t
133GuiTeamUiSettings::_SetTo(const GuiTeamUiSettings& other)
134{
135	_Unset();
136
137	fID = other.fID;
138
139	fValues = other.fValues;
140
141	return B_OK;
142}
143
144
145void
146GuiTeamUiSettings::_Unset()
147{
148	fID.Truncate(0);
149
150	fValues.MakeEmpty();
151}
152