1 /*****************************************************************************
2 * stream.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: streamwizard.cpp,v 1.2 2003/12/04 16:49:43 sam Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
35 #include "wxwindows.h"
37 #include <wx/statline.h>
40 #define STREAM_INTRO N_( "Stream with VLC in three steps" )
41 #define STREAM_STEP1 N_( "Step 1: Select what to stream" )
42 #define STREAM_STEP2 N_( "Step 2: Define streaming method" )
43 #define STREAM_STEP3 N_( "Step 3: Start streaming" )
46 /*****************************************************************************
48 *****************************************************************************/
50 /* IDs for the controls and the menu commands */
59 BEGIN_EVENT_TABLE(StreamDialog, wxFrame)
61 EVT_BUTTON(wxID_OK, StreamDialog::OnClose)
63 EVT_BUTTON(Open_Event,StreamDialog::OnOpen)
64 EVT_BUTTON(Sout_Event,StreamDialog::OnSout)
65 EVT_BUTTON(Start_Event,StreamDialog::OnStart)
67 /* Hide the window when the user closes the window */
68 EVT_CLOSE(StreamDialog::OnClose)
72 /*****************************************************************************
74 *****************************************************************************/
75 StreamDialog::StreamDialog( intf_thread_t *_p_intf, wxWindow *p_parent ):
76 wxFrame( p_parent, -1, wxU(_("Stream")), wxDefaultPosition,
77 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
81 SetIcon( *p_intf->p_sys->p_icon );
82 SetAutoLayout( TRUE );
87 /* Create a panel to put everything in */
88 wxPanel *panel = new wxPanel( this, -1 );
89 panel->SetAutoLayout( TRUE );
91 wxStaticText *intro_label = new wxStaticText( panel,
92 -1 , wxU(_( STREAM_INTRO )));
95 wxStaticText *step1_label = new wxStaticText( panel,
96 -1 , wxU(_( STREAM_STEP1 )));
98 step2_label = new wxStaticText( panel,
99 -1 , wxU(_( STREAM_STEP2 )));
101 step3_label = new wxStaticText( panel,
102 -1 , wxU(_( STREAM_STEP3 )));
104 wxButton *open_button = new wxButton( panel,
105 Open_Event, wxU(_("Open...")));
107 sout_button = new wxButton( panel,
108 Sout_Event, wxU(_("Choose...")));
110 start_button = new wxButton( panel,
111 Start_Event, wxU(_("Start !")));
114 step2_label->Disable();
115 step3_label->Disable();
117 sout_button->Disable();
118 start_button->Disable();
120 /* Place everything in sizers */
121 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
122 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
124 wxBoxSizer *step1_sizer = new wxBoxSizer( wxHORIZONTAL );
125 wxBoxSizer *step2_sizer = new wxBoxSizer( wxHORIZONTAL );
126 wxBoxSizer *step3_sizer = new wxBoxSizer( wxHORIZONTAL );
128 step1_sizer->Add( step1_label, 1, wxALL | wxEXPAND | wxALIGN_LEFT, 10 );
129 step1_sizer->Add( open_button, 1, wxALL | wxEXPAND | wxALIGN_RIGHT, 10 );
131 step2_sizer->Add( step2_label, 1, wxALL | wxEXPAND | wxALIGN_LEFT, 10 );
132 step2_sizer->Add( sout_button, 1, wxALL | wxEXPAND | wxALIGN_RIGHT, 10 );
134 step3_sizer->Add( step3_label, 1, wxALL | wxEXPAND | wxLEFT, 10 );
135 step3_sizer->Add( start_button, 1, wxALL | wxEXPAND | wxLEFT, 10 );
137 panel_sizer->Add( intro_label, 0, wxEXPAND | wxALL, 10 );
139 panel_sizer->Add( new wxStaticLine( panel, 0), 0,
140 wxEXPAND | wxLEFT | wxRIGHT, 2 );
141 panel_sizer->Add( step1_sizer, 0, wxEXPAND, 10 );
142 panel_sizer->Add( new wxStaticLine( panel, 0), 0,
143 wxEXPAND | wxLEFT | wxRIGHT, 2 );
144 panel_sizer->Add( step2_sizer, 0, wxEXPAND, 10 );
145 panel_sizer->Add( new wxStaticLine( panel, 0), 0,
146 wxEXPAND | wxLEFT | wxRIGHT, 2 );
147 panel_sizer->Add( step3_sizer, 0, wxEXPAND, 10 );
149 panel_sizer->Layout();
150 panel->SetSizerAndFit( panel_sizer );
151 main_sizer->Add( panel, 1, wxEXPAND, 0 );
152 main_sizer->Layout();
153 SetSizerAndFit( main_sizer );
157 /*****************************************************************************
159 *****************************************************************************/
160 StreamDialog::~StreamDialog()
162 if( p_open_dialog ) delete p_open_dialog;
163 if( p_sout_dialog ) delete p_sout_dialog;
166 void StreamDialog::OnOpen( wxCommandEvent& event )
170 p_open_dialog = new OpenDialog(
171 p_intf, this, FILE_ACCESS, 1 , OPEN_STREAM );
176 p_open_dialog->Show();
177 mrl = p_open_dialog->mrl;
178 sout_button->Enable();
179 step2_label->Enable();
183 void StreamDialog::OnSout( wxCommandEvent& event )
185 /* Show/hide the sout dialog */
186 if( p_sout_dialog == NULL )
187 p_sout_dialog = new SoutDialog( p_intf, this );
189 if( p_sout_dialog && p_sout_dialog->ShowModal() == wxID_OK )
191 sout_mrl = p_sout_dialog->GetOptions();
192 start_button->Enable();
193 step3_label->Enable();
197 void StreamDialog::OnStart( wxCommandEvent& event )
199 /* Update the playlist */
200 playlist_t *p_playlist =
201 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
203 if( p_playlist == NULL ) return;
205 for( int i = 0; i < (int)p_open_dialog->mrl.GetCount(); i++ )
207 int i_options = 0, i_total_options;
208 char **ppsz_options = NULL;
210 /* Count the input options */
211 while( i + i_options + 1 < (int)p_open_dialog->mrl.GetCount() &&
212 ((const char *)p_open_dialog->mrl[i + i_options + 1].
213 mb_str())[0] == ':' )
218 /* Allocate ppsz_options */
219 for( int j = 0; j < i_options; j++ )
222 ppsz_options = (char **)malloc( sizeof(char *) * i_options );
224 ppsz_options[j] = strdup( p_open_dialog->mrl[i + j + 1].mb_str() );
227 i_total_options = i_options;
229 /* Get the options from the stream output dialog */
230 if( sout_mrl.GetCount() )
232 ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
233 (i_total_options + sout_mrl.GetCount()) );
235 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
237 ppsz_options[i_total_options + j] =
238 strdup( sout_mrl[j].mb_str() );
241 i_total_options += sout_mrl.GetCount();
244 msg_Dbg(p_intf,"playings %s",(const char *)p_open_dialog->mrl[i].mb_str());
245 playlist_Add( p_playlist, (const char *)p_open_dialog->mrl[i].mb_str(),
246 (const char **)ppsz_options, i_total_options,
247 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
249 for( int j = 0; j < i_total_options; j++ )
250 free( ppsz_options[j] );
251 if( ppsz_options ) free( ppsz_options );
255 vlc_object_release( p_playlist );
261 void StreamDialog::OnClose( wxCommandEvent& event )