Update change log and spec for wrt-plugins-tizen_0.4.46
[platform/framework/web/wrt-plugins-tizen.git] / src / Callhistory / CallHistoryFilter.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <iomanip>
19 #include "CallHistoryDefine.h"
20 #include "CallHistoryFilter.h"
21 #include <Logger.h>
22
23 using namespace std;
24 using namespace DeviceAPI::Tizen;
25
26 namespace DeviceAPI {
27 namespace CallHistory {
28
29 CallHistoryFilter::CallHistoryFilter(contacts_filter_h filter)
30 {
31         m_filterStack.push(filter);
32 }
33
34 CallHistoryFilter::~CallHistoryFilter()
35 {
36         contacts_filter_h filter = NULL;
37         while (m_filterStack.size() > 1) {
38                 filter = m_filterStack.top();
39                 contacts_filter_destroy(filter);
40                 m_filterStack.pop();
41         }
42 }
43
44 void CallHistoryFilter::visitPreComposite(FilterType& type, int depth)
45 {
46         contacts_filter_h filter = NULL;
47         contacts_filter_create(_contacts_phone_log._uri, &filter);
48         if (filter != NULL) {
49                 m_filterStack.push(filter);
50         }
51 }
52
53 void CallHistoryFilter::visitInComposite(FilterType& type, int depth)
54 {
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);
60
61 }
62
63 void CallHistoryFilter::visitPostComposite(FilterType& type, int depth)
64 {
65         contacts_filter_h filter = m_filterStack.top();
66         if (m_filterStack.size() > 1) {
67                 m_filterStack.pop();
68                 contacts_filter_h filterParent = m_filterStack.top();
69                 contacts_filter_add_filter(filterParent, filter);
70                 contacts_filter_destroy(filter);
71         }
72 }
73
74 void CallHistoryFilter::visitAttribute(std::string& attrName, MatchFlag& matchFlag, DeviceAPI::Tizen::AnyPtr& matchValue, int depth)
75 {
76         std::string str ("");
77         contacts_match_str_flag_e mFlag;
78
79         if (matchValue == NULL) {
80                 return;
81         }
82
83         contacts_filter_h filter = m_filterStack.top();
84         contacts_filter_h subFilter = NULL;
85         contacts_filter_create(_contacts_phone_log._uri, &subFilter);
86
87         switch (matchFlag) {
88         case MATCH_EXACTLY:
89                 mFlag = CONTACTS_MATCH_EXACTLY;
90                 break;
91         case MATCH_FULLSTRING:
92                 mFlag = CONTACTS_MATCH_FULLSTRING;
93                 break;
94         case MATCH_CONTAINS:
95                 mFlag = CONTACTS_MATCH_CONTAINS;
96                 break;
97         case MATCH_STARTSWITH:
98                 mFlag = CONTACTS_MATCH_STARTSWITH;
99                 break;
100         case MATCH_ENDSWITH:
101                 mFlag = CONTACTS_MATCH_ENDSWITH;
102                 break;
103         case MATCH_EXISTS:
104                 mFlag = CONTACTS_MATCH_EXISTS;
105                 break;
106         default:
107                 mFlag = CONTACTS_MATCH_EXACTLY;
108         }
109
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);
141                 } else {
142                         contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
143                 }
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);
176                 } else {
177                         contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
178                 }
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()));
186                 }
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);
195                 } else {
196                         contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
197                 }
198         } else if (attrName.compare(STR_ENTRY_ID) == 0) {
199                 contacts_filter_add_str(filter, _contacts_phone_log.id, mFlag, matchValue->getString().c_str());
200         } else {
201                 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
202         }
203
204         contacts_filter_destroy(subFilter);
205 }
206
207 void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
208 {
209         if(initialValue == NULL || endValue == NULL)
210                 return;
211
212         contacts_filter_h filter = m_filterStack.top();
213         
214         unsigned int propertyId = 0;
215         int iValue = 0;
216         int eValue = 0;
217
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;
228         } else {
229                 return;
230         }
231
232         if (!initialValue->isNullOrUndefined()) {
233                 if (propertyId != _contacts_phone_log.address) {
234                         if(initialValue->isType(PrimitiveType_Time)) {
235                                 iValue = static_cast<int>(initialValue->getTimeT());
236                         } else {
237                                 iValue = atoi(initialValue->getString().c_str());
238                         }
239                 }
240         }
241
242         if (!endValue->isNullOrUndefined()) {
243                 if (propertyId != _contacts_phone_log.address) {
244                         if(endValue->isType(PrimitiveType_Time)) {
245                                 eValue = static_cast<int>(endValue->getTimeT());
246                         } else {
247                                 eValue = atoi(endValue->getString().c_str());
248                         }
249                 }
250         }
251
252         contacts_filter_h subFilter = NULL;
253         contacts_filter_create(_contacts_phone_log._uri, &subFilter);
254
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);
265                 }
266         } else {
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);
276                 }
277         }
278         contacts_filter_destroy(subFilter);
279 }
280
281 contacts_filter_h CallHistoryFilter::getResult() const
282 {
283         contacts_filter_h filter = m_filterStack.top();
284         return filter;
285 }
286
287 }
288 }