]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/infopanels.cpp
playlist: Make sure we don't pl_Release(p_playlist).
[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$
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_ALBUM, collection_text );
94     ADD_META( VLC_META_TRACK_NUMBER, 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     ADD_META( VLC_META_SETTING, setting_text );
102
103     meta_sizer->Layout();
104
105     panel_sizer->Add( sizer, 0, wxEXPAND | wxALL, 5 );
106     panel_sizer->Add( meta_sizer, 0, wxEXPAND | wxALL, 5 );
107     panel_sizer->Layout();
108     SetSizerAndFit( panel_sizer );
109 }
110
111 MetaDataPanel::~MetaDataPanel()
112 {
113 }
114
115 void MetaDataPanel::Update( input_item_t *p_item )
116 {
117     /* Rebuild the tree */
118     Clear();
119
120     char *psz_meta;
121
122 #define UPDATE_META( meta, widget ) {                                       \
123     psz_meta = input_item_Get##meta( p_item );                        \
124     if( psz_meta != NULL && *psz_meta)                                      \
125     {                                                                       \
126         widget->SetLabel( wxU( psz_meta ) );                                \
127     }                                                                       \
128     else { widget->SetLabel( wxU( "-" ) ); }                                \
129     }                                                                       \
130     free( psz_meta );
131
132     UPDATE_META( URI, uri_text );
133     UPDATE_META( Name, name_text );
134     UPDATE_META( Artist, artist_text );
135     UPDATE_META( Genre, genre_text );
136     UPDATE_META( Copyright, copyright_text );
137     UPDATE_META( Album, collection_text );
138     UPDATE_META( TrackNum, seqnum_text );
139     UPDATE_META( Description, description_text );
140     UPDATE_META( Rating, rating_text );
141     UPDATE_META( Date, date_text );
142     UPDATE_META( Language, language_text );
143     UPDATE_META( NowPlaying, nowplaying_text );
144     UPDATE_META( Publisher, publisher_text );
145     UPDATE_META( Setting, setting_text );
146
147 #undef UPDATE_META
148 }
149
150 char* MetaDataPanel::GetURI( )
151 {
152     return  strdup( uri_text->GetLineText(0).mb_str(wxConvUTF8) );
153 }
154
155 char* MetaDataPanel::GetName( )
156 {
157     return  strdup( name_text->GetLineText(0).mb_str(wxConvUTF8) );
158 }
159
160 void MetaDataPanel::Clear()
161 {
162 }
163
164 void MetaDataPanel::OnOk( )
165 {
166 }
167
168 void MetaDataPanel::OnCancel( )
169 {
170 }
171
172
173 /*****************************************************************************
174  * General info panel
175  *****************************************************************************/
176 BEGIN_EVENT_TABLE( AdvancedInfoPanel, wxPanel )
177 END_EVENT_TABLE()
178
179 AdvancedInfoPanel::AdvancedInfoPanel( intf_thread_t *_p_intf,
180                                       wxWindow* _p_parent ):
181     wxPanel( _p_parent, -1 )
182 {
183     /* Initializations */
184     p_intf = _p_intf;
185     p_parent = _p_parent;
186
187     SetAutoLayout( TRUE );
188
189     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
190
191     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,8,20);
192     sizer->AddGrowableCol(1);
193
194     /* Treeview */
195     info_tree = new wxTreeCtrl( this, -1, wxDefaultPosition,
196                                 wxSize(220,200),
197                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
198                                 wxTR_HIDE_ROOT );
199     info_root = info_tree->AddRoot( wxU( "" ) );
200
201     panel_sizer->Add( info_tree, 1, wxEXPAND | wxALL, 5 );
202     panel_sizer->Layout();
203     SetSizerAndFit( panel_sizer );
204 }
205
206 AdvancedInfoPanel::~AdvancedInfoPanel()
207 {
208 }
209
210 void AdvancedInfoPanel::Update( input_item_t *p_item )
211 {
212     /* Rebuild the tree */
213     Clear();
214
215     for( int i = 0; i< p_item->i_categories ; i++)
216     {
217         wxTreeItemId cat = info_tree->AppendItem( info_root,
218                             wxU( p_item->pp_categories[i]->psz_name) );
219
220         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
221         {
222            info_tree->AppendItem( cat , (wxString)
223                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_name) +
224                wxT(": ") +
225                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_value) );
226         }
227
228         info_tree->Expand( cat );
229     }
230 }
231
232 void AdvancedInfoPanel::Clear()
233 {
234     info_tree->DeleteChildren( info_root );
235 }
236
237 void AdvancedInfoPanel::OnOk( )
238 {
239 }
240
241 void AdvancedInfoPanel::OnCancel( )
242 {
243 }
244
245 /*****************************************************************************
246  * Statistics info panel
247  *****************************************************************************/
248 BEGIN_EVENT_TABLE( InputStatsInfoPanel, wxPanel )
249 END_EVENT_TABLE()
250
251 InputStatsInfoPanel::InputStatsInfoPanel( intf_thread_t *_p_intf,
252                                           wxWindow* _p_parent ):
253     wxPanel( _p_parent, -1 )
254 {
255     /* Initializations */
256     p_intf = _p_intf;
257     p_parent = _p_parent;
258
259     SetAutoLayout( TRUE );
260
261     panel_sizer = new wxBoxSizer( wxVERTICAL );
262
263     sizer = new wxFlexGridSizer( 2,2,20 );
264
265     /* Input */
266     wxStaticBox *input_box = new wxStaticBox( this, -1,
267                                               wxU( _("Input") ) );
268     input_box->SetAutoLayout( TRUE );
269     input_bsizer = new wxStaticBoxSizer( input_box, wxVERTICAL );
270     input_sizer = new wxFlexGridSizer( 4, 3, 2, 20 );
271
272 #define INPUT_ADD(txt,widget,dflt) \
273     { input_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),   \
274                          0, wxALIGN_LEFT|wxLEFT, 5 );           \
275       input_sizer->Add( 0, 0, wxEXPAND );                                \
276       widget = new wxStaticText( this, -1, wxU( dflt ), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );                \
277       input_sizer->Add( widget, 0, wxALIGN_RIGHT|wxRIGHT, 5  ); \
278     }
279
280     INPUT_ADD( "Read at media", read_bytes_text, "0" );
281     INPUT_ADD( "Input bitrate", input_bitrate_text, "           0" );
282
283     INPUT_ADD( "Demuxed", demux_bytes_text ,"0");
284     INPUT_ADD( "Stream bitrate", demux_bitrate_text, "0" );
285
286     input_sizer->Layout();
287     input_bsizer->Add( input_sizer, 0, wxALL | wxGROW, 5 );
288     input_bsizer->Layout();
289     sizer->Add( input_bsizer, 0, wxALL|wxGROW, 5 );
290
291    /* Vout */
292     wxStaticBox *video_box = new wxStaticBox( this, -1, wxU( _("Video" ) ) );
293     video_box->SetAutoLayout( TRUE );
294     video_bsizer = new wxStaticBoxSizer( video_box, wxVERTICAL );
295     video_sizer = new wxFlexGridSizer( 3, 3, 2, 20 );
296
297 #define VIDEO_ADD(txt,widget,dflt) \
298     { video_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),  \
299                          0, wxALIGN_LEFT|wxLEFT , 5  );        \
300       video_sizer->Add( 0, 0, wxEXPAND );                                \
301       widget = new wxStaticText( this, -1, wxU( dflt ), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );               \
302       video_sizer->Add( widget, 0, wxALIGN_RIGHT|wxRIGHT, 5 ); \
303     }
304     VIDEO_ADD( "Decoded blocks", video_decoded_text, "0" );
305     VIDEO_ADD( "Displayed frames", displayed_text, "           0" );
306     VIDEO_ADD( "Lost frames", lost_frames_text, "0" );
307
308
309     video_sizer->Layout();
310     video_bsizer->Add( video_sizer, 0, wxALL | wxGROW, 5 );
311     video_bsizer->Layout();
312     sizer->Add( video_bsizer , 0, wxALL| wxGROW, 5 );
313
314     /* Sout */
315     wxStaticBox *sout_box = new wxStaticBox( this, -1,
316                                               wxU( _("Streaming" ) ) );
317     sout_box->SetAutoLayout( TRUE );
318     sout_bsizer = new wxStaticBoxSizer( sout_box, wxVERTICAL );
319     sout_sizer = new wxFlexGridSizer( 3, 3, 2, 20 );
320
321 #define SOUT_ADD(txt,widget,dflt) \
322     { sout_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),  \
323                          0, wxALIGN_LEFT|wxLEFT, 5  );        \
324       sout_sizer->Add( 0, 0, wxEXPAND );                                \
325       widget = new wxStaticText( this, -1, wxU( dflt ), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );              \
326       sout_sizer->Add( widget, 0,wxALIGN_RIGHT|wxRIGHT, 5 ); \
327     }
328     SOUT_ADD( "Sent packets", sout_sent_packets_text, "          0" );
329     SOUT_ADD( "Sent bytes", sout_sent_bytes_text, "0" );
330     SOUT_ADD( "Send rate", sout_send_bitrate_text, "0" );
331     sout_sizer->Layout();
332     sout_bsizer->Add( sout_sizer, 0, wxALL | wxGROW, 5 );
333     sout_bsizer->Layout();
334     sizer->Add( sout_bsizer , 0, wxALL| wxGROW, 5 );
335
336    /* Aout */
337     wxStaticBox *audio_box = new wxStaticBox( this, -1,
338                                               wxU( _("Audio" ) ) );
339     audio_box->SetAutoLayout( TRUE );
340     audio_bsizer = new wxStaticBoxSizer( audio_box, wxVERTICAL );
341     audio_sizer = new wxFlexGridSizer( 3, 3, 2, 20 );
342
343 #define AUDIO_ADD(txt,widget,dflt) \
344     { audio_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),   \
345                          0, wxALIGN_LEFT|wxLEFT, 5  );          \
346       audio_sizer->Add( 0, 0, wxEXPAND );                                \
347       widget = new wxStaticText( this, -1, wxU( dflt ), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );                \
348       audio_sizer->Add( widget, 0, wxALIGN_RIGHT|wxRIGHT, 5 );  \
349     }
350     AUDIO_ADD( "Decoded blocks", audio_decoded_text, "         0" );
351     AUDIO_ADD( "Played buffers", played_abuffers_text, "0" );
352     AUDIO_ADD( "Lost buffers", lost_abuffers_text, "0" );
353     audio_sizer->Layout();
354     audio_bsizer->Add( audio_sizer, 0, wxALL | wxGROW, 5 );
355     audio_bsizer->Layout();
356     sizer->Add( audio_bsizer , 0, wxALL| wxGROW, 5 );
357
358     sizer->Layout();
359     panel_sizer->Add( sizer, 0, wxEXPAND, 5 );
360     panel_sizer->Layout();
361     SetSizerAndFit( panel_sizer );
362 }
363
364 InputStatsInfoPanel::~InputStatsInfoPanel()
365 {
366 }
367
368 void InputStatsInfoPanel::Update( input_item_t *p_item )
369 {
370     vlc_mutex_lock( &p_item->p_stats->lock );
371
372     /* Input */
373 #define UPDATE( widget,format, calc... )   \
374 {                                       \
375     wxString formatted;                 \
376     formatted.Printf(  wxString( wxT(format) ), ## calc ); \
377     widget->SetLabel( formatted );                      \
378 }
379     UPDATE( read_bytes_text, "%8.0f kB",(float)(p_item->p_stats->i_read_bytes)/1000 );
380     UPDATE( input_bitrate_text, "%6.0f kb/s", (float)(p_item->p_stats->f_input_bitrate)*8000 );
381     UPDATE( demux_bytes_text, "%8.0f kB", (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
382     UPDATE( demux_bitrate_text, "%6.0f kb/s",  (float)(p_item->p_stats->f_demux_bitrate)*8000 );
383
384     /* Video */
385     UPDATE( video_decoded_text, "%5i", p_item->p_stats->i_decoded_video );
386     UPDATE( displayed_text, "%5i", p_item->p_stats->i_displayed_pictures );
387     UPDATE( lost_frames_text, "%5i", p_item->p_stats->i_lost_pictures );
388
389     /* Sout */
390     UPDATE( sout_sent_packets_text, "%5i", p_item->p_stats->i_sent_packets );
391     UPDATE( sout_sent_bytes_text, "%8.0f kB",
392             (float)(p_item->p_stats->i_sent_bytes)/1000 );
393     UPDATE( sout_send_bitrate_text, "%6.0f kb/s",
394             (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
395
396     /* Audio*/
397     UPDATE( audio_decoded_text, "%5i", p_item->p_stats->i_decoded_audio );
398     UPDATE( played_abuffers_text, "%5i", p_item->p_stats->i_played_abuffers );
399     UPDATE( lost_abuffers_text, "%5i", p_item->p_stats->i_lost_abuffers );
400
401     vlc_mutex_unlock( &p_item->p_stats->lock );
402
403     input_sizer->Layout();
404     video_sizer->Layout();
405     sout_sizer->Layout();
406     audio_sizer->Layout();
407
408     sizer->Layout();
409     panel_sizer->Layout();
410     SetSizerAndFit( panel_sizer );
411 }
412
413 void InputStatsInfoPanel::Clear()
414 {}
415
416 void InputStatsInfoPanel::OnOk( )
417 {}
418
419 void InputStatsInfoPanel::OnCancel( )
420 {}
421