Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

fileinfo.cpp

00001 /*****************************************************************************
00002  * fileinfo.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: fileinfo.cpp 12836 2005-10-15 13:23:08Z sigmunau $
00006  *
00007  * Authors: Sigmund Augdal Helberg <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <vlc/vlc.h>
00028 #include <vlc/intf.h>
00029 
00030 #include "wxwidgets.h"
00031 
00032 /*****************************************************************************
00033  * Event Table.
00034  *****************************************************************************/
00035 
00036 static int ItemChanged( vlc_object_t *, const char *,
00037                         vlc_value_t, vlc_value_t, void * );
00038 
00039 
00040 /* IDs for the controls and the menu commands */
00041 enum
00042 {
00043     Close_Event
00044 };
00045 
00046 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
00047     /* Button events */
00048     EVT_BUTTON(wxID_OK, FileInfo::OnButtonClose)
00049 
00050     /* Hide the window when the user closes the window */
00051     EVT_CLOSE(FileInfo::OnClose)
00052 
00053 END_EVENT_TABLE()
00054 
00055 /*****************************************************************************
00056  * Constructor.
00057  *****************************************************************************/
00058 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
00059     wxFrame( p_parent, -1, wxU(_("Stream and media info")), wxDefaultPosition,
00060              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
00061 {
00062     playlist_t *p_playlist;
00063 
00064     /* Initializations */
00065     p_intf = _p_intf;
00066     SetIcon( *p_intf->p_sys->p_icon );
00067     SetAutoLayout( TRUE );
00068 
00069     /* Create a panel to put everything in */
00070     wxPanel *panel = new wxPanel( this, -1 );
00071     panel->SetAutoLayout( TRUE );
00072 
00073     fileinfo_tree =
00074         new wxTreeCtrl( panel, -1, wxDefaultPosition, wxSize( 350, 350 ),
00075                         wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | wxSUNKEN_BORDER );
00076 
00077     fileinfo_root_label = wxT("");
00078 
00079     /* Place everything in sizers */
00080     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
00081     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
00082     panel_sizer->Add( fileinfo_tree, 1, wxEXPAND | wxALL, 5 );
00083     panel_sizer->Layout();
00084     panel->SetSizerAndFit( panel_sizer );
00085     main_sizer->Add( panel, 1, wxEXPAND, 0 );
00086     main_sizer->Layout();
00087     SetSizerAndFit( main_sizer );
00088 
00089     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00090                                                 FIND_ANYWHERE );
00091 
00092     if( p_playlist )
00093     {
00094         var_AddCallback( p_playlist, "item-change", ItemChanged, this );
00095         vlc_object_release( p_playlist );
00096     }
00097 
00098     b_need_update = VLC_TRUE;
00099     UpdateFileInfo();
00100 }
00101 
00102 void FileInfo::UpdateFileInfo()
00103 {
00104     input_thread_t *p_input =
00105         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00106                                            FIND_ANYWHERE );
00107 
00108     if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
00109     {
00110         if( fileinfo_root )
00111         {
00112             fileinfo_root_label = wxT("");
00113             fileinfo_tree->DeleteChildren( fileinfo_root );
00114         }
00115         if (p_input)
00116         {
00117             vlc_object_release(p_input);
00118         }
00119         return;
00120     }
00121 
00122     if( !fileinfo_root )
00123     {
00124         /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
00125          * retrieved with the GetItemText() method, but it doesn't work on
00126          * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
00127          * use the fileinfo_root_label variable... */
00128         fileinfo_root =
00129             fileinfo_tree->AddRoot( wxL2U(p_input->input.p_item->psz_name) );
00130         fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
00131     }
00132     else if( fileinfo_root_label == wxL2U(p_input->input.p_item->psz_name) &&
00133              b_need_update == VLC_FALSE )
00134     {
00135         vlc_object_release(p_input);
00136         return;
00137     }
00138 
00139     /* We rebuild the tree from scratch */
00140     fileinfo_tree->DeleteChildren( fileinfo_root );
00141     fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
00142 
00143     vlc_mutex_lock( &p_input->input.p_item->lock );
00144     for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
00145     {
00146         info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
00147 
00148         wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
00149                                                       wxU(p_cat->psz_name) );
00150         for( int j = 0; j < p_cat->i_infos; j++ )
00151         {
00152             info_t *p_info = p_cat->pp_infos[j];
00153 
00154             if( p_info->psz_value[0] != 0 )
00155             /* We only wanna show fields that have an actual value */
00156             {
00157                 fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name)
00158                                         + wxT(": ") + wxU(p_info->psz_value) );
00159             }
00160         }
00161         fileinfo_tree->Expand( cat );
00162     }
00163     vlc_mutex_unlock( &p_input->input.p_item->lock );
00164 
00165     b_need_update = VLC_FALSE;
00166 
00167     vlc_object_release(p_input);
00168     return;
00169 }
00170 
00171 FileInfo::~FileInfo()
00172 {
00173 }
00174 
00175 void FileInfo::OnButtonClose( wxCommandEvent& event )
00176 {
00177     wxCloseEvent cevent;
00178     OnClose(cevent);
00179 }
00180 
00181 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
00182 {
00183     Hide();
00184 }
00185 
00186 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
00187                         vlc_value_t oldval, vlc_value_t newval, void *param )
00188 {
00189     FileInfo *p_fileinfo = (FileInfo *)param;
00190     p_fileinfo->b_need_update = VLC_TRUE;
00191     return VLC_SUCCESS;
00192 }

Generated on Tue Dec 20 10:14:44 2005 for vlc-0.8.4a by  doxygen 1.4.2