6ba79c2ae63bbdaa23b4df6b0a8971f0e80009c2
[framework/web/wrt-plugins-tizen.git] / src / Contact / ContactPhoneNumber.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        ContactPhoneNumber.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief
23  */
24
25 #include "ContactPhoneNumber.h"
26
27 namespace DeviceAPI {
28 namespace Contact {
29
30 using namespace std;
31
32 ContactPhoneNumber::ContactPhoneNumber() :
33                 m_numberIsSet(false),
34                 m_isDefault(false)
35 {
36         m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
37         is_typesSetJSArray = false;
38         m_context = NULL;
39         m_typesJsValue = NULL;
40         m_typesObj = NULL;
41 }
42
43 ContactPhoneNumber::~ContactPhoneNumber()
44 {
45         if(IsTypesSetJSArray()){
46                 JSContextRef contextRef = getContext();
47                 JSObjectRef tempJSObject = getTypesJSObj();
48                 JSValueUnprotect(contextRef, tempJSObject);
49         }
50 }
51
52 std::string ContactPhoneNumber::getNumber() const
53 {
54         return m_number;
55 }
56
57 void ContactPhoneNumber::setNumber(const std::string &value)
58 {
59         m_number = value;
60         m_numberIsSet = true;
61 }
62
63 void ContactPhoneNumber::unsetNumber()
64 {
65         m_number = "";
66         m_numberIsSet = false;
67 }
68
69 bool ContactPhoneNumber::getNumberIsSet() const
70 {
71         return m_numberIsSet;
72 }
73
74 bool ContactPhoneNumber::getIsDefault() const
75 {
76         return m_isDefault;
77 }
78
79 void ContactPhoneNumber::setIsDefault(const bool &value)
80 {
81         m_isDefault = value;
82 }
83
84 ContactPhoneNumberTypeArrayPtr ContactPhoneNumber::getTypes() const
85 {
86         return m_types;
87 }
88
89 void ContactPhoneNumber::setTypes(const ContactPhoneNumberTypeArrayPtr &value)
90 {
91         m_types = value;
92 }
93
94 void ContactPhoneNumber::addType(const ContactPhoneNumberType value)
95 {
96         m_types->push_back(value);
97 }
98
99 bool ContactPhoneNumber::isTypeOf(const ContactPhoneNumberType value) const
100 {
101         return std::find(m_types->begin(), m_types->end(), value) != m_types->end();
102 }
103
104 int ContactPhoneNumber::getTypesNum() const
105 {
106         return m_types->size();
107 }
108
109 void ContactPhoneNumber::clear()
110 {
111         m_number = "";
112         m_numberIsSet = false;
113
114         m_isDefault = false;
115
116         m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
117 }
118
119 ContactPhoneNumberPtr ContactPhoneNumber::clone() const
120 {
121         ContactPhoneNumberPtr result(new ContactPhoneNumber());
122
123         result->m_number = m_number;
124         result->m_numberIsSet = m_numberIsSet;
125
126         result->m_isDefault = m_isDefault;
127
128         result->m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
129         ContactPhoneNumberTypeArray::iterator typeIter;
130         for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
131         {
132                 ContactPhoneNumberType type = *typeIter;
133                 result->m_types->push_back(type);
134         }
135
136         return result;
137 }
138
139 void ContactPhoneNumber::setTypesJSArray(bool value, JSObjectRef initValue)
140 {
141         is_typesSetJSArray = value;
142         m_typesObj = initValue;
143 }
144
145 JSObjectRef ContactPhoneNumber::getTypesJSObj()
146 {
147         return m_typesObj;
148 }
149
150 JSValueRef ContactPhoneNumber::getTypesJSArray()
151 {
152         return m_typesJsValue;
153 }
154
155 bool ContactPhoneNumber::IsTypesSetJSArray() const
156 {
157         return is_typesSetJSArray;
158 }
159
160 void ContactPhoneNumber::resetTypesJSObj()
161 {
162         if(IsTypesSetJSArray()){
163                 JSContextRef contextRef = getContext();
164                 JSObjectRef tempJSObject = getTypesJSObj();
165                 JSValueUnprotect(contextRef, tempJSObject);
166         }
167         is_typesSetJSArray = false;
168         m_typesObj = NULL;
169         m_typesJsValue = NULL;
170 }
171
172 void ContactPhoneNumber::setContext(JSContextRef contextRef)
173 {
174         if(m_context == NULL)
175                 m_context = contextRef;
176 }
177
178 JSContextRef ContactPhoneNumber::getContext()
179 {
180         return m_context;
181 }
182
183 } // Contact
184 } // DeviceAPI