]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/fileinfo.cpp
contrib/makefile: add libmpcdec (Musepack) to win contribs
[vlc] / modules / gui / wxwidgets / fileinfo.cpp
1 /*****************************************************************************
2  * fileinfo.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
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 "wxwidgets.h"
31
32 /*****************************************************************************
33  * Event Table.
34  *****************************************************************************/
35
36 static int ItemChanged( vlc_object_t *, const char *,
37                         vlc_value_t, vlc_value_t, void * );
38
39
40 /* IDs for the controls and the menu commands */
41 enum
42 {
43     Close_Event
44 };
45
46 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
47     /* Button events */
48     EVT_BUTTON(wxID_OK, FileInfo::OnButtonClose)
49
50     /* Hide the window when the user closes the window */
51     EVT_CLOSE(FileInfo::OnClose)
52
53 END_EVENT_TABLE()
54
55 /*****************************************************************************
56  * Constructor.
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 )
61 {
62     playlist_t *p_playlist;
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     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
90                                                 FIND_ANYWHERE );
91
92     if( p_playlist )
93     {
94         var_AddCallback( p_playlist, "item-change", ItemChanged, this );
95         vlc_object_release( p_playlist );
96     }
97
98     b_need_update = VLC_TRUE;
99     UpdateFileInfo();
100 }
101
102 void FileInfo::UpdateFileInfo()
103 {
104     input_thread_t *p_input =
105         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
106                                            FIND_ANYWHERE );
107
108     if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
109     {
110         if( fileinfo_root )
111         {
112             fileinfo_root_label = wxT("");
113             fileinfo_tree->DeleteChildren( fileinfo_root );
114         }
115         if (p_input)
116         {
117             vlc_object_release(p_input);
118         }
119         return;
120     }
121
122     if( !fileinfo_root )
123     {
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... */
128         fileinfo_root =
129             fileinfo_tree->AddRoot( wxL2U(p_input->input.p_item->psz_name) );
130         fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
131     }
132     else if( fileinfo_root_label == wxL2U(p_input->input.p_item->psz_name) &&
133              b_need_update == VLC_FALSE )
134     {
135         vlc_object_release(p_input);
136         return;
137     }
138
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);
142
143     vlc_mutex_lock( &p_input->input.p_item->lock );
144     for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
145     {
146         info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
147
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++ )
151         {
152             info_t *p_info = p_cat->pp_infos[j];
153
154             if( p_info->psz_value[0] != 0 )
155             /* We only wanna show fields that have an actual value */
156             {
157                 fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name)
158                                         + wxT(": ") + wxU(p_info->psz_value) );
159             }
160         }
161         fileinfo_tree->Expand( cat );
162     }
163     vlc_mutex_unlock( &p_input->input.p_item->lock );
164
165     b_need_update = VLC_FALSE;
166
167     vlc_object_release(p_input);
168     return;
169 }
170
171 FileInfo::~FileInfo()
172 {
173 }
174
175 void FileInfo::OnButtonClose( wxCommandEvent& event )
176 {
177     wxCloseEvent cevent;
178     OnClose(cevent);
179 }
180
181 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
182 {
183     Hide();
184 }
185
186 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
187                         vlc_value_t oldval, vlc_value_t newval, void *param )
188 {
189     FileInfo *p_fileinfo = (FileInfo *)param;
190     p_fileinfo->b_need_update = VLC_TRUE;
191     return VLC_SUCCESS;
192 }