Initialize Tizen 2.3
[framework/osp/social.git] / src / FSclAddressbook.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                FSclAddressbook.cpp
18  * @brief               This is the implementation for Addressbook class.
19  *
20  * This file contains definitions of @e Addressbook class.
21  */
22
23 #include <new>
24 #include <FBaseColIList.h>
25 #include <FBaseResult.h>
26 #include <FBaseString.h>
27 #include <FBaseSysLog.h>
28 #include <FSclAddressbook.h>
29 #include <FSclCategory.h>
30 #include <FSclContact.h>
31 #include <FSclUserProfile.h>
32 #include <FSec_AccessController.h>
33 #include "FScl_AddressbookImpl.h"
34 #include "FScl_CategoryImpl.h"
35 #include "FScl_ContactImpl.h"
36 #include "FScl_RecordImpl.h"
37
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Security;
41
42 namespace Tizen { namespace Social
43 {
44
45 Addressbook::Addressbook(void)
46         : __pAddressbookImpl(null)
47 {
48         //empty body
49 }
50
51 Addressbook::~Addressbook(void)
52 {
53         delete __pAddressbookImpl;
54 }
55
56 result
57 Addressbook::Construct(IRecordEventListener* pListener)
58 {
59         result r = E_SUCCESS;
60
61         SysAssertf(__pAddressbookImpl == null,
62                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63
64         __pAddressbookImpl = new (std::nothrow) _AddressbookImpl();
65         SysTryReturn(NID_SCL, __pAddressbookImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
66
67         r = __pAddressbookImpl->Construct();
68         SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
69
70         if (pListener != null)
71         {
72                 r = __pAddressbookImpl->SetRecordEventListener(pListener);
73                 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
74         }
75
76         return E_SUCCESS;
77
78 CATCH:
79         delete __pAddressbookImpl;
80         __pAddressbookImpl = null;
81
82         return r;
83 }
84
85 result
86 Addressbook::SetEventListener(IAddressbookEventListener* pListener)
87 {
88         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
89         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
90         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
91         SysAssertf(__pAddressbookImpl != null,
92                         "Not yet constructed. Construct() should be called before use.");
93
94         r = __pAddressbookImpl->SetAddressbookEventListener(pListener);
95         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
96
97         return E_SUCCESS;
98 }
99
100 result
101 Addressbook::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
102 {
103         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
104         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
105         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
106         SysAssertf(__pAddressbookImpl != null,
107                         "Not yet constructed. Construct() should be called before use.");
108
109         r = __pAddressbookImpl->SetAddressbookChangeEventListener(pListener);
110         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
111
112         return E_SUCCESS;
113 }
114
115 String
116 Addressbook::GetName(void) const
117 {
118         SysAssertf(__pAddressbookImpl != null,
119                         "Not yet constructed. Construct() should be called before use.");
120
121         return __pAddressbookImpl->GetName();
122 }
123
124 AddressbookId
125 Addressbook::GetId(void) const
126 {
127         SysAssertf(__pAddressbookImpl != null,
128                         "Not yet constructed. Construct() should be called before use.");
129
130         return __pAddressbookImpl->GetId();
131 }
132
133 AccountId
134 Addressbook::GetAccountId(void) const
135 {
136         SysAssertf(__pAddressbookImpl != null,
137                         "Not yet constructed. Construct() should be called before use.");
138
139         return __pAddressbookImpl->GetAccountId();
140 }
141
142 result
143 Addressbook::AddContact(Contact& contact)
144 {
145         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
146         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
147         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
148         SysAssertf(__pAddressbookImpl != null,
149                         "Not yet constructed. Construct() should be called before use.");
150
151         r = __pAddressbookImpl->AddContact(contact);
152         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
153
154         return E_SUCCESS;
155 }
156
157 result
158 Addressbook::AddCategory(Category& category)
159 {
160         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
161         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
162         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
163         SysAssertf(__pAddressbookImpl != null,
164                         "Not yet constructed. Construct() should be called before use.");
165
166         r = __pAddressbookImpl->AddCategory(category);
167         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
168
169         return E_SUCCESS;
170 }
171
172 result
173 Addressbook::RemoveContact(Contact& contact)
174 {
175         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
176         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
177         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
178         SysAssertf(__pAddressbookImpl != null,
179                         "Not yet constructed. Construct() should be called before use.");
180
181         r = __pAddressbookImpl->RemoveContact(contact);
182         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
183
184         return E_SUCCESS;
185 }
186
187 result
188 Addressbook::RemoveContact(RecordId contactId)
189 {
190         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
191         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
192         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
193         SysAssertf(__pAddressbookImpl != null,
194                         "Not yet constructed. Construct() should be called before use.");
195
196         r = __pAddressbookImpl->RemoveContact(contactId);
197         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
198
199         return E_SUCCESS;
200 }
201
202 result
203 Addressbook::RemoveCategory(Category& category)
204 {
205         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
206         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
207         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
208         SysAssertf(__pAddressbookImpl != null,
209                         "Not yet constructed. Construct() should be called before use.");
210
211         r = __pAddressbookImpl->RemoveCategory(category.GetRecordId());
212         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
213
214         _CategoryImpl::GetInstance(category)->Invalidate();
215         _RecordImpl::GetInstance(category)->SetRecordId(INVALID_RECORD_ID);
216
217         return E_SUCCESS;
218 }
219
220 result
221 Addressbook::RemoveCategory(RecordId categoryId)
222 {
223         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
224         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
225         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
226         SysAssertf(__pAddressbookImpl != null,
227                         "Not yet constructed. Construct() should be called before use.");
228
229         r = __pAddressbookImpl->RemoveCategory(categoryId);
230         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
231
232         return E_SUCCESS;
233 }
234
235 result
236 Addressbook::UpdateContact(const Contact& contact)
237 {
238         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
239         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
240         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
241         SysAssertf(__pAddressbookImpl != null,
242                         "Not yet constructed. Construct() should be called before use.");
243
244         r = __pAddressbookImpl->UpdateContact(contact);
245         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
246
247         return E_SUCCESS;
248 }
249
250 result
251 Addressbook::UpdateCategory(const Category& category)
252 {
253         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
254         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
255         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
256         SysAssertf(__pAddressbookImpl != null,
257                         "Not yet constructed. Construct() should be called before use.");
258
259         r = __pAddressbookImpl->UpdateCategory(category);
260         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
261
262         return E_SUCCESS;
263 }
264
265 IList*
266 Addressbook::GetAllContactsN(void) const
267 {
268         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
269         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
270         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
271         SysAssertf(__pAddressbookImpl != null,
272                         "Not yet constructed. Construct() should be called before use.");
273
274         IList* pList = __pAddressbookImpl->GetAllContactsN();
275         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
276
277         return pList;
278 }
279
280 IList*
281 Addressbook::GetContactsByCategoryN(RecordId categoryId) const
282 {
283         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
284         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
285         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
286         SysAssertf(__pAddressbookImpl != null,
287                         "Not yet constructed. Construct() should be called before use.");
288
289         IList* pList = __pAddressbookImpl->GetContactsByCategoryN(categoryId);
290         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
291
292         return pList;
293 }
294
295 result
296 Addressbook::AddMemberToCategory(RecordId categoryId, RecordId contactId)
297 {
298         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
299         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
300         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
301         SysAssertf(__pAddressbookImpl != null,
302                         "Not yet constructed. Construct() should be called before use.");
303
304         r = __pAddressbookImpl->AddMemberToCategory(categoryId, contactId);
305         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
306
307         return E_SUCCESS;
308 }
309
310 result
311 Addressbook::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
312 {
313         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
314         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
315         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
316         SysAssertf(__pAddressbookImpl != null,
317                         "Not yet constructed. Construct() should be called before use.");
318
319         r = __pAddressbookImpl->RemoveMemberFromCategory(categoryId, contactId);
320         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
321
322         return E_SUCCESS;
323 }
324
325 IList*
326 Addressbook::GetAllCategoriesN(void) const
327 {
328         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
329         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
330         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
331         SysAssertf(__pAddressbookImpl != null,
332                         "Not yet constructed. Construct() should be called before use.");
333
334         IList* pList = __pAddressbookImpl->GetAllCategoriesN();
335         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
336
337         return pList;
338 }
339
340 IList*
341 Addressbook::GetCategoriesByContactN(RecordId contactId) const
342 {
343         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
344         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
345         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
346         SysAssertf(__pAddressbookImpl != null,
347                         "Not yet constructed. Construct() should be called before use.");
348
349         IList* pList = __pAddressbookImpl->GetCategoriesByContactN(contactId);
350         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
351
352         return pList;
353 }
354
355 IList*
356 Addressbook::GetContactsN(int pageNo, int countPerPage) const
357 {
358         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
359         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
360         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
361         SysAssertf(__pAddressbookImpl != null,
362                         "Not yet constructed. Construct() should be called before use.");
363
364         IList* pList = __pAddressbookImpl->GetContactsN(pageNo, countPerPage);
365         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
366
367         return pList;
368 }
369
370 IList*
371 Addressbook::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
372 {
373         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
374         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
375         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
376         SysAssertf(__pAddressbookImpl != null,
377                         "Not yet constructed. Construct() should be called before use.");
378
379         IList* pList = __pAddressbookImpl->GetContactsInN(category, pageNo, countPerPage);
380         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
381
382         return pList;
383 }
384
385 IList*
386 Addressbook::SearchContactsByEmailN(const String& email) const
387 {
388         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
389         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
390         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
391         SysAssertf(__pAddressbookImpl != null,
392                         "Not yet constructed. Construct() should be called before use.");
393
394         IList* pList = __pAddressbookImpl->SearchContactsByEmailN(email);
395         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
396
397         return pList;
398 }
399
400 IList*
401 Addressbook::SearchContactsByNameN(const String& name) const
402 {
403         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
404         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
405         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
406         SysAssertf(__pAddressbookImpl != null,
407                         "Not yet constructed. Construct() should be called before use.");
408
409         IList* pList = __pAddressbookImpl->SearchContactsByNameN(name);
410         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
411
412         return pList;
413 }
414
415 IList*
416 Addressbook::SearchContactsByPhoneNumberN(const String& phoneNumber) const
417 {
418         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
419         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
420         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
421         SysAssertf(__pAddressbookImpl != null,
422                         "Not yet constructed. Construct() should be called before use.");
423
424         IList* pList = __pAddressbookImpl->SearchContactsByPhoneNumberN(phoneNumber);
425         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
426
427         return pList;
428 }
429
430 int
431 Addressbook::GetCategoryCount(void) const
432 {
433         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
434         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
435         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
436         SysAssertf(__pAddressbookImpl != null,
437                         "Not yet constructed. Construct() should be called before use.");
438
439         int count = __pAddressbookImpl->GetCategoryCount();
440         SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
441
442         return count;
443 }
444
445 int
446 Addressbook::GetContactCount(void) const
447 {
448         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
449         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
450         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
451         SysAssertf(__pAddressbookImpl != null,
452                         "Not yet constructed. Construct() should be called before use.");
453
454         int count = __pAddressbookImpl->GetContactCount();
455         SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
456
457         return count;
458 }
459
460 Contact*
461 Addressbook::GetContactN(RecordId contactId) const
462 {
463         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
464         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
465         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
466         SysAssertf(__pAddressbookImpl != null,
467                         "Not yet constructed. Construct() should be called before use.");
468
469         Contact* pContact = __pAddressbookImpl->GetContactN(contactId);
470         SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
471
472         return pContact;
473 }
474
475 Category*
476 Addressbook::GetCategoryN(RecordId categoryId) const
477 {
478         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
479         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
480         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
481         SysAssertf(__pAddressbookImpl != null,
482                         "Not yet constructed. Construct() should be called before use.");
483
484         Category* pCategory = __pAddressbookImpl->GetCategoryN(categoryId);
485         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
486
487         return pCategory;
488 }
489
490 int
491 Addressbook::GetLatestVersion(void) const
492 {
493         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
494         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
495         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
496         SysAssertf(__pAddressbookImpl != null,
497                         "Not yet constructed. Construct() should be called before use.");
498
499         int latestVersion = __pAddressbookImpl->GetLatestVersion();
500         SysTryReturn(NID_SCL, latestVersion != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
501
502         return latestVersion;
503 }
504
505 IList*
506 Addressbook::GetChangedContactsAfterN(int version, int& latestVersion) const
507 {
508         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
509         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
510         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
511         SysAssertf(__pAddressbookImpl != null,
512                         "Not yet constructed. Construct() should be called before use.");
513
514         IList* pList = __pAddressbookImpl->GetChangedContactsAfterN(version, latestVersion);
515         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
516
517         return pList;
518 }
519
520 IList*
521 Addressbook::GetChangedCategoriesAfterN(int version, int& latestVersion) const
522 {
523         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
524         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
525         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
526         SysAssertf(__pAddressbookImpl != null,
527                         "Not yet constructed. Construct() should be called before use.");
528
529         IList* pList = __pAddressbookImpl->GetChangedCategoriesAfterN(version, latestVersion);
530         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
531
532         return pList;
533 }
534
535 IList*
536 Addressbook::GetChangedContactInfoListN(int version, int& latestVersion) const
537 {
538         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
539         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
540         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
541         SysAssertf(__pAddressbookImpl != null,
542                         "Not yet constructed. Construct() should be called before use.");
543
544         IList* pList = __pAddressbookImpl->GetChangedContactInfoListN(version, latestVersion);
545         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
546
547         return pList;
548 }
549
550 IList*
551 Addressbook::GetChangedCategoryInfoListN(int version, int& latestVersion) const
552 {
553         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
554         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
555         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
556         SysAssertf(__pAddressbookImpl != null,
557                         "Not yet constructed. Construct() should be called before use.");
558
559         IList* pList = __pAddressbookImpl->GetChangedCategoryInfoListN(version, latestVersion);
560         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
561
562         return pList;
563 }
564
565 result
566 Addressbook::AddContacts(const IList& contactList, IListT<RecordId>* pContactIdList)
567 {
568         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
569         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
570         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
571         SysAssertf(__pAddressbookImpl != null,
572                         "Not yet constructed. Construct() should be called before use.");
573
574         r = __pAddressbookImpl->AddContacts(contactList, pContactIdList);
575
576         return r;
577 }
578
579 result
580 Addressbook::UpdateContacts(const IList& contactList)
581 {
582         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
583         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
584         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
585         SysAssertf(__pAddressbookImpl != null,
586                         "Not yet constructed. Construct() should be called before use.");
587
588         r = __pAddressbookImpl->UpdateContacts(contactList);
589
590         return r;
591 }
592
593 result
594 Addressbook::RemoveContacts(const IListT<RecordId>& contactIdList)
595 {
596         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
597         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
598         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
599         SysAssertf(__pAddressbookImpl != null,
600                         "Not yet constructed. Construct() should be called before use.");
601
602         r = __pAddressbookImpl->RemoveContacts(contactIdList);
603
604         return r;
605 }
606
607 result
608 Addressbook::SetUserProfile(const UserProfile* pUserProfile)
609 {
610         result r = _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_WRITE);
611         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
612         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
613         SysAssertf(__pAddressbookImpl != null,
614                         "Not yet constructed. Construct() should be called before use.");
615
616         r = __pAddressbookImpl->SetUserProfile(pUserProfile);
617         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
618
619         return E_SUCCESS;
620 }
621
622 UserProfile*
623 Addressbook::GetUserProfileN(void) const
624 {
625         result r = _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ);
626         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
627         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
628         SysAssertf(__pAddressbookImpl != null,
629                         "Not yet constructed. Construct() should be called before use.");
630
631         UserProfile* pProfile = __pAddressbookImpl->GetUserProfileN();
632         SysTryReturn(NID_SCL, pProfile != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
633
634         return pProfile;
635 }
636
637 bool
638 Addressbook::IsUserProfileChangedAfter(int version) const
639 {
640         result r = _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ);
641         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
642         SysTryReturn(NID_SCL, r == E_SUCCESS, false, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
643         SysAssertf(__pAddressbookImpl != null,
644                         "Not yet constructed. Construct() should be called before use.");
645
646         bool isChanged = __pAddressbookImpl->IsUserProfileChangedAfter(version);
647         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
648
649         return isChanged;
650 }
651
652 }}  // Tizen::Social