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 "FScl_ReminderImpl.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::App;
32 using namespace Tizen::Io;
34 namespace Tizen { namespace Social
37 static const int _MINUTES_OF_HOUR = 60;
38 static const int _MINUTES_OF_DAY = 1440;
39 static const int _MINUTES_OF_WEEK = 10080;
41 Reminder::Reminder(void)
42 : __timeUnit(REMINDER_TIME_UNIT_MINUTE)
44 , __pReminderImpl(null)
46 __pReminderImpl = new (std::nothrow) _ReminderImpl();
47 SysTryReturnVoidResult(NID_SCL, __pReminderImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
50 Reminder::Reminder(const Reminder& rhs)
51 : __timeUnit(rhs.__timeUnit)
52 , __timeOffset(rhs.__timeOffset)
53 , __soundFilePath(rhs.__soundFilePath)
54 , __pReminderImpl(null)
56 __pReminderImpl = new (std::nothrow) _ReminderImpl(*rhs.__pReminderImpl);
57 SysTryReturnVoidResult(NID_SCL, __pReminderImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
60 Reminder::~Reminder(void)
62 delete __pReminderImpl;
66 Reminder::operator =(const Reminder& rhs)
73 __timeUnit = rhs.__timeUnit;
74 __timeOffset = rhs.__timeOffset;
75 __soundFilePath = rhs.__soundFilePath;
76 *__pReminderImpl = *rhs.__pReminderImpl;
82 Reminder::Equals(const Object& rhs) const
84 const Reminder* pReminder = dynamic_cast<const Reminder*>(&rhs);
86 if (pReminder == null)
91 return (__timeUnit == pReminder->__timeUnit && __timeOffset == pReminder->__timeOffset
92 && __soundFilePath == pReminder->__soundFilePath && __pReminderImpl->Equals(*pReminder->__pReminderImpl));
96 Reminder::GetHashCode(void) const
100 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __timeUnit;
101 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __timeOffset;
102 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __soundFilePath.GetHashCode();
103 hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __pReminderImpl->GetHashCode();
109 Reminder::GetMinutesBefore(void) const
115 case REMINDER_TIME_UNIT_MINUTE:
116 minutes = __timeOffset;
118 case REMINDER_TIME_UNIT_HOUR:
119 minutes = __timeOffset * _MINUTES_OF_HOUR;
121 case REMINDER_TIME_UNIT_DAY:
122 minutes = __timeOffset * _MINUTES_OF_DAY;
124 case REMINDER_TIME_UNIT_WEEK:
125 minutes = __timeOffset * _MINUTES_OF_WEEK;
135 Reminder::GetSoundFile(void) const
137 return __soundFilePath;
141 Reminder::SetMinutesBefore(int minutes)
143 SysTryReturnResult(NID_SCL, minutes >= 0, E_INVALID_ARG, "Invalid argument is used. The minutes is less than 0.");
144 SysTryReturnResult(NID_SCL, minutes <= MAX_REMINDER_OFFSET_VALUE, E_INVALID_ARG, "Invalid argument is used. The minutes is greater than 40320.");
146 __timeUnit = REMINDER_TIME_UNIT_MINUTE;
147 __timeOffset = minutes;
149 __pReminderImpl->__absoluteTime = DateTime::GetMinValue();
150 __pReminderImpl->__isAbsolute = false;
156 Reminder::SetSoundFile(const String& filePath)
158 if (!filePath.IsEmpty())
160 SysTryReturnResult(NID_SCL, File::IsFileExist(filePath), E_INVALID_ARG
161 , "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.");
164 __soundFilePath = filePath;
170 Reminder::SetTimeOffset(ReminderTimeUnit timeUnit, int timeOffset)
172 SysTryReturnResult(NID_SCL, timeUnit != REMINDER_TIME_UNIT_NONE, E_INVALID_ARG, "Invalid argument is used. The timeUnit is REMINDER_TIME_UNIT_NONE.");
173 SysTryReturnResult(NID_SCL, timeOffset >= 0, E_INVALID_ARG, "Invalid argument is used. The timeOffset is less than 0.");
175 __timeUnit = timeUnit;
176 __timeOffset = timeOffset;
178 __pReminderImpl->__absoluteTime = DateTime::GetMinValue();
179 __pReminderImpl->__isAbsolute = false;
185 Reminder::GetTimeUnit(void) const
191 Reminder::GetTimeOffset(void) const
197 Reminder::SetAbsoluteTime(const DateTime& time)
199 result r = __pReminderImpl->SetAbsoluteTime(time);
200 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
202 __timeUnit = REMINDER_TIME_UNIT_NONE;
209 Reminder::GetAbsoluteTime(void) const
211 return __pReminderImpl->GetAbsoluteTime();
215 Reminder::IsAbsolute(void) const
217 return __pReminderImpl->IsAbsolute();