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

audio views: Simplify creating a view from a view

When browsing from a view (for instance, listing an artist's albums), we
were relying on the library_item to fetch the proper content.
We are now passing this element upon list_view creation.
This also removes some fairly hackish library_controller ownership from
within the parent view.
parent 00940b9f
......@@ -32,6 +32,7 @@
struct list_sys
{
LIST_VIEW_COMMON
char* psz_artist_name;
};
struct list_view_item
......@@ -40,34 +41,16 @@ struct list_view_item
const Elm_Genlist_Item_Class* itc;
album_item* p_album_item;
Elm_Object_Item* p_object_item;
// members used when spawning a new view out of an item
media_library_controller* p_songs_controller;
};
/* List songs when an album is clicked */
static void
audio_list_album_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_album_songs(p_ml, p_view_item->p_album_item->psz_name, cb, p_view_item->p_songs_controller);
}
static void
audio_list_album_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_songs_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);
/* Create a controller that will feed the new view */
application* p_app = intf_get_application(p_view_item->p_list_sys->p_intf);
p_songs_view->p_sys->p_ctrl = p_view_item->p_songs_controller = audio_controller_create(p_app, p_songs_view);
/* Tweak the video controller to list the songs of a specific album only */
media_library_controller_set_content_callback(p_view_item->p_songs_controller,
audio_list_album_item_get_songs_cb, p_view_item);
media_library_controller_refresh(p_view_item->p_songs_controller);
list_view* p_songs_view = audio_list_song_view_album_create(p_view_item->p_list_sys->p_intf, p_view_item->p_list_sys->p_parent,
p_view_item->p_album_item->psz_name, LIST_CREATE_ALL);
Evas_Object* p_new_list = p_songs_view->pf_get_widget(p_songs_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);
......@@ -137,8 +120,27 @@ audio_list_album_view_append_item(list_sys *p_list_sys, void* p_data)
return p_view_item;
}
static void
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);
}
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);
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, list_view_create_option opts)
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, const char* psz_artist_name, list_view_create_option opts)
{
list_view* p_list_view = calloc(1, sizeof(*p_list_view));
if (p_list_view == NULL)
......@@ -146,6 +148,8 @@ audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, list_view
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);
list_view_common_setup(p_list_view, p_list_sys, p_intf, p_parent, opts);
......@@ -158,13 +162,11 @@ audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, list_view
p_list_view->pf_append_item = &audio_list_album_view_append_item;
p_list_view->pf_get_item = &audio_list_album_item_get_media_item;
p_list_view->pf_set_item = &audio_list_album_item_set_media_item;
p_list_view->pf_del = &audio_list_album_view_delete;
if (opts & LIST_CREATE_MEDIA_CONTROLLER)
{
application* p_app = intf_get_application( p_intf );
p_list_sys->p_ctrl = album_controller_create(p_app, p_list_view);
media_library_controller_refresh( p_list_sys->p_ctrl );
}
application* p_app = intf_get_application( p_intf );
p_list_sys->p_ctrl = album_controller_create(p_app, p_list_view);
media_library_controller_set_content_callback(p_list_sys->p_ctrl, audio_list_album_get_albums_cb, p_list_sys);
media_library_controller_refresh(p_list_sys->p_ctrl);
return p_list_view;
}
......@@ -40,57 +40,28 @@ struct list_view_item
const Elm_Genlist_Item_Class* itc;
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_controller;
};
/*
* List albums when an artist is clicked
*/
/* This adds a layer to plumb the proper parameters in the media_controller call */
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_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;
application* p_app = intf_get_application(p_view_item->p_list_sys->p_intf);
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);
p_view_item->p_artist_item->psz_name, LIST_CREATE_ALL );
}
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);
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 );
}
media_library_controller_refresh(p_view_item->p_controller);
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);
......@@ -182,12 +153,9 @@ audio_list_artist_view_create(interface* p_intf, Evas_Object* p_parent, list_vie
p_list_view->pf_get_item = &audio_list_artist_item_get_media_item;
p_list_view->pf_set_item = &audio_list_artist_item_set_media_item;
if (opts & LIST_CREATE_MEDIA_CONTROLLER)
{
application* p_app = intf_get_application( p_intf );
p_list_sys->p_ctrl = artist_controller_create(p_app, p_list_view);
media_library_controller_refresh( p_list_sys->p_ctrl );
}
application* p_app = intf_get_application( p_intf );
p_list_sys->p_ctrl = artist_controller_create(p_app, p_list_view);
media_library_controller_refresh( p_list_sys->p_ctrl );
return p_list_view;
}
......@@ -36,6 +36,8 @@
struct list_sys
{
LIST_VIEW_COMMON
char* psz_artist_name;
char* psz_album_name;
};
struct list_view_item
......@@ -172,7 +174,31 @@ audio_list_song_view_append_item(list_sys *p_sys, void* p_data)
return ali;
}
list_view*
static void
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_album_name);
free(p_list_sys->psz_artist_name);
free(p_list_sys);
}
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_albums(p_ml, p_list_sys->psz_artist_name, cb, p_list_sys->p_ctrl);
}
static void
audio_list_song_get_album_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_album_songs(p_ml, p_list_sys->psz_album_name, 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)
{
list_view* p_view = calloc(1, sizeof(*p_view));
......@@ -195,14 +221,42 @@ audio_list_song_view_create(interface* p_intf, Evas_Object* p_parent, list_view_
p_view->pf_append_item = &audio_list_song_view_append_item;
p_view->pf_get_item = &audio_list_song_item_get_media_item;
p_view->pf_set_item = &audio_list_song_item_set_media_item;
p_view->pf_del = &audio_list_song_view_delete;
if (opts & LIST_CREATE_MEDIA_CONTROLLER)
{
application* p_app = intf_get_application( p_intf );
p_sys->p_ctrl = audio_controller_create(p_app, p_view);
media_library_controller_refresh(p_sys->p_ctrl);
}
application* p_app = intf_get_application( p_intf );
p_sys->p_ctrl = audio_controller_create(p_app, p_view);
return p_view;
}
list_view*
audio_list_song_view_all_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts )
{
list_view* p_view = audio_list_song_view_create(p_intf, p_parent, opts);
// Default audio controller is listing all songs. No more config is required.
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
}
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 )
{
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);
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;
}
list_view*
audio_list_song_view_album_create(interface* p_intf, Evas_Object* p_parent, const char* psz_album_name, list_view_create_option opts )
{
list_view* p_view = audio_list_song_view_create(p_intf, p_parent, opts);
if (psz_album_name != NULL)
p_view->p_sys->psz_album_name = strdup(psz_album_name);
media_library_controller_set_content_callback(p_view->p_sys->p_ctrl, audio_list_song_get_album_songs_cb, p_view->p_sys);
media_library_controller_refresh(p_view->p_sys->p_ctrl);
return p_view;
}
......@@ -68,13 +68,13 @@ create_audio_list_type(view_sys *p_view_sys, audio_view_type type )
{
case AUDIO_VIEW_SONG:
default:
p_view = audio_list_song_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, LIST_CREATE_ALL);
p_view = audio_list_song_view_all_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, LIST_CREATE_ALL);
break;
case AUDIO_VIEW_ARTIST:
p_view = audio_list_artist_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, LIST_CREATE_ALL);
break;
case AUDIO_VIEW_ALBUM:
p_view = audio_list_album_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, LIST_CREATE_ALL);
p_view = audio_list_album_view_create(p_view_sys->p_intf, p_view_sys->nf_toolbar, NULL, LIST_CREATE_ALL);
break;
}
......
......@@ -31,7 +31,6 @@
typedef enum list_view_create_option
{
LIST_CREATE_MEDIA_CONTROLLER = 1,
LIST_CREATE_LIST = 1 << 1,
LIST_CREATE_ALL = ~0
} list_view_create_option;
......@@ -39,13 +38,25 @@ typedef enum list_view_create_option
list_view*
audio_list_artist_view_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts );
// Creates a view that lists all known songs
list_view*
audio_list_song_view_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts );
audio_list_song_view_all_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts );
// 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 );
// Creates a view that lists the specified album's songs
list_view*
audio_list_song_view_album_create(interface* p_intf, Evas_Object* p_parent, const char* psz_album_name, list_view_create_option opts );
list_view*
video_view_list_create(interface *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
list_view*
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, list_view_create_option opts);
audio_list_album_view_create(interface* p_intf, Evas_Object* p_parent, const char* psz_artist_name, list_view_create_option opts);
#endif // LIST_VIEW_H_
......@@ -229,12 +229,9 @@ video_view_list_create(interface *p_intf, Evas_Object *p_parent, list_view_creat
p_list_view->pf_get_item = &video_list_item_get_media_item;
p_list_view->pf_set_item = &video_list_item_set_media_item;
if (opts & LIST_CREATE_MEDIA_CONTROLLER)
{
// So far we don't manually refresh the list because it's going to happen once we
// start the media library. This seems like a weird asymmetry with the audio views though.
p_list_sys->p_ctrl = video_controller_create(intf_get_application(p_intf), p_list_view);
}
// So far we don't manually refresh the list because it's going to happen once we
// start the media library. This seems like a weird asymmetry with the audio views though.
p_list_sys->p_ctrl = video_controller_create(intf_get_application(p_intf), p_list_view);
return p_list_view;
}
......
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