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