]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/infopanels.cpp
Uniformize source files encoding
[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 #ifndef wxRB_SINGLE
29 #   define wxRB_SINGLE 0
30 #endif
31
32 /*****************************************************************************
33  * General info panel
34  *****************************************************************************/
35 BEGIN_EVENT_TABLE( ItemInfoPanel, wxPanel )
36 END_EVENT_TABLE()
37
38 ItemInfoPanel::ItemInfoPanel( intf_thread_t *_p_intf,
39                               wxWindow* _p_parent,
40                               bool _b_modifiable ):
41     wxPanel( _p_parent, -1 )
42 {
43     int flags= wxTE_PROCESS_ENTER;
44     /* Initializations */
45     p_intf = _p_intf;
46     p_parent = _p_parent;
47     b_modifiable = _b_modifiable;
48
49     SetAutoLayout( TRUE );
50
51     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
52
53     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,8,20);
54     sizer->AddGrowableCol(1);
55
56     if( !b_modifiable )
57         flags |= wxTE_READONLY;
58
59     /* URI Textbox */
60     wxStaticText *uri_static =
61            new wxStaticText( this, -1, wxU(_("URI")) );
62     sizer->Add( uri_static, 0 , wxALL , 0 );
63
64     uri_text = new wxTextCtrl( this, -1,
65             wxU(""), wxDefaultPosition, wxSize( 300, -1 ), flags );
66     sizer->Add( uri_text, 1 ,  wxALL|wxEXPAND , 0 );
67
68     /* Name Textbox */
69     wxStaticText *name_static =
70            new wxStaticText(  this, -1, wxU(_("Name")) );
71     sizer->Add( name_static, 0 , wxALL , 0  );
72
73     name_text = new wxTextCtrl( this, -1,
74             wxU(""), wxDefaultPosition, wxSize( 300, -1 ), flags );
75     sizer->Add( name_text, 1 , wxALL|wxEXPAND , 0 );
76
77     /* Treeview */
78     info_tree = new wxTreeCtrl( this, -1, wxDefaultPosition,
79                                 wxSize(220,200),
80                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
81                                 wxTR_HIDE_ROOT );
82     info_root = info_tree->AddRoot( wxU( "" ) );
83
84     sizer->Layout();
85     panel_sizer->Add( sizer, 0, wxEXPAND | wxALL, 15 );
86     panel_sizer->Add( info_tree, 1, wxEXPAND | wxALL, 5 );
87     panel_sizer->Layout();
88     SetSizerAndFit( panel_sizer );
89 }
90
91 ItemInfoPanel::~ItemInfoPanel()
92 {
93 }
94
95 void ItemInfoPanel::Update( input_item_t *p_item )
96 {
97     /* Rebuild the tree */
98     Clear();
99
100     uri_text->SetValue( wxU( p_item->psz_uri ) );
101     name_text->SetValue( wxU( p_item->psz_name ) );
102
103     for( int i = 0; i< p_item->i_categories ; i++)
104     {
105         wxTreeItemId cat = info_tree->AppendItem( info_root,
106                             wxU( p_item->pp_categories[i]->psz_name) );
107
108         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
109         {
110            info_tree->AppendItem( cat , (wxString)
111                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_name) +
112                wxT(": ") +
113                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_value) );
114         }
115
116         info_tree->Expand( cat );
117     }
118 }
119
120 char* ItemInfoPanel::GetURI( )
121 {
122     return  strdup( uri_text->GetLineText(0).mb_str() );
123 }
124
125 char* ItemInfoPanel::GetName( )
126 {
127     return  strdup( name_text->GetLineText(0).mb_str() );
128 }
129
130 void ItemInfoPanel::Clear()
131 {
132     info_tree->DeleteChildren( info_root );
133 }
134
135 void ItemInfoPanel::OnOk( )
136 {
137 }
138
139 void ItemInfoPanel::OnCancel( )
140 {
141 }
142
143 /*****************************************************************************
144  * Statistics info panel
145  *****************************************************************************/
146 BEGIN_EVENT_TABLE( InputStatsInfoPanel, wxPanel )
147 END_EVENT_TABLE()
148
149 InputStatsInfoPanel::InputStatsInfoPanel( intf_thread_t *_p_intf,
150                                           wxWindow* _p_parent ):
151     wxPanel( _p_parent, -1 )
152 {
153     /* Initializations */
154     p_intf = _p_intf;
155     p_parent = _p_parent;
156
157     SetAutoLayout( TRUE );
158
159     panel_sizer = new wxBoxSizer( wxVERTICAL );
160
161     sizer = new wxFlexGridSizer( 2,2,20 );
162
163     /* Input */
164     wxStaticBox *input_box = new wxStaticBox( this, -1,
165                                               wxU( _("Input") ) );
166     input_box->SetAutoLayout( TRUE );
167     input_bsizer = new wxStaticBoxSizer( input_box, wxVERTICAL );
168     input_sizer = new wxFlexGridSizer( 2,2, 20 );
169
170 #define INPUT_ADD(txt,widget,dflt) \
171     { input_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),  \
172                          0, wxEXPAND| wxRIGHT, 5 );                     \
173       widget = new wxStaticText( this, -1, wxU( dflt ) );               \
174       input_sizer->Add( widget, 0, wxEXPAND| wxLEFT, 5  );              \
175     }
176
177     INPUT_ADD( "Read at media", read_bytes_text, "0" );
178     INPUT_ADD( "Input bitrate", input_bitrate_text, "0" );
179
180     INPUT_ADD( "Demuxed", demux_bytes_text ,"0");
181     /* Hack to get enough size */
182     INPUT_ADD( "Stream bitrate", demux_bitrate_text, "0              " );
183
184     input_sizer->Layout();
185     input_bsizer->Add( input_sizer, 0, wxALL | wxGROW, 5 );
186     input_bsizer->Layout();
187     sizer->Add( input_bsizer, 0, wxALL|wxGROW, 5 );
188
189    /* Vout */
190     wxStaticBox *video_box = new wxStaticBox( this, -1,
191                                               wxU( _("Video" ) ) );
192     video_box->SetAutoLayout( TRUE );
193     video_bsizer = new wxStaticBoxSizer( video_box,
194                                                           wxVERTICAL );
195     video_sizer = new wxFlexGridSizer( 2,3, 20 );
196
197 #define VIDEO_ADD(txt,widget,dflt) \
198     { video_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),   \
199                          0, wxEXPAND|wxLEFT , 5  );                      \
200       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
201       video_sizer->Add( widget, 0, wxEXPAND|wxRIGHT, 5 );                \
202     }
203     VIDEO_ADD( "Decoded blocks", video_decoded_text, "0" );
204     /* Hack to get enough size */
205     VIDEO_ADD( "Displayed frames", displayed_text, "0                  " );
206     VIDEO_ADD( "Lost frames", lost_frames_text, "0" );
207
208
209     video_sizer->Layout();
210     video_bsizer->Add( video_sizer, 0, wxALL | wxGROW, 5 );
211     video_bsizer->Layout();
212     sizer->Add( video_bsizer , 0, wxALL| wxGROW, 5 );
213
214     /* Sout */
215     wxStaticBox *sout_box = new wxStaticBox( this, -1,
216                                               wxU( _("Streaming" ) ) );
217     sout_box->SetAutoLayout( TRUE );
218     sout_bsizer = new wxStaticBoxSizer( sout_box, wxVERTICAL );
219     sout_sizer = new wxFlexGridSizer( 2,3, 20 );
220
221 #define SOUT_ADD(txt,widget,dflt) \
222     { sout_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),    \
223                          0, wxEXPAND|wxLEFT|wxALIGN_LEFT , 5  );         \
224       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
225       sout_sizer->Add( widget, 0, wxEXPAND|wxRIGHT|wxALIGN_RIGHT, 5 );   \
226     }
227     SOUT_ADD( "Sent packets", sout_sent_packets_text, "0" );
228     SOUT_ADD( "Sent bytes", sout_sent_bytes_text, "0          " );
229     SOUT_ADD( "Send rate", sout_send_bitrate_text, "0        " );
230     sout_sizer->Layout();
231     sout_bsizer->Add( sout_sizer, 0, wxALL | wxGROW, 5 );
232     sout_bsizer->Layout();
233     sizer->Add( sout_bsizer , 0, wxALL| wxGROW, 5 );
234
235    /* Aout */
236     wxStaticBox *audio_box = new wxStaticBox( this, -1,
237                                               wxU( _("Audio" ) ) );
238     audio_box->SetAutoLayout( TRUE );
239     audio_bsizer = new wxStaticBoxSizer( audio_box, wxVERTICAL );
240     audio_sizer = new wxFlexGridSizer( 2,3, 20 );
241
242 #define AUDIO_ADD(txt,widget,dflt) \
243     { audio_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ),   \
244                          0, wxEXPAND|wxLEFT , 5  );                      \
245       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
246       audio_sizer->Add( widget, 0, wxEXPAND|wxRIGHT, 5 );                \
247     }
248     AUDIO_ADD( "Decoded blocks", audio_decoded_text, "0" );
249     /* Hack to get enough size */
250     AUDIO_ADD( "Played buffers", played_abuffers_text,
251                                  "0                  " );
252     AUDIO_ADD( "Lost buffers", lost_abuffers_text, "0" );
253     audio_sizer->Layout();
254     audio_bsizer->Add( audio_sizer, 0, wxALL | wxGROW, 5 );
255     audio_bsizer->Layout();
256     sizer->Add( audio_bsizer , 0, wxALL| wxGROW, 5 );
257
258     sizer->Layout();
259     panel_sizer->Add( sizer, 0, wxEXPAND, 5 );
260     panel_sizer->Layout();
261     SetSizerAndFit( panel_sizer );
262 }
263
264 InputStatsInfoPanel::~InputStatsInfoPanel()
265 {
266 }
267
268 void InputStatsInfoPanel::Update( input_item_t *p_item )
269 {
270     vlc_mutex_lock( &p_item->p_stats->lock );
271
272     /* Input */
273 #define UPDATE( widget,format, calc... )   \
274 {                                       \
275     wxString formatted;                 \
276     formatted.Printf(  wxString( wxT(format) ), ## calc ); \
277     widget->SetLabel( formatted );                      \
278 }
279     UPDATE( read_bytes_text, "%8.0f kB",(float)(p_item->p_stats->i_read_bytes)/1000 );
280     UPDATE( input_bitrate_text, "%6.0f kB/s", (float)(p_item->p_stats->f_input_bitrate)*1000 );
281     UPDATE( demux_bytes_text, "%8.0f kB", (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
282     UPDATE( demux_bitrate_text, "%6.0f kB/s",  (float)(p_item->p_stats->f_demux_bitrate)*1000 );
283
284     /* Video */
285     UPDATE( video_decoded_text, "%5i", p_item->p_stats->i_decoded_video );
286     UPDATE( displayed_text, "%5i", p_item->p_stats->i_displayed_pictures );
287     UPDATE( lost_frames_text, "%5i", p_item->p_stats->i_lost_pictures );
288
289     /* Sout */
290     UPDATE( sout_sent_packets_text, "%5i", p_item->p_stats->i_sent_packets );
291     UPDATE( sout_sent_bytes_text, "%8.0f kB",
292             (float)(p_item->p_stats->i_sent_bytes)/1000 );
293     UPDATE( sout_send_bitrate_text, "%6.0f kB/S",
294             (float)(p_item->p_stats->f_send_bitrate)*1000 );
295
296     /* Audio*/
297     UPDATE( audio_decoded_text, "%5i", p_item->p_stats->i_decoded_audio );
298     UPDATE( played_abuffers_text, "%5i", p_item->p_stats->i_played_abuffers );
299     UPDATE( lost_abuffers_text, "%5i", p_item->p_stats->i_lost_abuffers );
300
301     vlc_mutex_unlock( &p_item->p_stats->lock );
302
303     input_sizer->Layout();
304     video_sizer->Layout();
305
306     sizer->Layout();
307     panel_sizer->Layout();
308     SetSizerAndFit( panel_sizer );
309 }
310
311 void InputStatsInfoPanel::Clear()
312 {}
313
314 void InputStatsInfoPanel::OnOk( )
315 {}
316
317 void InputStatsInfoPanel::OnCancel( )
318 {}
319