588424265b71d5935379d3d52c246b13134070e0
[framework/osp/social.git] / src / FSclPhoneNumber.cpp
1 //
2 // Open Service Platform
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 * @file         FSclPhoneNumber.cpp
19 * @brief                This is the implementation for PhoneNumber class.
20 *
21 * This file contains definitions of @e PhoneNumber class.
22 */
23
24 #include <FSclPhoneNumber.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27 #include "FScl_PhoneNumberImpl.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::App;
31
32 namespace Tizen { namespace Social
33 {
34
35 PhoneNumber::PhoneNumber(void)
36 {
37         __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl();
38         SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
39 }
40
41 PhoneNumber::PhoneNumber(PhoneNumberType type, const String& number)
42 {
43         __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(type, number);
44         SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 }
46
47 PhoneNumber::PhoneNumber(const PhoneNumber& rhs)
48 {
49         __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(*rhs.__pPhoneNumberImpl);
50         SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 }
52
53 PhoneNumber::~PhoneNumber(void)
54 {
55         delete __pPhoneNumberImpl;
56 }
57
58 PhoneNumber&
59 PhoneNumber::operator =(const PhoneNumber& rhs)
60 {
61         if (this == &rhs)
62         {
63                 return *this;
64         }
65
66         *__pPhoneNumberImpl = *rhs.__pPhoneNumberImpl;
67
68         return *this;
69 }
70
71 bool
72 PhoneNumber::operator ==(const PhoneNumber& rhs) const
73 {
74         return *__pPhoneNumberImpl == *rhs.__pPhoneNumberImpl;
75 }
76
77 bool
78 PhoneNumber::operator !=(const PhoneNumber& rhs) const
79 {
80         return !(*this == rhs);
81 }
82
83 bool
84 PhoneNumber::Equals(const Object& rhs) const
85 {
86         const PhoneNumber* pPhoneNumber = dynamic_cast<const PhoneNumber*>(&rhs);
87         if (pPhoneNumber == null)
88         {
89                 return false;
90         }
91
92         return *this == *pPhoneNumber;
93 }
94
95 int
96 PhoneNumber::GetHashCode(void) const
97 {
98         return __pPhoneNumberImpl->GetHashCode();
99 }
100
101 PhoneNumberType
102 PhoneNumber::GetType(void) const
103 {
104         PhoneNumberType type =  __pPhoneNumberImpl->GetType();
105         if (type == PHONENUMBER_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
106         {
107                 type =  PHONENUMBER_TYPE_OTHER;
108         }
109
110         return type;
111 }
112
113 String
114 PhoneNumber::GetLabel(void) const
115 {
116         return __pPhoneNumberImpl->GetLabel();
117 }
118
119 String
120 PhoneNumber::GetPhoneNumber(void) const
121 {
122         String phoneNumber =  __pPhoneNumberImpl->GetPhoneNumber();
123
124         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
125         {
126                 if (phoneNumber.GetLength() > MAX_PHONE_NUMBER_LENGTH)
127                 {
128                         phoneNumber.SetLength(MAX_PHONE_NUMBER_LENGTH);
129                 }
130         }
131
132         return phoneNumber;
133 }
134
135
136 void
137 PhoneNumber::SetType(PhoneNumberType type)
138 {
139         __pPhoneNumberImpl->SetType(type);
140 }
141
142 void
143 PhoneNumber::SetLabel(const String& label)
144 {
145         __pPhoneNumberImpl->SetLabel(label);
146 }
147
148 result
149 PhoneNumber::SetPhoneNumber(const String& number)
150 {
151         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
152         {
153                 SysTryReturn(NID_SCL, number.GetLength() <= MAX_PHONE_NUMBER_LENGTH,
154                                 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the number exceeds MAX_PHONE_NUMBER_LENGTH.", GetErrorMessage(E_INVALID_ARG));
155         }
156
157         return __pPhoneNumberImpl->SetPhoneNumber(number);
158 }
159
160 }} // Tizen::Social