diff options
Diffstat (limited to 'src/widget/mp-popup.c')
-rwxr-xr-x | src/widget/mp-popup.c | 437 |
1 files changed, 437 insertions, 0 deletions
diff --git a/src/widget/mp-popup.c b/src/widget/mp-popup.c new file mode 100755 index 0000000..f3fa552 --- /dev/null +++ b/src/widget/mp-popup.c @@ -0,0 +1,437 @@ +/* + * 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. + */ + + +#include <stdio.h> +#include <appcore-efl.h> +#include "music.h" +#include "mp-menu.h" +#include "mp-popup.h" +#include "mp-item.h" +#include "mp-player-debug.h" +#include "mp-view-layout.h" +#include "mp-play-list.h" +#include "mp-common.h" +#include "mm_sound.h" +#include "mp-widget.h" + +typedef struct { + Evas_Object *popup; + Evas_Smart_Cb response_cb; + void *cb_data; + int response; +} Popup_Cb_Data; + +static Elm_Genlist_Item_Class itc; + +static Evas_Object *g_popup_win = NULL; + +static void +_mp_popup_response_cb(void *data, Evas_Object * obj, void *event_info) +{ + DEBUG_TRACE("response callback=%d", (int)event_info); + if (g_popup_win) + { + evas_object_del(g_popup_win); + g_popup_win = NULL; + } + + if ((int)event_info != 5) + evas_object_del(obj); +} + +static char * +_mp_popup_gl_label_get(void *data, Evas_Object * obj, const char *part) +{ + char *label = (char *)data; + DEBUG_TRACE("%s", label); + return strdup(label); +} + +static Evas_Object * +_mp_popup_gl_icon_get(void *data, Evas_Object * obj, const char *part) +{ + DEBUG_TRACE(""); + MP_CHECK_NULL(data); + + struct appdata *ad = evas_object_data_get(obj, "ad"); + MP_CHECK_NULL(ad); + + Evas_Object *radio = elm_radio_add(obj); + elm_radio_group_add(radio, ad->radio_group); + + if (!strcmp(GET_SYS_STR("IDS_COM_OPT_HEADPHONES_ABB"), data)) + { + elm_radio_state_value_set(radio, MP_SND_PATH_EARPHONE); + evas_object_data_set(radio, "idx", (void *)(MP_SND_PATH_EARPHONE)); + } + else if (!strcmp(GET_SYS_STR("Speaker"), data)) + { + elm_radio_state_value_set(radio, MP_SND_PATH_SPEAKER); + evas_object_data_set(radio, "idx", (void *)(MP_SND_PATH_SPEAKER)); + } + else + { + elm_radio_state_value_set(radio, MP_SND_PATH_BT); + evas_object_data_set(radio, "idx", (void *)(MP_SND_PATH_BT)); + } + + evas_object_show(radio); + + elm_radio_value_set(ad->radio_group, ad->snd_path); + + return radio; +} + +static void +_mp_popup_set_min_size(Evas_Object *box, int cnt) +{ + int min_h = 0; + MP_CHECK(box); + if(cnt > 3) + min_h = MP_POPUP_GENLIST_ITEM_H_MAX; + else + min_h = MP_POPUP_GENLIST_ITEM_H*cnt + cnt -1; + + evas_object_size_hint_min_set(box, + MP_POPUP_GENLIST_ITEM_W * elm_scale_get(), min_h * elm_scale_get()); +} + +static Evas_Object * +_mp_popup_create_min_style_popup(Evas_Object * parent, char *title, int cnt) +{ + Evas_Object *genlist = NULL; + Evas_Object *box = NULL; + Evas_Object *popup = elm_popup_add(parent); + MP_CHECK_NULL(popup); + + elm_object_style_set(popup, "min_menustyle"); + mp_popup_title_set(popup, title); + + box = elm_box_add(popup); + MP_CHECK_NULL(box); + + _mp_popup_set_min_size(box, cnt); + + genlist = elm_genlist_add(box); + MP_CHECK_NULL(genlist); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + + evas_object_data_set(popup, "genlist", genlist); + + evas_object_show(genlist); + elm_box_pack_end(box, genlist); + mp_popup_content_set(popup, box); + evas_object_show(box); + + mp_popup_set_response_cb(popup, _mp_popup_response_cb, NULL); + mp_popup_button_set(popup, "button1", GET_SYS_STR("IDS_COM_POP_CANCEL"), MP_POPUP_NO); + evas_object_show(popup); + + return popup; +} + +static Evas_Object * +_mp_popup_sound_path_create(Evas_Object * parent, void *data) +{ + DEBUG_TRACE_FUNC(); + + Evas_Object *popup = NULL; + int bt_connected = 0; + int earjack = 0; + int ret = 0; + char *bt_name = NULL; + int cnt = 1; + + ret = mm_sound_route_get_a2dp_status(&bt_connected, &bt_name); + if (ret != MM_ERROR_NONE) + { + WARN_TRACE("Fail to mm_sound_route_get_a2dp_status ret = [%d]", ret); + } + IF_FREE(bt_name); + if(bt_connected) + cnt++; + + if (vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &earjack)) + WARN_TRACE("Earjack state get Fail..."); + if(earjack) + cnt++; + + popup = _mp_popup_create_min_style_popup(parent, GET_STR("Sound path"), cnt); + + return popup; +} + +static Evas_Object * +_mp_popup_add_to_playlist_create(Evas_Object * parent, void *data, struct appdata *ad) +{ + DEBUG_TRACE_FUNC(); + + Evas_Object *popup = NULL; + int ret; + int count = 0; + + ret = audio_svc_count_playlist(ad->media_svc_handle, "", "", &count); + DEBUG_TRACE("count,%d", count); + + popup = _mp_popup_create_min_style_popup(parent, GET_STR("IDS_MUSIC_BODY_ADD_TO_PLAYLIST"), count+1); + + return popup; +} + +static void +_mp_popup_del_cb(void *data, Evas * e, Evas_Object * eo, void *event_info) +{ + DEBUG_TRACE(""); + struct appdata *ad = (struct appdata *)data; + int type = (int)evas_object_data_get(eo, "type"); + DEBUG_TRACE("type: %d", type); + if (type >= MP_POPUP_MAX) + { + ERROR_TRACE("Never should be here!!!"); + return; + } + ad->popup[type] = NULL; +} + +static bool +_mp_popup_popup_exist(struct appdata *ad, mp_popup_t type) +{ + MP_CHECK_FALSE(ad); + if (ad->popup[type]) + return TRUE; + return FALSE; +} + +Elm_Object_Item * +mp_genlist_popup_item_append(Evas_Object * popup, char *label, Evas_Object * icon, void *cb, void *data) +{ + MP_CHECK_NULL(popup); + MP_CHECK_NULL(label); + + Evas_Object *genlist = evas_object_data_get(popup, "genlist"); + MP_CHECK_NULL(genlist); + + Elm_Object_Item *item = NULL; + + if (!icon) + { + itc.item_style = "1text"; + itc.func.text_get = _mp_popup_gl_label_get; + itc.func.content_get = NULL; + itc.func.state_get = NULL; + itc.func.del = NULL; + } + else + { + itc.item_style = "1text.1icon.3"; + itc.func.text_get = _mp_popup_gl_label_get; + itc.func.content_get = _mp_popup_gl_icon_get; + itc.func.state_get = NULL; + itc.func.del = NULL; + } + + item = elm_genlist_item_append(genlist, &itc, label, NULL, ELM_GENLIST_ITEM_NONE, cb, data); + + return item; + +} + +Evas_Object * +mp_genlist_popup_create(Evas_Object * parent, mp_popup_t type, void *user_data, struct appdata * ad) +{ + mp_retvm_if(parent == NULL, NULL, "parent is NULL"); + MP_CHECK_NULL(ad); + + if (_mp_popup_popup_exist(ad, MP_POPUP_GENLIST)) + { + DEBUG_TRACE("popup already exist..."); + return NULL; + } + + Evas_Object *popup = NULL; + + switch (type) + { + case MP_POPUP_ADD_TO_PLST: + popup = _mp_popup_add_to_playlist_create(parent, user_data, ad); + break; + case MP_POPUP_SOUND_PATH: + popup = _mp_popup_sound_path_create(parent, user_data); + evas_object_data_set(popup, "sound_path", (char *)1); + break; + default: + break; + } + + if (popup) + { + evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _mp_popup_del_cb, ad); + evas_object_data_set(popup, "type", (void *)MP_POPUP_GENLIST); + ad->popup[MP_POPUP_GENLIST] = popup; + } + + return popup; +} + +void +mp_popup_destroy(struct appdata *ad) +{ + MP_CHECK(ad); + int i = 0; + for(i=0; i < MP_POPUP_MAX; i++) + { + if (ad->popup[i]) + { + mp_popup_response(ad->popup[i], -1); + ad->popup[i] = NULL; + } + } +} + +Evas_Object * +mp_popup_create(Evas_Object * parent, mp_popup_type type, char *title, void *user_data, void *response_cb, + struct appdata *ad) +{ + Evas_Object *popup = NULL; + Evas_Object *progressbar = NULL; + + MP_CHECK_NULL(parent); + MP_CHECK_NULL(type); + MP_CHECK_NULL(ad); + + if (_mp_popup_popup_exist(ad, type)) + { + DEBUG_TRACE("popup already exist..."); + return NULL; + } + + switch (type) + { + case MP_POPUP_PROGRESS: + popup = elm_popup_add(ad->win_main); + MP_CHECK_NULL(popup); + + progressbar = elm_progressbar_add(popup); + MP_CHECK_NULL(progressbar); + + elm_object_style_set(progressbar, "list_process"); + evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5); + evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(progressbar); + elm_progressbar_pulse(progressbar, EINA_TRUE); + + mp_popup_title_set(popup, title); + mp_popup_content_set(popup, progressbar); + + mp_popup_set_response_cb(popup, response_cb, user_data); + mp_popup_button_set(popup, "button1", GET_SYS_STR("IDS_COM_POP_CANCEL"), MP_POPUP_NO); + + evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _mp_popup_del_cb, ad); + evas_object_data_set(popup, "type", (void *)type); + + break; + + default: + DEBUG_TRACE("Unsupported type: %d", type); + return NULL; + } + + evas_object_show(popup); + + ad->popup[type] = popup; + + return popup; + +} + +static void +_mp_poup_button_response_cb(void *data, Evas_Object *obj, void *event_info) +{ + MP_CHECK(data); + Evas_Object *popup = data; + + int response = mp_popup_btn_response_get(obj); + mp_popup_response(popup, response); +} + +void +mp_popup_set_response_cb(Evas_Object *popup, Evas_Smart_Cb response_cb, void *data) +{ + MP_CHECK(popup); + + evas_object_data_set(popup, "popup_response_cb", response_cb); + evas_object_data_set(popup, "popup_response_cb_data", data); +} + +void +mp_popup_response(Evas_Object *popup, int response) +{ + MP_CHECK(popup); + + Evas_Smart_Cb response_cb = evas_object_data_get(popup, "popup_response_cb"); + void *cb_data = evas_object_data_get(popup, "popup_response_cb_data"); + + if (response_cb) + response_cb(cb_data, popup, (void *)response); + else + evas_object_del(popup); +} + +Evas_Object * +mp_popup_button_set(Evas_Object *popup, const char *part, const char *text, int response) +{ + MP_CHECK_NULL(popup); + MP_CHECK_NULL(part); + + if (g_strcmp0(part, "button1") && g_strcmp0(part, "button2") && g_strcmp0(part, "button3")) { + mp_error("invalid part"); + return NULL; + } + + Evas_Object *button = mp_widget_create_button(popup, NULL, (char *)text, NULL, _mp_poup_button_response_cb, popup); + if (button) { + elm_object_part_content_set(popup, part, button); + mp_popup_btn_popup_set(button, popup); + mp_popup_btn_response_set(button, response); + } + + return button; +} + +static void +_mp_poup_default_response_cb(void *data, Evas_Object *obj, void *event_info) +{ + mp_popup_response(obj, (int)data); +} + +void +mp_popup_timeout_set(Evas_Object *popup, double timeout) +{ + MP_CHECK(popup); + + elm_popup_timeout_set(popup, timeout); + evas_object_smart_callback_add(popup, "timeout", _mp_poup_default_response_cb, (void *)MP_POPUP_DEL); +} + +void +mp_popup_block_clicked_set(Evas_Object *popup) +{ + MP_CHECK(popup); + + evas_object_smart_callback_add(popup, "block,clicked", _mp_poup_default_response_cb, (void *)MP_POPUP_DEL); +} |