2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 * @author Lukasz Marek (l.marek@samsung.com)
22 #include <dpl/log/log.h>
23 #include <Commons/Exception.h>
24 #include "CalendarEvent.h"
26 namespace WrtDeviceApis {
30 CalendarEvent::CalendarEvent() :
31 m_calendarId(UNDEFINED_CALENDAR_ID),
32 m_recurrence(UNDEFINED_RECURRENCE),
33 m_status(UNDEFINED_STATUS),
34 m_alarmType(UNDEFINED_ALARM_TYPE),
35 m_categories(new CategoryList()),
40 CalendarEvent::~CalendarEvent()
44 bool CalendarEvent::getIdIsSet() const
46 return !m_id.IsNull();
49 bool CalendarEvent::getAlarmTimeIsSet() const
51 return !m_alarmTime.IsNull();
54 bool CalendarEvent::getExpiresIsSet() const
56 return !m_expires.IsNull();
59 int CalendarEvent::getCalendarId() const
64 void CalendarEvent::setCalendarId(int value)
69 int CalendarEvent::getId() const
74 void CalendarEvent::setId(int value)
79 void CalendarEvent::resetId()
81 m_id = DPL::Optional<int>();
84 std::string CalendarEvent::getDescription() const
89 void CalendarEvent::setDescription(const std::string &value)
91 m_description = value;
94 std::string CalendarEvent::getSubject() const
99 void CalendarEvent::setSubject(const std::string &value)
104 time_t CalendarEvent::getStartTime() const
109 void CalendarEvent::setStartTime(time_t value)
114 time_t CalendarEvent::getEndTime() const
119 void CalendarEvent::setEndTime(time_t value)
124 std::string CalendarEvent::getLocation() const
129 void CalendarEvent::setLocation(const std::string &value)
134 CalendarEvent::EventRecurrence CalendarEvent::getRecurrence() const
136 return m_recurrence == UNDEFINED_RECURRENCE ? NO_RECURRENCE : m_recurrence;
139 void CalendarEvent::setRecurrence(EventRecurrence value)
141 m_recurrence = value;
144 CalendarEvent::EventStatus CalendarEvent::getStatus() const
146 return m_status == UNDEFINED_STATUS ? TENTATIVE_STATUS : m_status;
149 void CalendarEvent::setStatus(EventStatus value)
154 time_t CalendarEvent::getAlarmTime() const
159 void CalendarEvent::setAlarmTime(time_t value)
164 void CalendarEvent::resetAlarmTime()
166 m_alarmTime = DPL::Optional<std::time_t>();
169 CalendarEvent::EventAlarmType CalendarEvent::getAlarmType() const
171 return m_alarmType == UNDEFINED_ALARM_TYPE ? NO_ALARM : m_alarmType;
174 void CalendarEvent::setAlarmType(EventAlarmType value)
179 CategoryListPtr CalendarEvent::getCategories() const
183 void CalendarEvent::setCategories(const CategoryListPtr &value)
185 m_categories = value;
188 time_t CalendarEvent::getExpires() const
193 void CalendarEvent::setExpires(time_t value)
198 void CalendarEvent::resetExpires()
200 m_expires = DPL::Optional<std::time_t>();
203 int CalendarEvent::getInterval() const
208 void CalendarEvent::setInterval(int value)
210 if (m_interval < 1) {
211 LogError("invalid interval");
212 ThrowMsg(Commons::InvalidArgumentException, "interval less than 1");
217 void CalendarEvent::display() const
219 LogDebug("m_id " << m_id);
220 LogDebug("m_calendarId " << m_calendarId);
221 LogDebug("m_description " << m_description);
222 LogDebug("m_subject " << m_subject);
223 LogDebug("m_startTime " << m_startTime);
224 LogDebug("m_endTime " << m_endTime);
225 LogDebug("m_location " << m_location);
226 LogDebug("m_recurrence " << m_recurrence);
227 LogDebug("m_status " << m_status);
228 if (!m_alarmTime.IsNull()) {
229 LogDebug("m_alarmTime " << *m_alarmTime);
231 LogDebug("m_alarmType " << m_alarmType);
232 if (!m_expires.IsNull()) {
233 LogDebug("m_expires" << *m_expires);
235 LogDebug("m_categories size " << m_categories->size());
236 for (size_t i = 0; i < m_categories->size(); ++i) {
237 LogDebug("category" << i << " " << m_categories->at(i));
241 bool CalendarEvent::validate() const
243 if (m_alarmType == INVALID_ALARM_TYPE) {
244 LogError("Incorrect alarm type value detected");
247 if (m_recurrence == INVALID_RECURRENCE) {
248 LogError("Incorrect recurrence value detected");
251 if (m_status == INVALID_STATUS) {
252 LogError("Incorrect status value detected");