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"
24 using namespace DeviceAPI::Tizen;
27 namespace CallHistory {
29 CallHistoryFilter::CallHistoryFilter(contacts_filter_h filter)
31 m_filterStack.push(filter);
34 CallHistoryFilter::~CallHistoryFilter()
36 contacts_filter_h filter = NULL;
37 while (m_filterStack.size() > 1) {
38 filter = m_filterStack.top();
39 contacts_filter_destroy(filter);
44 void CallHistoryFilter::visitPreComposite(FilterType& type, int depth)
46 contacts_filter_h filter = NULL;
47 contacts_filter_create(_contacts_phone_log._uri, &filter);
49 m_filterStack.push(filter);
53 void CallHistoryFilter::visitInComposite(FilterType& type, int depth)
55 contacts_filter_h filter = m_filterStack.top();
56 if(type == DeviceAPI::Tizen::UNION_FILTER)
57 contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
58 else if(type == DeviceAPI::Tizen::INTERSECTION_FILTER)
59 contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
63 void CallHistoryFilter::visitPostComposite(FilterType& type, int depth)
65 contacts_filter_h filter = m_filterStack.top();
66 if (m_filterStack.size() > 1) {
68 contacts_filter_h filterParent = m_filterStack.top();
69 contacts_filter_add_filter(filterParent, filter);
70 contacts_filter_destroy(filter);
74 void CallHistoryFilter::visitAttribute(std::string& attrName, MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& matchValue, int depth)
77 contacts_match_str_flag_e mFlag;
79 if (matchValue == NULL) {
83 contacts_filter_h filter = m_filterStack.top();
84 contacts_filter_h subFilter = NULL;
85 contacts_filter_create(_contacts_phone_log._uri, &subFilter);
89 mFlag = CONTACTS_MATCH_EXACTLY;
91 case MATCH_FULLSTRING:
92 mFlag = CONTACTS_MATCH_FULLSTRING;
95 mFlag = CONTACTS_MATCH_CONTAINS;
97 case MATCH_STARTSWITH:
98 mFlag = CONTACTS_MATCH_STARTSWITH;
101 mFlag = CONTACTS_MATCH_ENDSWITH;
104 mFlag = CONTACTS_MATCH_EXISTS;
107 mFlag = CONTACTS_MATCH_EXACTLY;
110 if (attrName.compare(STR_DIRECTION) == 0) {
111 if (matchValue->getString().compare(STR_RECEIVED) == 0) {
112 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
113 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
114 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING);
115 contacts_filter_add_filter(filter, subFilter);
116 } else if (matchValue->getString().compare(STR_DIALED) == 0) {
117 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_OUTGOING);
118 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
119 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_OUTGOING);
120 contacts_filter_add_filter(filter, subFilter);
121 } else if (matchValue->getString().compare(STR_MISSED) == 0) {
122 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
123 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
124 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
125 contacts_filter_add_filter(filter, subFilter);
126 } else if (matchValue->getString().compare(STR_MISSED_NEW) == 0) {
127 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
128 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
129 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
130 contacts_filter_add_filter(filter, subFilter);
131 } else if (matchValue->getString().compare(STR_REJECTED) == 0) {
132 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_REJECT);
133 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
134 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_REJECT);
135 contacts_filter_add_filter(filter, subFilter);
136 } else if (matchValue->getString().compare(STR_BLOCKED) == 0) {
137 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_BLOCKED);
138 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
139 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
140 contacts_filter_add_filter(filter, subFilter);
142 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
144 } else if (attrName.compare(STR_TAGS) == 0) {
145 if (matchValue->getString().compare(STR_CALL) == 0) {
146 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
147 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
148 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
149 contacts_filter_add_filter(filter, subFilter);
150 } else if (matchValue->getString().compare(STR_CALL_VOICE) == 0) {
151 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
152 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
153 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_OUTGOING);
154 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
155 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
156 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
157 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
158 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
159 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_REJECT);
160 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
161 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_BLOCKED);
162 contacts_filter_add_filter(filter, subFilter);
163 } else if (matchValue->getString().compare(STR_CALL_VIDEO) == 0) {
164 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING);
165 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
166 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_OUTGOING);
167 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
168 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
169 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
170 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
171 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
172 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_REJECT);
173 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
174 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
175 contacts_filter_add_filter(filter, subFilter);
177 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
179 } else if (attrName.compare(STR_RP_REMOTEPARTY) == 0) {
180 contacts_filter_add_str(filter, _contacts_phone_log.address, mFlag, matchValue->getString().c_str());
181 } else if (attrName.compare(STR_RP_PERSONID) == 0) {
182 contacts_filter_add_str(filter, _contacts_phone_log.person_id, mFlag, matchValue->getString().c_str());
183 } else if (attrName.compare(STR_START_TIME) == 0) {
184 if(matchValue->isType(PrimitiveType_Time)) {
185 contacts_filter_add_int(filter, _contacts_phone_log.log_time, CONTACTS_MATCH_EQUAL, static_cast<int>(matchValue->getTimeT()));
187 } else if (attrName.compare(STR_DURATION) == 0) {
188 contacts_filter_add_str(filter, _contacts_phone_log.extra_data1, mFlag, matchValue->toString().c_str());
189 } else if (attrName.compare(STR_CALL_TYPE) == 0) {
190 if (matchValue->getString().compare(STR_TIZEN_TEL) == 0) {
191 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
192 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
193 contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
194 contacts_filter_add_filter(filter, subFilter);
196 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
198 } else if (attrName.compare(STR_ENTRY_ID) == 0) {
199 contacts_filter_add_str(filter, _contacts_phone_log.id, mFlag, matchValue->getString().c_str());
201 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
204 contacts_filter_destroy(subFilter);
207 void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
209 if(initialValue == NULL || endValue == NULL)
212 contacts_filter_h filter = m_filterStack.top();
214 unsigned int propertyId = 0;
218 if (attrName.compare(STR_RP_REMOTEPARTY) == 0) {
219 propertyId = _contacts_phone_log.address;
220 } else if (attrName.compare(STR_RP_PERSONID) == 0) {
221 propertyId = _contacts_phone_log.person_id;
222 } else if (attrName.compare(STR_START_TIME) == 0) {
223 propertyId = _contacts_phone_log.log_time;
224 } else if (attrName.compare(STR_DURATION) == 0) {
225 propertyId = _contacts_phone_log.extra_data1;
226 } else if (attrName.compare(STR_ENTRY_ID) == 0) {
227 propertyId = _contacts_phone_log.id;
232 if (!initialValue->isNullOrUndefined()) {
233 if (propertyId != _contacts_phone_log.address) {
234 if(initialValue->isType(PrimitiveType_Time)) {
235 iValue = static_cast<int>(initialValue->getTimeT());
237 iValue = atoi(initialValue->getString().c_str());
242 if (!endValue->isNullOrUndefined()) {
243 if (propertyId != _contacts_phone_log.address) {
244 if(endValue->isType(PrimitiveType_Time)) {
245 eValue = static_cast<int>(endValue->getTimeT());
247 eValue = atoi(endValue->getString().c_str());
252 contacts_filter_h subFilter = NULL;
253 contacts_filter_create(_contacts_phone_log._uri, &subFilter);
255 if (propertyId == _contacts_phone_log.address) {
256 if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) {
257 contacts_filter_add_str(filter, propertyId, CONTACTS_MATCH_STARTSWITH, initialValue->getString().c_str());
258 } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
259 contacts_filter_add_str(filter, propertyId, CONTACTS_MATCH_ENDSWITH, endValue->getString().c_str());
260 } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
261 contacts_filter_add_str(subFilter, propertyId, CONTACTS_MATCH_STARTSWITH, initialValue->getString().c_str());
262 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
263 contacts_filter_add_str(subFilter, propertyId, CONTACTS_MATCH_ENDSWITH, endValue->getString().c_str());
264 contacts_filter_add_filter(filter, subFilter);
267 if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) {
268 contacts_filter_add_int(filter, propertyId, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, iValue);
269 } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
270 contacts_filter_add_int(filter, propertyId, CONTACTS_MATCH_LESS_THAN, eValue);
271 } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
272 contacts_filter_add_int(subFilter, propertyId, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, iValue);
273 contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
274 contacts_filter_add_int(subFilter, propertyId, CONTACTS_MATCH_LESS_THAN, eValue);
275 contacts_filter_add_filter(filter, subFilter);
278 contacts_filter_destroy(subFilter);
281 contacts_filter_h CallHistoryFilter::getResult() const
283 contacts_filter_h filter = m_filterStack.top();