2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "mp-widget.h"
21 #include "mp-setting-ctrl.h"
23 #include "mp-player-control.h"
24 #include "mp-play-view.h"
25 #include "mp-http-mgr.h"
26 #include "mp-playlist-mgr.h"
27 #include "mp-ug-launch.h"
32 #include <glib-object.h>
33 #include "mp-player-mgr.h"
34 #include "mp-player-debug.h"
35 #include <syspopup_caller.h>
37 #include "mp-minicontroller.h"
40 #include "mp-volume.h"
41 #include "mp-common-defs.h"
44 #ifdef MP_SOUND_PLAYER
45 #include "sp-view-manager.h"
47 #include "mp-library.h"
48 #include "mp-common.h"
49 #include "mp-view-manager.h"
55 #ifdef MP_FEATURE_AVRCP_13
62 #ifdef MP_FEATURE_EXIT_ON_BACK
63 #define MP_EXIT_ON_BACK "ExitOnBack"
67 static bool _mp_main_init(struct appdata *ad);
68 static Eina_Bool _mp_main_win_visibility_change_cb(void *data, int type, void *event);
69 static Eina_Bool _mp_main_win_focus_in_cb(void *data, int type, void *event);
70 static Eina_Bool _mp_main_win_focus_out_cb(void *data, int type, void *event);
71 static Eina_Bool _mp_main_app_init_idler_cb(void *data);
74 _mp_main_exit_cb(void *data, Evas_Object * obj, void *event_info)
76 mp_evas_object_del(obj);
82 _mp_evas_flush_post(void *data, Evas * e, void *event_info)
84 struct appdata *ad = (struct appdata *)data;
87 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_FLUSH_POST, _mp_evas_flush_post);
92 _mp_main_init(struct appdata *ad)
95 ad->request_play_id = MP_SYS_PLST_NONE;
96 ad->music_setting_change_flag = false;
98 mp_media_info_connect();
100 ad->app_init_idler = ecore_idler_add(_mp_main_app_init_idler_cb, ad);
106 _mp_main_set_current_playing_item(struct appdata *ad, const char *current_player_path)
109 ad->loadtype = LOAD_TRACK;
111 mp_playlist_mgr_clear(ad->playlist_mgr);
112 mp_plst_item *item = mp_playlist_mgr_item_append(ad->playlist_mgr, current_player_path, NULL, MP_TRACK_URI);
113 mp_playlist_mgr_set_current(ad->playlist_mgr, item);
115 ad->launch_type = MP_LAUNCH_BY_PATH;
122 _mp_main_is_launching_available(struct appdata *ad)
124 TA_S(2, "mp_check_battery_available");
125 if (mp_check_battery_available())
127 Evas_Object *popup = mp_popup_create(ad->win_main, MP_POPUP_NORMAL, NULL, ad, _mp_main_exit_cb, ad);
128 elm_object_text_set(popup, GET_SYS_STR("IDS_COM_BODY_LOW_BATTERY"));
129 mp_popup_button_set(popup, MP_POPUP_BTN_1, GET_SYS_STR("IDS_COM_SK_OK"), MP_POPUP_YES);
130 mp_popup_timeout_set(popup, MP_POPUP_TIMEOUT);
131 evas_object_show(ad->win_main);
132 evas_object_show(popup);
135 TA_E(2,"mp_check_battery_available");
137 TA_S(2, "mp_check_mass_storage_mode");
138 if (mp_check_mass_storage_mode())
140 Evas_Object *popup = mp_popup_create(ad->win_main, MP_POPUP_NORMAL, NULL, ad, _mp_main_exit_cb, ad);
141 elm_object_text_set(popup, GET_SYS_STR("IDS_COM_POP_UNABLE_TO_USE_DURING_MASS_STORAGE_MODE"));
142 mp_popup_button_set(popup, MP_POPUP_BTN_1, GET_SYS_STR("IDS_COM_SK_OK"), MP_POPUP_YES);
143 mp_popup_timeout_set(popup, MP_POPUP_TIMEOUT);
144 evas_object_show(ad->win_main);
145 evas_object_show(popup);
148 TA_E(2,"mp_check_mass_storage_mode");
152 #ifndef MP_SOUND_PLAYER
154 _mp_main_create_view_by_item(struct appdata *ad, const char *argv1)
156 mp_retm_if(argv1 == NULL, "argv1 is NULL");
157 mp_retm_if(ad == NULL, "ad is NULL");
161 if (strstr(argv1, MP_SHORTCUT_PLAYLIST) == argv1)
163 int playlist_id = -1;
165 id = strtok((char *)argv1, MP_FUNC_ADD_TO_HOME_SEPARATION);
166 id = strtok(NULL, MP_FUNC_ADD_TO_HOME_SEPARATION);
169 playlist_id = atoi(id);
170 DEBUG_TRACE("Playlist id is %d", playlist_id);
171 ad->launch_type = MP_LAUNCH_ADD_TO_HOME;
172 ad->loadtype = LOAD_PLAYLIST;
173 ad->request_play_id = playlist_id;
178 else if (strstr(argv1, MP_SHORTCUT_GROUP) == argv1)
181 id = strtok((char *)argv1, MP_FUNC_ADD_TO_HOME_SEPARATION);
182 id = strtok(NULL, MP_FUNC_ADD_TO_HOME_SEPARATION);
185 ad->request_group_type = (atoi(id));
186 mp_debug("view_type is %d", ad->request_group_type);
188 id = strtok(NULL, MP_FUNC_ADD_TO_HOME_SEPARATION);
192 IF_FREE(ad->request_group_name);
193 ad->request_group_name = g_strdup(id);
195 DEBUG_TRACE("Reqest Album name is %s", ad->request_group_name);
196 ad->launch_type = MP_LAUNCH_ADD_TO_HOME;
197 ad->loadtype = LOAD_GROUP;
202 else if (strstr(argv1, MP_SHORTCUT_SONG) == argv1)
204 char current_player_path[255] = { 0, };
205 char temp[255] = { 0, };
206 strncpy(temp, argv1, 255);
209 for (i = 0; i < strlen(temp); i++)
216 current_player_path[j - (i + 1)] = temp[j];
219 DEBUG_TRACE("current_player_path is %s", current_player_path);
224 ad->launch_type = MP_LAUNCH_ADD_TO_HOME;
225 ad->loadtype = LOAD_TRACK;
227 IF_FREE(ad->request_playing_path);
228 ad->request_playing_path = g_strdup(current_player_path);
235 static Eina_Bool _mp_main_win_visibility_change_cb(void *data, int type, void *event)
237 struct appdata *ad = (struct appdata *)data;
238 mp_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is null");
240 Ecore_X_Event_Window_Visibility_Change* ev = (Ecore_X_Event_Window_Visibility_Change *)event;
241 mp_debug("## Type=[%d], win=[%d], fully_obscured=[%d] ##", type, ev->win, ev->fully_obscured);
243 if (ev->win == ad->xwin) {
245 if (ev->fully_obscured == 1) {
246 mp_debug("hide main window");
247 mp_player_mgr_vol_type_unset();
249 ad->app_is_foreground = false;
251 mp_debug("show main window");
252 mp_player_mgr_vol_type_set();
253 ad->app_is_foreground = true;
257 return ECORE_CALLBACK_PASS_ON;
260 static Eina_Bool _mp_main_win_focus_in_cb(void *data, int type, void *event)
263 struct appdata *ad = (struct appdata *)data;
264 mp_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is null");
267 Ecore_X_Event_Window_Focus_In *ev = (Ecore_X_Event_Window_Focus_In *)event;
268 if (ev->win == ad->xwin) {
269 ad->is_focus_out = false;
270 if (ad->win_minicon && ad->b_minicontroller_show)
271 mp_minicontroller_destroy(ad);
273 #ifndef MP_SOUND_PLAYER
274 int db_state = VCONFKEY_FILEMANAGER_DB_UPDATED;
275 vconf_get_int(VCONFKEY_FILEMANAGER_DB_STATUS, &db_state);
276 if(db_state == VCONFKEY_FILEMANAGER_DB_UPDATING)
278 DEBUG_TRACE("update list");
279 mp_view_manager_update_list_contents(mp_util_get_view_data(ad), true);
284 if (ad->playing_view && ad->playing_view->layout && !ad->ug) {
285 mp_volume_key_grab_start(ad->xwin);
288 return ECORE_CALLBACK_PASS_ON;
291 static void _show_minicontroller(struct appdata *ad)
293 ad->is_focus_out = true;
294 if (ad->player_state == PLAY_STATE_PAUSED || ad->player_state == PLAY_STATE_PLAYING)
296 if (!ad->win_minicon)
297 mp_minicontroller_create(ad);
299 mp_minicontroller_show(ad);
303 static Eina_Bool _mp_main_win_focus_out_cb(void *data, int type, void *event)
306 struct appdata *ad = (struct appdata *)data;
307 mp_retvm_if(ad == NULL, ECORE_CALLBACK_CANCEL, "ad is null");
310 Ecore_X_Event_Window_Focus_Out *ev = (Ecore_X_Event_Window_Focus_Out *)event;
311 if (ev->win == ad->xwin) {
312 /* Testing Code. If a track is getting played or paused,
313 the MiniController should be displayed as soon as the main window goes to back ground.
314 When again the Music ICon in Main menu is pressed, the mini controller will be hidden and
315 The Main Screen of the Music Application will be displayed. */
316 _show_minicontroller(ad);
320 mp_volume_key_grab_end();
322 return ECORE_CALLBACK_PASS_ON;
325 static Eina_Bool _mp_main_client_message_cb(void *data, int type, void *event)
327 struct appdata *ad = data;
330 Ecore_X_Event_Client_Message *ev =
331 (Ecore_X_Event_Client_Message *) event;
334 if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE)
336 new_angle = ev->data.l[0];
337 DEBUG_TRACE("ROTATION: %d", new_angle);
338 mp_minicontroller_rotate(ad, new_angle);
340 else if (ev->message_type == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_STATE)
342 bool visible = false;
343 if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON)
345 mp_debug("quickpanel show");
350 mp_debug("quickpanel hide");
353 mp_minicontroller_visible_set(ad, visible);
356 return ECORE_CALLBACK_PASS_ON;
359 static void __mp_main_lcd_state_changed_cb(power_state_e state, void *user_data)
361 DEBUG_TRACE("power_state: %d", state);
363 struct appdata *ad = user_data;
366 if(state == POWER_STATE_SCREEN_OFF){
367 ad->is_lcd_off = true;
368 #ifdef MP_SOUND_PLAYER
369 mp_play_view_progress_timer_freeze(ad);
371 mp_view_manager_freeze_progress_timer(ad);
373 }else if(state == POWER_STATE_NORMAL){
374 ad->is_lcd_off = false;
375 /* for refresh progressbar */
376 ad->music_pos = mp_player_mgr_get_position() / 1000.0;
377 ad->music_length = mp_player_mgr_get_duration() / 1000.0;
378 #ifdef MP_SOUND_PLAYER
379 mp_play_view_progress_timer_thaw(ad);
381 mp_view_manager_thaw_progress_timer(ad);
387 Eina_Bool __mp_main_app_prop_change(void *data, int ev_type, void *ev)
390 Ecore_X_Event_Window_Property *event = ev;
392 if (event->win != ecore_x_window_root_first_get())
393 return ECORE_CALLBACK_PASS_ON;
395 if (event->atom != ecore_x_atom_get("FONT_TYPE_change"))
396 return ECORE_CALLBACK_PASS_ON;
398 DEBUG_TRACE("Font is changed!(FONT_TYPE_change)\n");
400 //We have a config(font) changed property. Here you can apply to new fonts
402 return ECORE_CALLBACK_PASS_ON;
406 _mp_main_app_init_idler_cb(void *data)
409 struct appdata *ad = data;
412 if (!mp_app_noti_init(ad))
414 ERROR_TRACE("Error when noti init");
417 ad->key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, mp_app_key_down_cb, ad);
418 ad->key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, mp_app_key_up_cb, ad);
419 ad->mouse_button_down = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, mp_app_mouse_event_cb, ad);
420 ad->mouse_button_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, mp_app_mouse_event_cb, ad);
421 ad->mouse_move = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, mp_app_mouse_event_cb, ad);
422 /* window visibility change event */
423 ad->visibility_change = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE, _mp_main_win_visibility_change_cb, ad);
424 /* window focus in/out event */
425 ad->focus_in = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_IN, _mp_main_win_focus_in_cb, ad);
426 ad->focus_out = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_OUT, _mp_main_win_focus_out_cb, ad);
427 ad->client_msg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _mp_main_client_message_cb, ad);
428 ad->property = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, __mp_main_app_prop_change, ad);
430 #ifdef MP_ENABLE_INOTIFY
431 mp_app_inotify_init(ad);
434 ad->app_init_idler = NULL;
437 #ifdef MP_FEATURE_AUTO_OFF
438 mp_setting_auto_off_set_callback(mp_app_auto_off_changed_cb, ad);
441 #ifdef MP_FEATURE_PLAY_SPEED
442 mp_setting_reset_play_speed();
443 mp_setting_set_play_speed_change_callback(mp_app_play_speed_changed_cb, ad);
446 power_set_changed_cb(__mp_main_lcd_state_changed_cb, ad);
451 return ECORE_CALLBACK_CANCEL;
454 static bool __mp_main_service_extra_data_cb(service_h service, const char *key, void *user_data)
456 MP_CHECK_FALSE(service);
458 service_get_extra_data(service, key, &value);
459 DEBUG_TRACE("key: %s, value: %s", key, value);
466 #ifdef MP_FEATURE_EXIT_ON_BACK
468 _mp_main_caller_win_destroy_cb(void *data, int type, void *event)
471 Ecore_X_Event_Window_Hide *ev;
472 struct appdata *ad = data;
473 MP_CHECK_VAL(ad, ECORE_CALLBACK_RENEW);
477 DEBUG_TRACE("ev is NULL");
478 return ECORE_CALLBACK_RENEW;
480 //DEBUG_TRACE("win: %d, caller_win: %d", ev->win ,ad->caller_win_id);
481 if(ev->win == ad->caller_win_id) {
485 return ECORE_CALLBACK_RENEW;
491 _mp_main_parse_service(struct appdata *ad, service_h service, char **request_title, char **path, int *lunching_by_menu_icon, bool *activate_window)
494 MP_CHECK_VAL(service, -1);
496 service_foreach_extra_data(service, __mp_main_service_extra_data_cb, NULL);
498 #ifdef MP_SOUND_PLAYER
499 if (!service_get_extra_data(service, MP_REQ_TYPE, &value))
501 DEBUG_TRACE("launch by S Voice app. req tyep: %s", value);
503 else if(mp_util_get_uri_from_app_svc(service, ad, path))
505 DEBUG_TRACE("uri: %s", *path);
508 ERROR_TRACE("No uri...");
510 #ifdef MP_FEATURE_EXIT_ON_BACK
511 if(ad->caller_win_id)
513 DEBUG_TRACE("unset transient for win: 0x%x", ad->caller_win_id);
514 ecore_x_icccm_transient_for_unset(elm_win_xwindow_get(ad->win_main));
515 ecore_event_handler_del(ad->callerWinEventHandler);
516 ad->caller_win_id = 0;
517 ad->callerWinEventHandler = NULL;
521 service_get_window(service, &id);
522 service_get_extra_data(service, MP_EXIT_ON_BACK, &value);
524 DEBUG_TRACE("Caller window id: 0x%x, ExitOnBack: %s", id, value);
525 if(id && value && !strcasecmp(value, "true"))
527 ecore_x_icccm_transient_for_set(elm_win_xwindow_get(ad->win_main), id);
528 ecore_x_window_client_manage(id);
530 ad->callerWinEventHandler =
531 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY,
532 _mp_main_caller_win_destroy_cb, ad);
533 ad->caller_win_id = id;
540 *activate_window = true;
542 if(!service_get_extra_data(service, "shortcut", &uri))
546 mp_debug("uri = %s", uri);
547 *lunching_by_menu_icon = 1;
551 else if (!service_get_extra_data(service, MP_REQ_TYPE, &value))
558 if(!service_get_extra_data(service, MP_MM_KEY, &value))
560 DEBUG_TRACE("mm key event, ad->player_state : %d", ad->player_state);
561 *activate_window = false;
562 if(ad->player_state == PLAY_STATE_PAUSED)
564 ad->launch_type = MP_LAUNCH_DEFAULT;
565 ad->loadtype = LOAD_DEFAULT;
566 mp_play_control_play_pause(ad, true);
570 ad->launch_type = MP_LAUNCH_PLAY_RECENT;
571 ad->loadtype = LOAD_MM_KEY;
574 mp_media_list_h media = NULL;
576 *activate_window = false;
577 mp_media_info_list_count(MP_TRACK_BY_PLAYED_TIME, NULL, NULL, NULL, 0, &count);
580 mp_media_info_list_count(MP_TRACK_ALL, NULL, NULL, NULL, 0, &count);
581 mp_media_info_list_create(&media, MP_TRACK_ALL, NULL, NULL, NULL, 0, 0, count);
584 mp_media_info_list_create(&media, MP_TRACK_BY_PLAYED_TIME, NULL, NULL, NULL, 0, 0, count);
586 mp_util_append_media_list_item_to_playlist(ad->playlist_mgr, media, count, 0, NULL);
587 mp_media_info_list_destroy(media);
601 ERROR_TRACE("%%%%%%%%%%%%%%%%%%%%%");
602 ERROR_TRACE("#exit() invoked. music-player is exiting");
603 ERROR_TRACE("%%%%%%%%%%%%%%%%%%%%%");
607 _mp_playlist_item_change_callback(mp_plst_item *item, void *userdata)
609 struct appdata *ad = userdata;
612 if(ad->current_track_info)
614 mp_util_free_track_info(ad->current_track_info);
615 ad->current_track_info = NULL;
620 mp_util_load_track_info(ad, item, &ad->current_track_info);
621 #ifdef MP_FEATURE_AVRCP_13
622 mp_avrcp_noti_track(ad->current_track_info->title,
623 ad->current_track_info->artist, ad->current_track_info->album,
624 ad->current_track_info->genre, ad->current_track_info->duration);
630 /**< Called before main loop */
632 mp_create(void *data)
634 struct appdata *ad = data;
636 atexit(_mp_atexit_cb);
638 MP_CHECK_VAL(ad, EINA_FALSE);
640 TA_S(0, "mp_create");
642 TA_S(1, "elm_theme_extension_add");
643 /* do extension add before add elm object.*/
644 elm_theme_extension_add(NULL, THEME_NAME);
645 TA_E(1,"elm_theme_extension_add");
647 TA_S(1, "bindtextdomain");
648 bindtextdomain(DOMAIN_NAME, LOCALE_DIR);
649 DEBUG_TRACE("DOMAIN_NAME: %s, LOCALE_DIR: %s", DOMAIN_NAME, LOCALE_DIR);
650 TA_E(1,"bindtextdomain");
652 TA_S(1, "mp_create_win");
653 ad->win_main = mp_create_win(GET_SYS_STR("IDS_COM_BODY_MUSIC"));
654 mp_retv_if(ad->win_main == NULL, EINA_FALSE);
655 elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
656 evas_event_callback_add(evas_object_evas_get(ad->win_main), EVAS_CALLBACK_RENDER_FLUSH_POST,
657 _mp_evas_flush_post, ad);
658 ad->xwin = elm_win_xwindow_get(ad->win_main);
659 TA_E(1,"mp_create_win");
661 TA_S(1, "mp_widget_create_bgimg");
662 ad->bgimage = mp_widget_create_bgimg(ad->win_main);
663 ad->evas = evas_object_evas_get(ad->win_main);
664 TA_E(1,"mp_widget_create_bgimg");
666 TA_S(1, "mp_player_mgr_session_init");
667 /*initialize session type */
668 if (!mp_player_mgr_session_init())
670 ERROR_TRACE("Error when set session");
673 TA_E(1,"mp_player_mgr_session_init");
675 TA_S(1, "mp_setting_init");
677 TA_E(1,"mp_setting_init");
679 TA_S(1, "_mp_main_init");
680 if (!_mp_main_init(ad))
682 ERROR_TRACE("Fail when init music");
685 TA_E(1,"_mp_main_init");
688 #ifdef ENABLE_RICHINFO
692 TA_S(1, "mp_http_mgr_create");
693 mp_http_mgr_create(ad);
694 TA_E(1,"mp_http_mgr_create");
697 TA_S(1, "mp_playlist_mgr_create");
698 ad->playlist_mgr = mp_playlist_mgr_create();
699 mp_playlist_mgr_set_item_change_callback(ad->playlist_mgr, _mp_playlist_item_change_callback, ad);
701 mp_setting_get_shuffle_state(&val);
702 mp_playlist_mgr_set_shuffle(ad->playlist_mgr, val);
703 #ifdef MP_SOUND_PLAYER
704 val = MP_SETTING_REP_NON;
706 mp_setting_get_repeat_state(&val);
708 mp_playlist_mgr_set_repeat(ad->playlist_mgr, val);
709 TA_E(1,"mp_playlist_mgr_create");
711 TA_S(1, "mp_language_mgr_create");
712 mp_language_mgr_create();
713 TA_E(1,"mp_language_mgr_create");
715 TA_S(1, "mp_conformant_add");
716 Evas_Object *conformant = elm_conformant_add(ad->win_main);
717 MP_CHECK_FALSE(conformant);
718 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
719 evas_object_show(conformant);
720 elm_win_resize_object_add(ad->win_main, conformant);
721 ad->conformant = conformant;
722 TA_E(1,"mp_conformant_add");
724 TA_E(0, "mp_create");
728 /**< Called after main loop */
730 mp_terminate(void *data)
732 struct appdata *ad = data;
736 mp_language_mgr_destroy();
737 mp_ecore_idler_del(ad->mss_startup_idler);
738 mp_ecore_idler_del(ad->bt_pause_idler);
739 mp_ecore_idler_del(ad->app_init_idler);
740 mp_ecore_idler_del(ad->popup_del_idler);
741 mp_ecore_timer_del(ad->longpress_timer);
742 #ifdef MP_FEATURE_AUTO_OFF
743 mp_ecore_timer_del(ad->auto_off_timer);
744 mp_ecore_timer_del(ad->pause_off_timer);
747 mp_app_ungrab_mm_keys(ad);
750 ecore_event_handler_del(ad->key_down);
752 ecore_event_handler_del(ad->key_up);
753 if (ad->mouse_button_down)
754 ecore_event_handler_del(ad->mouse_button_down);
755 if (ad->visibility_change) {
756 ecore_event_handler_del(ad->visibility_change);
757 ad->visibility_change = NULL;
760 ecore_event_handler_del(ad->focus_in);
764 ecore_event_handler_del(ad->focus_out);
765 ad->focus_out = NULL;
768 if (ad->player_state != PLAY_STATE_NONE)
770 mp_player_mgr_stop(ad);
771 mp_player_mgr_destroy(ad);
774 if (!mp_util_is_other_player_playing())
776 vconf_set_int(VCONFKEY_MUSIC_STATE, VCONFKEY_MUSIC_OFF);
778 mp_minicontroller_destroy(ad);
779 mp_player_mgr_vol_type_unset();
780 if (!mp_player_mgr_session_finish())
781 ERROR_TRACE("Error when set session");
782 #ifdef MP_ENABLE_INOTIFY
783 mp_app_inotify_finalize(ad);
785 mp_http_mgr_destory(ad);
787 mp_media_info_disconnect();
789 #ifdef ENABLE_RICHINFO
792 mp_setting_deinit(ad);
793 if (!mp_app_noti_ignore())
794 ERROR_TRACE("Error when ignore noti");
797 #ifdef MP_SOUND_PLAYER
798 sp_view_mgr_destroy(ad->view_mgr);
803 MP_TA_ACUM_ITEM_SHOW_RESULT_TO(MP_TA_SHOW_FILE);
806 mp_lyric_mgr_destory(ad);
815 /**< Called when every window goes back */
824 /**< Called when any window comes on top */
826 mp_resume(void *data)
833 /**< Called at the first idler and relaunched by AUL*/
835 mp_service(service_h service, void *data)
839 struct appdata *ad = data;
840 mp_ret_if(ad == NULL);
842 if(ad->app_is_foreground)
844 DEBUG_TRACE("relaunch is not allowed");
845 elm_win_activate(ad->win_main);
849 ad->app_is_foreground = true;
851 TA_S(0, "mp_service");
853 TA_S(1, "_mp_main_is_launching_available");
854 if (!_mp_main_is_launching_available(ad))
856 TA_E(1,"_mp_main_is_launching_available");
858 char *request_title = NULL;
859 int lunching_by_menu_icon = 0;
861 bool activate_window = true;
863 ad->launch_type = MP_LAUNCH_DEFAULT;
864 ad->loadtype = LOAD_DEFAULT;
866 TA_S(1, "_mp_main_parse_service");
867 if(_mp_main_parse_service(ad, service, &request_title, &path, &lunching_by_menu_icon, &activate_window))
869 ERROR_TRACE("Error: _mp_main_parse_service");
873 TA_E(1,"_mp_main_parse_service");
875 #ifdef MP_SOUND_PLAYER
877 _mp_main_set_current_playing_item(ad, path);
886 IF_FREE(ad->latest_playing_key_id);
887 if (!ad->base_layout_main) {
889 ad->base_layout_main = mp_widget_create_layout_main(ad->conformant);
890 elm_object_content_set(ad->conformant, ad->base_layout_main);
892 ad->loadtype = LOAD_TRACK;
893 /* create base navi bar */
894 Evas_Object *navibar = mp_widget_navigation_new(ad->base_layout_main, ad);
895 elm_object_part_content_set(ad->base_layout_main, "elm.swallow.content", navibar);
897 ad->view_mgr = sp_view_mgr_create(navibar);
898 ad->naviframe = navibar;
902 mp_play_view_load(ad);
903 ad->paused_by_user = FALSE;
905 mp_play_new_file(data, TRUE);
910 if (lunching_by_menu_icon)
911 _mp_main_create_view_by_item(ad, path);
914 _mp_main_set_current_playing_item(ad, path);
915 IF_FREE(ad->request_playing_path);
916 ad->request_playing_path = g_strdup(path);
921 DEBUG_TRACE("ad->launch_type:%d, ad->loadtype:%d", ad->launch_type, ad->loadtype);
923 if (ad->launch_type != MP_LAUNCH_DEFAULT)
926 mp_popup_destroy(ad);
928 //destroy info view..
929 mp_view_manager_pop_info_view(ad);
932 mp_ug_destory_all(ad);
936 TA_S(1, "mp_library_create");
937 if (ad->base_layout_main == NULL)
938 mp_library_create(ad);
939 TA_E(1, "mp_library_create");
941 if (ad->launch_type != MP_LAUNCH_DEFAULT &&
942 (ad->loadtype == LOAD_TRACK))
944 IF_FREE(ad->latest_playing_key_id);
945 ad->load_play_view = true;
947 ad->b_add_tracks = 0;
948 elm_toolbar_item_selected_set(ad->library->ctltab_songs, EINA_TRUE);
949 Evas_Object *layout = mp_view_manager_get_last_view_layout(ad);
950 mp_view_layout_set_edit_mode(mp_util_get_layout_data(layout), false);
952 if(ad->loadtype == LOAD_TRACK)
954 mp_play_view_load_by_path(ad, ad->request_playing_path);
958 mp_play_view_load_and_play(ad, NULL, FALSE);
961 IF_FREE(ad->request_playing_path);
963 ad->paused_by_user = FALSE;
966 else if(ad->loadtype == LOAD_MM_KEY)
968 ad->launch_type = MP_LAUNCH_DEFAULT;
969 ad->loadtype= LOAD_DEFAULT;
970 mp_play_new_file(ad, TRUE);
971 _show_minicontroller(ad);
976 TA_S(1, "evas_object_show");
977 evas_object_show(ad->win_main);
978 TA_E(1,"evas_object_show");
982 DEBUG_TRACE("activate window");
983 TA_S(1, "elm_win_activate");
984 elm_win_activate(ad->win_main);
985 TA_E(1,"elm_win_activate");
989 evas_object_hide(ad->win_main);
990 ad->app_is_foreground = false;
991 elm_win_iconified_set(ad->win_main, EINA_TRUE);
994 TA_S(1, "mp_player_mgr_vol_type_set");
995 mp_player_mgr_vol_type_set();
996 TA_E(1,"mp_player_mgr_vol_type_set");
998 TA_E(0,"MP-LAUNCH_TIME");
999 TA_E(0,"mp_service");
1007 mp_low_battery(void *data)
1009 struct appdata *ad = (struct appdata *)data;
1012 if (mp_check_battery_available())
1020 mp_device_orientation_cb(app_device_orientation_e orientation, void *user_data)
1022 struct appdata *ad = user_data;
1028 __mp_language_changed_cb(void *user_data)
1031 struct appdata *ad = user_data;
1032 mp_popup_destroy(ad);
1033 #ifndef MP_SOUND_PLAYER
1034 mp_view_manager_pop_info_view(ad);
1036 mp_ug_destory_all(ad);
1037 mp_language_mgr_update();
1041 main(int argc, char *argv[])
1044 app_event_callback_s event_callbacks;
1046 event_callbacks.create = mp_create;
1047 event_callbacks.terminate = mp_terminate;
1048 event_callbacks.pause = mp_pause;
1049 event_callbacks.resume = mp_resume;
1050 event_callbacks.service = mp_service;
1051 event_callbacks.low_memory = NULL;
1052 event_callbacks.low_battery = mp_low_battery;
1053 event_callbacks.device_orientation = mp_device_orientation_cb;
1054 event_callbacks.language_changed = __mp_language_changed_cb;
1055 event_callbacks.region_format_changed = NULL;
1057 DEBUG_TRACE(" starting music main");
1060 TA_S(0, "MP-LAUNCH_TIME");
1061 memset(&ad, 0x0, sizeof(struct appdata));
1062 return app_efl_main(&argc, &argv, &event_callbacks, &ad);