2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013-2015, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
8 #include "TeamSettings.h"
14 #include <AutoLocker.h>
16 #include "ArchivingUtils.h"
17 #include "BreakpointSetting.h"
19 #include "TeamFileManagerSettings.h"
20 #include "TeamSignalSettings.h"
21 #include "TeamUiSettings.h"
22 #include "TeamUiSettingsFactory.h"
23 #include "UserBreakpoint.h"
26 TeamSettings::TeamSettings()
28 fFileManagerSettings
= new TeamFileManagerSettings();
29 fSignalSettings
= new TeamSignalSettings();
33 TeamSettings::TeamSettings(const TeamSettings
& other
)
44 TeamSettings::~TeamSettings()
51 TeamSettings::SetTo(Team
* team
)
55 AutoLocker
<Team
> locker(team
);
57 fTeamName
= team
->Name();
60 for (UserBreakpointList::ConstIterator it
61 = team
->UserBreakpoints().GetIterator();
62 UserBreakpoint
* breakpoint
= it
.Next();) {
63 BreakpointSetting
* breakpointSetting
64 = new(std::nothrow
) BreakpointSetting
;
65 if (breakpointSetting
== NULL
)
68 status_t error
= breakpointSetting
->SetTo(breakpoint
->Location(),
69 breakpoint
->IsEnabled(), breakpoint
->IsHidden(),
70 breakpoint
->Condition());
71 if (error
== B_OK
&& !fBreakpoints
.AddItem(breakpointSetting
))
74 delete breakpointSetting
;
79 // add signal configuration
81 fSignalSettings
->SetDefaultSignalDisposition(
82 team
->DefaultSignalDisposition());
84 const SignalDispositionMappings
& mappings
85 = team
->GetSignalDispositionMappings();
87 for (SignalDispositionMappings::const_iterator it
= mappings
.begin();
88 it
!= mappings
.end(); ++it
) {
89 status_t error
= fSignalSettings
->AddCustomSignalDisposition(
90 it
->first
, it
->second
);
100 TeamSettings::SetTo(const BMessage
& archive
,
101 const TeamUiSettingsFactory
& factory
)
105 status_t error
= archive
.FindString("teamName", &fTeamName
);
110 BMessage childArchive
;
111 for (int32 i
= 0; archive
.FindMessage("breakpoints", i
, &childArchive
)
113 BreakpointSetting
* breakpointSetting
114 = new(std::nothrow
) BreakpointSetting
;
115 if (breakpointSetting
== NULL
)
118 error
= breakpointSetting
->SetTo(childArchive
);
119 if (error
== B_OK
&& !fBreakpoints
.AddItem(breakpointSetting
))
122 delete breakpointSetting
;
128 for (int32 i
= 0; archive
.FindMessage("uisettings", i
, &childArchive
)
130 TeamUiSettings
* setting
= NULL
;
131 error
= factory
.Create(childArchive
, setting
);
132 if (error
== B_OK
&& !fUiSettings
.AddItem(setting
))
140 if (archive
.FindMessage("filemanagersettings", &childArchive
) == B_OK
) {
141 error
= fFileManagerSettings
->SetTo(childArchive
);
146 if (archive
.FindMessage("signalsettings", &childArchive
) == B_OK
) {
147 error
= fSignalSettings
->SetTo(childArchive
);
157 TeamSettings::WriteTo(BMessage
& archive
) const
159 status_t error
= archive
.AddString("teamName", fTeamName
);
163 BMessage childArchive
;
164 for (int32 i
= 0; BreakpointSetting
* breakpoint
= fBreakpoints
.ItemAt(i
);
166 error
= breakpoint
->WriteTo(childArchive
);
170 error
= archive
.AddMessage("breakpoints", &childArchive
);
175 for (int32 i
= 0; TeamUiSettings
* uiSetting
= fUiSettings
.ItemAt(i
);
177 error
= uiSetting
->WriteTo(childArchive
);
181 error
= archive
.AddMessage("uisettings", &childArchive
);
186 error
= fFileManagerSettings
->WriteTo(childArchive
);
190 error
= archive
.AddMessage("filemanagersettings", &childArchive
);
194 error
= fSignalSettings
->WriteTo(childArchive
);
198 error
= archive
.AddMessage("signalsettings", &childArchive
);
207 TeamSettings::CountBreakpoints() const
209 return fBreakpoints
.CountItems();
213 const BreakpointSetting
*
214 TeamSettings::BreakpointAt(int32 index
) const
216 return fBreakpoints
.ItemAt(index
);
221 TeamSettings::CountUiSettings() const
223 return fUiSettings
.CountItems();
227 const TeamUiSettings
*
228 TeamSettings::UiSettingAt(int32 index
) const
230 return fUiSettings
.ItemAt(index
);
234 const TeamUiSettings
*
235 TeamSettings::UiSettingFor(const char* id
) const
237 for (int32 i
= 0; i
< fUiSettings
.CountItems(); i
++) {
238 TeamUiSettings
* settings
= fUiSettings
.ItemAt(i
);
239 if (strcmp(settings
->ID(), id
) == 0)
248 TeamSettings::AddUiSettings(TeamUiSettings
* settings
)
250 if (!fUiSettings
.AddItem(settings
))
258 TeamSettings::operator=(const TeamSettings
& other
)
265 fTeamName
= other
.fTeamName
;
267 for (int32 i
= 0; BreakpointSetting
* breakpoint
268 = other
.fBreakpoints
.ItemAt(i
); i
++) {
269 BreakpointSetting
* clonedBreakpoint
270 = new BreakpointSetting(*breakpoint
);
271 if (!fBreakpoints
.AddItem(clonedBreakpoint
)) {
272 delete clonedBreakpoint
;
273 throw std::bad_alloc();
277 for (int32 i
= 0; TeamUiSettings
* uiSetting
278 = other
.fUiSettings
.ItemAt(i
); i
++) {
279 TeamUiSettings
* clonedSetting
280 = uiSetting
->Clone();
281 if (!fUiSettings
.AddItem(clonedSetting
)) {
282 delete clonedSetting
;
283 throw std::bad_alloc();
287 *fFileManagerSettings
= *other
.fFileManagerSettings
;
289 *fSignalSettings
= *other
.fSignalSettings
;
295 TeamFileManagerSettings
*
296 TeamSettings::FileManagerSettings() const
298 return fFileManagerSettings
;
303 TeamSettings::SetFileManagerSettings(TeamFileManagerSettings
* settings
)
306 *fFileManagerSettings
= *settings
;
316 TeamSettings::SignalSettings() const
318 return fSignalSettings
;
323 TeamSettings::SetSignalSettings(TeamSignalSettings
* settings
)
326 *fSignalSettings
= *settings
;
336 TeamSettings::_Unset()
338 for (int32 i
= 0; BreakpointSetting
* breakpoint
= fBreakpoints
.ItemAt(i
);
343 for (int32 i
= 0; TeamUiSettings
* uiSetting
= fUiSettings
.ItemAt(i
); i
++)
346 fBreakpoints
.MakeEmpty();
347 fUiSettings
.MakeEmpty();
348 fSignalSettings
->Unset();
350 fTeamName
.Truncate(0);