]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/infopanels.cpp
Show stats in interface (Refs:#473)
[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     /* Initializations */
44     p_intf = _p_intf;
45     p_parent = _p_parent;
46     b_modifiable = _b_modifiable;
47
48     SetAutoLayout( TRUE );
49
50     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
51
52     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,3,20);
53     /* URI Textbox */
54     wxStaticText *uri_static =
55            new wxStaticText( this, -1, wxU(_("URI")) );
56     sizer->Add( uri_static, 0 , wxALL , 5 );
57
58     uri_text = new wxTextCtrl( this, -1,
59             wxU(""), wxDefaultPosition, wxSize( 300, -1 ),
60             wxTE_PROCESS_ENTER );
61     sizer->Add( uri_text, 1 ,  wxALL , 5 );
62
63     /* Name Textbox */
64     wxStaticText *name_static =
65            new wxStaticText(  this, -1, wxU(_("Name")) );
66     sizer->Add( name_static, 0 , wxALL , 5  );
67
68     name_text = new wxTextCtrl( this, -1,
69             wxU(""), wxDefaultPosition, wxSize( 300, -1 ),
70             wxTE_PROCESS_ENTER );
71     sizer->Add( name_text, 1 , wxALL , 5 );
72
73     /* Treeview */
74     info_tree = new wxTreeCtrl( this, -1, wxDefaultPosition,
75                                 wxSize(220,200),
76                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
77                                 wxTR_HIDE_ROOT );
78     info_root = info_tree->AddRoot( wxU( "" ) );
79
80     sizer->Layout();
81     panel_sizer->Add( sizer, 0, wxEXPAND, 5 );
82     panel_sizer->Add( info_tree, 0, wxEXPAND, 5 );
83     panel_sizer->Layout();
84     SetSizerAndFit( panel_sizer );
85 }
86
87 ItemInfoPanel::~ItemInfoPanel()
88 {
89 }
90
91 void ItemInfoPanel::Update( input_item_t *p_item )
92 {
93     /* Rebuild the tree */
94     Clear();
95
96     uri_text->SetValue( wxU( p_item->psz_uri ) );
97     name_text->SetValue( wxU( p_item->psz_name ) );
98
99     for( int i = 0; i< p_item->i_categories ; i++)
100     {
101         wxTreeItemId cat = info_tree->AppendItem( info_root,
102                             wxU( p_item->pp_categories[i]->psz_name) );
103
104         for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
105         {
106            info_tree->AppendItem( cat , (wxString)
107                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_name) +
108                wxT(": ") +
109                wxU(p_item->pp_categories[i]->pp_infos[j]->psz_value) );
110         }
111
112         info_tree->Expand( cat );
113     }
114 }
115
116 void ItemInfoPanel::Clear()
117 {
118     info_tree->DeleteChildren( info_root );
119 }
120
121 void ItemInfoPanel::OnOk( )
122 {
123 }
124
125 void ItemInfoPanel::OnCancel( )
126 {
127 }
128
129 /*****************************************************************************
130  * Statistics info panel
131  *****************************************************************************/
132 BEGIN_EVENT_TABLE( InputStatsInfoPanel, wxPanel )
133 END_EVENT_TABLE()
134
135 InputStatsInfoPanel::InputStatsInfoPanel( intf_thread_t *_p_intf,
136                                           wxWindow* _p_parent ):
137     wxPanel( _p_parent, -1 )
138 {
139     /* Initializations */
140     p_intf = _p_intf;
141     p_parent = _p_parent;
142
143     SetAutoLayout( TRUE );
144
145     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
146
147     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2,2,20 );
148
149     /* Input */
150     wxStaticBox *input_box = new wxStaticBox( this, -1,
151                                               wxU( _("Input") ) );
152     wxStaticBoxSizer *input_bsizer = new wxStaticBoxSizer( input_box,
153                                                           wxVERTICAL );
154     wxFlexGridSizer *input_sizer = new wxFlexGridSizer( 2,2, 20 );
155
156 #define INPUT_ADD(txt,widget,dflt) \
157     { input_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ) ); \
158       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
159       input_sizer->Add( widget );                                        \
160     }
161
162     INPUT_ADD( "Read at media", read_bytes_text, "0" );
163     INPUT_ADD( "Input bitrate", input_bitrate_text, "0" );
164
165     INPUT_ADD( "Demuxed", demux_bytes_text ,"0");
166     INPUT_ADD( "Stream bitrate", demux_bitrate_text, "0" );
167
168     input_sizer->Layout();
169     input_bsizer->Add( input_sizer, 0, wxALL | wxGROW, 5 );
170     input_bsizer->Layout();
171     sizer->Add( input_bsizer, 0, wxALL|wxGROW, 5 );
172
173    /* Vout */
174     wxStaticBox *video_box = new wxStaticBox( this, -1,
175                                               wxU( _("Video" ) ) );
176     wxStaticBoxSizer *video_bsizer = new wxStaticBoxSizer( video_box,
177                                                            wxVERTICAL );
178     wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 2,3, 20 );
179
180 #define VIDEO_ADD(txt,widget,dflt) \
181     { video_sizer->Add ( new wxStaticText( this, -1, wxU(_( txt ) ) ) ); \
182       widget = new wxStaticText( this, -1, wxU( dflt ) );                \
183       video_sizer->Add( widget );                                        \
184     }
185     VIDEO_ADD( "Decoded blocks", video_decoded_text, "0" );
186     VIDEO_ADD( "Displayed frames", displayed_text, "0" );
187     VIDEO_ADD( "Lost frames", lost_frames_text, "0" );
188
189
190     video_sizer->Layout();
191     video_bsizer->Add( video_sizer, 0, wxALL | wxGROW, 5 );
192     video_bsizer->Layout();
193     sizer->Add( video_bsizer , 0, wxALL| wxGROW, 5 );
194
195     panel_sizer->Add( sizer, 0, wxEXPAND, 5 );
196     panel_sizer->Layout();
197     SetSizerAndFit( panel_sizer );
198
199 }
200
201 InputStatsInfoPanel::~InputStatsInfoPanel()
202 {
203 }
204
205 void InputStatsInfoPanel::Update( input_item_t *p_item )
206 {
207     vlc_mutex_lock( &p_item->p_stats->lock );
208
209     /* Input */
210 #define UPDATE( widget,format, calc... )   \
211 {                                       \
212     wxString formatted;                 \
213     formatted.Printf(  wxString( wxT(format) ), ## calc ); \
214     widget->SetLabel( formatted );                      \
215 }
216     UPDATE( read_bytes_text, "%.0f kB",(float)(p_item->p_stats->i_read_bytes)/1000 );
217     UPDATE( input_bitrate_text, "%.0f kB/s", (float)(p_item->p_stats->f_input_bitrate)*1000 );
218     UPDATE( demux_bytes_text, "%.0f kB", (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
219     UPDATE( demux_bitrate_text, "%.0f kB/s",  (float)(p_item->p_stats->f_demux_bitrate)*1000 );
220
221     /* Video */
222     UPDATE( video_decoded_text, "%i", p_item->p_stats->i_decoded_video );
223     UPDATE( displayed_text, "%i", p_item->p_stats->i_displayed_pictures );
224     UPDATE( lost_frames_text, "%i", p_item->p_stats->i_lost_pictures );
225
226     vlc_mutex_unlock( &p_item->p_stats->lock );
227 }
228
229 void InputStatsInfoPanel::Clear()
230 {}
231
232 void InputStatsInfoPanel::OnOk( )
233 {}
234
235 void InputStatsInfoPanel::OnCancel( )
236 {}
237