fileinfo.cpp
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:6k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * fileinfo.cpp : wxWindows plugin for vlc
  3.  *****************************************************************************
  4.  * Copyright (C) 2000-2004 VideoLAN
  5.  * $Id: fileinfo.cpp 8554 2004-08-28 19:29:32Z zorglub $
  6.  *
  7.  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #include <vlc/vlc.h>
  27. #include <vlc/intf.h>
  28. #include "wxwindows.h"
  29. /*****************************************************************************
  30.  * Event Table.
  31.  *****************************************************************************/
  32. static int ItemChanged( vlc_object_t *, const char *,
  33.                         vlc_value_t, vlc_value_t, void * );
  34. /* IDs for the controls and the menu commands */
  35. enum
  36. {
  37.     Close_Event
  38. };
  39. BEGIN_EVENT_TABLE(FileInfo, wxFrame)
  40.     /* Button events */
  41.     EVT_BUTTON(wxID_OK, FileInfo::OnClose)
  42.     /* Hide the window when the user closes the window */
  43.     EVT_CLOSE(FileInfo::OnClose)
  44. END_EVENT_TABLE()
  45. /*****************************************************************************
  46.  * Constructor.
  47.  *****************************************************************************/
  48. FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
  49.     wxFrame( p_parent, -1, wxU(_("Stream and media info")), wxDefaultPosition,
  50.              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
  51. {
  52.     playlist_t *p_playlist;
  53.     /* Initializations */
  54.     p_intf = _p_intf;
  55.     SetIcon( *p_intf->p_sys->p_icon );
  56.     SetAutoLayout( TRUE );
  57.     /* Create a panel to put everything in */
  58.     wxPanel *panel = new wxPanel( this, -1 );
  59.     panel->SetAutoLayout( TRUE );
  60.     fileinfo_tree =
  61.         new wxTreeCtrl( panel, -1, wxDefaultPosition, wxSize( 350, 350 ),
  62.                         wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | wxSUNKEN_BORDER );
  63.     fileinfo_root_label = wxT("");
  64.     /* Place everything in sizers */
  65.     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
  66.     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
  67.     panel_sizer->Add( fileinfo_tree, 1, wxEXPAND | wxALL, 5 );
  68.     panel_sizer->Layout();
  69.     panel->SetSizerAndFit( panel_sizer );
  70.     main_sizer->Add( panel, 1, wxEXPAND, 0 );
  71.     main_sizer->Layout();
  72.     SetSizerAndFit( main_sizer );
  73.     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
  74.                                                 FIND_ANYWHERE );
  75.     if( p_playlist )
  76.     {
  77.         var_AddCallback( p_playlist, "item-change", ItemChanged, this );
  78.         vlc_object_release( p_playlist );
  79.     }
  80.     b_need_update = VLC_TRUE;
  81.     UpdateFileInfo();
  82. }
  83. void FileInfo::UpdateFileInfo()
  84. {
  85.     input_thread_t *p_input = p_intf->p_sys->p_input;
  86.     if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
  87.     {
  88.         if( fileinfo_root )
  89.         {
  90.             fileinfo_root_label = wxT("");
  91.             fileinfo_tree->DeleteChildren( fileinfo_root );
  92.         }
  93.         return;
  94.     }
  95.     if( !fileinfo_root )
  96.     {
  97.         /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
  98.          * retrieved with the GetItemText() method, but it doesn't work on
  99.          * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
  100.          * use the fileinfo_root_label variable... */
  101.         fileinfo_root =
  102.             fileinfo_tree->AddRoot( wxL2U(p_input->input.p_item->psz_name) );
  103.         fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
  104.     }
  105.     else if( fileinfo_root_label == wxL2U(p_input->input.p_item->psz_name) &&
  106.              b_need_update == VLC_FALSE )
  107.     {
  108.         return;
  109.     }
  110.     /* We rebuild the tree from scratch */
  111.     fileinfo_tree->DeleteChildren( fileinfo_root );
  112.     fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
  113.     vlc_mutex_lock( &p_input->input.p_item->lock );
  114.     for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
  115.     {
  116.         info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
  117.         wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
  118.                                                       wxU(p_cat->psz_name) );
  119.         for( int j = 0; j < p_cat->i_infos; j++ )
  120.         {
  121.             info_t *p_info = p_cat->pp_infos[j];
  122.             fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name) +
  123.                                        wxT(": ") + wxU(p_info->psz_value) );
  124.         }
  125.         fileinfo_tree->Expand( cat );
  126.     }
  127.     vlc_mutex_unlock( &p_input->input.p_item->lock );
  128.     b_need_update = VLC_FALSE;
  129.     return;
  130. }
  131. FileInfo::~FileInfo()
  132. {
  133. }
  134. void FileInfo::OnClose( wxCommandEvent& event )
  135. {
  136.     Hide();
  137. }
  138. static int ItemChanged( vlc_object_t *p_this, const char *psz_var, 
  139.                         vlc_value_t oldval, vlc_value_t newval, void *param )
  140. {
  141.     FileInfo *p_fileinfo = (FileInfo *)param;
  142.     p_fileinfo->b_need_update = VLC_TRUE;
  143.     return VLC_SUCCESS;
  144. }