1 /*****************************************************************************
2 * fileinfo.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
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 /*****************************************************************************
26 *****************************************************************************/
30 #include "wxwindows.h"
32 /*****************************************************************************
34 *****************************************************************************/
36 static int ItemChanged( vlc_object_t *, const char *,
37 vlc_value_t, vlc_value_t, void * );
40 /* IDs for the controls and the menu commands */
46 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
48 EVT_BUTTON(wxID_OK, FileInfo::OnButtonClose)
50 /* Hide the window when the user closes the window */
51 EVT_CLOSE(FileInfo::OnClose)
55 /*****************************************************************************
57 *****************************************************************************/
58 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
59 wxFrame( p_parent, -1, wxU(_("Stream and media info")), wxDefaultPosition,
60 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
62 playlist_t *p_playlist;
66 SetIcon( *p_intf->p_sys->p_icon );
67 SetAutoLayout( TRUE );
69 /* Create a panel to put everything in */
70 wxPanel *panel = new wxPanel( this, -1 );
71 panel->SetAutoLayout( TRUE );
74 new wxTreeCtrl( panel, -1, wxDefaultPosition, wxSize( 350, 350 ),
75 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | wxSUNKEN_BORDER );
77 fileinfo_root_label = wxT("");
79 /* Place everything in sizers */
80 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
81 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
82 panel_sizer->Add( fileinfo_tree, 1, wxEXPAND | wxALL, 5 );
83 panel_sizer->Layout();
84 panel->SetSizerAndFit( panel_sizer );
85 main_sizer->Add( panel, 1, wxEXPAND, 0 );
87 SetSizerAndFit( main_sizer );
89 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
94 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
95 vlc_object_release( p_playlist );
98 b_need_update = VLC_TRUE;
102 void FileInfo::UpdateFileInfo()
104 input_thread_t *p_input =
105 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
108 if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
112 fileinfo_root_label = wxT("");
113 fileinfo_tree->DeleteChildren( fileinfo_root );
117 vlc_object_release(p_input);
124 /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
125 * retrieved with the GetItemText() method, but it doesn't work on
126 * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
127 * use the fileinfo_root_label variable... */
129 fileinfo_tree->AddRoot( wxL2U(p_input->input.p_item->psz_name) );
130 fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
132 else if( fileinfo_root_label == wxL2U(p_input->input.p_item->psz_name) &&
133 b_need_update == VLC_FALSE )
135 vlc_object_release(p_input);
139 /* We rebuild the tree from scratch */
140 fileinfo_tree->DeleteChildren( fileinfo_root );
141 fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
143 vlc_mutex_lock( &p_input->input.p_item->lock );
144 for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
146 info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
148 wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
149 wxU(p_cat->psz_name) );
150 for( int j = 0; j < p_cat->i_infos; j++ )
152 info_t *p_info = p_cat->pp_infos[j];
154 fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name) +
155 wxT(": ") + wxU(p_info->psz_value) );
157 fileinfo_tree->Expand( cat );
159 vlc_mutex_unlock( &p_input->input.p_item->lock );
161 b_need_update = VLC_FALSE;
163 vlc_object_release(p_input);
167 FileInfo::~FileInfo()
171 void FileInfo::OnButtonClose( wxCommandEvent& event )
177 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
182 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
183 vlc_value_t oldval, vlc_value_t newval, void *param )
185 FileInfo *p_fileinfo = (FileInfo *)param;
186 p_fileinfo->b_need_update = VLC_TRUE;