4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <setting-cfg.h>
23 #include <setting-debug.h>
25 #include <Elementary.h>
26 #include <setting-common-general-func.h>
29 #define CFG_FILE_DIR_PATH "/opt/data/setting/"
30 #define CFG_FILE_PATH CFG_FILE_DIR_PATH"setting.cfg"
33 JsonNode* root; /* category_list */
35 char* setting_cfg_get_path()
40 int setting_cfg_file_write( JsonNode * node );
42 #define __create_an_item(item_name, icon_path, ug_args, defaultPos, is_resetable) do\
44 if (!is_ug_installed_by_ug_args(ug_args)) break;\
45 menu_item = json_node_new(JSON_NODE_OBJECT); \
46 object = json_object_new(); \
47 json_node_take_object(menu_item, object); \
48 json_object_set_string_member(object, "key_name", item_name); \
49 json_object_set_string_member(object, "icon_path", icon_path); \
50 json_object_set_string_member(object, "ug_args", ug_args); \
51 json_object_set_int_member(object, "pos", defaultPos); \
52 json_object_set_int_member(object, "click_times", 0); \
53 json_object_set_int_member(object, "is_resetable", is_resetable); \
54 json_array_add_element(menu, menu_item); \
57 #define __create_an_item_by_pkg(item_name, pkg_name, ug_args, defaultPos, is_resetable) do\
59 if (!is_ug_installed_by_ug_args(ug_args)) break;\
60 menu_item = json_node_new(JSON_NODE_OBJECT); \
61 object = json_object_new(); \
62 char* __temp_##item_name = get_icon_path(pkg_name); \
63 json_node_take_object(menu_item, object); \
64 json_object_set_string_member(object, "key_name", item_name); \
65 json_object_set_string_member(object, "icon_path", __temp_##item_name); \
66 json_object_set_string_member(object, "ug_args", ug_args); \
67 json_object_set_int_member(object, "pos", defaultPos); \
68 json_object_set_int_member(object, "click_times", 0); \
69 json_object_set_int_member(object, "is_resetable", is_resetable); \
70 json_array_add_element(menu, menu_item); \
71 free(__temp_##item_name); __temp_##item_name = NULL; \
75 #define __create_a_menu(menu_name)\
77 category = json_node_new( JSON_NODE_OBJECT );\
78 object = json_object_new();\
79 json_node_take_object ( category, object );\
80 json_object_set_string_member( object, "name", menu_name );\
81 menu = json_array_new();\
82 json_object_set_array_member( object, "menu", menu );\
83 json_array_add_element( json_node_get_array( category_list ), category );\
86 void setting_cfg_print( void )
88 JsonNode * node = root;
90 JsonGenerator *generator = json_generator_new ();
91 g_object_set( generator, "pretty", TRUE, NULL );
92 json_generator_set_root ( generator, node );
93 gchar *data = json_generator_to_data ( generator, NULL );
94 SETTING_TRACE( "%s", (char *)data );
97 g_object_unref(generator);
100 /* create config file from scratch */
101 int setting_cfg_create(void)
103 JsonNode *category_list, *category, *menu_item;
108 category_list = json_node_new (JSON_NODE_ARRAY);
109 json_node_take_array ( category_list, json_array_new () );
112 __create_a_menu(KeyStr_Connectivity);
114 __create_an_item(KeyStr_WiFi, IMG_WiFi, "wifi-efl-UG", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
115 __create_an_item(KeyStr_MobileAP, IMG_MobileAP, "setting-mobile-ap-ug", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
116 __create_an_item(KeyStr_Location, IMG_Location, "setting-location-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
117 __create_an_item(KeyStr_Network, IMG_Network, "setting-network-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
118 __create_an_item(KeyStr_Bluetooth, IMG_Bluetooth, "setting-bluetooth-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
119 __create_an_item(KeyStr_NFC, IMG_NFC, "setting-nfc-efl|type:nfc", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
121 #if SUPPORT_DATA_USAGE
122 __create_an_item(KeyStr_DataUsage, IMG_DataUsage, "setting-datausage-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
125 #if SUPPORT_WIFI_DIRECT
126 __create_an_item(KeyStr_WiFiDirect, IMG_WiFiDirect, "setting-wifidirect-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
130 __create_a_menu(KeyStr_System);
134 #if SUPPORT_WALLPAPER
135 /* kinds of wallpaper version.. */
136 __create_an_item(KeyStr_Wallpaper, IMG_Wallpaper, "setting-display-efl|viewtype:wallpaper", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
139 __create_an_item(KeyStr_Sounds, IMG_Sounds, "setting-profile-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
141 #if SUPPOR_SEPARATE_BRIGHTNESS
142 __create_an_item(KeyStr_Brightness, IMG_Brightness, "setting-display-efl|viewtype:brightness", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
146 __create_an_item(KeyStr_Security, IMG_Security, "setting-security-efl", Cfg_Item_Pos_Level0, Cfg_Item_Resetable);
149 #if SUPPORT_POWERSAVING
150 __create_an_item(KeyStr_Powersaving, IMG_Powersaving, "setting-powersaving-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
154 __create_an_item(KeyStr_Font, IMG_Font, "setting-font-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
157 __create_an_item(KeyStr_Display, IMG_Dispaly, "setting-display-efl|viewtype:main", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
158 #if SUPPORT_MENUSCREEN
159 __create_an_item(KeyStr_Menuscreen, IMG_Menuscreen, "setting-homescreen-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
161 __create_an_item(KeyStr_Landscape, IMG_Landscape, NULL, Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
162 __create_an_item(KeyStr_DateTime, IMG_DateTime, "setting-time-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
163 __create_an_item(KeyStr_LanguageRegion, IMG_DisplayLanguage, "setting-phone-efl|viewtype:language", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
164 __create_an_item(KeyStr_KeyboradLanguage, IMG_KeyboradLanguage, "isfsetting-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
167 __create_an_item(KeyStr_Storage, IMG_DefaultIcon, "setting-storage-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
169 __create_an_item(KeyStr_ManageApps, IMG_MANAGE_APPS, "setting-manage-applications-efl|viewtype:manage-applications", Cfg_Item_Pos_Level1,
172 #if SUPPORT_WEB_APPLICATION
173 __create_an_item(KeyStr_WebApps, IMG_Web_Apps, "webapp-common-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
176 #if SUPPORT_CERTIFICATES
177 __create_an_item(KeyStr_CertUI, IMG_MANAGE_APPS, "setting-manage-certificates-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
180 __create_an_item(KeyStr_Memory, IMG_Memory, "setting-memory-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
181 __create_an_item(KeyStr_Reset, IMG_Reset, "setting-reset-efl", Cfg_Item_Pos_Level1, Cfg_Item_unResetable);
182 __create_an_item(KeyStr_DeveloperOption, IMG_USBconnection, "setting-developeroption-efl|viewtype:usb", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
183 __create_an_item(KeyStr_AboutPhone, IMG_AboutPhone, "setting-about-efl", Cfg_Item_Pos_Level1, Cfg_Item_Resetable);
186 __create_a_menu(KeyStr_Applications);
188 __create_an_item(KeyStr_Call, IMG_Call, "setting-call-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
189 __create_an_item(KeyStr_Messages, IMG_Messages, "msg-setting-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
190 __create_an_item(KeyStr_Email, IMG_Email, "email-setting-efl|VIEW_TYPE:main-view", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
191 __create_an_item(KeyStr_Contacts, IMG_Contacts, "contacts-settings-efl|request_type:71", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
193 __create_an_item(KeyStr_Calendar, IMG_Calendar, "calendar-settings-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
195 __create_an_item(KeyStr_Gallery, IMG_Gallery, "setting-gallery-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
196 __create_an_item(KeyStr_VoiceRecorder, IMG_VoiceRecorder, "setting-voicerecorder-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
200 __create_an_item_by_pkg(KeyStr_FMRadio, "org.tizen.fm-radio", "setting-fmradio-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
201 SETTING_TRACE_DEBUG("Added FMRadio");
210 __create_an_item_by_pkg(KeyStr_NFC, "com.samsung.nfc-app", "setting-nfc-efl", Cfg_Item_Pos_Level0, Cfg_Item_unResetable);
214 __create_a_menu(KeyStr_DownloadedAPPs);
217 int ret = setting_cfg_file_write( category_list );
219 json_node_free( category_list );
226 int setting_cfg_file_read( void )
229 if (access( CFG_FILE_PATH, R_OK|F_OK ) !=0 )
231 SETTING_TRACE("file [%s] not legal, need to check your file-system.[%s:%d]\n", CFG_FILE_PATH, __FILE__, __LINE__);
232 //return Cfg_Error_Type_FilePermissionDenied;
236 parser = json_parser_new (); /* to be freed on exit */
239 GError *error = NULL;
240 gboolean ret = json_parser_load_from_file( parser, CFG_FILE_PATH, &error );
246 SETTING_TRACE_ERROR("error->message:%s", (char*)(error->message));
248 /* The file is existing and can be accessed normally, but it was
249 * loaded failed as a json script, it means setting.cfg is
250 * damaged(not the normal formatting ), we need to remove
251 * the file and recreate in next running time*/
252 SETTING_TRACE_ERROR("The file[%s] is existing and can be accessed "\
253 "normally, but it was loaded failed as a json "\
254 "script, it means setting.cfg is damaged (the "\
255 "formatting ia abnormal), we need to remove the"\
256 " file and recreate in next running time!",
259 SETTING_TRACE("Trying to removing the damaged file.");
260 if (remove(CFG_FILE_PATH) != 0)
262 SETTING_TRACE_ERROR("Error to remove the damaged file");
266 if( FALSE == setting_cfg_create() )
268 SETTING_TRACE_ERROR("Error to create a new config file");
271 /*if the failed is caused by reading the file recursively invoking */
272 return setting_cfg_file_read();
277 root = json_parser_get_root( parser ); /* to be freed on exit*/
282 * @brief dump JSON to file
284 int setting_cfg_file_write( JsonNode * node )
286 GError *error = NULL;
287 JsonGenerator *generator = json_generator_new ();
288 json_generator_set_root ( generator, node );
289 g_object_set( generator, "pretty", TRUE, NULL ); //write file in indent format
290 gboolean ret = json_generator_to_file( generator, CFG_FILE_PATH, &error );
291 g_object_unref(generator);
293 /* ***BEGIN*** DAC black screen SAMSUNG 2010/8/9 add
295 *chown -R inhouse:inhouse /home/inhouse/setting.cfg
299 SETTING_TRACE_ERROR("Error writing file %s!", CFG_FILE_PATH );
305 /* public functions */
307 int setting_cfg_init( void )
314 if (access( CFG_FILE_DIR_PATH, R_OK|W_OK|F_OK ) !=0 )
316 SETTING_TRACE_ERROR("dir [%s] not legal, need to check your file-system.[%s:%d]\n", CFG_FILE_DIR_PATH, __FILE__, __LINE__);
317 return Cfg_Error_Type_DirPermissionDenied;
319 if( stat(CFG_FILE_DIR_PATH, &st) != 0)/* to make more stable */
321 /* if (0 != system("sudo mkdir /opt/data/setting/")); */
322 /* if (EINA_TRUE != ecore_file_mkpath(CFG_FILE_DIR_PATH)); */
323 if (EINA_TRUE != ecore_file_mkdir(CFG_FILE_DIR_PATH));
326 return Cfg_Error_Type_Mkdir_Failed;
330 if( stat(CFG_FILE_PATH, &st) != 0)
332 SETTING_TRACE_ERROR("Config file doesn't exist. Create it!");
333 if( FALSE == setting_cfg_create() )
335 /* perror("setting_cfg_create"); */
336 return Cfg_Error_Type_CreateCfg_Failed;
338 stat(CFG_FILE_PATH, &st);
340 /* ***BEGIN*** error handle(caused by unstable file system) SAMSUNG 2010/9/10 add*/
341 else if (0 == st.st_size ||
342 0 != access( CFG_FILE_PATH, R_OK|F_OK ))
344 SETTING_TRACE("the %s is 0 Byte, we need to recreate it.", CFG_FILE_PATH);
345 /* delete the file */
346 if (remove(CFG_FILE_PATH) != 0)
349 return Cfg_Error_Type_RemoveCfg_Failed;
351 if( FALSE == setting_cfg_create() )
353 /* perror("setting_cfg_create"); */
354 return Cfg_Error_Type_CreateCfg_Failed;
358 /* ****END**** error handle(caused by unstable file system) SAMSUNG 2010/9/10 add
359 * cfg file exists but invalid -> re-create
360 * load file into parser
362 if( FALSE == setting_cfg_file_read() )
364 /* remove current setting file */
365 if (remove(CFG_FILE_PATH) != 0)
367 /* perror("remove"); */
368 return Cfg_Error_Type_RemoveCfg_Failed;
370 return Cfg_Error_Type_ReadCfg_Failed;
373 return Cfg_Error_Type_Sucess;
377 int setting_cfg_init( void )
381 if (!access(CFG_FILE_PATH, R_OK|W_OK|F_OK )) { // succeed to access
382 if(!setting_cfg_file_read()) { // return FALSE
383 if (remove(CFG_FILE_PATH)) {
384 return Cfg_Error_Type_RemoveCfg_Failed;
386 return Cfg_Error_Type_ReadCfg_Failed;
389 return Cfg_Error_Type_Sucess;
390 } else { // fail to access
392 // file non-existing case
394 SETTING_TRACE_ERROR("non-existing file/dir");
395 ecore_file_mkdir(CFG_FILE_DIR_PATH);
396 if (!setting_cfg_create()) { // return FALSE
397 SETTING_TRACE_ERROR("Error to create a new config file");
398 return Cfg_Error_Type_CreateCfg_Failed;
400 if(!setting_cfg_file_read() ) { // return FALSE
401 if (remove(CFG_FILE_PATH)) {
402 return Cfg_Error_Type_RemoveCfg_Failed;
404 return Cfg_Error_Type_ReadCfg_Failed;
407 return Cfg_Error_Type_Sucess;
412 return Cfg_Error_Type_DirPermissionDenied;
417 void setting_cfg_exit( void )
419 json_node_free(root);
420 g_object_unref (parser);
423 int setting_cfg_file_update( void )
425 if (access( CFG_FILE_PATH, W_OK|F_OK ) !=0 )
429 return setting_cfg_file_write( root );
432 int setting_cfg_get_category_length( void )
434 return json_array_get_length( json_node_get_array( root ) );
437 char* setting_cfg_get_category_name( int category_index )
439 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
440 return (char*)json_object_get_string_member( category_obj, "name" );
443 int setting_cfg_get_menu_length( int category_index )
445 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
446 JsonArray * menu = json_object_get_array_member( category_obj, "menu" );
447 return json_array_get_length( menu );
450 char * setting_cfg_get_keyname_idx( int category_index, int menu_index )
452 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
453 JsonArray * menu = json_object_get_array_member( category_obj, "menu" );
454 JsonObject * menu_item = json_array_get_object_element( menu, menu_index );
455 return (char*)json_object_get_string_member( menu_item, "key_name" );
458 char * setting_cfg_get_string_field_idx( int category_index, int menu_index, char *field_name)
460 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
461 JsonArray * menu = json_object_get_array_member( category_obj, "menu" );
462 JsonObject * menu_item = json_array_get_object_element( menu, menu_index );
464 char *data = (char *)json_object_get_string_member( menu_item, field_name );
465 if (!safeStrCmp(data, "(null)"))/* pass NULL to ug_args when create setting.cfg. */
472 int setting_cfg_get_int_field_idx( int category_index, int menu_index , char *field_name)
474 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
475 JsonArray * menu = json_object_get_array_member( category_obj, "menu" );
476 JsonObject * menu_item = json_array_get_object_element( menu, menu_index );
477 return json_object_get_int_member( menu_item, field_name );
480 char * setting_cfg_get_icon_path_idx( int category_index, int menu_index )
482 return setting_cfg_get_string_field_idx(category_index, menu_index, "icon_path");
485 char * setting_cfg_get_ug_args_idx( int category_index, int menu_index )
487 return setting_cfg_get_string_field_idx(category_index, menu_index, "ug_args");
490 char * setting_cfg_get_ugpath_idx( int category_index, int menu_index )
492 return setting_cfg_get_string_field_idx(category_index, menu_index, "ug_path");
495 char * setting_cfg_get_ugpath( char * keyname )
498 for( i = 0; i < setting_cfg_get_category_length(); i++ )
500 for( j = 0; j < setting_cfg_get_menu_length( i ); j++ )
502 if( safeStrCmp( setting_cfg_get_keyname_idx( i, j ), keyname ) == 0 )
503 return setting_cfg_get_ugpath_idx( i, j );
509 int setting_cfg_get_pos_idx( int category_index, int menu_index )
511 return setting_cfg_get_int_field_idx(category_index, menu_index, "pos");
514 int setting_cfg_get_pos( char * keyname )
517 for( i = 0; i < setting_cfg_get_category_length(); i++ )
519 for( j = 0; j < setting_cfg_get_menu_length( i ); j++ )
521 if( safeStrCmp( setting_cfg_get_keyname_idx( i, j ), keyname ) == 0 )
522 return setting_cfg_get_pos_idx( i, j );
528 void setting_cfg_set_pos_idx( int category_index, int menu_index, int pos )
530 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
531 JsonArray * menu = json_object_get_array_member( category_obj, "menu" );
532 JsonObject * menu_item = json_array_get_object_element( menu, menu_index );
533 json_object_remove_member( menu_item, "pos" );
534 json_object_set_int_member( menu_item, "pos", pos );
537 void setting_cfg_set_pos( char * keyname, int pos )
540 for( i = 0; i < setting_cfg_get_category_length(); i++ )
542 for( j = 0; j < setting_cfg_get_menu_length( i ); j++ )
544 if( safeStrCmp( setting_cfg_get_keyname_idx( i, j ), keyname ) == 0 )
546 setting_cfg_set_pos_idx( i, j, pos );
554 int setting_cfg_get_click_times_idx( int category_index, int menu_index )
556 return setting_cfg_get_int_field_idx(category_index, menu_index, "click_times");
559 int setting_cfg_get_click_times( char * keyname )
562 for( i = 0; i < setting_cfg_get_category_length(); i++ )
564 for( j = 0; j < setting_cfg_get_menu_length( i ); j++ )
566 if( safeStrCmp( setting_cfg_get_keyname_idx( i, j ), keyname ) == 0 )
567 return setting_cfg_get_click_times_idx( i, j );
573 void setting_cfg_set_click_times_idx( int category_index, int menu_index, int click_times )
575 JsonObject * category_obj = json_array_get_object_element( json_node_get_array( root ), category_index );
576 JsonArray * menu = json_object_get_array_member( category_obj, "menu" );
577 JsonObject * menu_item = json_array_get_object_element( menu, menu_index );
578 json_object_remove_member( menu_item, "click_times" );
579 json_object_set_int_member( menu_item, "click_times", click_times );
582 void setting_cfg_set_click_times( char * keyname, int click_times )
585 for( i = 0; i < setting_cfg_get_category_length(); i++ )
587 for( j = 0; j < setting_cfg_get_menu_length( i ); j++ )
589 if( safeStrCmp( setting_cfg_get_keyname_idx( i, j ), keyname ) == 0 )
591 setting_cfg_set_click_times_idx( i, j, click_times );
599 int setting_cfg_get_resetable_flag_idx(int category_index, int menu_index)
601 return setting_cfg_get_int_field_idx(category_index, menu_index,
605 void setting_cfg_add_downloaded_app( char *keyname, char *icon_path, char *ug_args, int pos)
612 for( i=0; i<setting_cfg_get_category_length(); i++ )
614 if( safeStrCmp( setting_cfg_get_category_name(i), "Downloaded App" ) == 0 )
616 menu_item = json_node_new( JSON_NODE_OBJECT );
617 object = json_object_new();
618 json_node_take_object ( menu_item, object );
619 json_object_set_string_member( object, "key_name", keyname );
620 json_object_set_string_member( object, "icon_path", icon_path );
621 json_object_set_string_member( object, "ug_args", ug_args );
622 json_object_set_int_member( object, "pos", pos );
624 object = json_array_get_object_element( json_node_get_array( root ), i );
625 menu = json_object_get_array_member( object, "menu" );
626 json_array_add_element( menu, menu_item );
631 void setting_cfg_remove_downloaded_app( char * keyname )
637 for( i = 0; i < setting_cfg_get_category_length(); i++ )
639 if( safeStrCmp( setting_cfg_get_category_name(i), "Downloaded App" ) == 0 )
641 for( j = 0; j < setting_cfg_get_menu_length( i ); j++ )
643 if( safeStrCmp( setting_cfg_get_keyname_idx( i, j ), keyname ) == 0 )
645 object = json_array_get_object_element( json_node_get_array( root ), i );
646 menu = json_object_get_array_member( object, "menu" );
647 json_array_remove_element( menu, j );
655 bool is_ug_installed_by_ug_args(void *data)
657 retv_if(!data, TRUE);//if passing NULL,drawing it
658 char* ug_args = data;
659 char *ug_name = get_ug_path_from_ug_args(ug_args);
661 bool is_installed_in_usr = false;
662 bool is_installed_in_opt = false;
664 //1.first do exist-checking in /usr/ug/lib
665 char ug_file[PATH_MAX + 1];
666 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH, ug_name);
668 if(stat(ug_file, &st) != 0) {
670 //2.if it does not exit in /usr/ug/lib, then do exist-checking in /usr/ug/lib
671 memset(ug_file, 0x00, PATH_MAX + 1);
672 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR, ug_name);
673 if(stat(ug_file, &st) != 0) {
674 //both not exist,skip it
675 SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
677 is_installed_in_usr = false;
680 is_installed_in_usr = true;
682 //2.first do exist-checking in /opt/ug/lib
683 //char ug_file[PATH_MAX + 1];
684 memset(ug_file, 0x00, PATH_MAX + 1);
685 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_OPT, ug_name);
687 if(stat(ug_file, &st) != 0) {
689 //2.if it does not exit in /usr/ug/lib, then do exist-checking in /usr/ug/lib
690 memset(ug_file, 0x00, PATH_MAX + 1);
691 snprintf(ug_file, PATH_MAX, "%s/libug-%s.so", SETTING_UG_PATH_USR_OPT, ug_name);
692 if(stat(ug_file, &st) != 0) {
693 //both not exist,skip it
694 SETTING_TRACE_ERROR(" libug-%s.so is *NOT* present, so skip it..\n", ug_name);
696 is_installed_in_opt = false;
699 is_installed_in_opt = true;
701 return (is_installed_in_opt || is_installed_in_opt);
704 /*other relative function*/
705 char *get_ug_path_from_ug_args(void *data)
707 /*SETTING_TRACE_BEGIN;*/
708 char *p = (char *)data;
709 if (NULL == p || '\0' == p[0]) {
713 char *q = strchr(p, '|');
716 if (q) { /* copy out the content before '|'; eg, ab|cd */
717 path = (char *)calloc(1, q - p + 1);
718 setting_retvm_if(!path, NULL, "calloc failed");
719 safeCopyStr(path, p, q - p);
720 /* redundant handle */
722 } else { /* copy out all the content. eg.abb */
724 path = (char *)calloc(1, safeStrLen(p) + 1);
725 setting_retvm_if(!path, NULL, "calloc failed");
726 safeCopyStr(path, p, safeStrLen(p));
728 /*SETTING_TRACE("get the ug['%s']", path);*/
732 service_h get_bundle_from_ug_args(void *data)
734 /*SETTING_TRACE_BEGIN;*/
735 char *p = (char *)data;
736 if (NULL == p || '\0' == p[0]) {
740 char *q = strchr(p, '|');
741 if (q) { /* (key, value) pairs exit. eg: ug_args = "sevenemail-setting-efl|caller:setting; cmd:main option" */
744 if (service_create(&svc))
746 int str_len = safeStrLen(p) + 1;
747 char *v_key = (char *)calloc(1, str_len);
749 service_destroy(svc);
753 char *v_value = (char *)calloc(1, str_len);
755 service_destroy(svc);
763 if (q) { /* not the last field */
764 m = strchr(p, ':'); /* ziduannei */
766 safeCopyStr(v_key, p, m - p);
769 safeCopyStr(v_value, m, q - m);
771 ("To add ('%s', '%s') to bundle data",
773 service_add_extra_data(svc, v_key, v_value);
776 ("invalid key-value format!!\n");
777 break; /* end the whole while */
779 } else { /* the last field */
781 m = strchr(p, ':'); /* ziduannei */
783 safeCopyStr(v_key, p, m - p);
785 safeCopyStr(v_value, m, safeStrLen(m));
787 service_add_extra_data(svc, v_key, v_value);
790 ("invalid key-value format!!\n");
792 break; /* end the whole while */
795 memset(v_key, '\0', str_len);
796 memset(v_value, '\0', str_len);
803 } else { /* eg: ug_args = "setting-browser-efl" */
805 /*SETTING_TRACE("(key, value) pairs not exit");*/