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