Initialize Tizen 2.3
[framework/osp/social.git] / src / FSclPerson.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                FSclPerson.cpp
18  * @brief               This is the implementation for Profile class.
19  *
20  * This file contains definitions of @e Person class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FSclPerson.h>
25 #include <FSclPhoneNumber.h>
26 #include <FSclEmail.h>
27 #include <FSec_AccessController.h>
28 #include "FScl_PersonImpl.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace Social
35 {
36
37 Person::Person(void)
38 {
39         _PersonImpl* pPersonImpl = new (std::nothrow) _PersonImpl();
40         SysTryReturnVoidResult(NID_SCL, pPersonImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(GetLastResult()));
41
42         __pPersonImpl = pPersonImpl;
43 }
44
45 Person::~Person(void)
46 {
47         delete __pPersonImpl;
48 }
49
50 bool
51 Person::Equals(const Object& rhs) const
52 {
53         const Person* pPerson = dynamic_cast<const Person*>(&rhs);
54         if (pPerson == null)
55         {
56                 return false;
57         }
58
59         return __pPersonImpl->Equals(*pPerson->__pPersonImpl);;
60 }
61
62 int
63 Person::GetHashCode(void) const
64 {
65         return __pPersonImpl->GetHashCode();
66 }
67
68 String
69 Person::GetDisplayName(void) const
70 {
71         return __pPersonImpl->GetDisplayName();
72 }
73
74 PersonId
75 Person::GetId(void) const
76 {
77         return __pPersonImpl->GetId();
78 }
79
80 result
81 Person::SetAsFavorite(bool isFavorite)
82 {
83         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
84         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
85         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
86
87         return __pPersonImpl->SetAsFavorite(isFavorite);
88 }
89
90 bool
91 Person::IsFavorite(void) const
92 {
93         return __pPersonImpl->IsFavorite();
94 }
95
96 String
97 Person::GetThumbnailPath(void) const
98 {
99         return  __pPersonImpl->GetThumbnailPath();
100 }
101
102 String
103 Person::GetRingtonePath(void) const
104 {
105         return __pPersonImpl->GetRingtonePath();
106 }
107
108 bool
109 Person::HasPhoneNumber(void) const
110 {
111         return __pPersonImpl->HasPhoneNumber();
112 }
113
114 bool
115 Person::HasEmail(void) const
116 {
117         return __pPersonImpl->HasEmail();
118 }
119
120 IListT<AccountId>*
121 Person::GetAccountIdsN(void) const
122 {
123         return __pPersonImpl->GetAccountIdsN();
124 }
125
126 result
127 Person::SetAsPrimaryPhoneNumber(const PhoneNumber& phoneNumber)
128 {
129         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
130         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
131         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
132
133         return __pPersonImpl->SetAsPrimaryPhoneNumber(phoneNumber);     
134 }
135
136 result
137 Person::SetAsPrimaryEmail(const Email& email)
138 {
139         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
140         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
141         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
142
143         return __pPersonImpl->SetAsPrimaryEmail(email);
144 }
145
146 PhoneNumber
147 Person::GetPrimaryPhoneNumber(void) const
148 {
149         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
150         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
151         SysTryReturn(NID_SCL, r == E_SUCCESS, PhoneNumber(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
152
153         return __pPersonImpl->GetPrimaryPhoneNumber();
154 }
155
156 Email
157 Person::GetPrimaryEmail(void) const
158 {
159         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
160         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
161         SysTryReturn(NID_SCL, r == E_SUCCESS, Email(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
162
163         return __pPersonImpl->GetPrimaryEmail();
164 }
165
166 }} // Tizen::Social