]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/streamwizard.cpp
450154da11688576deb21f2f0e5a6e4a9b270c20
[vlc] / modules / gui / wxwindows / streamwizard.cpp
1 /*****************************************************************************
2  * stream.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id: streamwizard.cpp,v 1.6 2004/01/29 17:51:08 zorglub Exp $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 #include "wxwindows.h"
36
37 #include <wx/statline.h>
38
39
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." )
44
45
46 /*****************************************************************************
47  * Event Table.
48  *****************************************************************************/
49
50 /* IDs for the controls and the menu commands */
51 enum
52 {
53     Open_Event,
54     Sout_Event,
55     Start_Event,
56     Close_Event
57 };
58
59 BEGIN_EVENT_TABLE(StreamDialog, wxFrame)
60     /* Button events */
61     EVT_BUTTON(wxID_OK, StreamDialog::OnClose)
62
63     EVT_BUTTON(Open_Event,StreamDialog::OnOpen)
64     EVT_BUTTON(Sout_Event,StreamDialog::OnSout)
65     EVT_BUTTON(Start_Event,StreamDialog::OnStart)
66
67     /* Hide the window when the user closes the window */
68     EVT_CLOSE(StreamDialog::OnClose)
69
70 END_EVENT_TABLE()
71
72 /*****************************************************************************
73  * Constructor.
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 )
78 {
79     /* Initializations */
80     p_intf = _p_intf;
81     SetIcon( *p_intf->p_sys->p_icon );
82     SetAutoLayout( TRUE );
83
84     p_open_dialog = NULL;
85     p_sout_dialog = NULL;
86
87     /* Create a panel to put everything in */
88     wxPanel *panel = new wxPanel( this, -1 );
89     panel->SetAutoLayout( TRUE );
90
91     wxStaticText *intro_label = new wxStaticText( panel,
92                           -1 , wxU(_( STREAM_INTRO )));
93
94
95     wxStaticText *step1_label = new wxStaticText( panel,
96                            -1 , wxU(_( STREAM_STEP1 )));
97
98     step2_label = new wxStaticText( panel,
99                  -1 , wxU(_( STREAM_STEP2 )));
100
101     step3_label = new wxStaticText( panel,
102                  -1 , wxU(_( STREAM_STEP3 )));
103
104     wxButton *open_button = new wxButton( panel,
105                   Open_Event, wxU(_("Open...")));
106
107     sout_button = new wxButton( panel,
108                    Sout_Event, wxU(_("Choose...")));
109
110     start_button = new wxButton( panel,
111                    Start_Event, wxU(_("Start!")));
112
113
114     step2_label->Disable();
115     step3_label->Disable();
116
117     sout_button->Disable();
118     start_button->Disable();
119
120     /* Place everything in sizers */
121     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
122     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
123
124     wxBoxSizer *step1_sizer = new wxBoxSizer( wxHORIZONTAL );
125     wxBoxSizer *step2_sizer = new wxBoxSizer( wxHORIZONTAL );
126     wxBoxSizer *step3_sizer = new wxBoxSizer( wxHORIZONTAL );
127
128     step1_sizer->Add( step1_label, 1, wxALL | wxEXPAND | wxALIGN_LEFT, 10 );
129     step1_sizer->Add( open_button, 1, wxALL | wxEXPAND | wxALIGN_RIGHT, 10 );
130
131     step2_sizer->Add( step2_label, 1, wxALL | wxEXPAND | wxALIGN_LEFT, 10 );
132     step2_sizer->Add( sout_button, 1, wxALL | wxEXPAND | wxALIGN_RIGHT, 10 );
133
134     step3_sizer->Add( step3_label,  1, wxALL | wxEXPAND | wxLEFT, 10 );
135     step3_sizer->Add( start_button, 1, wxALL | wxEXPAND | wxLEFT, 10 );
136
137     panel_sizer->Add( intro_label, 0, wxEXPAND | wxALL, 10 );
138
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 );
148
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 );
154
155 }
156
157 /*****************************************************************************
158  * Destructor.
159  *****************************************************************************/
160 StreamDialog::~StreamDialog()
161 {
162     if( p_open_dialog ) delete p_open_dialog;
163     if( p_sout_dialog ) delete p_sout_dialog;
164 }
165
166 void StreamDialog::OnOpen( wxCommandEvent& event )
167 {
168     if( !p_open_dialog )
169     {
170         p_open_dialog = new OpenDialog(
171                     p_intf, this, FILE_ACCESS, 1 , OPEN_STREAM );
172     }
173
174     if( p_open_dialog)
175     {
176        p_open_dialog->Show();
177        mrl = p_open_dialog->mrl;
178        sout_button->Enable();
179        step2_label->Enable();
180     }
181 }
182
183 void StreamDialog::OnSout( wxCommandEvent& event )
184 {
185     /* Show/hide the sout dialog */
186     if( p_sout_dialog == NULL )
187         p_sout_dialog = new SoutDialog( p_intf, this );
188
189     if( p_sout_dialog && p_sout_dialog->ShowModal() == wxID_OK )
190     {
191         sout_mrl = p_sout_dialog->GetOptions();
192         start_button->Enable();
193         step3_label->Enable();
194     }
195 }
196
197 void StreamDialog::OnStart( wxCommandEvent& event )
198 {
199     /* Update the playlist */
200     playlist_t *p_playlist =
201         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
202                                        FIND_ANYWHERE );
203     if( p_playlist == NULL ) return;
204
205     for( int i = 0; i < (int)p_open_dialog->mrl.GetCount(); i++ )
206     {
207         playlist_item_t *p_item = playlist_ItemNew( p_intf,
208                       (const char *)p_open_dialog->mrl[i].mb_str(),
209                       (const char *)p_open_dialog->mrl[i].mb_str() );
210         int i_options = 0;
211
212         /* Count the input options */
213         while( i + i_options + 1 < (int)p_open_dialog->mrl.GetCount() &&
214                ((const char *)p_open_dialog->mrl[i + i_options + 1].
215                                              mb_str())[0] == ':' )
216         {
217             i_options++;
218         }
219
220         /* Insert options */
221         for( int j = 0; j < i_options; j++ )
222         {
223             playlist_ItemAddOption( p_item ,
224                                 p_open_dialog->mrl[i + j  + 1].mb_str() );
225         }
226
227         /* Get the options from the stream output dialog */
228         if( sout_mrl.GetCount() )
229         {
230             for( int j = 0; j < (int)sout_mrl.GetCount(); j++ )
231             {
232                 playlist_ItemAddOption( p_item , sout_mrl[j].mb_str() );
233             }
234         }
235
236          playlist_AddItem( p_playlist, p_item,
237                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
238
239         msg_Dbg(p_intf,"playings %s",
240                  (const char *)p_open_dialog->mrl[i].mb_str());
241
242         i += i_options;
243     }
244     vlc_object_release( p_playlist );
245
246     Hide();
247 }
248
249
250 void StreamDialog::OnClose( wxCommandEvent& event )
251 {
252     Hide();
253 }