Fix for CompatTC Fail
[framework/osp/social.git] / src / FSclEmail.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         FSclEmail.cpp
18 * @brief        This is the implementation for Email class.
19 *
20 * This file contains definitions of @e Email class.
21 */
22
23 #include <FSclEmail.h>
24 #include <FApp_AppInfo.h>
25 #include <FBaseSysLog.h>
26 #include "FScl_EmailImpl.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30
31 namespace Tizen { namespace Social
32 {
33
34 Email::Email(void)
35 {
36         __pEmailImpl = new (std::nothrow) _EmailImpl();
37         SysTryReturnVoidResult(NID_SCL, __pEmailImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
38 }
39
40 Email::Email(EmailType type, const String& email)
41 {
42         __pEmailImpl = new (std::nothrow) _EmailImpl(type, email);
43         SysTryReturnVoidResult(NID_SCL, __pEmailImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
44 }
45
46 Email::Email(const Email& rhs)
47 {
48         __pEmailImpl = new (std::nothrow) _EmailImpl(*rhs.__pEmailImpl);
49         SysTryReturnVoidResult(NID_SCL, __pEmailImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
50 }
51
52 Email::~Email(void)
53 {
54         delete __pEmailImpl;
55 }
56
57 Email&
58 Email::operator =(const Email& rhs)
59 {
60         if (this == &rhs)
61         {
62                 return *this;
63         }
64
65         *__pEmailImpl = *rhs.__pEmailImpl;
66
67         return *this;
68 }
69
70 bool
71 Email::operator ==(const Email& rhs) const
72 {
73         return *__pEmailImpl == *rhs.__pEmailImpl;
74 }
75
76 bool
77 Email::operator !=(const Email& rhs) const
78 {
79         return !(*this == rhs);
80 }
81
82 bool
83 Email::Equals(const Object& rhs) const
84 {
85         const Email* pEmail = dynamic_cast<const Email*>(&rhs);
86
87         if (pEmail == null)
88         {
89                 return false;
90         }
91
92         return __pEmailImpl->Equals(*pEmail->__pEmailImpl);
93 }
94
95 int
96 Email::GetHashCode(void) const
97 {
98         return __pEmailImpl->GetHashCode();
99 }
100
101 EmailType
102 Email::GetType(void) const
103 {
104         EmailType type = __pEmailImpl->GetType();
105
106         if (type == EMAIL_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
107         {
108                 type =  EMAIL_TYPE_OTHER;
109         }
110
111         return type;
112 }
113
114 String
115 Email::GetLabel(void) const
116 {
117         return __pEmailImpl->GetLabel();
118 }
119
120 String
121 Email::GetEmail(void) const
122 {
123         String email = __pEmailImpl->GetEmail();
124
125         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
126         {
127                 if (email.GetLength() > MAX_EMAIL_LENGTH)
128                 {
129                         email.SetLength(MAX_EMAIL_LENGTH);
130                 }
131         }
132
133         return email;
134 }
135
136 void
137 Email::SetType(EmailType type)
138 {
139         return __pEmailImpl->SetType(type);
140 }
141
142 void
143 Email::SetLabel(const String& label)
144 {
145         return __pEmailImpl->SetLabel(label);
146 }
147
148 result
149 Email::SetEmail(const String& email)
150 {
151         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
152         {
153                 SysTryReturnResult(NID_SCL, email.GetLength() <= MAX_EMAIL_LENGTH, E_INVALID_ARG, "The length of the email exceeds the max length.");
154         }
155
156         return __pEmailImpl->SetEmail(email);
157 }
158
159 }} // Tizen::Social