]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/wizard.cpp
4181b4d690ddf652ab9cccc1907ba7ffb3efa23d
[vlc] / modules / gui / wxwidgets / dialogs / wizard.cpp
1 /*****************************************************************************
2  * wizard.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "dialogs/wizard.hpp"
28 #include "streamdata.h"
29 #include "dialogs/open.hpp"
30
31 #include <wx/listctrl.h>
32 #include <wx/statline.h>
33 #include <network.h>
34 #include <charset.h>
35
36 class wizHelloPage;
37 class wizInputPage;
38
39 /*****************************************************************************
40  * Define events
41  *****************************************************************************/
42 enum
43 {
44     ActionRadio0_Event, ActionRadio1_Event,
45     MoreInfoStreaming_Event,
46     MoreInfoTranscode_Event,
47
48     Open_Event , Choose_Event ,
49     ListView_Event,
50     InputRadio0_Event, InputRadio1_Event,
51     PartialEnable_Event,
52
53     MethodRadio0_Event, MethodRadio1_Event,
54     MethodRadio2_Event, MethodRadio3_Event,
55
56     EncapRadio0_Event, EncapRadio1_Event,
57     EncapRadio2_Event, EncapRadio3_Event,
58     EncapRadio4_Event, EncapRadio5_Event,
59     EncapRadio6_Event, EncapRadio7_Event,
60     EncapRadio8_Event, EncapRadio9_Event,
61     EncapRadio10_Event, EncapRadio11_Event,
62
63     VideoEnable_Event, VideoCodec_Event,VideoBitrate_Event,
64     AudioEnable_Event, AudioCodec_Event,AudioBitrate_Event,
65
66     SAP_Event,
67
68 };
69
70 #define TEXTWIDTH 55
71 #define ACTION_STREAM 0
72 #define ACTION_TRANSCODE 1
73
74 BEGIN_EVENT_TABLE(WizardDialog, wxWizard)
75 END_EVENT_TABLE()
76
77 /*****************************************************************************
78  * Wizard strings
79  *****************************************************************************/
80
81 #define ERROR_MSG _("Error")
82 #define ITEM_NAME _("Streaming/Transcoding Wizard")
83
84 /* Hello page */
85 #define HELLO_TITLE _("Streaming/Transcoding Wizard")
86 #define HELLO_TEXT _("This wizard helps you to stream, transcode or" \
87                      " save a stream.")
88 #define HELLO_STREAMING _("Stream to network")
89 #define HELLO_STREAMING_DESC _("Use this to stream on a network.")
90 #define HELLO_TRANSCODE _("Transcode/Save to file")
91 #define HELLO_TRANSCODE_DESC _("Use this to re-encode a stream and save it "\
92         "to a file.")
93 #define HELLO_NOTICE _("This wizard only contains a small subset " \
94         "of VLC's streaming and transcoding capabilities. Use the Open "\
95         "and Stream Output dialogs to access all of them.")
96
97 #define MOREINFO_STREAM _("Use this to stream on a network")
98
99 #define MOREINFO_TRANSCODE _("Saves the stream to a file. The stream must " \
100         "be a format that VLC recognizes. If desired, the stream can also " \
101         "be transcoded to another format.\n\nPlease note that VLC is not very" \
102         " suited for file-to-file transcoding. Its transcoding " \
103         "features are more appropriate for saving network streams." )
104
105 /* Input page */
106 #define INPUT_TITLE _("Input")
107 #define INPUT_TEXT _("Input stream")
108
109 #define INPUT_OPEN _("Select a stream" )
110 #define INPUT_PL _( "Existing playlist item" )
111
112 #define CHOOSE_STREAM _("You must choose a stream")
113 #define NO_PLAYLIST _("Unable to find playlist")
114
115 #define PARTIAL _("Use this to read only a part of the stream. " \
116                   "To use, enter the starting and ending times (in seconds)." \
117                   "\n\nNote: You must be able to control the incoming stream " \
118                   "(for example, a file or a disc, but not a RTP/UDP " \
119                   "network stream).\n" \
120 )
121
122 #define INPUT_BUTTON _("Choose")
123
124 /* Transcode 1 */
125 #define TRANSCODE1_TITLE _("Transcode")
126 #define TRANSCODE1_TEXT _("Changes the compression format " \
127         "of the audio or video tracks. To change only the " \
128         "container format, proceed to the next page.")
129
130 #define TR_VIDEO_TEXT0 _("Transcode video (if available)" )
131 #define TR_VIDEO_TEXT _("Select the target video codec. Choose a codec to " \
132                         "display more information about it.")
133
134 #define TR_AUDIO_TEXT0 _("Transcode audio (if available)"
135 #define TR_AUDIO_TEXT _("Select the target audio codec. Choose a codec to " \
136                         "display more information about it.")
137
138 /* Streaming 1 */
139 #define STREAMING1_TITLE _("Streaming")
140 #define STREAMING1_TEXT _("Determines how the input stream will be sent.")
141
142
143 #define INVALID_MCAST_ADDRESS _("This does not appear to be a valid " \
144                                 "multicast address" )
145 #define NO_ADDRESS_TEXT _("Please enter an address" )
146
147 /* Encap  */
148 #define ENCAP_TITLE _("Encapsulation format")
149 #define ENCAP_TEXT _("Determines how the stream will be encapsulated. " \
150                      "Depending on the previous choices, some formats " \
151                      "might not be available." )
152
153
154 /* Transcode 2 */
155 #define EXTRATRANSCODE_TITLE _("Additional transcode options")
156 #define EXTRATRANSCODE_TEXT _("Defines a few additional parameters " \
157                               "for the transcoding." )
158
159 #define CHOOSE_OUTFILE _("You must choose a file to save to")
160
161 /* Streaming 2 */
162 #define EXTRASTREAMING_TITLE _("Additional streaming options")
163 #define EXTRASTREAMING_TEXT _("Defines a few additional parameters " \
164                               "for the stream." )
165
166 #define TTL _("Define the TTL (Time-To-Live) of the stream. This parameter " \
167               "is the maximum number of routers your stream can go through. " \
168               "If you don't know what it means, or if you want to stream on " \
169               "your local network only, leave this setting to 1." )
170
171 #define SAP _("When streaming using RTP, you can announce your streams " \
172               "using the SAP/SDP announcing protocol. This way, the clients " \
173               "won't have to type in the multicast address, it will appear " \
174               "in their playlist if they enable the SAP extra interface.\n" \
175               "If you want to give a name to your stream, enter it here. " \
176               "Otherwise, a default name will be used." )
177
178 /*****************************************************************************
179  * All the pages of the wizard, declaration
180  *****************************************************************************/
181
182 /* Declare classes */
183 class wizHelloPage : public wxWizardPageSimple
184 {
185     public:
186         wizHelloPage( wxWizard *parent);
187         void OnActionChange( wxCommandEvent& event );
188         void OnWizardPageChanging(wxWizardEvent& event);
189         void OnMoreInfo( wxCommandEvent& event );
190     protected:
191         int i_action;
192         WizardDialog *p_parent;
193         wxRadioButton *action_radios[2];
194         DECLARE_EVENT_TABLE()
195 };
196
197 BEGIN_EVENT_TABLE(wizHelloPage, wxWizardPageSimple)
198     EVT_RADIOBUTTON( ActionRadio0_Event, wizHelloPage::OnActionChange)
199     EVT_RADIOBUTTON( ActionRadio1_Event, wizHelloPage::OnActionChange)
200     EVT_BUTTON( MoreInfoStreaming_Event, wizHelloPage::OnMoreInfo )
201     EVT_BUTTON( MoreInfoTranscode_Event, wizHelloPage::OnMoreInfo )
202
203     EVT_WIZARD_PAGE_CHANGING(-1, wizHelloPage::OnWizardPageChanging)
204 END_EVENT_TABLE()
205
206
207 class wizInputPage : public wxWizardPage
208 {
209     public:
210         wizInputPage( wxWizard *, wxWizardPage *, intf_thread_t *);
211         wizInputPage::~wizInputPage();
212         void OnWizardPageChanging(wxWizardEvent& event);
213         void OnInputChange( wxCommandEvent& event );
214         void OnEnablePartial(wxCommandEvent& event);
215         virtual wxWizardPage *GetPrev() const;
216         virtual wxWizardPage *GetNext() const;
217         void SetStreamingPage( wxWizardPage *page);
218         void SetTranscodePage( wxWizardPage *page);
219         void SetAction( int i_action );
220         void SetPintf( intf_thread_t *p_intf );
221         void SetUri( char *psz_uri );
222         void SetPartial( int i_from, int i_to );
223
224     protected:
225         bool b_chosen;
226         intf_thread_t *p_intf;
227         int i_action;
228         int i_input;
229
230         void OnChoose( wxCommandEvent& event );
231
232         WizardDialog *p_parent;
233         wxRadioButton *input_radios[2];
234         wxCheckBox *enable_checkbox;
235         wxBoxSizer *mainSizer;
236         wxArrayString mrl;
237         wxTextCtrl *mrl_text;
238         wxTextCtrl *from_text;
239         wxTextCtrl *to_text;
240         OpenDialog *p_open_dialog;
241         wxListView *listview;
242         wxPanel *open_panel;
243         wxPanel *radio_panel; /* radio buttons should be in their own panel... */
244         wxWizardPage *p_prev;
245         wxWizardPage *p_streaming_page;
246         wxWizardPage *p_transcode_page;
247
248         DECLARE_EVENT_TABLE()
249 };
250
251 BEGIN_EVENT_TABLE(wizInputPage, wxWizardPage)
252     EVT_RADIOBUTTON( InputRadio0_Event, wizInputPage::OnInputChange)
253     EVT_RADIOBUTTON( InputRadio1_Event, wizInputPage::OnInputChange)
254     EVT_BUTTON( Choose_Event, wizInputPage::OnChoose)
255     EVT_CHECKBOX( PartialEnable_Event, wizInputPage::OnEnablePartial)
256     EVT_WIZARD_PAGE_CHANGING(-1, wizInputPage::OnWizardPageChanging)
257 END_EVENT_TABLE()
258
259
260 class wizTranscodeCodecPage : public wxWizardPage
261 {
262 public:
263     wizTranscodeCodecPage( wxWizard *parent, wxWizardPage *next);
264     ~wizTranscodeCodecPage();
265     void wizTranscodeCodecPage::OnWizardPageChanging(wxWizardEvent& event);
266     virtual wxWizardPage *GetPrev() const;
267     virtual wxWizardPage *GetNext() const;
268     void SetPrev( wxWizardPage *page);
269 protected:
270     wxCheckBox *video_checkbox;
271     wxComboBox *video_combo;
272     wxComboBox *vb_combo;
273     wxStaticText * video_text;
274     wxCheckBox *audio_checkbox;
275     wxComboBox *audio_combo;
276     wxComboBox *ab_combo;
277     wxStaticText * audio_text;
278
279     WizardDialog *p_parent;
280     int i_audio_codec;
281     int i_video_codec;
282
283     char *vcodec;
284     char *acodec;
285
286     wxWizardPage *p_prev;
287     wxWizardPage *p_next;
288
289     void OnVideoCodecChange(wxCommandEvent& event);
290     void OnAudioCodecChange(wxCommandEvent& event);
291     void OnEnableVideo(wxCommandEvent& event);
292     void OnEnableAudio(wxCommandEvent& event);
293
294     DECLARE_EVENT_TABLE()
295 };
296
297 BEGIN_EVENT_TABLE(wizTranscodeCodecPage, wxWizardPage)
298    EVT_CHECKBOX( VideoEnable_Event, wizTranscodeCodecPage::OnEnableVideo)
299    EVT_CHECKBOX( AudioEnable_Event, wizTranscodeCodecPage::OnEnableAudio)
300    EVT_COMBOBOX( VideoCodec_Event, wizTranscodeCodecPage::OnVideoCodecChange)
301    EVT_COMBOBOX( AudioCodec_Event, wizTranscodeCodecPage::OnAudioCodecChange)
302    EVT_WIZARD_PAGE_CHANGING(-1, wizTranscodeCodecPage::OnWizardPageChanging)
303 END_EVENT_TABLE()
304
305 class wizStreamingMethodPage : public wxWizardPage
306 {
307 public:
308     wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
309                             wxWizardPage *next) ;
310     void OnWizardPageChanging(wxWizardEvent& event);
311     virtual wxWizardPage *GetPrev() const;
312     virtual wxWizardPage *GetNext() const;
313     void SetPrev( wxWizardPage *page);
314 protected:
315     DECLARE_EVENT_TABLE()
316     int i_method;
317     wxBoxSizer *mainSizer;
318     wxStaticBoxSizer *address_sizer;
319     wxStaticText *address_text;
320     wxTextCtrl *address_txtctrl;
321     WizardDialog * p_parent;
322     void OnMethodChange( wxCommandEvent& event );
323     wxRadioButton *method_radios[4];
324     wxWizardPage *p_prev;
325     wxWizardPage *p_next;
326     intf_thread_t *p_intf;
327 };
328
329 BEGIN_EVENT_TABLE(wizStreamingMethodPage, wxWizardPage)
330     EVT_RADIOBUTTON( MethodRadio0_Event, wizStreamingMethodPage::OnMethodChange)
331     EVT_RADIOBUTTON( MethodRadio1_Event, wizStreamingMethodPage::OnMethodChange)
332     EVT_RADIOBUTTON( MethodRadio2_Event, wizStreamingMethodPage::OnMethodChange)
333     EVT_RADIOBUTTON( MethodRadio3_Event, wizStreamingMethodPage::OnMethodChange)
334     EVT_WIZARD_PAGE_CHANGING(-1, wizStreamingMethodPage::OnWizardPageChanging)
335 END_EVENT_TABLE()
336
337
338 class wizEncapPage : public wxWizardPage
339 {
340 public:
341     wizEncapPage( wxWizard *parent);
342     wizEncapPage::~wizEncapPage();
343     void OnWizardPageChanging(wxWizardEvent& event);
344     virtual wxWizardPage *GetPrev() const;
345     virtual wxWizardPage *GetNext() const;
346     void SetStreamingPage( wxWizardPage *page);
347     void SetTranscodePage( wxWizardPage *page);
348     void SetPrev( wxWizardPage *page);
349     void SetAction( int );
350     void EnableEncap( int encap );
351 protected:
352     DECLARE_EVENT_TABLE()
353     int i_encap;
354     int i_mux;
355     int i_action;
356     void OnEncapChange( wxCommandEvent& event );
357     wxRadioButton *encap_radios[MUXERS_NUMBER];
358     WizardDialog *p_parent;
359     wxWizardPage *p_prev;
360     wxWizardPage *p_streaming_page;
361     wxWizardPage *p_transcode_page;
362 };
363
364 BEGIN_EVENT_TABLE(wizEncapPage, wxWizardPage)
365     EVT_WIZARD_PAGE_CHANGING(-1, wizEncapPage::OnWizardPageChanging)
366     EVT_RADIOBUTTON( EncapRadio0_Event, wizEncapPage::OnEncapChange)
367     EVT_RADIOBUTTON( EncapRadio1_Event, wizEncapPage::OnEncapChange)
368     EVT_RADIOBUTTON( EncapRadio2_Event, wizEncapPage::OnEncapChange)
369     EVT_RADIOBUTTON( EncapRadio3_Event, wizEncapPage::OnEncapChange)
370     EVT_RADIOBUTTON( EncapRadio4_Event, wizEncapPage::OnEncapChange)
371     EVT_RADIOBUTTON( EncapRadio5_Event, wizEncapPage::OnEncapChange)
372     EVT_RADIOBUTTON( EncapRadio6_Event, wizEncapPage::OnEncapChange)
373     EVT_RADIOBUTTON( EncapRadio7_Event, wizEncapPage::OnEncapChange)
374     EVT_RADIOBUTTON( EncapRadio8_Event, wizEncapPage::OnEncapChange)
375     EVT_RADIOBUTTON( EncapRadio9_Event, wizEncapPage::OnEncapChange)
376     EVT_RADIOBUTTON( EncapRadio10_Event, wizEncapPage::OnEncapChange)
377 END_EVENT_TABLE()
378
379 /* Additional settings for transcode */
380 class wizTranscodeExtraPage : public wxWizardPage
381 {
382 public:
383     wizTranscodeExtraPage( wxWizard *parent, wxWizardPage *prev,
384                             wxWizardPage *next);
385     virtual wxWizardPage *GetPrev() const;
386     virtual wxWizardPage *GetNext() const;
387     void OnWizardPageChanging( wxWizardEvent& event );
388 protected:
389     DECLARE_EVENT_TABLE()
390     void wizTranscodeExtraPage::OnSelectFile(wxCommandEvent&);
391     wxTextCtrl *file_text;
392     WizardDialog *p_parent;
393     wxWizardPage *p_prev;
394     wxWizardPage *p_next;
395 };
396
397 BEGIN_EVENT_TABLE(wizTranscodeExtraPage, wxWizardPage)
398     EVT_BUTTON( Open_Event, wizTranscodeExtraPage::OnSelectFile)
399     EVT_WIZARD_PAGE_CHANGING(-1, wizTranscodeExtraPage::OnWizardPageChanging)
400 END_EVENT_TABLE()
401
402 /* Additional settings for streaming */
403 class wizStreamingExtraPage : public wxWizardPage
404 {
405 public:
406     wizStreamingExtraPage( wxWizard *parent, wxWizardPage *prev,
407                             wxWizardPage *next);
408     virtual wxWizardPage *GetPrev() const;
409     virtual wxWizardPage *GetNext() const;
410     void OnWizardPageChanging(wxWizardEvent&);
411     void OnSAP( wxCommandEvent&);
412     wxCheckBox *sap_checkbox;
413     wxTextCtrl *sap_text;
414 protected:
415     friend class wizEncapPage;
416     DECLARE_EVENT_TABLE()
417     WizardDialog *p_parent;
418     wxWizardPage *p_prev;
419     wxWizardPage *p_next;
420
421     wxSpinCtrl *ttl_spin;
422 };
423
424 BEGIN_EVENT_TABLE(wizStreamingExtraPage, wxWizardPage)
425     EVT_CHECKBOX( SAP_Event, wizStreamingExtraPage::OnSAP )
426     EVT_WIZARD_PAGE_CHANGING(-1, wizStreamingExtraPage::OnWizardPageChanging)
427 END_EVENT_TABLE()
428
429
430 /* Local functions */
431 static void pageHeader( wxWindow *window, wxBoxSizer *sizer,
432                        char *psz_title, char *psz_text);
433
434 static void pageHeader( wxWindow *window, wxBoxSizer *sizer,
435                         char *psz_title, char *psz_text)
436 {
437     wxStaticText *wtitle = new wxStaticText( window, -1, wxU( psz_title ) );
438     wxFont font = wtitle->GetFont();
439     font.SetPointSize(14);
440     wtitle->SetFont(font);
441     sizer->Add( wtitle, 0, wxALL, 5 );
442     sizer->Add( new wxStaticText( window, -1,
443                 wxU( vlc_wraptext( psz_text , TEXTWIDTH ) ) ),
444                         0, wxALL, 5 );
445 }
446
447 /***************************************************************************
448  * Implementation of the pages
449  ***************************************************************************/
450
451
452 /***************************************************
453  * First page: choose between stream and transcode *
454  ***************************************************/
455 wizHelloPage::wizHelloPage( wxWizard *parent) : wxWizardPageSimple(parent)
456 {
457         i_action = 0;
458         p_parent = (WizardDialog *)parent;
459         wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
460
461         /* Create the texts */
462         pageHeader( this, mainSizer, HELLO_TITLE, HELLO_TEXT );
463
464         /* Create the radio buttons with their helps */
465         action_radios[0] = new wxRadioButton( this, ActionRadio0_Event,
466                                               wxU( HELLO_STREAMING ) );
467         action_radios[1] = new wxRadioButton( this, ActionRadio1_Event,
468                                               wxU( HELLO_TRANSCODE ) );
469         i_action = 0;
470
471         mainSizer->Add( 0, 0, 1 );
472
473         wxBoxSizer *stream_sizer = new wxBoxSizer( wxHORIZONTAL );
474         stream_sizer->Add( action_radios[0], 0, wxALL, 5 );
475         stream_sizer->Add( 0,0,1 );
476         stream_sizer->Add( new wxButton( this, MoreInfoStreaming_Event,
477                                 wxU( _("More Info")) ), 0, 0, 0 );
478         mainSizer->Add( stream_sizer, 0, wxALL | wxEXPAND , 5 );
479
480         wxBoxSizer *transcode_sizer = new wxBoxSizer( wxHORIZONTAL );
481         transcode_sizer->Add( action_radios[1], 0, wxALL, 5 );
482         transcode_sizer->Add( 0,0,1);
483         transcode_sizer->Add( new wxButton( this, MoreInfoTranscode_Event,
484                                 wxU( _("More Info")) ), 0 ,  0 , 0 );
485         mainSizer->Add( transcode_sizer, 0, wxALL | wxEXPAND, 5 );
486
487         mainSizer->Add( 0, 0, 1 );
488
489         mainSizer->Add( new wxStaticLine(this, -1 ), 0, wxEXPAND| wxTOP|
490                         wxBOTTOM, 5 );
491
492         mainSizer->Add( new wxStaticText(this, -1,
493                         wxU( vlc_wraptext(HELLO_NOTICE , TEXTWIDTH ))),
494                         0, wxALL, 5 );
495
496         SetSizer(mainSizer);
497         mainSizer->Fit(this);
498     }
499
500 void wizHelloPage::OnMoreInfo(wxCommandEvent& event)
501 {
502     wxString msg;
503     msg.Printf( wxString( wxU( event.GetId() == MoreInfoStreaming_Event ?
504                                     MOREINFO_STREAM :
505                                     MOREINFO_TRANSCODE ) ) );
506     wxMessageBox( msg, wxU(_("More information")),
507                   wxOK | wxICON_INFORMATION, this->p_parent );
508 }
509
510 void wizHelloPage::OnActionChange( wxCommandEvent& event )
511 {
512     i_action = event.GetId() - ActionRadio0_Event;
513     ((wizInputPage *)GetNext())->SetAction( i_action );
514     p_parent->SetAction( i_action );
515 }
516
517 void wizHelloPage::OnWizardPageChanging(wxWizardEvent& event)
518 {
519     ((wizInputPage *)GetNext())->SetAction( i_action );
520     p_parent->SetAction( i_action );
521 }
522
523 /************************************
524  * Second page: choose input stream *
525  ************************************/
526 wizInputPage::wizInputPage( wxWizard *parent, wxWizardPage *prev, intf_thread_t *_p_intf) :
527               wxWizardPage(parent)
528 {
529     p_prev = prev;
530     p_intf = _p_intf;
531     p_parent = (WizardDialog *)parent;
532     b_chosen = false;
533     p_open_dialog = NULL;
534     listview = NULL;
535     mrl_text = NULL;
536     mainSizer = new wxBoxSizer(wxVERTICAL);
537
538     /* Create the texts */
539     pageHeader( this, mainSizer, INPUT_TITLE, INPUT_TEXT );
540
541     mainSizer->Add( 0,20,0 );
542
543     radio_panel = new wxPanel(this, -1);
544     radio_panel->SetAutoLayout( TRUE );
545
546     wxBoxSizer *radioSizer = new wxBoxSizer(wxVERTICAL);
547
548     /* Create the radio buttons */
549     input_radios[0] = new wxRadioButton( radio_panel, InputRadio0_Event ,
550                                wxU( INPUT_OPEN ) );
551     radioSizer->Add( input_radios[0], 0, wxALL, 5 );
552     input_radios[1] = new wxRadioButton( radio_panel, InputRadio1_Event ,
553                                wxU( INPUT_PL ) );  
554     radioSizer->Add( input_radios[1], 0, wxALL, 5 );
555
556     radio_panel->SetSizer( radioSizer );
557     radioSizer->Layout();
558     radioSizer->Fit(radio_panel);
559     mainSizer->Add( radio_panel );
560
561     i_input = 0;
562
563     /* Open Panel */
564     open_panel = new wxPanel(this, -1);
565     open_panel->SetAutoLayout( TRUE );
566
567     wxBoxSizer *openSizer = new wxBoxSizer(wxHORIZONTAL);
568
569     mrl_text = new wxTextCtrl( open_panel, -1, wxU( "" ), wxDefaultPosition,
570                               wxSize(200,25) );
571
572     openSizer->Add( mrl_text, 0 , wxALL, 5 );
573     openSizer->Add( new wxButton( open_panel, Choose_Event, wxU(_("Choose...")) ), 0, wxALL, 5 );
574
575     open_panel->SetSizer( openSizer );
576     openSizer->Layout();
577     openSizer->Fit(open_panel);
578     mainSizer->Add( open_panel );
579
580     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
581                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
582
583     if( p_playlist )
584     {
585         if( p_playlist->i_size > 0)
586         {
587             listview = new wxListView( this, ListView_Event,
588                                        wxDefaultPosition, wxDefaultSize,
589                                        wxLC_REPORT | wxSUNKEN_BORDER );
590             listview->InsertColumn( 0, wxU(_("Name")) );
591             listview->InsertColumn( 1, wxU(_("URI")) );
592             listview->SetColumnWidth( 0, 250 );
593             listview->SetColumnWidth( 1, 100 );
594 #if 0
595             for( int i=0 ; i < p_playlist->i_size ; i++ )
596             {
597                 wxString filename = wxL2U( p_playlist->pp_items[i]->input.
598                                                                     psz_name );
599                 listview->InsertItem( i, filename );
600                 listview->SetItem( i, 1, wxL2U( p_playlist->pp_items[i]->
601                                                             input.psz_uri) );
602                 listview->SetItemData( i,
603                                   (long)p_playlist->pp_items[i]->input.i_id );
604             }
605             listview->Select( p_playlist->i_index , TRUE);
606 #endif
607             mainSizer->Add( listview, 1, wxALL|wxEXPAND, 5 );
608
609             listview->Hide();
610             mainSizer->Hide( listview );
611             mainSizer->Layout();
612         }
613         else
614         {
615             input_radios[1]->Disable();
616         }
617         vlc_object_release( p_playlist );
618     }
619     else
620     {
621         input_radios[1]->Disable();
622     }
623
624     /* Partial Extract Box */
625     mainSizer->Add( 0, 10, 0 );
626     wxStaticBox *partial_box = new wxStaticBox( this, -1,
627                     wxU(_("Partial Extract")) );
628
629     wxStaticBoxSizer *partial_sizer = new wxStaticBoxSizer( partial_box,
630                                                           wxVERTICAL );
631
632     enable_checkbox = new wxCheckBox( this, PartialEnable_Event,
633                                                 wxU(_("Enable") ) );
634     enable_checkbox->SetToolTip(wxU(_(PARTIAL) ) ) ;
635     partial_sizer->Add( enable_checkbox, 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 ); //wxLEFT
636
637     wxFlexGridSizer *partial_sizer2 = new wxFlexGridSizer( 4 , 1 , 20 );
638     partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "From" ) ) ),
639                          0 , wxLEFT , 5 );
640     from_text = new wxTextCtrl( this, -1, wxT(""),
641                                 wxDefaultPosition, wxSize( 80,25 ) );
642     partial_sizer2->Add( from_text, 0 , wxALIGN_RIGHT);
643     partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "To" ) ) ),
644                          0 , wxLEFT , 5 );
645     to_text = new wxTextCtrl( this, -1, wxT(""),
646                                   wxDefaultPosition, wxSize( 80 , 25 ) );
647     partial_sizer2->Add( to_text, 0 , wxALIGN_RIGHT );
648
649     partial_sizer->Add( partial_sizer2, 0, wxALL, 0 );
650
651     partial_sizer->Fit( partial_box );
652
653     mainSizer->Add( partial_sizer, 0, 0, 0 );
654
655     from_text->Disable();
656     to_text->Disable();
657     SetSizer(mainSizer);
658     mainSizer->Fit(this);
659     mainSizer->Layout();
660 }
661
662 wizInputPage::~wizInputPage()
663 {
664 }
665
666 void wizInputPage::OnInputChange( wxCommandEvent& event )
667 {
668     i_input = event.GetId() - InputRadio0_Event;
669     if( i_input == 0 )
670     {
671         if( listview )
672         {
673             listview->Hide();
674             mainSizer->Hide( listview );
675             open_panel->Show();
676             mainSizer->Show( open_panel );
677             mainSizer->Layout();
678         }
679     }
680     else
681     {
682         open_panel->Hide();
683         mainSizer->Hide( open_panel );
684         listview->Show();
685         mainSizer->Show( listview );
686         mainSizer->Layout();
687     }
688 }
689
690 void wizInputPage::OnEnablePartial(wxCommandEvent& event)
691 {
692    from_text->Enable( event.IsChecked() );
693    to_text->Enable( event.IsChecked() );
694 }
695
696
697 void wizInputPage::OnChoose(wxCommandEvent& event)
698 {
699     p_open_dialog = new OpenDialog( p_intf, this, -1, -1, OPEN_STREAM );
700     if(  p_open_dialog->ShowModal() == wxID_OK &&
701          !p_open_dialog->mrl.IsEmpty() )
702     {
703         mrl_text->SetValue(p_open_dialog->mrl[0] );
704     }
705     delete p_open_dialog;
706     p_open_dialog = NULL;
707 }
708
709 void wizInputPage::OnWizardPageChanging(wxWizardEvent& event)
710 {
711     if( i_input == 0)
712     {
713         if( mrl_text->GetValue().IsSameAs( wxT(""), TRUE ) &&
714                         event.GetDirection() )
715         {
716             wxMessageBox( wxU( CHOOSE_STREAM ), wxU( ERROR_MSG ),
717                           wxICON_WARNING | wxOK, this->p_parent );
718             event.Veto();
719             return;
720         }
721         else
722         {
723             p_parent->SetMrl( (const char *)mrl_text->GetValue().mb_str() );
724         }
725     }
726     else
727     {
728         int i = -1;
729         i = listview->GetNextItem( i , wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
730         if( i != -1 )
731         {
732             long data = listview->GetItemData( i );
733             playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
734                                       VLC_OBJECT_PLAYLIST, FIND_ANYWHERE);
735             if( p_playlist )
736             {
737                 playlist_item_t * p_item = playlist_LockItemGetById(
738                                                    p_playlist, (int)data );
739                 if( p_item )
740                 {
741                     p_parent->SetMrl( (const char*)p_item->p_input->psz_uri );
742                 }
743                 else
744                     event.Veto();
745             }
746             else
747                 event.Veto();
748         }
749     }
750     if( enable_checkbox->IsChecked() )
751     {
752         int i_from = atoi( from_text->GetValue().mb_str() );
753         int i_to = atoi( to_text->GetValue().mb_str() );
754         p_parent->SetPartial( i_from, i_to );
755     }
756     return;
757 }
758
759 wxWizardPage *wizInputPage::GetPrev() const { return p_prev; }
760 wxWizardPage *wizInputPage::GetNext() const
761 {
762     if( i_action == ACTION_STREAM )
763         return p_streaming_page;
764     else
765        return p_transcode_page;
766 }
767
768 void wizInputPage::SetStreamingPage( wxWizardPage *page)
769 {
770     p_streaming_page = page;
771 }
772
773 void wizInputPage::SetTranscodePage( wxWizardPage *page)
774 {
775     p_transcode_page = page;
776 }
777
778 void wizInputPage::SetAction( int i_action )
779 {
780     this->i_action = i_action;
781 }
782
783 void wizInputPage::SetPintf( intf_thread_t *p_intf )
784 {
785     this->p_intf = p_intf;
786 }
787
788 void wizInputPage::SetUri( char *psz_uri )
789 {
790     mrl_text->SetValue( wxU( psz_uri ) );
791 }
792
793 void wizInputPage::SetPartial( int i_from, int i_to )
794 {
795    wxString msg;
796    msg.Printf( wxString( wxT( "%i") ), i_from );
797    from_text->Enable( TRUE );
798    from_text->SetValue( msg );
799    msg.Printf( wxString( wxT( "%i") ), i_to );
800    to_text->Enable( TRUE );
801    to_text->SetValue( msg );
802    enable_checkbox->SetValue( TRUE );
803 }
804
805 /***************************************************
806  * First transcode page: choose codecs             *
807  ***************************************************/
808 wizTranscodeCodecPage::wizTranscodeCodecPage( wxWizard *parent,
809                        wxWizardPage *next) : wxWizardPage(parent)
810 {
811     int i;
812
813     p_next = next;
814
815     acodec = NULL;
816     vcodec = NULL;
817     p_parent = (WizardDialog *) parent;
818
819     wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
820
821     /* Header */
822     pageHeader( this, main_sizer,  TRANSCODE1_TITLE, TRANSCODE1_TEXT );
823
824     /* Video Box */
825     wxStaticBox *video_box = new wxStaticBox( this, -1, wxU(_("Video")) );
826     wxStaticBoxSizer *video_sizer = new wxStaticBoxSizer( video_box,
827                                                           wxVERTICAL );
828     /* Line 1 : only the checkbox */
829     wxFlexGridSizer *video_sizer1 = new wxFlexGridSizer( 2,3,20 );
830     video_sizer1->Add( new wxCheckBox( this, VideoEnable_Event,
831                        wxU(_("Transcode video") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL , 5 );
832     video_sizer1->Add( 0,0,1);
833     /* Line 2 : codec */
834     video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT ,5);
835     video_combo = new wxComboBox( this, VideoCodec_Event, wxT(""),
836                                   wxDefaultPosition, wxSize(200,25), 0, NULL, 
837                                   wxCB_DROPDOWN| wxCB_READONLY );
838     for( i= 0; vcodecs_array[i].psz_display != NULL; i++ )
839     {
840         video_combo->Append( wxU( vcodecs_array[i].psz_display ) ,
841                             (void *)&vcodecs_array[i] );
842     }
843     i_video_codec = 0;
844     video_combo->SetSelection(0);
845
846     video_sizer1->Add( video_combo, 0 , wxALIGN_LEFT , 0 );
847
848     video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
849                        wxLEFT ,5);
850     vb_combo = new wxComboBox( this, VideoBitrate_Event, wxT("1024"),
851                                wxDefaultPosition, wxDefaultSize,
852                                WXSIZEOF(vbitrates_array), vbitrates_array, wxCB_READONLY );
853     video_sizer1->Add( vb_combo, 0, wxALIGN_LEFT , 0 );
854
855     /* Line 3 : text */
856     video_text = new wxStaticText( this, -1,
857                      wxU( vlc_wraptext( TR_VIDEO_TEXT, TEXTWIDTH ) ) );
858     /* Fill the main video sizer */
859     video_sizer->Add( video_sizer1 , 0, wxEXPAND , 5 );
860     video_sizer->Add( video_text, 0, wxLEFT|wxTOP , 5 );
861
862
863     /* Audio box */
864     wxStaticBox *audio_box = new wxStaticBox( this, -1, wxU(_("Audio")) );
865     wxStaticBoxSizer *audio_sizer = new wxStaticBoxSizer( audio_box,
866                                                           wxVERTICAL );
867     /* Line1: enabler */
868     wxFlexGridSizer *audio_sizer1 = new wxFlexGridSizer( 2,3,20);
869     audio_sizer1->Add( new wxCheckBox( this, AudioEnable_Event,
870                             wxU(_("Transcode audio") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 );
871     audio_sizer1->Add( 0, 0, 1 );
872
873     /* Line 2 : codec */
874     audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT,5);
875     audio_combo = new wxComboBox( this, AudioCodec_Event, wxT(""),
876                                   wxDefaultPosition, wxSize(200,25), 0, NULL, 
877                                   wxCB_DROPDOWN| wxCB_READONLY );
878     for( i= 0; acodecs_array[i].psz_display != NULL; i++ )
879     {
880         audio_combo->Append( wxU( acodecs_array[i].psz_display ) ,
881                             (void *)&acodecs_array[i] );
882     }
883     i_audio_codec = 0;
884     audio_combo->SetSelection(0);
885     audio_sizer1->Add( audio_combo, 0 , wxALIGN_LEFT, 0 );
886
887     audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
888                        wxLEFT ,5);
889     ab_combo = new wxComboBox( this, AudioBitrate_Event, wxT("192"),
890                                wxDefaultPosition, wxDefaultSize,
891                                WXSIZEOF(abitrates_array), abitrates_array, wxCB_READONLY );
892     audio_sizer1->Add( ab_combo, 0, wxALIGN_LEFT, 0 );
893
894     /* Line 3 : text */
895     audio_text = new wxStaticText( this, -1,
896                      wxU( vlc_wraptext( TR_AUDIO_TEXT, TEXTWIDTH ) ) );
897
898     audio_sizer->Add(audio_sizer1, 0, wxEXPAND, 5);
899     audio_sizer->Add( audio_text, 0, wxLEFT | wxTOP, 5 );
900
901     main_sizer->Add( video_sizer, 1, wxGROW, 0 );
902     main_sizer->Add( audio_sizer, 1, wxGROW, 0 );
903     main_sizer->Layout();
904     SetSizerAndFit( main_sizer );
905
906     /* Default disabled */
907     video_combo->Disable(); video_text->Disable();vb_combo->Disable();
908     audio_combo->Disable(); audio_text->Disable();ab_combo->Disable();
909
910 }
911
912 wizTranscodeCodecPage::~wizTranscodeCodecPage()
913 {
914     if( acodec ) free( acodec );
915     if( vcodec ) free( vcodec );
916 }
917
918 void wizTranscodeCodecPage::OnEnableVideo(wxCommandEvent& event)
919 {
920    video_combo->Enable( event.IsChecked() );
921    vb_combo->Enable( event.IsChecked() );
922    video_text->Enable( event.IsChecked() );
923 }
924
925 void wizTranscodeCodecPage::OnEnableAudio(wxCommandEvent& event)
926 {
927    audio_combo->Enable( event.IsChecked() );
928    ab_combo->Enable( event.IsChecked() );
929    audio_text->Enable( event.IsChecked() );
930 }
931
932 void wizTranscodeCodecPage::OnVideoCodecChange(wxCommandEvent& event)
933 {
934     struct codec *c = (struct codec*)
935              (video_combo->GetClientData(video_combo->GetSelection()));
936     video_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH ) ) );
937     i_video_codec = video_combo->GetSelection();
938     vcodec = strdup(c->psz_codec);
939 }
940
941 void wizTranscodeCodecPage::OnAudioCodecChange(wxCommandEvent& event)
942 {
943     struct codec *c = (struct codec*)
944              (audio_combo->GetClientData(audio_combo->GetSelection()));
945     audio_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH ) ) );
946     i_audio_codec = audio_combo->GetSelection();
947     acodec = strdup(c->psz_codec);
948
949 }
950
951 void wizTranscodeCodecPage::OnWizardPageChanging(wxWizardEvent& event)
952 {
953     unsigned int i,j;
954
955     if( !event.GetDirection() )
956     {
957             GetPrev()->Enable();
958             return;
959     }
960
961     /* Set the dummy codec ( accept all muxers ) if needed */
962     if( !video_combo->IsEnabled() )
963     {
964         i_video_codec = VCODECS_NUMBER;
965     }
966     if( !audio_combo->IsEnabled() )
967     {
968         i_audio_codec = ACODECS_NUMBER;
969     }
970
971     ((wizEncapPage *)GetNext())->SetPrev(this);
972
973     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
974     {
975         if( vcodecs_array[i_video_codec].muxers[i] != -1 )
976         {
977             for( j = 0 ; j<  MUXERS_NUMBER ; j++ )
978             {
979                 if( acodecs_array[i_audio_codec].muxers[j] ==
980                               vcodecs_array[i_video_codec].muxers[i] )
981                 {
982                     ((wizEncapPage*)GetNext())->EnableEncap(
983                                vcodecs_array[i_video_codec].muxers[i] );
984                 }
985             }
986         }
987     }
988     struct codec *c = (struct codec*)
989              (video_combo->GetClientData( video_combo->IsEnabled() ?
990                                           video_combo->GetSelection(): i_video_codec ));
991     vcodec = strdup(c->psz_codec);
992     c = (struct codec*)
993            (audio_combo->GetClientData( audio_combo->IsEnabled() ?
994                                        audio_combo->GetSelection() : i_audio_codec ));
995     acodec = strdup(c->psz_codec);
996
997     int vb = atoi(vb_combo->GetValue().mb_str() );
998     if( vb == 0 )
999     {
1000          vb = 1024;
1001     }
1002     int ab = atoi(ab_combo->GetValue().mb_str() );
1003     if( ab == 0)
1004     {
1005         ab = 192;
1006     }
1007
1008     p_parent->SetTranscode( vcodec, vb , acodec, ab );
1009     ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
1010     p_parent->SetAction( p_parent->GetAction() );
1011
1012     return;
1013 }
1014
1015 wxWizardPage *wizTranscodeCodecPage::GetPrev() const { return p_prev; }
1016 wxWizardPage *wizTranscodeCodecPage::GetNext() const { return p_next; }
1017 void wizTranscodeCodecPage::SetPrev( wxWizardPage *page) {p_prev = page; }
1018
1019
1020 /***************************************************
1021  * First streaming page: choose method             *
1022  ***************************************************/
1023 wizStreamingMethodPage::wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
1024     wxWizardPage *next) : wxWizardPage(parent), p_intf( p_this )
1025 {
1026     int i;
1027     p_next = next;
1028     p_parent = (WizardDialog *)parent;
1029
1030     mainSizer = new wxBoxSizer(wxVERTICAL);
1031
1032     /* Create the texts */
1033     pageHeader( this, mainSizer,  STREAMING1_TITLE, STREAMING1_TEXT );
1034
1035     mainSizer->Add( 0,50,0 );
1036
1037     i_method = 0;
1038
1039     wxStaticBox *method_box = new wxStaticBox( this, -1,
1040                                                wxU(_("Streaming method")) );
1041     wxStaticBoxSizer *method_sizer = new wxStaticBoxSizer(method_box,
1042                                                           wxHORIZONTAL );
1043     for( i = 0 ; i< 3 ; i++ )
1044     {
1045         method_radios[i] = new wxRadioButton( this, MethodRadio0_Event + i,
1046                                wxU( methods_array[i].psz_method ) );
1047         method_radios[i]->SetToolTip( wxU(_( methods_array[i].psz_descr ) ) );
1048         method_sizer->Add( method_radios[i], 0, wxALL, 5 );
1049     }
1050
1051     method_sizer->Layout();
1052
1053     wxStaticBox *address_box = new wxStaticBox( this, -1,
1054                     wxU(_("Destination")) );
1055
1056     address_sizer = new wxStaticBoxSizer(address_box,
1057                                          wxVERTICAL );
1058
1059     /* Big kludge, we take the longest text to get the size */
1060     address_text = new wxStaticText(this, -1,
1061                wxU( vlc_wraptext(methods_array[2].psz_address, TEXTWIDTH ) ),
1062                wxDefaultPosition, wxDefaultSize );
1063
1064     address_txtctrl = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
1065                                       wxSize(200,25));
1066     address_sizer->Add( address_text, 0, wxALL, 5 );
1067     address_sizer->Add( address_txtctrl, 0, wxALL, 5 );
1068     address_sizer->Layout();
1069
1070     /* Set the minimum size */
1071     address_sizer->SetMinSize( address_sizer->GetSize() );
1072     address_text->SetLabel( wxU(
1073      vlc_wraptext( _(methods_array[0].psz_address), TEXTWIDTH )));
1074
1075     mainSizer->Add( method_sizer, 0, wxALL | wxEXPAND, 5 );
1076     mainSizer->Add( address_sizer, 0, wxALL | wxEXPAND, 5 );
1077
1078     mainSizer->Add( 0,0,1 );
1079
1080     mainSizer->Layout();
1081
1082     SetSizer(mainSizer);
1083     mainSizer->Fit(this);
1084
1085     return;
1086 }
1087
1088 void wizStreamingMethodPage::OnWizardPageChanging(wxWizardEvent& event)
1089 {
1090     unsigned int i;
1091     if( !event.GetDirection() ) return;
1092
1093     /* Check valid address */
1094     if( i_method == 1
1095      && !net_AddressIsMulticast( (vlc_object_t *)p_intf,
1096                                  address_txtctrl->GetValue().mb_str()) )
1097     {
1098         wxMessageBox( wxU( INVALID_MCAST_ADDRESS ) , wxU( ERROR_MSG ),
1099                       wxICON_WARNING | wxOK, this->p_parent );
1100         event.Veto();
1101
1102     }
1103     else if( i_method == 0 && address_txtctrl->GetValue().IsEmpty() )
1104     {
1105         wxMessageBox( wxU( NO_ADDRESS_TEXT ) , wxU( ERROR_MSG ),
1106                       wxICON_WARNING | wxOK, this->p_parent );
1107         event.Veto();
1108
1109     }
1110
1111     ((wizEncapPage *)GetNext())->SetPrev(this);
1112     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
1113     {
1114         if( methods_array[i_method].muxers[i] != -1 )
1115         {
1116             ((wizEncapPage*)GetNext())->EnableEncap(
1117                                methods_array[i_method].muxers[i] );
1118         }
1119     }
1120     p_parent->SetStream( methods_array[i_method].psz_access ,
1121                          address_txtctrl->GetValue().mb_str() );
1122
1123     /* Set the action for the muxer page */
1124     ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
1125     return;
1126 }
1127
1128 wxWizardPage *wizStreamingMethodPage::GetPrev() const { return p_prev; }
1129 wxWizardPage *wizStreamingMethodPage::GetNext() const { return p_next; }
1130
1131 void wizStreamingMethodPage::SetPrev( wxWizardPage *page) {p_prev = page; }
1132
1133
1134 void wizStreamingMethodPage::OnMethodChange( wxCommandEvent& event )
1135 {
1136     i_method = event.GetId() - MethodRadio0_Event;
1137     address_text->SetLabel( wxU(
1138      vlc_wraptext( _(methods_array[i_method].psz_address), TEXTWIDTH )));
1139     address_sizer->Layout();
1140     mainSizer->Layout();
1141 }
1142
1143 /***************************************************
1144  * Choose encapsulation format                     *
1145  ***************************************************/
1146 wizEncapPage::wizEncapPage( wxWizard *parent ) : wxWizardPage(parent)
1147 {
1148     int i;
1149     i_mux = 0;
1150     p_parent = (WizardDialog *)parent;
1151     p_streaming_page = NULL;
1152     p_transcode_page = NULL;
1153     p_prev = NULL;
1154     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1155
1156     /* Create the texts */
1157     pageHeader( this, mainSizer, ENCAP_TITLE, ENCAP_TEXT );
1158
1159     mainSizer->Add( 0,0,1 );
1160
1161     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
1162     {
1163         encap_radios[i] = new wxRadioButton( this, EncapRadio0_Event + i,
1164                                wxU( encaps_array[i].psz_encap ) );
1165         encap_radios[i]->SetToolTip( wxU(_( encaps_array[i].psz_descr ) ) );
1166         mainSizer->Add( encap_radios[i], 0, wxLEFT, 5 );
1167         encap_radios[i]->Disable();
1168     }
1169
1170     mainSizer->Add( 0,0,1 );
1171
1172     SetSizer(mainSizer);
1173     mainSizer->Fit(this);
1174 }
1175
1176 wizEncapPage::~wizEncapPage()
1177 {
1178 }
1179
1180 void wizEncapPage::OnWizardPageChanging(wxWizardEvent& event)
1181 {
1182     int i;
1183     if( !event.GetDirection() )
1184     {
1185         for( i = 0 ; i< MUXERS_NUMBER ; i++ )
1186         {
1187             encap_radios[i]->Disable();
1188         }
1189     }
1190     p_parent->SetMux( encaps_array[i_mux].psz_mux );
1191
1192     if( p_parent->GetAction() == ACTION_STREAM )
1193     {
1194         if( strstr( p_parent->method, "rtp" ))
1195         {
1196             ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable();
1197             ((wizStreamingExtraPage *)GetNext())->sap_text->Enable(false);
1198         }
1199         else
1200         {
1201            ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable( false );
1202            ((wizStreamingExtraPage *)GetNext())->sap_text->Enable( false );
1203         }
1204     }
1205
1206     return;
1207 }
1208
1209
1210 void wizEncapPage::OnEncapChange( wxCommandEvent& event )
1211 {
1212     i_mux = event.GetId() - EncapRadio0_Event;
1213 }
1214
1215 void wizEncapPage::EnableEncap( int encap )
1216 {
1217     int i;
1218     for( i = 0 ; i< MUXERS_NUMBER ; i++)
1219     {
1220         if( encaps_array[i].id == encap )
1221         {
1222             encap_radios[i]->Enable();
1223             encap_radios[i]->SetValue(true);
1224             i_mux = i;
1225         }
1226     }
1227 }
1228
1229 void wizEncapPage::SetStreamingPage( wxWizardPage *page)
1230 {
1231     p_streaming_page = page;
1232 }
1233
1234 void wizEncapPage::SetTranscodePage( wxWizardPage *page)
1235 {
1236     p_transcode_page = page;
1237 }
1238
1239 wxWizardPage *wizEncapPage::GetPrev() const { return p_prev; }
1240
1241 wxWizardPage *wizEncapPage::GetNext() const
1242 {
1243     if( i_action== ACTION_STREAM )
1244         return p_streaming_page;
1245     else
1246        return p_transcode_page;
1247 }
1248
1249 void wizEncapPage::SetAction( int i_act  ) { i_action = i_act; }
1250
1251 void wizEncapPage::SetPrev( wxWizardPage *page) { p_prev = page; }
1252
1253 /***************************************************
1254  * Extra transcoding page : Select file            *
1255  ***************************************************/
1256 wizTranscodeExtraPage::wizTranscodeExtraPage( wxWizard *parent,
1257                        wxWizardPage *prev,
1258                        wxWizardPage *next) : wxWizardPage(parent)
1259 {
1260     p_next = next;
1261     p_prev = prev;
1262     p_parent = (WizardDialog *) parent;
1263     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1264
1265     /* Create the texts */
1266     pageHeader( this, mainSizer, EXTRATRANSCODE_TITLE, EXTRATRANSCODE_TEXT );
1267
1268     mainSizer->Add( 0, 0, 1 );
1269
1270     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 2, 1 );
1271     sizer->Add( new wxStaticText( this, -1,
1272                     wxU(_("Select the file to save to") ) ),
1273                     0, wxALL, 5 );
1274     sizer->Add( 0, 0, 1 );
1275
1276     file_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
1277                                 wxSize( 150, -1 ) );
1278
1279     sizer->Add( file_text, 0,  wxALL, 5 );
1280     sizer->Add( new wxButton( this, Open_Event, wxU("Choose") ) );
1281
1282     mainSizer->Add( sizer, 0, 0, 0) ;
1283
1284     mainSizer->Add( 0, 0, 1 );
1285     SetSizer(mainSizer);
1286     mainSizer->Fit(this);
1287 }
1288
1289 void wizTranscodeExtraPage::OnSelectFile( wxCommandEvent &event)
1290 {
1291     wxFileDialog *file_dialog =  new wxFileDialog( this, wxU(_("Save to file")),
1292                    wxT(""), wxT(""), wxT("*"), wxSAVE );
1293
1294     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1295     {
1296         if( file_dialog->GetFilename().mb_str() )
1297         {
1298             file_text->SetValue( file_dialog->GetPath() );
1299         }
1300     }
1301 }
1302
1303 void wizTranscodeExtraPage::OnWizardPageChanging( wxWizardEvent& event )
1304 {
1305     if( event.GetDirection() && file_text->GetValue().IsEmpty() )
1306     {
1307         wxMessageBox( wxU( CHOOSE_OUTFILE ), wxU( ERROR_MSG ),
1308                       wxICON_WARNING | wxOK, this->p_parent );
1309         event.Veto();
1310     }
1311     if( event.GetDirection() )
1312     {
1313        p_parent->SetTranscodeOut( file_text->GetValue().mb_str());
1314     }
1315 }
1316
1317 wxWizardPage *wizTranscodeExtraPage::GetPrev() const { return p_prev; }
1318 wxWizardPage *wizTranscodeExtraPage::GetNext() const {return p_next; }
1319
1320 /***********************************************************
1321  *  Extra streaming page
1322  ***********************************************************/
1323 wizStreamingExtraPage::wizStreamingExtraPage( wxWizard *parent,
1324                        wxWizardPage *prev,
1325                        wxWizardPage *next) : wxWizardPage(parent)
1326 {
1327     p_next = next;
1328     p_prev = prev;
1329     p_parent = (WizardDialog *) parent;
1330     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1331
1332     /* Create the texts */
1333     pageHeader( this, mainSizer, EXTRASTREAMING_TITLE, EXTRASTREAMING_TEXT );
1334
1335     mainSizer->Add( 0, 0, 1 );
1336
1337     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2,2,1) ;
1338
1339     /* TTL */
1340     sizer->Add( new wxStaticText( this, -1, wxU(_("Time-To-Live (TTL)"))),
1341                     0, wxALL,  5 );
1342     ttl_spin = new wxSpinCtrl( this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
1343                     0, 1, 255, 1 );
1344     ttl_spin->SetToolTip(wxU(_(TTL) ) ) ;
1345     sizer->Add( ttl_spin, 0, wxALL , 5 );
1346
1347     /* SAP announce */
1348     sap_checkbox =  new wxCheckBox( this, SAP_Event, wxU(_("SAP Announce")) );
1349     sap_checkbox->SetToolTip( wxU(_( SAP ) ) );
1350     sizer->Add( sap_checkbox, 0, 0 , 0 );
1351     sap_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
1352                     wxSize(100,25) );
1353     sap_text->SetToolTip( wxU(_( SAP ) ) );
1354     sizer->Add( sap_text, 0, wxALL , 5 );
1355
1356     mainSizer->Add(sizer, 0, wxALL, 5 );
1357
1358     mainSizer->Add( 0, 0, 1 );
1359
1360     SetSizer(mainSizer);
1361     mainSizer->Fit(this);
1362 }
1363
1364 void wizStreamingExtraPage::OnSAP( wxCommandEvent &event )
1365 {
1366     sap_text->Enable( event.IsChecked() );
1367 }
1368
1369 void wizStreamingExtraPage::OnWizardPageChanging(wxWizardEvent& event)
1370 {
1371     if( sap_checkbox->IsChecked() )
1372     {
1373         if( sap_text->GetValue().IsEmpty() )
1374         {
1375             p_parent->SetSAP( true, NULL );
1376         }
1377         else
1378         {
1379             p_parent->SetSAP( true,
1380                              (const char *)sap_text->GetValue().mb_str() );
1381         }
1382     }
1383     else
1384     {
1385         p_parent->SetSAP( false, NULL );
1386     }
1387
1388     p_parent->SetTTL( ttl_spin->GetValue() );
1389 }
1390
1391 wxWizardPage *wizStreamingExtraPage::GetPrev() const { return p_prev; }
1392 wxWizardPage *wizStreamingExtraPage::GetNext() const {return p_next; }
1393
1394
1395 /***************************************************************************
1396  * Implementation of the wizard itself
1397  ***************************************************************************/
1398 wizHelloPage *page1;
1399 wizInputPage *page2 ;
1400 wizTranscodeCodecPage *tr_page1 ;
1401 wizStreamingMethodPage *st_page1;
1402 wizTranscodeExtraPage *tr_page2 ;
1403 wizStreamingExtraPage *st_page2;
1404 wizEncapPage *encap_page;
1405
1406 WizardDialog::WizardDialog(intf_thread_t *_p_intf, wxWindow *_p_parent,
1407                            char *psz_uri, int _i_from, int _i_to  ) :
1408 wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, wxDefaultPosition)
1409 {
1410     /* Initializations */
1411     p_intf = _p_intf;
1412     SetPageSize(wxSize(400,420));
1413
1414     /* Initialize structure */
1415     i_action = 0;
1416     i_from = _i_from;
1417     i_to = _i_to;
1418     i_ttl = 1;
1419     vb = 0;
1420     ab = 0;
1421     acodec=NULL;
1422     vcodec=NULL;
1423
1424     page1 = new wizHelloPage(this);
1425     page2 = new wizInputPage(this, page1, p_intf);
1426
1427     if( psz_uri )
1428     {
1429         page2->SetUri( psz_uri );
1430     }
1431     if( i_from != 0 || i_to != 0 )
1432     {
1433         page2->SetPartial( i_from, i_to );
1434     }
1435
1436     encap_page = new wizEncapPage(this );
1437     tr_page1 = new wizTranscodeCodecPage(this, encap_page );
1438     st_page1 = new wizStreamingMethodPage( p_intf, this, encap_page);
1439
1440     tr_page2 = new wizTranscodeExtraPage(this, encap_page, NULL );
1441     st_page2 = new wizStreamingExtraPage(this, encap_page, NULL );
1442
1443     /* Page 1 -> 2 */
1444     page1->SetNext( page2 );
1445     /* 2->1 in constructor of 2 */
1446
1447     /* Page 2 -> 3 */
1448     page2->SetTranscodePage(tr_page1);
1449     page2->SetStreamingPage(st_page1);
1450     page2->SetPintf( p_intf );
1451     tr_page1->SetPrev(page2);
1452     st_page1->SetPrev(page2);
1453
1454     /* Page 3 -> 4 */
1455     encap_page->SetTranscodePage( tr_page2 );
1456     encap_page->SetStreamingPage( st_page2 );
1457     /* 3->4 in constructor of 3 */
1458 //    encap_page->SetPrev(tr_page1);
1459 }
1460
1461 WizardDialog::~WizardDialog()
1462 {
1463     Destroy();
1464     delete page1;
1465     delete page2;
1466     delete tr_page1;
1467     delete st_page1 ;
1468     delete st_page2;
1469     delete tr_page2;
1470     delete encap_page;
1471 }
1472
1473 void WizardDialog::SetMrl( const char *mrl )
1474 {
1475     this->mrl = strdup( mrl );
1476 }
1477
1478 void WizardDialog::SetTTL( int i_ttl )
1479 {
1480     this->i_ttl = i_ttl;
1481 }
1482
1483 void WizardDialog::SetSAP( bool b_enabled, const char *psz_text )
1484 {
1485     this->b_sap = b_enabled;
1486     if( b_enabled )
1487     {
1488         if( psz_text != NULL )
1489         {
1490             this->psz_sap_name = strdup( psz_text );
1491         }
1492         else
1493         {
1494             this->psz_sap_name = NULL;
1495         }
1496     }
1497 }
1498
1499 void WizardDialog::SetPartial( int i_from, int i_to )
1500 {
1501     this->i_from = i_from;
1502     this->i_to = i_to;
1503 }
1504
1505 void WizardDialog::SetTranscode( char const *vcodec, int vb,
1506                                  char const *acodec, int ab)
1507 {
1508     if( strcmp( vcodec, "dummy") )
1509     {
1510         this->vcodec= strdup(vcodec);
1511     }
1512     if( strcmp( acodec, "dummy" ) )
1513     {
1514         this->acodec = strdup(acodec);
1515     }
1516     this->vb = vb;
1517     this->ab = ab;
1518 }
1519
1520 void WizardDialog::SetStream( char const *method, char const *address )
1521 {
1522     this->method = strdup( method );
1523     this->address = strdup( address );
1524 }
1525
1526 void WizardDialog::SetTranscodeOut( char const *address )
1527 {
1528     char *psz_utf8 = FromLocale( address );
1529     this->address = strdup( psz_utf8 );
1530     LocaleFree( psz_utf8 );
1531 }
1532
1533 void WizardDialog::SetMux( char const *mux )
1534 {
1535     this->mux = strdup( mux );
1536 }
1537
1538 void WizardDialog::SetAction( int i_action )
1539 {
1540     this->i_action = i_action;
1541 }
1542
1543 int WizardDialog::GetAction()
1544 {
1545     return i_action;
1546 }
1547
1548 void WizardDialog::Run()
1549 {
1550     if( RunWizard(page1) )
1551     {
1552         char *psz_opt;
1553
1554         if( i_action == ACTION_TRANSCODE )
1555         {
1556             msg_Dbg( p_intf,"starting transcode of %s to file %s",
1557                                   mrl, address);
1558             msg_Dbg( p_intf,"using %s (%i kbps) / %s (%i kbps),encap %s",
1559                                 vcodec,vb,acodec,ab,mux);
1560             char *psz_transcode;
1561
1562             if( vcodec != NULL || acodec != NULL )
1563             {
1564                 int i_tr_size = 14;
1565                 if( vcodec != NULL )
1566                     i_tr_size += strlen( vcodec ) + 17;
1567                 if( acodec != NULL )
1568                     i_tr_size += strlen( acodec ) + 17;
1569
1570                 if( vb > 999999 )
1571                     vb = 999999;
1572                 else if( vb < 0 )
1573                     vb = 0;
1574
1575                 if( ab > 999999 )
1576                     ab = 999999;
1577                 else if( ab < 0 )
1578                     ab = 0;
1579
1580                 psz_transcode = (char *)malloc( i_tr_size * sizeof(char) );
1581
1582                 strcpy( psz_transcode, "transcode{" );
1583                 if( vcodec != NULL )
1584                 {
1585                     sprintf( psz_transcode + strlen( psz_transcode ),
1586                              "vcodec=%s,vb=%i%s", vcodec, vb,
1587                              ( acodec != NULL ) ? "," : "}:" );
1588                 }
1589                 if( acodec != NULL )
1590                 {
1591                     sprintf( psz_transcode + strlen( psz_transcode ),
1592                              "acodec=%s,ab=%i}:", acodec, ab );
1593                 }
1594             }
1595             else
1596                 psz_transcode = "";
1597
1598             asprintf( &psz_opt, ":sout=#%sstandard{mux=%s,dst=%s,"
1599                       "access=file}", psz_transcode, mux, address );
1600
1601             if( *psz_transcode )
1602                 free( psz_transcode );
1603         }
1604         else
1605         {
1606             char *psz_sap_option = NULL;
1607             bool v6;
1608
1609             msg_Dbg( p_intf, "starting stream of %s to %s using %s, encap %s",
1610                                mrl, address, method, mux );
1611             if( b_sap )
1612             {
1613                 if( psz_sap_name )
1614                 {
1615                     asprintf( &psz_sap_option,
1616                               ",sap,name=\"%s\"", psz_sap_name );
1617                 }
1618                 else
1619                     psz_sap_option = strdup( ",sap" );
1620
1621             }
1622
1623             /* Add brackets automatically for IPv6 if they are missing */
1624             v6 = ( address[0] != '[' ) && ( strchr( address, ':' ) != NULL );
1625             asprintf( &psz_opt,
1626                       ":sout=#standard{mux=%s,dst=%s%s%s,access=%s%s}",
1627                       mux, v6 ? "[" : "", address, v6 ? "]" : "", method,
1628                       psz_sap_option ?: "" );
1629             if( psz_sap_option ) free( psz_sap_option );
1630         }
1631
1632         playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
1633                             VLC_OBJECT_PLAYLIST, FIND_ANYWHERE);
1634         if( p_playlist )
1635         {
1636             input_item_t *p_input = input_ItemNew( p_playlist, mrl,
1637                                                    ITEM_NAME );
1638             input_ItemAddOption( p_input, psz_opt );
1639             if( i_from != 0)
1640             {
1641                 char psz_from[20];
1642                 snprintf( psz_from, 20, "start-time=%i", i_from);
1643                 input_ItemAddOption( p_input, psz_from );
1644             }
1645             if( i_to != 0)
1646             {
1647                 char psz_to[20];
1648                 snprintf( psz_to, 20, "stop-time=%i", i_to);
1649                 input_ItemAddOption( p_input, psz_to );
1650             }
1651
1652             char psz_ttl[20];
1653             snprintf( psz_ttl, 20, "ttl=%i",i_ttl );
1654             input_ItemAddOption( p_input, psz_ttl );
1655
1656             playlist_PlaylistAddInput( p_playlist, p_input,
1657                                        PLAYLIST_GO, PLAYLIST_END );
1658             vlc_object_release(p_playlist);
1659         }
1660         else
1661         {
1662             wxMessageBox( wxU( NO_PLAYLIST ), wxU( ERROR_MSG ),
1663                           wxICON_WARNING | wxOK, this );
1664         }
1665     }
1666 }