1 /*****************************************************************************
2 * stream.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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>
39 #define STREAM_INTRO N_( "Stream with VLC in three steps." )
40 #define STREAM_STEP1 N_( "Step 1: Select what to stream." )
41 #define STREAM_STEP2 N_( "Step 2: Define streaming method." )
42 #define STREAM_STEP3 N_( "Step 3: Start streaming." )
44 /*****************************************************************************
46 *****************************************************************************/
48 /* IDs for the controls and the menu commands */
57 BEGIN_EVENT_TABLE(StreamDialog, wxFrame)
59 EVT_BUTTON(wxID_OK, StreamDialog::OnClose)
61 EVT_BUTTON(Open_Event,StreamDialog::OnOpen)
62 EVT_BUTTON(Sout_Event,StreamDialog::OnSout)
63 EVT_BUTTON(Start_Event,StreamDialog::OnStart)
65 /* Hide the window when the user closes the window */
66 EVT_CLOSE(StreamDialog::OnClose)
70 /*****************************************************************************
72 *****************************************************************************/
73 StreamDialog::StreamDialog( intf_thread_t *_p_intf, wxWindow *p_parent ):
74 wxFrame( p_parent, -1, wxU(_("Stream")), wxDefaultPosition,
75 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
79 SetIcon( *p_intf->p_sys->p_icon );
80 SetAutoLayout( TRUE );
85 /* Create a panel to put everything in */
86 wxPanel *panel = new wxPanel( this, -1 );
87 panel->SetAutoLayout( TRUE );
89 wxStaticText *intro_label = new wxStaticText( panel,
90 -1 , wxU(_( STREAM_INTRO )));
93 wxStaticText *step1_label = new wxStaticText( panel,
94 -1 , wxU(_( STREAM_STEP1 )));
96 step2_label = new wxStaticText( panel,
97 -1 , wxU(_( STREAM_STEP2 )));
99 step3_label = new wxStaticText( panel,
100 -1 , wxU(_( STREAM_STEP3 )));
102 wxButton *open_button = new wxButton( panel,
103 Open_Event, wxU(_("Open...")));
105 sout_button = new wxButton( panel,
106 Sout_Event, wxU(_("Choose...")));
108 start_button = new wxButton( panel,
109 Start_Event, wxU(_("Start!")));
111 step2_label->Disable();
112 step3_label->Disable();
114 sout_button->Disable();
115 start_button->Disable();
117 /* Place everything in sizers */
118 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
119 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
121 wxBoxSizer *step1_sizer = new wxBoxSizer( wxHORIZONTAL );
122 wxBoxSizer *step2_sizer = new wxBoxSizer( wxHORIZONTAL );
123 wxBoxSizer *step3_sizer = new wxBoxSizer( wxHORIZONTAL );
125 step1_sizer->Add( step1_label, 1, wxALL | wxEXPAND | wxALIGN_LEFT, 10 );
126 step1_sizer->Add( open_button, 1, wxALL | wxEXPAND | wxALIGN_RIGHT, 10 );
128 step2_sizer->Add( step2_label, 1, wxALL | wxEXPAND | wxALIGN_LEFT, 10 );
129 step2_sizer->Add( sout_button, 1, wxALL | wxEXPAND | wxALIGN_RIGHT, 10 );
131 step3_sizer->Add( step3_label, 1, wxALL | wxEXPAND | wxLEFT, 10 );
132 step3_sizer->Add( start_button, 1, wxALL | wxEXPAND | wxLEFT, 10 );
134 panel_sizer->Add( intro_label, 0, wxEXPAND | wxALL, 10 );
136 panel_sizer->Add( new wxStaticLine( panel, 0), 0,
137 wxEXPAND | wxLEFT | wxRIGHT, 2 );
138 panel_sizer->Add( step1_sizer, 0, wxEXPAND, 10 );
139 panel_sizer->Add( new wxStaticLine( panel, 0), 0,
140 wxEXPAND | wxLEFT | wxRIGHT, 2 );
141 panel_sizer->Add( step2_sizer, 0, wxEXPAND, 10 );
142 panel_sizer->Add( new wxStaticLine( panel, 0), 0,
143 wxEXPAND | wxLEFT | wxRIGHT, 2 );
144 panel_sizer->Add( step3_sizer, 0, wxEXPAND, 10 );
146 panel_sizer->Layout();
147 panel->SetSizerAndFit( panel_sizer );
148 main_sizer->Add( panel, 1, wxEXPAND, 0 );
149 main_sizer->Layout();
150 SetSizerAndFit( main_sizer );
154 /*****************************************************************************
156 *****************************************************************************/
157 StreamDialog::~StreamDialog()
159 if( p_open_dialog ) delete p_open_dialog;
160 if( p_sout_dialog ) delete p_sout_dialog;
163 void StreamDialog::OnOpen( wxCommandEvent& event )
168 new OpenDialog( p_intf, this, FILE_ACCESS, 1 , OPEN_STREAM );
173 p_open_dialog->Show();
174 p_open_dialog->Enable();
175 mrl = p_open_dialog->mrl;
176 sout_button->Enable();
177 step2_label->Enable();
181 void StreamDialog::OnSout( wxCommandEvent& event )
183 /* Show/hide the sout dialog */
184 if( p_sout_dialog == NULL )
185 p_sout_dialog = new SoutDialog( p_intf, this );
187 if( p_sout_dialog && p_sout_dialog->ShowModal() == wxID_OK )
189 sout_mrl = p_sout_dialog->GetOptions();
190 start_button->Enable();
191 step3_label->Enable();
195 void StreamDialog::OnStart( wxCommandEvent& event )
197 /* Update the playlist */
198 playlist_t *p_playlist =
199 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
201 if( p_playlist == NULL ) return;
203 for( int i = 0; i < (int)p_open_dialog->mrl.GetCount(); i++ )
205 playlist_item_t *p_item = playlist_ItemNew( p_intf,
206 (const char *)p_open_dialog->mrl[i].mb_str(),
207 (const char *)p_open_dialog->mrl[i].mb_str() );
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] == ':' )
219 for( int j = 0; j < i_options; j++ )
221 playlist_ItemAddOption( p_item ,
222 p_open_dialog->mrl[i + j + 1].mb_str() );
225 /* Get the options from the stream output dialog */
226 if( sout_mrl.GetCount() )
228 for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
230 playlist_ItemAddOption( p_item , sout_mrl[j].mb_str() );
234 playlist_AddItem( p_playlist, p_item,
235 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
238 msg_Dbg( p_intf,"playings %s",
239 (const char *)p_open_dialog->mrl[i].mb_str() );
243 vlc_object_release( p_playlist );
248 void StreamDialog::OnClose( wxCommandEvent& event )