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

Plug list_view with media_controller

This privatizes a bunch of public functions, uniformize prototypes, and
should help plugin in more views
parent 2572c6ad
......@@ -31,8 +31,6 @@
#include "media_library_controller_private.h"
#include "ui/views/video_view.h"
#include "ui/views/audio_view.h"
#include "ui/views/audio_list_song_view.h"
#include "ui/views/video_view_list.h"
static bool
video_controller_accept_item( const void* p_item )
......@@ -49,16 +47,12 @@ audio_controller_accept_item( const void* p_item )
}
media_library_controller*
video_controller_create(application* p_app, view_sys* p_view)
video_controller_create(application* p_app, list_view* p_list_view)
{
media_library_controller* p_ctrl = media_library_controller_create( p_app, p_view );
media_library_controller* p_ctrl = media_library_controller_create( p_app, p_list_view );
if ( p_ctrl == NULL )
return NULL;
p_ctrl->pf_view_append_media_item = (pf_view_append_media_item_cb)&video_view_append_item;
p_ctrl->pf_get_media_item = (pf_get_media_item_cb)&video_list_item_get_media_item;
p_ctrl->pf_set_media_item = (pf_set_media_item_cb)&video_list_item_set_media_item;
p_ctrl->pf_media_library_get_content = (pf_media_library_get_content_cb)&media_library_get_video_files;
p_ctrl->pf_view_clear = (pf_view_clear_cb)&video_view_clear;
p_ctrl->pf_item_duplicate = (pf_item_duplicate_cb)&media_item_copy;
p_ctrl->pf_item_compare = (pf_item_compare_cb)&media_item_identical;
p_ctrl->pf_accept_item = &video_controller_accept_item;
......@@ -66,16 +60,12 @@ video_controller_create(application* p_app, view_sys* p_view)
}
media_library_controller*
audio_controller_create(application* p_app, view_sys* p_view)
audio_controller_create(application* p_app, list_view* p_list_view)
{
media_library_controller* p_ctrl = media_library_controller_create( p_app, p_view );
media_library_controller* p_ctrl = media_library_controller_create( p_app, p_list_view );
if ( p_ctrl == NULL )
return NULL;
p_ctrl->pf_view_append_media_item = (pf_view_append_media_item_cb)&audio_list_song_view_append_item;
p_ctrl->pf_get_media_item = (pf_get_media_item_cb)&audio_list_song_item_get_media_item;
p_ctrl->pf_set_media_item = (pf_set_media_item_cb)&audio_list_song_item_set_media_item;
p_ctrl->pf_media_library_get_content = (pf_media_library_get_content_cb)&media_library_get_audio_files;
p_ctrl->pf_view_clear = (pf_view_clear_cb)&audio_list_song_view_clear;
p_ctrl->pf_item_duplicate = (pf_item_duplicate_cb)&media_item_copy;
p_ctrl->pf_item_compare = (pf_item_compare_cb)&media_item_identical;
p_ctrl->pf_accept_item = &audio_controller_accept_item;
......
......@@ -31,8 +31,8 @@
#include "media_library_controller.h"
media_library_controller*
video_controller_create(application* p_app, view_sys* p_view);
video_controller_create(application* p_app, list_view* p_list_view);
media_library_controller*
audio_controller_create(application* p_app, view_sys* p_view);
audio_controller_create(application* p_app, list_view* p_list_view);
......@@ -39,7 +39,7 @@
static void
media_library_controller_add_item(media_library_controller* ctrl, media_item* p_item)
{
void* p_view_item = ctrl->pf_view_append_media_item( ctrl->p_view, p_item );
void* p_view_item = ctrl->p_list_view->pf_append_item( ctrl->p_list_view->p_sys, p_item );
if (p_view_item == NULL)
return;
ctrl->p_content = eina_list_append(ctrl->p_content, p_view_item);
......@@ -61,11 +61,11 @@ media_library_controller_file_update( media_library_controller* ctrl, const void
void* p_item;
EINA_LIST_FOREACH( ctrl->p_content, it, p_item )
{
const void* p_media_item = ctrl->pf_get_media_item(p_item);
const void* p_media_item = ctrl->p_list_view->pf_get_item(p_item);
if ( ctrl->pf_item_compare( p_media_item, p_new_media_item) )
{
ctrl->pf_set_media_item(p_item, p_new_media_item);
ctrl->p_list_view->pf_set_item(p_item, p_new_media_item);
return true;
}
}
......@@ -113,7 +113,7 @@ media_library_controller_content_changed_cb(void* p_data)
if (ctrl->p_content != NULL)
{
eina_list_free(ctrl->p_content);
ctrl->pf_view_clear(ctrl->p_view);
ctrl->p_list_view->pf_clear(ctrl->p_list_view->p_sys);
ctrl->p_content = NULL;
}
media_library* p_ml = (media_library*)application_get_media_library( ctrl->p_app );
......@@ -127,13 +127,13 @@ media_library_controller_refresh(media_library_controller* p_ctrl)
}
media_library_controller*
media_library_controller_create(application* p_app, view_sys* p_view )
media_library_controller_create(application* p_app, list_view* p_list_view )
{
media_library_controller* ctrl = calloc(1, sizeof(*ctrl));
if ( ctrl == NULL )
return NULL;
ctrl->p_app = p_app;
ctrl->p_view = p_view;
ctrl->p_list_view = p_list_view;
/* Populate it */
media_library* p_ml = (media_library*)application_get_media_library(p_app);
......
......@@ -31,7 +31,7 @@
#include "ui/interface.h"
media_library_controller*
media_library_controller_create( application* p_app, view_sys* p_view );
media_library_controller_create( application* p_app, list_view* p_list_view );
void
media_library_controller_destroy(media_library_controller *);
......
......@@ -29,10 +29,6 @@
#include "application.h"
typedef void* (*pf_view_append_media_item_cb)( view_sys* p_view, media_item* p_item );
typedef void (*pf_view_clear_cb)( view_sys* view );
typedef const media_item* (*pf_get_media_item_cb)( void* p_item_view );
typedef void (*pf_set_media_item_cb)( void* p_item_view, media_item* p_item );
typedef void (*pf_media_library_get_content_cb)( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
typedef bool (*pf_item_compare_cb)(const void* p_left, const void* p_right);
typedef void* (*pf_item_duplicate_cb)( const void* p_item );
......@@ -44,16 +40,12 @@ struct media_library_controller
* Content Management
*/
application* p_app;
view_sys* p_view;
list_view* p_list_view;
Eina_List* p_content;
/**
* Callbacks & settings
*/
pf_view_append_media_item_cb pf_view_append_media_item;
pf_view_clear_cb pf_view_clear;
pf_get_media_item_cb pf_get_media_item;
pf_set_media_item_cb pf_set_media_item;
pf_media_library_get_content_cb pf_media_library_get_content;
pf_item_compare_cb pf_item_compare;
pf_item_duplicate_cb pf_item_duplicate;
......
......@@ -115,11 +115,16 @@ intf_ml_file_changed( void* p_user_data );
/* List view items */
typedef struct list_sys list_sys;
typedef struct list_view list_view;
typedef struct list_view_item list_view_item;
typedef struct list_view
{
list_sys* p_sys;
void (*pf_del)(list_sys* p_sys);
void (*pf_show)(list_sys* p_sys, Evas_Object* p_parent);
void (*pf_del)(list_sys* p_sys);
void (*pf_show)(list_sys* p_sys, Evas_Object* p_parent);
list_view_item* (*pf_append_item)(list_sys* p_sys, void* p_item);
void (*pf_clear)(list_sys* p_sys);
const void* (*pf_get_item)(list_view_item* p_list_item);
void (*pf_set_item)(list_view_item* p_list_item, void* p_item);
} list_view;
#endif /* INTERFACE_H_ */
......@@ -40,7 +40,7 @@ struct list_sys
Elm_Genlist_Item_Class* p_default_item_class;
};
struct audio_list_item
struct list_view_item
{
const list_sys* p_list;
const Elm_Genlist_Item_Class* itc;
......@@ -51,7 +51,7 @@ struct audio_list_item
static void
free_list_item_data(void *data, Evas_Object *obj, void *event_info)
{
audio_list_item *ali = data;
list_view_item *ali = data;
media_item_destroy(ali->p_media_item);
free(ali);
}
......@@ -59,7 +59,7 @@ free_list_item_data(void *data, Evas_Object *obj, void *event_info)
static char *
genlist_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
audio_list_item *ali = data;
list_view_item *ali = data;
const Elm_Genlist_Item_Class *itc = ali->itc;
char *buf;
......@@ -83,15 +83,16 @@ genlist_text_get_cb(void *data, Evas_Object *obj, const char *part)
return NULL;
}
const media_item*
audio_list_song_item_get_media_item(audio_list_item* p_item)
static const void*
audio_list_song_item_get_media_item(list_view_item* p_item)
{
return p_item->p_media_item;
}
void
audio_list_song_item_set_media_item(audio_list_item* p_item, media_item* p_media_item)
static void
audio_list_song_item_set_media_item(list_view_item* p_item, void* p_data)
{
media_item *p_media_item = (media_item*)p_data;
p_item->p_media_item = p_media_item;
ecore_main_loop_thread_safe_call_async((Ecore_Cb)elm_genlist_item_update, p_item->p_object_item);
}
......@@ -99,7 +100,7 @@ audio_list_song_item_set_media_item(audio_list_item* p_item, media_item* p_media
static Evas_Object*
genlist_content_get_cb(void *data, Evas_Object *obj, const char *part)
{
audio_list_item *ali = data;
list_view_item *ali = data;
const Elm_Genlist_Item_Class *itc = ali->itc;
Evas_Object *layout = NULL;
......@@ -124,19 +125,20 @@ genlist_content_get_cb(void *data, Evas_Object *obj, const char *part)
static void
genlist_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
audio_list_item *ali = data;
list_view_item *ali = data;
intf_create_audio_player(ali->p_list->p_intf, ali->p_media_item->psz_path);
}
audio_list_item *
audio_list_song_view_append_item(list_sys *p_sys, media_item* p_item)
static list_view_item*
audio_list_song_view_append_item(list_sys *p_sys, void* p_data)
{
audio_list_item *ali = calloc(1, sizeof(*ali));
media_item* p_media_item = (media_item*)p_data;
list_view_item *ali = calloc(1, sizeof(*ali));
ali->p_list = p_sys;
ali->itc = p_sys->p_default_item_class;
ali->p_media_item = p_item;
ali->p_media_item = p_media_item;
/* Set and append new item in the genlist */
Elm_Object_Item *it = elm_genlist_item_append(p_sys->p_list,
......@@ -152,32 +154,13 @@ audio_list_song_view_append_item(list_sys *p_sys, media_item* p_item)
return ali;
}
list_sys*
audio_list_song_view_create(application* p_app, interface* p_intf, Evas_Object* p_genlist)
{
list_sys* p_list = calloc(1, sizeof(*p_list));
if (p_list == NULL)
return NULL;
p_list->p_list = p_genlist;
/* Item Class */
p_list->p_default_item_class = elm_genlist_item_class_new();
p_list->p_default_item_class->item_style = "2line.top.3";
p_list->p_default_item_class->func.text_get = genlist_text_get_cb;
p_list->p_default_item_class->func.content_get = genlist_content_get_cb;
p_list->p_ctrl = audio_controller_create(p_app, p_list);
p_list->p_intf = p_intf;
media_library_controller_refresh( p_list->p_ctrl );
return p_list;
}
void
static void
audio_list_song_view_clear(list_sys* p_list)
{
elm_genlist_clear(p_list->p_list);
}
void
static void
audio_list_song_view_show(list_sys* p_sys, Evas_Object* p_parent)
{
Elm_Object_Item *it = elm_naviframe_item_push(p_parent, "", NULL, NULL, p_sys->p_list, NULL);
......@@ -185,10 +168,41 @@ audio_list_song_view_show(list_sys* p_sys, Evas_Object* p_parent)
evas_object_show(p_sys->p_list);
}
void
static void
audio_list_song_view_destroy(list_sys* p_list)
{
media_library_controller_destroy(p_list->p_ctrl);
elm_genlist_item_class_free(p_list->p_default_item_class);
free(p_list);
}
list_view*
audio_list_song_view_create(application* p_app, interface* p_intf, Evas_Object* p_genlist)
{
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;
p_sys->p_list = p_genlist;
/* Item Class */
p_sys->p_default_item_class = elm_genlist_item_class_new();
p_sys->p_default_item_class->item_style = "2line.top.3";
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;
p_sys->p_intf = p_intf;
p_view->pf_show = &audio_list_song_view_show;
p_view->pf_del = &audio_list_song_view_destroy;
p_view->pf_append_item = &audio_list_song_view_append_item;
p_view->pf_clear = &audio_list_song_view_clear;
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_sys->p_ctrl = audio_controller_create(p_app, p_view);
media_library_controller_refresh( p_sys->p_ctrl );
return p_view;
}
......@@ -30,27 +30,7 @@
#include "media/media_item.h"
#include "ui/interface.h"
typedef struct audio_list_item audio_list_item;
const media_item*
audio_list_song_item_get_media_item(audio_list_item* p_item);
void
audio_list_song_item_set_media_item(audio_list_item* p_item, media_item* p_media_item);
audio_list_item *
audio_list_song_view_append_item(list_sys *p_sys, media_item* p_item);
void
audio_list_song_view_clear(list_sys* p_list);
list_sys*
list_view*
audio_list_song_view_create(application* p_app, interface* p_intf, Evas_Object* p_genlist);
void
audio_list_song_view_show(list_sys* p_sys, Evas_Object* p_parent);
void
audio_list_song_view_destroy(list_sys* p_list);
#endif // AUDIO_LIST_SONG_ITEM_H_
......@@ -78,9 +78,6 @@ create_audio_list_type(view_sys *av, audio_view_type type )
list_view* p_view = av->p_lists[type];
if(p_view == NULL)
{
p_view = calloc(1, sizeof(*p_view));
if (p_view == NULL)
return NULL;
Evas_Object* p_genlist = genlist_create(av);
if (p_genlist == NULL)
return NULL;
......@@ -88,9 +85,7 @@ create_audio_list_type(view_sys *av, audio_view_type type )
{
case AUDIO_VIEW_SONG:
default:
p_view->p_sys = audio_list_song_view_create(av->p_app, av->p_intf, p_genlist);
p_view->pf_show = &audio_list_song_view_show;
p_view->pf_del = &audio_list_song_view_destroy;
p_view = audio_list_song_view_create(av->p_app, av->p_intf, p_genlist);
// default:
// p_list = NULL;
}
......
......@@ -62,7 +62,7 @@ void
destroy_video_view(interface_view *view)
{
list_view* p_list_view = view->p_view_sys->p_list;
p_list_view->pf_del(p_list_view);
p_list_view->pf_del(p_list_view->p_sys);
free(p_list_view);
free(view->p_view_sys);
free(view);
......
......@@ -35,7 +35,7 @@
#include "video_player.h"
typedef struct video_list_item
struct list_view_item
{
list_sys* p_list;
media_item* p_media_item;
......@@ -43,7 +43,7 @@ typedef struct video_list_item
//For refresh purposes.
Elm_Object_Item* p_object_item;
} video_list_item;
};
struct list_sys
{
......@@ -76,7 +76,7 @@ genlist_update_empty_view(list_sys *p_sys)
void
genlist_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
{
video_list_item *vli = (video_list_item*)data;
list_view_item *vli = (list_view_item*)data;
intf_video_player_play(vli->p_list->p_intf, vli->p_media_item->psz_path);
}
......@@ -84,7 +84,7 @@ genlist_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
static void
free_list_item(void *data, Evas_Object *obj, void *event_info)
{
video_list_item *vli = data;
list_view_item *vli = data;
media_item_destroy(vli->p_media_item);
free(vli);
}
......@@ -92,7 +92,7 @@ free_list_item(void *data, Evas_Object *obj, void *event_info)
static char *
genlist_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
video_list_item *vli = data;
list_view_item *vli = data;
const Elm_Genlist_Item_Class *itc = vli->itc;
/* Check the item class style and put the current folder or file name as a string */
......@@ -120,15 +120,16 @@ genlist_text_get_cb(void *data, Evas_Object *obj, const char *part)
return NULL;
}
const media_item*
video_list_item_get_media_item(video_list_item* p_item)
static const void*
video_list_item_get_media_item(list_view_item* p_list_item)
{
return p_item->p_media_item;
return p_list_item->p_media_item;
}
void
video_list_item_set_media_item(video_list_item* p_item, media_item* p_media_item)
static void
video_list_item_set_media_item(list_view_item* p_item, void* p_data)
{
media_item* p_media_item = (media_item*)p_data;
p_item->p_media_item = p_media_item;
ecore_main_loop_thread_safe_call_async((Ecore_Cb)elm_genlist_item_update, p_item->p_object_item);
}
......@@ -136,7 +137,7 @@ video_list_item_set_media_item(video_list_item* p_item, media_item* p_media_item
static Evas_Object*
genlist_content_get_cb(void *data, Evas_Object *obj, const char *part)
{
video_list_item *vli = data;
list_view_item *vli = data;
const Elm_Genlist_Item_Class *itc = vli->itc;
Evas_Object *layout = NULL;
......@@ -186,11 +187,13 @@ genlist_contracted_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
elm_genlist_item_subitems_clear(it);
}
video_list_item *
video_view_append_item(list_sys *p_list, media_item* p_item)
static list_view_item*
video_view_append_item(list_sys *p_list, void* p_data)
{
media_item* p_item = (media_item*)p_data;
/* */
video_list_item *vli = calloc(1, sizeof(*vli));
LOGE("Adding media item %s", p_item->psz_path);
list_view_item *vli = calloc(1, sizeof(*vli));
if (vli == NULL)
return NULL;
vli->p_list = p_list;
......@@ -217,7 +220,7 @@ video_view_append_item(list_sys *p_list, media_item* p_item)
return vli;
}
void
static void
video_view_clear(list_sys* videoview)
{
elm_genlist_clear(videoview->p_video_list);
......@@ -273,10 +276,16 @@ video_view_list_create(interface *p_intf, Evas_Object *p_parent)
evas_object_smart_callback_add(p_genlist, "contracted", genlist_contracted_cb, NULL);
p_sys->p_intf = p_intf;
p_sys->p_controller = video_controller_create(intf_get_application(p_intf), p_sys);
p_view->pf_del = &video_view_list_destroy;
p_view->pf_append_item = &video_view_append_item;
p_view->pf_clear = &video_view_clear;
p_view->pf_get_item = &video_list_item_get_media_item;
p_view->pf_set_item = &video_list_item_set_media_item;
p_sys->p_controller = video_controller_create(intf_get_application(p_intf), p_view);
genlist_update_empty_view(p_sys);
return p_view;
......
......@@ -30,20 +30,6 @@
#include "media/media_item.h"
#include "ui/interface.h"
typedef struct video_list_item video_list_item;
const media_item*
video_list_item_get_media_item(video_list_item* p_item);
void
video_list_item_set_media_item(video_list_item* p_item, media_item* p_media_item);
video_list_item *
video_view_append_item(list_sys *videoview, media_item* p_item);
void
video_view_clear(list_sys* videoview);
list_view*
video_view_list_create(interface *intf, Evas_Object *p_genlist);
......
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