]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/fileinfo.cpp
Add a close button. Put "-" instead of nothing when there is no info
[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 = (playlist_t *)vlc_object_find( p_intf,
59                                                  VLC_OBJECT_PLAYLIST,
60                                                  FIND_ANYWHERE );
61
62     /* Initializations */
63     SetIcon( *p_intf->p_sys->p_icon );
64     SetAutoLayout( TRUE );
65
66     panel_sizer = new wxBoxSizer( wxVERTICAL );
67
68     wxNotebook *notebook = new wxNotebook( this, -1 );
69 #if (!wxCHECK_VERSION(2,5,2))
70         wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
71 #endif
72     item_info = new MetaDataPanel( p_intf, notebook, false );
73     advanced_info = new AdvancedInfoPanel( p_intf, notebook );
74     stats_info = new InputStatsInfoPanel( p_intf, notebook );
75
76     notebook->AddPage( item_info, wxU(_("General") ), true );
77     notebook->AddPage( advanced_info, wxU(_("Advanced information") ), false );
78     notebook->AddPage( stats_info, wxU(_("Statistics") ), false );
79
80 #if (!wxCHECK_VERSION(2,5,2))
81     panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
82 #else
83     panel_sizer->Add( notebook, 1, wxEXPAND | wxALL, 5 );
84 #endif
85
86     panel_sizer->Add( new wxButton( this, wxID_CLOSE, wxU(_("Close") )) ,
87                       0, wxALL|wxALIGN_RIGHT, 5 );
88
89     panel_sizer->Layout();
90     SetSizerAndFit( panel_sizer );
91
92     if( p_playlist )
93     {
94         var_AddCallback( p_playlist, "item-change", ItemChanged, this );
95         vlc_object_release( p_playlist );
96     }
97
98     last_update = 0L;
99     b_need_update = VLC_TRUE;
100     Update();
101 }
102
103 void FileInfo::Update()
104 {
105
106     if( mdate() - last_update < 400000L ) return;
107     last_update = mdate();
108
109     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
110                                                  VLC_OBJECT_PLAYLIST,
111                                                  FIND_ANYWHERE );
112     if( !p_playlist ) return;
113
114     input_thread_t *p_input = p_playlist->p_input ;
115
116     if( !p_input || p_input->b_dead || !p_input->input.p_item->psz_name )
117     {
118         item_info->Clear();
119         advanced_info->Clear();
120         stats_info->Clear();
121         vlc_object_release( p_playlist );
122         return;
123     }
124
125     vlc_object_yield( p_input );
126     vlc_mutex_lock( &p_input->input.p_item->lock );
127     if( b_need_update == VLC_TRUE )
128     {
129         vlc_mutex_unlock( &p_input->input.p_item->lock  );
130         item_info->Update( p_input->input.p_item );
131         vlc_mutex_lock( &p_input->input.p_item->lock  );
132         advanced_info->Update( p_input->input.p_item );
133     }
134     stats_info->Update( p_input->input.p_item );
135     vlc_mutex_unlock( &p_input->input.p_item->lock );
136
137     vlc_object_release(p_input);
138     vlc_object_release( p_playlist );
139     b_need_update = VLC_FALSE;
140     panel_sizer->Layout();
141
142     return;
143 }
144
145 FileInfo::~FileInfo()
146 {
147 }
148
149 void FileInfo::OnButtonClose( wxCommandEvent& event )
150 {
151     wxCloseEvent cevent;
152     OnClose(cevent);
153 }
154
155 void FileInfo::OnClose( wxCloseEvent& WXUNUSED(event) )
156 {
157     Hide();
158 }
159
160 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
161                         vlc_value_t oldval, vlc_value_t newval, void *param )
162 {
163     FileInfo *p_fileinfo = (FileInfo *)param;
164     p_fileinfo->b_need_update = VLC_TRUE;
165     return VLC_SUCCESS;
166 }