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

Handle video files updates

parent 900f4544
......@@ -32,10 +32,13 @@
#include "ui/views/video_view.h"
#include "ui/interface.h"
#include <assert.h>
struct video_controller
{
application* p_app;
video_view* p_view;
// This is the content as a video_list_item list.
Eina_List* p_content;
};
......@@ -46,20 +49,28 @@ void
video_controller_content_update_cb(Eina_List* p_content, void* p_data)
{
video_controller* ctrl = (video_controller*)p_data;
ctrl->p_content = p_content;
video_view_update( ctrl->p_view, p_content );
if (p_content == NULL)
return;
Eina_List* it;
media_item* p_item;
assert(ctrl->p_content == NULL);
EINA_LIST_FOREACH( p_content, it, p_item )
{
video_list_item* p_view_item = video_view_append_item( ctrl->p_view, p_item );
if (p_view_item == NULL)
continue;
ctrl->p_content = eina_list_append(ctrl->p_content, p_view_item);
}
}
/* Queries the media library for the updated video list */
void
video_controller_content_refresh(video_controller* ctrl)
{
// If we already have some content, simply send it to the view
// If we already have some content, consider the view up to date
if (ctrl->p_content != NULL)
{
video_view_update( ctrl->p_view, ctrl->p_content );
return;
}
// otherwise, update from media library
const media_library* p_ml = application_get_media_library( ctrl->p_app );
media_library_get_video_files(p_ml, &video_controller_content_update_cb, ctrl);
......@@ -80,6 +91,33 @@ video_controller_content_changed_cb(void* p_data)
video_controller_content_refresh(ctrl);
}
static bool
video_controller_file_updated_cb( void* p_data, const media_item* p_new_media_item )
{
LOGI("Updating: %s", p_new_media_item->psz_path);
video_controller* ctrl = (video_controller*)p_data;
if ( ctrl->p_content == NULL )
{
LOGI("No content, aborting");
return false;
}
Eina_List* it;
video_list_item* p_item;
EINA_LIST_FOREACH( ctrl->p_content, it, p_item )
{
const media_item* p_media_item = video_list_item_get_media_item(p_item);
if (!strcmp( p_media_item->psz_path, p_new_media_item->psz_path))
{
video_list_item_set_media_item(p_item, p_new_media_item);
return true;
}
}
return false;
}
video_controller*
video_controller_create( application* p_app, video_view* p_view )
{
......@@ -92,5 +130,6 @@ video_controller_create( application* p_app, video_view* p_view )
/* Populate it */
media_library* p_ml = application_get_media_library(p_app);
media_library_register_on_change(p_ml, video_controller_content_changed_cb, ctrl);
media_library_register_item_updated(p_ml, video_controller_file_updated_cb, ctrl);
return ctrl;
}
......@@ -274,10 +274,7 @@ fileToMediaItem( FilePtr file )
return nullptr;
}
media_item_set_meta(mi, MEDIA_ITEM_META_TITLE, file->name().c_str());
// If the file hasn't been parsed yet, there's no change we can do something
// usefull past this point, we will try again after onFileUpdated gets called.
if ( file->isParsed() == false )
return mi;
mi->i_duration = file->duration();
if ( file->type() == IFile::Type::VideoType )
{
......
......@@ -44,6 +44,8 @@ typedef struct video_view
Evas_Object *p_parent;
Evas_Object *p_genlist;
video_controller* p_controller;
Elm_Genlist_Item_Class* p_default_itc;
} video_view;
typedef struct video_list_item
......@@ -54,6 +56,9 @@ typedef struct video_list_item
media_item *p_media_item;
//For refresh purposes.
Elm_Object_Item* p_object_item;
} video_list_item;
void
......@@ -131,6 +136,29 @@ 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)
{
return p_item->p_media_item;
}
void
video_list_item_set_media_item(video_list_item* p_item, const media_item* p_media_item)
{
LOGI("Received update request for [%s]", p_media_item->psz_path);
bool b_changed = false;
if (p_item->p_media_item->i_duration != p_media_item->i_duration)
{
LOGI("Updated duration");
p_item->p_media_item->i_duration = p_media_item->i_duration;
b_changed = true;
}
if (b_changed == true)
{
ecore_main_loop_thread_safe_call_async(elm_genlist_item_update, p_item->p_object_item);
}
}
static Evas_Object*
genlist_content_get_cb(void *data, Evas_Object *obj, const char *part)
{
......@@ -180,50 +208,40 @@ genlist_contracted_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
elm_genlist_item_subitems_clear(it);
}
static video_list_item *
genlist_item_create(video_view *videoview, media_item* p_item, Elm_Genlist_Item_Class* itc)
video_list_item *
video_view_append_item(video_view *videoview, media_item* p_item)
{
/* */
video_list_item *vli = calloc(1, sizeof(*vli));
if (vli == NULL)
return NULL;
vli->videoview = videoview;
vli->itc = itc;
vli->itc = videoview->p_default_itc;
/* Item instantiation */
vli->p_media_item = p_item;
/* Set and append new item in the genlist */
Elm_Object_Item *it = elm_genlist_item_append(videoview->p_genlist,
itc, /* genlist item class */
vli->p_object_item = elm_genlist_item_append(videoview->p_genlist,
vli->itc, /* genlist item class */
vli, /* genlist item class user data */
NULL, /* genlist parent item for trees */
ELM_GENLIST_ITEM_NONE, /* genlist item type */
genlist_item_selected_cb, /* genlist select smart callback */
vli); /* genlist smart callback user data */
if (vli->p_object_item == NULL)
{
free(vli);
return NULL;
}
/* */
elm_object_item_del_cb_set(it, free_list_item);
elm_object_item_del_cb_set(vli->p_object_item, free_list_item);
return vli;
}
void
video_view_update(video_view* vv, Eina_List* p_content)
video_view_clear(video_view* videoview)
{
if ( p_content == NULL )
return;
/* Genlist class */
Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
itc->item_style = "2line.top.3";
itc->func.text_get = genlist_text_get_cb;
itc->func.content_get = genlist_content_get_cb;
Eina_List* it = NULL;
media_item* p_item;
EINA_LIST_FOREACH( p_content, it, p_item )
{
genlist_item_create(vv, p_item, itc);
}
elm_genlist_item_class_free(itc);
elm_genlist_clear(videoview->p_genlist);
}
Evas_Object*
......@@ -234,6 +252,13 @@ create_video_view(interface *intf, Evas_Object *parent)
vv->p_parent = parent;
vv->p_controller = video_controller_create( intf_get_application(intf), vv );
/* Genlist class */
vv->p_default_itc = elm_genlist_item_class_new();
//FIXME: this is leaking, please call elm_genlist_item_class_free() from somewhere
vv->p_default_itc->item_style = "2line.top.3";
vv->p_default_itc->func.text_get = genlist_text_get_cb;
vv->p_default_itc->func.content_get = genlist_content_get_cb;
/* Set then create the Genlist object */
Evas_Object *genlist = vv->p_genlist = elm_genlist_add(parent);
......
......@@ -30,6 +30,7 @@
#include <Elementary.h>
typedef struct video_view video_view;
typedef struct video_list_item video_list_item;
Evas_Object*
create_video_view(interface *intf, Evas_Object *parent);
......@@ -37,4 +38,16 @@ create_video_view(interface *intf, Evas_Object *parent);
void
video_view_update(video_view* vv, Eina_List* p_content);
video_list_item *
video_view_append_item(video_view *videoview, media_item* p_item);
void
video_view_clear(video_view* videoview);
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, const media_item* p_media_item);
#endif /* VIDEO_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