minicontrol_view.c 5.99 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
/*****************************************************************************
 * 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>

struct minicontrol
{
    playback_service *p_ps;
    Evas_Object *win;

    Evas_Object *layout;
    Evas_Object *play_button;
    Evas_Object *next_button;
    Evas_Object *prev_button;
    Evas_Object *cover;
    Evas_Object *progress;
};

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));
}

static void
mini_control_play_pause_toggle_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
    minicontrol *mc = data;

    playback_service_toggle_play_pause(mc->p_ps);
}

static void
mini_control_next_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
    minicontrol *mc = data;
    playback_service_list_set_next(mc->p_ps);
}

static void
mini_control_prev_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
    minicontrol *mc = data;
    playback_service_list_set_prev(mc->p_ps);
}

// 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)
{
    if (event_type == MINICONTROL_VIEWER_EVENT_HIDE || event_type == MINICONTROL_EVENT_REQUEST_HIDE)
        playback_service_stop_notify(ps, true);
}

minicontrol*
mini_control_view_create(playback_service *p_ps)
{
    minicontrol *mc = calloc(1, sizeof(*mc));
    mc->p_ps = p_ps;
    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);

    evas_object_smart_callback_add(mc->play_button, "clicked", mini_control_play_pause_toggle_cb, mc);
    evas_object_smart_callback_add(mc->next_button, "clicked", mini_control_next_cb, mc);
    evas_object_smart_callback_add(mc->prev_button, "clicked", mini_control_prev_cb, mc);

    /* */
    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);
}