Commit 47ae2c92 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add playlist listing

parent 2ed92886
......@@ -32,6 +32,7 @@
#include "media/artist_item.h"
#include "media/album_item.h"
#include "media/genre_item.h"
#include "media/playlist_item.h"
#include "ui/views/video_view.h"
#include "ui/views/audio_view.h"
......@@ -69,6 +70,12 @@ genre_controller_accept_item( const library_item* p_item )
return p_item->i_library_item_type == LIBRARY_ITEM_GENRE;
}
static bool
playlist_controller_accept_item( const library_item* p_item )
{
return p_item->i_library_item_type == LIBRARY_ITEM_PLAYLIST;
}
media_library_controller*
video_controller_create(application* p_app, list_view* p_list_view)
{
......@@ -133,3 +140,16 @@ genre_controller_create(application* p_app, list_view* p_list_view)
p_ctrl->pf_accept_item = &genre_controller_accept_item;
return p_ctrl;
}
media_library_controller*
playlist_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_playlists;
p_ctrl->pf_item_duplicate = (pf_item_duplicate_cb)&playlist_item_copy;
p_ctrl->pf_item_compare = (pf_item_compare_cb)&playlist_item_identical;
p_ctrl->pf_accept_item = &playlist_controller_accept_item;
return p_ctrl;
}
......@@ -48,4 +48,7 @@ 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);
media_library_controller*
playlist_controller_create(application* p_app, list_view* p_list_view);
#endif // MEDIA_CONTROLLER_H_
......@@ -35,6 +35,7 @@
#include "IArtist.h"
#include "IFile.h"
#include "IGenre.h"
#include "IPlaylist.h"
#include "media/genre_item.h"
static char*
......@@ -182,3 +183,14 @@ genreToGenreItem( GenrePtr genre )
p_item->i_id = genre->id();
return p_item;
}
playlist_item*
playlistToPlaylistItem( PlaylistPtr playlist )
{
auto p_item = playlist_item_create( playlist->name().c_str() );
if ( p_item == nullptr )
return nullptr;
p_item->i_id = playlist->id();
return p_item;
}
......@@ -39,7 +39,8 @@ typedef enum library_item_type
LIBRARY_ITEM_MEDIA = 1,
LIBRARY_ITEM_ALBUM,
LIBRARY_ITEM_ARTIST,
LIBRARY_ITEM_GENRE
LIBRARY_ITEM_GENRE,
LIBRARY_ITEM_PLAYLIST
} library_item_type;
#define LIBRARY_ITEM_COMMON \
......
......@@ -33,6 +33,7 @@
#include "IArtist.h"
#include "IAlbum.h"
#include "IGenre.h"
#include "IPlaylist.h"
#include "media_library_private.hpp"
#include "system_storage.h"
......@@ -348,6 +349,13 @@ media_library_get_genres( media_library* p_ml, media_library_list_cb cb, void* p
}, genreToGenreItem);
}
void
media_library_get_playlists( 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->playlists();
}, playlistToPlaylistItem );
}
void
media_library_get_artist_albums( media_library* p_ml, unsigned int i_artist_id, media_library_list_cb cb, void* p_user_data )
......@@ -403,6 +411,18 @@ media_library_get_genres_songs(media_library* p_ml, unsigned int i_genre_id, med
media_library_common_getter(cb, p_user_data, [genre]{ return genre->tracks(); }, &fileToMediaItem);
}
void
media_library_get_playlist_songs(media_library* p_ml, unsigned int i_playlist_id, media_library_list_cb cb, void* p_user_data)
{
PlaylistPtr playlist = p_ml->ml->playlist(i_playlist_id);
if ( playlist == nullptr )
{
LOGE("Can't find playlist %u", i_playlist_id);
return;
}
media_library_common_getter(cb, p_user_data, [playlist]{ return playlist->media(); }, &fileToMediaItem);
}
void
media_library_register_on_change(media_library* ml, media_library_file_list_changed_cb cb, void* p_data)
{
......
......@@ -79,6 +79,9 @@ media_library_get_artists( media_library* p_ml, media_library_list_cb cb, void*
void
media_library_get_genres( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
void
media_library_get_playlists( 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);
......@@ -88,6 +91,9 @@ media_library_get_artist_songs(media_library* p_ml, unsigned int i_artist_id, me
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_get_playlist_songs(media_library* p_ml, unsigned int i_playlist_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);
......
......@@ -34,11 +34,13 @@
#include "media/album_item.h"
#include "media/artist_item.h"
#include "media/genre_item.h"
#include "media/playlist_item.h"
media_item* fileToMediaItem( MediaPtr file );
album_item* albumToAlbumItem( AlbumPtr album );
artist_item* artistToArtistItem( ArtistPtr album );
genre_item* genreToGenreItem( GenrePtr genre );
playlist_item* playlistToPlaylistItem( PlaylistPtr playlist );
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 "playlist_item.h"
playlist_item*
playlist_item_create(const char* psz_name)
{
playlist_item* p_item = calloc(1, sizeof(*p_item));
if (p_item == NULL)
return NULL;
p_item->i_library_item_type = LIBRARY_ITEM_PLAYLIST;
p_item->psz_name = strdup(psz_name);
if (p_item->psz_name == NULL)
{
free(p_item);
return NULL;
}
return p_item;
}
playlist_item*
playlist_item_copy(const playlist_item* p_item)
{
playlist_item* p_new_item = playlist_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
playlist_item_identical(const playlist_item* p_left, const playlist_item* p_right)
{
return p_left->i_id == p_right->i_id;
}
void
playlist_item_destroy(playlist_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 PLAYLIST_ITEM_H_
# define PLAYLIST_ITEM_H_
#include "media/library/library_item.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct playlist_item {
LIBRARY_ITEM_COMMON
unsigned int i_id;
char* psz_name;
} playlist_item;
playlist_item*
playlist_item_create( const char* psz_name );
playlist_item*
playlist_item_copy( const playlist_item* p_item );
bool
playlist_item_identical( const playlist_item* p_left, const playlist_item* p_right);
void
playlist_item_destroy( playlist_item* p_item );
#ifdef __cplusplus
} // extern "C"
#endif
#endif //PLAYLIST_ITEM_H_
/*****************************************************************************
* 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/playlist_item.h"
struct list_sys
{
LIST_VIEW_COMMON
};
struct list_view_item
{
const list_sys* p_list_sys;
const Elm_Genlist_Item_Class* itc;
playlist_item* p_playlist_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;
playlist_item_destroy(ali->p_playlist_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_playlist_item->psz_name);
return buf;
}
}
return NULL;
}
static const void*
audio_list_playlists_item_get_playlist_item(list_view_item* p_item)
{
return p_item->p_playlist_item;
}
static void
audio_list_playlists_item_set_playlist_item(list_view_item* p_item, void* p_data)
{
playlist_item *p_playlist_item = (playlist_item*)p_data;
p_item->p_playlist_item = p_playlist_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_playlists_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_playlist_create(p_view_item->p_list_sys->p_intf,
p_view_item->p_list_sys->p_parent,
p_view_item->p_playlist_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_playlists_view_append_item(list_sys *p_sys, void* p_data)
{
playlist_item* p_playlist_item = (playlist_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_playlist_item = p_playlist_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_playlists_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_playlists_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_playlists_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_playlists_view_append_item;
p_view->pf_get_item = &audio_list_playlists_item_get_playlist_item;
p_view->pf_set_item = &audio_list_playlists_item_set_playlist_item;
p_view->pf_del = &audio_list_playlists_view_delete;
application* p_app = intf_get_application( p_intf );
p_sys->p_ctrl = playlist_controller_create(p_app, p_view);
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
}
......@@ -39,6 +39,7 @@ struct list_sys
unsigned int i_artist_id;
unsigned int i_album_id;
unsigned int i_genre_id;
unsigned int i_playlist_id;
};
struct list_view_item
......@@ -208,6 +209,13 @@ audio_list_song_get_genre_songs_cb(media_library* p_ml, media_library_list_cb cb
media_library_get_genres_songs(p_ml, p_list_sys->i_genre_id, cb, p_list_sys->p_ctrl);
}
static void
audio_list_song_get_playlist_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_playlist_songs(p_ml, p_list_sys->i_playlist_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)
{
......@@ -278,4 +286,13 @@ audio_list_song_view_genre_create(interface* p_intf, Evas_Object* p_parent, unsi
return p_view;
}
list_view*
audio_list_song_view_playlist_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_playlist_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_playlist_id = i_playlist_id;
media_library_controller_set_content_callback(p_view->p_sys->p_ctrl, audio_list_song_get_playlist_songs_cb, p_view->p_sys);
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
}
......@@ -42,7 +42,7 @@ typedef enum audio_view_type
AUDIO_VIEW_ALBUM,
AUDIO_VIEW_SONG,
AUDIO_VIEW_GENRE,
//AUDIO_VIEW_PLAYLIST,
AUDIO_VIEW_PLAYLIST,
AUDIO_VIEW_MAX,
} audio_view_type;
......@@ -79,6 +79,9 @@ create_audio_list_type(view_sys *p_view_sys, audio_view_type type )
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;
case AUDIO_VIEW_PLAYLIST:
p_view = audio_list_playlists_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, LIST_CREATE_ALL);
break;
}
// Purge the audio view naviframe when switching tabs
......@@ -145,6 +148,7 @@ create_toolbar(view_sys *p_view_sys, Evas_Object *parent)
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_PLAYLIST,"Playlist", tabbar_item_cb, p_view_sys);
// Select the first tab.
elm_toolbar_item_selected_set(it, EINA_TRUE);
......
......@@ -54,12 +54,20 @@ audio_list_song_view_album_create(interface* p_intf, Evas_Object* p_parent, unsi
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 );
// Creates a view that lists a playlist's songs
list_view*
audio_list_song_view_playlist_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_playlist_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);
list_view*
audio_list_playlists_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