]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/fileinfo.cpp
corrected a newbie notation
[vlc] / modules / gui / wxwindows / fileinfo.cpp
1 /*****************************************************************************
2  * fileinfo.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: fileinfo.cpp,v 1.16 2003/06/09 19:08:33 asmax Exp $
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 <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44 #include <wx/treectrl.h>
45
46 #include <vlc/intf.h>
47
48 #if defined MODULE_NAME_IS_skins
49 #   include "../skins/src/skin_common.h"
50 #endif
51
52 #include "wxwindows.h"
53
54 /*****************************************************************************
55  * Event Table.
56  *****************************************************************************/
57
58 /* IDs for the controls and the menu commands */
59 enum
60 {
61     Close_Event
62 };
63
64 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
65     /* Button events */
66     EVT_BUTTON(wxID_OK, FileInfo::OnClose)
67
68     /* Hide the window when the user closes the window */
69     EVT_CLOSE(FileInfo::OnClose)
70
71 END_EVENT_TABLE()
72
73 /*****************************************************************************
74  * Constructor.
75  *****************************************************************************/
76 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
77     wxFrame( p_parent, -1, wxU(_("FileInfo")), wxDefaultPosition,
78              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
79 {
80     /* Initializations */
81     p_intf = _p_intf;
82     SetIcon( *p_intf->p_sys->p_icon );
83     SetAutoLayout( TRUE );
84
85     /* Create a panel to put everything in */
86     wxPanel *panel = new wxPanel( this, -1 );
87     panel->SetAutoLayout( TRUE );
88
89     fileinfo_tree =
90         new wxTreeCtrl( panel, -1, wxDefaultPosition, wxSize( 350, 350 ),
91                         wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | wxSUNKEN_BORDER );
92
93     fileinfo_root_label = wxT("");
94
95     /* Create the OK button */
96     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
97     ok_button->SetDefault();
98
99     /* Place everything in sizers */
100     wxBoxSizer *ok_button_sizer = new wxBoxSizer( wxHORIZONTAL );
101     ok_button_sizer->Add( ok_button, 0, wxALL, 5 );
102     ok_button_sizer->Layout();
103     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
104     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
105     panel_sizer->Add( fileinfo_tree, 1, wxEXPAND | wxALL, 5 );
106     panel_sizer->Add( ok_button_sizer, 0, wxALIGN_CENTRE );
107     panel_sizer->Layout();
108     panel->SetSizerAndFit( panel_sizer );
109     main_sizer->Add( panel, 1, wxEXPAND, 0 );
110     main_sizer->Layout();
111     SetSizerAndFit( main_sizer );
112
113     UpdateFileInfo();
114 }
115
116 void FileInfo::UpdateFileInfo()
117 {
118     input_thread_t *p_input = p_intf->p_sys->p_input;
119
120     if( !p_input || p_input->b_dead || !p_input->psz_name )
121     {
122         if( fileinfo_root )
123         {
124             fileinfo_root_label = wxT("");
125             fileinfo_tree->DeleteChildren( fileinfo_root );
126         }
127         return;
128     }
129
130     if( !fileinfo_root )
131     {
132         /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
133          * retrieved with the GetItemText() method, but it doesn't work on
134          * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
135          * use the fileinfo_root_label variable... */
136         fileinfo_root = fileinfo_tree->AddRoot( wxU(p_input->psz_name) );
137         fileinfo_root_label = wxU(p_input->psz_name);
138     }
139     else if( fileinfo_root_label == wxU(p_input->psz_name) )
140     {
141         return;
142     }
143
144     /* We rebuild the tree from scratch */
145     fileinfo_tree->DeleteChildren( fileinfo_root );
146     fileinfo_root_label = wxU(p_input->psz_name);
147
148     vlc_mutex_lock( &p_input->stream.stream_lock );
149
150     input_info_category_t *p_cat = p_input->stream.p_info;
151
152     while( p_cat )
153     {
154         wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
155                                                       wxU(p_cat->psz_name) );
156         input_info_t *p_info = p_cat->p_info;
157         while( p_info )
158         {
159             fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name) +
160                                        wxT(": ") + wxU(p_info->psz_value) );
161             p_info = p_info->p_next;
162         }
163         p_cat = p_cat->p_next;
164         fileinfo_tree->Expand( cat );
165     }
166
167     vlc_mutex_unlock( &p_input->stream.stream_lock );
168
169     return;
170 }
171
172 FileInfo::~FileInfo()
173 {
174 }
175
176 void FileInfo::OnClose( wxCommandEvent& event )
177 {
178     Hide();
179 }