ce6a4b0a3c3b799b66d920dfc6690fa3be4aa3c0
[framework/web/wrt-plugins-tizen.git] / src / Contact / ContactName.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        ContactName.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief
23  */
24
25 #include "ContactName.h"
26
27 namespace DeviceAPI {
28 namespace Contact {
29
30 ContactName::ContactName() :
31                 m_prefixIsSet(false),
32                 m_suffixIsSet(false),
33                 m_firstNameIsSet(false),
34                 m_middleNameIsSet(false),
35                 m_lastNameIsSet(false),
36                 m_phoneticFirstNameIsSet(false),
37                 m_phoneticLastNameIsSet(false),
38                 m_displayNameIsSet(false)
39 {
40         m_nicknames = StringArrayPtr(new StringArray());
41         is_typesSetJSArray = false;
42         m_context = NULL;
43         m_typesJsValue = NULL;
44         m_typesObj = NULL;
45 }
46
47 ContactName::~ContactName()
48 {
49         if(IsTypesSetJSArray()){
50                 JSContextRef contextRef = getContext();
51                 JSObjectRef tempJSObject = getTypesJSObj();
52                 JSValueUnprotect(contextRef, tempJSObject);
53         }
54 }
55
56 std::string ContactName::getPrefix() const
57 {
58         return m_prefix;
59 }
60
61 void ContactName::setPrefix(const std::string &value)
62 {
63         m_prefix = value;
64         m_prefixIsSet = true;
65 }
66
67 void ContactName::unsetPrefix()
68 {
69         m_prefix = "";
70         m_prefixIsSet = false;
71 }
72
73 bool ContactName::getPrefixIsSet() const
74 {
75         return m_prefixIsSet;
76 }
77
78 std::string ContactName::getSuffix() const
79 {
80         return m_suffix;
81 }
82
83 void ContactName::setSuffix(const std::string &value)
84 {
85         m_suffix = value;
86         m_suffixIsSet = true;
87 }
88
89 void ContactName::unsetSuffix()
90 {
91         m_suffix = "";
92         m_suffixIsSet = false;
93 }
94
95 bool ContactName::getSuffixIsSet() const
96 {
97         return m_suffixIsSet;
98 }
99
100 std::string ContactName::getFirstName() const
101 {
102         return m_firstName;
103 }
104
105 void ContactName::setFirstName(const std::string &value)
106 {
107         m_firstName = value;
108         m_firstNameIsSet = true;
109 }
110
111 void ContactName::unsetFirstName()
112 {
113         m_firstName = "";
114         m_firstNameIsSet = false;
115 }
116
117 bool ContactName::getFirstNameIsSet() const
118 {
119         return m_firstNameIsSet;
120 }
121
122 std::string ContactName::getMiddleName() const
123 {
124         return m_middleName;
125 }
126
127 void ContactName::setMiddleName(const std::string &value)
128 {
129         m_middleName = value;
130         m_middleNameIsSet = true;
131 }
132
133 void ContactName::unsetMiddleName()
134 {
135         m_middleName = "";
136         m_middleNameIsSet = false;
137 }
138
139 bool ContactName::getMiddleNameIsSet() const
140 {
141         return m_middleNameIsSet;
142 }
143
144 std::string ContactName::getLastName() const
145 {
146         return m_lastName;
147 }
148
149 void ContactName::setLastName(const std::string &value)
150 {
151         m_lastName = value;
152         m_lastNameIsSet = true;
153 }
154
155 void ContactName::unsetLastName()
156 {
157         m_lastName = "";
158         m_lastNameIsSet = false;
159 }
160
161 bool ContactName::getLastNameIsSet() const
162 {
163         return m_lastNameIsSet;
164 }
165
166 StringArrayPtr ContactName::getNicknames() const
167 {
168         return m_nicknames;
169 }
170
171 void ContactName::setNicknames(const StringArrayPtr &value)
172 {
173         if(value == NULL)
174                 m_nicknames = StringArrayPtr(new StringArray());
175         else
176                 m_nicknames = value;
177 }
178
179 void ContactName::addNickname(const std::string &value)
180 {
181         m_nicknames->push_back(value);
182 }
183
184 void ContactName::clearNicknames()
185 {
186         m_nicknames->clear();
187 }
188
189 int ContactName::getNicknamesNum() const
190 {
191         return m_nicknames->size();
192 }
193
194 std::string ContactName::getPhoneticFirstName() const
195 {
196         return m_phoneticFirstName;
197 }
198
199 void ContactName::setPhoneticFirstName(const std::string &value)
200 {
201         m_phoneticFirstName = value;
202         m_phoneticFirstNameIsSet = true;
203 }
204
205 void ContactName::unsetPhoneticFirstName()
206 {
207         m_phoneticFirstName = "";
208         m_phoneticFirstNameIsSet = false;
209 }
210
211 bool ContactName::getPhoneticFirstNameIsSet() const
212 {
213         return m_phoneticFirstNameIsSet;
214 }
215
216 std::string ContactName::getPhoneticLastName() const
217 {
218         return m_phoneticLastName;
219 }
220
221 void ContactName::setPhoneticLastName(const std::string &value)
222 {
223         m_phoneticLastName = value;
224         m_phoneticLastNameIsSet = true;
225 }
226
227 void ContactName::unsetPhoneticLastName()
228 {
229         m_phoneticLastName = "";
230         m_phoneticLastNameIsSet = false;
231 }
232
233 bool ContactName::getPhoneticLastNameIsSet() const
234 {
235         return m_phoneticLastNameIsSet;
236 }
237
238 std::string ContactName::getDisplayName() const
239 {
240         return m_displayName;
241 }
242
243 void ContactName::setDisplayName(const std::string &value)
244 {
245         m_displayName = value;
246         m_displayNameIsSet = true;
247 }
248
249 void ContactName::unsetDisplayName()
250 {
251         m_displayName = "";
252         m_displayNameIsSet = false;
253 }
254
255 bool ContactName::getDisplayNameIsSet() const
256 {
257         return m_displayNameIsSet;
258 }
259
260 void ContactName::clear()
261 {
262         m_prefix = "";
263         m_prefixIsSet = false;
264
265         m_suffix = "";
266         m_suffixIsSet = false;
267
268         m_firstName = "";
269         m_firstNameIsSet = false;
270
271         m_middleName = "";
272         m_middleNameIsSet = false;
273
274         m_lastName = "";
275         m_lastNameIsSet = false;
276
277         m_nicknames = StringArrayPtr(new StringArray());
278
279         m_phoneticFirstName = "";
280         m_phoneticFirstNameIsSet = false;
281
282         m_phoneticLastName = "";
283         m_phoneticLastNameIsSet = false;
284
285         m_displayName = "";
286         m_displayNameIsSet = false;
287 }
288
289 ContactNamePtr ContactName::clone() const
290 {
291         ContactNamePtr result(new ContactName());
292
293         result->m_prefix = m_prefix;
294         result->m_prefixIsSet = m_prefixIsSet;
295
296         result->m_suffix = m_suffix;
297         result->m_suffixIsSet = m_suffixIsSet;
298
299         result->m_firstName = m_firstName;
300         result->m_firstNameIsSet = m_firstNameIsSet;
301
302         result->m_middleName = m_middleName;
303         result->m_middleNameIsSet = m_middleNameIsSet;
304
305         result->m_lastName = m_lastName;
306         result->m_lastNameIsSet = m_lastNameIsSet;
307
308         result->m_nicknames = StringArrayPtr(new StringArray());
309         StringArray::iterator nicknameIter;
310         for(nicknameIter = m_nicknames->begin(); nicknameIter != m_nicknames->end(); nicknameIter++)
311         {
312                 std::string nickname = *nicknameIter;
313                 result->m_nicknames->push_back(nickname);
314         }
315
316         result->m_phoneticFirstName = m_phoneticFirstName;
317         result->m_phoneticFirstNameIsSet = m_phoneticFirstNameIsSet;
318
319         result->m_phoneticLastName = m_phoneticLastName;
320         result->m_phoneticLastNameIsSet = m_phoneticLastNameIsSet;
321
322         result->m_displayName = m_displayName;
323         result->m_displayNameIsSet = m_displayNameIsSet;
324
325         return result;
326 }
327
328 void ContactName::setTypesJSArray(bool value, JSObjectRef initValue)
329 {
330         is_typesSetJSArray = value;
331         m_typesObj = initValue;
332 }
333
334 JSValueRef ContactName::getTypesJSArray()
335 {
336         return m_typesJsValue;
337 }
338
339 JSObjectRef ContactName::getTypesJSObj()
340 {
341         return m_typesObj;
342 }
343
344 bool ContactName::IsTypesSetJSArray() const
345 {
346         return is_typesSetJSArray;
347 }
348
349 void ContactName::resetTypesJSObj()
350 {
351         if(IsTypesSetJSArray()){
352                 JSContextRef contextRef = getContext();
353                 JSObjectRef tempJSObject = getTypesJSObj();
354                 JSValueUnprotect(contextRef, tempJSObject);
355         }
356         is_typesSetJSArray = false;
357         m_typesObj = NULL;
358         m_typesJsValue = NULL;
359 }
360
361 void ContactName::setContext(JSContextRef contextRef)
362 {
363         if(m_context == NULL)
364                 m_context = contextRef;
365 }
366
367 JSContextRef ContactName::getContext()
368 {
369         return m_context;
370 }
371
372 } // Contact
373 } // DeviceAPI