Fix the boiler plate codes
[framework/osp/social.git] / src / FSclContact.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                FSclContact.cpp
18  * @brief               This is the implementation for Profile class.
19  *
20  * This file contains definitions of @e Contact class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FSclAddress.h>
25 #include <FSclPhoneNumber.h>
26 #include <FSclEmail.h>
27 #include <FSclUrl.h>
28 #include <FSclImAddress.h>
29 #include <FSclOrganization.h>
30 #include <FSclContactEvent.h>
31 #include <FSclRelationship.h>
32 #include <FSclContact.h>
33 #include "FScl_ContactImpl.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Graphics;
38
39 namespace Tizen { namespace Social
40 {
41
42 Contact::Contact(void)
43         : Record(RECORD_TYPE_CONTACT)
44 {
45         __pContactImpl = new (std::nothrow) _ContactImpl();
46         SysTryReturnVoidResult(NID_SCL, __pContactImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
47 }
48
49 Contact::Contact(const Contact& rhs)
50         : Record(rhs)
51 {
52         __pContactImpl = new (std::nothrow) _ContactImpl(*rhs.__pContactImpl);
53         SysTryReturnVoidResult(NID_SCL, __pContactImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
54 }
55
56 Contact::~Contact(void)
57 {
58         delete __pContactImpl;
59 }
60
61 Contact&
62 Contact::operator =(const Contact& rhs)
63 {
64         if (this == &rhs)
65         {
66                 return *this;
67         }
68
69         Record::operator=(rhs);
70
71         *__pContactImpl = *rhs.__pContactImpl;
72
73         return *this;
74 }
75
76 bool
77 Contact::Equals(const Object& rhs) const
78 {
79         const Contact* pContact = dynamic_cast<const Contact*>(&rhs);
80         if (pContact == null)
81         {
82                 return false;
83         }
84
85         if (GetRecordId() == INVALID_RECORD_ID)
86         {
87                 return false;
88         }
89
90         if (GetRecordId() == pContact->GetRecordId())
91         {
92                 return true;
93         }
94
95         return false;
96 }
97
98 int
99 Contact::GetHashCode(void) const
100 {
101         return GetRecordId();
102 }
103
104 PersonId
105 Contact::GetPersonId(void) const
106 {
107         return __pContactImpl->GetPersonId();
108 }
109
110 AddressbookId
111 Contact::GetAddressbookId(void) const
112 {
113         return __pContactImpl->GetAddressbookId();
114 }
115
116 Bitmap*
117 Contact::GetThumbnailN(void) const
118 {
119         Bitmap* pBitmap = __pContactImpl->GetThumbnailN();
120         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121
122         return pBitmap;
123 }
124
125 String
126 Contact::GetThumbnailPath(void) const
127 {
128         return  __pContactImpl->GetThumbnailPath();
129 }
130
131 result
132 Contact::SetThumbnail(const String& filePath)
133 {
134         result r = __pContactImpl->SetThumbnailPath(filePath);
135         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
136
137         return E_SUCCESS;
138 }
139
140 result
141 Contact::GetValue(ContactPropertyId id, String& value) const
142 {
143         result r = __pContactImpl->GetValue(id, value);
144         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
145
146         return E_SUCCESS;
147 }
148
149 result
150 Contact::GetValue(ContactPropertyId id, DateTime& value) const
151 {
152         result r = __pContactImpl->GetValue(id, value);
153         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155         return E_SUCCESS;
156 }
157
158 result
159 Contact::SetValue(ContactPropertyId id, const String& value)
160 {
161         result r = __pContactImpl->SetValue(id, value);
162         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
163
164         return E_SUCCESS;
165 }
166
167 result
168 Contact::SetValue(ContactPropertyId id, const DateTime& value)
169 {
170         result r = __pContactImpl->SetValue(id, value);
171         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
172
173         return E_SUCCESS;
174 }
175
176 result
177 Contact::AddNote(const String& note)
178 {
179         result r = __pContactImpl->AddNote(note);
180         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
181
182         return E_SUCCESS;
183 }
184
185 result
186 Contact::AddNickname(const String& nickname)
187 {
188         result r = __pContactImpl->AddNickname(nickname);
189         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
190
191         return E_SUCCESS;
192 }
193
194 result
195 Contact::AddPhoneNumber(const PhoneNumber& phoneNumber)
196 {
197         result r = __pContactImpl->AddPhoneNumber(phoneNumber);
198         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
199
200         return E_SUCCESS;
201 }
202
203 result
204 Contact::AddEmail(const Email& email)
205 {
206         result r = __pContactImpl->AddEmail(email);
207         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
208
209         return E_SUCCESS;
210 }
211
212 result
213 Contact::AddUrl(const Url& url)
214 {
215         result r = __pContactImpl->AddUrl(url);
216         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
217
218         return E_SUCCESS;
219 }
220
221 result
222 Contact::AddAddress(const Address& address)
223 {
224         result r = __pContactImpl->AddAddress(address);
225         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
226
227         return E_SUCCESS;
228 }
229
230 result
231 Contact::AddImAddress(const ImAddress& imAddress)
232 {
233         result r = __pContactImpl->AddImAddress(imAddress);
234         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
235
236         return E_SUCCESS;
237 }
238
239 result
240 Contact::AddOrganization(const Organization& organization)
241 {
242         result r = __pContactImpl->AddOrganization(organization);
243         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
244
245         return E_SUCCESS;
246 }
247
248 result
249 Contact::AddEvent(const ContactEvent& event)
250 {
251         result r = __pContactImpl->AddEvent(event);
252         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
253
254         return E_SUCCESS;
255 }
256
257 result
258 Contact::AddRelationship(const Relationship& relationship)
259 {
260         result r = __pContactImpl->AddRelationship(relationship);
261         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
262
263         return E_SUCCESS;
264 }
265
266 result
267 Contact::RemoveAt(ContactMultiPropertyId id, int index)
268 {
269         result r = __pContactImpl->RemoveAt(id, index);
270         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
271
272         return E_SUCCESS;
273 }
274
275 IList*
276 Contact::GetValuesN(ContactMultiPropertyId id) const
277 {
278         IList* pList = __pContactImpl->GetValuesN(id);
279         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
280
281         return pList;
282 }
283
284 result
285 Contact::SetNoteAt(int index, const String& note)
286 {
287         result r = __pContactImpl->SetNoteAt(index, note);
288         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
289
290         return E_SUCCESS;
291 }
292
293 result
294 Contact::SetNicknameAt(int index, const String& nickname)
295 {
296         result r = __pContactImpl->SetNicknameAt(index, nickname);
297         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
298
299         return E_SUCCESS;
300 }
301
302 result
303 Contact::SetPhoneNumberAt(int index, const PhoneNumber& phoneNumber)
304 {
305         result r = __pContactImpl->SetPhoneNumberAt(index, phoneNumber);
306         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
307
308         return E_SUCCESS;
309 }
310
311 result
312 Contact::SetEmailAt(int index, const Email& email)
313 {
314         result r = __pContactImpl->SetEmailAt(index, email);
315         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
316
317         return E_SUCCESS;
318 }
319
320 result
321 Contact::SetEventAt(int index, const ContactEvent& event)
322 {
323         result r = __pContactImpl->SetEventAt(index, event);
324         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
325
326         return E_SUCCESS;
327 }
328
329 result
330 Contact::SetOrganizationAt(int index, const Organization& organization)
331 {
332         result r = __pContactImpl->SetOrganizationAt(index, organization);
333         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
334
335         return E_SUCCESS;
336 }
337
338 result
339 Contact::SetRelationshipAt(int index, const Relationship& relationship)
340 {
341         result r = __pContactImpl->SetRelationshipAt(index, relationship);
342         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
343
344         return E_SUCCESS;
345 }
346
347 result
348 Contact::SetUrlAt(int index, const Url& url)
349 {
350         result r = __pContactImpl->SetUrlAt(index, url);
351         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
352
353         return E_SUCCESS;
354 }
355
356 result
357 Contact::SetAddressAt(int index, const Address& address)
358 {
359         result r = __pContactImpl->SetAddressAt(index, address);
360         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
361
362         return E_SUCCESS;
363 }
364
365 result
366 Contact::SetImAddressAt(int index, const ImAddress& imAddress)
367 {
368         result r = __pContactImpl->SetImAddressAt(index, imAddress);
369         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
370
371         return E_SUCCESS;
372 }
373
374 bool
375 Contact::IsFavorite(void) const
376 {
377         return __pContactImpl->IsFavorite();
378 }
379
380 void
381 Contact::SetAsFavorite(bool isFavorite)
382 {
383         return __pContactImpl->SetAsFavorite(isFavorite);
384 }
385
386 }} // Tizen::Social