2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file ContactName.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "ContactName.h"
30 ContactName::ContactName() :
33 m_firstNameIsSet(false),
34 m_middleNameIsSet(false),
35 m_lastNameIsSet(false),
36 m_phoneticFirstNameIsSet(false),
37 m_phoneticLastNameIsSet(false),
38 m_displayNameIsSet(false)
40 m_nicknames = StringArrayPtr(new StringArray());
41 is_typesSetJSArray = false;
43 m_typesJsValue = NULL;
47 ContactName::~ContactName()
49 if(IsTypesSetJSArray()){
50 JSContextRef contextRef = getContext();
51 JSObjectRef tempJSObject = getTypesJSObj();
52 JSValueUnprotect(contextRef, tempJSObject);
56 std::string ContactName::getPrefix() const
61 void ContactName::setPrefix(const std::string &value)
67 void ContactName::unsetPrefix()
70 m_prefixIsSet = false;
73 bool ContactName::getPrefixIsSet() const
78 std::string ContactName::getSuffix() const
83 void ContactName::setSuffix(const std::string &value)
89 void ContactName::unsetSuffix()
92 m_suffixIsSet = false;
95 bool ContactName::getSuffixIsSet() const
100 std::string ContactName::getFirstName() const
105 void ContactName::setFirstName(const std::string &value)
108 m_firstNameIsSet = true;
111 void ContactName::unsetFirstName()
114 m_firstNameIsSet = false;
117 bool ContactName::getFirstNameIsSet() const
119 return m_firstNameIsSet;
122 std::string ContactName::getMiddleName() const
127 void ContactName::setMiddleName(const std::string &value)
129 m_middleName = value;
130 m_middleNameIsSet = true;
133 void ContactName::unsetMiddleName()
136 m_middleNameIsSet = false;
139 bool ContactName::getMiddleNameIsSet() const
141 return m_middleNameIsSet;
144 std::string ContactName::getLastName() const
149 void ContactName::setLastName(const std::string &value)
152 m_lastNameIsSet = true;
155 void ContactName::unsetLastName()
158 m_lastNameIsSet = false;
161 bool ContactName::getLastNameIsSet() const
163 return m_lastNameIsSet;
166 StringArrayPtr ContactName::getNicknames() const
171 void ContactName::setNicknames(const StringArrayPtr &value)
174 m_nicknames = StringArrayPtr(new StringArray());
179 void ContactName::addNickname(const std::string &value)
181 m_nicknames->push_back(value);
184 void ContactName::clearNicknames()
186 m_nicknames->clear();
189 int ContactName::getNicknamesNum() const
191 return m_nicknames->size();
194 std::string ContactName::getPhoneticFirstName() const
196 return m_phoneticFirstName;
199 void ContactName::setPhoneticFirstName(const std::string &value)
201 m_phoneticFirstName = value;
202 m_phoneticFirstNameIsSet = true;
205 void ContactName::unsetPhoneticFirstName()
207 m_phoneticFirstName = "";
208 m_phoneticFirstNameIsSet = false;
211 bool ContactName::getPhoneticFirstNameIsSet() const
213 return m_phoneticFirstNameIsSet;
216 std::string ContactName::getPhoneticLastName() const
218 return m_phoneticLastName;
221 void ContactName::setPhoneticLastName(const std::string &value)
223 m_phoneticLastName = value;
224 m_phoneticLastNameIsSet = true;
227 void ContactName::unsetPhoneticLastName()
229 m_phoneticLastName = "";
230 m_phoneticLastNameIsSet = false;
233 bool ContactName::getPhoneticLastNameIsSet() const
235 return m_phoneticLastNameIsSet;
238 std::string ContactName::getDisplayName() const
240 return m_displayName;
243 void ContactName::setDisplayName(const std::string &value)
245 m_displayName = value;
246 m_displayNameIsSet = true;
249 void ContactName::unsetDisplayName()
252 m_displayNameIsSet = false;
255 bool ContactName::getDisplayNameIsSet() const
257 return m_displayNameIsSet;
260 void ContactName::clear()
263 m_prefixIsSet = false;
266 m_suffixIsSet = false;
269 m_firstNameIsSet = false;
272 m_middleNameIsSet = false;
275 m_lastNameIsSet = false;
277 m_nicknames = StringArrayPtr(new StringArray());
279 m_phoneticFirstName = "";
280 m_phoneticFirstNameIsSet = false;
282 m_phoneticLastName = "";
283 m_phoneticLastNameIsSet = false;
286 m_displayNameIsSet = false;
289 ContactNamePtr ContactName::clone() const
291 ContactNamePtr result(new ContactName());
293 result->m_prefix = m_prefix;
294 result->m_prefixIsSet = m_prefixIsSet;
296 result->m_suffix = m_suffix;
297 result->m_suffixIsSet = m_suffixIsSet;
299 result->m_firstName = m_firstName;
300 result->m_firstNameIsSet = m_firstNameIsSet;
302 result->m_middleName = m_middleName;
303 result->m_middleNameIsSet = m_middleNameIsSet;
305 result->m_lastName = m_lastName;
306 result->m_lastNameIsSet = m_lastNameIsSet;
308 result->m_nicknames = StringArrayPtr(new StringArray());
309 StringArray::iterator nicknameIter;
310 for(nicknameIter = m_nicknames->begin(); nicknameIter != m_nicknames->end(); nicknameIter++)
312 std::string nickname = *nicknameIter;
313 result->m_nicknames->push_back(nickname);
316 result->m_phoneticFirstName = m_phoneticFirstName;
317 result->m_phoneticFirstNameIsSet = m_phoneticFirstNameIsSet;
319 result->m_phoneticLastName = m_phoneticLastName;
320 result->m_phoneticLastNameIsSet = m_phoneticLastNameIsSet;
322 result->m_displayName = m_displayName;
323 result->m_displayNameIsSet = m_displayNameIsSet;
328 void ContactName::setTypesJSArray(bool value, JSObjectRef initValue)
330 is_typesSetJSArray = value;
331 m_typesObj = initValue;
334 JSValueRef ContactName::getTypesJSArray()
336 return m_typesJsValue;
339 JSObjectRef ContactName::getTypesJSObj()
344 bool ContactName::IsTypesSetJSArray() const
346 return is_typesSetJSArray;
349 void ContactName::resetTypesJSObj()
351 if(IsTypesSetJSArray()){
352 JSContextRef contextRef = getContext();
353 JSObjectRef tempJSObject = getTypesJSObj();
354 JSValueUnprotect(contextRef, tempJSObject);
356 is_typesSetJSArray = false;
358 m_typesJsValue = NULL;
361 void ContactName::setContext(JSContextRef contextRef)
363 if(m_context == NULL)
364 m_context = contextRef;
367 JSContextRef ContactName::getContext()