xref: /haiku/src/apps/debugger/user_interface/gui/settings/GuiTeamUiSettings.cpp (revision ec60909a20fb5d87db22583cd87e225e5c67e95e)
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 
GuiTeamUiSettings()12 GuiTeamUiSettings::GuiTeamUiSettings()
13 {
14 }
15 
16 
GuiTeamUiSettings(const char * settingsID)17 GuiTeamUiSettings::GuiTeamUiSettings(const char* settingsID)
18 	:
19 	fID(settingsID)
20 {
21 }
22 
23 
GuiTeamUiSettings(const GuiTeamUiSettings & other)24 GuiTeamUiSettings::GuiTeamUiSettings(const GuiTeamUiSettings& other)
25 {
26 	if (_SetTo(other) != B_OK)
27 		throw std::bad_alloc();
28 }
29 
30 
~GuiTeamUiSettings()31 GuiTeamUiSettings::~GuiTeamUiSettings()
32 {
33 	_Unset();
34 }
35 
36 
37 team_ui_settings_type
Type() const38 GuiTeamUiSettings::Type() const
39 {
40 	return TEAM_UI_SETTINGS_TYPE_GUI;
41 }
42 
43 
44 const char*
ID() const45 GuiTeamUiSettings::ID() const
46 {
47 	return fID.String();
48 }
49 
50 
51 status_t
SetTo(const BMessage & archive)52 GuiTeamUiSettings::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 
64 status_t
WriteTo(BMessage & archive) const65 GuiTeamUiSettings::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 
82 TeamUiSettings*
Clone() const83 GuiTeamUiSettings::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 
99 bool
AddSettings(const char * settingID,const BMessage & data)100 GuiTeamUiSettings::AddSettings(const char* settingID, const BMessage& data)
101 {
102 	fValues.RemoveName(settingID);
103 
104 	return fValues.AddMessage(settingID, &data) == B_OK;
105 }
106 
107 
108 status_t
Settings(const char * settingID,BMessage & data) const109 GuiTeamUiSettings::Settings(const char* settingID, BMessage &data) const
110 {
111 	return fValues.FindMessage(settingID, &data);
112 }
113 
114 
115 const BMessage&
Values() const116 GuiTeamUiSettings::Values() const
117 {
118 	return fValues;
119 }
120 
121 
122 GuiTeamUiSettings&
operator =(const GuiTeamUiSettings & other)123 GuiTeamUiSettings::operator=(const GuiTeamUiSettings& other)
124 {
125 	if (_SetTo(other) != B_OK)
126 		throw std::bad_alloc();
127 
128 	return *this;
129 }
130 
131 
132 status_t
_SetTo(const GuiTeamUiSettings & other)133 GuiTeamUiSettings::_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 
145 void
_Unset()146 GuiTeamUiSettings::_Unset()
147 {
148 	fID.Truncate(0);
149 
150 	fValues.MakeEmpty();
151 }
152