list_view_common.c 4.06 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
/*****************************************************************************
 * Copyright © 2015 VideoLAN, VideoLabs SAS
 *****************************************************************************
 *
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
 *
 * 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 "list_view_private.h"
#include "controller/media_library_controller.h"

struct list_sys
{
    LIST_VIEW_COMMON
};

static void
38
list_view_clear(list_sys* p_list_sys)
39
{
40 41
    elm_genlist_clear(p_list_sys->p_list);
    list_view_toggle_empty(p_list_sys, true);
42 43 44
}

static void
45
list_view_destroy(list_sys* p_list_sys)
46
{
47 48 49
    media_library_controller_destroy(p_list_sys->p_ctrl);
    elm_genlist_item_class_free(p_list_sys->p_default_item_class);
    free(p_list_sys);
50 51
}

52
static Evas_Object*
53
list_view_get_widget(list_sys* p_list_sys)
54
{
55
    return p_list_sys->p_container;
56 57 58 59 60 61 62 63 64
}

void
list_view_toggle_empty(list_sys* p_list_sys, bool b_empty)
{
    if (p_list_sys->b_empty == b_empty)
        return;
    p_list_sys->b_empty = b_empty;
    Evas_Object* p_list = p_list_sys->p_list;
65 66
    Evas_Object* p_show = b_empty ? p_list_sys->p_empty : p_list;
    Evas_Object* p_hide = b_empty ? p_list : p_list_sys->p_empty;
67 68 69 70 71

    elm_box_unpack_all(p_list_sys->p_container);
    elm_box_pack_end(p_list_sys->p_container, p_show);
    evas_object_show(p_show);
    evas_object_hide(p_hide);
72 73
}

74
void
75
list_view_common_setup(list_view* p_list_view, list_sys* p_list_sys, interface* p_intf, Evas_Object* p_parent, list_view_create_option opts )
76
{
77 78
    p_list_sys->p_intf = p_intf;
    p_list_sys->p_parent = p_parent;
79

80
    /* Container box */
81
    p_list_sys->p_container = elm_box_add(p_parent);
82

83 84
    /* Empty list */
    p_list_sys->p_empty = elm_layout_add(p_list_sys->p_container);
85
    elm_layout_file_set(p_list_sys->p_empty, BASICTEXTEDJ, "basic_text");
86 87
    evas_object_size_hint_weight_set(p_list_sys->p_empty, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(p_list_sys->p_empty, EVAS_HINT_FILL, EVAS_HINT_FILL);
88

89 90 91 92
    Evas_Object *label = elm_label_add(p_list_sys->p_empty);
    elm_object_text_set(label, "No content to display");
    elm_object_part_content_set(p_list_sys->p_empty, "swallow.main", label);

93 94 95 96 97 98 99
    /* Create genlist (if required) */
    if (opts & LIST_CREATE_LIST)
    {
        p_list_sys->p_list = elm_genlist_add(p_list_sys->p_container);
        elm_scroller_single_direction_set(p_list_sys->p_list, ELM_SCROLLER_SINGLE_DIRECTION_HARD);
        elm_genlist_homogeneous_set(p_list_sys->p_list, EINA_TRUE);
        elm_genlist_mode_set(p_list_sys->p_list, ELM_LIST_COMPRESS);
100

101 102 103 104
        /* Item Class */
        p_list_sys->p_default_item_class = elm_genlist_item_class_new();
        p_list_sys->p_default_item_class->item_style = "2line.top.3";
    }
105 106

    /* Setup common callbacks */
107 108 109
    p_list_view->pf_del = &list_view_destroy;
    p_list_view->pf_clear = &list_view_clear;
    p_list_view->pf_get_widget = &list_view_get_widget;
110 111

    /* Ensure the initial update takes place (keep in mind that b_empty is 0 initialized) */
112
    list_view_toggle_empty(p_list_sys, true);
113
}