tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / API / Calendar / CalendarEvent.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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        Event.cpp
18  * @author      Lukasz Marek (l.marek@samsung.com)
19  * @version     0.1
20  */
21
22 #include <dpl/log/log.h>
23 #include <Commons/Exception.h>
24 #include "CalendarEvent.h"
25
26 namespace WrtDeviceApis {
27 namespace Calendar {
28 namespace Api {
29
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()),
36     m_interval(1)
37 {
38 }
39
40 CalendarEvent::~CalendarEvent()
41 {
42 }
43
44 bool CalendarEvent::getIdIsSet() const
45 {
46     return !m_id.IsNull();
47 }
48
49 bool CalendarEvent::getAlarmTimeIsSet() const
50 {
51     return !m_alarmTime.IsNull();
52 }
53
54 bool CalendarEvent::getExpiresIsSet() const
55 {
56     return !m_expires.IsNull();
57 }
58
59 int CalendarEvent::getCalendarId() const
60 {
61     return m_calendarId;
62 }
63
64 void CalendarEvent::setCalendarId(int value)
65 {
66     m_calendarId = value;
67 }
68
69 int CalendarEvent::getId() const
70 {
71     return *m_id;
72 }
73
74 void CalendarEvent::setId(int value)
75 {
76     m_id = value;
77 }
78
79 void CalendarEvent::resetId()
80 {
81     m_id = DPL::Optional<int>();
82 }
83
84 std::string CalendarEvent::getDescription() const
85 {
86     return m_description;
87 }
88
89 void CalendarEvent::setDescription(const std::string &value)
90 {
91     m_description = value;
92 }
93
94 std::string CalendarEvent::getSubject() const
95 {
96     return m_subject;
97 }
98
99 void CalendarEvent::setSubject(const std::string &value)
100 {
101     m_subject = value;
102 }
103
104 time_t CalendarEvent::getStartTime() const
105 {
106     return m_startTime;
107 }
108
109 void CalendarEvent::setStartTime(time_t value)
110 {
111     m_startTime = value;
112 }
113
114 time_t CalendarEvent::getEndTime() const
115 {
116     return m_endTime;
117 }
118
119 void CalendarEvent::setEndTime(time_t value)
120 {
121     m_endTime = value;
122 }
123
124 std::string CalendarEvent::getLocation() const
125 {
126     return m_location;
127 }
128
129 void CalendarEvent::setLocation(const std::string &value)
130 {
131     m_location = value;
132 }
133
134 CalendarEvent::EventRecurrence CalendarEvent::getRecurrence() const
135 {
136     return m_recurrence == UNDEFINED_RECURRENCE ? NO_RECURRENCE : m_recurrence;
137 }
138
139 void CalendarEvent::setRecurrence(EventRecurrence value)
140 {
141     m_recurrence = value;
142 }
143
144 CalendarEvent::EventStatus CalendarEvent::getStatus() const
145 {
146     return m_status == UNDEFINED_STATUS ? TENTATIVE_STATUS : m_status;
147 }
148
149 void CalendarEvent::setStatus(EventStatus value)
150 {
151     m_status = value;
152 }
153
154 time_t CalendarEvent::getAlarmTime() const
155 {
156     return *m_alarmTime;
157 }
158
159 void CalendarEvent::setAlarmTime(time_t value)
160 {
161     m_alarmTime = value;
162 }
163
164 void CalendarEvent::resetAlarmTime()
165 {
166     m_alarmTime = DPL::Optional<std::time_t>();
167 }
168
169 CalendarEvent::EventAlarmType CalendarEvent::getAlarmType() const
170 {
171     return m_alarmType == UNDEFINED_ALARM_TYPE ? NO_ALARM : m_alarmType;
172 }
173
174 void CalendarEvent::setAlarmType(EventAlarmType value)
175 {
176     m_alarmType = value;
177 }
178
179 CategoryListPtr CalendarEvent::getCategories() const
180 {
181     return m_categories;
182 }
183 void CalendarEvent::setCategories(const CategoryListPtr &value)
184 {
185     m_categories = value;
186 }
187
188 time_t CalendarEvent::getExpires() const
189 {
190     return *m_expires;
191 }
192
193 void CalendarEvent::setExpires(time_t value)
194 {
195     m_expires = value;
196 }
197
198 void CalendarEvent::resetExpires()
199 {
200     m_expires = DPL::Optional<std::time_t>();
201 }
202
203 int CalendarEvent::getInterval() const
204 {
205     return m_interval;
206 }
207
208 void CalendarEvent::setInterval(int value)
209 {
210     if (m_interval < 1) {
211         LogError("invalid interval");
212         ThrowMsg(Commons::InvalidArgumentException, "interval less than 1");
213     }
214     m_interval = value;
215 }
216
217 void CalendarEvent::display() const
218 {
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);
230     }
231     LogDebug("m_alarmType " << m_alarmType);
232     if (!m_expires.IsNull()) {
233         LogDebug("m_expires" << *m_expires);
234     }
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));
238     }
239 }
240
241 bool CalendarEvent::validate() const
242 {
243     if (m_alarmType == INVALID_ALARM_TYPE) {
244         LogError("Incorrect alarm type value detected");
245         return false;
246     }
247     if (m_recurrence == INVALID_RECURRENCE) {
248         LogError("Incorrect recurrence value detected");
249         return false;
250     }
251     if (m_status == INVALID_STATUS) {
252         LogError("Incorrect status value detected");
253         return false;
254     }
255     return true;
256 }
257
258 }
259 }
260 }