Commit 9793dde0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add genre listing

parent f42db62d
......@@ -31,6 +31,7 @@
#include "media_library_controller_private.h"
#include "media/artist_item.h"
#include "media/album_item.h"
#include "media/genre_item.h"
#include "ui/views/video_view.h"
#include "ui/views/audio_view.h"
......@@ -62,6 +63,12 @@ album_controller_accept_item( const library_item* p_item )
return p_item->i_library_item_type == LIBRARY_ITEM_ALBUM;
}
static bool
genre_controller_accept_item( const library_item* p_item )
{
return p_item->i_library_item_type == LIBRARY_ITEM_GENRE;
}
media_library_controller*
video_controller_create(application* p_app, list_view* p_list_view)
{
......@@ -113,3 +120,16 @@ album_controller_create(application* p_app, list_view* p_list_view)
p_ctrl->pf_accept_item = &album_controller_accept_item;
return p_ctrl;
}
media_library_controller*
genre_controller_create(application* p_app, list_view* p_list_view)
{
media_library_controller* p_ctrl = media_library_controller_create( p_app, p_list_view );
if ( p_ctrl == NULL )
return NULL;
p_ctrl->pf_media_library_get_content = (pf_media_library_get_content_cb)&media_library_get_genres;
p_ctrl->pf_item_duplicate = (pf_item_duplicate_cb)&genre_item_copy;
p_ctrl->pf_item_compare = (pf_item_compare_cb)&genre_item_identical;
p_ctrl->pf_accept_item = &genre_controller_accept_item;
return p_ctrl;
}
......@@ -45,4 +45,7 @@ artist_controller_create(application* p_app, list_view* p_list_view);
media_library_controller*
album_controller_create(application* p_app, list_view* p_list_view);
media_library_controller*
genre_controller_create(application* p_app, list_view* p_list_view);
#endif // MEDIA_CONTROLLER_H_
......@@ -65,7 +65,6 @@ album_item_identical(const album_item* p_left, const album_item* p_right)
return p_left->i_id == p_right->i_id;
}
void
album_item_destroy(album_item* p_item)
{
......
/*****************************************************************************
* Copyright © 2015-2016 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 "genre_item.h"
genre_item*
genre_item_create(const char* psz_name)
{
genre_item* p_item = calloc(1, sizeof(*p_item));
if (p_item == NULL)
return NULL;
p_item->i_library_item_type = LIBRARY_ITEM_GENRE;
p_item->psz_name = strdup(psz_name);
if (p_item->psz_name == NULL)
{
free(p_item);
return NULL;
}
return p_item;
}
genre_item*
genre_item_copy(const genre_item* p_item)
{
genre_item* p_new_item = genre_item_create(p_item->psz_name);
if (p_new_item == NULL)
return NULL;
p_new_item->i_id = p_item->i_id;
return p_new_item;
}
bool
genre_item_identical(const genre_item* p_left, const genre_item* p_right)
{
return p_left->i_id == p_right->i_id;
}
void
genre_item_destroy(genre_item* p_item)
{
if (p_item == NULL)
return;
free(p_item->psz_name);
free(p_item);
}
/*****************************************************************************
* Copyright © 2015-2016 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
*****************************************************************************/
#ifndef GENRE_ITEM_H_
# define GENRE_ITEM_H_
#include "media/library/library_item.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct genre_item {
LIBRARY_ITEM_COMMON
unsigned int i_id;
char* psz_name;
} genre_item;
genre_item*
genre_item_create( const char* psz_name );
genre_item*
genre_item_copy( const genre_item* p_item );
bool
genre_item_identical( const genre_item* p_left, const genre_item* p_right);
void
genre_item_destroy( genre_item* p_item );
#ifdef __cplusplus
} // extern "C"
#endif
#endif //GENRE_ITEM_H_
......@@ -34,6 +34,8 @@
#include "IAlbumTrack.h"
#include "IArtist.h"
#include "IFile.h"
#include "IGenre.h"
#include "media/genre_item.h"
static char*
path_from_url(const char* psz_str)
......@@ -170,3 +172,13 @@ artistToArtistItem( ArtistPtr artist )
p_item->i_nb_albums = albums.size();
return p_item;
}
genre_item*
genreToGenreItem( GenrePtr genre )
{
auto p_item = genre_item_create( genre->name().c_str() );
if ( p_item == nullptr )
return nullptr;
p_item->i_id = genre->id();
return p_item;
}
......@@ -32,10 +32,10 @@
#include "IVideoTrack.h"
#include "IArtist.h"
#include "IAlbum.h"
#include "IGenre.h"
#include "media_library_private.hpp"
#include "system_storage.h"
media_library::media_library()
: ml( NewMediaLibrary() )
, m_progressCb( nullptr )
......@@ -340,6 +340,15 @@ media_library_get_artists( media_library* p_ml, media_library_list_cb cb, void*
artistToArtistItem);
}
void
media_library_get_genres( media_library* p_ml, media_library_list_cb cb, void* p_user_data )
{
media_library_common_getter(cb, p_user_data,
[p_ml](){ return p_ml->ml->genres();
}, genreToGenreItem);
}
void
media_library_get_artist_albums( media_library* p_ml, unsigned int i_artist_id, media_library_list_cb cb, void* p_user_data )
{
......@@ -382,6 +391,18 @@ media_library_get_artist_songs(media_library* p_ml, unsigned int i_artist_id, me
&fileToMediaItem);
}
void
media_library_get_genres_songs(media_library* p_ml, unsigned int i_genre_id, media_library_list_cb cb, void* p_user_data)
{
GenrePtr genre = p_ml->ml->genre(i_genre_id);
if ( genre == nullptr )
{
LOGE("Can't find genre %u", i_genre_id);
return;
}
media_library_common_getter(cb, p_user_data, [genre]{ return genre->tracks(); }, &fileToMediaItem);
}
void
media_library_register_on_change(media_library* ml, media_library_file_list_changed_cb cb, void* p_data)
{
......
......@@ -76,12 +76,18 @@ media_library_get_albums( media_library* p_ml, media_library_list_cb cb, void* p
void
media_library_get_artists( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
void
media_library_get_genres( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
void
media_library_get_album_songs(media_library* p_ml, unsigned int i_album_id, media_library_list_cb cb, void* p_user_data);
void
media_library_get_artist_songs(media_library* p_ml, unsigned int i_artist_id, media_library_list_cb cb, void* p_user_data);
void
media_library_get_genres_songs(media_library* p_ml, unsigned int i_genre_id, media_library_list_cb cb, void* p_user_data);
void
media_library_register_on_change(media_library* ml, media_library_file_list_changed_cb cb, void* p_data);
......
......@@ -33,10 +33,12 @@
#include "media/media_item.h"
#include "media/album_item.h"
#include "media/artist_item.h"
#include "media/genre_item.h"
media_item* fileToMediaItem( MediaPtr file );
album_item* albumToAlbumItem( AlbumPtr album );
artist_item* artistToArtistItem( ArtistPtr album );
genre_item* genreToGenreItem( GenrePtr genre );
class TizenLogger : public ILogger
{
......
/*****************************************************************************
* Copyright © 2015-2016 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.h"
#include "audio_view.h"
#include "controller/media_controller.h"
#include "list_view_private.h"
#include "ui/interface.h"
#include "ui/utils.h"
#include "media/genre_item.h"
struct list_sys
{
LIST_VIEW_COMMON
};
struct list_view_item
{
const list_sys* p_list_sys;
const Elm_Genlist_Item_Class* itc;
genre_item* p_genre_item;
Elm_Object_Item* p_object_item;
};
static void
free_list_item_data(void *data, Evas_Object *obj, void *event_info)
{
list_view_item *ali = data;
genre_item_destroy(ali->p_genre_item);
free(ali);
}
static char *
genlist_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
list_view_item *ali = data;
const Elm_Genlist_Item_Class *itc = ali->itc;
char *buf;
/* Check the item class style and put the current folder or file name as a string */
/* Then put this string as the genlist item label */
if (itc->item_style && !strcmp(itc->item_style, "2line.top.3")) {
if (part && !strcmp(part, "elm.text.main.left.top")) {
// Don't display track number out of the album songs view (ie. when i_album_id != 0)
asprintf(&buf, "<b>%s</b>", ali->p_genre_item->psz_name);
return buf;
}
}
return NULL;
}
static const void*
audio_list_genres_item_get_genre_item(list_view_item* p_item)
{
return p_item->p_genre_item;
}
static void
audio_list_genres_item_set_genre_item(list_view_item* p_item, void* p_data)
{
genre_item *p_genre_item = (genre_item*)p_data;
p_item->p_genre_item = p_genre_item;
ecore_main_loop_thread_safe_call_async((Ecore_Cb)elm_genlist_item_update, p_item->p_object_item);
}
static Evas_Object*
genlist_content_get_cb(void *data, Evas_Object *obj, const char *part)
{
list_view_item *ali = data;
const Elm_Genlist_Item_Class *itc = ali->itc;
Evas_Object *layout = NULL;
/* Check the item class style and add the object needed in the item class*/
/* Here, puts the icon in the item class to add it to genlist items */
if (itc->item_style && !strcmp(itc->item_style, "2line.top.3")) {
if (part && !strcmp(part, "elm.icon.1")) {
layout = elm_layout_add(obj);
elm_layout_theme_set(layout, "layout", "list/B/type.1", "default");
Evas_Object *icon;
icon = create_icon(layout, "background_cone.png");
elm_layout_content_set(layout, "elm.swallow.content", icon);
}
}
return layout;
}
static void
audio_list_genres_item_selected(void *data, Evas_Object *obj, void *event_info)
{
list_view_item* p_view_item = (list_view_item*)data;
list_view* p_view;
p_view = audio_list_song_view_genre_create(p_view_item->p_list_sys->p_intf,
p_view_item->p_list_sys->p_parent,
p_view_item->p_genre_item->i_id, LIST_CREATE_ALL);
Evas_Object* p_new_list = p_view->pf_get_widget(p_view->p_sys);
Elm_Object_Item *it = elm_naviframe_item_push(p_view_item->p_list_sys->p_parent, "", NULL, NULL, p_new_list, NULL);
elm_naviframe_item_title_enabled_set(it, EINA_FALSE, EINA_FALSE);
}
static list_view_item*
audio_list_genres_view_append_item(list_sys *p_sys, void* p_data)
{
genre_item* p_genre_item = (genre_item*)p_data;
list_view_item *ali = calloc(1, sizeof(*ali));
ali->p_list_sys = p_sys;
ali->itc = p_sys->p_default_item_class;
ali->p_genre_item = p_genre_item;
/* Set and append new item in the genlist */
Elm_Object_Item *it = elm_genlist_item_append(p_sys->p_list,
p_sys->p_default_item_class, /* genlist item class */
ali, /* genlist item class user data */
NULL, /* genlist parent item */
ELM_GENLIST_ITEM_NONE, /* genlist item type */
audio_list_genres_item_selected, /* genlist select smart callback */
ali); /* genlist smart callback user data */
/* */
elm_object_item_del_cb_set(it, free_list_item_data);
list_view_toggle_empty(p_sys, false);
return ali;
}
static void
audio_list_genres_view_delete(list_sys* p_list_sys)
{
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);
}
list_view*
audio_list_genres_view_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts)
{
list_view* p_view = calloc(1, sizeof(*p_view));
if (p_view == NULL)
return NULL;
list_sys* p_sys = p_view->p_sys = calloc(1, sizeof(*p_sys));
if (p_sys == NULL)
return NULL;
/* Setup common parts */
list_view_common_setup(p_view, p_sys, p_intf, p_parent, opts);
/* Connect genlist callbacks */
p_sys->p_default_item_class->func.text_get = genlist_text_get_cb;
p_sys->p_default_item_class->func.content_get = genlist_content_get_cb;
evas_object_size_hint_weight_set(p_sys->p_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(p_sys->p_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
p_view->pf_append_item = &audio_list_genres_view_append_item;
p_view->pf_get_item = &audio_list_genres_item_get_genre_item;
p_view->pf_set_item = &audio_list_genres_item_set_genre_item;
p_view->pf_del = &audio_list_genres_view_delete;
application* p_app = intf_get_application( p_intf );
p_sys->p_ctrl = genre_controller_create(p_app, p_view);
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
}
......@@ -38,6 +38,7 @@ struct list_sys
LIST_VIEW_COMMON
unsigned int i_artist_id;
unsigned int i_album_id;
unsigned int i_genre_id;
};
struct list_view_item
......@@ -200,6 +201,13 @@ audio_list_song_get_album_songs_cb(media_library* p_ml, media_library_list_cb cb
media_library_get_album_songs(p_ml, p_list_sys->i_album_id, cb, p_list_sys->p_ctrl);
}
static void
audio_list_song_get_genre_songs_cb(media_library* p_ml, media_library_list_cb cb, void* p_user_data)
{
list_sys* p_list_sys = (list_sys*)p_user_data;
media_library_get_genres_songs(p_ml, p_list_sys->i_genre_id, cb, p_list_sys->p_ctrl);
}
static list_view*
audio_list_song_view_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts)
{
......@@ -260,3 +268,14 @@ audio_list_song_view_album_create(interface* p_intf, Evas_Object* p_parent, unsi
return p_view;
}
list_view*
audio_list_song_view_genre_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_genre_id, list_view_create_option opts )
{
list_view* p_view = audio_list_song_view_create(p_intf, p_parent, opts);
p_view->p_sys->i_genre_id = i_genre_id;
media_library_controller_set_content_callback(p_view->p_sys->p_ctrl, audio_list_song_get_genre_songs_cb, p_view->p_sys);
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
}
......@@ -76,6 +76,9 @@ create_audio_list_type(view_sys *p_view_sys, audio_view_type type )
case AUDIO_VIEW_ALBUM:
p_view = audio_list_album_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, 0, LIST_CREATE_ALL);
break;
case AUDIO_VIEW_GENRE:
p_view = audio_list_genres_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, LIST_CREATE_ALL);
break;
}
// Purge the audio view naviframe when switching tabs
......@@ -141,7 +144,7 @@ create_toolbar(view_sys *p_view_sys, Evas_Object *parent)
Elm_Object_Item *it = toolbar_item_append(tabbar, AUDIO_VIEW_ARTIST, "Artists", tabbar_item_cb, p_view_sys);
toolbar_item_append(tabbar, AUDIO_VIEW_ALBUM, "Albums", tabbar_item_cb, p_view_sys);
toolbar_item_append(tabbar, AUDIO_VIEW_SONG, "Songs", tabbar_item_cb, p_view_sys);
//toolbar_item_append(tabbar, AUDIO_VIEW_GENRE, "Genre", tabbar_item_cb, p_view_sys);
toolbar_item_append(tabbar, AUDIO_VIEW_GENRE, "Genre", tabbar_item_cb, p_view_sys);
// Select the first tab.
elm_toolbar_item_selected_set(it, EINA_TRUE);
......
......@@ -50,9 +50,16 @@ audio_list_song_view_artist_create(interface* p_intf, Evas_Object* p_parent, uns
list_view*
audio_list_song_view_album_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_album_id, list_view_create_option opts );
// Creates a view that lists the specified genre's songs
list_view*
audio_list_song_view_genre_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_genre_id, list_view_create_option opts );
list_view*
video_view_list_create(interface *intf, Evas_Object *p_parent, list_view_create_option opts );
list_view*
audio_list_genres_view_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts);
// Create a view that lists albums.
// If psz_artist_name is non-NULL, only this artist's albums are listed.
// Otherwise, all known albums are displayed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment