]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/fileinfo.cpp
df06c633c32065d570c0fcadca50af5b0698e1bc
[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 #include "dialogs/infopanels.hpp"
26
27 /*****************************************************************************
28  * Event Table.
29  *****************************************************************************/
30
31 static int ItemChanged( vlc_object_t *, const char *,
32                         vlc_value_t, vlc_value_t, void * );
33
34
35 /* IDs for the controls and the menu commands */
36 enum
37 {
38     Close_Event
39 };
40
41 BEGIN_EVENT_TABLE(FileInfo, wxFrame)
42     /* Button events */
43     EVT_BUTTON(wxID_CLOSE, FileInfo::OnButtonClose)
44
45     /* Hide the window when the user closes the window */
46     EVT_CLOSE(FileInfo::OnClose)
47
48 END_EVENT_TABLE()
49
50 /*****************************************************************************
51  * Constructor.
52  *****************************************************************************/
53 FileInfo::FileInfo( intf_thread_t *_p_intf, wxWindow *p_parent ):
54     wxFrame( p_parent, -1, wxU(_("Stream and Media Info")), wxDefaultPosition,
55              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
56 {
57     p_intf = _p_intf;
58     playlist_t *p_playlist = pl_Yield( p_intf );
59
60     b_stats = config_GetInt(p_intf, "stats");
61     /* Initializations */
62     SetIcon( *p_intf->p_sys->p_icon );
63     SetAutoLayout( TRUE );
64
65     /* Create a panel to put everything in */
66     wxPanel *panel = new wxPanel( this, -1 );
67     panel->SetAutoLayout( TRUE );
68
69     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
70     panel_sizer = new wxBoxSizer( wxVERTICAL );
71
72     wxNotebook *notebook = new wxNotebook( panel, -1 );
73 #if (!wxCHECK_VERSION(2,5,2))
74         wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
75 #endif
76     item_info = new MetaDataPanel( p_intf, notebook, false );
77     advanced_info = new AdvancedInfoPanel( p_intf, notebook );
78     if( b_stats )
79         stats_info = new InputStatsInfoPanel( p_intf, notebook );
80
81     notebook->AddPage( item_info, wxU(_("General") ), true );
82     notebook->AddPage( advanced_info, wxU(_("Advanced information") ), false );
83     if( b_stats )
84         notebook->AddPage( stats_info, wxU(_("Statistics") ), false );
85
86 #if (!wxCHECK_VERSION(2,5,2))
87     panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
88 #else
89     panel_sizer->Add( notebook, 1, wxEXPAND | wxALL, 5 );
90 #endif
91
92     panel_sizer->Add( new wxButton( panel, wxID_CLOSE, wxU(_("&Close")) ) ,
93                       0, wxALL|wxALIGN_RIGHT, 5 );
94
95     panel_sizer->Layout();
96     panel->SetSizerAndFit( panel_sizer );
97     main_sizer->Add( panel, 1, wxGROW, 0 );
98     main_sizer->Layout();
99     SetSizerAndFit( main_sizer );
100
101     if( p_playlist )
102     {
103         var_AddCallback( p_playlist, "item-change", ItemChanged, this );
104         pl_Release( p_playlist );
105     }
106
107     last_update = 0L;
108     b_need_update = true;
109     Update();
110 }
111
112 void FileInfo::Update()
113 {
114     if( mdate() - last_update < 400000L ) return;
115     last_update = mdate();
116
117     playlist_t *p_playlist = pl_Yield( p_intf );
118     if( !p_playlist ) return;
119
120     input_thread_t *p_input = p_playlist->p_input ;
121     if( !p_input || p_input->b_dead || !input_GetItem(p_input)->psz_name )
122     {
123         item_info->Clear();
124         advanced_info->Clear();
125         if( b_stats )
126             stats_info->Clear();
127         pl_Release( p_playlist );
128         return;
129     }
130     pl_Release( p_playlist );
131
132     vlc_object_yield( p_input );
133     vlc_mutex_lock( &input_GetItem(p_input)->lock );
134     if( b_need_update == true )
135     {
136         vlc_mutex_unlock( &input_GetItem(p_input)->lock  );
137         item_info->Update( input_GetItem(p_input) );
138         vlc_mutex_lock( &input_GetItem(p_input)->lock  );
139         advanced_info->Update( input_GetItem(p_input) );
140     }
141     if( b_stats )
142         stats_info->Update( input_GetItem(p_input) );
143     vlc_mutex_unlock( &input_GetItem(p_input)->lock );
144
145     vlc_object_release(p_input);
146     pl_Release( p_playlist );
147     b_need_update = false;
148     panel_sizer->Layout();
149
150     return;
151 }
152
153 FileInfo::~FileInfo()
154 {
155 }
156
157 void FileInfo::OnButtonClose( wxCommandEvent& event )
158 {
159     wxCloseEvent cevent;
160     OnClose(cevent);
161 }
162
163 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
164 {
165     Hide();
166 }
167
168 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
169                         vlc_value_t oldval, vlc_value_t newval, void *param )
170 {
171     FileInfo *p_fileinfo = (FileInfo *)param;
172     p_fileinfo->b_need_update = true;
173     return VLC_SUCCESS;
174 }