]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/infopanels.cpp
* Show meta-information separately
[vlc] / modules / gui / wxwidgets / dialogs / infopanels.cpp
1 /*****************************************************************************
2  * infopanels.cpp : Information panels (general info, stats, ...)
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id: iteminfo.cpp 13905 2006-01-12 23:10:04Z dionoea $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@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/infopanels.hpp"
25 #include <wx/combobox.h>
26 #include <wx/statline.h>
27
28 #include <vlc_meta.h>
29
30 #ifndef wxRB_SINGLE
31 #   define wxRB_SINGLE 0
32 #endif
33
34 /*****************************************************************************
35  * General info (URI, name, metadata)
36  *****************************************************************************/
37 BEGIN_EVENT_TABLE( MetaDataPanel, wxPanel )
38 END_EVENT_TABLE()
39
40 MetaDataPanel::MetaDataPanel( intf_thread_t *_p_intf,
41                               wxWindow* _p_parent,
42                               bool _b_modifiable ):
43     wxPanel( _p_parent, -1 )
44 {
45     int flags= wxTE_PROCESS_ENTER;
46     /* Initializations */
47     p_intf = _p_intf;
48     p_parent = _p_parent;
49     b_modifiable = _b_modifiable;
50
51     SetAutoLayout( TRUE );
52
53     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
54
55     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,8,20);
56     sizer->AddGrowableCol(1);
57
58     if( !b_modifiable )
59         flags |= wxTE_READONLY;
60
61     /* URI Textbox */
62     wxStaticText *uri_static =
63            new wxStaticText( this, -1, wxU(_("URI")) );
64     sizer->Add( uri_static, 0 , wxALL , 0 );
65
66     uri_text = new wxTextCtrl( this, -1,
67             wxU(""), wxDefaultPosition, wxSize( 300, -1 ), flags );
68     sizer->Add( uri_text, 1 ,  wxALL|wxEXPAND , 0 );
69
70     /* Name Textbox */
71     wxStaticText *name_static =
72            new wxStaticText(  this, -1, wxU(_("Name")) );
73     sizer->Add( name_static, 0 , wxALL , 0  );
74
75     name_text = new wxTextCtrl( this, -1,
76             wxU(""), wxDefaultPosition, wxSize( 300, -1 ), flags );
77     sizer->Add( name_text, 1 , wxALL|wxEXPAND , 0 );
78     sizer->Layout();
79
80     /* Metadata */
81     wxFlexGridSizer *meta_sizer = new wxFlexGridSizer(2,11,20);
82     meta_sizer->AddGrowableCol(1);
83
84 #define ADD_META( string, widget ) {                                        \
85         meta_sizer->Add( new wxStaticText( this, -1, wxU(_(string) ) ),1,   \
86                          wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 0 );                \
87         widget = new wxStaticText( this, -1, wxU( "" ) );                   \
88         meta_sizer->Add( widget, 1, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 0 ); }
89
90     ADD_META( VLC_META_ARTIST, artist_text );
91     ADD_META( VLC_META_GENRE, genre_text );
92     ADD_META( VLC_META_COPYRIGHT, copyright_text );
93     ADD_META( VLC_META_COLLECTION, collection_text );
94     ADD_META( VLC_META_SEQ_NUM, seqnum_text );
95     ADD_META( VLC_META_DESCRIPTION, description_text );
96     ADD_META( VLC_META_RATING, rating_text );
97     ADD_META( VLC_META_DATE, date_text );
98     ADD_META( VLC_META_LANGUAGE, language_text );
99     ADD_META( VLC_META_NOW_PLAYING, nowplaying_text );
100     ADD_META( VLC_META_PUBLISHER, publisher_text );
101
102     meta_sizer->Layout();
103
104     panel_sizer->Add( sizer, 0, wxEXPAND | wxALL, 5 );
105     panel_sizer->Add( meta_sizer, 0, wxEXPAND | wxALL, 5 );
106     panel_sizer->Layout();
107     SetSizerAndFit( panel_sizer );
108 }
109
110 MetaDataPanel::~MetaDataPanel()
111 {
112 }
113
114 void MetaDataPanel::Update( input_item_t *p_item )
115 {
116     /* Rebuild the tree */
117     Clear();
118
119     uri_text->SetValue( wxU( p_item->psz_uri ) );
120     name_text->SetValue( wxU( p_item->psz_name ) );
121
122 #define UPDATE_META( meta, widget ) {                                       \
123     char *psz_meta = vlc_input_item_GetInfo( p_item, _(VLC_META_INFO_CAT),  \
124                                             _(meta) );                      \
125     if( psz_meta != NULL )                                                  \
126     {                                                                       \
127         widget->SetLabel( wxU( psz_meta ) );                                \
128     }                                                                       \
129     }
130
131     UPDATE_META( VLC_META_ARTIST, artist_text );
132     UPDATE_META( VLC_META_GENRE, genre_text );
133     UPDATE_META( VLC_META_COPYRIGHT, copyright_text );
134     UPDATE_META( VLC_META_COLLECTION, collection_text );
135     UPDATE_META( VLC_META_SEQ_NUM, seqnum_text );
136     UPDATE_META( VLC_META_DESCRIPTION, description_text );
137     UPDATE_META( VLC_META_RATING, rating_text );
138     UPDATE_META( VLC_META_DATE, date_text );
139     UPDATE_META( VLC_META_LANGUAGE, language_text );
140     UPDATE_META( VLC_META_NOW_PLAYING, nowplaying_text );
141     UPDATE_META( VLC_META_PUBLISHER, publisher_text );
142
143 #undef UPDATE_META
144 }
145
146 char* MetaDataPanel::GetURI( )
147 {
148     return  strdup( uri_text->GetLineText(0).mb_str() );
149 }
150
151 char* MetaDataPanel::GetName( )
152 {
153     return  strdup( name_text->GetLineText(0).mb_str() );
154 }
155
156 void MetaDataPanel::Clear()
157 {
158 }
159
160 void MetaDataPanel::OnOk( )
161 {
162 }
163
164 void MetaDataPanel::OnCancel( )
165 {
166 }
167
168
169 /*****************************************************************************
170  * General info panel
171  *****************************************************************************/
172 BEGIN_EVENT_TABLE( AdvancedInfoPanel, wxPanel )
173 END_EVENT_TABLE()
174
175 AdvancedInfoPanel::AdvancedInfoPanel( intf_thread_t *_p_intf,
176                                       wxWindow* _p_parent ):
177     wxPanel( _p_parent, -1 )
178 {
179     int flags= wxTE_PROCESS_ENTER;
180     /* Initializations */
181     p_intf = _p_intf;
182     p_parent = _p_parent;
183
184     SetAutoLayout( TRUE );
185
186     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
187
188     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,8,20);
189     sizer->AddGrowableCol(1);
190
191     /* Treeview */
192     info_tree = new wxTreeCtrl( this, -1, wxDefaultPosition,
193                                 wxSize(220,200),
194                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
195                                 wxTR_HIDE_ROOT );
196     info_root = info_tree->AddRoot( wxU( "" ) );
197
198     panel_sizer->Add( info_tree, 1, wxEXPAND | wxALL, 5 );
199     panel_sizer->Layout();
200     SetSizerAndFit( panel_sizer );
201 }
202
203 AdvancedInfoPanel::~AdvancedInfoPanel()
204 {
205 }
206
207 void AdvancedInfoPanel::Update( input_item_t *p_item )
208 {
209     /* Rebuild the tree */
210     Clear();
211
212     for( int i = 0; i< p_item->i_categories ; i++)
213     {
214         wxTreeItemId cat = info_tree->AppendItem( info_root,
215                             wxU( p_item->pp_categories[i]->psz_name) );
216
217         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
218         {
219            info_tree->AppendItem( cat , (wxString)
220                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_name) +
221                wxT(": ") +
222                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_value) );
223         }
224
225         info_tree->Expand( cat );
226     }
227 }
228
229 void AdvancedInfoPanel::Clear()
230 {
231     info_tree->DeleteChildren( info_root );
232 }
233
234 void AdvancedInfoPanel::OnOk( )
235 {
236 }
237
238 void AdvancedInfoPanel::OnCancel( )
239 {
240 }
241
242 /*****************************************************************************
243  * Statistics info panel
244  *****************************************************************************/
245 BEGIN_EVENT_TABLE( InputStatsInfoPanel, wxPanel )
246 END_EVENT_TABLE()
247
248 InputStatsInfoPanel::InputStatsInfoPanel( intf_thread_t *_p_intf,
249                                           wxWindow* _p_parent ):
250     wxPanel( _p_parent, -1 )
251 {
252     /* Initializations */
253     p_intf = _p_intf;
254     p_parent = _p_parent;
255
256     SetAutoLayout( TRUE );
257
258     panel_sizer = new wxBoxSizer( wxVERTICAL );
259
260     sizer = new wxFlexGridSizer( 2,2,20 );
261
262     /* Input */
263     wxStaticBox *input_box = new wxStaticBox( this, -1,
264                                               wxU( _("Input") ) );
265     input_box->SetAutoLayout( TRUE );
266     input_bsizer = new wxStaticBoxSizer( input_box, wxVERTICAL );
267     input_sizer = new wxFlexGridSizer( 2,2, 20 );
268
269 #define INPUT_ADD(txt,widget,dflt) \
270     { input_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),  \
271                          0, wxEXPAND| wxRIGHT, 5 );                     \
272       widget = new wxStaticText( this, -1, wxU( dflt ) );               \
273       input_sizer->Add( widget, 0, wxEXPAND| wxLEFT, 5  );              \
274     }
275
276     INPUT_ADD( "Read at media", read_bytes_text, "0" );
277     INPUT_ADD( "Input bitrate", input_bitrate_text, "0" );
278
279     INPUT_ADD( "Demuxed", demux_bytes_text ,"0");
280     /* Hack to get enough size */
281     INPUT_ADD( "Stream bitrate", demux_bitrate_text, "0              " );
282
283     input_sizer->Layout();
284     input_bsizer->Add( input_sizer, 0, wxALL | wxGROW, 5 );
285     input_bsizer->Layout();
286     sizer->Add( input_bsizer, 0, wxALL|wxGROW, 5 );
287
288    /* Vout */
289     wxStaticBox *video_box = new wxStaticBox( this, -1,
290                                               wxU( _("Video" ) ) );
291     video_box->SetAutoLayout( TRUE );
292     video_bsizer = new wxStaticBoxSizer( video_box,
293                                                           wxVERTICAL );
294     video_sizer = new wxFlexGridSizer( 2,3, 20 );
295
296 #define VIDEO_ADD(txt,widget,dflt) \
297     { video_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),   \
298                          0, wxEXPAND|wxLEFT , 5  );                      \
299       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
300       video_sizer->Add( widget, 0, wxEXPAND|wxRIGHT, 5 );                \
301     }
302     VIDEO_ADD( "Decoded blocks", video_decoded_text, "0" );
303     /* Hack to get enough size */
304     VIDEO_ADD( "Displayed frames", displayed_text, "0                  " );
305     VIDEO_ADD( "Lost frames", lost_frames_text, "0" );
306
307
308     video_sizer->Layout();
309     video_bsizer->Add( video_sizer, 0, wxALL | wxGROW, 5 );
310     video_bsizer->Layout();
311     sizer->Add( video_bsizer , 0, wxALL| wxGROW, 5 );
312
313     /* Sout */
314     wxStaticBox *sout_box = new wxStaticBox( this, -1,
315                                               wxU( _("Streaming" ) ) );
316     sout_box->SetAutoLayout( TRUE );
317     sout_bsizer = new wxStaticBoxSizer( sout_box, wxVERTICAL );
318     sout_sizer = new wxFlexGridSizer( 2,3, 20 );
319
320 #define SOUT_ADD(txt,widget,dflt) \
321     { sout_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),    \
322                          0, wxEXPAND|wxLEFT|wxALIGN_LEFT , 5  );         \
323       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
324       sout_sizer->Add( widget, 0, wxEXPAND|wxRIGHT|wxALIGN_RIGHT, 5 );   \
325     }
326     SOUT_ADD( "Sent packets", sout_sent_packets_text, "0" );
327     SOUT_ADD( "Sent bytes", sout_sent_bytes_text, "0          " );
328     SOUT_ADD( "Send rate", sout_send_bitrate_text, "0        " );
329     sout_sizer->Layout();
330     sout_bsizer->Add( sout_sizer, 0, wxALL | wxGROW, 5 );
331     sout_bsizer->Layout();
332     sizer->Add( sout_bsizer , 0, wxALL| wxGROW, 5 );
333
334    /* Aout */
335     wxStaticBox *audio_box = new wxStaticBox( this, -1,
336                                               wxU( _("Audio" ) ) );
337     audio_box->SetAutoLayout( TRUE );
338     audio_bsizer = new wxStaticBoxSizer( audio_box, wxVERTICAL );
339     audio_sizer = new wxFlexGridSizer( 2,3, 20 );
340
341 #define AUDIO_ADD(txt,widget,dflt) \
342     { audio_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),   \
343                          0, wxEXPAND|wxLEFT , 5  );                      \
344       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
345       audio_sizer->Add( widget, 0, wxEXPAND|wxRIGHT, 5 );                \
346     }
347     AUDIO_ADD( "Decoded blocks", audio_decoded_text, "0" );
348     /* Hack to get enough size */
349     AUDIO_ADD( "Played buffers", played_abuffers_text,
350                                  "0                  " );
351     AUDIO_ADD( "Lost buffers", lost_abuffers_text, "0" );
352     audio_sizer->Layout();
353     audio_bsizer->Add( audio_sizer, 0, wxALL | wxGROW, 5 );
354     audio_bsizer->Layout();
355     sizer->Add( audio_bsizer , 0, wxALL| wxGROW, 5 );
356
357     sizer->Layout();
358     panel_sizer->Add( sizer, 0, wxEXPAND, 5 );
359     panel_sizer->Layout();
360     SetSizerAndFit( panel_sizer );
361 }
362
363 InputStatsInfoPanel::~InputStatsInfoPanel()
364 {
365 }
366
367 void InputStatsInfoPanel::Update( input_item_t *p_item )
368 {
369     vlc_mutex_lock( &p_item->p_stats->lock );
370
371     /* Input */
372 #define UPDATE( widget,format, calc... )   \
373 {                                       \
374     wxString formatted;                 \
375     formatted.Printf(  wxString( wxT(format) ), ## calc ); \
376     widget->SetLabel( formatted );                      \
377 }
378     UPDATE( read_bytes_text, "%8.0f kB",(float)(p_item->p_stats->i_read_bytes)/1000 );
379     UPDATE( input_bitrate_text, "%6.0f kB/s", (float)(p_item->p_stats->f_input_bitrate)*1000 );
380     UPDATE( demux_bytes_text, "%8.0f kB", (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
381     UPDATE( demux_bitrate_text, "%6.0f kB/s",  (float)(p_item->p_stats->f_demux_bitrate)*1000 );
382
383     /* Video */
384     UPDATE( video_decoded_text, "%5i", p_item->p_stats->i_decoded_video );
385     UPDATE( displayed_text, "%5i", p_item->p_stats->i_displayed_pictures );
386     UPDATE( lost_frames_text, "%5i", p_item->p_stats->i_lost_pictures );
387
388     /* Sout */
389     UPDATE( sout_sent_packets_text, "%5i", p_item->p_stats->i_sent_packets );
390     UPDATE( sout_sent_bytes_text, "%8.0f kB",
391             (float)(p_item->p_stats->i_sent_bytes)/1000 );
392     UPDATE( sout_send_bitrate_text, "%6.0f kB/S",
393             (float)(p_item->p_stats->f_send_bitrate)*1000 );
394
395     /* Audio*/
396     UPDATE( audio_decoded_text, "%5i", p_item->p_stats->i_decoded_audio );
397     UPDATE( played_abuffers_text, "%5i", p_item->p_stats->i_played_abuffers );
398     UPDATE( lost_abuffers_text, "%5i", p_item->p_stats->i_lost_abuffers );
399
400     vlc_mutex_unlock( &p_item->p_stats->lock );
401
402     input_sizer->Layout();
403     video_sizer->Layout();
404
405     sizer->Layout();
406     panel_sizer->Layout();
407     SetSizerAndFit( panel_sizer );
408 }
409
410 void InputStatsInfoPanel::Clear()
411 {}
412
413 void InputStatsInfoPanel::OnOk( )
414 {}
415
416 void InputStatsInfoPanel::OnCancel( )
417 {}
418