2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include "CallHistoryDefine.h"
20 #include "CallHistoryFilter.h"
25 using namespace DeviceAPI::Tizen;
28 namespace CallHistory {
30 CallHistoryFilter::CallHistoryFilter(contacts_filter_h filter)
32 m_filterStack.push(filter);
35 CallHistoryFilter::~CallHistoryFilter()
37 contacts_filter_h filter = NULL;
38 while (m_filterStack.size() > 1) {
39 filter = m_filterStack.top();
40 contacts_filter_destroy(filter);
45 void CallHistoryFilter::visitPreComposite(FilterType& type, int depth)
47 contacts_filter_h filter = NULL;
48 contacts_filter_create(_contacts_phone_log._uri, &filter);
50 m_filterStack.push(filter);
54 void CallHistoryFilter::visitInComposite(FilterType& type, int depth)
56 contacts_filter_h filter = m_filterStack.top();
57 if(type == DeviceAPI::Tizen::UNION_FILTER)
58 contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
59 else if(type == DeviceAPI::Tizen::INTERSECTION_FILTER)
60 contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
64 void CallHistoryFilter::visitPostComposite(FilterType& type, int depth)
66 contacts_filter_h filter = m_filterStack.top();
67 if (m_filterStack.size() > 1) {
69 contacts_filter_h filterParent = m_filterStack.top();
70 contacts_filter_add_filter(filterParent, filter);
71 contacts_filter_destroy(filter);
75 void CallHistoryFilter::visitAttribute(std::string& attrName, MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& matchValue, int depth)
78 contacts_match_str_flag_e mFlag;
80 if (matchValue == NULL) {
84 contacts_filter_h filter = m_filterStack.top();
85 contacts_filter_h subFilter = NULL;
86 contacts_filter_create(_contacts_phone_log._uri, &subFilter);
90 mFlag = CONTACTS_MATCH_EXACTLY;
92 case MATCH_FULLSTRING:
93 mFlag = CONTACTS_MATCH_FULLSTRING;
96 mFlag = CONTACTS_MATCH_CONTAINS;
98 case MATCH_STARTSWITH:
99 mFlag = CONTACTS_MATCH_STARTSWITH;
102 mFlag = CONTACTS_MATCH_ENDSWITH;
105 mFlag = CONTACTS_MATCH_EXISTS;
108 mFlag = CONTACTS_MATCH_EXACTLY;
111 if (attrName.compare(STR_DIRECTION) == 0) {
112 if (matchValue->getString().compare(STR_RECEIVED) == 0) {
113 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
114 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
115 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING);
116 contacts_filter_add_filter(filter, subFilter);
117 } else if (matchValue->getString().compare(STR_DIALED) == 0) {
118 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_OUTGOING);
119 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
120 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_OUTGOING);
121 contacts_filter_add_filter(filter, subFilter);
122 } else if (matchValue->getString().compare(STR_MISSED) == 0) {
123 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
124 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
125 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
126 contacts_filter_add_filter(filter, subFilter);
127 } else if (matchValue->getString().compare(STR_MISSED_NEW) == 0) {
128 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
129 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
130 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
131 contacts_filter_add_filter(filter, subFilter);
132 } else if (matchValue->getString().compare(STR_REJECTED) == 0) {
133 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_REJECT);
134 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
135 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_REJECT);
136 contacts_filter_add_filter(filter, subFilter);
137 } else if (matchValue->getString().compare(STR_BLOCKED) == 0) {
138 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_BLOCKED);
139 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
140 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
141 contacts_filter_add_filter(filter, subFilter);
143 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
145 } else if (attrName.compare(STR_TAGS) == 0) {
146 if (matchValue->getString().compare(STR_CALL) == 0) {
147 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
148 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
149 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
150 contacts_filter_add_filter(filter, subFilter);
151 } else if (matchValue->getString().compare(STR_CALL_VOICE) == 0) {
152 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
153 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
154 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_OUTGOING);
155 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
156 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
157 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
158 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
159 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
160 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_REJECT);
161 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
162 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_BLOCKED);
163 contacts_filter_add_filter(filter, subFilter);
164 } else if (matchValue->getString().compare(STR_CALL_VIDEO) == 0) {
165 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING);
166 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
167 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_OUTGOING);
168 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
169 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
170 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
171 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
172 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
173 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_REJECT);
174 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
175 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
176 contacts_filter_add_filter(filter, subFilter);
178 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
180 } else if (attrName.compare(STR_RP_REMOTEPARTY) == 0) {
181 contacts_filter_add_str(filter, _contacts_phone_log.address, mFlag, matchValue->getString().c_str());
182 } else if (attrName.compare(STR_RP_PERSONID) == 0) {
183 contacts_filter_add_str(filter, _contacts_phone_log.person_id, mFlag, matchValue->getString().c_str());
184 } else if (attrName.compare(STR_START_TIME) == 0) {
185 if(matchValue->isType(PrimitiveType_Time)) {
186 contacts_filter_add_int(filter, _contacts_phone_log.log_time, CONTACTS_MATCH_EQUAL, static_cast<int>(matchValue->getTimeT()));
188 } else if (attrName.compare(STR_DURATION) == 0) {
189 contacts_filter_add_str(filter, _contacts_phone_log.extra_data1, mFlag, matchValue->toString().c_str());
190 } else if (attrName.compare(STR_CALL_TYPE) == 0) {
191 if (matchValue->getString().compare(STR_TIZEN_TEL) == 0) {
192 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
193 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
194 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
195 contacts_filter_add_filter(filter, subFilter);
197 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
199 } else if (attrName.compare(STR_ENTRY_ID) == 0) {
201 istringstream iss(matchValue->getString());
204 contacts_filter_add_int(filter, _contacts_phone_log.id, CONTACTS_MATCH_EQUAL, result);
206 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
209 contacts_filter_destroy(subFilter);
212 void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
214 if(initialValue == NULL || endValue == NULL)
217 contacts_filter_h filter = m_filterStack.top();
219 unsigned int propertyId = 0;
223 if (attrName.compare(STR_RP_REMOTEPARTY) == 0) {
224 propertyId = _contacts_phone_log.address;
225 } else if (attrName.compare(STR_RP_PERSONID) == 0) {
226 propertyId = _contacts_phone_log.person_id;
227 } else if (attrName.compare(STR_START_TIME) == 0) {
228 propertyId = _contacts_phone_log.log_time;
229 } else if (attrName.compare(STR_DURATION) == 0) {
230 propertyId = _contacts_phone_log.extra_data1;
231 } else if (attrName.compare(STR_ENTRY_ID) == 0) {
232 propertyId = _contacts_phone_log.id;
237 if (!initialValue->isNullOrUndefined()) {
238 if (propertyId != _contacts_phone_log.address) {
239 if(initialValue->isType(PrimitiveType_Time)) {
240 iValue = static_cast<int>(initialValue->getTimeT());
242 iValue = atoi(initialValue->getString().c_str());
247 if (!endValue->isNullOrUndefined()) {
248 if (propertyId != _contacts_phone_log.address) {
249 if(endValue->isType(PrimitiveType_Time)) {
250 eValue = static_cast<int>(endValue->getTimeT());
252 eValue = atoi(endValue->getString().c_str());
257 contacts_filter_h subFilter = NULL;
258 contacts_filter_create(_contacts_phone_log._uri, &subFilter);
260 if (propertyId == _contacts_phone_log.address) {
261 if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) {
262 contacts_filter_add_str(filter, propertyId, CONTACTS_MATCH_STARTSWITH, initialValue->getString().c_str());
263 } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
264 contacts_filter_add_str(filter, propertyId, CONTACTS_MATCH_ENDSWITH, endValue->getString().c_str());
265 } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
266 contacts_filter_add_str(subFilter, propertyId, CONTACTS_MATCH_STARTSWITH, initialValue->getString().c_str());
267 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
268 contacts_filter_add_str(subFilter, propertyId, CONTACTS_MATCH_ENDSWITH, endValue->getString().c_str());
269 contacts_filter_add_filter(filter, subFilter);
272 if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) {
273 contacts_filter_add_int(filter, propertyId, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, iValue);
274 } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
275 contacts_filter_add_int(filter, propertyId, CONTACTS_MATCH_LESS_THAN, eValue);
276 } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
277 contacts_filter_add_int(subFilter, propertyId, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, iValue);
278 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
279 contacts_filter_add_int(subFilter, propertyId, CONTACTS_MATCH_LESS_THAN, eValue);
280 contacts_filter_add_filter(filter, subFilter);
283 contacts_filter_destroy(subFilter);
286 contacts_filter_h CallHistoryFilter::getResult() const
288 contacts_filter_h filter = m_filterStack.top();