d4216a1d608cd0307938b1c3f8fa02b3b95a1ab6
[framework/web/wrt-plugins-common.git] / src / modules / API / Task / CalendarTask.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        CalendarTask.cpp
18  * @author      Shi Hezhang (hezhang.shi@samsung.com)
19  * @author      Pan Rui (r.pan@samsung.com)
20  * @version     0.1
21  */
22
23 #include "CalendarTask.h"
24 #include <dpl/log/log.h>
25
26 namespace {
27 const int UNDEFINED_TASK_ID = -1;
28 }
29
30 namespace WrtDeviceApis {
31 namespace Task {
32 namespace Api {
33
34 CalendarTask::CalendarTask() :
35     m_id(UNDEFINED_TASK_ID),
36     m_taskId(UNDEFINED_TASK_ID),
37     m_dueDate(UNDEFINED_TASK_TIME_T_VALUE),
38     m_status(UNDEFINED_STATUS),
39     m_priority(UNDEFINED_PRIORITY),
40     m_descriptionIsSet(false),
41     m_subjectIsSet(false)
42 {
43 }
44
45 CalendarTask::~CalendarTask()
46 {
47 }
48
49 bool CalendarTask::getIdIsSet() const
50 {
51     return m_id != UNDEFINED_TASK_ID;
52 }
53
54 bool CalendarTask::getTaskIdIsSet() const
55 {
56     return m_taskId != UNDEFINED_TASK_ID;
57 }
58
59 bool CalendarTask::getDescriptionIsSet() const
60 {
61     return m_descriptionIsSet;
62 }
63
64 bool CalendarTask::getSubjectIsSet() const
65 {
66     return m_subjectIsSet;
67 }
68
69 bool CalendarTask::getDueDateIsSet() const
70 {
71     return m_dueDate >= 0;
72 }
73
74 bool CalendarTask::getStatusIsSet() const
75 {
76     return m_status != UNDEFINED_STATUS;
77 }
78
79 bool CalendarTask::getPriorityIsSet() const
80 {
81     return m_priority != UNDEFINED_PRIORITY;
82 }
83
84 int CalendarTask::getTaskId() const
85 {
86     return m_taskId;
87 }
88
89 void CalendarTask::setTaskId(int value)
90 {
91     m_taskId = value;
92 }
93
94 int CalendarTask::getId() const
95 {
96     return m_id;
97 }
98
99 void CalendarTask::setId(int value)
100 {
101     m_id = value;
102 }
103
104 std::string CalendarTask::getDescription() const
105 {
106     return m_description;
107 }
108
109 void CalendarTask::setDescription(const std::string &value)
110 {
111     m_descriptionIsSet = true;
112     m_description = value;
113 }
114
115 std::string CalendarTask::getSubject() const
116 {
117     return m_subject;
118 }
119
120 void CalendarTask::setSubject(const std::string &value)
121 {
122     m_subjectIsSet = true;
123     m_subject = value;
124 }
125
126 time_t CalendarTask::getDueDate() const
127 {
128     return m_dueDate > 0 ? m_dueDate : 0;
129 }
130
131 void CalendarTask::setDueDate(time_t value)
132 {
133     m_dueDate = value;
134 }
135
136 CalendarTask::TaskStatus CalendarTask::getStatus() const
137 {
138     return m_status == UNDEFINED_STATUS ? STATUS_NEEDS_ACTION : m_status;
139 }
140
141 void CalendarTask::setStatus(TaskStatus value)
142 {
143     m_status = value;
144 }
145
146 CalendarTask::TaskPriority CalendarTask::getPriority() const
147 {
148     return m_priority == UNDEFINED_PRIORITY ? LOW_PRIORITY : m_priority;
149 }
150
151 void CalendarTask::setPriority(TaskPriority value)
152 {
153     m_priority = value;
154 }
155
156 void CalendarTask::display() const
157 {
158     LogDebug("m_id " << m_id);
159     LogDebug("m_calendarId " << m_taskId);
160     LogDebug("m_description " << m_description);
161     LogDebug("m_subject " << m_subject);
162     LogDebug("m_dueDate " << m_dueDate);
163     LogDebug("m_status " << m_status);
164     LogDebug("m_priority " << m_priority);
165 }
166
167 bool CalendarTask::validate() const
168 {
169     if (m_dueDate == -1) {
170         LogError("Incorrect due time value detected");
171         return false;
172     }
173     if (m_status == CalendarTask::INVALID_STATUS) {
174         LogError("Incorrect status value detected");
175         return false;
176     }
177     if (m_priority == CalendarTask::INVALID_PRIORITY) {
178         LogError("Incorrect priority value detected");
179         return false;
180     }
181     return true;
182 }
183
184 }
185 }
186 }