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

introduce a library_item type.

It is a "base" of all library originating items.
This prevents accepting albums in artist views, and vice versa.
It should also allow us to share more code among views
parent 77f8e6e1
......@@ -34,32 +34,37 @@
#include "ui/views/video_view.h"
#include "ui/views/audio_view.h"
struct library_item
{
LIBRARY_ITEM_COMMON
};
static bool
video_controller_accept_item( const void* p_item )
video_controller_accept_item( const library_item* p_item )
{
const media_item* p_media_item = (const media_item*)p_item;
return p_media_item->i_type == MEDIA_ITEM_TYPE_VIDEO;
return p_item->i_library_item_type == LIBRARY_ITEM_MEDIA &&
p_media_item->i_type == MEDIA_ITEM_TYPE_VIDEO;
}
static bool
audio_controller_accept_item( const void* p_item )
audio_controller_accept_item( const library_item* p_item )
{
const media_item* p_media_item = (const media_item*)p_item;
return p_media_item->i_type == MEDIA_ITEM_TYPE_AUDIO;
return p_item->i_library_item_type == LIBRARY_ITEM_MEDIA &&
p_media_item->i_type == MEDIA_ITEM_TYPE_AUDIO;
}
static bool
artist_controller_accept_item( const void* p_item )
artist_controller_accept_item( const library_item* p_item )
{
(void)p_item;
return true;
return p_item->i_library_item_type == LIBRARY_ITEM_ARTIST;
}
static bool
album_controller_accept_item( const void* p_item )
album_controller_accept_item( const library_item* p_item )
{
(void)p_item;
return true;
return p_item->i_library_item_type == LIBRARY_ITEM_ALBUM;
}
media_library_controller*
......
......@@ -46,7 +46,7 @@ media_library_controller_add_item(media_library_controller* ctrl, media_item* p_
}
bool
media_library_controller_file_update( media_library_controller* ctrl, const void* p_media_item )
media_library_controller_file_update( media_library_controller* ctrl, const library_item* p_media_item )
{
if ( ctrl->pf_accept_item( p_media_item ) == false )
return false;
......@@ -75,7 +75,7 @@ media_library_controller_file_update( media_library_controller* ctrl, const void
}
static bool
media_library_controller_file_updated_cb(void* p_data, const media_item* p_new_media_item, bool b_added )
media_library_controller_file_updated_cb(void* p_data, const library_item* p_new_media_item, bool b_added )
{
(void)b_added;
media_library_controller* ctrl = (media_library_controller*)p_data;
......
......@@ -28,11 +28,12 @@
# define MEDIA_LIBRARY_CONTROLLER_PRIVATE_H_
#include "application.h"
#include "media/library/library_item.h"
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 );
typedef bool (*pf_accept_item_cb)( const library_item* p_item );
struct media_library_controller
{
......
......@@ -33,6 +33,7 @@ album_item_create(const char* psz_name)
album_item* p_item = calloc(1, sizeof(*p_item));
if (p_item == NULL)
return NULL;
p_item->i_library_item_type = LIBRARY_ITEM_ALBUM;
p_item->psz_name = strdup(psz_name);
if (p_item->psz_name == NULL)
{
......
......@@ -27,11 +27,15 @@
#ifndef ALBUM_ITEM_H_
# define ALBUM_ITEM_H_
#include "media/library/library_item.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct album_item {
LIBRARY_ITEM_COMMON
char* psz_name;
char* psz_summary;
time_t i_release_date;
......
......@@ -33,6 +33,7 @@ artist_item_create(const char* psz_name)
artist_item* p_item = calloc(1, sizeof(*p_item));
if (p_item == NULL)
return NULL;
p_item->i_library_item_type = LIBRARY_ITEM_ARTIST;
p_item->psz_name = strdup(psz_name);
if (p_item->psz_name == NULL)
{
......
......@@ -27,12 +27,16 @@
#ifndef ARTIST_ITEM_H_
# define ARTIST_ITEM_H_
#include "media/library/library_item.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct artist_item
{
LIBRARY_ITEM_COMMON
char* psz_name;
} artist_item;
......
/*****************************************************************************
* 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 LIBRARY_ITEM_H_
# define LIBRARY_ITEM_H_
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct library_item library_item;
typedef enum library_item_type
{
LIBRARY_ITEM_MEDIA = 1,
LIBRARY_ITEM_ALBUM,
LIBRARY_ITEM_ARTIST,
LIBRARY_ITEM_GENRE
} library_item_type;
#define LIBRARY_ITEM_COMMON \
library_item_type i_library_item_type;
#ifdef __cplusplus
}
#endif
#endif // LIBRARY_ITEM_H_
......@@ -64,7 +64,7 @@ media_library::sendFileUpdate( FilePtr file, bool added )
auto item_ptr = std::unique_ptr<media_item, void(*)(media_item*)> ( ctx->item, &media_item_destroy );
for ( auto& p : ctx->ml->m_onItemUpdatedCb )
{
if ( p.first( p.second, ctx->item, ctx->added ) == true )
if ( p.first( p.second, reinterpret_cast<library_item*>(ctx->item), ctx->added ) == true )
break;
}
delete ctx;
......
......@@ -44,7 +44,7 @@ typedef void (*media_library_list_cb)( Eina_List*, void *p_user_data );
* looking to update.
* There is no warranty about which thread will call this callback.
*/
typedef bool (*media_library_item_updated_cb)( void *p_user_data, const media_item* p_item, bool b_new );
typedef bool (*media_library_item_updated_cb)( void *p_user_data, const library_item* p_item, bool b_new );
media_library*
media_library_create(application* p_app);
......
......@@ -32,6 +32,7 @@ media_item_create(const char *psz_path, enum MEDIA_ITEM_TYPE i_type)
if (!p_mi)
return NULL;
p_mi->i_library_item_type = LIBRARY_ITEM_MEDIA;
p_mi->psz_path = strdup(psz_path);
if (!p_mi->psz_path)
goto error;
......
......@@ -25,6 +25,8 @@
#ifndef MEDIA_ITEM_H_
#define MEDIA_ITEM_H_
#include "media/library/library_item.h"
#ifdef __cplusplus
extern "C"
{
......@@ -51,6 +53,8 @@ enum MEDIA_ITEM_META {
};
typedef struct media_item {
LIBRARY_ITEM_COMMON
char *psz_path; /* Normalized path on the device */
enum MEDIA_ITEM_TYPE i_type; /* Video, Audio, Subs, etc... */
......
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