Merge "Export internal APIs needed by samsung-socil" into tizen_2.1
[framework/osp/social.git] / src / FSclAttendee.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                FSclAttendee.cpp
18  * @brief               This is the implementation for Attendee class.
19  *
20  * This file contains definitions of @e Attendee class.
21  */
22
23 #include <FSclAttendee.h>
24 #include <FBaseResult.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27
28 using namespace Tizen::Base;
29 using namespace Tizen::App;
30
31 namespace Tizen { namespace Social
32 {
33
34 Attendee::Attendee(const String& email)
35         : __email(email)
36         , __attendeeRole(ATTENDEE_ROLE_ATTENDEE)
37         , __attendeeStatus(ATTENDEE_STATUS_NONE)
38         , __pAttendeeImpl(null)
39         , __personId(INVALID_RECORD_ID)
40 {
41         // empty body.
42 }
43
44 Attendee::Attendee(const Attendee& rhs)
45         : __name(rhs.__name)
46         , __email(rhs.__email)
47         , __phoneNumber(rhs.__phoneNumber)
48         , __attendeeRole(rhs.__attendeeRole)
49         , __attendeeStatus(rhs.__attendeeStatus)
50         , __pAttendeeImpl(null)
51         , __personId(rhs.__personId)
52 {
53         // empty body.
54 }
55
56 Attendee::~Attendee(void)
57 {
58         // empty body.
59 }
60
61 Attendee&
62 Attendee::operator =(const Attendee& rhs)
63 {
64         if (this == &rhs)
65         {
66                 return *this;
67         }
68
69         __name = rhs.__name;
70         __email = rhs.__email;
71         __phoneNumber = rhs.__phoneNumber;
72         __attendeeRole = rhs.__attendeeRole;
73         __attendeeStatus = rhs.__attendeeStatus;
74         __personId = rhs.__personId;
75
76         return *this;
77 }
78
79 bool
80 Attendee::operator ==(const Attendee& rhs) const
81 {
82         if ((__name == rhs.__name) &&
83                         (__email == rhs.__email) &&
84                         (__phoneNumber == rhs.__phoneNumber) &&
85                         (__attendeeRole == rhs.__attendeeRole) &&
86                         (__attendeeStatus == rhs.__attendeeStatus) &&
87                         (__personId == rhs.__personId))
88         {
89                 return true;
90         }
91
92         return false;
93 }
94
95 bool
96 Attendee::operator !=(const Attendee& rhs) const
97 {
98         return !(*this == rhs);
99 }
100
101 bool
102 Attendee::Equals(const Object& rhs) const
103 {
104         const Attendee* pAttendee = dynamic_cast<const Attendee*>(&rhs);
105
106         if (pAttendee == null)
107         {
108                 return false;
109         }
110
111         return (*this == *pAttendee);
112 }
113
114 int
115 Attendee::GetHashCode(void) const
116 {
117         int hashCode = 17;
118
119         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __name.GetHashCode();
120         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __email.GetHashCode();
121         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __phoneNumber.GetHashCode();
122         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __attendeeRole;
123         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __attendeeStatus;
124         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __personId;
125
126         return hashCode;
127 }
128
129 String
130 Attendee::GetName(void) const
131 {
132         return __name;
133 }
134
135 String
136 Attendee::GetEmail(void) const
137 {
138         return __email;
139 }
140
141 AttendeeRole
142 Attendee::GetRole(void) const
143 {
144         return __attendeeRole;
145 }
146
147 AttendeeStatus
148 Attendee::GetStatus(void) const
149 {
150         return __attendeeStatus;
151 }
152
153 result
154 Attendee::SetName(const String& name)
155 {
156         SysTryReturnResult(NID_SCL, !name.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. The name is empty.");
157
158         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
159         {
160                 SysTryReturnResult(NID_SCL, name.GetLength() <= MAX_ATTENDEE_NAME_LENGTH,
161                             E_INVALID_ARG, "Invalid argument is used. The length of the name exceeds MAX_ATTENDEE_NAME_LENGTH.");
162         }
163
164         __name = name;
165
166         return E_SUCCESS;
167 }
168
169 result
170 Attendee::SetEmail(const String& email)
171 {
172         SysTryReturnResult(NID_SCL, !email.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. The email is empty.");
173
174         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
175         {
176                 SysTryReturnResult(NID_SCL, email.GetLength() <= MAX_ATTENDEE_EMAIL_LENGTH,
177                                         E_INVALID_ARG, "Invalid argument is used. The length of the email exceeds MAX_ATTENDEE_EMAIL_LENGTH.");
178         }
179
180         __email = email;
181
182         return E_SUCCESS;
183 }
184
185 void
186 Attendee::SetRole(AttendeeRole role)
187 {
188         switch (role)
189         {
190         case ATTENDEE_ROLE_ATTENDEE:
191                 //fall through
192         case ATTENDEE_ROLE_REQUIRED_ATTENDEE:
193                 //fall through
194         case ATTENDEE_ROLE_ORGANIZER:
195                 __attendeeRole = role;
196                 break;
197         default:
198                 __attendeeRole = ATTENDEE_ROLE_ATTENDEE;
199                 break;
200         }
201 }
202
203 void
204 Attendee::SetStatus(AttendeeStatus status)
205 {
206         switch (status)
207         {
208         case ATTENDEE_STATUS_NONE:
209                 //fall through
210         case ATTENDEE_STATUS_NOT_RESPONDED:
211                 //fall through
212         case ATTENDEE_STATUS_ACCEPTED:
213                 //fall through
214         case ATTENDEE_STATUS_DECLINED:
215                 //fall through
216         case ATTENDEE_STATUS_TENTATIVE:
217                 __attendeeStatus = status;
218                 break;
219         default:
220                 __attendeeStatus = ATTENDEE_STATUS_NONE;
221                 break;
222         }
223 }
224
225 void
226 Attendee::SetPhoneNumber(const String& phoneNumber)
227 {
228         __phoneNumber = phoneNumber;
229 }
230
231 String
232 Attendee::GetPhoneNumber(void) const
233 {
234         return __phoneNumber;
235 }
236
237 void
238 Attendee::SetPersonId(PersonId personId)
239 {
240         __personId = personId;
241 }
242
243 PersonId
244 Attendee::GetPersonId(void) const
245 {
246         return __personId;
247 }
248
249 }}      // Tizen::Social