1 /*****************************************************************************
2 * fileinfo.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
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.
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.
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 *****************************************************************************/
24 #include "dialogs/fileinfo.hpp"
26 /*****************************************************************************
28 *****************************************************************************/
30 static int ItemChanged( vlc_object_t *, const char *,
31 vlc_value_t, vlc_value_t, void * );
34 /* IDs for the controls and the menu commands */
40 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
42 EVT_BUTTON(wxID_OK, FileInfo::OnButtonClose)
44 /* Hide the window when the user closes the window */
45 EVT_CLOSE(FileInfo::OnClose)
49 /*****************************************************************************
51 *****************************************************************************/
52 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
53 wxFrame( p_parent, -1, wxU(_("Stream and media info")), wxDefaultPosition,
54 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
56 playlist_t *p_playlist;
60 SetIcon( *p_intf->p_sys->p_icon );
61 SetAutoLayout( TRUE );
63 /* Create a panel to put everything in */
64 wxPanel *panel = new wxPanel( this, -1 );
65 panel->SetAutoLayout( TRUE );
68 new wxTreeCtrl( panel, -1, wxDefaultPosition, wxSize( 350, 350 ),
69 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | wxSUNKEN_BORDER );
71 fileinfo_root_label = wxT("");
73 /* Place everything in sizers */
74 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
75 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
76 panel_sizer->Add( fileinfo_tree, 1, wxEXPAND | wxALL, 5 );
77 panel_sizer->Layout();
78 panel->SetSizerAndFit( panel_sizer );
79 main_sizer->Add( panel, 1, wxEXPAND, 0 );
81 SetSizerAndFit( main_sizer );
83 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
88 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
89 vlc_object_release( p_playlist );
92 b_need_update = VLC_TRUE;
96 void FileInfo::UpdateFileInfo()
98 input_thread_t *p_input =
99 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
102 if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
106 fileinfo_root_label = wxT("");
107 fileinfo_tree->DeleteChildren( fileinfo_root );
111 vlc_object_release(p_input);
118 /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
119 * retrieved with the GetItemText() method, but it doesn't work on
120 * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
121 * use the fileinfo_root_label variable... */
123 fileinfo_tree->AddRoot( wxL2U(p_input->input.p_item->psz_name) );
124 fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
126 else if( fileinfo_root_label == wxL2U(p_input->input.p_item->psz_name) &&
127 b_need_update == VLC_FALSE )
129 vlc_object_release(p_input);
133 /* We rebuild the tree from scratch */
134 fileinfo_tree->DeleteChildren( fileinfo_root );
135 fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
137 vlc_mutex_lock( &p_input->input.p_item->lock );
138 for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
140 info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
142 wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
143 wxU(p_cat->psz_name) );
144 for( int j = 0; j < p_cat->i_infos; j++ )
146 info_t *p_info = p_cat->pp_infos[j];
148 if( p_info->psz_value[0] != 0 )
149 /* We only wanna show fields that have an actual value */
151 fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name)
152 + wxT(": ") + wxU(p_info->psz_value) );
155 fileinfo_tree->Expand( cat );
157 vlc_mutex_unlock( &p_input->input.p_item->lock );
159 b_need_update = VLC_FALSE;
161 vlc_object_release(p_input);
165 FileInfo::~FileInfo()
169 void FileInfo::OnButtonClose( wxCommandEvent& event )
175 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
180 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
181 vlc_value_t oldval, vlc_value_t newval, void *param )
183 FileInfo *p_fileinfo = (FileInfo *)param;
184 p_fileinfo->b_need_update = VLC_TRUE;