Merge "Export internal APIs needed by samsung-socil" into tizen_2.1
[framework/osp/social.git] / src / FScl_EmailImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 * @file         FScl_EmailImpl.cpp
18 * @brief        This is the implementation for _EmailImpl class.
19 *
20 * This file contains definitions of @e _EmailImpl class.
21 */
22
23 #include <unique_ptr.h>
24 #include <FApp_AppInfo.h>
25 #include <FBaseSysLog.h>
26 #include <FSclEmail.h>
27 #include <FBase_StringConverter.h>
28 #include "FScl_EmailImpl.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Social
34 {
35
36 _EmailImpl::_EmailImpl(void)
37 : __recordId(-1)
38 , __type(EMAIL_TYPE_PERSONAL)
39 {
40
41 }
42
43 _EmailImpl::_EmailImpl(EmailType type, const String& email)
44 : __recordId(-1)
45 , __type(type)
46 {
47         String stringValue = email;
48         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
49         {
50                 if (stringValue.GetLength() > MAX_EMAIL_LENGTH)
51                 {
52                         stringValue.SetLength(MAX_EMAIL_LENGTH);
53                 }
54         }
55
56         __email = stringValue;
57
58 }
59
60 _EmailImpl::_EmailImpl(const _EmailImpl& rhs)
61 {
62         __recordId = rhs.__recordId;
63         __type = rhs.__type;
64         __label = rhs.__label;
65         __email = rhs.__email;
66 }
67
68 _EmailImpl::~_EmailImpl(void)
69 {
70
71 }
72
73
74 _EmailImpl&
75 _EmailImpl::operator =(const _EmailImpl& rhs)
76 {
77         if (this == &rhs)
78         {
79                 return *this;
80         }
81
82         __recordId = rhs.__recordId;
83         __type = rhs.__type;
84         __label = rhs.__label;
85         __email = rhs.__email;
86
87         return *this;
88 }
89
90 bool
91 _EmailImpl::operator ==(const _EmailImpl& rhs) const
92 {
93         if(__type != rhs.__type || __label != rhs.__label || __email != rhs.__email)
94         {
95                 return false;
96         }       
97
98         return true;
99 }
100
101 bool
102 _EmailImpl::operator !=(const _EmailImpl& rhs) const
103 {
104         return !(*this == rhs);
105 }
106
107 bool
108 _EmailImpl::Equals(const Object& rhs) const
109 {
110         const _EmailImpl* pEmailImpl = dynamic_cast<const _EmailImpl*>(&rhs);
111
112         if (pEmailImpl == null)
113         {
114                 return false;
115         }
116
117         return (*this == *pEmailImpl);
118 }
119
120 int
121 _EmailImpl::GetHashCode(void) const
122 {
123         int hashCode = __recordId;
124         hashCode += __type;
125         hashCode += __label.GetHashCode();
126         hashCode += __email.GetHashCode();
127
128         return hashCode;
129 }
130
131 EmailType
132 _EmailImpl::GetType(void) const
133 {
134
135
136         return __type;
137 }
138
139 String
140 _EmailImpl::GetEmail(void) const
141 {
142         return __email;
143 }
144
145 String
146 _EmailImpl::GetLabel(void) const
147 {
148         return __label;
149 }
150
151 void
152 _EmailImpl::SetType(EmailType type)
153 {
154         __type = type;
155 }
156
157 result
158 _EmailImpl::SetEmail(const String& email)
159 {
160         SysTryReturnResult(NID_SCL, !email.IsEmpty(), E_INVALID_ARG, "The email is an empty string.");
161
162
163         __email = email;
164
165         return E_SUCCESS;
166 }
167
168 void
169 _EmailImpl::SetLabel(const String& label)
170 {
171         __label = label;
172 }
173
174 void
175 _EmailImpl::SetRecordId(int recordId)
176 {
177         __recordId = recordId;
178 }
179
180 int
181 _EmailImpl::GetRecordId(void) const
182 {
183         return __recordId;
184 }
185
186 bool
187 _EmailImpl::IsEmpty(void) const
188 {
189         return __email.IsEmpty();
190 }
191
192 const _EmailImpl*
193 _EmailImpl::GetInstance(const Email& email)
194 {
195         return email.__pEmailImpl;
196 }
197
198 _EmailImpl*
199 _EmailImpl::GetInstance(Email& email)
200 {
201         return email.__pEmailImpl;
202 }
203
204
205 }} // Tizen::Social