/* * Copyright 2012 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://www.tizenopensource.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. */ #ifndef UG_MODULE_API #define UG_MODULE_API __attribute__ ((visibility("default"))) #endif #include #include #include #include #include #include #include "setting-theme-efl.h" static Evas_Object *_parent = NULL; static Elm_Genlist_Item_Class itc, itc2, edit_mode_itc; static Eina_List *gtheme_list = NULL; static Evas_Object *rdg = NULL; struct ug_down_theme_property { int ext; char name[SETTING_THEME_NAME_MAX_LEN]; }; struct ug_theme_list { struct ug_down_theme_property icon_theme; struct ug_down_theme_property boot_ani_theme; struct ug_down_theme_property key_snd_theme; struct ug_down_theme_property efl_theme; struct ug_down_theme_property gtk_theme; struct ug_down_theme_property screen_image_theme; struct ug_down_theme_property font_theme; struct ug_down_theme_property vibrate_theme; }; typedef enum { THEME_TYPE_DEFAULT, THEME_TYPE_DOWNLOAD, } ug_theme_type; struct ug_theme_info { ug_theme_type type; char* name; }; typedef struct _Item_Data Item_Data; typedef struct _View_Data View_Data; struct _View_Data { Evas_Object *bg; Evas_Object *nf; Evas_Object *box; Evas_Object *delete_btn; // 'Delete'/'Cancel' button Evas_Object *more_btn; Evas_Object *cbar; Elm_Object_Item *del_btn_item; // 'Delete' button Evas_Object *genlist; Elm_Object_Item *renamed_it; Evas_Object *select_all_layout; Evas_Object *select_all_checkbox; Eina_Bool select_all_checked; int total_count; int checked_count; int default_theme_count; }; struct _Item_Data { Elm_Object_Item *it; // Genlist Item pointer Eina_Bool checked; // Check status char *label; int idx; }; struct ug_data { Evas_Object *base; Eina_List *theme_list; struct ui_gadget *ug; struct ug_theme_list theme; View_Data *vd; }; static Evas_Object* _create_layout_main( Evas_Object* parent, View_Data* vd ) { Evas_Object *layout = elm_layout_add( parent ); if( layout == NULL ) return NULL; elm_layout_theme_set( layout, "layout", "application", "default" ); evas_object_size_hint_weight_set( layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); //Background Evas_Object *bg = elm_bg_add( layout ); vd->bg = bg; if ( bg ) { elm_object_style_set( bg, "group_list"); evas_object_size_hint_weight_set( bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND ); elm_object_part_content_set( layout, "elm.swallow.bg", bg ); } evas_object_show( layout ); return layout; } static void _setting_theme_def_response_cb( void *data, Evas_Object *obj, void *event_info ) { evas_object_del(obj); } static void _block_clicked_cb(void *data, Evas_Object *obj, void *event_info) { // Popup remove code...ex /*if (conformant) { evas_object_del(conformant); conformant = NULL; } if (del_timer) { ecore_timer_del(del_timer); del_timer = NULL; } evas_object_del(obj);*/ } static int _load_index_file(struct ug_data* ugd, struct ug_theme_info* selected_theme) { FILE* fp = NULL; Eina_Strbuf* temp_str_buf = eina_strbuf_new(); Eina_List *index_list = NULL; Eina_List *elist = NULL; char* meta_theme = NULL; eina_strbuf_append_printf( temp_str_buf, "%s/%s/%s", DOWNLOAD_THEME_FOLDER_PATH, selected_theme->name, DOWNLOAD_THEME_INDEX_FILE_NAME); if( !( fp = fopen( eina_strbuf_string_steal( temp_str_buf ), "r" ) ) ) { //make error popup : file not found Evas_Object *popup = elm_popup_add( ugd->base ); if( popup == NULL ) { eina_strbuf_free(temp_str_buf); return -1; } //TODO: Apply Strings to Multi Languange elm_object_text_set( popup, _("No Theme Contents") ); evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb, NULL); elm_popup_timeout_set( popup, POPUP_ALERT_TIMOUT_DURATION ); evas_object_smart_callback_add( popup, "response", _setting_theme_def_response_cb, NULL ); evas_object_show( popup ); eina_strbuf_free(temp_str_buf); return -1; } // Read File while( !feof( fp ) ) { char temp_buffer[ SETTING_THEME_NAME_MAX_LEN ] = {0,}; fgets( temp_buffer, SETTING_THEME_NAME_MAX_LEN, fp ); index_list = eina_list_append( index_list, strdup(temp_buffer)); } fclose(fp); // Parsing EINA_LIST_FOREACH( index_list, elist, meta_theme ) { char *ptr; char *meta = strtok_r( meta_theme, "=", &ptr); if(meta) { char *theme = strtok_r( NULL, "\n", &ptr); if( theme == NULL ) continue; if( !strncmp( DOWNLOAD_THEME_ICON_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_ICON_THEME_KEYWORD)) ) { ugd->theme.icon_theme.ext = 1; strncpy(ugd->theme.icon_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_BOOT_ANIMATOR_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_BOOT_ANIMATOR_THEME_KEYWORD)) ) { ugd->theme.boot_ani_theme.ext = 1; strncpy(ugd->theme.boot_ani_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_KEY_SOUND_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_KEY_SOUND_THEME_KEYWORD )) ) { ugd->theme.key_snd_theme.ext = 1; strncpy(ugd->theme.key_snd_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_EFL_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_EFL_THEME_KEYWORD ) ) ) { ugd->theme.efl_theme.ext = 1; strncpy(ugd->theme.efl_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_GTK_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_GTK_THEME_KEYWORD ) ) ) { ugd->theme.gtk_theme.ext = 1; strncpy(ugd->theme.gtk_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_SCREEN_IMG_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_SCREEN_IMG_THEME_KEYWORD ) ) ) { ugd->theme.screen_image_theme.ext = 1; strncpy(ugd->theme.screen_image_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_FONT_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_FONT_THEME_KEYWORD )) ) { ugd->theme.font_theme.ext = 1; strncpy(ugd->theme.font_theme.name,theme,strlen(theme)); } else if( !strncmp( DOWNLOAD_THEME_VIBRATION_THEME_KEYWORD, meta, strlen( DOWNLOAD_THEME_VIBRATION_THEME_KEYWORD )) ) { ugd->theme.vibrate_theme.ext = 1; strncpy(ugd->theme.vibrate_theme.name,theme,strlen(theme)); } } } // clear eina_strbuf_free(temp_str_buf); EINA_LIST_FOREACH( index_list, elist, meta_theme ) { index_list = eina_list_remove( index_list, meta_theme ); free( meta_theme ); } return 0; } static Evas_Object* _create_naviframe( Evas_Object* parent ) { if( parent == NULL ) return NULL; Evas_Object *nf = elm_naviframe_add( parent ); evas_object_show( nf ); return nf; } static void _remove_files_in_dir( const char *folder_path ) { struct stat statbuf; char path_buf[ PATH_MAX ]; DIR* dp = NULL; struct dirent *entry = NULL; char *mime = NULL; char *splitter = NULL; char *env = getenv( "UI_IDLECAPTURE_IMG_TYPE" ); if( !env ) { return ; } dp = opendir( folder_path ); if( dp == 0 ) { return ; } if( chdir( folder_path ) != 0 ) { fprintf( stderr, "Failed to change directory!\n" ); } while( ( entry = readdir( dp ) ) != NULL ) { stat( entry->d_name, &statbuf ); strcpy( path_buf, folder_path ); if( path_buf[ strlen( path_buf ) - 1 ] != '/' ) { strcat( path_buf, "/" ); } strcat( path_buf, entry->d_name ); //case of directory if( S_ISDIR( statbuf.st_mode ) ) { if( strcmp( ".", entry->d_name ) == 0 || strcmp( "..", entry->d_name ) == 0 ) { continue; } _remove_files_in_dir( path_buf ); continue; //case of file }else { //Check is it jpeg type. mime = (char *) efreet_mime_type_get( path_buf ); if( mime == 0 ) { continue; } while( (splitter = strpbrk( mime, "/" )) ) { if( strncmp( mime, env, splitter - mime ) == 0 ) { unlink( path_buf ); continue; }else { mime = ++splitter; } } if( strncmp( mime, env, strlen( mime ) ) == 0 ) { unlink( path_buf ); } } } if( chdir( ".." ) != 0 ) { fprintf( stderr, "Failed to change directory!\n" ); } closedir( dp ); } static int _strncmp( const char *s1, const char *s2) { const char *longer = NULL; const char *shorter = NULL; if( strlen( s1 ) > strlen ( s2 ) ) { longer = s1; shorter = s2; } else { longer = s2; shorter = s1; } return strncmp( longer, shorter, strlen( longer ) ); } static void _get_default_theme_list( const char *folder_path, Eina_List **theme_list ) { struct stat statbuf; char path_buf[ PATH_MAX ]; DIR* dp = NULL; struct dirent *entry = NULL; dp = opendir( folder_path ); if( dp == 0 ) { return ; } if( chdir( folder_path ) != 0 ) { fprintf( stderr, "Failed to change directory!\n" ); } while( ( entry = readdir( dp ) ) != NULL ) { stat( entry->d_name, &statbuf ); strcpy( path_buf, folder_path ); if( path_buf[ strlen( path_buf ) - 1 ] != '/' ) { strcat( path_buf, "/" ); } strcat( path_buf, entry->d_name ); //case of directory if( S_ISDIR( statbuf.st_mode ) ) { if( strcmp( ".", entry->d_name ) == 0 || strcmp( "..", entry->d_name ) == 0 ) { continue; } _get_default_theme_list( path_buf, theme_list ); continue; //case of file }else { //TODO: TEMPORARY COMPARE. SHOULD BE REMOVED! if( !_strncmp( entry->d_name, "tizen.edj") || !_strncmp( entry->d_name, "tizen-black.edj") || !_strncmp( entry->d_name, "default.edj") || !_strncmp( entry->d_name, "default-desktop.edj") ) { continue; } struct ug_theme_info *new_info = (struct ug_theme_info*)calloc(1,sizeof(struct ug_theme_info)); new_info->type = THEME_TYPE_DEFAULT; new_info->name = strndup(entry->d_name, strpbrk( entry->d_name, ".") - entry->d_name ); *theme_list = eina_list_append( *theme_list, new_info ); } } if( chdir( ".." ) != 0 ) { fprintf( stderr, "Failed to change directory!\n" ); } closedir( dp ); } static void _get_theme_list( const char *folder_path, Eina_List **theme_list ) { struct stat statbuf; char path_buf[ PATH_MAX ]; DIR* dp = NULL; struct dirent *entry = NULL; dp = opendir( folder_path ); if( dp == 0 ) { return ; } if( chdir( folder_path ) != 0 ) { fprintf( stderr, "Failed to change directory!\n" ); } while( ( entry = readdir( dp ) ) != NULL ) { stat( entry->d_name, &statbuf ); strcpy( path_buf, folder_path ); if( path_buf[ strlen( path_buf ) - 1 ] != '/' ) { strcat( path_buf, "/" ); } strcat( path_buf, entry->d_name ); //in case of directory, add folder name to list. if( S_ISDIR( statbuf.st_mode ) ) { if( strcmp( ".", entry->d_name ) == 0 || strcmp( "..", entry->d_name ) == 0 ) { continue; } struct ug_theme_info *new_info = (struct ug_theme_info*)calloc(1,sizeof(struct ug_theme_info)); new_info->type = THEME_TYPE_DOWNLOAD; new_info->name = strdup(entry->d_name); *theme_list = eina_list_append( *theme_list, new_info); } } closedir( dp ); } static int _selected_theme_idx_get() { Eina_List *elist = NULL; struct ug_theme_info *theme_info = NULL; // set selected theme char *theme_name = vconf_get_str(SETTING_THEME_SELECTED_THEME); int idx = 0; EINA_LIST_FOREACH( gtheme_list, elist, theme_info ) { if( _strncmp( theme_info->name, theme_name ) == 0 ) { FREE(theme_name); return idx; } idx++; } FREE(theme_name); return -1; } static int exit_apps_iterfunc( const aul_app_info *info, void *data ) { if( !info || !info->pkg_name) return 0; char *except_pkgs = (char *) getenv("SETTING_THEME_EXCEPT_PKGS"); if( except_pkgs ) { //TODO: should remove pkgs here!! //It can be skipped setting app by using aul with pid. }else { char* curr_menu = vconf_get_str("db/menuscreen/pkgname"); //TODO: Temporary comparison. Please remove this and implement above. if( !_strncmp(info->pkg_name, "com.samsung.menu-screen") || !_strncmp(info->pkg_name, "com.samsung.setting") || !_strncmp(info->pkg_name, "com.samsung.live-magazine") || !_strncmp(info->pkg_name, "com.samsung.live-data-provider") || !_strncmp(info->pkg_name, "com.samsung.quickpanel") || !_strncmp(info->pkg_name, "com.samsung.vtmain") || !_strncmp(info->pkg_name, "com.samsung.call") || !_strncmp(info->pkg_name, curr_menu) ) { FREE(curr_menu); return 0; } FREE(curr_menu); } aul_terminate_pid( info->pid ); return 0; } static void _popup_default_theme_response_no_cb( void *data, Evas_Object *obj, void *event_info ) { return; } static void _popup_default_theme_response_yes_cb( void *data, Evas_Object *obj, void *event_info ) { Item_Data *item_data = (Item_Data *)data; if(item_data == NULL) return; struct ug_theme_info *theme_info = NULL; theme_info = eina_list_nth(gtheme_list, item_data->idx); View_Data *vd = (View_Data *)evas_object_data_get(elm_object_item_widget_get(item_data->it), "view_data"); if(vd == NULL) return; elm_radio_value_set(rdg, item_data->idx); // Change EFL Theme Eina_Strbuf* efl_path = eina_strbuf_new(); eina_strbuf_append_printf( efl_path, "%s/%s.edj", DEFAULT_THEME_FOLDER_PATH, item_data->label); elm_theme_set(NULL, eina_strbuf_string_get(efl_path)); elm_config_all_flush(); vconf_set_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR, eina_strbuf_string_get(efl_path) ); eina_strbuf_free(efl_path); // Change Selected Theme Value vconf_set_str(SETTING_THEME_SELECTED_THEME, item_data->label); aul_app_get_running_app_info( exit_apps_iterfunc, NULL ); elm_exit(); } static void _cancel_button_clicked(void *data, Evas_Object *obj, void *event_info) { if (!data) return; Evas_Object *nf = (Evas_Object *) data; elm_naviframe_item_pop(nf); } static void _done_button_clicked(void *data, Evas_Object *obj, void *event_info) { Evas_Object *btn1, *btn2; Item_Data *item_data = (Item_Data *)data; if(item_data == NULL) return; struct ug_theme_info *theme_info = NULL; theme_info = eina_list_nth(gtheme_list, item_data->idx); View_Data *vd = (View_Data *)evas_object_data_get(elm_object_item_widget_get(item_data->it), "view_data"); if(vd == NULL) return; //TODO: Test Code Should be removed - View_Data and && item_data->idx <= vd->default_theme_count if (item_data->idx != _selected_theme_idx_get() && item_data->idx < vd->default_theme_count) { if (THEME_TYPE_DEFAULT == theme_info->type){ // Show popup Evas_Object *popup = elm_popup_add( vd->nf ); if( popup == NULL ) { return ; } //TODO: Apply Multi Lanaguage to this string. elm_object_text_set( popup, _("All Apps will be closed
to change theme") ); btn1 = elm_button_add(popup); elm_object_text_set(btn1, _("IDS_COM_POP_YES")); elm_object_part_content_set(popup, "button1", btn1); evas_object_smart_callback_add(btn1, "clicked", _popup_default_theme_response_yes_cb, popup); btn2 = elm_button_add(popup); elm_object_text_set(btn2, _("IDS_COM_POP_NO")); elm_object_part_content_set(popup, "button2", btn2); evas_object_smart_callback_add(btn2, "clicked", _popup_default_theme_response_no_cb, popup); evas_object_show( popup ); } //TODO: Download Winset Setting #if 0 else { if (_load_index_file(ugd,theme_info) == 0) { Eina_Strbuf* efl_path = eina_strbuf_new(); eina_strbuf_append_printf( efl_path, "%s/%s/%s/%s.edj", DOWNLOAD_THEME_FOLDER_PATH, theme_info->name, DOWNLOAD_THEME_EFL_FOLDER_NAME, ugd->theme.efl_theme.name); vconf_set_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR, eina_strbuf_string_get(efl_path)); elm_theme_set(NULL, eina_strbuf_string_get(efl_path)); elm_config_all_flush(); eina_strbuf_free(efl_path); } } #endif } } // This is called when check box status is changed static void _item_check_changed_cb(void *data, Evas_Object *obj, void *event_info) { Item_Data *item_data = (Item_Data *)data; View_Data *vd = (View_Data *)evas_object_data_get(elm_object_item_widget_get(item_data->it), "view_data"); if (vd == NULL) return; if (item_data->checked) vd->checked_count++; else vd->checked_count--; // update select all check button if (vd->select_all_layout) { if ((vd->total_count - vd->default_theme_count) == vd->checked_count) vd->select_all_checked = EINA_TRUE; else vd->select_all_checked = EINA_FALSE; elm_check_state_pointer_set(vd->select_all_checkbox, &vd->select_all_checked); } } // FIXME: Need proper method. // FIXME: This would be only available for our theme but not 3rd parties' static char* _rename_theme(const char * origin) { if ( !_strncmp(origin, "tizen-hd") ) { return strdup("White"); } else if ( !_strncmp(origin, "tizen-black-hd") ) { return strdup("Black"); } else return strdup(origin); } static void _reveal_button_clicked(void *data, Evas_Object *obj, void *event_info) { char *nf_title; Evas_Object *cbar; Evas_Object *cancel_btn; Evas_Object *done_btn; Evas_Object *nf; Evas_Object *box; Elm_Object_Item *ti; Item_Data *item_data = (Item_Data *)data; if (item_data == NULL) return; View_Data *vd = (View_Data *)evas_object_data_get(elm_object_item_widget_get(item_data->it), "view_data"); if (vd == NULL) return; nf = vd->nf; // Create Controlbar cbar = elm_toolbar_add(nf); if (cbar == NULL) return; elm_object_style_set(cbar, "naviframe"); cancel_btn = elm_button_add(cbar); elm_object_style_set(cancel_btn, "naviframe_control/default"); evas_object_size_hint_align_set(cancel_btn, EVAS_HINT_FILL, 0.5); elm_object_text_set(cancel_btn, _("Cancel")); evas_object_show(cancel_btn); evas_object_smart_callback_add(cancel_btn, "clicked", _cancel_button_clicked, nf); done_btn = elm_button_add(cbar); elm_object_style_set(done_btn, "naviframe_control/default"); evas_object_size_hint_align_set(done_btn, EVAS_HINT_FILL, 0.5); elm_object_text_set(done_btn, _("Done")); evas_object_show(done_btn); evas_object_smart_callback_add(done_btn, "clicked", _done_button_clicked, item_data); // Disable Button, If Currently Set char *theme_name = vconf_get_str(SETTING_THEME_SELECTED_THEME); if( _strncmp( item_data->label, theme_name ) == 0 ) { elm_object_disabled_set(done_btn, 1); } FREE(theme_name); // For Consistent Look ti = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ti, "object", cancel_btn); ti = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ti, "object", done_btn); nf_title = _rename_theme(item_data->label); box = elm_box_add(nf); evas_object_show(box); // TODO: Preview Image Should Get From Theme if (item_data->idx < vd->default_theme_count) { Evas_Object* icon; icon = elm_icon_add(nf); char* fn; if (!_strncmp(item_data->label, "tizen-hd")) fn = "tizen"; else if (!_strncmp(item_data->label, "tizen-black-hd")) fn = "tizen-black"; else fn = item_data->label; Eina_Strbuf* efl_path = eina_strbuf_new(); eina_strbuf_append_printf( efl_path, "%s/%s.png", IMG_DIR, fn); elm_icon_file_set(icon, eina_strbuf_string_get(efl_path), NULL); elm_icon_resizable_set(icon, 0, 0); evas_object_size_hint_align_set(icon, 0.5, 0.5); elm_box_pack_end(box, icon); evas_object_show(icon); eina_strbuf_free(efl_path); } Elm_Object_Item *navi_it = elm_naviframe_item_push(nf, nf_title, NULL, NULL, box, NULL); elm_object_item_part_content_set(navi_it, "optionheader", cbar); FREE(nf_title); // Remove Prev Button Evas_Object *prev_btn = elm_object_item_part_content_get(navi_it, "prev_btn"); evas_object_del(prev_btn); } static void _gl_sel( void *data, Evas_Object *obj, void *event_info) { Item_Data *item_data; Elm_Object_Item *genlist_item = (Elm_Object_Item *) event_info; if( genlist_item == NULL ) return; elm_genlist_item_selected_set(genlist_item, EINA_FALSE); item_data = elm_object_item_data_get(genlist_item); _done_button_clicked(item_data, NULL, NULL); } static char* _gl_label_get(void *data, Evas_Object *obj, const char *part) { Item_Data *item_data = (Item_Data *) data; if(item_data == NULL) return NULL; if( strcmp(part, "elm.text") == 0 ) { return _rename_theme(item_data->label); } return NULL; } Evas_Object *_load_edj(Evas_Object *parent, const char *file, const char *group) { Evas_Object *eo; int r; eo = elm_layout_add(parent); if (eo) { r = elm_layout_file_set(eo, file, group); if (!r) { evas_object_del(eo); return NULL; } } return eo; } static Evas_Object *_gl_icon_get(void *data, Evas_Object *obj, const char *part) { if(obj == NULL) return NULL; Item_Data *item_data = (Item_Data *) data; if(item_data == NULL) return NULL; Evas_Object *icon; if (!elm_genlist_decorate_mode_get(obj)) { if ( !strncmp( part, "elm.icon.1", strlen(part) ) ) { // radio button icon = elm_radio_add(obj); elm_radio_state_value_set(icon, (int) item_data->idx); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_radio_group_add( icon, rdg ); // For avoidng user click Evas_Object* fake_icon = _load_edj(obj, SETTING_THEME_EDJ, "fake_icon"); elm_object_part_content_set(fake_icon, "icon", icon); return fake_icon; } else if ( !strncmp( part, "elm.icon.2", strlen(part) ) ) { // preview button icon = elm_button_add(obj); elm_object_style_set(icon, "reveal"); evas_object_smart_callback_add(icon, "clicked", _reveal_button_clicked, item_data); evas_object_propagate_events_set(icon, EINA_FALSE); return icon; } } else { if (!strcmp(part, "elm.edit.icon.1")) { // swallow checkbox or radio button icon = elm_check_add(obj); elm_check_state_pointer_set(icon, &item_data->checked); evas_object_smart_callback_add(icon, "changed", _item_check_changed_cb, item_data); return icon; } } return NULL; } static void _clear_theme_list(Eina_List *theme_list) { Eina_List *elist = NULL; struct ug_theme_info *theme_info = NULL; EINA_LIST_FOREACH( theme_list, elist, theme_info ) { theme_list = eina_list_remove( theme_list, theme_info ); free( theme_info->name ); free( theme_info ); } } static void _base_object_del_cb(void * data, Evas *e, Evas_Object *obj, void *event_info) { struct ug_data *ugd = (struct ug_data *) data; ugd->base = NULL; } static void _back_button_clicked( void *data, Evas_Object *obj, void *event_info ) { struct ug_data * ugd = (struct ug_data *) data; ug_destroy_me(ugd->ug); } static void _check_select_all(View_Data *vd) { Item_Data *it_data; Elm_Object_Item *it; if (vd->select_all_checked) vd->checked_count = (vd->total_count - vd->default_theme_count); else vd->checked_count = 0; it = elm_genlist_first_item_get(vd->genlist); while(it) { it_data = elm_object_item_data_get(it); if (it_data) it_data->checked = vd->select_all_checked; it = elm_genlist_item_next_get(it); } // Update all realized items elm_genlist_realized_items_update(vd->genlist); } static void _select_all_check_changed_cb(void *data, Evas_Object *obj, void *event_info) { _check_select_all(data); } static void _genlist_to_normal(View_Data *data) { if (!data) return; View_Data *vd = data; Item_Data *item_data; Evas_Object *genlist = vd->genlist; Evas_Object *delete_btn = vd->delete_btn, *more_btn = vd->more_btn; Elm_Object_Item *it, *ti; Eina_List *elist = NULL; struct ug_theme_info *theme_info = NULL; int idx = 0; // Change background color to default background color elm_object_style_set(vd->bg, "group_list"); // Change button label elm_object_text_set(delete_btn, _("Delete")); elm_object_text_set(more_btn, _("More winsets")); // Remove 'Select All' layout. elm_box_unpack(vd->box, vd->select_all_layout); evas_object_del(vd->select_all_layout); vd->select_all_layout = NULL; // Unset edit mode elm_genlist_decorate_mode_set(genlist, EINA_FALSE); elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_ALWAYS); // Add Default Theme idx = 0; it = elm_genlist_first_item_get(genlist); EINA_LIST_FOREACH( gtheme_list, elist, theme_info ) { item_data = calloc(1, sizeof(Item_Data)); item_data->label = theme_info->name; item_data->idx = idx; if (it) item_data->it = elm_genlist_item_insert_before(genlist, &itc, (void *) item_data, NULL, it, ELM_GENLIST_ITEM_NONE, _gl_sel, NULL); else { item_data->it = elm_genlist_item_append(genlist, &itc, (void *) item_data, NULL, ELM_GENLIST_ITEM_NONE, _gl_sel, NULL); } idx++; if (idx >= vd->default_theme_count) break; } // Remove 'Delete' button idx = 0; it = elm_genlist_first_item_get(genlist); while(it) { idx++; it = elm_genlist_item_next_get(it); } if (idx <= vd->default_theme_count) { elm_object_item_del(vd->del_btn_item); ti = elm_toolbar_item_prepend(vd->cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ti, "object", NULL); } // Change Genlist Item Class idx = 0; it = elm_genlist_item_prepend(genlist, &itc2, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); it = elm_genlist_first_item_get(genlist); while(it) { if(idx != 0) { elm_genlist_item_item_class_update(it, &itc); } it = elm_genlist_item_next_get(it); ++idx; } } static void _delete_button_clicked(void *data, Evas_Object *obj, void *event_info) { if (!data) return; View_Data *vd = data; Item_Data *item_data; Evas_Object *genlist = vd->genlist, *layout, *check; Evas_Object *delete_btn = vd->delete_btn, *more_btn = vd->more_btn; Elm_Object_Item *it; int idx = 0; if (!elm_genlist_decorate_mode_get(genlist)) { // Genlist will be in Edit Mode // Change background color to edit_mode color elm_object_style_set(vd->bg, "edit_mode"); // Change button label elm_object_text_set(delete_btn, _("Cancel")); elm_object_text_set(more_btn, _("Done")); // Append 'Select All' layout layout = vd->select_all_layout = elm_layout_add(vd->box); elm_layout_theme_set(layout, "genlist", "item", "select_all/default"); evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_FILL); evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL); check = vd->select_all_checkbox = elm_check_add(vd->select_all_layout); elm_check_state_pointer_set(check, &vd->select_all_checked); evas_object_smart_callback_add(check, "changed", _select_all_check_changed_cb, vd); elm_check_state_set(check, EINA_FALSE); vd->select_all_checked = EINA_FALSE; evas_object_propagate_events_set(check, EINA_FALSE); elm_object_part_content_set(layout, "elm.icon", check); elm_object_part_text_set(vd->select_all_layout, "elm.text", "Select All"); elm_box_pack_start(vd->box, vd->select_all_layout); evas_object_show(vd->select_all_layout); // Delete Seperator Item it = elm_genlist_first_item_get(genlist); elm_object_item_del(it); // Delete Default Theme Item idx = vd->default_theme_count; it = elm_genlist_first_item_get(genlist); while(it && idx > 0) { item_data = elm_object_item_data_get(it); it = elm_genlist_item_next_get(it); if (item_data) { elm_object_item_del(item_data->it); idx--; } } // Change Genlist Item Class it = elm_genlist_first_item_get(genlist); while(it) { elm_genlist_item_item_class_update(it, &edit_mode_itc); item_data = elm_object_item_data_get(it); item_data->checked = EINA_FALSE; it = elm_genlist_item_next_get(it); } vd->checked_count = 0; elm_genlist_decorate_mode_set(genlist, EINA_TRUE); } else { // Genlist will be in Normal Mode _genlist_to_normal(vd); } } static void response_cb(void *data, Evas_Object *obj, void *event_info) { if (obj != NULL) evas_object_del(obj); } static void _more_button_clicked(void *data, Evas_Object *obj, void *event_info) { struct ug_data *ugd = (struct ug_data *) data; if (ugd == NULL) return; View_Data *vd = ugd->vd; if (vd == NULL) return; Item_Data *it_data; Elm_Object_Item *it; Evas_Object *genlist = vd->genlist; if (!elm_genlist_decorate_mode_get(genlist)) { if(aul_launch_app("com.samsung.samsungapps", NULL) < 0) { // Error Handling, Cannot Launch Samsung Apps Evas_Object *popup = elm_popup_add(vd->nf); elm_object_text_set(popup, "Samsung Apps is not installed"); evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb, NULL); elm_popup_timeout_set(popup, 3.0); evas_object_smart_callback_add(popup, "response", response_cb, NULL); evas_object_show(popup); } } else { // Done - Delete Selected Winset it = elm_genlist_first_item_get(genlist); while (it) { it_data = elm_object_item_data_get(it); it = elm_genlist_item_next_get(it); if ((it_data) && (it_data->checked)) { elm_object_item_del(it_data->it); vd->total_count--; vd->checked_count--; } } _genlist_to_normal(vd); } } static void _set_genlist_item_styles(View_Data *vd) { itc.item_style = "dialogue/1text.2icon.2"; itc.func.text_get = _gl_label_get; itc.func.content_get = _gl_icon_get; itc.func.state_get = NULL; itc.func.del = NULL; itc.decorate_item_style = "edit_default"; itc2.item_style = "dialogue/seperator"; itc2.func.text_get = NULL; itc2.func.content_get = NULL; itc2.func.state_get = NULL; itc2.func.del = NULL; edit_mode_itc.item_style = "1text"; edit_mode_itc.func.text_get = _gl_label_get; edit_mode_itc.func.content_get = _gl_icon_get; edit_mode_itc.func.state_get = NULL; edit_mode_itc.func.del = NULL; edit_mode_itc.decorate_item_style = "edit_default"; } // Create genlist and append items static Evas_Object *_create_genlist(struct ug_data *ugd) { if( ugd == NULL ) return NULL; View_Data *vd = ugd->vd; Item_Data *item_data; Evas_Object *genlist; // Create genlist genlist = elm_genlist_add(vd->nf); 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); // Get Default Theme Eina_List *theme_list = ugd->theme_list; _get_default_theme_list( DEFAULT_THEME_FOLDER_PATH, &theme_list); vd->default_theme_count = eina_list_count(theme_list); // Get Download Theme _get_theme_list( DOWNLOAD_THEME_FOLDER_PATH , &theme_list ); //TODO: Test Code - START, Should be removed #if 0 struct ug_theme_info *new_info_r = (struct ug_theme_info*)calloc(1,sizeof(struct ug_theme_info)); new_info_r->type = THEME_TYPE_DOWNLOAD; new_info_r->name = strndup("Red", strlen("Red")); eina_list_append( theme_list, new_info_r ); struct ug_theme_info *new_info_g = (struct ug_theme_info*)calloc(1,sizeof(struct ug_theme_info)); new_info_g->type = THEME_TYPE_DOWNLOAD; new_info_g->name = strndup("Green", strlen("Green")); eina_list_append( theme_list, new_info_g ); struct ug_theme_info *new_info_b = (struct ug_theme_info*)calloc(1,sizeof(struct ug_theme_info)); new_info_b->type = THEME_TYPE_DOWNLOAD; new_info_b->name = strndup("Blue", strlen("Blue")); eina_list_append( theme_list, new_info_b ); #endif //TODO: Test Code - END, Should be removed ugd->theme_list = theme_list; gtheme_list = eina_list_clone( ugd->theme_list ); Eina_List *elist = NULL; struct ug_theme_info *theme_info = NULL; int idx = 0; item_data = calloc(1, sizeof(Item_Data)); item_data->label = NULL; item_data->idx = idx; item_data->it = elm_genlist_item_append(genlist, &itc2, (void *) item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); elm_genlist_item_select_mode_set(item_data->it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); EINA_LIST_FOREACH( gtheme_list, elist, theme_info ) { item_data = calloc(1, sizeof(Item_Data)); item_data->label = theme_info->name; item_data->idx = idx; item_data->it = elm_genlist_item_append(genlist, &itc, (void *) item_data, NULL, ELM_GENLIST_ITEM_NONE, _gl_sel, NULL); idx++; } 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); vd->total_count = idx; // Check selected theme idx = _selected_theme_idx_get(); if (idx < 0) return genlist; // Create radio group rdg = elm_radio_add( genlist ); elm_radio_value_set( rdg, idx ); return genlist; } static Evas_Object *create_fullview( Evas_Object *parent, struct ug_data *ugd ) { Evas_Object *cbar; Elm_Object_Item *ti; if(parent == NULL) return NULL; // Create layout data View_Data *vd; vd = calloc(1, sizeof(View_Data)); ugd->vd = vd; // Create layout Evas_Object *layout = _create_layout_main( parent, vd ); if( layout == NULL ) return NULL; vd->nf = _create_naviframe( layout ); if( vd->nf == NULL ) { evas_object_del( layout ); return NULL; } // Create Genlist _set_genlist_item_styles(vd); vd->genlist = _create_genlist(ugd); // Need by Item Check Changed Callback , Reveal Button Clicked Callback evas_object_data_set(vd->genlist, "view_data", vd); // Create Box vd->box = elm_box_add(vd->nf); evas_object_size_hint_weight_set(vd->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(vd->box); elm_box_pack_end(vd->box, vd->genlist); evas_object_show(vd->genlist); elm_object_part_content_set( layout, "elm.swallow.content", vd->nf ); // Create Controlbar vd->cbar = cbar = elm_toolbar_add(vd->nf); if (cbar == NULL) return NULL; elm_object_style_set(cbar, "naviframe"); vd->more_btn = elm_button_add(cbar); elm_object_style_set(vd->more_btn, "naviframe_control/default"); evas_object_size_hint_align_set(vd->more_btn, EVAS_HINT_FILL, 0.5); elm_object_text_set(vd->more_btn, _("More winsets")); evas_object_show(vd->more_btn); evas_object_smart_callback_add(vd->more_btn, "clicked", _more_button_clicked, ugd); //If there is download winset, then enable delete button if(vd->default_theme_count < vd->total_count) { vd->delete_btn = elm_button_add(cbar); elm_object_style_set(vd->delete_btn, "naviframe_control/default"); evas_object_size_hint_align_set(vd->delete_btn, EVAS_HINT_FILL, 0.5); elm_object_text_set(vd->delete_btn, _("Delete")); evas_object_show(vd->delete_btn); evas_object_smart_callback_add(vd->delete_btn, "clicked", _delete_button_clicked, vd); vd->del_btn_item = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(vd->del_btn_item, "object", vd->delete_btn); } else { ti = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ti, "object", NULL); } ti = elm_toolbar_item_append(cbar, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(ti, "object", vd->more_btn); Evas_Object *back_btn = elm_button_add( vd->nf ); elm_object_style_set(back_btn, "naviframe/back_btn/default"); evas_object_smart_callback_add( back_btn, "clicked", _back_button_clicked, ugd ); Elm_Object_Item *navi_it = elm_naviframe_item_push( vd->nf, _("IDS_ST_BODY_THEME"), back_btn, NULL, vd->box, NULL ); // add controlbar to naviframe elm_object_item_part_content_set(navi_it, "optionheader", cbar); elm_object_item_signal_emit(navi_it, "elm,state,optionheader,instant_close", ""); evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, _base_object_del_cb, ugd); return layout; } static Evas_Object *create_frameview(Evas_Object *parent, struct ug_data *ugd) { Evas_Object *base = NULL; // Create Frame view return base; } static void *on_create(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv) { Evas_Object *parent; struct ug_data *ugd; if (!ug || !priv) return NULL; ugd = priv; ugd->ug = ug; bindtextdomain(PKGNAME, MO_FILE_PATH); parent = ug_get_parent_layout(ug); if (!parent) return NULL; if (mode == UG_MODE_FULLVIEW) ugd->base = create_fullview(parent, ugd); else ugd->base = create_frameview(parent, ugd); _parent = parent; return ugd->base; } static void on_start(struct ui_gadget *ug, bundle *data, void *priv) { } static void on_pause(struct ui_gadget *ug, bundle *data, void *priv) { } static void on_resume(struct ui_gadget *ug, bundle *data, void *priv) { } static void on_destroy(struct ui_gadget *ug, bundle *data, void *priv) { struct ug_data *ugd; if (!ug || !priv) return; ugd = priv; // Free View Data if (ugd->vd) { if (ugd->vd->bg) { evas_object_del(ugd->vd->bg); ugd->vd->bg = NULL; } evas_object_data_set(ugd->vd->genlist, "view_data", NULL); free(ugd->vd); ugd->vd = NULL; } _clear_theme_list( ugd->theme_list ); ugd->theme_list = NULL; if( ugd->base ) { evas_object_del(ugd->base); ugd->base = NULL; } eina_list_free( gtheme_list ); gtheme_list = NULL; if( rdg != NULL ) { evas_object_del( rdg ); rdg = NULL; } } static void on_message(struct ui_gadget *ug, bundle *msg, bundle *data, void *priv) { } static void on_event(struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv) { switch (event) { case UG_EVENT_LOW_MEMORY: break; case UG_EVENT_LOW_BATTERY: break; case UG_EVENT_LANG_CHANGE: break; case UG_EVENT_ROTATE_PORTRAIT: break; case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN: break; case UG_EVENT_ROTATE_LANDSCAPE: break; case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN: break; default: break; } } static void on_key_event(struct ui_gadget *ug, enum ug_key_event event, bundle *data, void *priv) { if (!ug) return; switch (event) { case UG_KEY_EVENT_END: ug_destroy_me(ug); break; default: break; } } UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops) { struct ug_data *ugd; if (!ops) return -1; ugd = calloc(1, sizeof(struct ug_data)); if (!ugd) return -1; ops->create = on_create; ops->start = on_start; ops->pause = on_pause; ops->resume = on_resume; ops->destroy = on_destroy; ops->message = on_message; ops->event = on_event; ops->key_event = on_key_event; ops->priv = ugd; ops->opt = UG_OPT_INDICATOR_ENABLE; return 0; } UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops) { struct ug_data *ugd; if (!ops) return; ugd = ops->priv; if (ugd) free(ugd); } // For Reset Operation UG_MODULE_API int setting_plugin_reset(bundle *data, void *priv) { //FIXME: Need to avoid hard coding for default theme name char *value = vconf_get_str(SETTING_THEME_SELECTED_THEME); if (value && !strcmp(value, "tizen-black-hd")) { vconf_set_bool(SETTING_THEME_IS_THEME_CHANGED, 0); } else { vconf_set_bool(SETTING_THEME_IS_THEME_CHANGED, 1); } FREE(value); // Change Selected Theme Value vconf_set_str(SETTING_THEME_SELECTED_THEME, "tizen-black-hd"); // Change EFL Theme Eina_Strbuf* efl_path = eina_strbuf_new(); eina_strbuf_append_printf( efl_path, "%s/tizen-black-hd.edj", DEFAULT_THEME_FOLDER_PATH); vconf_set_str(VCONFKEY_SETAPPL_WIDGET_THEME_STR, eina_strbuf_string_get(efl_path) ); eina_strbuf_free(efl_path); aul_app_get_running_app_info( exit_apps_iterfunc, NULL ); return 0; }