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

media_library: Use artist ID instead of its name

parent 6fe27df4
......@@ -63,6 +63,7 @@ artist_item_copy(const artist_item* p_item )
artist_item* p_new = artist_item_create( p_item->psz_name );
if (p_new == NULL)
return NULL;
p_new->i_id = p_item->i_id;
if (p_item->psz_artwork != NULL)
p_new->psz_artwork = strdup(p_item->psz_artwork);
p_new->i_nb_albums = p_item->i_nb_albums;
......@@ -74,5 +75,5 @@ 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;
return p_left->i_id == p_right->i_id;
}
......@@ -40,6 +40,7 @@ typedef struct artist_item
char* psz_name;
char* psz_artwork;
uint32_t i_nb_albums;
uint32_t i_id;
} artist_item;
artist_item*
......
......@@ -151,6 +151,7 @@ artistToArtistItem( ArtistPtr artist )
auto p_item = artist_item_create(artist->name().c_str());
if (p_item == nullptr)
return nullptr;
p_item->i_id = artist->id();
if (artist->artworkUrl().empty() == false)
p_item->psz_artwork = path_from_url( artist->artworkUrl().c_str() );
......
......@@ -279,14 +279,12 @@ media_library_get_artists( media_library* p_ml, media_library_list_cb cb, void*
}
void
media_library_get_artist_albums( media_library* p_ml, const char* psz_artistName, media_library_list_cb cb, void* p_user_data )
media_library_get_artist_albums( media_library* p_ml, unsigned int i_artist_id, media_library_list_cb cb, void* p_user_data )
{
ArtistPtr artist;
if (psz_artistName != NULL)
artist = p_ml->ml->artist(psz_artistName);
ArtistPtr artist = p_ml->ml->artist( i_artist_id );
if (artist == nullptr)
{
LOGE("Can't find artist %s", psz_artistName);
LOGE("Can't find artist %d", i_artist_id);
return;
}
media_library_common_getter(cb, p_user_data,
......@@ -309,14 +307,12 @@ media_library_get_album_songs(media_library* p_ml, unsigned int i_album_id, medi
}
void
media_library_get_artist_songs(media_library* p_ml, const char* psz_artistName, media_library_list_cb cb, void* p_user_data)
media_library_get_artist_songs(media_library* p_ml, unsigned int i_artist_id, media_library_list_cb cb, void* p_user_data)
{
ArtistPtr artist;
if (psz_artistName != NULL)
artist = p_ml->ml->artist(psz_artistName);
ArtistPtr artist = p_ml->ml->artist(i_artist_id);
if (artist == nullptr)
{
LOGE("Can't find artist %s", psz_artistName);
LOGE("Can't find artist %u", i_artist_id);
return;
}
media_library_common_getter(cb, p_user_data,
......
......@@ -65,7 +65,7 @@ void
media_library_get_audio_files( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
void
media_library_get_artist_albums( media_library* p_ml, const char* psz_artistName, media_library_list_cb cb, void* p_user_data );
media_library_get_artist_albums( media_library* p_ml, unsigned int i_artist_id, media_library_list_cb cb, void* p_user_data );
void
media_library_get_albums( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
......@@ -77,7 +77,7 @@ 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, const char* psz_artistName, media_library_list_cb cb, void* p_user_data);
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_register_on_change(media_library* ml, media_library_file_list_changed_cb cb, void* p_data);
......
......@@ -33,7 +33,7 @@
struct list_sys
{
LIST_VIEW_COMMON
char* psz_artist_name;
unsigned int i_artist_id;
};
struct list_view_item
......@@ -162,7 +162,6 @@ audio_list_album_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->psz_artist_name);
free(p_list_sys);
}
......@@ -170,14 +169,14 @@ static void
audio_list_album_get_albums_cb(media_library* p_ml, media_library_list_cb cb, void* p_user_data )
{
list_sys* p_list_sys = (list_sys*)p_user_data;
if (p_list_sys->psz_artist_name != NULL)
media_library_get_artist_albums(p_ml, p_list_sys->psz_artist_name, cb, p_list_sys->p_ctrl);
if (p_list_sys->i_artist_id != 0)
media_library_get_artist_albums(p_ml, p_list_sys->i_artist_id, cb, p_list_sys->p_ctrl);
else
media_library_get_albums(p_ml, cb, p_list_sys->p_ctrl);
}
list_view*
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, const char* psz_artist_name, list_view_create_option opts)
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_artist_id, list_view_create_option opts)
{
list_view* p_list_view = calloc(1, sizeof(*p_list_view));
if (p_list_view == NULL)
......@@ -185,8 +184,7 @@ audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, const cha
list_sys* p_list_sys = p_list_view->p_sys = calloc(1, sizeof(*p_list_sys));
if (p_list_sys == NULL)
return NULL;
if (psz_artist_name != NULL)
p_list_sys->psz_artist_name = strdup(psz_artist_name);
p_list_sys->i_artist_id = i_artist_id;
list_view_common_setup(p_list_view, p_list_sys, p_intf, p_parent, opts);
......
......@@ -52,15 +52,15 @@ audio_list_artist_item_selected(void *data, Evas_Object *obj /*EINA_UNUSED*/, vo
list_view_item *p_view_item = (list_view_item*)data;
list_view* p_view;
if (p_view_item->p_artist_item->psz_name != NULL)
if (p_view_item->p_artist_item->i_id != 0)
{
p_view = audio_list_album_view_create(p_view_item->p_list_sys->p_intf, p_view_item->p_list_sys->p_parent,
p_view_item->p_artist_item->psz_name, LIST_CREATE_ALL );
p_view_item->p_artist_item->i_id, LIST_CREATE_ALL );
}
else
{
p_view = audio_list_song_view_artist_create(p_view_item->p_list_sys->p_intf, p_view_item->p_list_sys->p_parent,
NULL, LIST_CREATE_ALL );
0, LIST_CREATE_ALL );
}
Evas_Object* p_new_list = p_view->pf_get_widget(p_view->p_sys);
......
......@@ -36,7 +36,7 @@
struct list_sys
{
LIST_VIEW_COMMON
char* psz_artist_name;
unsigned int i_artist_id;
unsigned int i_album_id;
};
......@@ -183,7 +183,6 @@ audio_list_song_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->psz_artist_name);
free(p_list_sys);
}
......@@ -191,7 +190,7 @@ static void
audio_list_song_get_artist_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_artist_songs(p_ml, p_list_sys->psz_artist_name, cb, p_list_sys->p_ctrl);
media_library_get_artist_songs(p_ml, p_list_sys->i_artist_id, cb, p_list_sys->p_ctrl);
}
static void
......@@ -242,11 +241,10 @@ audio_list_song_view_all_create(interface* p_intf, Evas_Object* p_parent, list_v
}
list_view*
audio_list_song_view_artist_create(interface* p_intf, Evas_Object* p_parent, const char* psz_artist_name, list_view_create_option opts )
audio_list_song_view_artist_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_artist_id, list_view_create_option opts )
{
list_view* p_view = audio_list_song_view_create(p_intf, p_parent, opts);
if (psz_artist_name != NULL)
p_view->p_sys->psz_artist_name = strdup(psz_artist_name);
p_view->p_sys->i_artist_id = i_artist_id;
media_library_controller_set_content_callback(p_view->p_sys->p_ctrl, audio_list_song_get_artist_songs_cb, p_view->p_sys);
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
......
......@@ -44,7 +44,7 @@ audio_list_song_view_all_create(interface* p_intf, Evas_Object* p_parent, list_v
// Creates a view that lists the specified artist's songs
list_view*
audio_list_song_view_artist_create(interface* p_intf, Evas_Object* p_parent, const char* psz_artist_name, list_view_create_option opts );
audio_list_song_view_artist_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_artist_id, list_view_create_option opts );
// Creates a view that lists the specified album's songs
list_view*
......@@ -57,6 +57,6 @@ video_view_list_create(interface *intf, Evas_Object *p_parent, list_view_create_
// If psz_artist_name is non-NULL, only this artist's albums are listed.
// Otherwise, all known albums are displayed
list_view*
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, const char* psz_artist_name, list_view_create_option opts);
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, unsigned int i_artist_, list_view_create_option opts);
#endif // LIST_VIEW_H_
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