]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/fileinfo.cpp
488e87dfc045bf33f17381de342f77dd0fd002b1
[vlc] / modules / gui / wxwidgets / dialogs / 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "dialogs/fileinfo.hpp"
25
26 /*****************************************************************************
27  * Event Table.
28  *****************************************************************************/
29
30 static int ItemChanged( vlc_object_t *, const char *,
31                         vlc_value_t, vlc_value_t, void * );
32
33
34 /* IDs for the controls and the menu commands */
35 enum
36 {
37     Close_Event
38 };
39
40 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
41     /* Button events */
42     EVT_BUTTON(wxID_OK, FileInfo::OnButtonClose)
43
44     /* Hide the window when the user closes the window */
45     EVT_CLOSE(FileInfo::OnClose)
46
47 END_EVENT_TABLE()
48
49 /*****************************************************************************
50  * Constructor.
51  *****************************************************************************/
52 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
53     wxFrame( p_parent, -1, wxU(_("Stream and media info")), wxDefaultPosition,
54              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
55 {
56     playlist_t *p_playlist;
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     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
84                                                 FIND_ANYWHERE );
85
86     if( p_playlist )
87     {
88         var_AddCallback( p_playlist, "item-change", ItemChanged, this );
89         vlc_object_release( p_playlist );
90     }
91
92     b_need_update = VLC_TRUE;
93     UpdateFileInfo();
94 }
95
96 void FileInfo::UpdateFileInfo()
97 {
98     input_thread_t *p_input =
99         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
100                                            FIND_ANYWHERE );
101
102     if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
103     {
104         if( fileinfo_root )
105         {
106             fileinfo_root_label = wxT("");
107             fileinfo_tree->DeleteChildren( fileinfo_root );
108         }
109         if (p_input)
110         {
111             vlc_object_release(p_input);
112         }
113         return;
114     }
115
116     if( !fileinfo_root )
117     {
118         /* On linux, the first argument of wxTreeCtrl::AddRoot() can be
119          * retrieved with the GetItemText() method, but it doesn't work on
120          * Windows when the wxTR_HIDE_ROOT style is set. That's why we need to
121          * use the fileinfo_root_label variable... */
122         fileinfo_root =
123             fileinfo_tree->AddRoot( wxL2U(p_input->input.p_item->psz_name) );
124         fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
125     }
126     else if( fileinfo_root_label == wxL2U(p_input->input.p_item->psz_name) &&
127              b_need_update == VLC_FALSE )
128     {
129         vlc_object_release(p_input);
130         return;
131     }
132
133     /* We rebuild the tree from scratch */
134     fileinfo_tree->DeleteChildren( fileinfo_root );
135     fileinfo_root_label = wxL2U(p_input->input.p_item->psz_name);
136
137     vlc_mutex_lock( &p_input->input.p_item->lock );
138     for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
139     {
140         info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
141
142         wxTreeItemId cat = fileinfo_tree->AppendItem( fileinfo_root,
143                                                       wxU(p_cat->psz_name) );
144         for( int j = 0; j < p_cat->i_infos; j++ )
145         {
146             info_t *p_info = p_cat->pp_infos[j];
147
148             if( p_info->psz_value[0] != 0 )
149             /* We only wanna show fields that have an actual value */
150             {
151                 fileinfo_tree->AppendItem( cat, (wxString)wxU(p_info->psz_name)
152                                         + wxT(": ") + wxU(p_info->psz_value) );
153             }
154         }
155         fileinfo_tree->Expand( cat );
156     }
157     vlc_mutex_unlock( &p_input->input.p_item->lock );
158
159     b_need_update = VLC_FALSE;
160
161     vlc_object_release(p_input);
162     return;
163 }
164
165 FileInfo::~FileInfo()
166 {
167 }
168
169 void FileInfo::OnButtonClose( wxCommandEvent& event )
170 {
171     wxCloseEvent cevent;
172     OnClose(cevent);
173 }
174
175 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
176 {
177     Hide();
178 }
179
180 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
181                         vlc_value_t oldval, vlc_value_t newval, void *param )
182 {
183     FileInfo *p_fileinfo = (FileInfo *)param;
184     p_fileinfo->b_need_update = VLC_TRUE;
185     return VLC_SUCCESS;
186 }