Fixed update instance
[framework/osp/social.git] / src / FSclEmail.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18 * @file         FSclEmail.cpp
19 * @brief        This is the implementation for Email class.
20 *
21 * This file contains definitions of @e Email class.
22 */
23
24 #include <FSclEmail.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseSysLog.h>
27 #include "FScl_EmailImpl.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Social
33 {
34
35 Email::Email(void)
36 {
37         __pEmailImpl = new (std::nothrow) _EmailImpl();
38         SysTryReturnVoidResult(NID_SCL, __pEmailImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
39 }
40
41 Email::Email(EmailType type, const String& email)
42 {
43         __pEmailImpl = new (std::nothrow) _EmailImpl(type, email);
44         SysTryReturnVoidResult(NID_SCL, __pEmailImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
45 }
46
47 Email::Email(const Email& rhs)
48 {
49         __pEmailImpl = new (std::nothrow) _EmailImpl(*rhs.__pEmailImpl);
50         SysTryReturnVoidResult(NID_SCL, __pEmailImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
51 }
52
53 Email::~Email(void)
54 {
55         delete __pEmailImpl;
56 }
57
58 Email&
59 Email::operator =(const Email& rhs)
60 {
61         if (this == &rhs)
62         {
63                 return *this;
64         }
65
66         *__pEmailImpl = *rhs.__pEmailImpl;
67
68         return *this;
69 }
70
71 bool
72 Email::operator ==(const Email& rhs) const
73 {
74         return *__pEmailImpl == *rhs.__pEmailImpl;
75 }
76
77 bool
78 Email::operator !=(const Email& rhs) const
79 {
80         return !(*this == rhs);
81 }
82
83 bool
84 Email::Equals(const Object& rhs) const
85 {
86         const Email* pEmail = dynamic_cast<const Email*>(&rhs);
87
88         if (pEmail == null)
89         {
90                 return false;
91         }
92
93         return __pEmailImpl->Equals(*pEmail->__pEmailImpl);
94 }
95
96 int
97 Email::GetHashCode(void) const
98 {
99         return __pEmailImpl->GetHashCode();
100 }
101
102 EmailType
103 Email::GetType(void) const
104 {
105         EmailType type = __pEmailImpl->GetType();
106
107         if (type == EMAIL_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
108         {
109                 type =  EMAIL_TYPE_OTHER;
110         }
111
112         return type;
113 }
114
115 String
116 Email::GetLabel(void) const
117 {
118         return __pEmailImpl->GetLabel();
119 }
120
121 String
122 Email::GetEmail(void) const
123 {
124         String email = __pEmailImpl->GetEmail();
125
126         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
127         {
128                 if (email.GetLength() > MAX_EMAIL_LENGTH)
129                 {
130                         email.SetLength(MAX_EMAIL_LENGTH);
131                 }
132         }
133
134         return email;
135 }
136
137 void
138 Email::SetType(EmailType type)
139 {
140         return __pEmailImpl->SetType(type);
141 }
142
143 void
144 Email::SetLabel(const String& label)
145 {
146         return __pEmailImpl->SetLabel(label);
147 }
148
149 result
150 Email::SetEmail(const String& email)
151 {
152         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
153         {
154                 SysTryReturnResult(NID_SCL, email.GetLength() <= MAX_EMAIL_LENGTH, E_INVALID_ARG, "The length of the email exceeds the max length.");
155         }
156
157         return __pEmailImpl->SetEmail(email);
158 }
159
160 }} // Tizen::Social