summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/common_util.cpp432
-rwxr-xr-xsrc/ps_app_interface.cpp760
-rwxr-xr-xsrc/ps_makeupviews.cpp1244
-rwxr-xr-xsrc/ps_searcher.cpp2255
-rwxr-xr-xsrc/search_bar.cpp572
-rwxr-xr-xsrc/smartsearch.cpp816
6 files changed, 6079 insertions, 0 deletions
diff --git a/src/common_util.cpp b/src/common_util.cpp
new file mode 100755
index 0000000..101b732
--- /dev/null
+++ b/src/common_util.cpp
@@ -0,0 +1,432 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd/
+ *
+ * Licensed under the Flora License, Version 1.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+
+
+
+#include <smartsearch.h>
+#include <common_util.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <unicode/uloc.h>
+#include <unicode/udat.h>
+#include <unicode/udatpg.h>
+#include <unicode/ustring.h>
+
+static UDateTimePatternGenerator *search_pattern_generator = NULL;
+static UDateFormat *search_formatter_yymmdd_12th;
+static UDateFormat *search_formatter_yymmdd_24th;
+
+static UDateFormat *search_formatter_yymmdd;
+static UDateFormat *search_formatter_yymm;
+
+UDateFormat *__search_util_make_date_format(const char *skeleton)
+{
+ SEARCH_FUNC_START;
+
+ UDateFormat *formatter = NULL;
+ UChar customSkeleton[SEARCH_MAX_UCHAR_SIZE] = { '\0' };
+ int32_t bestPatternCapacity, bestPatternLength;
+ UChar bestPattern[SEARCH_MAX_UCHAR_SIZE] = { 0, };
+ UErrorCode status = U_ZERO_ERROR;
+ const char *locale = NULL;
+
+ /* Pattern Generator */
+ if (search_pattern_generator) {
+ udatpg_close(search_pattern_generator);
+ search_pattern_generator = NULL;
+ }
+
+ uloc_setDefault(getenv("LC_TIME"), &status);
+
+ locale = uloc_getDefault();
+
+ search_pattern_generator = udatpg_open(uloc_getDefault(), &status);
+
+ if (!search_pattern_generator) {
+ SEARCH_DEBUG_WARNING
+ ("pattern_generator / udatpg_open fail : %s",
+ u_errorName(status));
+ return NULL;
+ }
+
+ SEARCH_DEBUG_LOG("skeleton : %s", skeleton);
+
+ u_uastrncpy(customSkeleton, skeleton, strlen(skeleton));
+
+ bestPatternCapacity =
+ (int32_t) (sizeof(bestPattern) / sizeof((bestPattern)[0]));
+ bestPatternLength =
+ udatpg_getBestPattern(search_pattern_generator, customSkeleton,
+ u_strlen(customSkeleton), bestPattern,
+ bestPatternCapacity, &status);
+
+ if (bestPatternLength == 0) {
+ SEARCH_DEBUG_WARNING("udatpg_getBestPattern fail");
+ return NULL;
+ }
+
+ formatter =
+ udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern,
+ -1, &status);
+
+ SEARCH_FUNC_END;
+
+ return formatter;
+ }
+
+
+void search_util_date_time_format_init()
+{
+ SEARCH_FUNC_START;
+
+ /* Date Time Format From Skeletons */
+ enum appcore_time_format timeformat;
+ int ret;
+ char *skeleton = NULL;
+
+ ret = appcore_get_timeformat(&timeformat);
+ if (ret == -1) {
+ SEARCH_DEBUG_WARNING("Fail to get time format!");
+ return;
+ }
+
+ SEARCH_MALLOC(skeleton, SEARCH_MAX_CHAR_SIZE, char);
+ snprintf(skeleton, SEARCH_MAX_CHAR_SIZE, "%s%s", UDAT_YEAR_MONTH_DAY, UDAT_HOUR_MINUTE);
+ search_formatter_yymmdd_12th = __search_util_make_date_format(skeleton);
+ snprintf(skeleton, SEARCH_MAX_CHAR_SIZE, "%s%s", UDAT_YEAR_MONTH_DAY, UDAT_HOUR24_MINUTE);
+ search_formatter_yymmdd_24th = __search_util_make_date_format(skeleton);
+ snprintf(skeleton, SEARCH_MAX_CHAR_SIZE, "%s", UDAT_YEAR_MONTH_DAY);
+ search_formatter_yymm = __search_util_make_date_format(skeleton);
+ SEARCH_FREE(skeleton);
+
+ if (timeformat == APPCORE_TIME_FORMAT_24) {
+ search_formatter_yymmdd = search_formatter_yymmdd_24th;
+ } else if (timeformat == APPCORE_TIME_FORMAT_12) {
+ search_formatter_yymmdd = search_formatter_yymmdd_12th;
+ } else {
+ SEARCH_DEBUG_WARNING("appcore_get_timeformat unknown error");
+ return;
+ }
+
+ SEARCH_FUNC_END;
+
+ return;
+ }
+
+void search_region_format_cb(void *data)
+{
+ SEARCH_FUNC_START;
+
+ enum appcore_time_format timeformat;
+ int ret;
+
+ ret = appcore_get_timeformat(&timeformat);
+
+ if (ret == -1) {
+ SEARCH_DEBUG_WARNING("Fail to get time format!");
+ return;
+ }
+
+ if (timeformat == APPCORE_TIME_FORMAT_24) {
+ search_formatter_yymmdd = search_formatter_yymmdd_24th;
+ } else if (timeformat == APPCORE_TIME_FORMAT_12) {
+ search_formatter_yymmdd = search_formatter_yymmdd_12th;
+ } else {
+ SEARCH_DEBUG_WARNING("appcore_get_timeformat unknown error");
+ return;
+}
+
+ SEARCH_FUNC_END;
+}
+
+void search_util_date_time_format_deinit()
+{
+ SEARCH_FUNC_START;
+
+ if (search_pattern_generator) {
+ udatpg_close(search_pattern_generator);
+ search_pattern_generator = NULL;
+ }
+
+ if (search_formatter_yymmdd_12th) {
+ udat_close(search_formatter_yymmdd_12th);
+ search_formatter_yymmdd_12th = NULL;
+ }
+
+ if (search_formatter_yymmdd_24th) {
+ udat_close(search_formatter_yymmdd_24th);
+ search_formatter_yymmdd_24th = NULL;
+ }
+
+ if (search_formatter_yymm) {
+ udat_close(search_formatter_yymm);
+ search_formatter_yymm = NULL;
+ }
+
+ SEARCH_FUNC_END;
+
+ return;
+}
+
+void search_util_date_time_format_get_val(time_t time, char *format_val, int type)
+{
+ SEARCH_FUNC_START;
+
+ UDate date;
+ UChar formatted[SEARCH_MAX_UCHAR_SIZE] = { 0, };
+ int32_t formattedCapacity, formattedLength;
+ UErrorCode status = U_ZERO_ERROR;
+ char formattedString[SEARCH_MAX_CHAR_SIZE] = { 0, };
+
+ date = (UDate) time *1000;
+
+ formattedCapacity =
+ (int32_t) (sizeof(formatted) / sizeof((formatted)[0]));
+
+ switch(type) {
+ case SEARCH_DATE_TYPE_YYMMDD:
+ if (search_formatter_yymmdd) {
+ formattedLength =
+ udat_format(search_formatter_yymmdd, date, formatted, formattedCapacity,
+ NULL, &status);
+ if (formattedLength == -1) {
+ SEARCH_DEBUG_WARNING("udat_format fail");
+ return;
+ }
+ }
+ break;
+ case SEARCH_DATE_TYPE_YYMM:
+ if (search_formatter_yymm) {
+ formattedLength =
+ udat_format(search_formatter_yymm, date, formatted, formattedCapacity,
+ NULL, &status);
+ if (formattedLength == -1) {
+ SEARCH_DEBUG_WARNING("udat_format fail");
+ return;
+ }
+ }
+ break;
+ }
+
+
+ u_austrncpy(formattedString, formatted, SEARCH_MAX_CHAR_SIZE);
+
+ SEARCH_DEBUG_LOG("formattedString : %s", formattedString);
+
+ snprintf(format_val, MAX_LENGTH_PER_LINE, "%s", formattedString);
+
+ SEARCH_FUNC_END;
+}
+
+void search_sql_make_keyword_bind_value(char *src, char *dest, int type)
+{
+ char *tmp;
+
+ if(type == SEARCH_SQL_BIND_TYPE_DUPLEX) {
+ *dest = '%';
+ ++dest;
+ }
+
+ for (tmp = src; *tmp; ++tmp, ++dest) {
+ if ((*tmp == '%') || (*tmp == '_') || (*tmp == *DB_ESCAPE_CHAR)) {
+ *dest = *DB_ESCAPE_CHAR;
+ ++dest;
+ }
+
+ *dest = *tmp;
+ }
+
+ *dest = '%';
+}
+
+void search_get_date_string(char *date_string)
+{
+ struct tm *time_tm = NULL;
+
+ unsigned long seconds;
+ seconds = atol(date_string);
+
+ time_tm = gmtime((time_t *) & seconds);
+ sprintf(date_string, "%4d-%02d-%02d %02d:%02d:%02d", time_tm->tm_year
+ + 1900, time_tm->tm_mon + 1, time_tm->tm_mday, time_tm->tm_hour,
+ time_tm->tm_min, time_tm->tm_sec);
+}
+
+
+#if (!CHECK_VALIDATE_UTF8)
+const char *search_markup_keyword(const char *string, char *searchword,
+ bool *result)
+{
+ char pstr[DEF_BUF_LEN + 1] = {0,};
+ char result_str[DEF_BUF_LEN + 1] = {0,};
+ char start_str[DEF_BUF_LEN + 1] = {0,};
+ static char return_string[DEF_BUF_LEN + 1] = { 0, };
+ int word_len = 0;
+ int search_len = 0;
+ int i = 0;
+ bool found = false;
+
+ SEARCH_RET_IF_STR_INVALID(string, return_string);
+ SEARCH_RET_IF_STR_INVALID(searchword, return_string);
+
+ strncpy(pstr, string, DEF_BUF_LEN);
+
+ word_len = strlen(pstr);
+ search_len = strlen(searchword);
+
+ for (i = 0; i < word_len; i++) {
+ if (!strncasecmp(searchword, &pstr[i], search_len)) {
+ found = true;
+ break;
+ }
+ }
+
+ *result = found;
+
+ if (found) {
+ if (i == 0) {
+ strncpy(result_str, &pstr[i], search_len);
+ result_str[search_len] = '\0';
+ snprintf(return_string, 128,
+ "<match>%s</match>%s", &result_str[0],
+ &pstr[search_len]);
+ } else if (i > 0) {
+ strncpy(start_str, &pstr[0], i);
+ start_str[i + 1] = '\0';
+ strncpy(result_str, &pstr[i], search_len);
+ result_str[search_len] = '\0';
+ snprintf(return_string, 128,
+ "%s<match>%s</match>%s", &start_str[0],
+ &result_str[0], &pstr[i + search_len]);
+ }
+ } else {
+ snprintf(return_string, 128, "%s", pstr);
+ }
+
+ return return_string;
+}
+
+
+#else
+const char *search_markup_keyword(const char *string, char *searchword,
+ bool *result)
+{
+ char pstr[DEF_BUF_LEN + 1] = {0,};
+ static char return_string[DEF_BUF_LEN + 1] = { 0, };
+ int word_len = 0;
+ int search_len = 0;
+ int i = 0;
+ bool found = false;
+ gchar* markup_text_start;
+ gchar* markup_text_end;
+ gchar* markup_text;
+
+ SEARCH_RET_IF_STR_INVALID(string, return_string);
+ SEARCH_RET_IF_STR_INVALID(searchword, return_string);
+
+ if(g_utf8_validate(string,-1,NULL)) {
+
+ strncpy(pstr, string, DEF_BUF_LEN);
+
+ word_len = strlen(pstr);
+ search_len = strlen(searchword);
+
+ for (i = 0; i < word_len; i++) {
+ if (!strncasecmp(searchword, &pstr[i], search_len)) {
+ found = true;
+ break;
+ }
+ }
+
+ *result = found;
+ memset(return_string, 0x00, DEF_BUF_LEN);
+
+ if (found) {
+ if (i == 0) {
+ markup_text = g_markup_escape_text(&pstr[0], search_len);
+ markup_text_end = g_markup_escape_text(&pstr[search_len], word_len-search_len);
+ snprintf(return_string,
+ DEF_BUF_LEN,
+ "<match>%s</match>%s",
+ markup_text,
+ (char*)markup_text_end);
+ g_free(markup_text);
+ g_free(markup_text_end);
+ } else {
+ markup_text_start = g_markup_escape_text(&pstr[0], i);
+ markup_text = g_markup_escape_text(&pstr[i], search_len);
+ markup_text_end = g_markup_escape_text(&pstr[i+search_len], word_len-(i+search_len));
+ snprintf(return_string,
+ DEF_BUF_LEN,
+ "%s<match>%s</match>%s",
+ (char*)markup_text_start,
+ markup_text,
+ (char*)markup_text_end);
+ g_free(markup_text);
+ g_free(markup_text_start);
+ g_free(markup_text_end);
+ }
+ } else {
+ snprintf(return_string, 128, "%s", pstr);
+ }
+ }
+
+ return return_string;
+}
+#endif
+
+char *search_get_main_window_name()
+{
+ SEARCH_FUNC_START;
+
+ XTextProperty tp;
+ int count = 0, i, ret;
+ char **list = NULL;
+ char return_win_name[256] = { 0, };
+ int revert_to;
+ Window focus_win;
+ Display *dpy;
+ int screen = 0;
+
+ dpy = XOpenDisplay(0);
+ screen = DefaultScreen(dpy);
+
+ XGetInputFocus(dpy, &focus_win, &revert_to);
+
+ if (focus_win) {
+ XGetWMName(dpy, focus_win, &tp);
+ if (tp.nitems > 0) {
+ ret =
+ XmbTextPropertyToTextList(dpy, &tp, &list, &count);
+ if ((ret == Success || ret > 0) && list != NULL) {
+ for (i = 0; i < count; i++)
+ strncpy(return_win_name, list[i],
+ strlen(list[i]));
+ XFreeStringList(list);
+ }
+ }
+ } else {
+ return NULL;
+ }
+
+ SEARCH_FUNC_END;
+
+ return strdup(return_win_name);
+}
diff --git a/src/ps_app_interface.cpp b/src/ps_app_interface.cpp
new file mode 100755
index 0000000..dbecb51
--- /dev/null
+++ b/src/ps_app_interface.cpp
@@ -0,0 +1,760 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd/
+ *
+ * Licensed under the Flora License, Version 1.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+
+
+
+#include "smartsearch.h"
+#include "ps_app_interface.h"
+#include "ps_searcher.h"
+#include <ui-gadget.h>
+#include <contacts-ug.h>
+#include <aul_service.h>
+#include <app.h>
+#include <app_manager.h>
+#include <bundle.h>
+
+static void __search_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode,
+ void *priv)
+{
+ SEARCH_FUNC_START;
+
+ Evas_Object *base = NULL; (Evas_Object *) ug_get_layout(ug);
+ Evas_Object *win = NULL;
+
+ SEARCH_RET_IF(ug == NULL || priv == NULL);
+
+ base = (Evas_Object *)ug_get_layout(ug);
+ win = (Evas_Object *)ug_get_window();
+
+ SEARCH_RET_IF(base == NULL);
+ SEARCH_RET_IF(win == NULL);
+
+ switch (mode) {
+ case UG_MODE_FULLVIEW:
+ evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, base);
+ evas_object_show(base);
+ break;
+ default:
+ break;
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_ug_closed_cb(ui_gadget_h ug, void *priv)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)priv;
+
+ SEARCH_RET_IF(ug == NULL);
+ SEARCH_RET_IF(ad == NULL);
+
+ ug_destroy(ug);
+ ad->detail_ug = NULL;
+
+ elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
+
+ if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
+ elm_object_scroll_freeze_pop(ad->search_gl);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_contact_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ service_h service = NULL;
+ int ret = 0;
+ bool err_popup_show = true;
+
+ Ecore_X_Window win_id = -1;
+
+ win_id = elm_win_xwindow_get(ad->win_main);
+
+ ret = service_create(&service);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_create");
+ goto out_func;
+ }
+
+ ret = service_set_app_id(service, "contacts-details-efl");
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_set_app_id!");
+ goto out_func;
+ }
+
+ ret = service_set_window(service, win_id);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_set_window!");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "type", "0");;
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : type!");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "person_id", cur_category_mem->launch_param);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_add_extra_data : person_id");
+ goto out_func;
+ }
+
+ ret = service_send_launch_request(service, NULL, NULL);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request");
+ goto out_func;
+ } else {
+ err_popup_show = false;
+ }
+
+out_func:
+ if (err_popup_show == true) {
+ search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
+ }
+
+ if (service != NULL) {
+ service_destroy(service);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_msg_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ service_h service = NULL;
+ int ret = 0;
+ bool err_popup_show = true;
+
+ ret = service_create(&service);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_create");
+ goto out_func;
+ }
+
+ ret = service_set_package(service, "org.tizen.message");
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_set_package!");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "type", "msg_id");
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msg_id");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "msgId", cur_category_mem->launch_param);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_set_extra_data : msgId parameter!");
+ goto out_func;
+ }
+
+ ret = service_send_launch_request(service, NULL, NULL);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("[Fail] service_send_launch_request");
+ goto out_func;
+ } else {
+ err_popup_show = false;
+ }
+
+out_func:
+ if (err_popup_show == true) {
+ search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
+ }
+
+ if (service != NULL) {
+ service_destroy(service);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_email_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ char *token_param = NULL;
+ char *saveptr1;
+ int i = 0;
+ int ret = 0;
+ bool err_popup_show = true;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+
+ char temp_path[MAX_LENGTH_PER_PATH] = { 0, };
+
+ service_h service = NULL;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ ret = service_create(&service);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to create service handle!");
+ goto out_func;
+ }
+
+ snprintf(temp_path, MAX_LENGTH_PER_PATH - 1, "%s", cur_category_mem->launch_path);
+ token_param = strtok_r(temp_path, " ", &saveptr1);
+
+ while (token_param != NULL) {
+ SEARCH_DEBUG_LOG("PARAMETER (%d) : %s", i, token_param);
+ if (i == 0) {
+ ret = service_add_extra_data(service, "ACCOUNT_ID", token_param);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add extra data : ACCOUND_ID!");
+ goto out_func;
+ }
+ } else if (i == 1) {
+ ret = service_add_extra_data(service, "MAIL_ID", token_param);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add extra data : MAIL_ID!");
+ goto out_func;
+ }
+ } else if (i == 2) {
+ ret = service_add_extra_data(service, "MAILBOX_ID", token_param);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add extra data : MAILBOX_ID!");
+ goto out_func;
+ }
+ } else {
+ break;
+ }
+
+ i++;
+ token_param = strtok_r(NULL, " ", &saveptr1);
+ }
+
+ ret = service_add_extra_data(service, "RUN_TYPE", "7");
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add extra data : RUN_TYPE!");
+ goto out_func;
+ }
+
+ ret = service_set_package(service, "org.tizen.email");
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to set package!");
+ goto out_func;
+ }
+
+ ret = service_send_launch_request(service, NULL, NULL);
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to send service!");
+ goto out_func;
+ }
+ err_popup_show = false;
+
+out_func:
+ if (err_popup_show == true) {
+ search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
+ }
+
+ if (service != NULL) {
+ ret = service_destroy(service);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
+ }
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_image_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+ int ret;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ if (access(cur_category_mem->launch_path, F_OK) != 0) {
+ SEARCH_DEBUG_ERROR("image access error : %s",
+ cur_category_mem->launch_path);
+ search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND,
+ ad);
+ } else {
+ SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
+ cur_category_mem->launch_path);
+
+ service_h service;
+ ret = service_create(&service);
+
+ if (ret == 0) {
+ service_set_operation(service, SERVICE_OPERATION_VIEW);
+ service_set_uri(service, cur_category_mem->launch_path);
+ ret = service_send_launch_request(service, NULL, NULL);
+
+ if (ret != 0) {
+ SEARCH_DEBUG_ERROR("image app service launching error(%d)", ret);
+ search_launch_popup_error(LAUNCH_ERROR_APPSVC,
+ ad);
+ }
+ service_destroy(service);
+ }
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_video_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+ int ret;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ if (access(cur_category_mem->launch_path, F_OK) != 0) {
+ SEARCH_DEBUG_ERROR("video access error : %s",
+ cur_category_mem->launch_path);
+ search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
+ } else {
+ SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
+ cur_category_mem->launch_path);
+
+ service_h service;
+ ret = service_create(&service);
+
+ if (ret == 0) {
+ service_set_operation(service, SERVICE_OPERATION_VIEW);
+ service_set_uri(service, cur_category_mem->launch_path);
+ ret = service_send_launch_request(service, NULL, NULL);
+
+ if (ret != 0) {
+ SEARCH_DEBUG_ERROR("video app service launching error(%d)", ret);
+ search_launch_popup_error(LAUNCH_ERROR_APPSVC,
+ ad);
+ }
+ service_destroy(service);
+ }
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_music_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+ int ret;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ if (access(cur_category_mem->launch_path, F_OK) != 0) {
+ SEARCH_DEBUG_ERROR("music file access error : %s",
+ cur_category_mem->launch_path);
+ search_launch_popup_error(LAUNCH_ERROR_FILE_NOT_FOUND, ad);
+ } else {
+ SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s",
+ cur_category_mem->launch_path);
+
+ service_h service;
+ ret = service_create(&service);
+
+ if (ret == 0) {
+ service_set_operation(service, SERVICE_OPERATION_VIEW);
+ service_set_uri(service, cur_category_mem->launch_path);
+ ret = service_send_launch_request(service, NULL, NULL);
+
+ if (ret != 0) {
+ SEARCH_DEBUG_ERROR("music app service launching error(%d)", ret);
+ search_launch_popup_error(LAUNCH_ERROR_APPSVC,
+ ad);
+ }
+ service_destroy(service);
+ }
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_calendar_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+ ui_gadget_h ug = NULL;
+ struct ug_cbs cbs = { 0, };
+ int ret = 0;
+ bool err_popup_show = true;
+ service_h service = NULL;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ if (strlen(cur_category_mem->launch_param) <= 0) {
+ SEARCH_DEBUG_ERROR("Selected item does not have data!");
+ goto out_func;
+ } else {
+ ret = service_create(&service);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to create service handle!");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "itemType", "event");
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "eventId", cur_category_mem->launch_param);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 2!");
+ goto out_func;
+ }
+
+ cbs.destroy_cb = __search_ug_closed_cb;
+ cbs.layout_cb = __search_ug_layout_cb;
+ cbs.result_cb = NULL;
+ cbs.priv = ad;
+
+ ug = ug_create(NULL, "calendar-detail-efl", UG_MODE_FULLVIEW, service, &cbs);
+
+ if (!ug) {
+ SEARCH_DEBUG_ERROR("... create_ug_calendar : failed !!!");
+ goto out_func;
+ }
+
+ ad->detail_ug = ug;
+ err_popup_show = false;
+ }
+
+out_func:
+ if (err_popup_show == true) {
+ search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
+ }
+
+ if (service != NULL) {
+ service_destroy(service);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_memo_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem = (struct search_item_sel *)record_info;
+ ui_gadget_h ug = NULL;
+ struct ug_cbs cbs = { 0, };
+
+ int ret = 0;
+ bool err_popup_show = true;
+
+ service_h service = NULL;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ if (strlen(cur_category_mem->launch_param) <= 0) {
+ SEARCH_DEBUG_ERROR("Selected item does not have data!");
+ goto out_func;
+ } else {
+ if (ad->detail_ug) {
+ SEARCH_DEBUG_WARNING("prev ug is exist. destroy prev ug");
+ ug_destroy(ug);
+ ad->detail_ug = NULL;
+ }
+
+ ret = service_create(&service);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to create service handle!");
+ goto out_func;
+ }
+
+ ret = service_add_extra_data(service, "index", cur_category_mem->launch_param);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to add service extra data : parameter 1!");
+ goto out_func;
+ }
+
+ cbs.layout_cb = __search_ug_layout_cb;
+ cbs.result_cb = NULL;
+ cbs.destroy_cb = __search_ug_closed_cb;
+ cbs.priv = ad;
+
+ ug = ug_create(NULL, "memo-efl", UG_MODE_FULLVIEW, service, &cbs);
+
+ if (!ug) {
+ SEARCH_DEBUG_ERROR("... create_ug_email : failed !!!");
+ goto out_func;
+ }
+
+ ad->detail_ug = ug;
+ err_popup_show = false;
+ }
+
+out_func:
+ if (err_popup_show == true) {
+ search_launch_popup_error(LAUNCH_ERROR_AUL_LAUNCH, ad);
+ }
+
+ if (service != NULL) {
+ service_destroy(service);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_menu_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem =
+ (struct search_item_sel *)record_info;
+ char *pkg_name = NULL;
+ bool is_running = false;
+ app_context_h app_h;
+
+ bool err_popup_show = true;
+ int ret;
+ service_h service = NULL;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ pkg_name = cur_category_mem->launch_path;
+
+ if (pkg_name != NULL && strlen(pkg_name)) {
+ ret = app_manager_is_running(pkg_name, &is_running);
+
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to get info : app_manager_is_running [%d]", ret);
+ goto out_func;
+ }
+
+ if (is_running == true) {
+ ret = app_manager_get_app_context(pkg_name, &app_h);
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to get info : app_manager_get_app_context [%d]", ret);
+ goto out_func;
+ }
+
+ ret = app_manager_resume_app(app_h);
+
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to get info : app_manager_resume_app [%d]", ret);
+ goto out_func;
+ }
+ err_popup_show = false;
+ } else {
+ ret = service_create(&service);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to create service header : [%d]", ret);
+ goto out_func;
+ }
+
+ ret = service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to set operation : [%d]", ret);
+ goto out_func;
+ }
+
+ ret = service_set_package(service, pkg_name);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to set package : [%d]", ret);
+ goto out_func;
+ }
+
+ ret = service_send_launch_request(service, NULL, NULL);
+
+ if (ret != SERVICE_ERROR_NONE) {
+ SEARCH_DEBUG_ERROR("Fail to send launch request : [%d]", ret);
+ goto out_func;
+ }
+ err_popup_show = false;
+ }
+ } else {
+ SEARCH_DEBUG_ERROR("Pkg name is NULL!");
+ }
+
+out_func:
+ if (err_popup_show == true)
+ search_launch_popup_error(LAUNCH_ERROR_APPSVC, ad);
+
+ if (service != NULL) {
+ ret = service_destroy(service);
+
+ if (ret != SERVICE_ERROR_NONE)
+ SEARCH_DEBUG_ERROR("Fail to destroy service header : [%d]", ret);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_browser_view(void *data, void *record_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem =
+ (struct search_item_sel *)record_info;
+ int ret;
+ service_h service;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ SEARCH_DEBUG_LOG("cur_category_mem->launch_path : %s", cur_category_mem->launch_path);
+
+ ret = service_create(&service);
+
+ if (ret == 0 && strlen(cur_category_mem->launch_path) > 0 ) {
+ service_set_operation(service, SERVICE_OPERATION_VIEW);
+ service_set_uri(service, cur_category_mem->launch_path);
+ ret = service_send_launch_request(service, NULL, NULL);
+
+ if (ret != 0) {
+ SEARCH_DEBUG_ERROR("browser app service launching error(%d)", ret);
+ search_launch_popup_error(LAUNCH_ERROR_APPSVC,
+ ad);
+ }
+ service_destroy(service);
+ }
+
+}
+
+static void __search_launch_popup_error_response_cb(void *data,
+ Evas_Object * obj,
+ void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ evas_object_del(ad->ctxpopup);
+ ad->ctxpopup = NULL;
+
+ SEARCH_FUNC_END;
+}
+
+void search_launch_popup_error(int error_type, void *data)
+{
+ Evas_Object *popup;
+ Evas_Object *btn1;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ if (error_type >= LAUNCH_ERROR_MAX) {
+ SEARCH_DEBUG_ERROR("wrong error_type : %d", error_type);
+ }
+
+ if (ad->ctxpopup) {
+ evas_object_del(ad->ctxpopup);
+ ad->ctxpopup = NULL;
+ }
+
+ elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
+
+ if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
+ elm_object_scroll_freeze_pop(ad->search_gl);
+ }
+
+ popup = elm_popup_add(ad->win_main);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+
+ switch(error_type) {
+ case LAUNCH_ERROR_FILE_NOT_FOUND:
+ elm_object_text_set(popup,
+ dgettext("sys_string",
+ "IDS_COM_POP_FILE_NOT_FOUND"));
+ break;
+ case LAUNCH_ERROR_AUL_LAUNCH:
+ /* This Message String enable to be another string in the future */
+ elm_object_text_set(popup,
+ gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
+ break;
+ case LAUNCH_ERROR_APPSVC:
+ elm_object_text_set(popup,
+ gettext("IDS_SSEARCH_POP_SELECTED_DATA_DOES_NOT_EXIST"));
+ break;
+ }
+
+ btn1 = elm_button_add(popup);
+ elm_object_style_set(btn1, "popup_button/default");
+
+ elm_object_text_set(btn1,
+ dgettext("sys_string","IDS_COM_POP_CLOSE"));
+ evas_object_smart_callback_add(btn1, "clicked",
+ __search_launch_popup_error_response_cb,
+ ad);
+
+ elm_object_part_content_set(popup, "button1", btn1);
+
+ elm_popup_timeout_set(popup, 3.0);
+
+ evas_object_smart_callback_add(popup, "timeout",
+ __search_launch_popup_error_response_cb,
+ ad);
+ evas_object_smart_callback_add(popup, "block,clicked",
+ __search_launch_popup_error_response_cb,
+ ad);
+ evas_object_show(popup);
+
+ ad->ctxpopup = popup;
+}
+
diff --git a/src/ps_makeupviews.cpp b/src/ps_makeupviews.cpp
new file mode 100755
index 0000000..b3888e9
--- /dev/null
+++ b/src/ps_makeupviews.cpp
@@ -0,0 +1,1244 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd/
+ *
+ * Licensed under the Flora License, Version 1.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "smartsearch.h"
+#include "ps_searcher.h"
+#include "ps_app_interface.h"
+#include <contacts.h>
+#include <calendar2.h>
+#include <memo-db.h>
+#include <media_content.h>
+#include <msg_types.h>
+#include <msg_storage.h>
+#include <msg.h>
+#include <favorites.h>
+
+struct search_thread_data {
+ struct appdata *ad;
+ char *keyword;
+ int is_search_result;
+};
+
+struct search_genlist_item_info* search_add_genlist_item(int type,
+ struct search_content_object *obj, Elm_Genlist_Item_Class *itc_style, void *data,
+ Elm_Object_Item *parent)
+{
+ struct search_genlist_item_info *item = (struct search_genlist_item_info *)
+ calloc(1,
+ sizeof(struct search_genlist_item_info));
+
+ if (item) {
+ item->type = type;
+ item->obj = obj;
+ item->itc_style = itc_style;
+ item->data = data;
+ item->parent = parent;
+ }
+
+ return item;
+}
+
+static void
+ecore_exe_pipe_cb(void *data, void *buf, unsigned int size)
+{
+ SEARCH_FUNC_START;
+
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_pipe_data *pipe_data = *((struct search_pipe_data**)buf);
+
+ struct search_content_object *obj = NULL;
+ struct search_genlist_item_info *item = NULL;
+ struct search_genlist_info *result_info = NULL;
+
+ int cmd = 0;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(pipe_data == NULL);
+
+ result_info = pipe_data->result_list;
+ cmd = pipe_data->cmd;
+
+ SEARCH_DEBUG_LOG("Pipe Command : %d ret : %d", cmd, pipe_data->search_ret);
+
+ switch (cmd) {
+ case SEARCH_PIPE_CMD_CLEAR_GENLIST:
+ elm_genlist_clear(ad->search_gl);
+ break;
+ case SEARCH_PIPE_CMD_SET_LAYOUT:
+ if (pipe_data->search_ret == SEARCH_RET_SEARCH_SUCCESS)
+ search_layout_set_search_list(ad);
+ else
+ search_layout_set_search_no_result(ad);
+ break;
+ case SEARCH_PIPE_CMD_ADD_GENLIST_PHONE:
+ if (result_info) {
+ if (result_info->group) {
+ item = result_info->group;
+ obj = item->obj;
+
+ obj->gl_result_grp = elm_genlist_item_append(ad->search_gl,
+ item->itc_style,
+ item->data,
+ NULL,
+ ELM_GENLIST_ITEM_GROUP,
+ NULL,
+ NULL);
+ elm_genlist_item_select_mode_set(obj->gl_result_grp,
+ ELM_OBJECT_SELECT_MODE_NONE);
+ SEARCH_FREE(item);
+ }
+
+ if (result_info->itemlist) {
+ GList *node = g_list_first(result_info->itemlist);
+
+ while (node != NULL) {
+ item = (struct search_genlist_item_info *)node->data;
+ if (item) {
+ obj = item->obj;
+ elm_genlist_item_append(ad->search_gl,
+ item->itc_style,
+ item->data,
+ obj->gl_result_grp,
+ ELM_GENLIST_ITEM_NONE,
+ search_gl_phone_result_sel,
+ ad);
+ SEARCH_FREE(item);
+ }
+ node = g_list_next(node);
+ }
+ g_list_free(result_info->itemlist);
+ result_info->itemlist = NULL;
+ }
+
+ if (result_info->more) {
+ item = result_info->more;
+ obj = item->obj;
+ elm_genlist_item_append(ad->search_gl,
+ item->itc_style,
+ item->data,
+ obj->gl_result_grp,
+ ELM_GENLIST_ITEM_NONE,
+ search_gl_result_more_item_append_cb,
+ ad);
+ SEARCH_FREE(item);
+ }
+
+ SEARCH_FREE(result_info);
+ }
+ break;
+ }
+
+ SEARCH_FREE(pipe_data);
+ SEARCH_FUNC_END;
+}
+
+static Evas_Object *__search_gl_content_get_genlist_item_type(void *data, Evas_Object *obj, const char *part)
+ {
+ Evas_Object *icon = NULL;
+ int icon_size = 0;
+ char *icon1_path = NULL;
+ char *icon2_path = NULL;
+
+ struct search_item_sel *sel_mem_info = (struct search_item_sel *)data;
+ double scale = elm_config_scale_get();
+
+ SEARCH_RETV_IF(sel_mem_info == NULL, NULL);
+
+ if (!SEARCH_STRCMP(part, "elm.icon") || !SEARCH_STRCMP(part, "elm.icon.1")) {
+ icon1_path = sel_mem_info->icon1;
+ if (icon1_path && strlen(icon1_path) > 0 ) {
+ icon = elm_icon_add(obj);
+ icon_size = (int)(SEARCH_THUMBNAIL_SIZE * scale);
+ elm_image_prescale_set(icon, icon_size);
+ elm_image_file_set(icon, icon1_path, NULL);
+ evas_object_size_hint_min_set(icon,
+ SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale);
+ evas_object_size_hint_max_set(icon,
+ SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale);
+ evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ }
+ } else if(!strcmp(part, "elm.icon.2")) {
+ icon2_path = sel_mem_info->icon2;
+
+ if (icon2_path && strlen(icon2_path) > 0 ) {
+ icon = elm_icon_add(obj);
+ icon_size = (int)(SEARCH_ICON_SIZE * scale);
+ elm_image_prescale_set(icon, icon_size);
+ elm_image_file_set(icon, icon2_path, NULL);
+ evas_object_size_hint_min_set(icon,
+ SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale);
+ evas_object_size_hint_max_set(icon,
+ SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale);
+ evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ }
+ }
+
+ return icon;
+}
+
+static Evas_Object *__search_gl_content_get_genlist_bookmark_item_type(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *icon = NULL;
+ int icon_size = 0;
+ int id = 0;
+ char *icon2_path = NULL;
+
+ struct search_item_sel *sel_mem_info = (struct search_item_sel *)data;
+ SEARCH_RETV_IF(sel_mem_info == NULL, NULL);
+
+ double scale = elm_config_scale_get();
+
+ if (!SEARCH_STRCMP(part, "elm.icon") || !SEARCH_STRCMP(part, "elm.icon.1")) {
+ if (sel_mem_info->launch_param) {
+ id = atoi(sel_mem_info->launch_param);
+ favorites_bookmark_get_favicon(id, evas_object_evas_get(obj), &icon);
+ }
+
+ if (!icon && sel_mem_info->icon1) {
+ icon = elm_icon_add(obj);
+ icon_size = (int)(SEARCH_ICON_SIZE * scale);
+ elm_image_prescale_set(icon, icon_size);
+ elm_image_file_set(icon, sel_mem_info->icon1, NULL);
+ }
+
+ if (icon) {
+ evas_object_size_hint_min_set(icon,
+ SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale);
+ evas_object_size_hint_max_set(icon,
+ SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale);
+ evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ }
+ } else if(!strcmp(part, "elm.icon.2")) {
+ icon2_path = sel_mem_info->icon2;
+
+ if (icon2_path && strlen(icon2_path) > 0 ) {
+ icon = elm_icon_add(obj);
+ icon_size = (int)(SEARCH_ICON_SIZE * scale);
+ elm_image_prescale_set(icon, icon_size);
+ elm_image_file_set(icon, icon2_path, NULL);
+ evas_object_size_hint_min_set(icon,
+ SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale);
+ evas_object_size_hint_max_set(icon,
+ SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale);
+ evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ }
+ }
+ return icon;
+ }
+
+static Evas_Object *__search_gl_content_get_genlist_history_item_type(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *icon = NULL;
+ int icon_size = 0;
+ char *icon2_path = NULL;
+ int id = 0;
+
+ struct search_item_sel *sel_mem_info = (struct search_item_sel *)data;
+ SEARCH_RETV_IF(sel_mem_info == NULL, NULL);
+
+ double scale = elm_config_scale_get();
+
+ if (!SEARCH_STRCMP(part, "elm.icon") || !SEARCH_STRCMP(part, "elm.icon.1")) {
+ if (sel_mem_info->launch_param) {
+ id = atoi(sel_mem_info->launch_param);
+ favorites_history_get_favicon(id, evas_object_evas_get(obj), &icon);
+ }
+
+ if (!icon && sel_mem_info->icon1) {
+ icon = elm_icon_add(obj);
+ icon_size = (int)(SEARCH_ICON_SIZE * scale);
+ elm_image_prescale_set(icon, icon_size);
+ elm_image_file_set(icon, sel_mem_info->icon1, NULL);
+ }
+
+ if (icon) {
+ evas_object_size_hint_min_set(icon,
+ SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale);
+ evas_object_size_hint_max_set(icon,
+ SEARCH_THUMBNAIL_SIZE * scale, SEARCH_THUMBNAIL_SIZE * scale);
+ evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ }
+ } else if(!strcmp(part, "elm.icon.2")) {
+ icon2_path = (char*)sel_mem_info->icon2;
+
+ if (icon2_path && strlen(icon2_path) > 0 ) {
+ icon = elm_icon_add(obj);
+ icon_size = (int)(SEARCH_ICON_SIZE * scale);
+ elm_image_prescale_set(icon, icon_size);
+ elm_image_file_set(icon, icon2_path, NULL);
+ evas_object_size_hint_min_set(icon,
+ SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale);
+ evas_object_size_hint_max_set(icon,
+ SEARCH_ICON_SIZE * scale, SEARCH_ICON_SIZE * scale);
+ evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ }
+ }
+
+ return icon;
+}
+
+static Eina_Bool __search_gl_state_get(void *data, Evas_Object * obj,
+ const char *part)
+{
+ return EINA_FALSE;
+}
+
+static char *__search_gl_label_get_genlist_item_type(void *data, Evas_Object * obj,
+ const char *part)
+{
+ char *buf = NULL;
+ struct search_item_sel *sel_mem_info = (struct search_item_sel *)data;
+ SEARCH_RETV_IF(sel_mem_info == NULL, g_strdup(""));
+
+ if (!SEARCH_STRCMP(part, "elm.text") || !SEARCH_STRCMP(part, "elm.text.1")) {
+ buf = g_strdup(sel_mem_info->text1);
+ } else if (!SEARCH_STRCMP(part, "elm.text.sub") || !SEARCH_STRCMP(part, "elm.text.2")) {
+ buf = g_strdup(sel_mem_info->text2);
+ } else {
+ buf = NULL;
+ }
+
+ return buf;
+}
+
+static char *__search_gl_label_get_normal_type(void *data, Evas_Object * obj,
+ const char *part)
+{
+ char *title_string = (char*)data;
+ if(title_string)
+ return strdup(title_string);
+ else
+ return strdup("");
+}
+
+static char *__search_gl_label_get_group(void *data, Evas_Object * obj,
+ const char *part)
+{
+ struct search_content_object *object = (struct search_content_object*)data;
+ SEARCH_RETV_IF(object == NULL, strdup(""));
+
+ if (object->string_type == SEARCH_STR_TYPE_APP_STRING) {
+ return strdup(gettext(object->name));
+ } else {
+ return strdup(dgettext("sys_string", object->name));
+ }
+}
+
+static char *__search_gl_label_get_more(void *data, Evas_Object * obj,
+ const char *part)
+{
+ return strdup(gettext("IDS_SSEARCH_BODY_MORE_RESULTS"));
+}
+
+static void __search_gl_del_grouptitle(void *data, Evas_Object * obj)
+{
+ SEARCH_FUNC_START;
+
+ SEARCH_FUNC_END;
+ return;
+}
+
+static void __search_gl_del(void *data, Evas_Object * obj)
+{
+ struct search_item_sel *sel_mem_info = (struct search_item_sel *)data;
+ SEARCH_RET_IF(sel_mem_info == NULL);
+
+ SEARCH_FREE(sel_mem_info->icon1);
+ SEARCH_FREE(sel_mem_info->icon2);
+ SEARCH_FREE(sel_mem_info->text1);
+ SEARCH_FREE(sel_mem_info->text2);
+ SEARCH_FREE(sel_mem_info->launch_path);
+ SEARCH_FREE(sel_mem_info->launch_param);
+ SEARCH_FREE(sel_mem_info);
+
+ return;
+}
+
+static void __search_gl_del_more_button(void *data, Evas_Object * obj)
+{
+ struct search_item_more_sel *sel_mem_more = (struct search_item_more_sel *)data;
+ SEARCH_RET_IF(sel_mem_more == NULL);
+
+ SEARCH_FREE(sel_mem_more);
+
+ return;
+}
+
+int search_app_connect(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ int rc = 0, conn_ret = 0;
+ int ret = SEARCH_RET_SUCCESS;
+ int i = 0;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_FAIL);
+
+ for (i = 0; i < SEARCH_CONT_MAX ; ++i) {
+ switch (ad->result_obj[i].contents_type) {
+ /* Contact-service should be conneted for display Message result.
+ Because We should display message with contact photo
+ if user have contact photo which have matched to tel-number of sender or receiver */
+ case SEARCH_CONT_PHONE_MSG:
+ {
+ msg_error_t err = MSG_SUCCESS;
+
+ if (ad->result_obj[i].visible == EINA_TRUE) {
+
+ /* Connect Contact-service if contact category status is invisible */
+ if (ad->result_obj[SEARCH_CONT_PHONE_CONTACTS].visible == EINA_FALSE) {
+ rc = contacts_connect2();
+ if (rc != CONTACTS_ERROR_NONE) {
+ /* If we fail to connect contact-service, display message-app icon */
+ SEARCH_DEBUG_WARNING("Fail to connect contact service : %d",rc);
+ }
+ }
+
+ /* Connect Message-Service */
+ err = msg_open_msg_handle(&ad->msg_handle);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("msg_open_msg_handle error : %d", err);
+ ad->msg_handle = NULL;
+ }
+ } else {
+ /* Disconnect Contact-service if contact category status is invisible */
+ if (ad->result_obj[SEARCH_CONT_PHONE_CONTACTS].visible == EINA_FALSE) {
+ rc = contacts_disconnect2();
+ if (rc != CONTACTS_ERROR_NONE)
+ SEARCH_DEBUG_WARNING("Fail to disconnect contact service : %d",rc);
+ }
+
+ /* Disconnect Message-Service */
+ if (ad->msg_handle != NULL ) {
+ err = msg_close_msg_handle(&ad->msg_handle);
+
+ if (err != MSG_SUCCESS)
+ SEARCH_DEBUG_WARNING("msg_close_msg_handle error : %d", err);
+ ad->msg_handle = NULL;
+ }
+ }
+ }
+ break;
+ case SEARCH_CONT_PHONE_EMAIL:
+ break;
+ /* IMAGE, MUSIC, VIDEO use common handle */
+ case SEARCH_CONT_PHONE_IMAGES:
+ case SEARCH_CONT_PHONE_MUSIC:
+ case SEARCH_CONT_PHONE_VIDEO:
+ {
+ if (ad->result_obj[SEARCH_CONT_PHONE_IMAGES].visible == EINA_TRUE
+ || ad->result_obj[SEARCH_CONT_PHONE_MUSIC].visible == EINA_TRUE
+ || ad->result_obj[SEARCH_CONT_PHONE_VIDEO].visible == EINA_TRUE ) {
+ conn_ret = media_content_connect();
+
+ if (conn_ret != 0)
+ SEARCH_DEBUG_WARNING("media_content_connect failed : %d\n", conn_ret);
+ } else {
+ conn_ret = media_content_disconnect();
+
+ if(conn_ret < 0)
+ SEARCH_DEBUG_WARNING("media_content_disconnect failed : %d\n", conn_ret);
+ }
+ }
+ break;
+ case SEARCH_CONT_PHONE_MEMO:
+ {
+ if (ad->result_obj[i].visible == EINA_TRUE) {
+ rc = memo_init(NULL);
+ if (rc == -1) {
+ SEARCH_DEBUG_WARNING
+ ("memo svc connect fail : %d", rc);
+ }
+ } else
+ memo_fini();
+ }
+ break;
+ }
+ }
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+int search_app_disconnect(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ int conn_ret = 0;
+ int i = 0;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_FAIL);
+
+ for (i = 0; i < SEARCH_CONT_MAX ; ++i) {
+ switch (ad->result_obj[i].contents_type) {
+ case SEARCH_CONT_PHONE_MSG:
+ {
+ if (ad->msg_handle != NULL ) {
+ msg_error_t err = MSG_SUCCESS;
+ err = msg_close_msg_handle(&ad->msg_handle);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("msg_close_msg_handle error : %d", err);
+ }
+
+ ad->msg_handle = NULL;
+ }
+ }
+ break;
+ case SEARCH_CONT_PHONE_EMAIL:
+ break;
+ case SEARCH_CONT_PHONE_IMAGES:
+ case SEARCH_CONT_PHONE_MUSIC:
+ case SEARCH_CONT_PHONE_VIDEO:
+ {
+ conn_ret = media_content_disconnect();
+ if(conn_ret != 0)
+ SEARCH_DEBUG_WARNING("media_content_disconnect failed : %d\n", conn_ret);
+ }
+ break;
+ case SEARCH_CONT_PHONE_MEMO:
+ {
+ memo_fini();
+ }
+ break;
+ }
+ }
+
+ SEARCH_FUNC_END;
+
+ return 0;
+}
+
+void search_gl_phone_result_sel(void *data, Evas_Object * obj, void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *cur_category_mem;
+ Elm_Object_Item *it = (Elm_Object_Item *) event_info;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(it == NULL);
+
+ cur_category_mem = (struct search_item_sel *)elm_object_item_data_get(it);
+ SEARCH_RET_IF(cur_category_mem == NULL);
+
+ SEARCH_DEBUG_LOG("cur_category_mem->type : %d", cur_category_mem->type);
+
+ elm_genlist_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_NONE);
+ elm_object_scroll_freeze_push(obj);
+
+ switch (cur_category_mem->type) {
+ case SEARCH_CONT_PHONE_CONTACTS:
+ search_launch_contact_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_MSG:
+ search_launch_msg_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_EMAIL:
+ search_launch_email_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_IMAGES:
+ search_launch_image_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_VIDEO:
+ search_launch_video_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_MUSIC:
+ search_launch_music_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_CALENDAR:
+ search_launch_calendar_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_MEMO:
+ search_launch_memo_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_MENU:
+ search_launch_menu_view(ad, cur_category_mem);
+ break;
+
+ case SEARCH_CONT_PHONE_BROWSER:
+ search_launch_browser_view(ad, cur_category_mem);
+
+ default:
+ break;
+ }
+
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+
+ SEARCH_FUNC_END;
+}
+
+static int __search_gl_set_phone_search_result(struct search_content_object *obj,
+ int offset,
+ char *keyword,
+ void *data,
+ struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ int sel_cnt = SEARCH_CATEGORY_LIST_MORE_CNT;
+ int func_ret = SEARCH_RET_SEARCH_NONE;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL);
+
+ obj->mr_info.offset = offset;
+
+ if (obj->mr_info.offset == 0) {
+ obj->mr_info.next_point = 0;
+ }
+
+ SEARCH_DEBUG_LOG("offset : %d, limit : %d keyword : %s", offset, sel_cnt, keyword);
+
+ if (obj->visible == EINA_TRUE ) {
+ switch (obj->contents_type) {
+ case SEARCH_CONT_PHONE_CONTACTS:
+ {
+ func_ret =
+ search_sql_contact_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+
+ case SEARCH_CONT_PHONE_MSG:
+ {
+ if (ad->msg_handle != NULL) {
+ func_ret =
+ search_sql_msg_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ }
+ break;
+
+ case SEARCH_CONT_PHONE_EMAIL:
+ {
+ func_ret =
+ search_sql_email_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_IMAGES:
+ {
+ func_ret =
+ search_sql_image_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_MUSIC:
+ {
+ func_ret =
+ search_sql_music_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_VIDEO:
+ {
+ func_ret =
+ search_sql_video_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_CALENDAR:
+ {
+ func_ret =
+ search_sql_calendar_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_MEMO:
+ {
+ func_ret =
+ search_sql_memo_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_MENU:
+ {
+ func_ret =
+ search_sql_menu_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ break;
+ case SEARCH_CONT_PHONE_BROWSER:
+ {
+ func_ret =
+ search_sql_browser_search_result_by_api(obj,
+ offset,
+ sel_cnt,
+ keyword,
+ ad,
+ result_info);
+ }
+ }
+ }
+
+ SEARCH_FUNC_END;
+ return func_ret;
+}
+
+static void __search_thread_heavy_cb(void *data, Ecore_Thread *th)
+{
+ SEARCH_FUNC_START;
+
+ struct search_thread_data *thread_data = (struct search_thread_data*)data;
+ struct appdata *ad = NULL;
+ struct search_content_object *obj = NULL;
+ struct search_genlist_info *result_info = NULL;
+
+ int ret = 0;
+
+ int i = SEARCH_CONT_PHONE_MIN;
+ int category_type = 0;
+
+ SEARCH_RET_IF(thread_data == NULL);
+ ad = thread_data->ad;
+ SEARCH_RET_IF(ad == NULL);
+
+ SEARCH_DEBUG_LOG("Thread ID : %p Keyword : %s", th, thread_data->keyword);
+
+ thread_data->is_search_result = SEARCH_RET_SEARCH_NONE;
+
+ while (i <= SEARCH_CONT_PHONE_MAX) {
+ int offset = 0;
+ obj = &ad->result_obj[i];
+ category_type = obj->category_type;
+
+ if (category_type == SEARCH_OBJ_PHONE_CONTENTS) {
+ if (ecore_thread_check(th) != EINA_TRUE) {
+ result_info = (struct search_genlist_info *)calloc(1, sizeof(struct search_genlist_info));
+ ret = __search_gl_set_phone_search_result(obj,
+ offset,
+ thread_data->keyword,
+ ad,
+ result_info);
+
+ if (ret == SEARCH_RET_SEARCH_SUCCESS) {
+ SEARCH_DEBUG_LOG("Matched result : %s %d", obj->name, ret);
+ thread_data->is_search_result = SEARCH_RET_SEARCH_SUCCESS;
+ ecore_thread_feedback(th, result_info);
+ } else {
+ SEARCH_FREE(result_info);
+ }
+ }
+ }
+ i++;
+ }
+ SEARCH_FUNC_END;
+}
+
+
+static void __search_thread_feedback_cb(void *data, Ecore_Thread *th, void *msg_data)
+{
+ SEARCH_FUNC_START;
+
+ struct search_thread_data *thread_data = (struct search_thread_data *)data;
+ struct appdata *ad = NULL;
+ struct search_genlist_info *result_list = (struct search_genlist_info *)msg_data;
+ struct search_pipe_data *pdata = NULL;
+
+ SEARCH_RET_IF(thread_data == NULL);
+ SEARCH_RET_IF(result_list == NULL);
+ ad = thread_data->ad;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (ecore_thread_check(th) == EINA_TRUE)
+ return;
+
+ pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data));
+ pdata->cmd = SEARCH_PIPE_CMD_ADD_GENLIST_PHONE;
+ pdata->obj = NULL;
+ pdata->result_list = result_list;
+ pdata->search_ret = thread_data->is_search_result;
+
+ ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data));
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_thread_end_cb(void *data, Ecore_Thread *th)
+{
+ SEARCH_FUNC_START;
+
+ struct search_thread_data *thread_data = (struct search_thread_data *)data;
+ struct appdata *ad = NULL;
+ struct search_pipe_data *pdata = NULL;
+
+ SEARCH_RET_IF(thread_data == NULL);
+ ad = thread_data->ad;
+ SEARCH_RET_IF(ad == NULL);
+
+ pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data));
+ pdata->cmd = SEARCH_PIPE_CMD_SET_LAYOUT;
+ pdata->search_ret = thread_data->is_search_result;
+
+ if (ecore_thread_check(th) == EINA_TRUE)
+ return;
+
+ ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data));
+
+ SEARCH_FREE(thread_data->keyword);
+ SEARCH_FREE(thread_data);
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_thread_cancel_cb(void *data, Ecore_Thread *th)
+{
+ SEARCH_FUNC_START;
+
+ struct search_thread_data *thread_data = (struct search_thread_data *)data;
+ SEARCH_RET_IF(thread_data == NULL);
+
+ SEARCH_FREE(thread_data->keyword);
+ SEARCH_FREE(thread_data);
+
+ SEARCH_FUNC_END;
+}
+
+void search_stop_search(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ if (ad->search_thread) {
+ ecore_thread_cancel(ad->search_thread);
+ ad->search_thread = NULL;
+ }
+
+ if (ad->search_timer) {
+ ecore_timer_del(ad->search_timer);
+ ad->search_timer = NULL;
+ }
+
+ SEARCH_FUNC_END;
+}
+
+Ecore_Thread* search_make_result_thread(void *data)
+{
+ SEARCH_FUNC_START;
+
+ Ecore_Thread *th = NULL;
+ struct appdata *ad = (struct appdata *)data;
+ struct search_thread_data *thread_data = NULL;
+
+ SEARCH_RETV_IF(ad == NULL, NULL);
+
+ /* Create Thread for Phone Search */
+ thread_data = (struct search_thread_data *)calloc(1, sizeof(struct search_thread_data));
+ thread_data->ad = ad;
+ thread_data->is_search_result = SEARCH_RET_SEARCH_NONE;
+ thread_data->keyword = strdup(ad->search_word);
+
+ th = ecore_thread_feedback_run(__search_thread_heavy_cb,
+ __search_thread_feedback_cb,
+ __search_thread_end_cb,
+ __search_thread_cancel_cb,
+ thread_data,
+ EINA_TRUE);
+
+ SEARCH_FUNC_END;
+ return th;
+}
+
+
+void search_result_gl_init(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ ad->pipe = ecore_pipe_add(ecore_exe_pipe_cb, ad);
+ eina_lock_new(&ad->mutex);
+ eina_condition_new(&ad->condition, &ad->mutex);
+
+ Evas_Object *genlist;
+
+ if (ad->itc_pslist_1line == NULL) {
+ ad->itc_pslist_1line = elm_genlist_item_class_new();
+ ad->itc_pslist_1line->item_style = "1text.tb";
+ ad->itc_pslist_1line->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_1line->func.content_get = __search_gl_content_get_genlist_item_type;
+ ad->itc_pslist_1line->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_1line->func.del = __search_gl_del;
+ }
+
+ if (ad->itc_pslist_1line_1icon == NULL) {
+ ad->itc_pslist_1line_1icon = elm_genlist_item_class_new();
+ ad->itc_pslist_1line_1icon->item_style = "1text.1icon.2.tb";
+ ad->itc_pslist_1line_1icon->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_1line_1icon->func.content_get = __search_gl_content_get_genlist_item_type;
+ ad->itc_pslist_1line_1icon->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_1line_1icon->func.del = __search_gl_del;
+ }
+
+ if (ad->itc_pslist_1line_1icon_browser_history== NULL) {
+ ad->itc_pslist_1line_1icon_browser_history = elm_genlist_item_class_new();
+ ad->itc_pslist_1line_1icon_browser_history->item_style = "1text.1icon.2.tb";
+ ad->itc_pslist_1line_1icon_browser_history->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_1line_1icon_browser_history->func.content_get = __search_gl_content_get_genlist_history_item_type;
+ ad->itc_pslist_1line_1icon_browser_history->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_1line_1icon_browser_history->func.del = __search_gl_del;
+ }
+
+ if (ad->itc_pslist_1line_2icon == NULL) {
+ ad->itc_pslist_1line_2icon = elm_genlist_item_class_new();
+ ad->itc_pslist_1line_2icon->item_style = "1text.2icon.6.tb";
+ ad->itc_pslist_1line_2icon->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_1line_2icon->func.content_get = __search_gl_content_get_genlist_item_type;
+ ad->itc_pslist_1line_2icon->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_1line_2icon->func.del = __search_gl_del;
+ }
+
+ if (ad->itc_pslist_2line_1icon == NULL) {
+ ad->itc_pslist_2line_1icon = elm_genlist_item_class_new();
+ ad->itc_pslist_2line_1icon->item_style = "2text.1icon.4.tb";
+ ad->itc_pslist_2line_1icon->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_2line_1icon->func.content_get = __search_gl_content_get_genlist_item_type;
+ ad->itc_pslist_2line_1icon->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_2line_1icon->func.del = __search_gl_del;
+ }
+
+ if (ad->itc_pslist_2line_2icon == NULL) {
+ ad->itc_pslist_2line_2icon = elm_genlist_item_class_new();
+ ad->itc_pslist_2line_2icon->item_style = "2text.2icon.4.tb";
+ ad->itc_pslist_2line_2icon->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_2line_2icon->func.content_get = __search_gl_content_get_genlist_item_type;
+ ad->itc_pslist_2line_2icon->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_2line_2icon->func.del = __search_gl_del;
+ }
+
+ if (ad->itc_pslist_2line_2icon_browser_bookmark == NULL) {
+ ad->itc_pslist_2line_2icon_browser_bookmark = elm_genlist_item_class_new();
+ ad->itc_pslist_2line_2icon_browser_bookmark->item_style = "2text.2icon.4.tb";
+ ad->itc_pslist_2line_2icon_browser_bookmark->func.text_get = __search_gl_label_get_genlist_item_type;
+ ad->itc_pslist_2line_2icon_browser_bookmark->func.state_get = __search_gl_state_get;
+ ad->itc_pslist_2line_2icon_browser_bookmark->func.content_get = __search_gl_content_get_genlist_bookmark_item_type;
+ ad->itc_pslist_2line_2icon_browser_bookmark->func.del = __search_gl_del;
+ }
+
+
+ if (ad->itc_grouptitle == NULL) {
+ ad->itc_grouptitle = elm_genlist_item_class_new();
+ ad->itc_grouptitle->item_style = "groupindex";
+ ad->itc_grouptitle->func.text_get = __search_gl_label_get_group;
+ ad->itc_grouptitle->func.state_get = __search_gl_state_get;
+ ad->itc_grouptitle->func.del = __search_gl_del_grouptitle;
+ }
+
+ if (ad->itc_listmore == NULL) {
+ ad->itc_listmore = elm_genlist_item_class_new();
+ ad->itc_listmore->item_style = "1text.tb";
+ ad->itc_listmore->func.text_get = __search_gl_label_get_more;
+ ad->itc_listmore->func.state_get = __search_gl_state_get;
+ ad->itc_listmore->func.del = __search_gl_del_more_button;
+ }
+
+ ad->search_gl = NULL;
+
+ genlist = elm_genlist_add(ad->conformant);
+
+ // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
+ // then the item's height is calculated while the item's width fits to genlist width.
+ elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+ elm_genlist_tree_effect_enabled_set(genlist, EINA_TRUE);
+
+ ad->search_gl = genlist;
+
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL,
+ EVAS_HINT_FILL);
+ SEARCH_FUNC_END;
+}
+
+void search_result_gl_deinit(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ ecore_pipe_del(ad->pipe);
+ eina_condition_free(&ad->condition);
+ eina_lock_free(&ad->mutex);
+
+ if (ad->itc_pslist_1line != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_1line);
+
+ if (ad->itc_pslist_1line_1icon != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_1line_1icon);
+
+ if (ad->itc_pslist_1line_1icon_browser_history != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_1line_1icon_browser_history);
+
+ if (ad->itc_pslist_1line_2icon != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_1line_2icon);
+
+ if (ad->itc_pslist_2line_1icon != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_2line_1icon);
+
+ if (ad->itc_pslist_2line_2icon != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_2line_2icon);
+
+ if (ad->itc_pslist_2line_2icon_browser_bookmark != NULL)
+ elm_genlist_item_class_free(ad->itc_pslist_2line_2icon_browser_bookmark);
+
+ if (ad->itc_grouptitle != NULL)
+ elm_genlist_item_class_free(ad->itc_grouptitle);
+
+ if (ad->itc_listmore != NULL)
+ elm_genlist_item_class_free(ad->itc_listmore);
+
+ SEARCH_FUNC_END;
+}
+
+
+void search_gl_result_more_item_append_cb(void *data, Evas_Object * obj,
+ void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ Elm_Object_Item *it = (Elm_Object_Item *) event_info;
+ struct search_pipe_data *pdata = NULL;
+ struct search_genlist_info *result_info = NULL;
+ struct search_item_more_sel *sel_more =
+ (search_item_more_sel *)elm_object_item_data_get(it);
+
+ struct search_content_object *content_obj = sel_more->obj;
+ int offset = content_obj->mr_info.next_point;
+ int ret = SEARCH_RET_SEARCH_NONE;
+
+ elm_object_item_del(it);
+
+ result_info = (struct search_genlist_info *)calloc(1, sizeof(struct search_genlist_info));
+ ret = __search_gl_set_phone_search_result(content_obj,
+ offset,
+ ad->search_word,
+ ad,
+ result_info);
+
+ pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data));
+ pdata->cmd = SEARCH_PIPE_CMD_ADD_GENLIST_PHONE;
+ pdata->obj = NULL;
+ pdata->result_list = result_info;
+ pdata->search_ret = ret;
+ ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data));
+
+ pdata = (struct search_pipe_data *)calloc(1,sizeof(struct search_pipe_data));
+ pdata->cmd = SEARCH_PIPE_CMD_SET_LAYOUT;
+ pdata->search_ret = ret;
+ ecore_pipe_write(ad->pipe, &pdata, sizeof(struct search_pipe_data));
+
+ SEARCH_FUNC_END;
+}
+
+void search_set_result_list(void *data)
+{
+ SEARCH_FUNC_START;
+ struct appdata *ad = (struct appdata *)data;
+
+ int category = 0;
+ int ret = SEARCH_RET_SEARCH_NONE;
+
+ bool is_input_keyword = false;
+ struct search_pipe_data *pipe_data = NULL;
+ char *text = NULL;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ category = ad->search_category;
+ search_stop_search(ad);
+
+ text = elm_entry_markup_to_utf8(elm_object_text_get(ad->search_entry));
+ SEARCH_FREE(ad->not_markup_search_word);
+ SEARCH_FREE(ad->search_word);
+
+ if((text) && (strlen(text) > 0)) {
+ if (ad->first_search == true) {
+ search_result_gl_init(ad);
+ search_util_date_time_format_init();
+ search_app_connect(ad);
+ ad->first_search = false;
+ }
+
+ ad->not_markup_search_word = strdup(elm_object_text_get(ad->search_entry));
+ ad->search_word = text;
+ is_input_keyword = true;
+
+ /* set keyword to vconf for save last search histroy */
+ ret = vconf_set_str(SMARTSEARCH_KEY_KEYWORD, ad->not_markup_search_word);
+
+ if (ret < 0)
+ SEARCH_DEBUG_WARNING("Error : set keyword to vconf");
+ } else {
+ if (category == SEARCH_CATE_PHONE) {
+ pipe_data = (struct search_pipe_data *)calloc(1, sizeof(struct search_pipe_data));
+ pipe_data->cmd = SEARCH_PIPE_CMD_SET_LAYOUT;
+ pipe_data->search_ret = SEARCH_RET_SEARCH_NONE;
+ ecore_pipe_write(ad->pipe, &pipe_data, sizeof(struct search_pipe_data));
+ }
+ /* set keyword to vconf for save last search histroy */
+ ret = vconf_set_str(SMARTSEARCH_KEY_KEYWORD, "");
+
+ if (ret < 0) {
+ SEARCH_DEBUG_WARNING("Error : set keyword to vconf");
+ }
+
+ SEARCH_FREE(text);
+ }
+
+ /* If category is Phone, make a thread for search */
+ pipe_data = (struct search_pipe_data *)calloc(1, sizeof(struct search_pipe_data));
+ pipe_data->cmd = SEARCH_PIPE_CMD_CLEAR_GENLIST;
+ ecore_pipe_write(ad->pipe, &pipe_data, sizeof(struct search_pipe_data));
+
+ switch(category) {
+ case SEARCH_CATE_PHONE:
+ if (is_input_keyword) {
+ ad->search_thread = search_make_result_thread(ad);
+ }
+ break;
+ }
+ SEARCH_FUNC_END;
+}
+
+void search_layout_set_search_list(void* data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (elm_object_part_content_get(ad->sb_layout,"list_noresult")) {
+ elm_object_part_content_unset(ad->sb_layout,"list_noresult");
+ evas_object_hide(ad->noresult_view);
+
+ if (ad->search_gl) {
+ elm_object_part_content_set(ad->sb_layout, "list", ad->search_gl);
+ evas_object_show(ad->search_gl);
+ }
+ }
+
+ if (ad->search_gl) {
+ elm_genlist_item_show(elm_genlist_first_item_get(ad->search_gl), ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ }
+
+ SEARCH_FUNC_END;
+
+ return;
+}
+
+void search_layout_set_search_no_result(void* data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (elm_object_part_content_get(ad->sb_layout,"list")) {
+ elm_object_part_content_unset(ad->sb_layout, "list");
+
+ if (ad->search_gl) {
+ evas_object_hide(ad->search_gl);
+ }
+
+ elm_object_part_content_set(ad->sb_layout,"list_noresult", ad->noresult_view);
+ evas_object_show(ad->noresult_view);
+ }
+
+ SEARCH_FUNC_END;
+
+ return;
+}
+
+int search_layout_get_content_list_set_status(void* data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ int ret = SEARCH_RET_FAIL;
+
+ SEARCH_RETV_IF(ad == NULL, ret);
+
+ if (elm_object_part_content_get(ad->sb_layout,"list")) {
+ ret = SEARCH_RET_SUCCESS;
+ } else {
+ ret = SEARCH_RET_FAIL;
+ }
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+
diff --git a/src/ps_searcher.cpp b/src/ps_searcher.cpp
new file mode 100755
index 0000000..ed43f30
--- /dev/null
+++ b/src/ps_searcher.cpp
@@ -0,0 +1,2255 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd/
+ *
+ * Licensed under the Flora License, Version 1.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+
+
+
+#include "smartsearch.h"
+
+#include <sqlite3.h>
+
+#include <contacts.h>
+#include <calendar2.h>
+#include <memo-db.h>
+
+#include <email-api-mail.h>
+
+#include <favorites.h>
+#include <media_content.h>
+
+#include <msg_storage.h>
+#include <msg_storage_types.h>
+#include <msg.h>
+
+#include <ail.h>
+#include <unicode/ucal.h>
+#include <unicode/ustring.h>
+#include <unicode/ustdio.h>
+#include <unicode/udat.h>
+
+char* g_keyword = NULL;
+
+struct search_cb_data {
+ struct search_content_object *obj;
+ struct appdata *ad;
+ char *keyword;
+ struct search_genlist_info *result_info;
+};
+
+struct search_cb_data_browser {
+ struct search_content_object *obj;
+ struct appdata *ad;
+ char *keyword;
+ struct search_genlist_info *result_info;
+ struct search_more_result *info;
+ bool search_ret;
+};
+
+struct media_cb_data {
+ bool is_sdcard;
+ char *dirname;
+};
+
+int search_sql_stmt_init(sqlite3_stmt * sql_stmt)
+{
+ SEARCH_FUNC_START;
+
+ int rc = 0;
+
+ rc = sqlite3_clear_bindings(sql_stmt);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR("sqlite3_clear_bindings error");
+ return SEARCH_RET_FAIL;
+ }
+
+ rc = sqlite3_reset(sql_stmt);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR("sqlite3_reset error");
+ return SEARCH_RET_FAIL;
+ }
+
+ SEARCH_FUNC_END;
+
+ return SEARCH_RET_SUCCESS;
+}
+
+int search_sql_stmt_finalize(sqlite3_stmt * stmt)
+{
+ SEARCH_FUNC_START;
+
+ int ret;
+
+ ret = sqlite3_finalize(stmt);
+ if (ret != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR("sqlite3_finalize error : %d ", ret);
+ return -1;
+ }
+
+ SEARCH_FUNC_END;
+
+ return 0;
+}
+
+int search_sql_prepare_stmt(sqlite3 *db_handle, const char *query,
+ sqlite3_stmt ** stmt_out)
+{
+ SEARCH_FUNC_START;
+
+ int rc = 0;
+ int ret = 0;
+
+ rc = sqlite3_prepare(db_handle, query, strlen(query), stmt_out, NULL);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR("sql preapre error : %d / %s", rc, query);
+ ret = SEARCH_RET_FAIL;
+ } else {
+ ret = SEARCH_RET_SUCCESS;
+ }
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+int search_sql_bind_text(sqlite3* db_handle, sqlite3_stmt *sql_stmt, int col, char *data)
+{
+ int rc = 0;
+ int ret = SEARCH_RET_SEARCH_NONE;
+
+ rc = sqlite3_bind_text(sql_stmt, col, data, strlen(data), SQLITE_STATIC);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR("SQL BIND TEXT ERROR : %s(%d) / %s\n",
+ sqlite3_errmsg(db_handle),
+ rc,
+ data);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ }
+
+ return ret;
+}
+
+int search_sql_bind_int(sqlite3* db_handle, sqlite3_stmt *sql_stmt, int col, int data)
+{
+ int rc = 0;
+ int ret = SEARCH_RET_SEARCH_NONE;
+
+ rc = sqlite3_bind_int(sql_stmt, col, data);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR("SQL BIND INT ERROR : %s(%d) / %d\n",
+ sqlite3_errmsg(db_handle),
+ rc,
+ data);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ }
+ return ret;
+}
+
+int search_sql_contact_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ int ret = 0;
+
+ contacts_query_h query = NULL;
+ contacts_filter_h filter = NULL;
+ contacts_list_h list = NULL;
+
+ unsigned int count = 0;
+ int total_cnt = -1;
+ int curr_cnt = -1;
+ int loop_cnt = 0;
+ int search_ret = SEARCH_RET_SEARCH_NONE;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL);
+
+ ret = contacts_connect2();
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_connect2 : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_query_create(_contacts_person_number._uri, &query);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_query_create : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_filter_create(_contacts_person_number._uri, &filter);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_filter_create : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_filter_add_str(filter, _contacts_person_number.display_name, CONTACTS_MATCH_CONTAINS, keyword);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_filter_add_str : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_filter_add_operator : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_filter_add_str(filter, _contacts_person_number.number, CONTACTS_MATCH_CONTAINS, keyword);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_filter_add_str : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_query_set_filter(query, filter);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_query_set_filter : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_query_set_sort(query, _contacts_person_number.display_name, true);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_query_set_sort : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_db_get_count_with_query(query, &total_cnt);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_db_get_count_with_query : %d", ret);
+ goto out_func;
+ }
+
+ ret = contacts_db_get_records_with_query(query, offset, limit, &list);
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("contacts_db_get_records_with_query : %d", ret);
+ goto out_func;
+ }
+
+ SEARCH_RETV_IF_WITH_ERRORV(ret != CONTACTS_ERROR_NONE, SEARCH_RET_SEARCH_FAIL, ret);
+ contacts_list_get_count(list, &count);
+
+ SEARCH_DEBUG_LOG("CONTACT COUNT: %d", count);
+ SEARCH_DEBUG_LOG("TOTAL COUNT: %d", total_cnt);
+
+ if (count > 0) {
+ /* Set group title */
+ if (offset == 0) {
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj, ad->itc_grouptitle, obj, NULL);
+ }
+
+ do {
+ struct search_item_sel *sel_mem_info = NULL;
+ struct search_genlist_item_info *gen_item = NULL;
+ Elm_Genlist_Item_Class *itc_style = NULL;
+
+ int contact_id = -1;
+ char *contact_img_path = NULL;
+ char *str_display = NULL;
+ char *num_display = NULL;
+ const char *text_1line = NULL;
+ const char *text_2line = NULL;
+ bool is_word_in_str = false;
+ char contact_id_str[MAX_LENGTH_PER_ID] = {0,};
+
+ sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", loop_cnt);
+ continue;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+
+ contacts_record_h record;
+ contacts_list_get_current_record_p(list, &record);
+ contacts_record_get_str_p(record, _contacts_person.image_thumbnail_path, &contact_img_path);
+
+ if (contact_img_path != NULL) {
+ sel_mem_info->icon1 = strdup(contact_img_path);
+ }
+ else if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ contacts_record_get_str_p(record, _contacts_person.display_name, &str_display);
+ contacts_record_get_str_p(record, _contacts_number.number, &num_display);
+
+ if (str_display != NULL) {
+ text_1line = str_display;
+ }
+
+ if (num_display != NULL) {
+ text_2line = num_display;
+ }
+
+ if (text_1line != NULL && text_2line != NULL) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(str_display, keyword, &is_word_in_str));
+ sel_mem_info->text2 = strdup(search_markup_keyword(num_display, keyword, &is_word_in_str));
+ itc_style = ad->itc_pslist_2line_1icon;
+ } else {
+ if (text_1line) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(str_display, keyword, &is_word_in_str));
+ }
+ else {
+ sel_mem_info->text2 = strdup(search_markup_keyword(num_display, keyword, &is_word_in_str));
+ }
+ itc_style = ad->itc_pslist_1line_1icon;
+ }
+
+ contacts_record_get_int(record, _contacts_person.id, &contact_id);
+ snprintf(contact_id_str, MAX_LENGTH_PER_ID - 1, "%d", contact_id);
+ sel_mem_info->launch_param= strdup(contact_id_str);
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
+ obj, itc_style, sel_mem_info,
+ obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+
+ loop_cnt++;
+
+ if (loop_cnt == limit) {
+ break;
+ }
+ }while (contacts_list_next(list) == CONTACTS_ERROR_NONE);
+ } else {
+ SEARCH_DEBUG_WARNING("No matched contacts data", ret);
+ search_ret = SEARCH_RET_SEARCH_NONE;
+ goto out_func;
+ }
+
+ contacts_list_destroy(list, true);
+
+ /* Set more title to genlist (under 'search all') */
+ curr_cnt = offset + loop_cnt;
+
+ if (total_cnt > curr_cnt) {
+ struct search_item_more_sel *sel_mem_more = NULL;
+
+ obj->mr_info.next_point = offset + limit;
+
+ sel_mem_more =
+ (struct search_item_more_sel *)calloc(1,
+ sizeof(struct
+ search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ }
+
+ search_ret = SEARCH_RET_SEARCH_SUCCESS;
+
+out_func:
+ ret = contacts_disconnect2();
+
+ if (filter) {
+ contacts_filter_destroy(filter);
+ }
+
+ if (query) {
+ contacts_query_destroy(query);
+ }
+
+ SEARCH_FUNC_END;
+
+ return search_ret;
+}
+
+int search_sql_calendar_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_item_sel *sel_mem_info = NULL;
+ struct search_item_more_sel *sel_mem_more = NULL;
+ struct search_genlist_item_info *gen_item = NULL;
+
+ int loop_cnt = 0;
+ int count = -1;
+ int total_cnt = -1;
+ int ret = 0;
+ int search_ret = SEARCH_RET_SEARCH_NONE;
+ int curr_cnt = 0;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL);
+
+ ret = calendar_connect();
+ SEARCH_RETV_IF_WITH_ERRORV(ret != CALENDAR_ERROR_NONE, SEARCH_RET_SEARCH_FAIL, ret);
+
+ calendar_query_h query = NULL;
+ calendar_filter_h visibility_filter = NULL;
+ calendar_list_h list = NULL;
+
+ ret = calendar_query_create(_calendar_event._uri, &query);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_query_create : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_filter_create(_calendar_event._uri, &visibility_filter);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_filter_create : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_filter_add_str(visibility_filter, _calendar_event.summary, CALENDAR_MATCH_CONTAINS, keyword);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_filter_add_str : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_filter_add_operator(visibility_filter, CALENDAR_FILTER_OPERATOR_AND);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_filter_add_operator : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_query_set_filter(query, visibility_filter);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_query_set_filter : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_query_set_sort(query, _calendar_event.summary, true);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_query_set_sort : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_db_get_count_with_query(query, &total_cnt);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_db_get_count_with_query : %d", ret);
+ goto out_func;
+ }
+
+ ret = calendar_db_get_records_with_query(query, offset, limit, &list);
+ if (ret != CALENDAR_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("calendar_db_get_records_with_query : %d", ret);
+ goto out_func;
+ }
+
+ calendar_list_get_count(list, &count);
+
+ SEARCH_DEBUG_LOG("CALENDAR COUNT : %d", count);
+ SEARCH_DEBUG_LOG("TOTAL COUNT : %d", total_cnt);
+
+ if (count > 0) {
+ /* Set group title */
+ if (offset == 0) {
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ do {
+ int main_id = -1;
+ char *summary = NULL;
+ bool is_word_in_str = false;
+ char format_val[MAX_LENGTH_PER_LINE] = {0,};
+ char calendar_id_str[MAX_LENGTH_PER_ID] = {0,};
+
+ calendar_record_h record;
+ calendar_time_s cal;
+ calendar_list_get_current_record_p(list, &record);
+
+ sel_mem_info = (struct search_item_sel *)calloc(1,sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", loop_cnt);
+ continue;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+
+ /* Set Thumbnail Image */
+ if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ /* Set text 1line - Summary */
+ calendar_record_get_str_p(record, _calendar_event.summary, &summary);
+ if ((summary) && (strlen(summary) > 0)) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(summary, keyword, &is_word_in_str));
+ }
+
+ /* Set text 2line - Date */
+ calendar_record_get_caltime(record, _calendar_event.start_time, &cal);
+
+ if (cal.type == CALENDAR_TIME_UTIME) {
+ search_util_date_time_format_get_val(cal.time.utime, format_val, SEARCH_DATE_TYPE_YYMMDD);
+ } else {
+ search_util_date_time_format_get_val(cal.time.utime, format_val, SEARCH_DATE_TYPE_YYMM);
+ }
+ sel_mem_info->text2 = strdup(format_val);
+
+ /* Set id for launching caledar contents */
+ calendar_record_get_int (record, _calendar_event.id, &main_id);
+ snprintf(calendar_id_str, MAX_LENGTH_PER_ID - 1, "%d", main_id);
+ sel_mem_info->launch_param = strdup(calendar_id_str);
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, ad->itc_pslist_2line_1icon,
+ sel_mem_info, obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+
+ loop_cnt++;
+
+ if (loop_cnt == limit) {
+ break;
+ }
+ } while (calendar_list_next(list) == CALENDAR_ERROR_NONE);
+ } else {
+ SEARCH_DEBUG_WARNING("No Matched calendar data: %d", count);
+
+ search_ret = SEARCH_RET_SEARCH_NONE;
+ goto out_func;
+ }
+
+ curr_cnt = offset + loop_cnt;
+
+ /* Set more title to genlist (under 'search all') */
+ if (total_cnt > curr_cnt) {
+ obj->mr_info.next_point = offset + limit;
+
+ sel_mem_more =
+ (struct search_item_more_sel *)calloc(1,
+ sizeof(struct
+ search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ }
+ search_ret = SEARCH_RET_SEARCH_SUCCESS;
+
+out_func:
+ ret = calendar_disconnect();
+
+ if (visibility_filter) {
+ calendar_filter_destroy(visibility_filter);
+ }
+
+ if (query) {
+ calendar_query_destroy(query);
+ }
+
+ SEARCH_FUNC_END;
+ return search_ret;
+}
+
+static void __search_sql_memo_search_result_cb(memo_data_t * value,
+ void *user_data)
+{
+ SEARCH_FUNC_START;
+
+ struct search_cb_data *scd = (struct search_cb_data *)user_data;
+ struct appdata *ad = NULL;
+ struct search_content_object *obj = NULL;
+ struct search_genlist_info *result_info = NULL;
+
+ struct search_genlist_item_info *gen_item = NULL;
+ struct search_item_sel *sel_mem_info = NULL;
+ struct search_item_more_sel *sel_mem_more = NULL;
+
+ char *keyword = scd->keyword;
+ bool is_word_in_str = false;
+ char memo_id_str[MAX_LENGTH_PER_ID] = {0,};
+ char format_val[MAX_LENGTH_PER_LINE] = {0,};
+
+ SEARCH_RET_IF(scd == NULL);
+ ad = scd->ad;
+ obj = scd->obj;
+ result_info = scd->result_info;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(value == NULL);
+
+ if (obj->mr_info.next_point == 0) {
+ /* Set group title */
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ if (obj->mr_info.next_point <
+ obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+ sel_mem_info = (struct search_item_sel*)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", obj->mr_info.next_point);
+ return;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+
+ /********** START : set search result to sel_mem_info buf ************/
+
+ if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ /* First, We should check comment field. It means drawing memo
+ * If comment field is NULL, then we check content field */
+ if ((value->comment) && (strlen(value->comment) > 0)) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(value->comment, keyword, &is_word_in_str));
+ } else if ((value->content) && (strlen(value->content) > 0)) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(value->content, keyword, &is_word_in_str));
+ }
+
+ search_util_date_time_format_get_val(value->modi_time, format_val, SEARCH_DATE_TYPE_YYMM);
+ sel_mem_info->text2 = strdup(format_val);
+
+ snprintf(memo_id_str, MAX_LENGTH_PER_ID - 1, "%d", value->id);
+ sel_mem_info->launch_param = strdup(memo_id_str);
+
+ /********** END : set search result to sel_mem_info buf *************/
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, ad->itc_pslist_2line_1icon,
+ sel_mem_info, obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+
+ obj->mr_info.next_point++;
+ } else if (obj->mr_info.next_point ==
+ obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+ /* Set more title to genlist (under 'search all') */
+ sel_mem_more =
+ (struct search_item_more_sel *)calloc(1,
+ sizeof(struct
+ search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ } else {
+ SEARCH_DEBUG_WARNING
+ ("__search_sql_memo_search_result_cb wrong index : %d",
+ obj->mr_info.next_point);
+ }
+
+ SEARCH_FUNC_END;
+
+ return;
+}
+
+int search_sql_memo_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_cb_data scd = {obj, ad, keyword, result_info};
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL);
+
+ memo_search_data(keyword,
+ limit, offset,
+ MEMO_SORT_TITLE_ASC,
+ __search_sql_memo_search_result_cb,
+ &scd);
+
+ if (obj->mr_info.next_point == 0) {
+ SEARCH_DEBUG_WARNING("no memo search result");
+ return SEARCH_RET_SEARCH_NONE;
+ }
+
+ SEARCH_FUNC_END;
+ return SEARCH_RET_SEARCH_SUCCESS;
+}
+
+int search_sql_email_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ int ret = EMAIL_ERROR_NONE;
+ int i = 0;
+ email_mail_list_item_t *mail_list = NULL;
+ email_list_filter_t *filter_list = NULL;
+ email_list_sorting_rule_t *sorting_rule_list = NULL;
+
+ int filter_list_count = 5;
+ int sorting_rule_list_count = 1;
+ int mail_count = 0;
+ int total_mail_cnt = -1;
+ int unseen_mail_cnt = -1;
+
+ struct search_genlist_item_info *gen_item = NULL;
+ struct search_item_sel *sel_mem_info = NULL;
+ struct search_item_more_sel *sel_mem_more = NULL;
+ bool is_word_in_str = false;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL);
+
+ int search_ret = SEARCH_RET_SEARCH_FAIL;
+
+ filter_list = (email_list_filter_t *)malloc(sizeof(email_list_filter_t) * filter_list_count);
+ memset(filter_list, 0 , sizeof(email_list_filter_t) * filter_list_count);
+
+ filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
+ filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
+ filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
+ filter_list[0].list_filter_item.rule.key_value.string_type_value = keyword;
+ filter_list[0].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE;
+
+ filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
+ filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
+
+ filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
+ filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO;
+ filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
+ filter_list[2].list_filter_item.rule.key_value.string_type_value = keyword;
+ filter_list[2].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE;
+
+ filter_list[3].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
+ filter_list[3].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
+
+ filter_list[4].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
+ filter_list[4].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
+ filter_list[4].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
+ filter_list[4].list_filter_item.rule.key_value.string_type_value = keyword;
+ filter_list[4].list_filter_item.rule.case_sensitivity = EMAIL_CASE_INSENSITIVE;
+
+ sorting_rule_list = (email_list_sorting_rule_t *)malloc(sizeof(email_list_sorting_rule_t) * sorting_rule_list_count);
+ memset(sorting_rule_list, 0, sizeof(email_list_sorting_rule_t) * sorting_rule_list_count);
+
+ sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
+ sorting_rule_list[0].sort_order = EMAIL_SORT_ORDER_ASCEND;
+
+ ret = email_count_mail(filter_list, filter_list_count, &total_mail_cnt, &unseen_mail_cnt);
+ if (ret != EMAIL_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to call email_count_mail");
+ goto out_func;
+ }
+
+ ret = email_get_mail_list_ex(filter_list, filter_list_count, sorting_rule_list, sorting_rule_list_count,
+ offset, limit, &mail_list, &mail_count);
+
+
+
+ if (ret != EMAIL_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to call email_get_mail_list_ex");
+ goto out_func;
+ }
+
+ SEARCH_DEBUG_LOG("EMAIL TOTAL COUNT : %d UNSEEN : %d", total_mail_cnt, unseen_mail_cnt);
+ SEARCH_DEBUG_LOG("EMAIL COUNT : %d", mail_count);
+
+ if(mail_list == NULL) {
+ SEARCH_DEBUG_WARNING("mail_list is null");
+ search_ret = SEARCH_RET_SEARCH_NONE;
+ goto out_func;
+ }
+
+ if (mail_count == 0) {
+ SEARCH_DEBUG_WARNING("no email search result");
+ search_ret = SEARCH_RET_SEARCH_NONE;
+ goto out_func;
+ }
+
+ /* Set group title */
+ if (offset == 0) {
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ /* Set search result to genlist */
+ for(i = 0 ; i < mail_count ; i++) {
+ char email_id_str[MAX_LENGTH_PER_ID] = {0,};
+ char email_path_str[MAX_LENGTH_PER_PATH] = {0,};
+
+ sel_mem_info = (struct search_item_sel*)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", i);
+ continue;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+
+ if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+
+ }
+
+ snprintf(email_id_str, MAX_LENGTH_PER_ID - 1, "%d", mail_list[i].mail_id);
+ sel_mem_info->launch_param = strdup(email_id_str);
+
+
+ snprintf(email_path_str, MAX_LENGTH_PER_PATH - 1, "%d %d %d",
+ mail_list[i].account_id, mail_list[i].mail_id, mail_list[i].mailbox_id);
+ sel_mem_info->launch_path = strdup(email_path_str);
+
+ if(strlen(mail_list[i].subject) > 0) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(mail_list[i].subject, ad->search_word, &is_word_in_str));
+ }
+
+ if(strlen(mail_list[i].full_address_from) > 0) {
+ sel_mem_info->text2 = strdup(search_markup_keyword(mail_list[i].full_address_from, ad->search_word, &is_word_in_str));
+ }
+
+ if(is_word_in_str == false && (strlen(mail_list[i].email_address_recipient) > 0)) {
+ sel_mem_info->text2 = strdup(search_markup_keyword(mail_list[i].email_address_recipient, ad->search_word, &is_word_in_str));
+ }
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, ad->itc_pslist_2line_1icon, sel_mem_info, obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+ }
+
+ /* Set more title to genlist (under 'search all') */
+ if (i < total_mail_cnt) {
+ obj->mr_info.next_point = offset + i;
+
+ sel_mem_more =
+ (struct search_item_more_sel *)calloc(1,
+ sizeof(struct search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ }
+ search_ret = SEARCH_RET_SEARCH_SUCCESS;
+
+out_func:
+ SEARCH_FREE(filter_list);
+ SEARCH_FREE(sorting_rule_list);
+ SEARCH_FREE(mail_list);
+
+ SEARCH_FUNC_END;
+ return search_ret;
+}
+
+static bool __search_media_info_cb(media_info_h media, void *user_data)
+{
+ char *media_id = NULL;
+ char *media_name = NULL;
+ char *media_path = NULL;
+ char *media_thumbnail = NULL;
+
+ struct search_item_sel *sel_mem_info = NULL;
+ Elm_Genlist_Item_Class *itc_style = NULL;
+ bool is_word_in_str = false;
+
+ struct search_cb_data *scd = (struct search_cb_data*)user_data;
+ struct appdata *ad = NULL;
+ struct search_content_object *obj = NULL;
+ struct search_genlist_info *result_info = NULL;
+ char *keyword = NULL;
+
+ struct search_genlist_item_info *gen_item = NULL;
+ char media_id_str[MAX_LENGTH_PER_PATH] = {0,};
+
+ SEARCH_RETV_IF(scd == NULL, true);
+ ad = scd->ad;
+ obj = scd->obj;
+ result_info = scd->result_info;
+ keyword = scd->keyword;
+
+ SEARCH_RETV_IF(ad == NULL, true);
+
+ media_info_get_media_id(media, &media_id);
+ media_info_get_display_name(media, &media_name);
+ media_info_get_file_path(media, &media_path);
+ media_info_get_thumbnail_path(media, &media_thumbnail);
+
+ sel_mem_info = (struct search_item_sel*)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", media_id);
+ return true;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+
+ if ((media_thumbnail) && ecore_file_exists(media_thumbnail) == EINA_TRUE) {
+ sel_mem_info->icon1 = strdup(media_thumbnail);
+ } else if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ if (media_name && strlen(media_name)) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(media_name, keyword, &is_word_in_str));
+ }
+
+ if (media_id) {
+ snprintf(media_id_str, MAX_LENGTH_PER_ID, "%s", media_id);
+ sel_mem_info->launch_param = strdup(media_id_str);
+ }
+
+ if (media_path) {
+ sel_mem_info->launch_path = strdup(media_path);
+ }
+
+ itc_style = ad->itc_pslist_1line_1icon;
+
+ /* Add Info to genlist */
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
+ obj,
+ itc_style,
+ sel_mem_info,
+ obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+
+ SEARCH_FREE(media_id);
+ SEARCH_FREE(media_name);
+ SEARCH_FREE(media_thumbnail);
+ SEARCH_FREE(media_path);
+
+ return true;
+ }
+
+static bool __search_sql_music_info_cb(media_info_h media, void *user_data)
+{
+ char *media_id = NULL;
+ char *media_path = NULL;
+ char *media_thumbnail = NULL;
+ char *title = NULL;
+ char *artist = NULL;
+ char *album = NULL;
+ int ret = 0;
+
+ audio_meta_h a_handle = NULL;
+
+ media_content_storage_e storage_type = MEDIA_CONTENT_STORAGE_INTERNAL;
+
+ struct search_item_sel *sel_mem_info = NULL;
+ Elm_Genlist_Item_Class *itc_style = NULL;
+ bool is_word_in_str = false;
+
+ struct search_cb_data *scd = (struct search_cb_data*)user_data;
+ struct appdata *ad = NULL;
+ struct search_content_object *obj = NULL;
+ struct search_genlist_info *result_info = NULL;
+ char *keyword = NULL;
+
+ struct search_genlist_item_info *gen_item = NULL;
+ char music_id_str[MAX_LENGTH_PER_PATH] = {0,};
+
+ SEARCH_RETV_IF(scd == NULL, true);
+ ad = scd->ad;
+ obj = scd->obj;
+ result_info = scd->result_info;
+ keyword = scd->keyword;
+
+ SEARCH_RETV_IF(ad == NULL, true);
+
+ media_info_get_media_id(media, &media_id);
+ media_info_get_file_path(media, &media_path);
+ media_info_get_storage_type(media, &storage_type);
+ media_info_get_thumbnail_path(media, &media_thumbnail);
+
+ ret = media_info_get_audio(media, &a_handle);
+
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to get audio info!");
+ return true;
+ } else {
+ ret = audio_meta_get_title(a_handle, &title);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to get title info!");
+ }
+
+ ret = audio_meta_get_album(a_handle, &album);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to get album info!");
+ }
+
+ ret = audio_meta_get_artist(a_handle, &artist);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to get artist info!");
+ }
+
+ }
+
+ audio_meta_destroy(a_handle);
+
+ sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", media_id);
+ return true;
+ }
+
+ sel_mem_info->type = obj->contents_type;;
+
+ if ((media_thumbnail) && ecore_file_exists(media_thumbnail) == EINA_TRUE) {
+ sel_mem_info->icon1 = strdup(media_thumbnail);
+ } else if(obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ if ((title) && (strlen(title) > 0)) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(title, keyword, &is_word_in_str));
+ }
+
+ if (is_word_in_str) {
+ if ((artist) && (strlen(artist) > 0)) {
+ sel_mem_info->text2 = strdup(search_markup_keyword(artist, keyword, &is_word_in_str));
+ }
+ } else {
+ if ((artist) && (strlen(artist) > 0)) {
+ sel_mem_info->text2 = strdup(search_markup_keyword(artist, keyword, &is_word_in_str));
+ }
+
+ if (is_word_in_str == false && (album) && (strlen(album) > 0)) {
+ sel_mem_info->text2 = strdup(search_markup_keyword(album, keyword, &is_word_in_str));
+ }
+
+ if (is_word_in_str == false) {
+ SEARCH_DEBUG_LOG("search_result is 0. No match keyword in title,album,artist string");
+ }
+ }
+
+ if (storage_type == MEDIA_CONTENT_STORAGE_EXTERNAL) {
+ itc_style = ad->itc_pslist_2line_2icon;
+ sel_mem_info->icon2 = strdup(SEARCH_SDCARD_ICON);
+ }
+ else {
+ itc_style = ad->itc_pslist_2line_1icon;
+ }
+
+ if (media_id) {
+ snprintf(music_id_str, MAX_LENGTH_PER_ID - 1, "%s", media_id);
+ sel_mem_info->launch_param = strdup(music_id_str);
+ }
+
+ if (media_path) {
+ sel_mem_info->launch_path = strdup(media_path);
+ }
+
+ /* Add Information to genlist */
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM, obj, itc_style, sel_mem_info,
+ obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+
+ SEARCH_FREE(media_id);
+ SEARCH_FREE(media_path);
+ SEARCH_FREE(media_thumbnail);
+ SEARCH_FREE(title);
+ SEARCH_FREE(artist);
+ SEARCH_FREE(album);
+
+ return true;
+ }
+
+static int __search_sql_media_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit,
+ char *keyword,
+ filter_h filter,
+ media_info_cb func_cb,
+ void *data,
+ struct search_genlist_info *result_info,
+ int total_cnt)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_cb_data scd = {obj, ad, keyword, result_info};
+
+ int result_cnt = 0;
+ int ret = 0;
+ int func_ret = SEARCH_RET_SEARCH_SUCCESS;
+ int curr_cnt = 0;
+
+ struct search_item_more_sel *sel_mem_more = NULL;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_SEARCH_FAIL);
+
+ media_info_get_media_count_from_db(filter, &result_cnt);
+
+ if (result_cnt != 0) {
+ /* Set group title */
+ if (obj->mr_info.offset== 0) {
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ ret = media_info_foreach_media_from_db(filter, func_cb, &scd);
+
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_info_foreach_media_from_db failed : %d\n", ret);
+ func_ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ curr_cnt = offset + result_cnt;
+
+ /* Set more title to genlist (under 'search all') */
+ if (total_cnt > curr_cnt) {
+ obj->mr_info.next_point = offset + result_cnt;
+
+ sel_mem_more =
+ (struct search_item_more_sel *)calloc(1,
+ sizeof(struct search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ }
+ } else {
+ func_ret = SEARCH_RET_SEARCH_NONE;
+ }
+
+out_func:
+ SEARCH_FUNC_END;
+
+ return func_ret;
+}
+
+
+int search_sql_image_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit,
+ char *keyword,
+ void *data,
+ struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ int ret = SEARCH_RET_SEARCH_SUCCESS;
+ int len = 0;
+ int total_cnt = -1;
+
+ char *search_query = NULL;
+ char *escape_added_keyword = NULL;
+
+ const char *image_query = "(MEDIA_TYPE=0 and (MEDIA_DISPLAY_NAME like \"%%%s%%\" ESCAPE (\"%s\")))";
+
+ SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
+ memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
+ search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
+
+ len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(image_query) + 1;
+ search_query = (char*)calloc(1, len);
+
+ snprintf(search_query, len, image_query, escape_added_keyword, "%");
+
+ filter_h filter;
+
+ ret = media_filter_create(&filter);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_DISPLAY_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+}
+
+ media_info_get_media_count_from_db(filter, &total_cnt);
+ SEARCH_DEBUG_LOG("Matched Image Total Cnt : %d", total_cnt);
+
+ ret = media_filter_set_offset(filter, offset, limit);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+
+ ret = __search_sql_media_search_result_by_api(obj,
+ offset,
+ limit,
+ keyword,
+ filter,
+ __search_media_info_cb,
+ data,
+ result_info,
+ total_cnt);
+
+out_func:
+ SEARCH_FREE(search_query);
+ SEARCH_FREE(escape_added_keyword);
+ media_filter_destroy(filter);
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+int search_sql_video_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit, char *keyword, void *data, struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ int ret = SEARCH_RET_SEARCH_SUCCESS;
+ int len = 0;
+ char *search_query = NULL;
+ char *escape_added_keyword = NULL;
+ int total_cnt = -1;
+
+ const char *video_query = "(MEDIA_TYPE=1 and (MEDIA_DISPLAY_NAME LIKE \"%%%s%%\" ESCAPE (\"%s\")))";
+
+ SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
+ memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
+ search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
+
+ len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(video_query) + 1;
+ search_query = (char*)calloc(1, len);
+
+ snprintf(search_query, len, video_query, escape_added_keyword, DB_ESCAPE_CHAR);
+
+ filter_h filter;
+
+ ret = media_filter_create(&filter);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = media_filter_set_offset(filter, offset, limit);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_DISPLAY_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ media_info_get_media_count_from_db(filter, &total_cnt);
+ SEARCH_DEBUG_LOG("Matched Video Total cnt : %d", total_cnt);
+
+ ret = media_filter_set_offset(filter, offset, limit);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = __search_sql_media_search_result_by_api(obj,
+ offset,
+ limit,
+ keyword,
+ filter,
+ __search_media_info_cb,
+ data,
+ result_info,
+ total_cnt);
+
+out_func:
+
+ SEARCH_FREE(search_query);
+ SEARCH_FREE(escape_added_keyword);
+ media_filter_destroy(filter);
+
+ SEARCH_FUNC_END;
+
+ return ret;
+ }
+
+int search_sql_music_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit,
+ char *keyword,
+ void *data,
+ struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ int ret = SEARCH_RET_SEARCH_SUCCESS;
+ int len = 0;
+ char *search_query = NULL;
+ char *escape_added_keyword = NULL;
+ int total_cnt = -1;
+
+ const char *music_query = "(MEDIA_TYPE=3 and (MEDIA_TITLE LIKE \"%%%s%%\" or MEDIA_ALBUM LIKE \"%%%s%%\" or MEDIA_ARTIST LIKE \"%%%s%%\" ESCAPE (\"%s\")))";
+
+ SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
+ memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
+ search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
+
+ len = strlen(escape_added_keyword) + strlen(DB_ESCAPE_CHAR) + strlen(music_query) + 1;
+ search_query = (char*)calloc(1, len);
+
+ snprintf(search_query, len, music_query, escape_added_keyword,
+ escape_added_keyword, escape_added_keyword, DB_ESCAPE_CHAR);
+
+ filter_h filter;
+
+ ret = media_filter_create(&filter);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_create failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+
+
+ ret = media_filter_set_condition(filter, search_query, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_condition failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_order failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ media_info_get_media_count_from_db(filter, &total_cnt);
+ SEARCH_DEBUG_LOG("Matched Music Total cnt : %d", total_cnt);
+
+ ret = media_filter_set_offset(filter, offset, limit);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("media_filter_set_offset failed : %d\n", ret);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ ret = __search_sql_media_search_result_by_api(obj,
+ offset,
+ limit,
+ keyword,
+ filter,
+ __search_sql_music_info_cb,
+ data,
+ result_info,
+ total_cnt);
+
+out_func:
+
+ SEARCH_FREE(search_query);
+ SEARCH_FREE(escape_added_keyword);
+ media_filter_destroy(filter);
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+ail_cb_ret_e __search_sql_menu_search_result_cb(
+ const ail_appinfo_h appinfo,
+ void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct search_cb_data *scd = (struct search_cb_data*)data;
+ struct appdata *ad = scd->ad;
+ struct search_content_object* obj = scd->obj;
+ struct search_genlist_info *result_info = scd->result_info;
+ char *keyword = scd->keyword;
+
+ struct search_genlist_item_info *gen_item = NULL;
+ struct search_item_sel *sel_mem_info = NULL;
+ struct search_item_more_sel *sel_mem_more = NULL;
+
+ bool is_word_in_str;
+ ail_cb_ret_e ret;
+
+ if (obj->mr_info.loop_cnt < obj->mr_info.next_point) {
+ obj->mr_info.loop_cnt++;
+ return AIL_CB_RET_CONTINUE;
+ }
+
+ if(obj->mr_info.next_point <
+ obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+
+ sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", obj->mr_info.loop_cnt);
+ return AIL_CB_RET_CONTINUE;
+ }
+
+ sel_mem_info->type = obj->contents_type;;
+
+ /********** START : set search result to sel_mem_info buf ************/
+
+ char *name = NULL;
+ char *package = NULL;
+ char *icon = NULL;
+
+ ail_appinfo_get_str(appinfo, AIL_PROP_ICON_STR, &icon);
+
+ if (icon) {
+ sel_mem_info->icon1 = strdup(icon);
+ }
+
+ ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
+ if ((package) && (strlen(package) > 0)) {
+
+ if(strcmp(package, "org.tizen.smartsearch") == 0) {
+ SEARCH_DEBUG_LOG("'smartsearch' does not appended");
+ obj->mr_info.loop_cnt++;
+ obj->mr_info.next_point++;
+ SEARCH_FREE(sel_mem_info);
+ return AIL_CB_RET_CONTINUE;
+ }
+
+ sel_mem_info->launch_path = strdup(package);
+ } else {
+ SEARCH_DEBUG_WARNING("package : null");
+ }
+
+ ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &name);
+ if ((name) && (strlen(name) > 0)) {
+ sel_mem_info->text1 = strdup(search_markup_keyword(name, keyword, &is_word_in_str));
+ } else {
+ SEARCH_DEBUG_WARNING("name : null");
+}
+
+ if(obj->mr_info.next_point == 0) {
+ /* Set group title */
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ /********** END : set search result to sel_mem_info buf *************/
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
+ obj,
+ ad->itc_pslist_1line_1icon,
+ sel_mem_info,
+ obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+ obj->mr_info.next_point++;
+ obj->mr_info.loop_cnt++;
+
+ ret = AIL_CB_RET_CONTINUE;
+
+ } else if (obj->mr_info.next_point ==
+ obj->mr_info.offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+
+ /* Check that only "SMARTSEARCH" is left in more result */
+ if(obj->mr_info.next_point == obj->mr_info.result_cnt-1) {
+
+ char *package = NULL;
+
+ ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package);
+ if ((package) && (strlen(package) > 0) && (strcmp(package, "org.tizen.smartsearch") == 0)) {
+ SEARCH_DEBUG_LOG("Only 'SMARTSEARCH' is left in more result");
+ return AIL_CB_RET_CANCEL;
+ }
+ }
+
+ /* Set more title to genlist (under 'search all') */
+ sel_mem_more = (struct search_item_more_sel *)calloc(1, sizeof(struct search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+
+ ret = AIL_CB_RET_CANCEL;
+ } else {
+ SEARCH_DEBUG_WARNING
+ ("__search_sql_menu_search_result_cb wrong index : %d",
+ obj->mr_info.next_point);
+
+ ret = AIL_CB_RET_CANCEL;
+ }
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+int search_sql_menu_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit,
+ char *keyword,
+ void *data,
+ struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_cb_data scd = {obj, ad, keyword, result_info};
+
+ int cnt = 0;
+ int ret = 0;
+
+ ail_filter_h filter = NULL;
+ ail_error_e rc;
+
+ char *escape_added_keyword = NULL;
+ SEARCH_MALLOC(escape_added_keyword, strlen(keyword)*2+5, char);
+ memset(escape_added_keyword, 0x0, strlen(keyword)*2+5);
+ search_sql_make_keyword_bind_value(keyword, escape_added_keyword, SEARCH_SQL_BIND_TYPE_DUPLEX);
+
+ rc = ail_filter_new(&filter);
+ if (rc != AIL_ERROR_OK) {
+ SEARCH_DEBUG_WARNING("menu search - ail_filter_new error : %d", rc);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ rc = ail_filter_add_str(filter, AIL_PROP_NAME_STR, escape_added_keyword);
+ if (rc != AIL_ERROR_OK) {
+ SEARCH_DEBUG_WARNING("menu search - ail_filter_add_str error : %d", rc);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ rc = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false);
+ if (rc != AIL_ERROR_OK) {
+ SEARCH_DEBUG_WARNING("menu search - ail_filter_add_bool error : %d", rc);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ rc = ail_filter_count_appinfo(filter, &cnt);
+ if( rc != AIL_ERROR_OK) {
+ SEARCH_DEBUG_WARNING("menu search - ail_filter_count_appinfo error : %d", rc);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ SEARCH_DEBUG_LOG("ail search result : %d", cnt);
+ obj->mr_info.result_cnt = cnt;
+
+ if(cnt > 0) {
+ obj->mr_info.loop_cnt = 0;
+ rc = ail_filter_list_appinfo_foreach(filter, __search_sql_menu_search_result_cb, &scd);
+ if( rc != AIL_ERROR_OK) {
+ SEARCH_DEBUG_WARNING("menu search - ail_filter_list_appinfo_foreach error : %d", rc);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ goto out_func;
+ }
+
+ if (obj->mr_info.next_point == 0) {
+ ret = SEARCH_RET_SEARCH_NONE;
+ } else {
+ ret = SEARCH_RET_SEARCH_SUCCESS;
+ }
+ } else {
+ ret = SEARCH_RET_SEARCH_NONE;
+ }
+
+out_func:
+ if (filter) {
+ ail_filter_destroy(filter);
+ }
+
+ SEARCH_FREE(escape_added_keyword);
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+bool __search_sql_browser_bookmark_result_cb(favorites_bookmark_entry_s *item, void *user_data)
+{
+ SEARCH_FUNC_START;
+ struct search_item_sel *sel_mem_info = NULL;
+
+ bool ret = false;
+ bool is_word_in_str_main = false;
+ bool is_word_in_str_sub = false;
+
+ char* match_str_title = NULL;
+ char* match_str_addr = NULL;
+
+ struct search_cb_data_browser *scd = (struct search_cb_data_browser*)user_data;
+ struct appdata *ad = scd->ad;
+ struct search_content_object *obj = scd->obj;
+ struct search_genlist_info *result_info = scd->result_info;
+ char *keyword = scd->keyword;
+
+ struct search_genlist_item_info *gen_item = NULL;
+ struct search_more_result *info = scd->info;
+
+ if (info->loop_cnt < info->next_point) {
+ info->loop_cnt++;
+ return true;
+ }
+
+ if (info->next_point < info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+ char bookmark_id_str[MAX_LENGTH_PER_PATH] = {0,};
+
+ /********** START : set search result to sel_mem_info buf ************/
+
+ if (item != NULL && item->title) {
+ match_str_title = strdup(search_markup_keyword(item->title, keyword, &is_word_in_str_main));
+ }
+
+ if (item != NULL && item->address) {
+ match_str_addr = strdup(search_markup_keyword(item->address, keyword, &is_word_in_str_sub));
+ }
+
+ if (is_word_in_str_main == true || is_word_in_str_sub == true) {
+ if (obj->gl_result_grp == NULL && result_info->group == NULL) {
+ /* Set group title */
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", info->loop_cnt);
+ return true;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+ snprintf(bookmark_id_str, MAX_LENGTH_PER_ID - 1, "%d", item->id);
+ sel_mem_info->launch_param = strdup(bookmark_id_str);
+
+ if (match_str_title) {
+ sel_mem_info->text1 = strdup(match_str_title);
+ }
+
+ if (match_str_addr) {
+ sel_mem_info->text2 = strdup(match_str_addr);
+ sel_mem_info->launch_path= strdup(item->address);
+ }
+
+ if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ sel_mem_info->icon2 = strdup(SEARCH_FAVORITE_ICON);
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
+ obj,
+ ad->itc_pslist_2line_2icon_browser_bookmark,
+ sel_mem_info,
+ obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+ scd->search_ret = true;
+ }
+
+ SEARCH_FREE(match_str_title);
+ SEARCH_FREE(match_str_addr);
+
+ /********** END : set search result to sel_mem_info buf *************/
+ info->next_point++;
+ info->loop_cnt++;
+
+ ret = true;
+ } else if (info->next_point ==
+ info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+ info->offset = info->next_point;
+ ret = false;
+ } else {
+ SEARCH_DEBUG_WARNING
+ ("__search_sql_browser_bookmark_result_cb wrong index : %d",
+ info->next_point);
+
+ ret = false;
+ }
+ SEARCH_FUNC_END;
+ return ret;
+
+}
+
+bool __search_sql_browser_history_result_cb(favorites_history_entry_s *item, void *user_data)
+{
+ SEARCH_FUNC_START;
+ struct search_item_sel *sel_mem_info = NULL;
+
+ bool ret = false;
+ bool is_word_in_str_main = false;
+
+ const char* match_str = NULL;
+
+ struct search_cb_data_browser *scd = (struct search_cb_data_browser*)user_data;
+ struct appdata *ad = scd->ad;
+ struct search_content_object *obj = scd->obj;
+ struct search_genlist_info *result_info = scd->result_info;
+ char *keyword = scd->keyword;
+
+ struct search_more_result *info = scd->info;
+ struct search_genlist_item_info *gen_item = NULL;
+
+ if (info->loop_cnt < info->next_point) {
+ info->loop_cnt++;
+ return true;
+ }
+
+ if (info->next_point < info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+ char history_id_str[MAX_LENGTH_PER_PATH] = {0,};
+
+ /********** START : set search result to sel_mem_info buf ************/
+
+ if (item != NULL && item->address) {
+ match_str = search_markup_keyword(item->address, keyword, &is_word_in_str_main);
+ }
+
+ if (is_word_in_str_main != false ) {
+ if (obj->gl_result_grp == NULL && result_info->group == NULL ) {
+ /* Set group title */
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ sel_mem_info = (struct search_item_sel *)calloc(1, sizeof(struct search_item_sel));
+
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", info->loop_cnt);
+ return true;
+ }
+
+ sel_mem_info->type = obj->contents_type;
+ snprintf(history_id_str, MAX_LENGTH_PER_ID - 1, "%d", item->id);
+ sel_mem_info->launch_param = strdup(history_id_str);
+
+ if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+
+ if (item->address) {
+ sel_mem_info->launch_path = strdup(item->address);
+ }
+
+ sel_mem_info->text1 = strdup(match_str);
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
+ obj,
+ ad->itc_pslist_1line_1icon_browser_history,
+ sel_mem_info,
+ obj->gl_result_grp);
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+ scd->search_ret = true;
+ }
+
+ info->next_point++;
+ info->loop_cnt++;
+
+ ret = true;
+
+ } else if (info->next_point ==
+ info->offset + SEARCH_CATEGORY_LIST_MORE_CNT) {
+ info->offset = info->next_point;
+ ret = false;
+ } else {
+ SEARCH_DEBUG_WARNING
+ ("__search_sql_browser_history_result_cb wrong index : %d",
+ info->next_point);
+
+ ret = false;
+ }
+
+ SEARCH_FUNC_END;
+ return ret;
+}
+
+int search_sql_browser_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit,
+ char *keyword,
+ void *data,
+ struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ struct search_cb_data_browser scd_browser = {obj, ad, keyword, result_info, NULL, false};
+ struct search_cb_data_browser scd_history = {obj, ad, keyword, result_info, NULL, false};
+
+ static struct search_more_result browser_result[2];
+ struct search_item_more_sel *sel_mem_more = NULL;
+
+ int ret = 0;
+ int bookmark_cnt = 0, history_cnt = 0;
+ int bookmark_ret = 0, history_ret = 0;
+
+ if (offset == 0) {
+ /* offset 0 means first search result, so we initialize struct */
+ memset(browser_result, 0x0, sizeof(browser_result));
+
+ favorites_bookmark_get_count(&browser_result[0].result_cnt);
+ favorites_history_get_count(&browser_result[1].result_cnt);
+
+ bookmark_cnt = browser_result[0].result_cnt;
+ history_cnt = browser_result[1].result_cnt;
+ browser_result[0].ad = browser_result[1].ad = ad;
+ obj->gl_result_grp = NULL;
+
+ if ( bookmark_cnt <= 0 && history_cnt <= 0 )
+ return SEARCH_RET_SEARCH_NONE;
+ } else {
+ bookmark_cnt = browser_result[0].result_cnt;
+ history_cnt = browser_result[1].result_cnt;
+ browser_result[0].loop_cnt = 0;
+ browser_result[1].loop_cnt = 0;
+ }
+
+ if (offset >= bookmark_cnt + history_cnt) {
+ /* We need not to search */
+ return SEARCH_RET_SEARCH_NONE;
+ }
+
+ scd_browser.info = &browser_result[0];
+ scd_history.info = &browser_result[1];
+
+ /* offset check */
+ if (bookmark_cnt > browser_result[0].next_point )
+ bookmark_ret = favorites_bookmark_foreach(__search_sql_browser_bookmark_result_cb,
+ &scd_browser);
+ if (history_cnt > browser_result[1].next_point && g_list_length(result_info->itemlist) < SEARCH_CATEGORY_LIST_MORE_CNT)
+ history_ret = favorites_history_foreach(__search_sql_browser_history_result_cb,
+ &scd_history);
+
+ if (bookmark_ret == FAVORITES_ERROR_DB_FAILED
+ && history_ret == FAVORITES_ERROR_DB_FAILED ) {
+ ret = SEARCH_RET_SEARCH_FAIL;
+ }
+ else if (scd_browser.search_ret == false && scd_history.search_ret == false){
+ /* It means we can't get matched results */
+ ret = SEARCH_RET_SEARCH_NONE;
+ }
+ else {
+ /* Make More button */
+ if (browser_result[0].next_point < bookmark_cnt
+ || browser_result[1].next_point < history_cnt) {
+ sel_mem_more = (struct search_item_more_sel *)calloc(1, sizeof(struct search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ }
+
+ /* return check */
+ obj->mr_info.next_point = browser_result[0].next_point
+ + browser_result[1].next_point;
+ ret = SEARCH_RET_SEARCH_SUCCESS;
+ }
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+int search_sql_msg_search_result_by_api(struct search_content_object *obj,
+ int offset, int limit,
+ char *keyword,
+ void *data,
+ struct search_genlist_info *result_info)
+{
+ SEARCH_FUNC_START;
+
+ int ret = SEARCH_RET_SEARCH_FAIL;
+
+ struct search_item_sel *sel_mem_info = NULL;
+ struct search_item_more_sel *sel_mem_more = NULL;
+ struct appdata *ad = (struct appdata *)data;
+ struct search_genlist_item_info *gen_item = NULL;
+
+ bool is_word_in_str;
+
+ int i = 0;
+ int j = 0;
+ bool is_word_in_title = false;
+
+ msg_error_t err = MSG_SUCCESS;
+
+ msg_struct_list_s total_msgList;
+ msg_struct_list_s msgList;
+ msg_struct_t search_s = NULL;
+ msg_struct_list_s *addr_list = NULL;
+
+ search_s = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION);
+
+ err = msg_set_int_value(search_s, MSG_SEARCH_CONDITION_FOLDERID_INT, MSG_ALLBOX_ID);
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_FOLDERID_INT");
+ goto out_func;
+ };
+
+ err = msg_set_int_value(search_s, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_INVALID);
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_MSGTYPE_INT");
+ goto out_func;
+ }
+
+ err = msg_set_str_value(search_s, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, keyword, strlen(keyword));
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_SEARCH_CONDITION_SEARCH_VALUE_STR");
+ goto out_func;
+ }
+
+ err = msg_search_message(ad->msg_handle, search_s, 0, 0, &total_msgList);
+ if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+ SEARCH_DEBUG_WARNING("msg_search_message is failed : %d", err);
+ goto out_func;
+ }
+
+ err = msg_search_message(ad->msg_handle, search_s, offset, limit, &msgList);
+
+ if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+ SEARCH_DEBUG_WARNING("msg_search_message is failed : %d", err);
+ goto out_func;
+ }
+
+ SEARCH_DEBUG_LOG("Matched Total Message : %d", total_msgList.nCount);
+ SEARCH_DEBUG_LOG("Message Count : %d", msgList.nCount);
+
+ if (msgList.nCount <= 0) {
+ SEARCH_DEBUG_WARNING("no msg search result");
+ ret = SEARCH_RET_SEARCH_NONE;
+ } else {
+
+ /* Set group title */
+ if (offset == 0) {
+ /* Set group title */
+ result_info->group = search_add_genlist_item(SEARCH_GENLIST_GROUP,
+ obj,
+ ad->itc_grouptitle,
+ obj,
+ NULL);
+ }
+
+ /********** START : set search result to sel_mem_info buf ************/
+
+ for (i = 0; i < msgList.nCount; i++) {
+ const char *text_1line = NULL;
+ const char *markup_keyword = NULL;
+ char *img_path = NULL;
+
+ int msg_type = 0;
+ int contact_id = -1;
+ int message_id = -1;
+
+ char subject[MAX_SUBJECT_LEN] = {0};
+ char str_number[MAX_ADDRESS_VAL_LEN] = {0,};
+ char str_name[MAX_DISPLAY_NAME_LEN] = {0,};
+ char msg_text[MAX_MSG_TEXT_LEN] = {0,};
+ char msg_id_str[MAX_LENGTH_PER_PATH] = {0,};
+
+ err = msg_get_int_value(msgList.msg_struct_info[i], MSG_MESSAGE_TYPE_INT, &msg_type);
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_MESSAGE_TYPE_INT %d", err);
+ goto out_func;
+ }
+
+ SEARCH_DEBUG_LOG("mms : %d", msg_type);
+
+
+ sel_mem_info = (struct search_item_sel *)calloc(1,sizeof(struct search_item_sel));
+ if (!sel_mem_info) {
+ SEARCH_DEBUG_WARNING("[%d] Fail to make a genlist select info item!", i);
+ return true;
+ }
+
+ sel_mem_info->type = obj->contents_type;;
+
+ err = msg_get_int_value(msgList.msg_struct_info[i], MSG_MESSAGE_ID_INT, &message_id);
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to make search struct : MSG_MESSAGE_ID_INT %d", err);
+ goto out_func;
+ }
+
+ snprintf(msg_id_str, MAX_LENGTH_PER_ID - 1, "%d", message_id);
+ sel_mem_info->launch_param= strdup(msg_id_str);
+
+ /* Set 1st line string */
+ if (msg_type == MSG_TYPE_MMS || msg_type == MSG_TYPE_MMS_JAVA || msg_type == MSG_TYPE_MMS_NOTI) {
+ /* MMS case */
+ err = msg_get_str_value(msgList.msg_struct_info[i], MSG_MESSAGE_SUBJECT_STR,
+ subject, MAX_SUBJECT_LEN);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get sms context %d", err);
+ goto out_func;
+ }
+
+ text_1line = subject;
+ markup_keyword = search_markup_keyword(text_1line, keyword,&is_word_in_title);
+
+ if (!is_word_in_title) {
+ memset(msg_text, 0x00, sizeof(msg_text));
+ err = msg_get_str_value(msgList.msg_struct_info[i],
+ MSG_MESSAGE_MMS_TEXT_STR,
+ msg_text,
+ sizeof(msg_text));
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get mms context %d", err);
+ goto out_func;
+ }
+
+ text_1line = msg_text;
+
+ markup_keyword = search_markup_keyword(text_1line,
+ keyword,
+ &is_word_in_title);
+ }
+
+ if ((text_1line) && (strlen(text_1line) > 0 )) {
+ sel_mem_info->text1 = strdup(markup_keyword);
+ } else {
+ sel_mem_info->text1 = strdup("Unknown");
+ }
+ } else if(msg_type == MSG_TYPE_SMS) {
+ /* SMS Case */
+ err = msg_get_str_value(msgList.msg_struct_info[i],
+ MSG_MESSAGE_SMS_DATA_STR,
+ msg_text,
+ sizeof(msg_text));
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get sms context %d", err);
+ goto out_func;
+ }
+
+ text_1line = msg_text;
+
+ markup_keyword = search_markup_keyword(text_1line,
+ keyword,
+ &is_word_in_title);
+ SEARCH_DEBUG_LOG("1st string : %s", text_1line);
+
+ if ((text_1line) && (strlen(text_1line) > 0)) {
+ sel_mem_info->text1 = strdup(markup_keyword);
+ }
+ }
+
+ err = msg_get_list_handle(msgList.msg_struct_info[i],
+ MSG_MESSAGE_ADDR_LIST_STRUCT,
+ (void **)&addr_list);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get address list handle! %d", err);
+ goto out_func;
+ }
+
+ /* Set 2nd line string */
+ for ( j=0; j<addr_list->nCount; j++) {
+ memset(str_number, 0, sizeof(str_number));
+ memset(str_name, 0, sizeof(str_name));
+ contact_id = -1;
+ is_word_in_str = false;
+
+ /* First We set text_2line to first address data */
+ err = msg_get_str_value(addr_list->msg_struct_info[j],
+ MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
+ str_number,
+ MAX_ADDRESS_VAL_LEN);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_DISPLAYNAME_STR %d", err);
+ goto out_func;
+ }
+
+ err = msg_get_str_value(addr_list->msg_struct_info[j],
+ MSG_ADDRESS_INFO_DISPLAYNAME_STR,
+ str_name,
+ MAX_DISPLAY_NAME_LEN);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_ADDRESS_VALUE_STR %d", err);
+ goto out_func;
+ }
+
+ err = msg_get_int_value(addr_list->msg_struct_info[j],
+ MSG_ADDRESS_INFO_CONTACT_ID_INT,
+ &contact_id);
+
+ if (err != MSG_SUCCESS) {
+ SEARCH_DEBUG_WARNING("Fail to get data! : MSG_ADDRESS_INFO_CONTACT_ID_INT %d", err);
+ goto out_func;
+ }
+
+ /* Set text_2line */
+ markup_keyword = search_markup_keyword(str_number, keyword, &is_word_in_str);
+
+ if (strlen(str_name) > 0) {
+ sel_mem_info->text2 = strdup(str_name);
+ } else if(strlen(str_number) > 0) {
+ sel_mem_info->text2 = strdup(markup_keyword);
+ } else {
+ sel_mem_info->text2 = strdup("Unknown");
+ }
+
+ /* Check Whether Thumbnail Image exist or not */
+ if (contact_id > -1) {
+ contacts_query_h query = NULL;
+ contacts_filter_h filter = NULL;
+ contacts_list_h list = NULL;
+
+ unsigned int count = 0;
+ ret = contacts_connect2();
+
+ if (ret != CONTACTS_ERROR_NONE) {
+ SEARCH_DEBUG_WARNING("Fail to connect contact service!");
+ if (obj->obj_icon_path != NULL) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+ continue;
+ } else {
+ contacts_query_create(_contacts_person_number._uri, &query);
+ contacts_filter_create(_contacts_person_number._uri, &filter);
+ contacts_filter_add_int(filter, _contacts_person.id, CONTACTS_MATCH_EQUAL,
+ contact_id);
+ contacts_query_set_filter(query, filter);
+ contacts_db_get_records_with_query(query, 0, 0, &list);
+ contacts_list_get_count(list, &count);
+
+ if (count > 0) {
+ contacts_record_h record;
+ contacts_list_get_current_record_p(list, &record);
+ contacts_record_get_str_p(record, _contacts_person.image_thumbnail_path, &img_path);
+ }
+
+ if (img_path != NULL) {
+ sel_mem_info->icon1 = strdup(img_path);
+ } else if (obj->obj_icon_path != NULL) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+ if (filter) {
+ contacts_filter_destroy(filter);
+ }
+
+ if (query) {
+ contacts_query_destroy(query);
+ }
+ if (list) {
+ contacts_list_destroy(list, true);
+ }
+
+ ret = contacts_disconnect2();
+ }
+ } else {
+ if (obj->obj_icon_path) {
+ sel_mem_info->icon1 = strdup(obj->obj_icon_path);
+ }
+ }
+
+ if ((is_word_in_title) || (is_word_in_str)) {
+ break;
+ }
+ }
+
+ gen_item = search_add_genlist_item(SEARCH_GENLIST_ITEM,
+ obj,
+ ad->itc_pslist_2line_1icon,
+ sel_mem_info,
+ obj->gl_result_grp);
+
+ result_info->itemlist = g_list_append(result_info->itemlist, (void*)gen_item);
+ }
+
+ msg_release_list_struct(&msgList);
+ msg_release_list_struct(&total_msgList);
+
+ /* Set more title to genlist (under 'search all') */
+ if (total_msgList.nCount > offset + i) {
+ obj->mr_info.next_point = offset + i;
+
+ sel_mem_more = (struct search_item_more_sel *)
+ calloc(1,sizeof(struct search_item_more_sel));
+ sel_mem_more->obj = obj;
+
+ result_info->more = search_add_genlist_item(SEARCH_GENLIST_MORE,
+ obj,
+ ad->itc_listmore,
+ sel_mem_more,
+ obj->gl_result_grp);
+ }
+
+ ret = SEARCH_RET_SEARCH_SUCCESS;
+ }
+
+out_func:
+ if (search_s != NULL) {
+ msg_release_struct(&search_s);
+ }
+ SEARCH_FUNC_END;
+ return ret;
+}
+
+void search_sql_update_result_object(struct search_content_object* result_obj, sqlite3* db_handle, sqlite3_stmt** db_sql)
+{
+ SEARCH_FUNC_START;
+
+ int rc = 0;
+
+ sqlite3_stmt *sql_stmt = db_sql[SEARCH_STMT_UPDATE_OBJECT_INFO];
+ SEARCH_RET_IF(sql_stmt==NULL);
+
+ search_sql_bind_text(db_handle, sql_stmt, 1, result_obj->name);
+ search_sql_bind_int(db_handle, sql_stmt, 2, result_obj->string_type);
+ search_sql_bind_int(db_handle, sql_stmt, 3, result_obj->visible);
+ search_sql_bind_int(db_handle, sql_stmt, 4, result_obj->order);
+ search_sql_bind_int(db_handle, sql_stmt, 5, result_obj->contents_type);
+ search_sql_bind_int(db_handle, sql_stmt, 6, result_obj->category_type);
+ search_sql_bind_text(db_handle, sql_stmt, 7, result_obj->def_pkg_name);
+ search_sql_bind_int(db_handle, sql_stmt, 8, result_obj->contents_type);
+
+ rc = sqlite3_step(sql_stmt);
+
+ if (rc == SQLITE_OK)
+ SEARCH_DEBUG_LOG("INSERT STEP SUCCESS");
+
+ search_sql_stmt_init(sql_stmt);
+
+ SEARCH_FUNC_END;
+
+}
diff --git a/src/search_bar.cpp b/src/search_bar.cpp
new file mode 100755
index 0000000..a56ed2a
--- /dev/null
+++ b/src/search_bar.cpp
@@ -0,0 +1,572 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd/
+ *
+ * Licensed under the Flora License, Version 1.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+
+
+
+#include <string.h>
+#include "smartsearch.h"
+#include "Elementary.h"
+
+Eina_Bool __search_entry_timer_cb(void *data)
+{
+ SEARCH_FUNC_START;
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL);
+
+ search_set_result_list(ad);
+ ad->search_timer = NULL;
+
+ SEARCH_FUNC_END;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+void __search_searchbar_entry_changed_cb(void *data, Evas_Object * obj,
+ void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (elm_object_focus_get(ad->search_bar)) {
+ if (elm_entry_is_empty(ad->search_entry)) {
+ elm_object_signal_emit(ad->search_bar, "elm,state,eraser,hide", "elm");
+ }
+ else {
+ elm_object_signal_emit(ad->search_bar, "elm,state,eraser,show", "elm");
+ }
+ } else {
+ if (elm_entry_is_empty(ad->search_entry)) {
+ elm_object_signal_emit(ad->search_bar, "elm,state,guidetext,show", "elm");
+ }
+ else {
+ elm_object_signal_emit(ad->search_bar, "elm,state,guidetext,hide", "elm");
+ }
+ }
+
+ /* Make timer for check user's input */
+ search_stop_search(ad);
+
+ ad->search_timer = ecore_timer_add(0.4, __search_entry_timer_cb, ad);
+
+ SEARCH_FUNC_END;
+ return;
+}
+
+
+static void __search_searchbar_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (!elm_entry_is_empty(ad->search_entry)) {
+ elm_object_signal_emit(ad->search_bar, "elm,state,eraser,show", "elm");
+ }
+
+ elm_object_signal_emit(ad->search_bar, "elm,state,guidetext,hide", "elm");
+ elm_object_signal_emit(ad->search_bar, "cancel,in", "");
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_searchbar_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (elm_entry_is_empty(ad->search_entry)) {
+ elm_object_signal_emit(ad->search_bar, "elm,state,guidetext,show", "elm");
+ }
+
+ elm_object_signal_emit(ad->search_bar, "elm,state,eraser,hide", "elm");
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_searchbar_bg_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ elm_object_focus_set(ad->search_entry, EINA_TRUE);
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_searchbar_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source) // When X marked button is clicked, empty entry's contents.
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ elm_entry_entry_set(ad->search_entry, "");
+
+ Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(ad->search_entry);
+
+ if (imf_context) {
+ ecore_imf_context_input_panel_show(imf_context);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_searchbar_key_down_cb(void *data, Evas * e, Evas_Object * obj, void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *) event_info;
+
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(ev == NULL);
+
+ SEARCH_DEBUG_LOG("ev->key : %s", ev->key);
+
+ if (SEARCH_STRCMP(ev->key, "Return") == 0) {
+ ecore_imf_context_input_panel_hide
+ ((Ecore_IMF_Context *)elm_entry_imf_context_get
+ (ad->search_entry));
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_searchbar_cancel_clicked_cb(void *data, Evas_Object * obj,
+ void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ const char* text = NULL;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ elm_object_focus_set(ad->cate_btn, EINA_TRUE);
+ evas_object_hide(ad->search_cancel_btn);
+ elm_object_signal_emit(ad->search_bar, "cancel,out", "");
+ text = elm_entry_entry_get(ad->search_entry);
+
+ if (text != NULL && strlen(text) > 0)
+ elm_entry_entry_set(ad->search_entry, NULL);
+
+ elm_object_signal_emit(ad->search_bar, "elm,state,eraser,hide", "elm");
+
+ search_set_result_list(ad);
+
+ malloc_trim(0);
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_searchbar_gl_drag_scroll_start_cb(void *data, Evas_Object * obj, void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(ad->search_entry);
+
+ if (imf_context) {
+ ecore_imf_context_input_panel_hide(imf_context);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+
+static void
+__search_searchbar_state_event_cb(void *data, Ecore_IMF_Context *imf_context, int value)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ switch (value)
+ {
+ case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
+ evas_object_smart_callback_add(
+ ad->search_gl,
+ "scroll,drag,start",
+ __search_searchbar_gl_drag_scroll_start_cb,
+ data);
+ break;
+ case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
+ /* ISE state has changed to ISE_STATE_HIDE status */
+ evas_object_smart_callback_del(
+ ad->search_gl,
+ "scroll,drag,start",
+ __search_searchbar_gl_drag_scroll_start_cb);
+ break;
+ }
+
+ SEARCH_FUNC_END;
+}
+
+Evas_Object *__search_init_noresult_view(Evas_Object* parent)
+{
+ SEARCH_FUNC_START;
+
+ Evas_Object *noc = NULL;
+
+ noc = elm_layout_add(parent);
+ elm_layout_theme_set(noc, "layout", "nocontents", "search");
+ elm_object_part_text_set(noc, "elm.text", dgettext("sys_string", "IDS_COM_BODY_NO_SEARCH_RESULTS"));
+ elm_object_focus_allow_set(noc, EINA_TRUE);
+
+ SEARCH_FUNC_END;
+
+ return noc;
+}
+
+Evas_Object *search_category_custom_layout_add(Evas_Object *parent)
+{
+ SEARCH_FUNC_START;
+
+ Evas_Object *layout = NULL;
+ layout = elm_layout_add(parent);
+ elm_layout_file_set(layout, SEARCH_EDJ, "smartsearch/custom_image_button");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, 0.5, 0.5);
+ evas_object_show(layout);
+
+ SEARCH_FUNC_END;
+ return layout;
+}
+
+Evas_Object *search_category_image_add(char* imgpath, Evas_Object *parent, int width, int height, bool resize)
+{
+ SEARCH_FUNC_START;
+
+ char buf[MAX_LENGTH_PER_PATH] = { 0, };
+ Evas_Object *image = NULL;
+
+ image = elm_image_add(parent);
+ elm_image_resizable_set(image,1,1);
+ snprintf(buf, sizeof(buf), SEARCH_ICON_PATH "%s", imgpath);
+ elm_image_file_set(image, buf, NULL);
+ evas_object_show(image);
+
+ SEARCH_FUNC_END;
+ return image;
+}
+
+Evas_Object *search_searchbar_category_icon_add(char* img, Evas_Object *parent, int width, int height, bool resize)
+{
+ SEARCH_FUNC_START;
+
+ char buf[MAX_LENGTH_PER_PATH] = { 0, };
+ Evas_Object* cate_icon = NULL;
+ double scale = elm_config_scale_get();
+
+ if (img != NULL ) {
+ cate_icon = elm_icon_add(parent);
+
+ snprintf(buf, sizeof(buf), SEARCH_ICON_PATH "%s", img);
+
+ SEARCH_DEBUG_LOG("buf : %s", buf);
+
+ elm_image_file_set(cate_icon, buf, NULL);
+
+ evas_object_size_hint_aspect_set(cate_icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+
+ if (resize != false) {
+ elm_image_resizable_set(cate_icon, EINA_TRUE, EINA_TRUE);
+ } else {
+ elm_image_resizable_set(cate_icon, EINA_FALSE, EINA_FALSE);
+ }
+
+ evas_object_size_hint_min_set(cate_icon, width * scale, height * scale);
+ evas_object_size_hint_max_set(cate_icon, width * scale, height * scale);
+ }
+
+ SEARCH_FUNC_END;
+
+ return cate_icon;
+}
+
+
+void search_delete_searchbar(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ if (ad->search_bar) {
+ elm_object_signal_callback_del(
+ ad->search_bar,
+ "elm,bg,clicked",
+ "elm",
+ __search_searchbar_bg_clicked_cb);
+ elm_object_signal_callback_del(
+ ad->search_bar,
+ "elm,eraser,clicked",
+ "elm",
+ __search_searchbar_eraser_clicked_cb);
+
+ evas_object_del(ad->search_bar);
+ ad->search_bar = NULL;
+ }
+
+ if (ad->search_entry) {
+ evas_object_smart_callback_del(
+ ad->search_entry,
+ "changed",
+ __search_searchbar_entry_changed_cb);
+ evas_object_smart_callback_del(
+ ad->search_entry,
+ "preedit,changed",
+ __search_searchbar_entry_changed_cb);
+ evas_object_smart_callback_del(
+ ad->search_entry,
+ "focused",
+ __search_searchbar_entry_focused_cb);
+ evas_object_smart_callback_del(
+ ad->search_entry,
+ "unfocused",
+ __search_searchbar_entry_unfocused_cb);
+
+ evas_object_del(ad->search_entry);
+ ad->search_entry = NULL;
+ }
+
+ if (ad->search_cancel_btn) {
+ evas_object_smart_callback_del(
+ ad->search_cancel_btn,
+ "clicked",
+ __search_searchbar_cancel_clicked_cb);
+ evas_object_del(ad->search_cancel_btn);
+ ad->search_cancel_btn = NULL;
+ }
+
+ if (ad->cate_btn) {
+ evas_object_del(ad->cate_btn);
+ ad->cate_btn = NULL;
+ }
+
+ if (ad->sb_layout) {
+ elm_object_part_content_unset(ad->sb_layout, "list");
+ evas_object_del(ad->sb_layout);
+ }
+
+ SEARCH_EVAS_OBJECT_FREE(ad->noresult_view);
+ SEARCH_EVAS_OBJECT_FREE(ad->search_gl);
+
+ SEARCH_FUNC_END;
+}
+
+void search_create_searchbar_layout(Evas_Object *parent, void *data)
+{
+ SEARCH_FUNC_START;
+
+ Evas_Object *genlist = NULL;
+ struct appdata *ad = (struct appdata *)data;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ ad->sb_layout = search_create_layout(parent,
+ SEARCH_EDJ,
+ SEARCH_SEARCHBAR_GROUP_NORMAL);
+
+ SEARCH_RET_IF(ad->sb_layout == NULL);
+
+ // Category button
+ ad->cate_btn = search_create_category_button(ad->sb_layout, ad);
+
+ SEARCH_RET_IF(ad->cate_btn == NULL);
+ elm_object_part_content_set(ad->sb_layout,
+ "searchbar_area_category", ad->cate_btn);
+
+ // Search bar
+ ad->search_bar = search_create_search_bar(ad->sb_layout);
+ SEARCH_RET_IF(ad->search_bar == NULL);
+ elm_object_signal_callback_add(ad->search_bar, "elm,bg,clicked",
+ "elm", __search_searchbar_bg_clicked_cb, ad);
+ elm_object_signal_callback_add(ad->search_bar, "elm,eraser,clicked",
+ "elm", __search_searchbar_eraser_clicked_cb, ad);
+ elm_object_part_content_set(ad->sb_layout, "searchbar_area_entry",
+ ad->search_bar);
+
+ // Search entry
+ ad->search_entry = search_create_search_entry(ad->sb_layout, ad);
+ SEARCH_RET_IF(ad->search_entry == NULL);
+ elm_object_part_content_set(ad->search_bar,
+ "elm.swallow.content", ad->search_entry);
+ evas_object_smart_callback_add(ad->search_entry, "changed",
+ __search_searchbar_entry_changed_cb, ad);
+ evas_object_smart_callback_add(ad->search_entry, "preedit,changed",
+ __search_searchbar_entry_changed_cb, ad);
+ evas_object_smart_callback_add(ad->search_entry, "focused",
+ __search_searchbar_entry_focused_cb, ad);
+ evas_object_smart_callback_add(ad->search_entry, "unfocused",
+ __search_searchbar_entry_unfocused_cb, ad);
+ evas_object_event_callback_add(ad->search_entry, EVAS_CALLBACK_KEY_DOWN,
+ __search_searchbar_key_down_cb, ad);
+
+ // Search Cancel button
+ ad->search_cancel_btn = search_create_search_cancel_btn(ad->sb_layout);
+ SEARCH_RET_IF(ad->search_cancel_btn == NULL);
+ evas_object_smart_callback_add(ad->search_cancel_btn, "clicked",
+ __search_searchbar_cancel_clicked_cb,ad);
+ elm_object_part_content_set(ad->search_bar,
+ "button_cancel", ad->search_cancel_btn);
+
+ // Genlist
+ genlist = elm_genlist_add(ad->sb_layout);
+
+ // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
+ // then the item's height is calculated while the item's width fits to genlist width.
+ elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+ elm_genlist_tree_effect_enabled_set(genlist, EINA_TRUE);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ ad->search_gl = genlist;
+
+ // Result area
+ ad->noresult_view = __search_init_noresult_view(ad->sb_layout);
+
+ SEARCH_RET_IF(ad->noresult_view == NULL);
+ elm_object_part_content_set(ad->sb_layout, "list_noresult",
+ ad->noresult_view);
+
+
+ SEARCH_FUNC_END;
+}
+
+Evas_Object *search_create_layout(Evas_Object *parent, const char *file, const char *group)
+{
+ SEARCH_FUNC_START;
+ Evas_Object *layout = NULL;
+
+ /* create layout */
+ layout = elm_layout_add(parent);
+
+ SEARCH_RETV_IF(layout == NULL, NULL);
+
+ elm_layout_file_set(layout, file, group);
+
+ SEARCH_FUNC_END;
+ return layout;
+}
+
+Evas_Object *search_create_category_button(Evas_Object *parent, void *data)
+{
+ SEARCH_FUNC_START;
+ struct appdata *ad = (struct appdata *)data;
+
+ Evas_Object *cate_btn;
+ Evas_Object *cate_icon;
+
+ int err = 0;
+ char *imgpath = NULL;
+ int category = 0;
+
+ /* set search category icon area */
+
+ category = SEARCH_CATE_PHONE;
+ ad->search_category = category;
+
+ imgpath = ad->category_info[ad->search_category].btn_icon_path;
+ cate_icon = search_searchbar_category_icon_add(imgpath,
+ parent,
+ SEARCH_CATEGORY_BTN_ICON_SIZE_WIDTH,
+ SEARCH_CATEGORY_BTN_ICON_SIZE_HEIGHT,
+ false);
+
+ cate_btn = elm_button_add(parent);
+
+ SEARCH_RETV_IF(cate_btn == NULL, NULL);
+
+ elm_object_style_set(cate_btn, "circle/empty");
+ ad->cate_btn = cate_btn;
+
+ elm_object_content_set(ad->cate_btn, cate_icon);
+ evas_object_show(cate_btn);
+
+ SEARCH_FUNC_END;
+ return cate_btn;
+}
+
+Evas_Object *search_create_search_bar(Evas_Object *parent)
+{
+ SEARCH_FUNC_START;
+
+ Evas_Object *layout = NULL;
+
+ layout = elm_layout_add(parent);
+ elm_layout_theme_set(layout, "layout", "searchbar", "cancel_button");
+ elm_object_part_text_set(layout, "elm.guidetext",
+ dgettext("sys_string", "IDS_COM_BODY_SEARCH"));
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ evas_object_show(layout);
+
+ SEARCH_FUNC_END;
+ return layout;
+}
+
+Evas_Object *search_create_search_cancel_btn(Evas_Object *parent)
+{
+ SEARCH_FUNC_START;
+ Evas_Object *cancel_btn = NULL;
+
+ cancel_btn = elm_button_add(parent);
+ elm_object_style_set(cancel_btn, "searchbar/default");
+ elm_object_text_set(cancel_btn, dgettext("sys_string", "IDS_COM_SK_CANCEL"));
+
+ SEARCH_FUNC_END;
+ return cancel_btn;
+}
+
+Evas_Object *search_create_search_entry(Evas_Object *parent, void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ Evas_Object *entry = NULL;
+
+ SEARCH_RETV_IF(ad == NULL, NULL);
+
+ entry = elm_entry_add(parent);
+
+ elm_entry_scrollable_set(entry, EINA_TRUE);
+ elm_entry_single_line_set(entry, EINA_TRUE);
+
+ elm_entry_cnp_mode_set(entry, ELM_CNP_MODE_PLAINTEXT);
+ elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
+ elm_entry_prediction_allow_set(entry, EINA_FALSE);
+ elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
+ elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH);
+
+ Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(entry);
+ ecore_imf_context_input_panel_event_callback_add(imf_context,
+ ECORE_IMF_INPUT_PANEL_STATE_EVENT,
+ __search_searchbar_state_event_cb,
+ ad);
+ SEARCH_FUNC_END;
+ return entry;
+}
+
+
diff --git a/src/smartsearch.cpp b/src/smartsearch.cpp
new file mode 100755
index 0000000..a372238
--- /dev/null
+++ b/src/smartsearch.cpp
@@ -0,0 +1,816 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd/
+ *
+ * Licensed under the Flora License, Version 1.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+
+
+
+#include <stdio.h>
+#include <utilX.h>
+#include <ui-gadget.h>
+
+#include "smartsearch.h"
+#include "search_bar.h"
+#include "ps_makeupviews.h"
+#include "ps_searcher.h"
+
+#include <app.h>
+#include <app_manager.h>
+
+struct search_content_object_default {
+ int order;
+ int visible;
+ char name[DEF_BUF_LEN];
+ int string_type;
+ int contents_type;
+ int category_type;
+ char def_pkg_name[DEF_BUF_LEN];
+};
+
+struct search_category_info_default {
+ char btn_icon_path[MAX_LENGTH_PER_PATH];
+ char btn_icon_press_path[MAX_LENGTH_PER_PATH];
+};
+
+static struct search_content_object_default def_obj[SEARCH_CONT_MAX] = {
+ { 0, EINA_TRUE, "IDS_COM_BODY_CONTACTS", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_CONTACTS, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.contacts" },
+ { 1, EINA_TRUE, "IDS_COM_BODY_MESSAGES", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_MSG, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.message" },
+ { 2, EINA_TRUE, "IDS_COM_BODY_EMAIL", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_EMAIL, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.email" },
+ { 3, EINA_TRUE, "IDS_COM_BODY_IMAGES", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_IMAGES, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.image-viewer"},
+ { 4, EINA_TRUE, "IDS_COM_BODY_MUSIC", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_MUSIC, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.music-player"},
+ { 5, EINA_TRUE, "IDS_COM_BODY_VIDEOS", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_VIDEO, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.video-player"},
+ { 6, EINA_TRUE, "IDS_COM_BODY_CALENDAR", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_CALENDAR, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.calendar"},
+ { 7, EINA_TRUE, "IDS_COM_BODY_MEMO", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_MEMO, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.memo"},
+ { 8, EINA_TRUE, "IDS_COM_BODY_APPLICATIONS", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_MENU, SEARCH_OBJ_PHONE_CONTENTS, {0} },
+ { 9, EINA_TRUE, "IDS_COM_BODY_INTERNET", SEARCH_STR_TYPE_SYSTEM_STRING,
+ SEARCH_CONT_PHONE_BROWSER, SEARCH_OBJ_PHONE_CONTENTS, "org.tizen.browser"},
+};
+
+static struct search_category_info_default def_category[SEARCH_CATE_MAX] = {
+ { "B10_btn_icon_Phone.png", "B10_btn_icon_Phone_press.png" },
+};
+
+static void __search_win_delete_cb(void *data, Evas_Object * obj,
+ void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ elm_exit();
+
+ SEARCH_FUNC_END;
+}
+
+static Eina_Bool __search_mousedown_event(void *data, int type, void *event)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ Ecore_Event_Mouse_Button *ev = NULL;
+ SEARCH_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL);
+ SEARCH_RETV_IF(event == NULL, ECORE_CALLBACK_CANCEL);
+
+ ev = (Ecore_Event_Mouse_Button *) event;
+
+ SEARCH_RETV_IF(ev == NULL, ECORE_CALLBACK_CANCEL);
+
+ ad->touch_x = ev->x;
+ ad->touch_y = ev->y;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+
+static Eina_Bool __search_keydown_event(void *data, int type, void *event)
+{
+ SEARCH_FUNC_START;
+
+ Ecore_Event_Key *ev = (Ecore_Event_Key *) event;
+ SEARCH_RETV_IF(ev == NULL, EINA_FALSE);
+
+ if (!SEARCH_STRCMP(ev->keyname, KEY_END)) {
+ //end key concept is close.
+ elm_exit();
+ }
+
+ SEARCH_FUNC_END;
+
+ return EINA_FALSE;
+}
+
+static void __search_delete_layout_main(void *data)
+{
+ SEARCH_FUNC_START;
+ SEARCH_RET_IF(data == NULL);
+
+ struct appdata *ad = (struct appdata *)data;
+
+ SEARCH_EVAS_OBJECT_FREE(ad->layout_main);
+ SEARCH_EVAS_OBJECT_FREE(ad->navi_bar);
+ SEARCH_EVAS_OBJECT_FREE(ad->back_btn);
+
+ search_delete_searchbar_layout(ad);
+ SEARCH_FUNC_END;
+}
+
+static Evas_Object *__search_create_bg(Evas_Object * parent) {
+ SEARCH_FUNC_START;
+
+ Evas_Object *bg = NULL;
+ SEARCH_RETV_IF(parent == NULL, NULL);
+
+ bg = elm_bg_add(parent);
+ SEARCH_RETV_IF(bg == NULL, NULL);
+
+ evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(parent, bg);
+ evas_object_show(bg);
+
+ SEARCH_FUNC_END;
+ return bg;
+}
+
+static Evas_Object *__search_create_conformant(Evas_Object * parent) {
+ SEARCH_FUNC_START;
+
+ Evas_Object *conformant = NULL;
+ SEARCH_RETV_IF(parent == NULL, NULL);
+
+ conformant = elm_conformant_add(parent);
+
+ SEARCH_RETV_IF(conformant == NULL, NULL);
+
+ evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(parent, conformant);
+ evas_object_show(conformant);
+
+ SEARCH_FUNC_END;
+
+ return conformant;
+}
+
+static Evas_Object *__search_create_layout_main(Evas_Object *parent, Evas_Object *bg)
+{
+ SEARCH_FUNC_START;
+ Evas_Object *layout = NULL;
+
+ SEARCH_RETV_IF(parent == NULL, NULL);
+
+ layout = elm_layout_add(parent);
+
+ SEARCH_RETV_IF(layout == NULL, NULL);
+
+ //elm_layout_theme_set(layout, "standard", "window", "integration");
+ elm_layout_theme_set(layout, "layout", "application", "default");
+
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_part_content_set(layout, "elm.swallow.bg", bg);
+
+ edje_object_signal_emit(_EDJ(layout), "elm,state,show,indicator","elm");
+ edje_object_signal_emit(_EDJ(layout), "elm,state,show,content", "elm");
+ evas_object_show(layout);
+
+ SEARCH_FUNC_END;
+
+ return layout;
+}
+
+static Evas_Object *__search_create_navigation_layout(Evas_Object * parent)
+{
+ SEARCH_FUNC_START;
+
+ Evas_Object *navi_bar; //, *sd;
+
+ SEARCH_RETV_IF(parent == NULL, NULL);
+
+ navi_bar = elm_naviframe_add(parent);
+
+ elm_object_part_content_set(parent, "elm.swallow.content", navi_bar);
+
+ evas_object_show(navi_bar);
+
+ SEARCH_FUNC_END;
+
+ return navi_bar;
+}
+
+static void __search_back_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ elm_win_lower(ad->win_main);
+
+ if(ad->back_btn_type == BACK_BTN_TYPE_CLOSE)
+ elm_exit();
+
+ SEARCH_FUNC_END;
+}
+
+static Evas_Object* __search_add_back_btn(struct appdata *ad)
+{
+ SEARCH_FUNC_START;
+ SEARCH_RETV_IF(ad == NULL, NULL);
+
+ /* add back key */
+ Evas_Object *btn = elm_button_add(ad->conformant);
+ elm_object_style_set(btn, "naviframe/end_btn/default");
+ evas_object_smart_callback_add(btn, "clicked", __search_back_btn_clicked_cb, ad);
+
+ SEARCH_FUNC_END;
+
+ return btn;
+}
+
+static int __search_init_smartsearch(struct appdata *ad)
+{
+ SEARCH_FUNC_START;
+
+ SEARCH_RETV_IF(ad == NULL, -1);
+
+ // Base Layout
+ ad->bg = __search_create_bg(ad->win_main);
+ ad->conformant = __search_create_conformant(ad->win_main);
+ ad->layout_main = __search_create_layout_main(ad->conformant, ad->bg);
+ SEARCH_RETV_IF(ad->layout_main == NULL, -1);
+ elm_object_content_set(ad->conformant, ad->layout_main);
+
+ // Indicator
+ elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
+
+ // Navigation Bar
+ ad->navi_bar = __search_create_navigation_layout(ad->layout_main);
+
+ // Backbutton
+ ad->back_btn = __search_add_back_btn(ad);
+
+ // Search bar layout
+ search_create_searchbar_layout(ad->conformant, ad);
+
+ ad->navi_it = elm_naviframe_item_push(ad->navi_bar,
+ dgettext("sys_string", "IDS_COM_BODY_SEARCH"),
+ ad->back_btn, NULL, ad->sb_layout, NULL);
+
+ ad->search_category = SEARCH_CATE_PHONE;
+
+ SEARCH_FUNC_END;
+
+ return 0;
+}
+
+static void __search_init_category_object(struct appdata *ad)
+{
+ SEARCH_FUNC_START;
+ int i = 0;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ /* Initialize Category */
+ for( i = 0 ; i < SEARCH_CATE_MAX; ++i ) {
+ ad->category_info[i].btn_icon_path = strdup(def_category[i].btn_icon_path);
+ ad->category_info[i].btn_icon_press_path = strdup(def_category[i].btn_icon_press_path);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_init_result_object(struct appdata *ad)
+{
+ SEARCH_FUNC_START;
+
+ int i = 0;
+ int rc = 0;
+ int ret = SEARCH_RET_SEARCH_NONE;
+
+ int ail_ret = 0;
+
+ sqlite3_stmt *sql_load = NULL;
+ sqlite3_stmt *sql_insert = NULL;
+
+ char *imgpath = NULL;
+
+ /* Load DB data */
+ sql_load = ad->search_db_sql[SEARCH_STMT_GET_CATEGORY_LIST_ALL];
+
+ rc = sqlite3_step(sql_load);
+ if (rc != SQLITE_ROW) {
+ if (rc == SQLITE_DONE) {
+ SEARCH_DEBUG_WARNING("SELECT STEP : SQLITE_DONE. No result");
+ ret = SEARCH_RET_SEARCH_NONE;
+ } else {
+ SEARCH_DEBUG_ERROR("SELECT STEP FAIL : (%d)", rc);
+ ret = SEARCH_RET_SEARCH_FAIL;
+ }
+ } else {
+ SEARCH_DEBUG_LOG("SELECT STEP SUCCESS");
+ ret = SEARCH_RET_SEARCH_SUCCESS;
+}
+
+ if( ret != SEARCH_RET_SEARCH_SUCCESS ) {
+ /* If db result is NULL, initialize to default setting and insert this data to DB */
+ for( i = 0; i < SEARCH_CONT_MAX ; ++i ) {
+ sql_insert = ad->search_db_sql[SEARCH_STMT_INSERT_OBJECT_INFO];
+ ad->result_obj[i].order = def_obj[i].order;
+ ad->result_obj[i].visible = def_obj[i].visible;
+ ad->result_obj[i].contents_type = def_obj[i].contents_type;
+ ad->result_obj[i].category_type = def_obj[i].category_type;
+ ad->result_obj[i].name = strdup(def_obj[i].name);
+ ad->result_obj[i].string_type = def_obj[i].string_type;
+ ad->result_obj[i].def_pkg_name = strdup(def_obj[i].def_pkg_name);
+ ail_ret = app_manager_get_app_icon_path(def_obj[i].def_pkg_name, &imgpath);
+
+ if (ail_ret == APP_MANAGER_ERROR_NONE && imgpath) {
+ ad->result_obj[i].obj_icon_path = strdup(imgpath);
+ SEARCH_FREE(imgpath);
+}
+
+ /* Insert DB */
+ search_sql_bind_text(ad->search_db_hd, sql_insert, 1, ad->result_obj[i].name);
+ search_sql_bind_int(ad->search_db_hd, sql_insert, 2, ad->result_obj[i].string_type);
+ search_sql_bind_int(ad->search_db_hd, sql_insert, 3, ad->result_obj[i].visible);
+ search_sql_bind_int(ad->search_db_hd, sql_insert, 4, ad->result_obj[i].order);
+ search_sql_bind_int(ad->search_db_hd, sql_insert, 5, ad->result_obj[i].contents_type);
+ search_sql_bind_int(ad->search_db_hd, sql_insert, 6, ad->result_obj[i].category_type);
+ search_sql_bind_text(ad->search_db_hd, sql_insert, 7, ad->result_obj[i].def_pkg_name);
+
+ rc = sqlite3_step(sql_insert);
+
+ if( sql_insert != NULL )
+ search_sql_stmt_init(sql_insert);
+ }
+ } else {
+ /* Copy db data to structure */
+ for(i = 0; i < SEARCH_CONT_MAX && rc == SQLITE_ROW; ++i) {
+ char *name = (char *)sqlite3_column_text(sql_load, 0);
+ int string_type = sqlite3_column_int(sql_load, 1);
+ int visible = sqlite3_column_int(sql_load, 2);
+ int order = sqlite3_column_int(sql_load, 3);
+ int contents_type = sqlite3_column_int(sql_load, 4);
+ int category_type = sqlite3_column_int(sql_load, 5);
+ char *def_pkg_name = (char *)sqlite3_column_text(sql_load, 6);
+
+ ad->result_obj[i].order = order;
+ ad->result_obj[i].contents_type = contents_type;
+ ad->result_obj[i].string_type = string_type;
+ ad->result_obj[i].category_type = category_type;
+ ad->result_obj[i].name = ( name != NULL ) ? strdup(name): NULL;
+ ad->result_obj[i].visible = ( visible > 0 ) ? EINA_TRUE : EINA_FALSE;
+ ad->result_obj[i].def_pkg_name = ( def_pkg_name != NULL) ?
+ strdup(def_pkg_name) : NULL;
+
+ if (def_pkg_name) {
+ ail_ret = app_manager_get_app_icon_path(def_obj[i].def_pkg_name, &imgpath);
+
+ if (ail_ret == APP_MANAGER_ERROR_NONE && imgpath) {
+ ad->result_obj[i].obj_icon_path = strdup(imgpath);
+ SEARCH_FREE(imgpath);
+ }
+ }
+
+ rc = sqlite3_step(sql_load);
+ }
+ }
+
+ if( sql_load != NULL )
+ search_sql_stmt_init(sql_load);
+ if( sql_insert != NULL )
+ search_sql_stmt_init(sql_insert);
+
+ SEARCH_FUNC_END;
+ }
+
+static Evas_Object *__search_create_win(const char *name, void *data)
+ {
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ Evas_Object *eo;
+ int w, h;
+
+ SEARCH_RETV_IF(ad == NULL, NULL);
+
+ eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
+ elm_win_conformant_set(eo, EINA_TRUE);
+
+ if (eo) {
+ elm_win_title_set(eo, name);
+ evas_object_smart_callback_add(eo, "delete,request",
+ __search_win_delete_cb, ad);
+ ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
+ evas_object_resize(eo, w, h);
+ }
+
+ SEARCH_FUNC_END;
+
+ return eo;
+}
+
+static int __search_init_db_connect(struct appdata *ad)
+{
+ SEARCH_FUNC_START;
+
+ int rc = 0;
+ int ret = SEARCH_RET_FAIL;
+
+ SEARCH_RETV_IF(ad == NULL, SEARCH_RET_FAIL);
+
+ rc = db_util_open(SEARCH_DB_PATH,
+ &(ad->search_db_hd),
+ 0);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_ERROR
+ ("db_util_open error : %d (%s)\n",
+ rc, SEARCH_DB_PATH);
+ ret = SEARCH_RET_FAIL;
+ } else {
+ int i = 0;
+ const char *query_list[SEARCH_STMT_MAX] = { SEARCH_DB_SQL_GET_CATEGORY_LIST_ALL,
+ SEARCH_DB_SQL_INSERT_OBJECT_IFNO,
+ SEARCH_DB_SQL_UPDATE_OBJECT_INFO
+ };
+
+ for (i = SEARCH_STMT_GET_CATEGORY_LIST_ALL; i < SEARCH_STMT_MAX ; ++i ) {
+ SEARCH_DEBUG_LOG("query : %s\n", query_list[i]);
+
+ ret = search_sql_prepare_stmt(ad->search_db_hd, query_list[i],
+ &(ad->search_db_sql[i]));
+ }
+ }
+
+ SEARCH_FUNC_END;
+
+ return ret;
+}
+
+static void __search_deinit_db_connect(struct appdata *ad)
+ {
+ SEARCH_FUNC_START;
+
+ int i = 0, rc = 0;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ for (i = SEARCH_STMT_GET_CATEGORY_LIST_ALL; i < SEARCH_STMT_MAX ; ++i ) {
+ if (ad->search_db_sql[i]) {
+ search_sql_stmt_finalize(ad->search_db_sql[i]);
+ ad->search_db_sql[i] = NULL;
+ }
+ }
+
+ if (ad->search_db_hd) {
+ rc = db_util_close(ad->search_db_hd);
+ if (rc != SQLITE_OK) {
+ SEARCH_DEBUG_WARNING
+ ("db_util_close error : %d / %s",
+ rc, SEARCH_DB_PATH);
+ } else {
+ SEARCH_DEBUG_LOG("db_util_close success");
+ }
+ ad->search_db_hd = NULL;
+ } else {
+ SEARCH_DEBUG_WARNING("db_handle(%s) is null", SEARCH_DB_PATH);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static Eina_Bool __search_init_after_ui_create(gpointer data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RETV_IF(ad == NULL, ECORE_CALLBACK_CANCEL);
+
+ ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
+ __search_keydown_event,
+ ad);
+
+ ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
+ __search_mousedown_event,
+ ad);
+
+ __search_init_db_connect(ad);
+ __search_init_result_object(ad);
+
+ UG_INIT_EFL(ad->win_main, UG_OPT_INDICATOR_ENABLE);
+
+ SEARCH_FUNC_END;
+
+ return ECORE_CALLBACK_CANCEL;
+}
+
+
+static void __search_update_lang(void *data)
+{
+ SEARCH_FUNC_START;
+ struct appdata *ad = (struct appdata *)data;
+ int i = 0;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ /* Update Text for match to current language */
+ if (ad->navi_it)
+ elm_object_item_text_set(ad->navi_it,
+ dgettext("sys_string", "IDS_COM_BODY_SEARCH"));
+
+ if (ad->search_bar)
+ elm_object_part_text_set(ad->search_bar,
+ "elm.guidetext",
+ dgettext("sys_string", "IDS_COM_BODY_SEARCH"));
+ if (ad->noresult_view)
+ elm_object_part_text_set(ad->noresult_view,
+ "elm.text",
+ dgettext("sys_string", "IDS_COM_BODY_NO_SEARCH_RESULTS"));
+
+ if (ad->search_cancel_btn)
+ elm_object_text_set(ad->search_cancel_btn,
+ dgettext("sys_string",
+ "IDS_COM_SK_CANCEL"));
+
+ for (i = 0; i < SEARCH_CONT_MAX; i++) {
+ Elm_Object_Item *it = ad->result_obj[i].gl_result_grp;
+ const char *item_name = ad->result_obj[i].name;
+
+ if (it && item_name)
+ elm_genlist_item_fields_update(it, "elm.text", ELM_GENLIST_ITEM_FIELD_TEXT);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static bool __search_app_create(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ SEARCH_RETV_IF(ad == NULL, false);
+
+ ad->win_main = __search_create_win(SEARCH_PACKAGE, ad);
+ SEARCH_RETV_IF(ad->win_main == NULL, -1);
+
+ evas_object_show(ad->win_main);
+
+ ad->scale_factor = elm_config_scale_get();
+
+ __search_init_category_object(ad);
+ __search_init_smartsearch(ad);
+
+ ad->first_search = true;
+ ad->idler_create_ui = ecore_idler_add(__search_init_after_ui_create, ad);
+ evas_object_show(ad->win_main);
+
+ SEARCH_FUNC_END;
+
+ return true;
+}
+
+static void __search_app_terminate(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ int i = 0;
+
+ SEARCH_RET_IF(ad == NULL);
+
+ if (ad->layout_main) {
+ evas_object_del(ad->layout_main);
+ ad->layout_main = NULL;
+ }
+
+ if (ad->win_main) {
+ evas_object_del(ad->win_main);
+ ad->win_main = NULL;
+ }
+
+ if(ad->idler_create_ui)
+ ecore_idler_del(ad->idler_create_ui);
+
+ search_result_gl_deinit(ad);
+
+ search_app_disconnect(ad);
+ __search_deinit_db_connect(ad);
+
+ search_util_date_time_format_deinit();
+
+ for ( i = 0 ; i < SEARCH_CONT_MAX ; ++i ) {
+ SEARCH_FREE(ad->result_obj[i].name);
+ SEARCH_FREE(ad->result_obj[i].obj_icon_path);
+ SEARCH_FREE(ad->result_obj[i].def_pkg_name);
+ }
+
+ for ( i = 0 ; i < SEARCH_CATE_MAX ; ++i ) {
+ SEARCH_FREE(ad->category_info[i].btn_icon_path);
+ SEARCH_FREE(ad->category_info[i].btn_icon_press_path);
+ }
+
+ SEARCH_FREE(ad->search_word);
+ SEARCH_FREE(ad->not_markup_search_word);
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_app_pause(void *data)
+{
+ SEARCH_FUNC_START;
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_app_resume(void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+
+ if (ad->win_main) {
+ elm_object_focus_set(ad->back_btn, EINA_FALSE);
+ }
+
+ elm_genlist_select_mode_set(ad->search_gl, ELM_OBJECT_SELECT_MODE_DEFAULT);
+
+ if (elm_object_scroll_freeze_get(ad->search_gl) > 0) {
+ elm_object_scroll_freeze_pop(ad->search_gl);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_app_service(service_h service, void *data)
+{
+ SEARCH_FUNC_START;
+
+ struct appdata *ad = (struct appdata *)data;
+
+ char *query = NULL;
+ char *keyword = NULL;
+ char *operation = NULL;
+
+ Evas_Object *cate_icon;
+ int ret = 0;
+ char *icon_path = NULL;
+
+ ad->back_btn_type = BACK_BTN_TYPE_LOWER;
+ SEARCH_FREE(ad->search_word);
+
+ ret = service_get_operation(service, &operation);
+
+ if (ret != 0) {
+ SEARCH_DEBUG_WARNING("Cannot get operation!");
+ return;
+ }
+
+ if(operation == NULL ) {
+ SEARCH_DEBUG_WARNING("Operation is NULL!");
+ return;
+ }
+
+ SEARCH_DEBUG_LOG("SERVICE OPERATION TYPE : %s", operation);
+ if (SEARCH_STRCMP(operation, SERVICE_OPERATION_SEARCH) == 0) {
+ ret = service_get_extra_data(service, "http://tizen.org/appcontrol/data/keyword", &query);
+
+ if(ret != 0) {
+ SEARCH_DEBUG_WARNING("Fail to Get Keyword data!");
+ query = NULL;
+ }
+
+ if( (query) && (strlen(query) > 0) ) {
+ keyword = (char*)malloc(strlen(query)+1);
+ memset(keyword, 0x00, strlen(query)+1);
+ strncpy(keyword, query, strlen(query));
+ }
+
+ ad->search_category = SEARCH_CATE_PHONE;
+ ad->back_btn_type = BACK_BTN_TYPE_CLOSE;
+
+ } else {
+ /* If Operation type is not SEARCH, Initializae valute to default */
+ keyword = vconf_get_str(SMARTSEARCH_KEY_KEYWORD);
+
+ if (keyword == NULL)
+ SEARCH_DEBUG_WARNING("Error(%d) : get current key from vconf", ret);
+
+ ad->search_category = SEARCH_CATE_PHONE;
+ }
+
+ SEARCH_DEBUG_LOG("current category : %d", ad->search_category);
+
+ icon_path = ad->category_info[ad->search_category].btn_icon_path;
+ cate_icon = search_searchbar_category_icon_add(icon_path,
+ ad->sb_layout,
+ SEARCH_CATEGORY_BTN_ICON_SIZE_WIDTH,
+ SEARCH_CATEGORY_BTN_ICON_SIZE_HEIGHT,
+ false);
+ elm_object_content_set(ad->cate_btn, cate_icon);
+
+ /* set current category to vconf */
+ ad->search_category = SEARCH_CATE_PHONE;
+
+ if ((keyword) && (strlen(keyword) > 0)) {
+ elm_object_text_set(ad->search_entry, keyword);
+ } else {
+ SEARCH_DEBUG_LOG("keyword is NULL");
+
+ elm_object_text_set(ad->search_entry, "");
+ elm_object_signal_emit(ad->search_bar, "cancel,hide", "");
+
+ search_set_result_list(ad);
+
+ /* set focus to entry for launching ime */
+ evas_object_show(ad->search_entry);
+ elm_object_focus_set(ad->search_entry,EINA_TRUE);
+ elm_object_signal_emit(ad->search_bar, "cancel,in", "");
+ }
+
+ SEARCH_FREE(keyword);
+ SEARCH_FREE(operation);
+ SEARCH_FREE(query);
+
+ elm_entry_cursor_end_set(ad->search_entry);
+
+ if (ad->win_main)
+ elm_win_activate(ad->win_main);
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_app_device_orientation_cb(app_device_orientation_e orientation, void *data)
+{
+ SEARCH_FUNC_START;
+ struct appdata *ad = (struct appdata *)data;
+ SEARCH_RET_IF(ad == NULL);
+ SEARCH_RET_IF(ad->win_main == NULL);
+
+ if (orientation >= 0) {
+ elm_win_rotation_with_resize_set(ad->win_main, orientation);
+ }
+
+ SEARCH_FUNC_END;
+}
+
+static void __search_app_lang_change(void *data)
+{
+ SEARCH_FUNC_START;
+ struct appdata *ad = (struct appdata *)data;
+
+ __search_update_lang(ad);
+
+ SEARCH_FUNC_END;
+}
+
+int main(int argc, char *argv[])
+{
+ SEARCH_FUNC_START;
+
+ struct appdata ad;
+
+ int i = 0;
+
+ app_event_callback_s event_callback;
+
+ event_callback.create = __search_app_create;
+ event_callback.terminate = __search_app_terminate;
+ event_callback.pause = __search_app_pause;
+ event_callback.resume = __search_app_resume;
+ event_callback.service = __search_app_service;
+ event_callback.low_memory = NULL;
+ event_callback.low_battery = NULL;
+ event_callback.device_orientation = __search_app_device_orientation_cb;
+ event_callback.language_changed = __search_app_lang_change;
+ event_callback.region_format_changed = search_region_format_cb;
+
+ memset(&ad, 0x0, sizeof(struct appdata));
+
+ for (i = 0; i < argc; i++)
+ SEARCH_DEBUG_LOG("argv[%d] = [%s]\n", i, argv[i]);
+
+ SEARCH_FUNC_END;
+
+ return app_efl_main(&argc, &argv, &event_callback, &ad);
+}