diff options
Diffstat (limited to 'mobile_src/Contact/ContactAddress.cpp')
-rw-r--r-- | mobile_src/Contact/ContactAddress.cpp | 413 |
1 files changed, 413 insertions, 0 deletions
diff --git a/mobile_src/Contact/ContactAddress.cpp b/mobile_src/Contact/ContactAddress.cpp new file mode 100644 index 0000000..9a0b372 --- /dev/null +++ b/mobile_src/Contact/ContactAddress.cpp @@ -0,0 +1,413 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file ContactAddress.cpp + * @version 0.1 + * @brief + */ + +#include <algorithm> +#include "ContactAddress.h" + +namespace DeviceAPI { +namespace Contact { + +ContactAddress::ContactAddress() : + m_countryIsSet(false), + m_regionIsSet(false), + m_cityIsSet(false), + m_streetAddressIsSet(false), + m_additionalInformationIsSet(false), + m_postalCodeIsSet(false), + m_isDefault(false) +{ + m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray()); + is_typesSetJSArray = false; + m_context = NULL; + m_typesJsValue = NULL; + m_typesObj = NULL; +} + +ContactAddress::~ContactAddress() +{ + if(IsTypesSetJSArray()){ + JSContextRef contextRef = getContext(); + JSObjectRef tempJSObject = getTypesJSObj(); + JSValueUnprotect(contextRef, tempJSObject); + } +} +std::string ContactAddress::getCountry() const +{ + return m_country; +} + +void ContactAddress::setCountry(const std::string &value) +{ + m_country = value; + m_countryIsSet = true; +} + +void ContactAddress::unsetCountry() +{ + m_country = ""; + m_countryIsSet = false; +} + +bool ContactAddress::getCountryIsSet() const +{ + return m_countryIsSet; +} + +std::string ContactAddress::getRegion() const +{ + return m_region; +} + +void ContactAddress::setRegion(const std::string &value) +{ + m_region = value; + m_regionIsSet = true; +} + +void ContactAddress::unsetRegion() +{ + m_region = ""; + m_regionIsSet = false; +} + +bool ContactAddress::getRegionIsSet() const +{ + return m_regionIsSet; +} + +std::string ContactAddress::getCity() const +{ + return m_city; +} + +void ContactAddress::setCity(const std::string &value) +{ + m_city = value; + m_cityIsSet = true; +} + +void ContactAddress::unsetCity() +{ + m_city = ""; + m_cityIsSet = false; +} + +bool ContactAddress::getCityIsSet() const +{ + return m_cityIsSet; +} + +std::string ContactAddress::getStreetAddress() const +{ + return m_streetAddress; +} + +void ContactAddress::setStreetAddress(const std::string &value) +{ + m_streetAddress = value; + m_streetAddressIsSet = true; +} + +void ContactAddress::unsetStreetAddress() +{ + m_streetAddress = ""; + m_streetAddressIsSet = false; +} + +bool ContactAddress::getStreetAddressIsSet() const +{ + return m_streetAddressIsSet; +} + +std::string ContactAddress::getAdditionalInformation() const +{ + return m_additionalInformation; +} + +void ContactAddress::setAdditionalInformation(const std::string &value) +{ + m_additionalInformation = value; + m_additionalInformationIsSet = true; +} + +void ContactAddress::unsetAdditionalInformation() +{ + m_additionalInformation = ""; + m_additionalInformationIsSet = false; +} + +bool ContactAddress::getAdditionalInformationIsSet() const +{ + return m_additionalInformationIsSet; +} + +std::string ContactAddress::getPostalCode() const +{ + return m_postalCode; +} + +void ContactAddress::setPostalCode(const std::string &value) +{ + m_postalCode = value; + m_postalCodeIsSet = true; +} + +void ContactAddress::unsetPostalCode() +{ + m_postalCode = ""; + m_postalCodeIsSet = false; +} + +bool ContactAddress::getPostalCodeIsSet() const +{ + return m_postalCodeIsSet; +} + +bool ContactAddress::getIsDefault() const +{ + return m_isDefault; +} + +void ContactAddress::setIsDefault(const bool &value) +{ + m_isDefault = value; +} + +ContactAddressTypeArrayPtr ContactAddress::getTypes() const +{ + return m_types; +} + +void ContactAddress::setTypes(const ContactAddressTypeArrayPtr &value) +{ + m_types = value; +} + +void ContactAddress::addType(const ContactAddressType &value) +{ + m_types->push_back(value); +} + +bool ContactAddress::isTypeOf(const ContactAddressType &value) const +{ + return std::find(m_types->begin(), m_types->end(), value) != m_types->end(); +} + +int ContactAddress::getTypesNum() const +{ + return m_types->size(); +} + + +bool ContactAddress::compareTo(const ContactAddressPtr &address, + bool includeId, + bool includeTypes) const +{ + //compare basic fields + if ((!includeId) && + m_country == address->getCountry() && + m_region == address->getRegion() && + m_city == address->getCity() && + m_streetAddress == address->getStreetAddress() && + m_additionalInformation == address->getAdditionalInformation() && + m_postalCode == address->getPostalCode()) { + //if not include fields then addresses are equal + if (!includeTypes) { + return true; + } + //if types have different sizes then addresses are different + if (m_types->size() != address->getTypes()->size()) { + return false; + } + //compare each type + for (size_t i = 0; i < address->getTypes()->size(); i++) { + if (!isTypeOf(address->getTypes()->at(i))) { + return false; + } + } + return true; + } + return false; +} + +std::string ContactAddress::getAsSingleString() const +{ + std::string fullAddress; + //add street and street number when not empty + if (!m_streetAddress.empty()) { + fullAddress = m_streetAddress; + } + //add city and postal code when not empty + if (!m_city.empty()) { + if (!fullAddress.empty()) { + fullAddress += " "; + } + if (!m_postalCode.empty()) { + fullAddress += m_postalCode + " " + m_city; + } else { + fullAddress += m_city; + } + } + //add country when not empty + if (!m_country.empty()) { + if (!fullAddress.empty()) { + fullAddress += " " + m_country; + } else { + fullAddress = m_country; + } + } + if (!fullAddress.empty()) { + return fullAddress; + } + //when no data on detailed fields, then return free form field + return ""; +} + +void ContactAddress::clear() +{ + m_country = ""; + m_countryIsSet = false; + + m_region = ""; + m_regionIsSet = false; + + m_city = ""; + m_cityIsSet = false; + + m_streetAddress = ""; + m_streetAddressIsSet = false; + + m_additionalInformation = ""; + m_additionalInformationIsSet = false; + + m_postalCode = ""; + m_postalCodeIsSet = false; + + m_label = ""; + m_labelIsSet = false; + + m_isDefault = false; + + m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray()); +} + +ContactAddressPtr ContactAddress::clone() const +{ + ContactAddressPtr result(new ContactAddress()); + + result->m_country = m_country; + result->m_countryIsSet = m_countryIsSet; + + result->m_region = m_region; + result->m_regionIsSet = m_regionIsSet; + + result->m_city = m_city; + result->m_cityIsSet = m_cityIsSet; + + result->m_streetAddress = m_streetAddress; + result->m_streetAddressIsSet = m_streetAddressIsSet; + + result->m_additionalInformation = m_additionalInformation; + result->m_additionalInformationIsSet = m_additionalInformationIsSet; + + result->m_postalCode = m_postalCode; + result->m_postalCodeIsSet = m_postalCodeIsSet; + + result->m_isDefault = m_isDefault; + + result->m_label = m_label; + result->m_labelIsSet = m_labelIsSet; + + result->m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray()); + ContactAddressTypeArray::iterator typeIter; + for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++) + { + ContactAddressType addressType = *typeIter; + result->m_types->push_back(addressType); + } + + return result; +} + +std::string ContactAddress::getLabel() const +{ + return m_label; +} + +void ContactAddress::setLabel(const std::string &value) +{ + m_label = value; + m_labelIsSet = true; +} + +bool ContactAddress::getLabelIsSet() const +{ + return m_labelIsSet; +} + +void ContactAddress::setTypesJSArray(bool value, JSObjectRef initValue) +{ + is_typesSetJSArray = value; + m_typesObj = initValue; +} + +JSValueRef ContactAddress::getTypesJSArray() +{ + return m_typesJsValue; +} + +JSObjectRef ContactAddress::getTypesJSObj() +{ + return m_typesObj; +} + +bool ContactAddress::IsTypesSetJSArray() const +{ + return is_typesSetJSArray; +} + +void ContactAddress::resetTypesJSObj() +{ + if(IsTypesSetJSArray()){ + JSContextRef contextRef = getContext(); + JSObjectRef tempJSObject = getTypesJSObj(); + JSValueUnprotect(contextRef, tempJSObject); + } + is_typesSetJSArray = false; + m_typesObj = NULL; + m_typesJsValue = NULL; +} + +void ContactAddress::setContext(JSContextRef contextRef) +{ + if(m_context == NULL) + m_context = contextRef; +} + +JSContextRef ContactAddress::getContext() +{ + return m_context; +} + +} // Contact +} // DeviceAPI |