hierarchical_media_list_view.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:8k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * hierarchical_media_list_view.c: libvlc hierarchical media list view functs.
  3.  *****************************************************************************
  4.  * Copyright (C) 2007 the VideoLAN team
  5.  * $Id: ee89ba8e5514138dcb6d91c14d3803240457ea95 $
  6.  *
  7.  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. #include <vlc/libvlc.h>
  24. #include <vlc/libvlc_media.h>
  25. #include <vlc/libvlc_media_list.h>
  26. #include <vlc/libvlc_media_list_view.h>
  27. #include "media_list_internal.h"
  28. #include "media_list_view_internal.h"
  29. //#define DEBUG_HIERARCHICAL_VIEW
  30. #ifdef DEBUG_HIERARCHICAL_VIEW
  31. # define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ )
  32. #else
  33. # define trace( ... )
  34. #endif
  35. /*
  36.  * Private functions
  37.  */
  38. /**************************************************************************
  39.  *       flat_media_list_view_count  (private)
  40.  * (called by media_list_view_count)
  41.  **************************************************************************/
  42. static int
  43. hierarch_media_list_view_count( libvlc_media_list_view_t * p_mlv,
  44.                                 libvlc_exception_t * p_e )
  45. {
  46.     return libvlc_media_list_count( p_mlv->p_mlist, p_e );
  47. }
  48. /**************************************************************************
  49.  *       flat_media_list_view_item_at_index  (private)
  50.  * (called by flat_media_list_view_item_at_index)
  51.  **************************************************************************/
  52. static libvlc_media_t *
  53. hierarch_media_list_view_item_at_index( libvlc_media_list_view_t * p_mlv,
  54.                                     int index,
  55.                                     libvlc_exception_t * p_e )
  56. {
  57.     return libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
  58. }
  59. /**************************************************************************
  60.  *       flat_media_list_view_item_at_index  (private)
  61.  * (called by flat_media_list_view_item_at_index)
  62.  **************************************************************************/
  63. static libvlc_media_list_view_t *
  64. hierarch_media_list_view_children_at_index( libvlc_media_list_view_t * p_mlv,
  65.                                         int index,
  66.                                         libvlc_exception_t * p_e )
  67. {
  68.     libvlc_media_t * p_md;
  69.     libvlc_media_list_t * p_submlist;
  70.     libvlc_media_list_view_t * p_ret;
  71.     p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
  72.     if( !p_md ) return NULL;
  73.     p_submlist = libvlc_media_subitems( p_md, p_e );
  74.     libvlc_media_release( p_md );
  75.     if( !p_submlist ) return NULL;
  76.     p_ret = libvlc_media_list_hierarchical_view( p_submlist, p_e );
  77.     libvlc_media_list_release( p_submlist );
  78.     return p_ret;
  79. }
  80. /**************************************************************************
  81.  *       media_list_(item|will)_* (private) (Event callback)
  82.  **************************************************************************/
  83. static void
  84. media_list_item_added( const libvlc_event_t * p_event, void * user_data )
  85. {
  86.     libvlc_media_t * p_md;
  87.     libvlc_media_list_view_t * p_mlv = user_data;
  88.     int index = p_event->u.media_list_item_added.index;
  89.     p_md = p_event->u.media_list_item_added.item;
  90.     libvlc_media_list_view_item_added( p_mlv, p_md, index );
  91. }
  92. static void
  93. media_list_will_add_item( const libvlc_event_t * p_event, void * user_data )
  94. {
  95.     libvlc_media_t * p_md;
  96.     libvlc_media_list_view_t * p_mlv = user_data;
  97.     int index = p_event->u.media_list_will_add_item.index;
  98.     p_md = p_event->u.media_list_will_add_item.item;
  99.     libvlc_media_list_view_will_add_item( p_mlv, p_md, index );
  100. }
  101. static void
  102. media_list_item_deleted( const libvlc_event_t * p_event, void * user_data )
  103. {
  104.     libvlc_media_t * p_md;
  105.     libvlc_media_list_view_t * p_mlv = user_data;
  106.     int index = p_event->u.media_list_item_deleted.index;
  107.     p_md = p_event->u.media_list_item_deleted.item;
  108.     libvlc_media_list_view_item_deleted( p_mlv, p_md, index );
  109. }
  110. static void
  111. media_list_will_delete_item( const libvlc_event_t * p_event, void * user_data )
  112. {
  113.     libvlc_media_t * p_md;
  114.     libvlc_media_list_view_t * p_mlv = user_data;
  115.     int index = p_event->u.media_list_will_delete_item.index;
  116.     p_md = p_event->u.media_list_will_delete_item.item;
  117.     libvlc_media_list_view_will_delete_item( p_mlv, p_md, index );
  118. }
  119. /*
  120.  * Public libvlc functions
  121.  */
  122. /**************************************************************************
  123.  *       flat_media_list_view_release (private)
  124.  * (called by media_list_view_release)
  125.  **************************************************************************/
  126. static void
  127. hierarch_media_list_view_release( libvlc_media_list_view_t * p_mlv )
  128. {
  129.     libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
  130.                          libvlc_MediaListItemAdded,
  131.                          media_list_item_added, p_mlv, NULL );
  132.     libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
  133.                          libvlc_MediaListWillAddItem,
  134.                          media_list_will_add_item, p_mlv, NULL );
  135.     libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
  136.                          libvlc_MediaListItemDeleted,
  137.                          media_list_item_deleted, p_mlv, NULL );
  138.     libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
  139.                          libvlc_MediaListWillDeleteItem,
  140.                          media_list_will_delete_item, p_mlv, NULL );
  141. }
  142. /**************************************************************************
  143.  *       libvlc_media_list_flat_view (Public)
  144.  **************************************************************************/
  145. libvlc_media_list_view_t *
  146. libvlc_media_list_hierarchical_view( libvlc_media_list_t * p_mlist,
  147.                                      libvlc_exception_t * p_e )
  148. {
  149.     trace("n");
  150.     libvlc_media_list_view_t * p_mlv;
  151.     p_mlv = libvlc_media_list_view_new( p_mlist,
  152.                                         hierarch_media_list_view_count,
  153.                                         hierarch_media_list_view_item_at_index,
  154.                                         hierarch_media_list_view_children_at_index,
  155.                                         libvlc_media_list_hierarchical_view,
  156.                                         hierarch_media_list_view_release,
  157.                                         NULL,
  158.                                         p_e );
  159.     libvlc_media_list_lock( p_mlist );
  160.     libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
  161.                          libvlc_MediaListItemAdded,
  162.                          media_list_item_added, p_mlv, NULL );
  163.     libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
  164.                          libvlc_MediaListWillAddItem,
  165.                          media_list_will_add_item, p_mlv, NULL );
  166.     libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
  167.                          libvlc_MediaListItemDeleted,
  168.                          media_list_item_deleted, p_mlv, NULL );
  169.     libvlc_event_attach( p_mlv->p_mlist->p_event_manager,
  170.                          libvlc_MediaListWillDeleteItem,
  171.                          media_list_will_delete_item, p_mlv, NULL );
  172.     libvlc_media_list_unlock( p_mlist );
  173.     return p_mlv;
  174. }