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 12 GuiTeamUiSettings::GuiTeamUiSettings() 13 { 14 } 15 16 17 GuiTeamUiSettings::GuiTeamUiSettings(const char* settingsID) 18 : 19 fID(settingsID) 20 { 21 } 22 23 24 GuiTeamUiSettings::GuiTeamUiSettings(const GuiTeamUiSettings& other) 25 { 26 if (_SetTo(other) != B_OK) 27 throw std::bad_alloc(); 28 } 29 30 31 GuiTeamUiSettings::~GuiTeamUiSettings() 32 { 33 _Unset(); 34 } 35 36 37 team_ui_settings_type 38 GuiTeamUiSettings::Type() const 39 { 40 return TEAM_UI_SETTINGS_TYPE_GUI; 41 } 42 43 44 const char* 45 GuiTeamUiSettings::ID() const 46 { 47 return fID.String(); 48 } 49 50 51 status_t 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 65 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* 83 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 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 109 GuiTeamUiSettings::Settings(const char* settingID, BMessage &data) const 110 { 111 return fValues.FindMessage(settingID, &data); 112 } 113 114 115 const BMessage& 116 GuiTeamUiSettings::Values() const 117 { 118 return fValues; 119 } 120 121 122 GuiTeamUiSettings& 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 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 146 GuiTeamUiSettings::_Unset() 147 { 148 fID.Truncate(0); 149 150 fValues.MakeEmpty(); 151 } 152