<commit_before>/*
 * GeeXboX Enna Media Center.
 * Copyright (C) 2005-2009 The Enna Project
 *
 * This file is part of Enna.
 *
 * Enna is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Enna is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Enna; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * FIXME : Remove unused object and fix navigation : it's actually not possible
 * to return from video playback !
 * Fix state machine
 * Enable Position set
 * EOS is not used !!!!
 */

#include <Edje.h>
#include <Elementary.h>
#include <Ecore_Input.h>

#include "enna.h"
#include "enna_config.h"
#include "module.h"
#include "activity.h"
#include "content.h"
#include "image.h"
#include "mainmenu.h"
#include "logs.h"
#include "vfs.h"
#include "view_list.h"
#include "browser.h"
#include "mediaplayer.h"
#include "volumes.h"
#include "buffer.h"
#include "metadata.h"
#include "utils.h"
#include "mediaplayer_obj.h"

#include "video.h"
#include "video_flags.h"
#include "video_infos.h"
#include "video_resume.h"
#include "video_picture.h"

#define ENNA_MODULE_NAME "video"

#define TIMER_DELAY 10.0

static void browser_cb_root (void *data, Evas_Object *obj, void *event_info);
static void browser_cb_select (void *data, Evas_Object *obj, void *event_info);
static void browser_cb_hilight (void *data, Evas_Object *obj, void *event_info);
static void browse (void *data);

static void _create_menu(void);
static void _return_to_video_info_gui();

static int _eos_cb(void *data, int type, void *event);
static void video_infos_del (void);

typedef struct _Enna_Module_Video Enna_Module_Video;
typedef enum _VIDEO_STATE VIDEO_STATE;

enum _VIDEO_STATE
{
    MENU_VIEW,
    BROWSER_VIEW,
    VIDEOPLAYER_VIEW
};

struct _Enna_Module_Video
{
    Evas *e;
    Evas_Object *o_edje;
    Evas_Object *o_list;
    Evas_Object *o_browser;
    Evas_Object *o_backdrop;
    Evas_Object *o_snapshot;
    Evas_Object *o_panel_infos;
    Evas_Object *o_resume;
    Evas_Object *o_video_flags;
    Evas_Object *o_mediaplayer;
    Evas_Object *o_mediacontrols;
    Enna_Module *em;
    VIDEO_STATE state;
    Ecore_Event_Handler *eos_event_handler;
    Enna_Playlist *enna_playlist;
    char *o_current_uri;
    int infos_displayed;
    int resume_displayed;
    int controls_displayed;
    Enna_Volumes_Listener *vl;
    Ecore_Timer *controls_timer;
    Ecore_Event_Handler *mouse_button_event_handler;
    Ecore_Event_Handler *mouse_move_event_handler;
};

static Enna_Module_Video *mod;

static void
update_movies_counter (Eina_List *list)
{
    Enna_Vfs_File *f;
    Eina_List *l;
    int children = 0;
    char label[128] = { 0 };

    if (!list)
        goto end;

    EINA_LIST_FOREACH(list, l, f)
    {
        if (!f->is_directory && !f->is_menu)
            children++;
    }
    if (children)
        snprintf(label, sizeof(label), _("%d Movies"), children);
end:
    edje_object_part_text_set(mod->o_edje, "movies.counter.label", label);
}

static int
_controls_timer_cb(void *data)
{
    media_controls_display(0);
    mod->controls_timer = NULL;
    return 0;
}

void
media_controls_display (int show)
{
    Evas_Coord w, h, h2, x, y;

    if (show)
    {
        ENNA_TIMER_DEL(mod->controls_timer);
        mod->controls_timer = ecore_timer_add(TIMER_DELAY, _controls_timer_cb, NULL);
    }

    if (show == mod->controls_displayed)
        return;

    evas_object_geometry_get(mod->o_mediaplayer, &x, &y, &w, &h);
    evas_object_geometry_get(mod->o_mediacontrols, NULL, NULL, NULL, &h2);

    if (show)
    {
        enna_mediaplayer_video_resize(x, y, w, h - h2);
        mod->controls_displayed = 1;
    }
    else
    {
        enna_mediaplayer_video_resize(x, y, w, h);
        mod->controls_displayed = 0;
    }
}

static void
menu_view_event (enna_input event)
{
    switch (event)
    {
    case ENNA_INPUT_EXIT:
        enna_content_hide();
        enna_mainmenu_show();
        break;
    case ENNA_INPUT_OK:
        browse (enna_list_selected_data_get(mod->o_list));
        break;
    default:
        enna_list_input_feed(mod->o_list, event);
        break;
    }
}

static void
videoplayer_view_event (enna_input event)
{

    media_controls_display(1);

    switch (event)
    {
    case ENNA_INPUT_QUIT:
    case ENNA_INPUT_EXIT:
        _return_to_video_info_gui ();
        break;
    default:
        enna_mediaplayer_obj_input_feed(mod->o_mediacontrols, event);
        break;
    }
}

static void
popup_resume_display (int show)
{
    if (show)
    {<commit_msg>restore video key bindings, behavior is different whether controls are displayed or not<commit_after>/*
 * GeeXboX Enna Media Center.
 * Copyright (C) 2005-2009 The Enna Project
 *
 * This file is part of Enna.
 *
 * Enna is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Enna is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Enna; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * FIXME : Remove unused object and fix navigation : it's actually not possible
 * to return from video playback !
 * Fix state machine
 * Enable Position set
 * EOS is not used !!!!
 */

#include <Edje.h>
#include <Elementary.h>
#include <Ecore_Input.h>

#include "enna.h"
#include "enna_config.h"
#include "module.h"
#include "activity.h"
#include "content.h"
#include "image.h"
#include "mainmenu.h"
#include "logs.h"
#include "vfs.h"
#include "view_list.h"
#include "browser.h"
#include "mediaplayer.h"
#include "volumes.h"
#include "buffer.h"
#include "metadata.h"
#include "utils.h"
#include "mediaplayer_obj.h"

#include "video.h"
#include "video_flags.h"
#include "video_infos.h"
#include "video_resume.h"
#include "video_picture.h"

#define ENNA_MODULE_NAME "video"

#define TIMER_DELAY 10.0

static void browser_cb_root (void *data, Evas_Object *obj, void *event_info);
static void browser_cb_select (void *data, Evas_Object *obj, void *event_info);
static void browser_cb_hilight (void *data, Evas_Object *obj, void *event_info);
static void browse (void *data);

static void _create_menu(void);
static void _return_to_video_info_gui();

static int _eos_cb(void *data, int type, void *event);
static void video_infos_del (void);

typedef struct _Enna_Module_Video Enna_Module_Video;
typedef enum _VIDEO_STATE VIDEO_STATE;

enum _VIDEO_STATE
{
    MENU_VIEW,
    BROWSER_VIEW,
    VIDEOPLAYER_VIEW
};

struct _Enna_Module_Video
{
    Evas *e;
    Evas_Object *o_edje;
    Evas_Object *o_list;
    Evas_Object *o_browser;
    Evas_Object *o_backdrop;
    Evas_Object *o_snapshot;
    Evas_Object *o_panel_infos;
    Evas_Object *o_resume;
    Evas_Object *o_video_flags;
    Evas_Object *o_mediaplayer;
    Evas_Object *o_mediacontrols;
    Enna_Module *em;
    VIDEO_STATE state;
    Ecore_Event_Handler *eos_event_handler;
    Enna_Playlist *enna_playlist;
    char *o_current_uri;
    int infos_displayed;
    int resume_displayed;
    int controls_displayed;
    Enna_Volumes_Listener *vl;
    Ecore_Timer *controls_timer;
    Ecore_Event_Handler *mouse_button_event_handler;
    Ecore_Event_Handler *mouse_move_event_handler;
};

static Enna_Module_Video *mod;

static void
update_movies_counter (Eina_List *list)
{
    Enna_Vfs_File *f;
    Eina_List *l;
    int children = 0;
    char label[128] = { 0 };

    if (!list)
        goto end;

    EINA_LIST_FOREACH(list, l, f)
    {
        if (!f->is_directory && !f->is_menu)
            children++;
    }
    if (children)
        snprintf(label, sizeof(label), _("%d Movies"), children);
end:
    edje_object_part_text_set(mod->o_edje, "movies.counter.label", label);
}

static int
_controls_timer_cb(void *data)
{
    media_controls_display(0);
    mod->controls_timer = NULL;
    return 0;
}

void
media_controls_display (int show)
{
    Evas_Coord w, h, h2, x, y;

    if (show)
    {
        ENNA_TIMER_DEL(mod->controls_timer);
        mod->controls_timer = ecore_timer_add(TIMER_DELAY, _controls_timer_cb, NULL);
    }

    if (show == mod->controls_displayed)
        return;

    evas_object_geometry_get(mod->o_mediaplayer, &x, &y, &w, &h);
    evas_object_geometry_get(mod->o_mediacontrols, NULL, NULL, NULL, &h2);

    if (show)
    {
        enna_mediaplayer_video_resize(x, y, w, h - h2);
        mod->controls_displayed = 1;
    }
    else
    {
        enna_mediaplayer_video_resize(x, y, w, h);
        mod->controls_displayed = 0;
    }
}

static void
menu_view_event (enna_input event)
{
    switch (event)
    {
    case ENNA_INPUT_EXIT:
        enna_content_hide();
        enna_mainmenu_show();
        break;
    case ENNA_INPUT_OK:
        browse (enna_list_selected_data_get(mod->o_list));
        break;
    default:
        enna_list_input_feed(mod->o_list, event);
        break;
    }
}

static void
_seek_video(double value)
{
    int pos = 0;
    double seek = 0.0;

    pos = enna_mediaplayer_position_percent_get();
    seek = ((double) pos + value) / 100.0;
    enna_mediaplayer_seek(seek);

    enna_log(ENNA_MSG_EVENT, ENNA_MODULE_NAME, "Seek value : %f", seek);
}

static void
videoplayer_view_event_no_display (enna_input event)
{
    switch (event)
    {
    case ENNA_INPUT_OK:
        media_controls_display(!mod->controls_displayed);
        break;
    case ENNA_INPUT_SPACE:
        enna_mediaplayer_play(mod->enna_playlist);
        break;
    case ENNA_INPUT_RIGHT:
        _seek_video(+1);
        break;
    case ENNA_INPUT_LEFT:
        _seek_video(-1);
        break;
    case ENNA_INPUT_UP:
        _seek_video(+5);
        break;
    case ENNA_INPUT_DOWN:
        _seek_video(-5);
        break;
    case ENNA_INPUT_PLUS:
        enna_mediaplayer_default_increase_volume();
        break;
    case ENNA_INPUT_MINUS:
        enna_mediaplayer_default_decrease_volume();
        break;
    case ENNA_INPUT_KEY_M:
        enna_mediaplayer_mute();
        break;
    case ENNA_INPUT_KEY_K:
        enna_mediaplayer_audio_previous();
        break;
    case ENNA_INPUT_KEY_L:
        enna_mediaplayer_audio_next();
        break;
    case ENNA_INPUT_KEY_P:
        enna_mediaplayer_audio_increase_delay();
        break;
    case ENNA_INPUT_KEY_O:
        enna_mediaplayer_audio_decrease_delay();
        break;
    case ENNA_INPUT_KEY_S:
        enna_mediaplayer_subtitle_set_visibility();
        break;
    case ENNA_INPUT_KEY_G:
        enna_mediaplayer_subtitle_previous();
        break;
    case ENNA_INPUT_KEY_Y:
        enna_mediaplayer_subtitle_next();
        break;
    case ENNA_INPUT_KEY_A:
        enna_mediaplayer_subtitle_set_alignment();
        break;
    case ENNA_INPUT_KEY_T:
        enna_mediaplayer_subtitle_increase_position();
        break;
    case ENNA_INPUT_KEY_R:
        enna_mediaplayer_subtitle_decrease_position();
        break;
    case ENNA_INPUT_KEY_J:
        enna_mediaplayer_subtitle_increase_scale();
        break;
    case ENNA_INPUT_KEY_I:
        enna_mediaplayer_subtitle_decrease_scale();
        break;
    case ENNA_INPUT_KEY_X:
        enna_mediaplayer_subtitle_increase_delay();
        break;
    case ENNA_INPUT_KEY_Z:
        enna_mediaplayer_subtitle_decrease_delay();
        break;
    case ENNA_INPUT_KEY_W:
        enna_mediaplayer_set_framedrop();
        break;
    default:
        break;
    }
}

static void
videoplayer_view_event (enna_input event)
{
    switch (event)
    {
    case ENNA_INPUT_QUIT:
    case ENNA_INPUT_EXIT:
        _return_to_video_info_gui ();
        break;
    default:
        if (!mod->controls_displayed)
            videoplayer_view_event_no_display (event);
        else
        {
            media_controls_display(1);
            enna_mediaplayer_obj_input_feed(mod->o_mediacontrols, event);
        }
        break;
    }
}

static void
popup_resume_display (int show)
{
    if (show)
    {
{'fraction_non_alphanumeric': 0.09245342101142946, 'fraction_numerical': 0.006654141224361985, 'mean_word_length': 3.3452380952380953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4650278', 'n_tokens_mistral': 4605, 'n_tokens_neox': 4416, 'n_words': 1076}