tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / API / Contact / ContactAddress.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  *
18  * @file        ContactEmail.cpp
19  * @author      Lukasz Marek (l.marek@samsung.com)
20  * @version     0.1
21  *
22  */
23
24 #include <algorithm>
25 #include "ContactAddress.h"
26
27 namespace WrtDeviceApis {
28 namespace Contact {
29 namespace Api {
30
31 ContactAddress::ContactAddress() :
32     //initialize fields
33     m_id(-1),
34     m_countryIsSet(false),
35     m_regionIsSet(false),
36     m_countyIsSet(false),
37     m_cityIsSet(false),
38     m_streetIsSet(false),
39     m_streetNumberIsSet(false),
40     m_premisesIsSet(false),
41     m_additionalInformationIsSet(false),
42     m_postalCodeIsSet(false)
43 {
44     //nothing to do
45 }
46
47 ContactAddress::~ContactAddress()
48 {
49     //nothing to do
50 }
51
52 bool ContactAddress::compareTo(const ContactAddressPtr &address,
53         bool includeId,
54         bool includeTypes) const
55 {
56     //compare basic fields
57     if ((!includeId || m_id == address->getId()) &&
58         m_country == address->getCountry() &&
59         m_region == address->getRegion() &&
60         m_county == address->getCounty() &&
61         m_city == address->getCity() &&
62         m_street == address->getStreet() &&
63         m_streetNumber == address->getStreetNumber() &&
64         m_premises == address->getPremises() &&
65         m_additionalInformation == address->getAdditionalInformation() &&
66         m_postalCode == address->getPostalCode()) {
67         //if not include fields then addresses are equal
68         if (!includeTypes) {
69             return true;
70         }
71         //if types have different sizes then addresses are different
72         if (m_types.size() != address->getTypes().size()) {
73             return false;
74         }
75         //compare each type
76         for (size_t i = 0; i < address->getTypes().size(); i++) {
77             if (!isTypeOf(address->getTypes()[i])) {
78                 return false;
79             }
80         }
81         return true;
82     }
83     return false;
84 }
85
86 ContactAddressPtr ContactAddress::clone() const
87 {
88     //clone object by using copy constructors
89     return ContactAddressPtr(new ContactAddress(*this));
90 }
91
92 std::string ContactAddress::getAsSingleString() const
93 {
94     std::string fullAddress;
95     //add street and street number when not empty
96     if (!m_street.empty()) {
97         fullAddress = m_street;
98         if (!m_streetNumber.empty()) {
99             fullAddress += " " + m_streetNumber;
100         }
101     }
102     //add city and postal code when not empty
103     if (!m_city.empty()) {
104         if (!fullAddress.empty()) {
105             fullAddress += " ";
106         }
107         if (!m_postalCode.empty()) {
108             fullAddress += m_postalCode + " " + m_city;
109         } else {
110             fullAddress += m_city;
111         }
112     }
113     //add country when not empty
114     if (!m_country.empty()) {
115         if (!fullAddress.empty()) {
116             fullAddress += " " + m_country;
117         } else {
118             fullAddress = m_country;
119         }
120     }
121     if (!fullAddress.empty()) {
122         return fullAddress;
123     }
124     //when no data on detailed fields, then return free form field
125     return m_address;
126 }
127
128 std::string ContactAddress::getAddress() const
129 {
130     //return free form field for address
131     return m_address;
132 }
133
134 void ContactAddress::setAddress(const std::string &value)
135 {
136     //set free form field for address
137     m_address = value;
138 }
139
140 int ContactAddress::getId() const
141 {
142     //return id of address record
143     return m_id;
144 }
145
146 void ContactAddress::setId(int value)
147 {
148     //set id of address record
149     m_id = value;
150 }
151
152 std::string ContactAddress::getCountry() const
153 {
154     //return country
155     return m_country;
156 }
157
158 void ContactAddress::setCountry(const std::string &value)
159 {
160     //set new contry
161     m_country = value;
162     //mark country as set
163     m_countryIsSet = true;
164 }
165
166 std::string ContactAddress::getRegion() const
167 {
168     //return region
169     return m_region;
170 }
171
172 void ContactAddress::setRegion(const std::string &value)
173 {
174     //set new region
175     m_region = value;
176     //mark region as set
177     m_regionIsSet = true;
178 }
179
180 std::string ContactAddress::getCounty() const
181 {
182     //return county
183     return m_county;
184 }
185
186 void ContactAddress::setCounty(const std::string &value)
187 {
188     //set new county
189     m_county = value;
190     //set county as set
191     m_countyIsSet = true;
192 }
193
194 std::string ContactAddress::getCity() const
195 {
196     //return city
197     return m_city;
198 }
199
200 void ContactAddress::setCity(const std::string &value)
201 {
202     //set new city
203     m_city = value;
204     //set city as marked
205     m_cityIsSet = true;
206 }
207
208 std::string ContactAddress::getStreet() const
209 {
210     //return street
211     return m_street;
212 }
213
214 void ContactAddress::setStreet(const std::string &value)
215 {
216     //set street
217     m_street = value;
218     //mark streen as set
219     m_streetIsSet = true;
220 }
221
222 std::string ContactAddress::getStreetNumber() const
223 {
224     //return street number
225     return m_streetNumber;
226 }
227
228 void ContactAddress::setStreetNumber(const std::string &value)
229 {
230     //set street number
231     m_streetNumber = value;
232     //mark streen number as set
233     m_streetNumberIsSet = true;
234 }
235
236 std::string ContactAddress::getPremises() const
237 {
238     //return premises
239     return m_premises;
240 }
241
242 void ContactAddress::setPremises(const std::string &value)
243 {
244     //set premises
245     m_premises = value;
246     //mark premises as set
247     m_premisesIsSet = true;
248 }
249
250 std::string ContactAddress::getAdditionalInformation() const
251 {
252     //return additional information
253     return m_additionalInformation;
254 }
255
256 void ContactAddress::setAdditionalInformation(const std::string &value)
257 {
258     //set additional information
259     m_additionalInformation = value;
260     //mark additional information as set
261     m_additionalInformationIsSet = true;
262 }
263
264 std::string ContactAddress::getPostalCode() const
265 {
266     //returns postal code
267     return m_postalCode;
268 }
269
270 void ContactAddress::setPostalCode(const std::string &value)
271 {
272     //set new postal code
273     m_postalCode = value;
274     //mark postal code as set
275     m_postalCodeIsSet = true;
276 }
277
278 std::vector<ContactAddress::ContactAddressType> ContactAddress::getTypes()
279 const
280 {
281     //return address types
282     return m_types;
283 }
284
285 void ContactAddress::addType(const ContactAddressType value)
286 {
287     //add new type to set
288     m_types.push_back(value);
289 }
290
291 void ContactAddress::setTypes(const std::vector<ContactAddressType> &value)
292 {
293     //set types
294     m_types = value;
295 }
296
297 bool ContactAddress::isTypeOf(const ContactAddressType value) const
298 {
299     //return true when address is type of type passed as argument
300     return std::find(m_types.begin(), m_types.end(), value) != m_types.end();
301 }
302
303 void ContactAddress::setTypeFilter(const ContactAddressType value)
304 {
305     //clear existing types and add new one
306     m_types.clear();
307     m_types.push_back(value);
308 }
309
310 ContactAddress::ContactAddressType ContactAddress::getTypeFilter() const
311 {
312     //return first type or undefined when non set
313     return m_types.size() == 0 ? CONTACT_ADDRESS_TYPE_PREF : m_types[0];
314 }
315
316 bool ContactAddress::getCountryIsSet() const
317 {
318     //returns true when contry is set
319     return m_countryIsSet;
320 }
321
322 bool ContactAddress::getRegionIsSet() const
323 {
324     //returns true when region is set
325     return m_regionIsSet;
326 }
327
328 bool ContactAddress::getCountyIsSet() const
329 {
330     //returns true when county is set
331     return m_countyIsSet;
332 }
333
334 bool ContactAddress::getCityIsSet() const
335 {
336     //returns true when city is set
337     return m_cityIsSet;
338 }
339
340 bool ContactAddress::getStreetIsSet() const
341 {
342     //returns true when street is set
343     return m_streetIsSet;
344 }
345
346 bool ContactAddress::getStreetNumberIsSet() const
347 {
348     //returns true when street number is set
349     return m_streetNumberIsSet;
350 }
351
352 bool ContactAddress::getPremisesIsSet() const
353 {
354     //returns true when premises is set
355     return m_premisesIsSet;
356 }
357
358 bool ContactAddress::getAdditionalInformationIsSet() const
359 {
360     //returns true when additional information is set
361     return m_additionalInformationIsSet;
362 }
363
364 bool ContactAddress::getPostalCodeIsSet() const
365 {
366     //returns true when postal code is set
367     return m_postalCodeIsSet;
368 }
369
370 }
371 }
372 }