minicontrol_view.c 7.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*****************************************************************************
 * Copyright © 2015-2016 VideoLAN, VideoLabs SAS
 *****************************************************************************
 *
 * Authors: Ludovic Fauvet <etix@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
/*
 * By committing to this project, you allow VideoLAN and VideoLabs to relicense
 * the code to a different OSI approved license, in case it is required for
 * compatibility with the Store
 *****************************************************************************/

#include "common.h"
#include "minicontrol_view.h"
#include "playback_service.h"
#include "ui/utils.h"

#include <minicontrol-provider.h>
33
#include <sys/time.h>
34 35 36 37

struct minicontrol
{
    playback_service *p_ps;
38
    application *p_app;
39 40 41 42 43 44 45 46
    Evas_Object *win;

    Evas_Object *layout;
    Evas_Object *play_button;
    Evas_Object *next_button;
    Evas_Object *prev_button;
    Evas_Object *cover;
    Evas_Object *progress;
47 48

    struct timeval button_last_event;
49 50
};

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
void
mini_control_update_next_prev(minicontrol *p_minicontrol, playback_service *p_ps)
{
    Evas_Object *edje = elm_layout_edje_get(p_minicontrol->layout);

    if (playback_service_has_next(p_ps))
        edje_object_signal_emit(edje, "swallow.next,show", "");
    else
        edje_object_signal_emit(edje, "swallow.next,hide", "");

    if (playback_service_has_prev(p_ps))
        edje_object_signal_emit(edje, "swallow.previous,show", "");
    else
        edje_object_signal_emit(edje, "swallow.previous,hide", "");
}

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
void
mini_control_visibility_set(minicontrol *mc, Eina_Bool visible)
{
    visible ? evas_object_show(mc->win) : evas_object_hide(mc->win);
}

void
mini_control_playing_set(minicontrol *mc, Eina_Bool playing)
{
    elm_image_file_set(mc->play_button, playing ? ICON_DIR "ic_pause_circle_normal_o.png" : ICON_DIR "ic_play_circle_normal_o.png", NULL);
}

void
mini_control_title_set(minicontrol *mc, const char* title)
{
    elm_object_part_text_set(mc->layout, "swallow.title", title);
}

void
mini_control_progress_set(minicontrol *mc, double progress)
{
    elm_slider_value_set(mc->progress, progress);
}

void
mini_control_cover_set(minicontrol *mc, const char* path)
{
    if (!path)
        elm_object_part_content_set(mc->layout, "swallow.cover", create_icon(mc->layout, "background_cone.png"));
    else
        elm_object_part_content_set(mc->layout, "swallow.cover", create_image(mc->layout, path));
}

100 101
long
elapsed_msec(struct timeval t0, struct timeval t1)
102
{
103 104
    return (t1.tv_sec - t0.tv_sec) +
            ((t1.tv_usec - t0.tv_usec)/1000000.0);
105 106 107
}

static void
108
mini_control_background_action_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
109 110
{
    minicontrol *mc = data;
111 112 113 114 115 116 117 118 119 120 121

    struct timeval t;
    gettimeofday(&t, 0);

    if (elapsed_msec(mc->button_last_event, t) <= 5)
        return;

    interface *p_intf = application_get_interface(mc->p_app);

    intf_raise(p_intf);
    playback_service_set_auto_exit(mc->p_ps, false);
122 123 124
}

static void
125
mini_control_action_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
126 127
{
    minicontrol *mc = data;
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

    if (obj == mc->play_button)
    {
        playback_service_toggle_play_pause(mc->p_ps);
    }
    else if (obj == mc->next_button)
    {
        playback_service_list_set_next(mc->p_ps);
    }
    else if (obj == mc->prev_button)
    {
        playback_service_list_set_prev(mc->p_ps);
    }
    else
    {
        return;
    }

    gettimeofday(&mc->button_last_event, 0);
147 148 149 150 151 152 153 154
}

// mini_control_event_cb doesn't provide an embedded opaque object...
static playback_service* ps = NULL;

static void
mini_control_event_cb(minicontrol_viewer_event_e event_type, bundle *event_arg)
{
155
    if (event_type == MINICONTROL_EVENT_REQUEST_HIDE)
156 157 158 159
        playback_service_stop_notify(ps, true);
}

minicontrol*
160
mini_control_view_create(playback_service *p_ps, application *p_app)
161 162 163
{
    minicontrol *mc = calloc(1, sizeof(*mc));
    mc->p_ps = p_ps;
164
    mc->p_app = p_app;
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    ps = p_ps;

    const Evas_Coord width = 720;
    const Evas_Coord height = 120;

    /* main widget */
    mc->win = minicontrol_create_window("quickpanel", MINICONTROL_TARGET_VIEWER_QUICK_PANEL, mini_control_event_cb);
    evas_object_resize(mc->win, width, height);
    evas_object_hide(mc->win);

    /* Create layout and set the theme */
    Evas_Object *wlayout = elm_layout_add(mc->win);
    evas_object_resize(wlayout, width, height);
    //elm_win_resize_object_add(mc->win, layout);
    elm_layout_theme_set(wlayout, "layout", "application", "default");
    evas_object_show(wlayout);

    /* Create the background */
    Evas_Object *bg = elm_bg_add(wlayout);
    elm_bg_color_set(bg, 255, 255, 255);
    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_show(bg);

    /* Set the background to the theme */
    elm_object_part_content_set(wlayout, "elm.swallow.bg", bg);

    /* */
    Evas_Object *layout = mc->layout = elm_layout_add(mc->win);
    elm_object_part_content_set(wlayout, "elm.swallow.content", layout);

    /* */
    elm_layout_file_set(layout, QUICKPANELCONTROLS_EDJ, "quick_panel_controls");
    evas_object_show(layout);

    mc->play_button = create_icon(layout, "ic_play_circle_normal_o.png");
    mc->next_button = create_icon(layout, "ic_widget_next_normal.png");
    mc->prev_button = create_icon(layout, "ic_widget_previous_normal.png");
    mc->cover = create_icon(layout, "background_cone.png");

    elm_object_part_content_set(layout, "swallow.play", mc->play_button);
    elm_object_part_content_set(layout, "swallow.cover", mc->cover);
    elm_object_part_content_set(layout, "swallow.previous", mc->prev_button);
    elm_object_part_content_set(layout, "swallow.next", mc->next_button);

210 211 212 213 214 215
    evas_object_event_callback_add(mc->play_button, EVAS_CALLBACK_MOUSE_UP, mini_control_action_cb, mc);
    evas_object_event_callback_add(mc->next_button, EVAS_CALLBACK_MOUSE_UP, mini_control_action_cb, mc);
    evas_object_event_callback_add(mc->prev_button, EVAS_CALLBACK_MOUSE_UP, mini_control_action_cb, mc);

    Evas_Object *edje = elm_layout_edje_get(layout);
    edje_object_signal_callback_add(edje, "mouse,clicked,1", "hub_background", mini_control_background_action_cb, mc);
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231

    /* */
    Evas_Object *progress = mc->progress = elm_slider_add(layout);
    elm_slider_horizontal_set(progress, EINA_TRUE);
    elm_object_disabled_set(progress, EINA_TRUE);
    elm_object_part_content_set(layout, "swallow.progress", progress);

    return mc;
}

void
mini_control_destroy(minicontrol *mc)
{
    evas_object_del(mc->win);
    free(mc);
}