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

Rename media_controller to media_library_controller

This removes references to video & media_item from the controller
A new video_controller_create function is introduced to create a
media_library_controller meant to handle video files
parent 9966905a
......@@ -38,7 +38,7 @@ typedef struct playback_service playback_service;
typedef struct media_storage media_storage;
typedef struct media_item media_item;
typedef struct media_list media_list;
typedef struct media_controller media_controller;
typedef struct media_library_controller media_library_controller;
#include "system_storage.h"
......
......@@ -25,148 +25,41 @@
*****************************************************************************/
#include "common.h"
#include "media_controller.h"
#include "application.h"
#include "media/library/media_library.hpp"
#include "media_controller.h"
#include "media_library_controller.h"
#include "media_library_controller_private.h"
#include "ui/views/video_view.h"
#include "ui/interface.h"
#include <assert.h>
struct media_controller
{
/**
* Content Management
*/
application* p_app;
view_sys* p_view;
// This is the content as a video_list_item list.
Eina_List* p_content;
/**
* Callbacks & settings
*/
video_list_item* (*pf_view_append_media_item)( view_sys* p_view, media_item* p_item );
void (*pf_view_clear)( view_sys* videoview );
const media_item* (*pf_get_media_item)( video_list_item* p_view );
void (*pf_set_media_item)( video_list_item* p_view, media_item* p_item );
void (*pf_media_library_get_content)( media_library* p_ml, media_library_list_cb cb, void* p_user_data );
enum MEDIA_ITEM_TYPE i_type;
};
static void
media_controller_add_item(media_controller* ctrl, media_item* p_item)
{
video_list_item* p_view_item = ctrl->pf_view_append_media_item( ctrl->p_view, p_item );
if (p_view_item == NULL)
return;
ctrl->p_content = eina_list_append(ctrl->p_content, p_view_item);
}
bool
media_controller_file_update( media_controller* ctrl, const media_item* p_media_item )
{
if ( p_media_item->i_type != ctrl->i_type )
return false;
media_item* p_new_media_item = media_item_copy( p_media_item );
if (p_new_media_item == NULL)
return true;
if ( ctrl->p_content != NULL )
{
Eina_List* it;
video_list_item* p_item;
EINA_LIST_FOREACH( ctrl->p_content, it, p_item )
{
const media_item* p_media_item = ctrl->pf_get_media_item(p_item);
if ( media_item_identical( p_media_item, p_new_media_item) )
{
ctrl->pf_set_media_item(p_item, p_new_media_item);
return true;
}
}
}
media_controller_add_item( ctrl, p_new_media_item );
return true;
}
static bool
media_controller_file_updated_cb(void* p_data, const media_item* p_new_media_item, bool b_added )
{
(void)b_added;
media_controller* ctrl = (media_controller*)p_data;
return media_controller_file_update(ctrl, p_new_media_item);
}
/* Called by the Media Library with updated video list
* Guaranteed to be called from the main loop
*/
void
media_controller_content_update_cb(Eina_List* p_content, void* p_data)
{
if (p_content == NULL)
return;
media_controller* ctrl = (media_controller*)p_data;
Eina_List* it;
media_item* p_item;
EINA_LIST_FOREACH( p_content, it, p_item )
{
media_controller_file_update(ctrl, p_item);
}
}
/*
* Called when media library signals a content change (currently, only after reload)
* Guaranteed to be called from the main loop
*/
void
media_controller_content_changed_cb(void* p_data)
video_controller_accept_item( const void* p_item )
{
media_controller* ctrl = (media_controller*)p_data;
// Discard previous content if any, and ask ML for the new content
if (ctrl->p_content != NULL)
{
eina_list_free(ctrl->p_content);
ctrl->pf_view_clear(ctrl->p_view);
ctrl->p_content = NULL;
}
media_library* p_ml = (media_library*)application_get_media_library( ctrl->p_app );
ctrl->pf_media_library_get_content(p_ml, &media_controller_content_update_cb, ctrl);
const media_item* p_media_item = (const media_item*)p_item;
return p_media_item->i_type == MEDIA_ITEM_TYPE_VIDEO;
}
media_controller*
video_controller_create(application* p_app, view_sys* p_view )
static media_library_controller*
media_controller_create(application* p_app, view_sys* p_view)
{
media_controller* ctrl = calloc(1, sizeof(*ctrl));
if ( ctrl == NULL )
return NULL;
ctrl->p_app = p_app;
ctrl->p_view = p_view;
ctrl->pf_view_append_media_item = &video_view_append_item;
ctrl->pf_get_media_item = &video_list_item_get_media_item;
ctrl->pf_set_media_item = &video_list_item_set_media_item;
ctrl->pf_media_library_get_content = &media_library_get_video_files;
ctrl->pf_view_clear = &video_view_clear;
ctrl->i_type = MEDIA_ITEM_TYPE_VIDEO;
/* Populate it */
media_library* p_ml = (media_library*)application_get_media_library(p_app);
media_library_register_on_change(p_ml, media_controller_content_changed_cb, ctrl);
media_library_register_item_updated(p_ml, media_controller_file_updated_cb, ctrl);
return ctrl;
media_library_controller* p_ctrl = media_library_controller_create( p_app, p_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;
return p_ctrl;
}
void
media_controller_destroy(media_controller *ctrl)
media_library_controller*
video_controller_create(application* p_app, view_sys* p_view)
{
eina_list_free(ctrl->p_content);
media_library* p_ml = (media_library*)application_get_media_library(ctrl->p_app);
media_library_unregister_on_change(p_ml, &media_controller_content_changed_cb, ctrl);
media_library_unregister_item_updated(p_ml, &media_controller_file_updated_cb, ctrl);
free(ctrl);
media_library_controller* p_ctrl = media_controller_create( p_app, p_view );
if ( p_ctrl == NULL )
return NULL;
p_ctrl->pf_accept_item = &video_controller_accept_item;
return p_ctrl;
}
......@@ -24,16 +24,11 @@
* compatibility with the Store
*****************************************************************************/
#ifndef VIDEO_CONTROLLER_H_
#define VIDEO_CONTROLLER_H_
#include "application.h"
#include "ui/interface.h"
media_controller*
video_controller_create( application* p_app, view_sys* p_view );
void
media_controller_destroy(media_controller *);
// Allow one file to include "media_controller.h" and still get public media_library_controller API
#include "media_library_controller.h"
#endif /* VIDEO_CONTROLLER_H_ */
media_library_controller*
video_controller_create(application* p_app, view_sys* p_view);
/*****************************************************************************
* Copyright © 2015 VideoLAN, VideoLabs SAS
*****************************************************************************
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*
* By committing to this project, you allow VideoLAN and VideoLabs to relicense
* the code to a different OSI approved license, in case it is required for
* compatibility with the Store
*****************************************************************************/
#include "common.h"
#include "media_library_controller.h"
#include "application.h"
#include "media/library/media_library.hpp"
#include "ui/views/video_view.h"
#include "ui/interface.h"
#include <assert.h>
#include "media_library_controller_private.h"
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 );
if (p_view_item == NULL)
return;
ctrl->p_content = eina_list_append(ctrl->p_content, p_view_item);
}
bool
media_library_controller_file_update( media_library_controller* ctrl, const void* p_media_item )
{
if ( ctrl->pf_accept_item( p_media_item ) == false )
return false;
void* p_new_media_item = ctrl->pf_item_duplicate( p_media_item );
if (p_new_media_item == NULL)
return true;
if ( ctrl->p_content != NULL )
{
Eina_List* it;
void* p_item;
EINA_LIST_FOREACH( ctrl->p_content, it, p_item )
{
const void* p_media_item = ctrl->pf_get_media_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);
return true;
}
}
}
media_library_controller_add_item( ctrl, p_new_media_item );
return true;
}
static bool
media_library_controller_file_updated_cb(void* p_data, const media_item* p_new_media_item, bool b_added )
{
(void)b_added;
media_library_controller* ctrl = (media_library_controller*)p_data;
return media_library_controller_file_update(ctrl, p_new_media_item);
}
/* Called by the Media Library with updated video list
* Guaranteed to be called from the main loop
*/
void
media_library_controller_content_update_cb(Eina_List* p_content, void* p_data)
{
if (p_content == NULL)
return;
media_library_controller* ctrl = (media_library_controller*)p_data;
Eina_List* it;
void* p_item;
EINA_LIST_FOREACH( p_content, it, p_item )
{
media_library_controller_file_update(ctrl, p_item);
}
}
/*
* Called when media library signals a content change (currently, only after reload)
* Guaranteed to be called from the main loop
*/
void
media_library_controller_content_changed_cb(void* p_data)
{
media_library_controller* ctrl = (media_library_controller*)p_data;
// Discard previous content if any, and ask ML for the new content
if (ctrl->p_content != NULL)
{
eina_list_free(ctrl->p_content);
ctrl->pf_view_clear(ctrl->p_view);
ctrl->p_content = NULL;
}
media_library* p_ml = (media_library*)application_get_media_library( ctrl->p_app );
ctrl->pf_media_library_get_content(p_ml, &media_library_controller_content_update_cb, ctrl);
}
media_library_controller*
media_library_controller_create(application* p_app, view_sys* p_view )
{
media_library_controller* ctrl = calloc(1, sizeof(*ctrl));
if ( ctrl == NULL )
return NULL;
ctrl->p_app = p_app;
ctrl->p_view = p_view;
/* Populate it */
media_library* p_ml = (media_library*)application_get_media_library(p_app);
media_library_register_on_change(p_ml, media_library_controller_content_changed_cb, ctrl);
media_library_register_item_updated(p_ml, media_library_controller_file_updated_cb, ctrl);
return ctrl;
}
void
media_library_controller_destroy(media_library_controller *ctrl)
{
eina_list_free(ctrl->p_content);
media_library* p_ml = (media_library*)application_get_media_library(ctrl->p_app);
media_library_unregister_on_change(p_ml, &media_library_controller_content_changed_cb, ctrl);
media_library_unregister_item_updated(p_ml, &media_library_controller_file_updated_cb, ctrl);
free(ctrl);
}
/*****************************************************************************
* Copyright © 2015 VideoLAN, VideoLabs SAS
*****************************************************************************
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*
* By committing to this project, you allow VideoLAN and VideoLabs to relicense
* the code to a different OSI approved license, in case it is required for
* compatibility with the Store
*****************************************************************************/
#ifndef VIDEO_CONTROLLER_H_
#define VIDEO_CONTROLLER_H_
#include "application.h"
#include "ui/interface.h"
media_library_controller*
media_library_controller_create( application* p_app, view_sys* p_view );
void
media_library_controller_destroy(media_library_controller *);
#endif /* VIDEO_CONTROLLER_H_ */
/*****************************************************************************
* Copyright © 2015 VideoLAN, VideoLabs SAS
*****************************************************************************
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*
* By committing to this project, you allow VideoLAN and VideoLabs to relicense
* the code to a different OSI approved license, in case it is required for
* compatibility with the Store
*****************************************************************************/
#ifndef MEDIA_LIBRARY_CONTROLLER_PRIVATE_H_
# define MEDIA_LIBRARY_CONTROLLER_PRIVATE_H_
#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 );
typedef bool (*pf_accept_item_cb)( const void* p_item );
struct media_library_controller
{
/**
* Content Management
*/
application* p_app;
view_sys* p_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;
pf_accept_item_cb pf_accept_item;
};
#endif //MEDIA_LIBRARY_CONTROLLER_PRIVATE_H_
......@@ -41,7 +41,7 @@ struct view_sys
{
interface *p_intf;
media_controller* p_controller;
media_library_controller* p_controller;
Evas_Object *p_video_list;
Elm_Genlist_Item_Class* p_default_item_class;
......@@ -246,7 +246,7 @@ void
destroy_video_view(interface_view *view)
{
elm_genlist_item_class_free(view->p_view_sys->p_default_item_class);
media_controller_destroy(view->p_view_sys->p_controller);
media_library_controller_destroy(view->p_view_sys->p_controller);
free(view->p_view_sys);
free(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