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

Display unknown artist songs when clicked

parent 115eba70
......@@ -34,11 +34,14 @@ artist_item_create(const char* psz_name)
if (p_item == NULL)
return NULL;
p_item->i_library_item_type = LIBRARY_ITEM_ARTIST;
p_item->psz_name = strdup(psz_name);
if (p_item->psz_name == NULL)
if (psz_name != NULL && *psz_name != 0)
{
free(p_item);
return NULL;
p_item->psz_name = strdup(psz_name);
if (p_item->psz_name == NULL)
{
free(p_item);
return NULL;
}
}
return p_item;
}
......@@ -61,5 +64,7 @@ artist_item_copy(const artist_item* p_item )
bool
artist_item_identical(const artist_item* p_left, const artist_item* p_right)
{
if (p_left->psz_name == NULL || p_right->psz_name == NULL)
return p_left->psz_name == p_right->psz_name;
return strcmp( p_left->psz_name, p_right->psz_name ) == 0;
}
......@@ -265,15 +265,27 @@ 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 )
{
auto ml = p_ml->ml;
media_library_common_getter(cb, p_user_data,
std::bind(&IMediaLibrary::artists, p_ml->ml),
artistToArtistItem);
[ml]() {
auto artists = ml->artists();
auto unknownArtist = ml->unknownArtist();
if (unknownArtist != nullptr )
{
artists.emplace_back(unknownArtist);
}
return artists;
}, artistToArtistItem);
}
void
media_library_get_artist_albums( media_library* p_ml, const char* psz_artistName, media_library_list_cb cb, void* p_user_data )
{
auto artist = p_ml->ml->artist(psz_artistName);
ArtistPtr artist;
if (psz_artistName != NULL)
artist = p_ml->ml->artist(psz_artistName);
else
artist = p_ml->ml->unknownArtist();
if (artist == nullptr)
{
LOGE("Can't find artist %s", psz_artistName);
......@@ -298,6 +310,24 @@ media_library_get_album_songs(media_library* p_ml, const char* psz_albumName, me
fileToMediaItem);
}
void
media_library_get_artist_songs(media_library* p_ml, const char* psz_artistName, media_library_list_cb cb, void* p_user_data)
{
ArtistPtr artist;
if (psz_artistName != NULL)
artist = p_ml->ml->artist(psz_artistName);
else
artist = p_ml->ml->unknownArtist();
if (artist == nullptr)
{
LOGE("Can't find artist %s", psz_artistName);
return;
}
media_library_common_getter(cb, p_user_data,
std::bind(&IArtist::media, artist),
&fileToMediaItem);
}
void
media_library_register_on_change(media_library* ml, media_library_file_list_changed_cb cb, void* p_data)
{
......
......@@ -76,6 +76,9 @@ media_library_get_artists( media_library* p_ml, media_library_list_cb cb, void*
void
media_library_get_album_songs(media_library* p_ml, const char* psz_albumName, media_library_list_cb cb, void* p_user_data);
void
media_library_get_artist_songs(media_library* p_ml, const char* psz_artistName, 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);
......
......@@ -41,7 +41,7 @@ struct list_view_item
artist_item* p_artist_item;
Elm_Object_Item* p_object_item;
// members used when spawning a new view out of an item
media_library_controller* p_albums_controller;
media_library_controller* p_controller;
};
/*
......@@ -53,27 +53,45 @@ static void
audio_list_artist_item_get_album_cb(media_library* p_ml, media_library_list_cb cb, void* p_user_data )
{
list_view_item* p_view_item = (list_view_item*)p_user_data;
media_library_get_artist_albums(p_ml, p_view_item->p_artist_item->psz_name, cb, p_view_item->p_albums_controller);
media_library_get_artist_albums(p_ml, p_view_item->p_artist_item->psz_name, cb, p_view_item->p_controller);
}
static void
audio_list_artist_item_get_songs_cb(media_library* p_ml, media_library_list_cb cb, void* p_user_data )
{
list_view_item* p_view_item = (list_view_item*)p_user_data;
media_library_get_artist_songs(p_ml, p_view_item->p_artist_item->psz_name, cb, p_view_item->p_controller);
}
static void
audio_list_artist_item_selected(void *data, Evas_Object *obj /*EINA_UNUSED*/, void *event_info)
{
list_view_item *p_view_item = (list_view_item*)data;
list_view* p_album_view = audio_list_album_view_create(p_view_item->p_list_sys->p_intf, p_view_item->p_list_sys->p_parent,
LIST_CREATE_ALL & ~LIST_CREATE_MEDIA_CONTROLLER);
/* Create a controller that will feed the new view */
application* p_app = intf_get_application(p_view_item->p_list_sys->p_intf);
p_album_view->p_sys->p_ctrl = p_view_item->p_albums_controller = album_controller_create(p_app, p_album_view);
list_view* p_view;
if (p_view_item->p_artist_item->psz_name != NULL)
{
p_view = audio_list_album_view_create(p_view_item->p_list_sys->p_intf, p_view_item->p_list_sys->p_parent,
LIST_CREATE_ALL & ~LIST_CREATE_MEDIA_CONTROLLER);
/* Create a controller that will feed the new view */
p_view->p_sys->p_ctrl = p_view_item->p_controller = album_controller_create(p_app, p_view);
/* Tweak the video controller to list the songs of a specific artist only */
media_library_controller_set_content_callback(p_view_item->p_controller,
audio_list_artist_item_get_album_cb, p_view_item);
}
else
{
p_view = audio_list_song_view_create(p_view_item->p_list_sys->p_intf, p_view_item->p_list_sys->p_parent,
LIST_CREATE_ALL & ~LIST_CREATE_MEDIA_CONTROLLER);
p_view->p_sys->p_ctrl = p_view_item->p_controller = audio_controller_create(p_app, p_view);
media_library_controller_set_content_callback(p_view_item->p_controller,
audio_list_artist_item_get_songs_cb, p_view_item);
}
/* Tweak the video controller to list the songs of a specific artist only */
media_library_controller_set_content_callback(p_view_item->p_albums_controller,
audio_list_artist_item_get_album_cb, p_view_item);
media_library_controller_refresh(p_view_item->p_albums_controller);
media_library_controller_refresh(p_view_item->p_controller);
Evas_Object* p_new_list = p_album_view->pf_get_widget(p_album_view->p_sys);
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);
}
......@@ -95,7 +113,8 @@ genlist_text_get_cb(void *data, Evas_Object *obj, const char *part)
if (itc->item_style && !strcmp(itc->item_style, "2line.top.3")) {
if (part && !strcmp(part, "elm.text.main.left.top")) {
asprintf(&buf, "<b>%s</b>", p_view_item->p_artist_item->psz_name);
asprintf(&buf, "<b>%s</b>", p_view_item->p_artist_item->psz_name ?
p_view_item->p_artist_item->psz_name : "Unknown Artist");
return buf;
}
}
......
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