1 /*****************************************************************************
2 * vlm_panel.cpp: VLM Panel
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
24 #include "dialogs/vlm/vlm_panel.hpp"
25 #include "dialogs/vlm/vlm_wrapper.hpp"
26 #include "dialogs/vlm/vlm_stream.hpp"
27 #include "dialogs/vlm/vlm_streampanel.hpp"
28 #include <wx/statline.h>
39 BEGIN_EVENT_TABLE( VLMPanel, wxPanel)
40 EVT_TIMER( Timer_Event, VLMPanel::OnTimer )
41 EVT_BUTTON( wxID_CLOSE, VLMPanel::OnClose )
42 EVT_BUTTON( Load_Event, VLMPanel::OnLoad )
43 EVT_BUTTON( wxID_SAVE, VLMPanel::OnSave )
47 VLMPanel::VLMPanel( intf_thread_t *_p_intf, wxWindow *_p_parent ) :
48 wxPanel( _p_parent, -1, wxDefaultPosition, wxDefaultSize ),
49 timer( this, Timer_Event )
54 p_vlm = new VLMWrapper( p_intf );
57 SetAutoLayout( TRUE );
59 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
61 p_notebook = new wxNotebook( this, Notebook_Event );
62 #if (!wxCHECK_VERSION(2,5,0))
63 wxNotebookSizer *notebook_sizer = new wxNotebookSizer( p_notebook );
65 p_notebook->AddPage( BroadcastPanel( p_notebook ), wxU( _("Broadcasts") ) );
67 p_notebook->AddPage( VODPanel( p_notebook ), wxU( _("VOD") ) );
69 #if (!wxCHECK_VERSION(2,5,0))
70 panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
72 panel_sizer->Add( p_notebook, 1 , wxEXPAND | wxALL, 5 );
75 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
76 button_sizer->Add( new wxButton( this, wxID_CLOSE, wxU(_("&Close") ) ) );
77 button_sizer->Add( 0, 0, 1 );
78 button_sizer->Add( new wxButton( this, Load_Event, wxU(_("Load") ) ), 0, wxRIGHT, 10 );
79 button_sizer->Add( new wxButton( this, wxID_SAVE, wxU(_("&Save") ) ) );
80 panel_sizer->Add( button_sizer, 0 , wxEXPAND | wxALL, 5 );
82 panel_sizer->Layout();
83 SetSizerAndFit( panel_sizer );
95 void VLMPanel::OnTimer( wxTimerEvent& event )
100 void VLMPanel::Update()
103 for( i = 0 ; i < broadcasts.size(); i++ )
105 ((VLMBroadcastStreamPanel *)broadcasts[i])->b_found = VLC_FALSE;
107 for( i = 0 ; i < vods.size(); i++ )
109 ((VLMVODStreamPanel *)vods[i])->b_found = VLC_FALSE;
113 /* Iterate over the media, to find the panels to add / remove */
114 /* FIXME: This code should be better wrapped */
115 for( i = 0; i < p_vlm->NbMedia(); i++ )
117 vlm_media_t *p_media = p_vlm->GetMedia( i );
119 if( p_media->i_type == BROADCAST_TYPE )
121 vlc_bool_t b_foundthis = VLC_FALSE;
122 for( unsigned int j = 0 ; j < broadcasts.size(); j++ )
124 VLMBroadcastStreamPanel *p_streamp =
125 (VLMBroadcastStreamPanel *)(broadcasts[j]);
126 /* FIXME: dangerous .. */
127 if( p_streamp->GetStream()->p_media == p_media )
129 p_streamp->b_found = VLC_TRUE;
130 b_foundthis = VLC_TRUE;
134 /* Create the stream */
137 VLMBroadcastStream *p_broadcast =
138 new VLMBroadcastStream( p_intf, p_media, p_vlm );
139 AppendBroadcast( p_broadcast );
142 else if( p_media->i_type == VOD_TYPE )
144 vlc_bool_t b_foundthis = VLC_FALSE;
145 for( unsigned int j = 0 ; i < vods.size(); i++ )
147 VLMVODStreamPanel *p_streamp = (VLMVODStreamPanel *)( vods[j] );
148 if( p_streamp->GetStream()->p_media == p_media )
150 p_streamp->b_found = VLC_TRUE;
151 b_foundthis = VLC_TRUE;
158 VLMVODStream *p_vod = new VLMVODStream(p_intf, p_media, p_vlm );
164 /* Those not marked as found must be removed */
165 vector<VLMBroadcastStreamPanel *>::iterator it = broadcasts.begin();
166 while( it < broadcasts.end() )
168 if( (*it)->b_found == VLC_FALSE )
170 vector<VLMBroadcastStreamPanel *>::iterator rem = it;
172 VLMBroadcastStreamPanel *p_remove = *rem;
173 broadcasts.erase( rem );
174 RemoveBroadcast( p_remove );
180 vector<VLMVODStreamPanel *>::iterator it2 = vods.begin();
181 while( it2 < vods.end() )
183 if( (*it2)->b_found == VLC_FALSE )
185 vector<VLMVODStreamPanel *>::iterator rem = it2;
187 VLMVODStreamPanel *p_remove = *rem;
189 RemoveVOD( p_remove );
197 for( unsigned int j = 0 ; j < broadcasts.size(); j++ )
199 VLMBroadcastStreamPanel *p_streamp =
200 (VLMBroadcastStreamPanel *)( broadcasts[j] );
206 void VLMPanel::OnClose( wxCommandEvent &event )
208 ((VLMFrame*)p_parent)->OnClose( *( new wxCloseEvent() ) );
211 void VLMPanel::OnLoad( wxCommandEvent &event )
213 p_file_dialog = new wxFileDialog( NULL, wxT(""), wxT(""), wxT(""),
214 wxT("*"), wxOPEN | wxMULTIPLE );
215 if( p_file_dialog == NULL ) return;
217 p_file_dialog->SetTitle( wxU(_("Load Configuration") ) );
218 if( p_file_dialog->ShowModal() == wxID_OK )
220 vlm_Load( p_vlm->GetVLM(), p_file_dialog->GetPath().mb_str(wxConvUTF8) );
225 void VLMPanel::OnSave( wxCommandEvent &event )
227 p_file_dialog = new wxFileDialog( NULL, wxT(""), wxT(""), wxT(""),
228 wxT("*"), wxSAVE | wxOVERWRITE_PROMPT );
229 if( p_file_dialog == NULL ) return;
231 p_file_dialog->SetTitle( wxU(_("Save Configuration") ) );
232 if( p_file_dialog->ShowModal() == wxID_OK )
234 vlm_Save( p_vlm->GetVLM(), p_file_dialog->GetPath().mb_str(wxConvUTF8) );
238 /*************************
239 * Broadcasts management
240 *************************/
241 wxPanel * VLMPanel::BroadcastPanel( wxWindow *parent )
243 broadcasts_panel = new wxPanel( parent, -1, wxDefaultPosition, wxSize( 500, 350 ) );
244 broadcasts_sizer = new wxBoxSizer( wxVERTICAL );
246 wxStaticBox *add_box = new wxStaticBox( broadcasts_panel, -1,
247 wxU( _( "New broadcast") ) );
248 wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( add_box, wxHORIZONTAL );
249 box_sizer->Add( AddBroadcastPanel( broadcasts_panel), 0, wxEXPAND|wxALL, 5 );
252 broadcasts_sizer->Add( box_sizer, 0, wxEXPAND|wxALL, 5 );
254 wxStaticLine *static_line = new wxStaticLine( broadcasts_panel, wxID_ANY );
255 broadcasts_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
257 scrolled_broadcasts = new wxScrolledWindow( broadcasts_panel, -1,
258 wxDefaultPosition, wxDefaultSize,
259 wxBORDER_NONE | wxVSCROLL );
261 scrolled_broadcasts_sizer = new wxBoxSizer( wxVERTICAL );
262 scrolled_broadcasts->SetAutoLayout( TRUE );
263 scrolled_broadcasts->SetScrollRate( 5,5 );
264 scrolled_broadcasts->SetSizerAndFit( scrolled_broadcasts_sizer );
266 broadcasts_sizer->Add( scrolled_broadcasts, 1, wxEXPAND| wxALL, 5 );
267 broadcasts_sizer->Layout();
269 broadcasts_panel->SetSizerAndFit( broadcasts_sizer );
271 return broadcasts_panel;
274 wxPanel * VLMPanel::AddBroadcastPanel( wxPanel *panel )
276 return new VLMAddStreamPanel( p_intf, panel, p_vlm, VLC_FALSE,
280 void VLMPanel::AppendBroadcast( VLMBroadcastStream *p_broadcast )
282 VLMBroadcastStreamPanel *p_new =
283 new VLMBroadcastStreamPanel( p_intf, scrolled_broadcasts,
285 p_new->b_found = VLC_TRUE;
286 scrolled_broadcasts_sizer->Add( p_new, 0, wxEXPAND | wxALL, 5 );
287 scrolled_broadcasts_sizer->Layout();
288 scrolled_broadcasts->FitInside();
289 broadcasts.push_back( p_new );
292 void VLMPanel::RemoveBroadcast( VLMBroadcastStreamPanel *p_streamp )
294 scrolled_broadcasts_sizer->Remove( p_streamp );
295 scrolled_broadcasts_sizer->Layout();
296 scrolled_broadcasts->FitInside();
299 /*************************
301 *************************/
302 wxPanel * VLMPanel::VODPanel( wxWindow *parent )
304 vods_panel = new wxPanel( parent, -1, wxDefaultPosition, wxSize( 500, 350 ) );
308 wxPanel * VLMPanel::AddVODPanel( wxPanel *panel )
310 return new VLMAddStreamPanel( p_intf, panel, p_vlm, VLC_FALSE,
314 void VLMPanel::AppendVOD( VLMVODStream *p_vod )
316 VLMVODStreamPanel *p_new =
317 new VLMVODStreamPanel( p_intf, scrolled_vods, p_vod );
318 p_new->b_found = VLC_TRUE;
319 scrolled_vods_sizer->Add( p_new, 0, wxEXPAND | wxALL, 5 );
320 scrolled_vods_sizer->Layout();
321 scrolled_vods->FitInside();
322 vods.push_back( p_new );
325 void VLMPanel::RemoveVOD( VLMVODStreamPanel *p_streamp )
327 scrolled_vods_sizer->Remove( p_streamp );
328 scrolled_vods_sizer->Layout();
329 scrolled_vods->FitInside();
332 /****************************************************************************
333 * VLM Add Broadcast panel implementation
334 *****************************************************************************/
343 BEGIN_EVENT_TABLE( VLMAddStreamPanel, wxPanel)
344 EVT_BUTTON( Create_Event, VLMAddStreamPanel::OnCreate )
345 EVT_BUTTON( Clear_Event, VLMAddStreamPanel::OnClear )
346 EVT_BUTTON( ChooseInput_Event, VLMAddStreamPanel::OnChooseInput )
347 EVT_BUTTON( ChooseOutput_Event, VLMAddStreamPanel::OnChooseOutput )
350 VLMAddStreamPanel::VLMAddStreamPanel( intf_thread_t *_p_intf,
351 wxWindow *_p_parent, VLMWrapper *_p_vlm,
352 vlc_bool_t _b_edit, vlc_bool_t _b_broadcast ):
353 wxPanel( _p_parent, -1, wxDefaultPosition, wxDefaultSize )
356 p_parent = _p_parent;
359 b_broadcast = _b_broadcast;
361 p_open_dialog = NULL;
362 p_sout_dialog = NULL;
364 SetAutoLayout( TRUE );
366 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
368 wxFlexGridSizer *upper_sizer = new wxFlexGridSizer( 5, 2 );
369 upper_sizer->AddGrowableCol( 1 );
370 upper_sizer->AddGrowableCol( 3 );
372 upper_sizer->Add( new wxStaticText( this, -1, wxU( _("Name") ) ), 0,
373 wxALIGN_CENTER_VERTICAL, 0 );
374 name_text = new wxTextCtrl( this, -1, wxU( "" ), wxDefaultPosition,
376 upper_sizer->Add( name_text , 1, wxEXPAND | wxLEFT | wxRIGHT, 5 );
378 upper_sizer->Add( new wxStaticText( this, -1, wxU( _("Input") ) ), 0,
379 wxALIGN_CENTER_VERTICAL, 0 );
380 input_text = new wxTextCtrl( this, -1, wxU( "" ) ,
381 wxDefaultPosition, wxSize( 150, -1 ) );
382 upper_sizer->Add( input_text , 1, wxEXPAND | wxLEFT | wxRIGHT, 5 );
383 upper_sizer->Add( new wxButton( this, ChooseInput_Event, wxU( _("Choose") ) ) );
385 upper_sizer->Add( 0,0 );
386 upper_sizer->Add( 0,0 );
388 upper_sizer->Add( new wxStaticText( this, -1, wxU( _("Output") ) ), 0,
389 wxALIGN_CENTER_VERTICAL, 0 );
390 output_text = new wxTextCtrl( this, -1, wxU( "" ) ,
391 wxDefaultPosition, wxSize( 150, -1 ) );
392 upper_sizer->Add( output_text, 1, wxEXPAND | wxLEFT | wxRIGHT, 5 );
393 upper_sizer->Add( new wxButton( this, ChooseOutput_Event,
394 wxU( _("Choose") ) ) );
396 panel_sizer->Add( upper_sizer, 0, wxEXPAND | wxALL, 5 );
398 wxBoxSizer *lower_sizer = new wxBoxSizer( wxHORIZONTAL );
399 enabled_checkbox = new wxCheckBox( this, -1, wxU( _("Enabled" ) ) );
400 enabled_checkbox->SetValue( true );
401 lower_sizer->Add( enabled_checkbox, 1 , wxEXPAND | wxALL , 5 );
404 loop_checkbox = new wxCheckBox( this, -1, wxU( _("Loop" ) ) );
405 lower_sizer->Add( loop_checkbox, 1 , wxEXPAND | wxALL , 5 );
410 lower_sizer->Add( new wxButton( this, wxID_CLEAR,
411 wxU( _( "&Clear" ) ) ),
412 0 , wxEXPAND | wxALL , 5 );
414 lower_sizer->Add( new wxButton( this, Create_Event,
415 wxU( _( b_edit ? "OK" : "Create" ) ) ),
416 0 , wxEXPAND | wxALL , 5 );
419 panel_sizer->Add( lower_sizer, 0 , wxEXPAND| wxALL, 5 );
420 panel_sizer->Layout();
421 SetSizerAndFit( panel_sizer );
424 VLMAddStreamPanel::~VLMAddStreamPanel()
428 void VLMAddStreamPanel::Load( VLMStream *p_stream )
430 name_text->SetValue( wxU( p_stream->p_media->psz_name ) );
431 name_text->SetEditable( false );
432 if( p_stream->p_media->i_input > 0 )
434 input_text->SetValue( wxU( p_stream->p_media->input[0] ) );
436 output_text->SetValue( wxU( p_stream->p_media->psz_output ) );
437 enabled_checkbox->SetValue( p_stream->p_media->b_enabled );
439 loop_checkbox->SetValue( p_stream->p_media->b_loop );
442 void VLMAddStreamPanel::OnCreate( wxCommandEvent &event )
444 char *psz_name = wxFromLocale( name_text->GetValue() );
445 char *psz_input = wxFromLocale( input_text->GetValue() );
446 char *psz_output = wxFromLocale( output_text->GetValue() );
447 if( b_broadcast && ! b_edit )
449 p_vlm->AddBroadcast( psz_name, psz_input, psz_output,
450 enabled_checkbox->IsChecked() ? VLC_TRUE: VLC_FALSE,
451 loop_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE );
453 else if( b_broadcast && b_edit )
455 p_vlm->EditBroadcast( psz_name, psz_input, psz_output,
456 enabled_checkbox->IsChecked() ? VLC_TRUE: VLC_FALSE,
457 loop_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE );
459 else if( !b_broadcast && !b_edit )
461 p_vlm->AddVod( psz_name, psz_input, psz_output,
462 enabled_checkbox->IsChecked() ? VLC_TRUE: VLC_FALSE,
463 loop_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE );
467 p_vlm->EditVod( psz_name, psz_input, psz_output,
468 enabled_checkbox->IsChecked() ? VLC_TRUE: VLC_FALSE,
469 loop_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE );
471 wxLocaleFree( psz_name) ; wxLocaleFree( psz_input ) ;
472 wxLocaleFree( psz_output);
479 void VLMAddStreamPanel::OnClear( wxCommandEvent &event )
481 name_text->SetValue( wxU("") );
482 input_text->SetValue( wxU("") );
483 output_text->SetValue( wxU("") );
486 void VLMAddStreamPanel::OnChooseInput( wxCommandEvent &event )
488 if( p_open_dialog == NULL )
489 p_open_dialog = new OpenDialog( p_intf, this, -1, -1, OPEN_STREAM );
491 if( p_open_dialog && p_open_dialog->ShowModal() == wxID_OK )
493 input_text->SetValue( p_open_dialog->mrl[0] );
497 void VLMAddStreamPanel::OnChooseOutput( wxCommandEvent &event )
499 if( p_sout_dialog == NULL )
500 p_sout_dialog = new SoutDialog( p_intf, this );
502 if( p_sout_dialog && p_sout_dialog->ShowModal() == wxID_OK )
504 wxString sout = (p_sout_dialog->GetOptions())[0] ;
505 sout = sout.AfterFirst( '=' );
506 output_text->SetValue( sout );
510 /****************************************************************************
511 * VLM Frame implementation
512 ****************************************************************************/
517 BEGIN_EVENT_TABLE( VLMFrame, wxFrame )
518 EVT_CLOSE( VLMFrame::OnClose )
521 VLMFrame::VLMFrame( intf_thread_t *_p_intf, wxWindow *_p_parent ) :
522 wxFrame( _p_parent, -1, wxU( _("VLM") ),
523 wxDefaultPosition, wxSize( 640,480 ), wxDEFAULT_FRAME_STYLE )
525 SetIcon( *_p_intf->p_sys->p_icon );
527 wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL );
528 vlm_panel = new VLMPanel( _p_intf, this );
531 main_sizer->Add( vlm_panel, 1, wxGROW, 0 );
533 main_sizer->Add( vlm_panel, 1, wxEXPAND | wxALL, 5 );
535 main_sizer->Layout();
536 SetSizerAndFit( main_sizer );
539 void VLMFrame::OnClose( wxCloseEvent& WXUNUSED(event) )
544 void VLMFrame::Update()
549 VLMFrame::~VLMFrame()
554 /****************************************************************************
555 * VLM Add stream Frame implementation
556 ****************************************************************************/
557 VLMEditStreamFrame::VLMEditStreamFrame( intf_thread_t *_p_intf,
558 wxWindow *_p_parent, VLMWrapper *_p_vlm, vlc_bool_t _b_broadcast,
559 VLMStream *p_stream ) :
560 wxFrame( _p_parent, -1, wxU( _("VLM stream") ),
561 wxDefaultPosition, wxSize( 640,480 ), wxDEFAULT_FRAME_STYLE )
563 SetIcon( *_p_intf->p_sys->p_icon );
565 wxBoxSizer *main_sizer = new wxBoxSizer( wxHORIZONTAL );
566 vlm_panel = new VLMAddStreamPanel( _p_intf, this, _p_vlm ,
567 VLC_TRUE, _b_broadcast );
569 vlm_panel->Load( p_stream );
571 main_sizer->Add( vlm_panel, 1, wxEXPAND | wxALL, 5 );
572 main_sizer->Layout();
573 SetSizerAndFit( main_sizer );
576 VLMEditStreamFrame::~VLMEditStreamFrame()