]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/fileinfo.cpp
* modules/gui/wxwindows/preferences_widgets.cpp: compilation fix.
[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.19 2003/09/21 18:07:51 gbazin 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 #include <vlc/intf.h>
34
35 #include "wxwindows.h"
36 #include <wx/treectrl.h>
37
38 /*****************************************************************************
39  * Event Table.
40  *****************************************************************************/
41
42 /* IDs for the controls and the menu commands */
43 enum
44 {
45     Close_Event
46 };
47
48 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
49     /* Button events */
50     EVT_BUTTON(wxID_OK, FileInfo::OnClose)
51
52     /* Hide the window when the user closes the window */
53     EVT_CLOSE(FileInfo::OnClose)
54
55 END_EVENT_TABLE()
56
57 /*****************************************************************************
58  * Constructor.
59  *****************************************************************************/
60 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
61     wxFrame( p_parent, -1, wxU(_("FileInfo")), wxDefaultPosition,
62              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
63 {
64     /* Initializations */
65     p_intf = _p_intf;
66     SetIcon( *p_intf->p_sys->p_icon );
67     SetAutoLayout( TRUE );
68
69     /* Create a panel to put everything in */
70     wxPanel *panel = new wxPanel( this, -1 );
71     panel->SetAutoLayout( TRUE );
72
73     fileinfo_tree =
74         new wxTreeCtrl( panel, -1, wxDefaultPosition, wxSize( 350, 350 ),
75                         wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | wxSUNKEN_BORDER );
76
77     fileinfo_root_label = wxT("");
78
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 );
86     main_sizer->Layout();
87     SetSizerAndFit( main_sizer );
88
89     UpdateFileInfo();
90 }
91
92 void FileInfo::UpdateFileInfo()
93 {
94     input_thread_t *p_input = p_intf->p_sys->p_input;
95
96     if( !p_input || p_input->b_dead || !p_input->psz_name )
97     {
98         if( fileinfo_root )
99         {
100             fileinfo_root_label = wxT("");
101             fileinfo_tree->DeleteChildren( fileinfo_root );
102         }
103         return;
104     }
105
106     if( !fileinfo_root )
107     {
108         /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
109          * retrieved with the GetItemText() method, but it doesn't work on
110          * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
111          * use the fileinfo_root_label variable... */
112         fileinfo_root = fileinfo_tree->AddRoot( wxU(p_input->psz_name) );
113         fileinfo_root_label = wxU(p_input->psz_name);
114     }
115     else if( fileinfo_root_label == wxU(p_input->psz_name) )
116     {
117         return;
118     }
119
120     /* We rebuild the tree from scratch */
121     fileinfo_tree->DeleteChildren( fileinfo_root );
122     fileinfo_root_label = wxU(p_input->psz_name);
123
124     vlc_mutex_lock( &p_input->stream.stream_lock );
125
126     input_info_category_t *p_cat = p_input->stream.p_info;
127
128     while( p_cat )
129     {
130         wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
131                                                       wxU(p_cat->psz_name) );
132         input_info_t *p_info = p_cat->p_info;
133         while( p_info )
134         {
135             fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name) +
136                                        wxT(": ") + wxU(p_info->psz_value) );
137             p_info = p_info->p_next;
138         }
139         p_cat = p_cat->p_next;
140         fileinfo_tree->Expand( cat );
141     }
142
143     vlc_mutex_unlock( &p_input->stream.stream_lock );
144
145     return;
146 }
147
148 FileInfo::~FileInfo()
149 {
150 }
151
152 void FileInfo::OnClose( wxCommandEvent& event )
153 {
154     Hide();
155 }