tizen 2.4 release
[apps/home/settings.git] / setting-common / src / setting-common-search.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18
19 #include <setting-common-search.h>
20 #include <unistd.h>
21 #include <eina_list.h>
22 #include <errno.h>
23 #include <glib.h>
24
25 #include <setting-debug.h>
26 #include <setting-cfg.h>
27 #include <setting-common-general-func.h>
28 #include <setting-common-draw-widget.h>
29
30 #include <dlfcn.h>
31
32 #define BUF_SIZE 512
33
34 /* search genlist */
35 static char *__search_label_get(void *data, Evas_Object *obj, const char *part);
36 static char *___add_tag_for_search(char *target, char *searcher);
37
38 static Evas_Object *__search_icon_get(void *data, Evas_Object *obj, const char *part);
39 static void __search_item_del(void *data, Evas_Object *obj);
40 static Evas_Object *__no_result_icon_get(void *data, Evas_Object *obj, const char *part);
41 /**
42  * [UI] search bar
43  * plain list item style
44  */
45
46 EXPORT_PUBLIC
47 const Elm_Genlist_Item_Class itc_no_reult = {
48         .item_style = "1icon/with_no_line",
49         .func.text_get = NULL,
50         .func.content_get = __no_result_icon_get,
51         .func.state_get = NULL,
52         .func.del = __search_item_del,
53 };
54
55 #define DEFINE_ITC2(style, name) \
56         EXPORT_PUBLIC const Elm_Genlist_Item_Class name = {\
57                                                            .item_style = style,\
58                                                            .func.text_get = __search_label_get,\
59                                                            .func.content_get = __search_icon_get,\
60                                                            .func.state_get = NULL,\
61                                                            .func.del = __search_item_del,\
62                                                           };
63
64 DEFINE_ITC2("dialogue/1text.1icon.3.tb", g_search_genlist_ts);
65 DEFINE_ITC2("dialogue/newset.1text.2icon.4.tb", g_search_genlist_ts_toggle);
66 DEFINE_ITC2("dialogue/newset.1text.2icon.4.divider.tb", g_search_genlist_ts_divided_toggle);
67
68 static
69 char *___add_tag_for_search(char *target, char *searcher)
70 {
71         const char *p = NULL;
72         const char *pre = NULL;
73         char buf[BUF_SIZE] = {0,};
74         char str_tag_added[BUF_SIZE] = {0,};
75
76         pre = target;
77         p = (const char *)strcasestr(pre, searcher);
78         if (p != NULL) {
79                 /* append characters before matched string */
80                 if (p != pre) {
81                         buf[0] = '\0';
82                         strncat(buf, pre, p - pre);
83                         sncat(str_tag_added, BUF_SIZE, buf);
84                 }
85                 /* highlight str */
86                 sncat(str_tag_added, BUF_SIZE, "<match>");
87                 buf[0] = '\0';
88                 strncat(buf, p, strlen(searcher));
89                 sncat(str_tag_added, BUF_SIZE, buf);
90                 sncat(str_tag_added, BUF_SIZE, "</match>");
91                 /* set pointer after matched string */
92                 pre = p + strlen(searcher);
93         }
94         sncat(str_tag_added, BUF_SIZE, pre);
95         return strdup(str_tag_added);
96 }
97
98
99
100
101
102 /**
103  * Callback function used for get label as member in genlist item
104  *
105  * @param[in]  data   data used for this function
106  * @param[in]  obj    object which caused this function
107  * @param[in]  part   part name of the label member in genlist item
108  * @return     pointer to content of label
109  */
110 static
111 char *__search_label_get(void *data, Evas_Object *obj, const char *part)
112 {
113         /*SETTING_TRACE_BEGIN; */
114         /*SETTING_TRACE("part : %s", part); */
115         ListItemObject *item = (ListItemObject *)data;
116
117         char buf[BUF_SIZE] = "";
118
119         char *tag_str = NULL;
120
121         retv_if(NULL == part, NULL);
122
123         if (!strcmp(part, "elm.text.1")) {
124                 snprintf(buf, BUF_SIZE, "%s", "elm.text.1");        /* print out test message */
125         } else if (!strcmp(part, "elm.text.2")) {
126                 snprintf(buf, BUF_SIZE, "%s", "elm.text.2");        /* print out test message */
127         } else if (!strcmp(part, "elm.text.3")) {
128                 snprintf(buf, BUF_SIZE, "%s", "elm.text.3");        /* print out test message */
129         } else if (!strcmp(part, "elm.text")) {
130 #if 0
131                 /*snprintf(buf, BUF_SIZE, "[%s] - %s", item->type, item->title);   // print out "[type] - title" */
132                 snprintf(buf, BUF_SIZE, "%s", item->title);   /* print out "[type] - title" */
133                 return strdup(buf);
134 #else
135                 /*tag_str = ___add_tag_for_search(item->title, g_ad->search_text); */
136                 tag_str = ___add_tag_for_search(item->title, "");
137                 snprintf(buf, BUF_SIZE, "%s", tag_str);   /* print out "[type] - title" */
138                 FREE(tag_str);
139                 return strdup(buf);
140 #endif
141         }
142         FREE(tag_str);
143         return strdup(buf);
144 }
145
146 /*--------------------------------------------------- */
147 /* wifi -> go to wifi after calling the set_state */
148 /* mock function */
149 /* do nothing */
150 /*--------------------------------------------------- */
151 static void ___toggle_chg_cb(void *data, Evas_Object *obj, void *event_info)
152 {
153         SETTING_TRACE_BEGIN;
154
155 }
156
157 static Evas_Object *__no_result_icon_get(void *data, Evas_Object *obj, const char *part)
158 {
159         SETTING_TRACE_BEGIN;
160         setting_retvm_if(!data || !obj, NULL, "!data || !obj");
161
162         if (!safeStrCmp(part, "elm.icon")) {
163                 Evas_Object *box = elm_box_add(obj);
164
165                 int rot = elm_win_rotation_get(obj);
166                 SETTING_TRACE_DEBUG("....change_ang:%d", rot);
167                 if (APP_DEVICE_ORIENTATION_0 == rot
168                     || APP_DEVICE_ORIENTATION_180 == rot) {
169                         /*b.separator.. */
170                         Evas_Object *separator = setting_create_blank_rect_customize(box, 1, 270);
171                         elm_box_pack_end(box, separator);
172                 }
173
174                 Evas_Object *sub_layout = elm_layout_add(obj);
175                 elm_layout_theme_set(sub_layout, "layout", "nocontents", "search");
176                 evas_object_size_hint_weight_set(sub_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177                 evas_object_size_hint_align_set(sub_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
178
179                 elm_object_part_text_set(sub_layout, "elm.text", _("IDS_ST_BODY_NO_RESULTS_FOUND"));
180                 setting_resize_object(sub_layout, 500, 500);
181                 evas_object_show(sub_layout);
182                 elm_box_pack_end(box, sub_layout);
183                 return box;
184         }
185
186         return NULL;
187 }
188
189 /**
190  * Get icon of given part in genlist item
191  *
192  * @param[in]  data   Data used in this function
193  * @param[in]  obj    Evas_Object who emit this event
194  * @param[in]  part   Name of the part in genlist item
195  *
196  * @return     NULL if meet error
197  *             Pointer to new icon
198  */
199 static
200 Evas_Object *__search_icon_get(void *data, Evas_Object *obj, const char *part)
201 {
202         /*SETTING_TRACE_BEGIN; */
203         retv_if(NULL == part, NULL);
204         ListItemObject *item = (ListItemObject *)data;
205
206         SETTING_TRACE(" genlist :: part : (%s) ", part);
207
208         retv_if(!item || !obj || !item->title, NULL);
209         if (!safeStrCmp(part, "elm.icon") || !safeStrCmp(part, "elm.icon.1")) {
210                 Evas_Object *icon = elm_icon_add(obj);
211
212                 char *icon_path = NULL;
213                 icon_path = IMG_SETTING;
214                 if (item->icon_path) {
215                         if (safeStrCmp(item->icon_path, "") == 0)
216                                 icon_path = IMG_SETTING;
217                         else
218                                 icon_path = item->icon_path;
219                 }
220                 /*SET//TING_TRACE("item->title:%s", item->title); */
221                 /*SETTING_TRACE("item->title2:%s", item->title2);       // plain text */
222                 /*SETTING_TRACE("item->iconpath:%s", icon_path);        // plain text */
223                 elm_image_file_set(icon, icon_path, NULL);
224                 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
225
226                 Evas_Object *ly_outer = elm_layout_add(obj);
227                 elm_layout_file_set(ly_outer, SETTING_THEME_EDJ_NAME, "nocontents");
228                 evas_object_show(ly_outer);
229
230                 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(63), ELM_SCALE_SIZE(63));
231                 evas_object_size_hint_max_set(icon, 63, 63);
232                 elm_object_part_content_set(ly_outer, "contents", icon);
233
234                 /*return icon; */
235                 return ly_outer;
236
237         } else if (!safeStrCmp(part, "elm.icon.2")) {
238                 Evas_Object *toggle = elm_check_add(obj);
239
240                 if (item->fp_check_btn_cb)
241                         evas_object_smart_callback_add(toggle, "changed", item->fp_check_btn_cb, item);
242                 else
243                         evas_object_smart_callback_add(toggle, "changed", ___toggle_chg_cb, item);
244
245                 /* get state------------------------------------- */
246                 /* if it is the 1'st depth item, get the pnode */
247                 /* display UG need to get the pointer */
248
249                 Setting_Cfg_Node_T *pnode = get_cfg_node_by_keystr(item->title2);
250
251                 Cfg_Item_State state = Cfg_Item_Error;
252                 if (pnode && pnode->tfunc && pnode->tfunc->get_item_state) {
253                         pnode->tfunc->get_item_state(&state, NULL);
254                 } else if (!pnode && item->viewname) {
255                         /* if get_cfg_node_by_keystr returns NULL, search for UG's keyword */
256                         int ret =  setting_search_get_module_item_state(item->title2, item->viewname, &state, NULL);
257                         SETTING_TRACE("---------------------------------------");
258                         SETTING_TRACE(" >>>  ret : %d, state : %d <<< ", ret, state);
259                         SETTING_TRACE("---------------------------------------");
260                 }
261
262                 if (state == Cfg_Item_On)
263                         elm_check_state_set(toggle, EINA_TRUE);
264                 else
265                         elm_check_state_set(toggle, EINA_FALSE);
266                 /* get state------------------------------------- */
267
268                 evas_object_propagate_events_set(toggle, 0);
269                 elm_object_style_set(toggle, "on&off");
270
271                 evas_object_pass_events_set(toggle, 1);
272
273                 evas_object_show(toggle);
274                 return toggle;
275         }
276
277         return NULL;
278 }
279
280 /**
281  * [UI] search bar
282  * used for genlist item style - callback function destroying an item of list
283  */
284 static
285 void __search_item_del(void *data, Evas_Object *obj)
286 {
287         /*SETTING_TRACE_BEGIN; */
288         ListItemObject *item = (ListItemObject *)data;
289         ret_if(!item);
290         FREE(item->title);
291         FREE(item->type);
292         FREE(item->infostr);
293         FREE(item->viewname);
294         FREE(item->fieldname);
295         FREE(item->icon_path);
296         __BACK_POINTER_UNSET(item); /*for pointer safety */
297         FREE(item);
298 }
299
300
301
302 static void sql_stmt(sqlite3 *db, const char *stmt)
303 {
304         char *errmsg;
305         int   ret;
306
307         ret = sqlite3_exec(db, stmt, 0, 0, &errmsg);
308         if (ret != SQLITE_OK) {
309                 SETTING_TRACE("Error in statement: %s [%s].", stmt, errmsg);
310         } else if (ret == SQLITE_OK) {
311                 SETTING_TRACE("OK running : (%s) --- [%s].", stmt, errmsg);
312         }
313 }
314
315 EXPORT_PUBLIC
316 int setting_searchdb_open(sqlite3 **ppdb)
317 {
318         SETTING_TRACE_BEGIN;
319         /*char *zErrMsg = NULL; */
320         int rc;
321         /*char query[512]; */
322         rc = sqlite3_open(SEARCH_DB_PATH, ppdb);
323         if (rc) {
324                 SETTING_TRACE_ERROR("Can't open database: %s", sqlite3_errmsg(*ppdb));
325                 sqlite3_close(*ppdb);
326                 return (-1);
327         } else {
328                 SETTING_TRACE("open database - OK - %d ", *ppdb);
329         }
330
331         return (0);
332 }
333
334 EXPORT_PUBLIC
335 void setting_searchdb_close(sqlite3 *db)
336 {
337         SETTING_TRACE_BEGIN;
338         sqlite3_close(db);
339 }
340
341 EXPORT_PUBLIC
342 void setting_add_db_search_clean(sqlite3 *db)
343 {
344         SETTING_TRACE_BEGIN;
345         sql_stmt(db, "BEGIN");
346         char *query = "DELETE FROM setting_search";
347
348         sql_stmt(db, query);
349         sql_stmt(db, "COMMIT");
350 }
351
352
353 /**
354 * @brief add index to DB
355 *
356 * @param db
357 * @param locale locale name (ko_KR, en_US ...)
358 * @param keystr string name (ex. Wi-Fi)
359 * @param infostr UG path, memta info, URL
360 * @param data_type 0, 1, 2, 3, 4 ... type
361 * @param viewname ""
362 * @param fieldname ""
363 * @param icon_path ""
364 */
365 EXPORT_PUBLIC
366 void setting_add_db_search_index(sqlite3 *db, char *locale, char *keystr, char *infostr, int data_type, char *viewname, char *fieldname, char *icon_path)
367 {
368         SETTING_TRACE_BEGIN;
369         sql_stmt(db, "BEGIN");
370         /*char query[1024]; */
371
372         /*snprintf(query, sizeof(query), "INSERT INTO setting_search VALUES (%Q, %Q, %Q, %d, NULL, %Q, %Q, %Q)", */
373         /*                      locale, fieldname, viewname, data_type, keystr, infostr, icon_path); */
374         char *query = sqlite3_mprintf("INSERT INTO setting_search VALUES (%Q, %Q, %Q, %d, NULL, %Q, %Q, %Q)",
375                                       locale, fieldname, viewname, data_type, keystr, infostr, icon_path);
376         sql_stmt(db, query);
377         sqlite3_free(query);
378         query = NULL;
379         sql_stmt(db, "COMMIT");
380 }
381
382 #if 1
383 EXPORT_PUBLIC
384 int setting_invoke_search_db_function(char *ug_name, app_control_h service, void *ext, char **ppapplocale)
385 {
386         SETTING_TRACE("Enter %s with ug_name:%s", __FUNCTION__, ug_name);
387         int (*search_plugin)(app_control_h pair, void **ptr, char **applocale);
388         int ret = OPERATE_LIB_SUCESS;
389
390         /*1.first do exist-checking in /opt/ug/lib */
391         char ug_file[PATH_MAX + 1];
392         snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
393         struct stat st;
394         if (stat(ug_file, &st) != 0) {
395
396                 /*2.if it does not exit in /opt/ug/lib, then do exist-checking in /usr/ug/lib */
397                 memset(ug_file, 0x00, PATH_MAX + 1);
398                 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
399                 if (stat(ug_file, &st) != 0) {
400                         /*both not exist,skip it */
401                         SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
402                         return OPERATE_LIB_SUCESS;
403                 }
404         }
405         /*------------------------------------------------------------------------------------- */
406         void *handle = dlopen(ug_file, RTLD_LAZY);
407         if (!handle) {
408                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
409                 return LOAD_LIB_FAILED;
410         }
411
412         char *error = NULL;
413         search_plugin = dlsym(handle, "setting_plugin_search_init");
414         if ((error = dlerror()) != NULL) {
415                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
416                 dlclose(handle);
417                 return UNDEFINED_LIB_SYMBOL;
418         }
419
420         if (search_plugin) {
421                 ret = (*search_plugin)(service, ext, ppapplocale);    /*  CALL */
422                 SETTING_TRACE(" after calling PLUGIN WITH -APP LOCALE ID = %s", *ppapplocale);
423         }
424         if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;/*from -2 on */
425
426         dlclose(handle);
427         return ret;
428 }
429 #endif
430
431
432 EXPORT_PUBLIC
433 int setting_search_set_module_item_state(char *keyword, char *ug_name, Cfg_Item_State item_state, cfg_func_table *pops)
434 {
435         SETTING_TRACE("Enter %s with ug_name:%s", __FUNCTION__, ug_name);
436         /* int setting_plugin_search_query_ops(char* str_id, void** tfunc_obj) */
437         int (*query_ops)(char *str_id, void **tfunc_obj);
438         int ret = OPERATE_LIB_SUCESS;
439
440         /*1.first do exist-checking in /opt/ug/lib */
441         char ug_file[PATH_MAX + 1];
442         snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
443         struct stat st;
444         if (stat(ug_file, &st) != 0) {
445
446                 /*2.if it does not exit in /opt/ug/lib, then do exist-checking in /usr/ug/lib */
447                 memset(ug_file, 0x00, PATH_MAX + 1);
448                 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
449                 if (stat(ug_file, &st) != 0) {
450                         /*both not exist,skip it */
451                         SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
452                         return OPERATE_LIB_SUCESS;
453                 }
454         }
455         /*------------------------------------------------------------------------------------- */
456         void *handle = dlopen(ug_file, RTLD_LAZY);
457         if (!handle) {
458                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
459                 return LOAD_LIB_FAILED;
460         }
461
462         char *error = NULL;
463         query_ops = dlsym(handle, "setting_plugin_search_query_ops");
464         if ((error = dlerror()) != NULL) {
465                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
466                 dlclose(handle);
467                 return UNDEFINED_LIB_SYMBOL;
468         }
469
470         if (query_ops && keyword) {
471                 /* OPS RETURNS NULL, IT'S PROBLEM */
472                 cfg_func_table *ops = NULL;
473                 /*ret = (*query_ops) ("MOCK_STR_ID", &ops);   */
474                 ret = (*query_ops)(keyword, (void **)&ops);   /*  CALL */
475                 SETTING_TRACE(" ops = %x ", ops);
476                 /*------------------------------------------------------------- */
477                 /* ACTUAL PROCESSING */
478                 /*------------------------------------------------------------- */
479                 if ((ops) && (ops)->set_item_state) {
480                         (ops)->set_item_state(item_state, NULL, NULL);
481                 }
482                 SETTING_TRACE(" ---> ppops.set_item_state(stat, NULL); -- after, sstat : %d", item_state);
483                 /*------------------------------------------------------------- */
484         }
485         if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;/*from -2 on */
486
487         dlclose(handle);
488         return ret;
489
490 }
491
492 #if 1
493 EXPORT_PUBLIC
494 int setting_search_get_module_item_state(char *keyword, char *ug_name, Cfg_Item_State *pstat, cfg_func_table *pops)
495 {
496         SETTING_TRACE("Enter %s with ug_name:%s", __FUNCTION__, ug_name);
497         /* int setting_plugin_search_query_ops(char* str_id, void** tfunc_obj) */
498         int (*query_ops)(char *str_id, void **tfunc_obj);
499         int ret = OPERATE_LIB_SUCESS;
500
501         /*1.first do exist-checking in /opt/ug/lib */
502         char ug_file[PATH_MAX + 1];
503         snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
504         struct stat st;
505         if (stat(ug_file, &st) != 0) {
506
507                 /*2.if it does not exit in /opt/ug/lib, then do exist-checking in /usr/ug/lib */
508                 memset(ug_file, 0x00, PATH_MAX + 1);
509                 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
510                 if (stat(ug_file, &st) != 0) {
511                         /*both not exist,skip it */
512                         SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
513                         return OPERATE_LIB_SUCESS;
514                 }
515         }
516         /*------------------------------------------------------------------------------------- */
517         void *handle = dlopen(ug_file, RTLD_LAZY);
518         if (!handle) {
519                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", dlerror());
520                 return LOAD_LIB_FAILED;
521         }
522
523         char *error = NULL;
524         query_ops = dlsym(handle, "setting_plugin_search_query_ops");
525         if ((error = dlerror()) != NULL) {
526                 SETTING_TRACE_ERROR(" >>>>>>>>>>> %s", error);
527                 dlclose(handle);
528                 return UNDEFINED_LIB_SYMBOL;
529         }
530
531         if (query_ops && keyword) {
532                 /* OPS RETURNS NULL, IT'S PROBLEM */
533                 cfg_func_table *ops = NULL;
534                 /*ret = (*query_ops) ("MOCK_STR_ID", &ops);   /*  CALL * / */
535                 ret = (*query_ops)(keyword, (void **)&ops);   /*  CALL */
536                 SETTING_TRACE(" ops = %x ", ops);
537                 /*------------------------------------------------------------- */
538                 /* ACTUAL PROCESSING */
539                 /*------------------------------------------------------------- */
540                 if ((ops) && (ops)->get_item_state)
541                         (ops)->get_item_state(pstat, NULL);
542
543                 SETTING_TRACE(" ---> ppops.get_item_state(pstat, NULL); -- after, pstat : %d", *pstat);
544                 /*------------------------------------------------------------- */
545         }
546         if (ret < 0) ret += UNDEFINED_LIB_SYMBOL;/*from -2 on */
547
548         dlclose(handle);
549         return ret;
550 }
551 #endif
552
553
554 EXPORT_PUBLIC
555 int __setting_init_search_index_module()
556 {
557
558         /* test, adding sql query */
559         sqlite3 *db = NULL;
560         setting_searchdb_open(&db);
561         SETTING_TRACE("search db = %d", db);
562
563         char *backup_langset =  vconf_get_str(VCONFKEY_LANGSET);
564         char *ug_name_arr[] = {
565                 "setting-display-efl",                                  /* finish */
566                 "setting-profile-efl",                                  /* finish */
567                 "setting-call-efl",                                             /* NO CODE !!! -- put  node here for testing */
568                 "setting-cloud-efl",                                    /*finish */
569                 "quickcommand-setting-efl",                             /* finish */
570                 "setting-mobileap-efl",                                 /* finish */
571                 "lockscreen-options",                                   /* finish */
572                 "email-setting-efl",                                    /* NO CODE !!! */
573                 "emergency-msg-setting-efl",                    /* NO CODE !!! */
574                 "msg-setting-efl",                                              /* NO CODE !!! */
575                 "setting-allshare-cast-efl",                    /* NO CODE !!! */
576                 "setting-allshare-efl",                                 /* NO CODE !!! */
577                 "setting-blockingmode-efl",                             /* NO CODE !!! */
578                 /*"ug-bluetooth-efl", */
579                 "setting-dock-efl",                                             /* NO CODE !!! */
580                 "setting-drivingmode-efl",                              /* NO CODE !!! */
581                 "setting-gallery-efl",                                  /* NO CODE !!! */
582                 "setting-homescreen-efl",                               /* NO CODE !!! */
583                 "setting-ledindicator-efl",                             /* NO CODE !!! */
584                 "setting-location-efl",                                 /* NO CODE !!! */
585                 "setting-manage-applications-efl",              /* NO CODE !!! */
586                 "setting-manage-certificates-efl",              /* NO CODE !!! */
587                 "setting-myaccount-efl",                                /* NO CODE !!! */
588                 "setting-phone-efl",                                    /* NO CODE !!! */
589                 "setting-readytoshare-efl",                             /* NO CODE !!! */
590                 "setting-synchronise-efl",                              /* NO CODE !!! */
591                 "wifi-efl-UG",                                                  /* NO CODE !!! */
592                 "setting-wifidirect-efl",                               /* NO CODE !!! */
593                 "worldclock-efl"                                                /* NO CODE !!! */
594                 "setting-nfc-efl",                                              /* NO CODE !!! */
595                 "setting-font-efl",                                             /* NO CODE !!! */
596                 "quickpanel-setting-efl",                               /* NO CODE !!! */
597                 "setting-easymode-efl",                                 /* NO CODE !!! */
598                 "setting-accessibility-efl",                    /* NO CODE !!! */
599                 "setting-personalpage-efl",                             /* NO CODE !!! */
600                 "setting-voice-efl",                                    /* NO CODE !!! */
601                 "setting-motion-efl",                                   /* NO CODE !!! */
602                 "setting-palmmotion-efl",                               /* NO CODE !!! */
603                 "setting-time-efl",                                             /* NO CODE !!! */
604                 "setting-accessory-efl",                                /* NO CODE !!! */
605                 "setting-powersaving-efl",                              /* NO CODE !!! */
606                 "setting-storage-efl",                                  /* NO CODE !!! */
607                 "setting-security-efl",                                 /* NO CODE !!! */
608                 "setting-privacy-efl",                                  /* NO CODE !!! */
609                 "isfsetting-efl",                                       /* NO CODE !!! */
610                 "setting-developeroption-efl",                  /* NO CODE !!! */
611                 "setting-about-efl",                                            /* NO CODE !!! */
612                 "setting-network-efl",                          /*finish */
613                 "setting-datausage-efl",
614                 "setting-fingerscanner-efl",
615                 "setting-vpn-efl",
616         };
617
618         int i;
619         for (i = 0; i < sizeof(ug_name_arr) / sizeof(ug_name_arr[0]); i++) {
620                 /*SETTING_TRACE("---------> UG NAME : %s", ug_name_arr[i]); */
621                 int ret = -1;
622                 Eina_List *plist = NULL;
623                 Setting_Cfg_Node_T *n = calloc(1, sizeof(Setting_Cfg_Node_T));
624                 if (n) {
625                         n->key_name = strdup("Sentinal");
626                         plist = eina_list_append(plist, n);
627                 }
628
629                 char *domainname = NULL;
630                 ret =  setting_invoke_search_db_function(ug_name_arr[i], NULL, &plist, &domainname);
631                 if (ret != OPERATE_LIB_SUCESS) {
632                         SETTING_TRACE_ERROR(" no plugin -- code : %s : %d ", ug_name_arr[i], ret);
633                         continue;
634                 } else {
635                         /*SETTING_TRACE(" return : %d", ret); */
636                         SETTING_TRACE(" plugin -- code : %s O.K : %d ", ug_name_arr[i], ret);
637                 }
638
639                 if (!domainname) {
640                         SETTING_TRACE_ERROR("domainname == NULL, it's error by plugin, not go next");
641                         Eina_List *l = NULL;
642                         Setting_Cfg_Node_T *node = NULL;
643                         /*int count = 0; */
644                         EINA_LIST_FOREACH(plist, l, node) {
645                                 FREE(node->key_name);
646                                 FREE(node->ug_args);
647                                 FREE(node->icon_path);
648                                 FREE(node->data);
649                                 FREE(node);
650                         }
651                         eina_list_free(plist);
652                         plist = NULL;
653                         FREE(domainname);
654                         continue;
655                 }
656                 char *p = strchr(domainname, ':');
657
658                 char *domain_appname = NULL;
659 #if 1
660                 if (p) {
661                         domain_appname = strtok(domainname, ":");
662                         SETTING_TRACE("p1:appname : %s\n", domain_appname);
663                         SETTING_TRACE("p2:localedir : %s\n", p + 1);
664                         /* set */
665                         setting_set_i18n(domain_appname, p + 1);
666                 } else {
667                         domain_appname = domainname;
668                         /* default locale */
669                         setting_set_i18n(domain_appname, "/usr/ug/res/locale");
670                 }
671 #endif
672
673                 /* test */
674                 Eina_List *langlist = setting_get_language_list2(LANGLIST_ALL_FILE_PATH);
675
676                 Eina_List *elist = NULL;
677                 setting_lang_entry *pnode = NULL;
678                 char *locale = NULL;
679                 EINA_LIST_FOREACH(langlist, elist, pnode) {
680                         locale = pnode->locale;
681
682                         char str[256];
683                         snprintf(str, 256, "%s.UTF-8", locale);
684                         (void)setlocale(LC_MESSAGES, str);
685
686                         /*-------------------------------------------------------------- */
687                         SETTING_TRACE(" (locale : %s) --------- BEFORE EINA LOOP : %x ", locale, plist);
688                         /* loop and print */
689                         Eina_List *l = NULL;
690                         Setting_Cfg_Node_T *node = NULL;
691                         int count = 0;
692                         EINA_LIST_FOREACH(plist, l, node) {
693                                 if (count != 0) {
694 #if 0
695                                         SETTING_TRACE(" key_name : %s", node->key_name);
696                                         SETTING_TRACE(" ug_args : %s", node->ug_args);
697                                         SETTING_TRACE(" icon_path : %s", node->icon_path);
698
699                                         SETTING_TRACE(" pos : %d", node->pos);
700                                         SETTING_TRACE(" reset_type : %d", node->reset_type);
701                                         SETTING_TRACE(" click_times : %d", node->click_times);
702                                         SETTING_TRACE(" item_type : %d", node->item_type);
703                                         SETTING_TRACE(" data : %x", node->data);
704                                         SETTING_TRACE(" -----------------------------");
705 #else
706                                         SETTING_TRACE(" add DB :: key_name : %s", node->key_name);
707
708
709                                         char *subindex = (node->sub_index) ? node->sub_index : "";
710                                         char *icon_path = (node->icon_path) ? node->icon_path : "";
711
712                                         setting_add_db_search_index(db, locale, __(node->key_name, domain_appname), node->ug_args, node->item_type, ug_name_arr[i], __(subindex, domain_appname), icon_path);
713 #endif
714                                 }
715                                 count++;
716                         }
717                         /*SETTING_TRACE(" --------- AFTER EINA LOOP "); */
718
719                 } /* locale - LOOP */
720
721                 /*free the list */
722                 Eina_List *l = NULL;
723                 Setting_Cfg_Node_T *node = NULL;
724
725                 EINA_LIST_FOREACH(plist, l, node) {
726                         FREE(node->key_name);
727                         FREE(node->ug_args);
728                         FREE(node->icon_path);
729                         FREE(node->data);
730                         FREE(node->sub_index);
731                         FREE(node);
732                 }
733                 eina_list_free(plist);
734                 plist = NULL;
735                 FREE(domainname);
736                 /*-------------------------------------------------------------- */
737         }       /* end of for loop */
738
739
740         /* roll back */
741         (void)setlocale(LC_MESSAGES, backup_langset);
742         setting_searchdb_close(db);
743
744         return 0;
745 }
746
747 EXPORT_PUBLIC
748 int __setting_init_search_index_app()
749 {
750         /* test, adding sql query */
751         sqlite3 *db = NULL;
752         setting_searchdb_open(&db);
753         SETTING_TRACE("search db = %d", db);
754
755         /* clean all entries */
756         setting_add_db_search_clean(db);
757
758         /* add index for testing */
759         Setting_Cfg_Node_T *pitem = get_cfg_node_first();       /* head */
760         int size = get_cfg_array_size();
761         SETTING_TRACE(" size of array : %d ", size);
762
763         char *locale = NULL;
764         char *backup_langset =  vconf_get_str(VCONFKEY_LANGSET);
765
766         /* get langlist // load language table from XML file */
767         Eina_List *elist = NULL;
768         setting_lang_entry *pnode = NULL;
769         Eina_List *langlist = setting_get_language_list2(LANGLIST_ALL_FILE_PATH);
770
771         EINA_LIST_FOREACH(langlist, elist, pnode) {
772                 /*SETTING_TRACE(" locale = %s --- language = %s --- mcc = %s ", pnode->locale, pnode->title, pnode->mcc); */
773                 locale = pnode->locale;
774
775                 char str[256];
776                 snprintf(str, 256, "%s.UTF-8", locale);
777                 (void)setlocale(LC_MESSAGES, str);
778
779                 int i;
780                 for (i = 0; i < size; i++) {
781                         /*SETTING_TRACE(" index : %d ", i); */
782                         char *subindex = (pitem[i].sub_index) ? _(pitem[i].sub_index) : "";
783                         char *icon_path = (pitem[i].icon_path) ? pitem[i].icon_path : "";
784                         if (pitem[i].item_type == Cfg_Item_Title_Node) {
785
786                                 setting_add_db_search_index(db, locale, _(pitem[i].key_name), pitem[i].ug_args, pitem[i].item_type/*title in Genlist*/, "", subindex, icon_path);
787
788                         } else if (pitem[i].item_type == Cfg_Item_Ug_Node
789                                    || pitem[i].item_type == Cfg_Item_Ug_Node_Toggle
790                                    || pitem[i].item_type == Cfg_Item_AppLauncher_Node
791                                    || pitem[i].item_type == Cfg_Item_AppLauncher_Node_Toggle
792                                   ) {
793
794                                 if (pitem[i].key_name && _(pitem[i].key_name)) {
795                                         setting_add_db_search_index(db, locale, _(pitem[i].key_name), pitem[i].ug_args, pitem[i].item_type/*UG name*/, "", subindex, icon_path);
796                                 }
797                         } else if (pitem[i].item_type == Cfg_Item_App_Node) {
798
799                                 if (pitem[i].key_name && _(pitem[i].key_name)) {
800                                         setting_add_db_search_index(db, locale, _(pitem[i].key_name), pitem[i].ug_args, pitem[i].item_type/*App Launching*/, "", subindex, icon_path);
801                                 }
802                         } else if (pitem[i].item_type == Cfg_Item_Ui_Node
803                                    || pitem[i].item_type == Cfg_Item_Ui_Node_Toggle
804                                   ) {
805
806                                 setting_add_db_search_index(db, locale, _(pitem[i].key_name), pitem[i].ug_args, pitem[i].item_type/*UI type*/, "", subindex, icon_path);
807                         }
808                 }
809
810         }
811         /* roll back */
812         (void)setlocale(LC_MESSAGES, backup_langset);
813         setting_searchdb_close(db);
814         return 0;
815 }