summaryrefslogtreecommitdiff
path: root/src/smartsearch.cpp
diff options
context:
space:
mode:
authorHyungKyu Song <hk76.song@samsung.com>2013-02-16 00:00:57 +0900
committerHyungKyu Song <hk76.song@samsung.com>2013-02-16 00:00:57 +0900
commitcc411fe3142413dc1341ad4d074d9596cd8bf3ef (patch)
tree13492e8870c607304fe4e80abae5cf49efc10bf9 /src/smartsearch.cpp
parent636878b6968ffd73d0fee4722d992ecb47e9f3a4 (diff)
downloadsmartsearch-cc411fe3142413dc1341ad4d074d9596cd8bf3ef.tar.gz
smartsearch-cc411fe3142413dc1341ad4d074d9596cd8bf3ef.tar.bz2
smartsearch-cc411fe3142413dc1341ad4d074d9596cd8bf3ef.zip
Diffstat (limited to 'src/smartsearch.cpp')
-rwxr-xr-xsrc/smartsearch.cpp816
1 files changed, 816 insertions, 0 deletions
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);
+}