2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FSclReminder.cpp
18 * @brief This is the implementation for Reminder class.
20 * This file contains definitions of @e Reminder class.
23 #include <FBaseSysLog.h>
24 #include <FBaseDateTime.h>
26 #include <FSclReminder.h>
27 #include <FApp_AppInfo.h>
28 #include <FIo_FileImpl.h>
29 #include "FScl_ReminderImpl.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::App;
33 using namespace Tizen::Io;
35 namespace Tizen { namespace Social
38 static const int _MINUTES_OF_HOUR = 60;
39 static const int _MINUTES_OF_DAY = 1440;
40 static const int _MINUTES_OF_WEEK = 10080;
42 Reminder::Reminder(void)
43 : __timeUnit(REMINDER_TIME_UNIT_MINUTE)
45 , __pReminderImpl(null)
47 __pReminderImpl = new (std::nothrow) _ReminderImpl();
48 SysTryReturnVoidResult(NID_SCL, __pReminderImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
51 Reminder::Reminder(const Reminder& rhs)
52 : __soundFilePath(rhs.__soundFilePath)
53 , __timeUnit(rhs.__timeUnit)
54 , __timeOffset(rhs.__timeOffset)
55 , __pReminderImpl(null)
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.");
61 Reminder::~Reminder(void)
63 delete __pReminderImpl;
67 Reminder::operator =(const Reminder& rhs)
74 __timeUnit = rhs.__timeUnit;
75 __timeOffset = rhs.__timeOffset;
76 __soundFilePath = rhs.__soundFilePath;
77 *__pReminderImpl = *rhs.__pReminderImpl;
83 Reminder::Equals(const Object& rhs) const
85 const Reminder* pReminder = dynamic_cast<const Reminder*>(&rhs);
87 if (pReminder == null)
92 return (__timeUnit == pReminder->__timeUnit && __timeOffset == pReminder->__timeOffset
93 && __soundFilePath == pReminder->__soundFilePath && __pReminderImpl->Equals(*pReminder->__pReminderImpl));
97 Reminder::GetHashCode(void) const
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();
110 Reminder::GetMinutesBefore(void) const
116 case REMINDER_TIME_UNIT_MINUTE:
117 minutes = __timeOffset;
119 case REMINDER_TIME_UNIT_HOUR:
120 minutes = __timeOffset * _MINUTES_OF_HOUR;
122 case REMINDER_TIME_UNIT_DAY:
123 minutes = __timeOffset * _MINUTES_OF_DAY;
125 case REMINDER_TIME_UNIT_WEEK:
126 minutes = __timeOffset * _MINUTES_OF_WEEK;
136 Reminder::GetSoundFile(void) const
138 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
141 _FileImpl::ConvertPhysicalToVirtualPath(__soundFilePath, tmpFilePath);
148 return __soundFilePath;
152 Reminder::SetMinutesBefore(int minutes)
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.");
157 __timeUnit = REMINDER_TIME_UNIT_MINUTE;
158 __timeOffset = minutes;
160 __pReminderImpl->__absoluteTime = DateTime::GetMinValue();
161 __pReminderImpl->__isAbsolute = false;
167 Reminder::SetSoundFile(const String& filePath)
169 if (filePath.IsEmpty())
171 __soundFilePath.Clear();
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.");
178 result r = E_SUCCESS;
181 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
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));
188 tmpFilePath = filePath;
191 __soundFilePath = tmpFilePath;
198 Reminder::SetTimeOffset(ReminderTimeUnit timeUnit, int timeOffset)
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.");
203 __timeUnit = timeUnit;
204 __timeOffset = timeOffset;
206 __pReminderImpl->__absoluteTime = DateTime::GetMinValue();
207 __pReminderImpl->__isAbsolute = false;
213 Reminder::GetTimeUnit(void) const
219 Reminder::GetTimeOffset(void) const
225 Reminder::SetAbsoluteTime(const DateTime& time)
227 result r = __pReminderImpl->SetAbsoluteTime(time);
228 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
230 __timeUnit = REMINDER_TIME_UNIT_NONE;
237 Reminder::GetAbsoluteTime(void) const
239 return __pReminderImpl->GetAbsoluteTime();
243 Reminder::IsAbsolute(void) const
245 return __pReminderImpl->IsAbsolute();