1 #include <Elementary.h>
8 typedef struct _Widget_Data Widget_Data;
28 static const char *widtype = NULL;
30 static const char SIG_FORWARD_CLICKED[] = "forward,clicked";
31 static const char SIG_INFO_CLICKED[] = "info,clicked";
32 static const char SIG_NEXT_CLICKED[] = "next,clicked";
33 static const char SIG_PAUSE_CLICKED[] = "pause,clicked";
34 static const char SIG_PLAY_CLICKED[] = "play,clicked";
35 static const char SIG_PREV_CLICKED[] = "prev,clicked";
36 static const char SIG_REWIND_CLICKED[] = "rewind,clicked";
37 static const char SIG_STOP_CLICKED[] = "stop,clicked";
39 static const Evas_Smart_Cb_Description _signals[] = {
40 { SIG_FORWARD_CLICKED, "" },
41 { SIG_INFO_CLICKED, "" },
42 { SIG_NEXT_CLICKED, "" },
43 { SIG_PAUSE_CLICKED, "" },
44 { SIG_PLAY_CLICKED, "" },
45 { SIG_PREV_CLICKED, "" },
46 { SIG_REWIND_CLICKED, "" },
47 { SIG_STOP_CLICKED, "" },
51 static void _del_hook(Evas_Object *obj);
52 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
53 static void _theme_hook(Evas_Object *obj);
54 static void _sizing_eval(Evas_Object *obj);
55 static void _on_focus_hook(void *data, Evas_Object *obj);
56 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
57 Evas_Callback_Type type, void *event_info);
60 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
62 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
63 Evas_Event_Key_Down *ev = event_info;
64 Widget_Data *wd = elm_widget_data_get(obj);
65 if (!wd) return EINA_FALSE;
66 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
67 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
68 if (!wd->video) return EINA_FALSE;
69 if ((!strcmp(ev->keyname, "Left")) ||
70 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
74 current = elm_video_play_position_get(wd->video);
75 last = elm_video_play_length_get(wd->video);
79 current += last / 100;
80 elm_video_play_position_set(wd->video, current);
83 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
86 if ((!strcmp(ev->keyname, "Right")) ||
87 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
91 current = elm_video_play_position_get(wd->video);
92 last = elm_video_play_length_get(wd->video);
96 current -= last / 100;
97 if (current < 0) current = 0;
98 elm_video_play_position_set(wd->video, current);
101 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
104 if (!strcmp(ev->keyname, "space"))
106 if (elm_video_is_playing_get(wd->video))
107 elm_video_pause(wd->video);
109 elm_video_play(wd->video);
110 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
113 fprintf(stderr, "keyname: '%s' not handle\n", ev->keyname);
118 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
120 Widget_Data *wd = elm_widget_data_get(obj);
122 if (elm_widget_focus_get(obj))
124 edje_object_signal_emit(wd->layout, "elm,action,focus", "elm");
125 evas_object_focus_set(wd->layout, EINA_TRUE);
129 edje_object_signal_emit(wd->layout, "elm,action,unfocus", "elm");
130 evas_object_focus_set(wd->layout, EINA_FALSE);
135 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
137 Widget_Data *wd = elm_widget_data_get(obj);
139 edje_object_mirrored_set(wd->layout, rtl);
143 _theme_hook(Evas_Object *obj)
145 Widget_Data *wd = elm_widget_data_get(obj);
147 _elm_widget_mirrored_reload(obj);
148 _mirrored_set(obj, elm_widget_mirrored_get(obj));
149 _elm_theme_object_set(obj, wd->layout, "video", "base", elm_widget_style_get(obj));
150 edje_object_scale_set(wd->layout, elm_widget_scale_get(obj) *
153 #define UPDATE_THEME(Obj, Target, Layout, Name) \
156 elm_object_style_set(Target, elm_widget_style_get(Obj)); \
157 if (!edje_object_part_swallow(Layout, Name, Target)) \
158 evas_object_hide(Target); \
159 elm_object_disabled_set(Target, elm_widget_disabled_get(Obj)); \
162 UPDATE_THEME(obj, wd->forward, wd->layout, "media_player/forward");
163 UPDATE_THEME(obj, wd->info, wd->layout, "media_player/info");
164 UPDATE_THEME(obj, wd->next, wd->layout, "media_player/next");
165 UPDATE_THEME(obj, wd->pause, wd->layout, "media_player/pause");
166 UPDATE_THEME(obj, wd->play, wd->layout, "media_player/play");
167 UPDATE_THEME(obj, wd->prev, wd->layout, "media_player/prev");
168 UPDATE_THEME(obj, wd->rewind, wd->layout, "media_player/rewind");
169 UPDATE_THEME(obj, wd->next, wd->layout, "media_player/next");
170 UPDATE_THEME(obj, wd->slider, wd->layout, "media_player/slider");
176 _sizing_eval(Evas_Object *obj)
178 Widget_Data *wd = elm_widget_data_get(obj);
182 edje_object_size_min_get(wd->layout, &w, &h);
183 edje_object_size_min_restricted_calc(wd->layout, &w, &h, w, h);
184 evas_object_size_hint_min_set(obj, w, h);
188 _update_slider(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
190 Evas_Object *player = data;
191 Widget_Data *wd = elm_widget_data_get(player);
196 seekable = elm_video_is_seekable_get(wd->video);
197 length = elm_video_play_length_get(wd->video);
198 pos = elm_video_play_position_get(wd->video);
200 elm_object_disabled_set(wd->slider, !seekable);
201 elm_slider_min_max_set(wd->slider, 0, length);
202 elm_slider_value_set(wd->slider, pos);
206 _update_position(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
208 Evas_Object *player = data;
209 Widget_Data *wd = elm_widget_data_get(player);
212 elm_video_play_position_set(wd->video, elm_slider_value_get(wd->slider));
216 _forward(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
218 Evas_Object *player = data;
219 Widget_Data *wd = elm_widget_data_get(player);
224 pos = elm_video_play_position_get(wd->video);
225 length = elm_video_play_length_get(wd->video);
228 elm_video_play_position_set(wd->video, pos);
230 edje_object_signal_emit(wd->layout, "elm,button,forward", "elm");
231 evas_object_smart_callback_call(player, SIG_FORWARD_CLICKED, NULL);
235 _info(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
237 Evas_Object *player = data;
238 Widget_Data *wd = elm_widget_data_get(player);
242 edje_object_signal_emit(wd->layout, "elm,button,info", "elm");
243 evas_object_smart_callback_call(player, SIG_INFO_CLICKED, NULL);
247 _next(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
249 Evas_Object *player = data;
250 Widget_Data *wd = elm_widget_data_get(player);
255 pos = elm_video_play_position_get(wd->video);
256 length = elm_video_play_length_get(wd->video);
259 elm_video_play_position_set(wd->video, pos);
261 edje_object_signal_emit(wd->layout, "elm,button,next", "elm");
262 evas_object_smart_callback_call(player, SIG_NEXT_CLICKED, NULL);
266 _pause(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
268 Evas_Object *player = data;
269 Widget_Data *wd = elm_widget_data_get(player);
273 edje_object_signal_emit(wd->layout, "elm,player,pause", "elm");
274 elm_video_pause(wd->video);
276 edje_object_signal_emit(wd->layout, "elm,button,pause", "elm");
277 evas_object_smart_callback_call(player, SIG_PAUSE_CLICKED, NULL);
281 _play(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
283 Evas_Object *player = data;
284 Widget_Data *wd = elm_widget_data_get(player);
287 elm_video_play(wd->video);
288 edje_object_signal_emit(wd->layout, "elm,button,play", "elm");
289 evas_object_smart_callback_call(player, SIG_PLAY_CLICKED, NULL);
293 _prev(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
295 Evas_Object *player = data;
296 Widget_Data *wd = elm_widget_data_get(player);
301 pos = elm_video_play_position_get(wd->video);
302 length = elm_video_play_length_get(wd->video);
305 elm_video_play_position_set(wd->video, pos);
306 evas_object_smart_callback_call(player, SIG_PREV_CLICKED, NULL);
307 edje_object_signal_emit(wd->layout, "elm,button,prev", "elm");
311 _rewind(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
313 Evas_Object *player = data;
314 Widget_Data *wd = elm_widget_data_get(player);
317 elm_video_play_position_set(wd->video, 0);
318 edje_object_signal_emit(wd->layout, "elm,button,rewind", "elm");
319 evas_object_smart_callback_call(player, SIG_REWIND_CLICKED, NULL);
323 _stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
325 Evas_Object *player = data;
326 Widget_Data *wd = elm_widget_data_get(player);
330 edje_object_signal_emit(wd->layout, "elm,button,stop", "elm");
331 evas_object_smart_callback_call(player, SIG_STOP_CLICKED, NULL);
335 _play_started(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
337 Evas_Object *player = data;
338 Widget_Data *wd = elm_widget_data_get(player);
342 edje_object_signal_emit(wd->layout, "elm,player,play", "elm");
346 _play_finished(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
348 Evas_Object *player = data;
349 Widget_Data *wd = elm_widget_data_get(player);
353 edje_object_signal_emit(wd->layout, "elm,player,pause", "elm");
357 _cleanup_callback(Widget_Data *wd)
359 if (!wd || !wd->emotion) return;
361 evas_object_smart_callback_del(wd->emotion, "frame_decode",
363 evas_object_smart_callback_del(wd->emotion, "frame_resize",
365 evas_object_smart_callback_del(wd->emotion, "length_change",
367 evas_object_smart_callback_del(wd->emotion, "position_update",
369 evas_object_smart_callback_del(wd->emotion, "playback_started",
371 evas_object_smart_callback_del(wd->emotion, "playback_finished",
373 elm_object_disabled_set(wd->slider, EINA_TRUE);
374 elm_object_disabled_set(wd->forward, EINA_TRUE);
375 elm_object_disabled_set(wd->info, EINA_TRUE);
376 elm_object_disabled_set(wd->next, EINA_TRUE);
377 elm_object_disabled_set(wd->pause, EINA_TRUE);
378 elm_object_disabled_set(wd->play, EINA_TRUE);
379 elm_object_disabled_set(wd->prev, EINA_TRUE);
380 elm_object_disabled_set(wd->rewind, EINA_TRUE);
381 elm_object_disabled_set(wd->next, EINA_TRUE);
387 _track_video(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
389 _cleanup_callback(data);
393 _del_hook(Evas_Object *obj)
395 Widget_Data *wd = elm_widget_data_get(obj);
398 evas_object_smart_callback_del(wd->forward, "clicked", _forward);
399 evas_object_smart_callback_del(wd->info, "clicked", _info);
400 evas_object_smart_callback_del(wd->next, "clicked", _next);
401 evas_object_smart_callback_del(wd->pause, "clicked", _pause);
402 evas_object_smart_callback_del(wd->play, "clicked", _play);
403 evas_object_smart_callback_del(wd->prev, "clicked", _prev);
404 evas_object_smart_callback_del(wd->rewind, "clicked", _rewind);
405 evas_object_smart_callback_del(wd->next, "clicked", _next);
406 _cleanup_callback(wd);
411 _player_button_add(Evas_Object *parent, Evas_Object *obj, Evas_Object *layout, const char *name, Evas_Smart_Cb func)
416 ic = elm_icon_add(parent);
417 elm_icon_standard_set(ic, name);
418 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
419 bt = elm_button_add(parent);
420 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
421 elm_object_part_content_set(bt, "icon", ic);
422 evas_object_size_hint_align_set(bt, 0.0, 0.0);
423 elm_object_style_set(bt, "anchor");
424 evas_object_smart_callback_add(bt, "clicked", func, obj);
425 elm_widget_sub_object_add(obj, bt);
427 if (!edje_object_part_swallow(layout, name, bt))
428 evas_object_hide(bt);
433 _double_to_time(double value)
439 pm = value / 60 - (ph * 60);
440 ps = value - (pm * 60);
441 pf = value * 100 - (ps * 100) - (pm * 60 * 100) - (ph * 60 * 60 * 100);
443 snprintf(buf, sizeof(buf), "%i:%02i:%02i.%02i",
446 snprintf(buf, sizeof(buf), "%02i:%02i.%02i",
449 snprintf(buf, sizeof(buf), "%02i.%02i",
452 return (char *)eina_stringshare_add(buf);
456 _value_free(char *data)
458 eina_stringshare_del(data);
464 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
466 if (part && strcmp(part, "video")) return;
467 ELM_CHECK_WIDTYPE(obj, widtype);
468 Widget_Data *wd = elm_widget_data_get(obj);
473 if (!_elm_video_check(content)) return;
474 if (wd->video == content) return;
476 if (wd->video) evas_object_del(wd->video);
477 _cleanup_callback(wd);
487 elm_object_disabled_set(wd->slider, EINA_FALSE);
488 elm_object_disabled_set(wd->forward, EINA_FALSE);
489 elm_object_disabled_set(wd->info, EINA_FALSE);
490 elm_object_disabled_set(wd->next, EINA_FALSE);
491 elm_object_disabled_set(wd->pause, EINA_FALSE);
492 elm_object_disabled_set(wd->play, EINA_FALSE);
493 elm_object_disabled_set(wd->prev, EINA_FALSE);
494 elm_object_disabled_set(wd->rewind, EINA_FALSE);
495 elm_object_disabled_set(wd->next, EINA_FALSE);
497 wd->emotion = elm_video_emotion_get(wd->video);
498 emotion_object_priority_set(wd->emotion, EINA_TRUE);
499 evas_object_event_callback_add(wd->video, EVAS_CALLBACK_DEL,
502 seekable = elm_video_is_seekable_get(wd->video);
503 length = elm_video_play_length_get(wd->video);
504 pos = elm_video_play_position_get(wd->video);
506 elm_object_disabled_set(wd->slider, !seekable);
507 elm_slider_min_max_set(wd->slider, 0, length);
508 elm_slider_value_set(wd->slider, pos);
510 if (elm_video_is_playing_get(wd->video)) edje_object_signal_emit(wd->layout, "elm,player,play", "elm");
511 else edje_object_signal_emit(wd->layout, "elm,player,pause", "elm");
513 evas_object_smart_callback_add(wd->emotion, "frame_decode",
514 _update_slider, obj);
515 evas_object_smart_callback_add(wd->emotion, "frame_resize",
516 _update_slider, obj);
517 evas_object_smart_callback_add(wd->emotion, "length_change",
518 _update_slider, obj);
519 evas_object_smart_callback_add(wd->emotion, "position_update",
520 _update_slider, obj);
521 evas_object_smart_callback_add(wd->emotion, "playback_started",
523 evas_object_smart_callback_add(wd->emotion, "playback_finished",
524 _play_finished, obj);
526 /* FIXME: track info from video */
531 elm_player_add(Evas_Object *parent)
538 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
539 ELM_SET_WIDTYPE(widtype, "player");
540 elm_widget_type_set(obj, "player");
541 elm_widget_sub_object_add(parent, obj);
542 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
543 elm_widget_data_set(obj, wd);
544 elm_widget_del_hook_set(obj, _del_hook);
545 elm_widget_theme_hook_set(obj, _theme_hook);
546 elm_widget_can_focus_set(obj, EINA_TRUE);
547 elm_widget_event_hook_set(obj, _event_hook);
548 elm_widget_content_set_hook_set(obj, _content_set_hook);
549 /* TODO: add content_unset and content_get hook */
551 wd->layout = edje_object_add(e);
552 _elm_theme_object_set(obj, wd->layout, "player", "base", "default");
553 elm_widget_resize_object_set(obj, wd->layout);
554 elm_widget_sub_object_add(obj, wd->layout);
555 evas_object_show(wd->layout);
556 evas_object_size_hint_weight_set(wd->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
558 wd->forward = _player_button_add(parent, obj, wd->layout, "media_player/forward", _forward);
559 wd->info = _player_button_add(parent, obj, wd->layout, "media_player/info", _info);
560 wd->next = _player_button_add(parent, obj, wd->layout, "media_player/next", _next);
561 wd->pause = _player_button_add(parent, obj, wd->layout, "media_player/pause", _pause);
562 wd->play = _player_button_add(parent, obj, wd->layout, "media_player/play", _play);
563 wd->prev = _player_button_add(parent, obj, wd->layout, "media_player/prev", _prev);
564 wd->rewind = _player_button_add(parent, obj, wd->layout, "media_player/rewind", _rewind);
565 wd->stop = _player_button_add(parent, obj, wd->layout, "media_player/stop", _stop);
567 wd->slider = elm_slider_add(parent);
568 elm_widget_sub_object_add(obj, wd->slider);
569 elm_slider_indicator_format_function_set(wd->slider, _double_to_time, _value_free);
570 elm_slider_units_format_function_set(wd->slider, _double_to_time, _value_free);
571 elm_slider_min_max_set(wd->slider, 0, 0);
572 elm_slider_value_set(wd->slider, 0);
573 elm_object_disabled_set(wd->slider, EINA_TRUE);
574 evas_object_size_hint_align_set(wd->slider, EVAS_HINT_FILL, 0.5);
575 evas_object_size_hint_weight_set(wd->slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
576 edje_object_part_swallow(wd->layout, "media_player/slider", wd->slider);
577 evas_object_smart_callback_add(wd->slider, "changed", _update_position, obj);
582 _mirrored_set(obj, elm_widget_mirrored_get(obj));