Fix for CompatTC Fail
[framework/osp/social.git] / src / FSclReminder.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                FSclReminder.cpp
18  * @brief               This is the implementation for Reminder class.
19  *
20  * This file contains definitions of @e Reminder class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FBaseDateTime.h>
25 #include <FIoFile.h>
26 #include <FSclReminder.h>
27 #include <FApp_AppInfo.h>
28 #include <FIo_FileImpl.h>
29 #include "FScl_ReminderImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::App;
33 using namespace Tizen::Io;
34
35 namespace Tizen { namespace Social
36 {
37
38 static const int _MINUTES_OF_HOUR = 60;
39 static const int _MINUTES_OF_DAY = 1440;
40 static const int _MINUTES_OF_WEEK = 10080;
41
42 Reminder::Reminder(void)
43         : __timeUnit(REMINDER_TIME_UNIT_MINUTE)
44         , __timeOffset(0)
45         , __pReminderImpl(null)
46 {
47         __pReminderImpl = new (std::nothrow) _ReminderImpl();
48         SysTryReturnVoidResult(NID_SCL, __pReminderImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
49 }
50
51 Reminder::Reminder(const Reminder& rhs)
52         : __soundFilePath(rhs.__soundFilePath)
53         , __timeUnit(rhs.__timeUnit)
54         , __timeOffset(rhs.__timeOffset)
55         , __pReminderImpl(null)
56 {
57         __pReminderImpl = new (std::nothrow) _ReminderImpl(*rhs.__pReminderImpl);
58         SysTryReturnVoidResult(NID_SCL, __pReminderImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
59 }
60
61 Reminder::~Reminder(void)
62 {
63         delete __pReminderImpl;
64 }
65
66 Reminder&
67 Reminder::operator =(const Reminder& rhs)
68 {
69         if (this == &rhs)
70         {
71                 return *this;
72         }
73
74         __timeUnit = rhs.__timeUnit;
75         __timeOffset = rhs.__timeOffset;
76         __soundFilePath = rhs.__soundFilePath;
77         *__pReminderImpl = *rhs.__pReminderImpl;
78
79         return *this;
80 }
81
82 bool
83 Reminder::Equals(const Object& rhs) const
84 {
85         const Reminder* pReminder = dynamic_cast<const Reminder*>(&rhs);
86
87         if (pReminder == null)
88         {
89                 return false;
90         }
91
92         return (__timeUnit == pReminder->__timeUnit && __timeOffset == pReminder->__timeOffset
93                         && __soundFilePath == pReminder->__soundFilePath && __pReminderImpl->Equals(*pReminder->__pReminderImpl));
94 }
95
96 int
97 Reminder::GetHashCode(void) const
98 {
99         int hashCode = 17;
100
101         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __timeUnit;
102         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __timeOffset;
103         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __soundFilePath.GetHashCode();
104         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __pReminderImpl->GetHashCode();
105
106         return hashCode;
107 }
108
109 int
110 Reminder::GetMinutesBefore(void) const
111 {
112         int minutes = 0;
113
114         switch (__timeUnit)
115         {
116         case REMINDER_TIME_UNIT_MINUTE:
117                 minutes = __timeOffset;
118                 break;
119         case REMINDER_TIME_UNIT_HOUR:
120                 minutes = __timeOffset * _MINUTES_OF_HOUR;
121                 break;
122         case REMINDER_TIME_UNIT_DAY:
123                 minutes = __timeOffset * _MINUTES_OF_DAY;
124                 break;
125         case REMINDER_TIME_UNIT_WEEK:
126                 minutes = __timeOffset * _MINUTES_OF_WEEK;
127                 break;
128         default:
129                 break;
130         }
131
132         return minutes;
133 }
134
135 String
136 Reminder::GetSoundFile(void) const
137 {
138         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
139         {
140                 String tmpFilePath;
141                 _FileImpl::ConvertPhysicalToVirtualPath(__soundFilePath, tmpFilePath);
142
143                 ClearLastResult();
144
145                 return tmpFilePath;
146         }
147
148         return __soundFilePath;
149 }
150
151 result
152 Reminder::SetMinutesBefore(int minutes)
153 {
154         SysTryReturnResult(NID_SCL, minutes >= 0, E_INVALID_ARG, "Invalid argument is used. The minutes is less than 0.");
155         SysTryReturnResult(NID_SCL, minutes <= MAX_REMINDER_OFFSET_VALUE, E_INVALID_ARG, "Invalid argument is used. The minutes is greater than 40320.");
156
157         __timeUnit = REMINDER_TIME_UNIT_MINUTE;
158         __timeOffset = minutes;
159
160         __pReminderImpl->__absoluteTime = DateTime::GetMinValue();
161         __pReminderImpl->__isAbsolute = false;
162
163         return E_SUCCESS;
164 }
165
166 result
167 Reminder::SetSoundFile(const String& filePath)
168 {
169         if (filePath.IsEmpty())
170         {
171                 __soundFilePath.Clear();
172         }
173         else
174         {
175                 SysTryReturnResult(NID_SCL, File::IsFileExist(filePath), E_INVALID_ARG
176                                         , "Invalid argument is used. The length of the filePath exceeds the maximum length or the file path is invalid or the file does not exist.");
177
178                 result r = E_SUCCESS;
179                 String tmpFilePath;
180
181                 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
182                 {
183                         r = _FileImpl::ConvertVirtualToPhysicalPath(filePath, tmpFilePath);
184                         SysTryReturn(NID_SCL, r == E_SUCCESS, E_INVALID_ARG,  E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
185                 }
186                 else
187                 {
188                         tmpFilePath = filePath;
189                 }
190
191                 __soundFilePath = tmpFilePath;
192         }
193
194         return E_SUCCESS;
195 }
196
197 result
198 Reminder::SetTimeOffset(ReminderTimeUnit timeUnit, int timeOffset)
199 {
200         SysTryReturnResult(NID_SCL, timeUnit != REMINDER_TIME_UNIT_NONE, E_INVALID_ARG, "Invalid argument is used. The timeUnit is REMINDER_TIME_UNIT_NONE.");
201         SysTryReturnResult(NID_SCL, timeOffset >= 0, E_INVALID_ARG,     "Invalid argument is used. The timeOffset is less than 0.");
202
203         __timeUnit = timeUnit;
204         __timeOffset = timeOffset;
205
206         __pReminderImpl->__absoluteTime = DateTime::GetMinValue();
207         __pReminderImpl->__isAbsolute = false;
208
209         return E_SUCCESS;
210 }
211
212 ReminderTimeUnit
213 Reminder::GetTimeUnit(void) const
214 {
215         return __timeUnit;
216 }
217
218 int
219 Reminder::GetTimeOffset(void) const
220 {
221         return __timeOffset;
222 }
223
224 result
225 Reminder::SetAbsoluteTime(const DateTime& time)
226 {
227         result r = __pReminderImpl->SetAbsoluteTime(time);
228         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
229
230         __timeUnit = REMINDER_TIME_UNIT_NONE;
231         __timeOffset = 0;
232
233         return E_SUCCESS;
234 }
235
236 DateTime
237 Reminder::GetAbsoluteTime(void) const
238 {
239         return __pReminderImpl->GetAbsoluteTime();
240 }
241
242 bool
243 Reminder::IsAbsolute(void) const
244 {
245         return __pReminderImpl->IsAbsolute();
246 }
247
248 }}  // Tizen::Social