]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/wizard.cpp
contrib/makefile: add libmpcdec (Musepack) to win contribs
[vlc] / modules / gui / wxwidgets / wizard.cpp
1 /*****************************************************************************
2  * wizard.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 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., 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 #include "network.h"
35
36 #include "wxwidgets.h"
37
38 #include "streamdata.h"
39
40 #include <wx/statline.h>
41
42 class wizHelloPage;
43 class wizInputPage;
44
45 /*****************************************************************************
46  * Define events
47  *****************************************************************************/
48 enum
49 {
50     ActionRadio0_Event, ActionRadio1_Event,
51     MoreInfoStreaming_Event,
52     MoreInfoTranscode_Event,
53
54     Open_Event , Choose_Event ,
55     ListView_Event,
56     InputRadio0_Event, InputRadio1_Event,
57     PartialEnable_Event,
58
59     MethodRadio0_Event, MethodRadio1_Event,
60     MethodRadio2_Event, MethodRadio3_Event,
61
62     EncapRadio0_Event, EncapRadio1_Event,
63     EncapRadio2_Event, EncapRadio3_Event,
64     EncapRadio4_Event, EncapRadio5_Event,
65     EncapRadio6_Event, EncapRadio7_Event,
66     EncapRadio8_Event, EncapRadio9_Event,
67     EncapRadio10_Event, EncapRadio11_Event,
68
69     VideoEnable_Event, VideoCodec_Event,VideoBitrate_Event,
70     AudioEnable_Event, AudioCodec_Event,AudioBitrate_Event,
71
72     SAP_Event,
73
74 };
75
76 #define TEXTWIDTH 55
77 #define ACTION_STREAM 0
78 #define ACTION_TRANSCODE 1
79
80 BEGIN_EVENT_TABLE(WizardDialog, wxWizard)
81 END_EVENT_TABLE()
82
83 /*****************************************************************************
84  * Wizard strings
85  *****************************************************************************/
86
87 #define ERROR_MSG _("Error")
88 #define ITEM_NAME _("Streaming/Transcoding Wizard")
89
90 /* Hello page */
91 #define HELLO_TITLE _("Streaming/Transcoding Wizard")
92 #define HELLO_TEXT _("This wizard helps you to stream, transcode or" \
93                      " save a stream.")
94 #define HELLO_STREAMING _("Stream to network")
95 #define HELLO_STREAMING_DESC _("Use this to stream on a network.")
96 #define HELLO_TRANSCODE _("Transcode/Save to file")
97 #define HELLO_TRANSCODE_DESC _("Use this to re-encode a stream and save it to a file.")
98 #define HELLO_NOTICE _("This wizard only gives access to a small subset of VLC's streaming and transcoding capabilities. Use the Open and Stream Output dialogs to get all of them.")
99
100 #define MOREINFO_STREAM _("Use this to stream on a network")
101
102 #define MOREINFO_TRANSCODE _("Use this to save a stream to a file. You have the possibility to reencode the stream. You can save whatever VLC can read.\nPlease notice that VLC is not very suited " \
103              "for file to file transcoding. You should use its transcoding " \
104              "features to save network streams, for example." )
105
106 /* Input page */
107 #define INPUT_TITLE _("Choose input")
108 #define INPUT_TEXT _("Choose here your input stream.")
109
110 #define INPUT_OPEN _("Select a stream" )
111 #define INPUT_PL _( "Existing playlist item" )
112
113 #define CHOOSE_STREAM _("You must choose a stream")
114 #define NO_PLAYLIST _("Uh Oh! Unable to find playlist !")
115
116 #define PARTIAL _("Use this to read only a part of the stream. " \
117                   "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                   "Enter the starting and ending times (in seconds).")
121
122 #define INPUT_BUTTON _("Choose")
123
124 /* Transcode 1 */
125 #define TRANSCODE1_TITLE _("Transcode")
126 #define TRANSCODE1_TEXT _("If you want to change the compression format of the audio or video tracks, fill in this page. (If you only want to change the container format, proceed to next page.)")
127
128 #define TR_VIDEO_TEXT0 _("If your stream has video and you want to " \
129                          "transcode it, enable this.")
130 #define TR_VIDEO_TEXT _("Select your video codec. Click one to get more " \
131                         "information.")
132
133 #define TR_AUDIO_TEXT0 _("If your stream has audio and you want to "\
134                          "transcode it, enable this.")
135 #define TR_AUDIO_TEXT _("Select your audio codec. Click one to get more " \
136                         "information.")
137
138 /* Streaming 1 */
139 #define STREAMING1_TITLE _("Streaming")
140 #define STREAMING1_TEXT _("In this page, you will select how your 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 _("You need to enter an address" )
146
147 /* Encap  */
148 #define ENCAP_TITLE _("Encapsulation format")
149 #define ENCAP_TEXT _("In this page, you will select how the stream will be "\
150                      "encapsulated. Depending on the choices you made, all "\
151                      "formats won't be available." )
152
153
154 /* Transcode 2 */
155 #define EXTRATRANSCODE_TITLE _("Additional transcode options")
156 #define EXTRATRANSCODE_TEXT _("In this page, you will define a few " \
157                               "additionnal parameters for your 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 _("In this page, you will define a few " \
164                               "additionnal parameters for your 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               "else, 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, false ) ) ),
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 , false ))),
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             for( int i=0 ; i < p_playlist->i_size ; i++ )
595             {
596                 wxString filename = wxL2U( p_playlist->pp_items[i]->input.
597                                                                     psz_name );
598                 listview->InsertItem( i, filename );
599                 listview->SetItem( i, 1, wxL2U( p_playlist->pp_items[i]->
600                                                             input.psz_uri) );
601             }
602             listview->Select( p_playlist->i_index , TRUE);
603             mainSizer->Add( listview, 1, wxALL|wxEXPAND, 5 );
604
605             listview->Hide();
606             mainSizer->Hide( listview );
607             mainSizer->Layout();
608         }
609         else
610         {
611             input_radios[1]->Disable();
612         }
613         vlc_object_release( p_playlist );
614     }
615     else
616     {
617         input_radios[1]->Disable();
618     }
619
620     /* Partial Extract Box */
621     mainSizer->Add( 0, 10, 0 );
622     wxStaticBox *partial_box = new wxStaticBox( this, -1,
623                     wxU(_("Partial Extract")) );
624
625     wxStaticBoxSizer *partial_sizer = new wxStaticBoxSizer( partial_box,
626                                                           wxVERTICAL );
627
628     enable_checkbox = new wxCheckBox( this, PartialEnable_Event,
629                                                 wxU(_("Enable") ) );
630     enable_checkbox->SetToolTip(wxU(_(PARTIAL) ) ) ;
631     partial_sizer->Add( enable_checkbox, 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 ); //wxLEFT
632
633     wxFlexGridSizer *partial_sizer2 = new wxFlexGridSizer( 4 , 1 , 20 );
634     partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "From" ) ) ),
635                          0 , wxLEFT , 5 );
636     from_text = new wxTextCtrl( this, -1, wxT(""),
637                                 wxDefaultPosition, wxSize( 80,25 ) );
638     partial_sizer2->Add( from_text, 0 , wxALIGN_RIGHT);
639     partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "To" ) ) ),
640                          0 , wxLEFT , 5 );
641     to_text = new wxTextCtrl( this, -1, wxT(""),
642                                   wxDefaultPosition, wxSize( 80 , 25 ) );
643     partial_sizer2->Add( to_text, 0 , wxALIGN_RIGHT );
644
645     partial_sizer->Add( partial_sizer2, 0, wxALL, 0 );
646
647     partial_sizer->Fit( partial_box );
648
649     mainSizer->Add( partial_sizer, 0, 0, 0 );
650
651     from_text->Disable();
652     to_text->Disable();
653     SetSizer(mainSizer);
654     mainSizer->Fit(this);
655     mainSizer->Layout();
656 }
657
658 wizInputPage::~wizInputPage()
659 {
660 }
661
662 void wizInputPage::OnInputChange( wxCommandEvent& event )
663 {
664     i_input = event.GetId() - InputRadio0_Event;
665     if( i_input == 0 )
666     {
667         if( listview )
668         {
669             listview->Hide();
670             mainSizer->Hide( listview );
671             open_panel->Show();
672             mainSizer->Show( open_panel );
673             mainSizer->Layout();
674         }
675     }
676     else
677     {
678         open_panel->Hide();
679         mainSizer->Hide( open_panel );
680         listview->Show();
681         mainSizer->Show( listview );
682         mainSizer->Layout();
683     }
684 }
685
686 void wizInputPage::OnEnablePartial(wxCommandEvent& event)
687 {
688    from_text->Enable( event.IsChecked() );
689    to_text->Enable( event.IsChecked() );
690 }
691
692
693 void wizInputPage::OnChoose(wxCommandEvent& event)
694 {
695     p_open_dialog = new OpenDialog( p_intf, this, -1, -1, OPEN_STREAM );
696     if(  p_open_dialog->ShowModal() == wxID_OK &&
697          !p_open_dialog->mrl.IsEmpty() )
698     {
699         mrl_text->SetValue(p_open_dialog->mrl[0] );
700     }
701     delete p_open_dialog;
702     p_open_dialog = NULL;
703 }
704
705 void wizInputPage::OnWizardPageChanging(wxWizardEvent& event)
706 {
707     if( i_input == 0)
708     {
709         if( mrl_text->GetValue().IsSameAs( wxT(""), TRUE ) &&
710                         event.GetDirection() )
711         {
712             wxMessageBox( wxU( CHOOSE_STREAM ), wxU( ERROR_MSG ),
713                           wxICON_WARNING | wxOK, this->p_parent );
714             event.Veto();
715             return;
716         }
717         else
718         {
719             p_parent->SetMrl( (const char *)mrl_text->GetValue().mb_str() );
720         }
721     }
722     else
723     {
724         int i = -1;
725         wxListItem listitem;
726         i = listview->GetNextItem( i , wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
727         if( i != -1 )
728         {
729             listitem.SetId( i );
730             listitem.SetColumn( 1 );
731             listview->GetItem( listitem );
732             p_parent->SetMrl( (const char*) listitem.GetText().mb_str() );
733         }
734     }
735     if( enable_checkbox->IsChecked() )
736     {
737         int i_from = atoi( from_text->GetValue().mb_str() );
738         int i_to = atoi( to_text->GetValue().mb_str() );
739         p_parent->SetPartial( i_from, i_to );
740     }
741     return;
742 }
743
744 wxWizardPage *wizInputPage::GetPrev() const { return p_prev; }
745 wxWizardPage *wizInputPage::GetNext() const
746 {
747     if( i_action == ACTION_STREAM )
748         return p_streaming_page;
749     else
750        return p_transcode_page;
751 }
752
753 void wizInputPage::SetStreamingPage( wxWizardPage *page)
754 {
755     p_streaming_page = page;
756 }
757
758 void wizInputPage::SetTranscodePage( wxWizardPage *page)
759 {
760     p_transcode_page = page;
761 }
762
763 void wizInputPage::SetAction( int i_action )
764 {
765     this->i_action = i_action;
766 }
767
768 void wizInputPage::SetPintf( intf_thread_t *p_intf )
769 {
770     this->p_intf = p_intf;
771 }
772
773 void wizInputPage::SetUri( char *psz_uri )
774 {
775     mrl_text->SetValue( wxU( psz_uri ) );
776 }
777
778 void wizInputPage::SetPartial( int i_from, int i_to )
779 {
780    wxString msg;
781    msg.Printf( wxString( wxT( "%i") ), i_from );
782    from_text->Enable( TRUE );
783    from_text->SetValue( msg );
784    msg.Printf( wxString( wxT( "%i") ), i_to );
785    to_text->Enable( TRUE );
786    to_text->SetValue( msg );
787    enable_checkbox->SetValue( TRUE );
788 }
789
790 /***************************************************
791  * First transcode page: choose codecs             *
792  ***************************************************/
793 wizTranscodeCodecPage::wizTranscodeCodecPage( wxWizard *parent,
794                        wxWizardPage *next) : wxWizardPage(parent)
795 {
796     int i;
797
798     p_next = next;
799
800     acodec = NULL;
801     vcodec = NULL;
802     p_parent = (WizardDialog *) parent;
803
804     wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
805
806     /* Header */
807     pageHeader( this, main_sizer,  TRANSCODE1_TITLE, TRANSCODE1_TEXT );
808
809     /* Video Box */
810     wxStaticBox *video_box = new wxStaticBox( this, -1, wxU(_("Video")) );
811     wxStaticBoxSizer *video_sizer = new wxStaticBoxSizer( video_box,
812                                                           wxVERTICAL );
813     /* Line 1 : only the checkbox */
814     wxFlexGridSizer *video_sizer1 = new wxFlexGridSizer( 2,3,20 );
815     video_sizer1->Add( new wxCheckBox( this, VideoEnable_Event,
816                        wxU(_("Transcode video") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL , 5 );
817     video_sizer1->Add( 0,0,1);
818     /* Line 2 : codec */
819     video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT ,5);
820     video_combo = new wxComboBox( this, VideoCodec_Event, wxT(""),
821                                   wxDefaultPosition, wxSize(200,25), 0, NULL, 
822                                   wxCB_DROPDOWN| wxCB_READONLY );
823     for( i= 0; vcodecs_array[i].psz_display != NULL; i++ )
824     {
825         video_combo->Append( wxU( vcodecs_array[i].psz_display ) ,
826                             (void *)&vcodecs_array[i] );
827     }
828     i_video_codec = 0;
829     video_combo->SetSelection(0);
830
831     video_sizer1->Add( video_combo, 0 , wxALIGN_LEFT , 0 );
832
833     video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
834                        wxLEFT ,5);
835     vb_combo = new wxComboBox( this, VideoBitrate_Event, wxT("1024"),
836                                wxDefaultPosition, wxDefaultSize,
837                                WXSIZEOF(vbitrates_array), vbitrates_array, wxCB_READONLY );
838     video_sizer1->Add( vb_combo, 0, wxALIGN_LEFT , 0 );
839
840     /* Line 3 : text */
841     video_text = new wxStaticText( this, -1,
842                      wxU( vlc_wraptext( TR_VIDEO_TEXT, TEXTWIDTH, false) ) );
843     /* Fill the main video sizer */
844     video_sizer->Add( video_sizer1 , 0, wxEXPAND , 5 );
845     video_sizer->Add( video_text, 0, wxLEFT|wxTOP , 5 );
846
847
848     /* Audio box */
849     wxStaticBox *audio_box = new wxStaticBox( this, -1, wxU(_("Audio")) );
850     wxStaticBoxSizer *audio_sizer = new wxStaticBoxSizer( audio_box,
851                                                           wxVERTICAL );
852     /* Line1: enabler */
853     wxFlexGridSizer *audio_sizer1 = new wxFlexGridSizer( 2,3,20);
854     audio_sizer1->Add( new wxCheckBox( this, AudioEnable_Event,
855                             wxU(_("Transcode audio") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 );
856     audio_sizer1->Add( 0, 0, 1 );
857
858     /* Line 2 : codec */
859     audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT,5);
860     audio_combo = new wxComboBox( this, AudioCodec_Event, wxT(""),
861                                   wxDefaultPosition, wxSize(200,25), 0, NULL, 
862                                   wxCB_DROPDOWN| wxCB_READONLY );
863     for( i= 0; acodecs_array[i].psz_display != NULL; i++ )
864     {
865         audio_combo->Append( wxU( acodecs_array[i].psz_display ) ,
866                             (void *)&acodecs_array[i] );
867     }
868     i_audio_codec = 0;
869     audio_combo->SetSelection(0);
870     audio_sizer1->Add( audio_combo, 0 , wxALIGN_LEFT, 0 );
871
872     audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
873                        wxLEFT ,5);
874     ab_combo = new wxComboBox( this, AudioBitrate_Event, wxT("192"),
875                                wxDefaultPosition, wxDefaultSize,
876                                WXSIZEOF(abitrates_array), abitrates_array, wxCB_READONLY );
877     audio_sizer1->Add( ab_combo, 0, wxALIGN_LEFT, 0 );
878
879     /* Line 3 : text */
880     audio_text = new wxStaticText( this, -1,
881                      wxU( vlc_wraptext( TR_AUDIO_TEXT, TEXTWIDTH, false) ) );
882
883     audio_sizer->Add(audio_sizer1, 0, wxEXPAND, 5);
884     audio_sizer->Add( audio_text, 0, wxLEFT | wxTOP, 5 );
885
886     main_sizer->Add( video_sizer, 1, wxGROW, 0 );
887     main_sizer->Add( audio_sizer, 1, wxGROW, 0 );
888     main_sizer->Layout();
889     SetSizerAndFit( main_sizer );
890
891     /* Default disabled */
892     video_combo->Disable(); video_text->Disable();vb_combo->Disable();
893     audio_combo->Disable(); audio_text->Disable();ab_combo->Disable();
894
895 }
896
897 wizTranscodeCodecPage::~wizTranscodeCodecPage()
898 {
899     if( acodec ) free( acodec );
900     if( vcodec ) free( vcodec );
901 }
902
903 void wizTranscodeCodecPage::OnEnableVideo(wxCommandEvent& event)
904 {
905    video_combo->Enable( event.IsChecked() );
906    vb_combo->Enable( event.IsChecked() );
907    video_text->Enable( event.IsChecked() );
908 }
909
910 void wizTranscodeCodecPage::OnEnableAudio(wxCommandEvent& event)
911 {
912    audio_combo->Enable( event.IsChecked() );
913    ab_combo->Enable( event.IsChecked() );
914    audio_text->Enable( event.IsChecked() );
915 }
916
917 void wizTranscodeCodecPage::OnVideoCodecChange(wxCommandEvent& event)
918 {
919     struct codec *c = (struct codec*)
920              (video_combo->GetClientData(video_combo->GetSelection()));
921     video_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH, false) ) );
922     i_video_codec = video_combo->GetSelection();
923     vcodec = strdup(c->psz_codec);
924 }
925
926 void wizTranscodeCodecPage::OnAudioCodecChange(wxCommandEvent& event)
927 {
928     struct codec *c = (struct codec*)
929              (audio_combo->GetClientData(audio_combo->GetSelection()));
930     audio_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH, false) ) );
931     i_audio_codec = audio_combo->GetSelection();
932     acodec = strdup(c->psz_codec);
933
934 }
935
936 void wizTranscodeCodecPage::OnWizardPageChanging(wxWizardEvent& event)
937 {
938     unsigned int i,j;
939
940     if( !event.GetDirection() )
941     {
942             GetPrev()->Enable();
943             return;
944     }
945
946     /* Set the dummy codec ( accept all muxers ) if needed */
947     if( !video_combo->IsEnabled() )
948     {
949         i_video_codec = VCODECS_NUMBER;
950     }
951     if( !audio_combo->IsEnabled() )
952     {
953         i_audio_codec = ACODECS_NUMBER;
954     }
955
956     ((wizEncapPage *)GetNext())->SetPrev(this);
957
958     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
959     {
960         if( vcodecs_array[i_video_codec].muxers[i] != -1 )
961         {
962             for( j = 0 ; j<  MUXERS_NUMBER ; j++ )
963             {
964                 if( acodecs_array[i_audio_codec].muxers[j] ==
965                               vcodecs_array[i_video_codec].muxers[i] )
966                 {
967                     ((wizEncapPage*)GetNext())->EnableEncap(
968                                vcodecs_array[i_video_codec].muxers[i] );
969                 }
970             }
971         }
972     }
973     struct codec *c = (struct codec*)
974              (video_combo->GetClientData( video_combo->IsEnabled() ?
975                                           video_combo->GetSelection(): i_video_codec ));
976     vcodec = strdup(c->psz_codec);
977     c = (struct codec*)
978            (audio_combo->GetClientData( audio_combo->IsEnabled() ?
979                                        audio_combo->GetSelection() : i_audio_codec ));
980     acodec = strdup(c->psz_codec);
981
982     int vb = atoi(vb_combo->GetValue().mb_str() );
983     if( vb == 0 )
984     {
985          vb = 1024;
986     }
987     int ab = atoi(ab_combo->GetValue().mb_str() );
988     if( ab == 0)
989     {
990         ab = 192;
991     }
992
993     p_parent->SetTranscode( vcodec, vb , acodec, ab );
994     ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
995     p_parent->SetAction( p_parent->GetAction() );
996
997     return;
998 }
999
1000 wxWizardPage *wizTranscodeCodecPage::GetPrev() const { return p_prev; }
1001 wxWizardPage *wizTranscodeCodecPage::GetNext() const { return p_next; }
1002 void wizTranscodeCodecPage::SetPrev( wxWizardPage *page) {p_prev = page; }
1003
1004
1005 /***************************************************
1006  * First streaming page: choose method             *
1007  ***************************************************/
1008 wizStreamingMethodPage::wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
1009     wxWizardPage *next) : wxWizardPage(parent), p_intf( p_this )
1010 {
1011     int i;
1012     p_next = next;
1013     p_parent = (WizardDialog *)parent;
1014
1015     mainSizer = new wxBoxSizer(wxVERTICAL);
1016
1017     /* Create the texts */
1018     pageHeader( this, mainSizer,  STREAMING1_TITLE, STREAMING1_TEXT );
1019
1020     mainSizer->Add( 0,50,0 );
1021
1022     i_method = 0;
1023
1024     wxStaticBox *method_box = new wxStaticBox( this, -1,
1025                                                wxU(_("Streaming method")) );
1026     wxStaticBoxSizer *method_sizer = new wxStaticBoxSizer(method_box,
1027                                                           wxHORIZONTAL );
1028     for( i = 0 ; i< 3 ; i++ )
1029     {
1030         method_radios[i] = new wxRadioButton( this, MethodRadio0_Event + i,
1031                                wxU( methods_array[i].psz_method ) );
1032         method_radios[i]->SetToolTip( wxU(_( methods_array[i].psz_descr ) ) );
1033         method_sizer->Add( method_radios[i], 0, wxALL, 5 );
1034     }
1035
1036     method_sizer->Layout();
1037
1038     wxStaticBox *address_box = new wxStaticBox( this, -1,
1039                     wxU(_("Destination")) );
1040
1041     address_sizer = new wxStaticBoxSizer(address_box,
1042                                          wxVERTICAL );
1043
1044     /* Big kludge, we take the longest text to get the size */
1045     address_text = new wxStaticText(this, -1,
1046                wxU( vlc_wraptext(methods_array[2].psz_address,
1047                                  TEXTWIDTH, false ) ),
1048                wxDefaultPosition, wxDefaultSize );
1049
1050     address_txtctrl = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
1051                                       wxSize(200,25));
1052     address_sizer->Add( address_text, 0, wxALL, 5 );
1053     address_sizer->Add( address_txtctrl, 0, wxALL, 5 );
1054     address_sizer->Layout();
1055
1056     /* Set the minimum size */
1057     address_sizer->SetMinSize( address_sizer->GetSize() );
1058     address_text->SetLabel( wxU(
1059      vlc_wraptext( _(methods_array[0].psz_address), TEXTWIDTH, false)));
1060
1061     mainSizer->Add( method_sizer, 0, wxALL | wxEXPAND, 5 );
1062     mainSizer->Add( address_sizer, 0, wxALL | wxEXPAND, 5 );
1063
1064     mainSizer->Add( 0,0,1 );
1065
1066     mainSizer->Layout();
1067
1068     SetSizer(mainSizer);
1069     mainSizer->Fit(this);
1070
1071     return;
1072 }
1073
1074 void wizStreamingMethodPage::OnWizardPageChanging(wxWizardEvent& event)
1075 {
1076     unsigned int i;
1077     if( !event.GetDirection() ) return;
1078
1079     /* Check valid address */
1080     if( i_method == 1
1081      && !net_AddressIsMulticast( (vlc_object_t *)p_intf,
1082                                  address_txtctrl->GetValue().mb_str()) )
1083     {
1084         wxMessageBox( wxU( INVALID_MCAST_ADDRESS ) , wxU( ERROR_MSG ),
1085                       wxICON_WARNING | wxOK, this->p_parent );
1086         event.Veto();
1087
1088     }
1089     else if( i_method == 0 && address_txtctrl->GetValue().IsEmpty() )
1090     {
1091         wxMessageBox( wxU( NO_ADDRESS_TEXT ) , wxU( ERROR_MSG ),
1092                       wxICON_WARNING | wxOK, this->p_parent );
1093         event.Veto();
1094
1095     }
1096
1097     ((wizEncapPage *)GetNext())->SetPrev(this);
1098     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
1099     {
1100         if( methods_array[i_method].muxers[i] != -1 )
1101         {
1102             ((wizEncapPage*)GetNext())->EnableEncap(
1103                                methods_array[i_method].muxers[i] );
1104         }
1105     }
1106     p_parent->SetStream( methods_array[i_method].psz_access ,
1107                          address_txtctrl->GetValue().mb_str() );
1108
1109     /* Set the action for the muxer page */
1110     ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
1111     return;
1112 }
1113
1114 wxWizardPage *wizStreamingMethodPage::GetPrev() const { return p_prev; }
1115 wxWizardPage *wizStreamingMethodPage::GetNext() const { return p_next; }
1116
1117 void wizStreamingMethodPage::SetPrev( wxWizardPage *page) {p_prev = page; }
1118
1119
1120 void wizStreamingMethodPage::OnMethodChange( wxCommandEvent& event )
1121 {
1122     i_method = event.GetId() - MethodRadio0_Event;
1123     address_text->SetLabel( wxU(
1124      vlc_wraptext( _(methods_array[i_method].psz_address), TEXTWIDTH, false)));
1125     address_sizer->Layout();
1126     mainSizer->Layout();
1127 }
1128
1129 /***************************************************
1130  * Choose encapsulation format                     *
1131  ***************************************************/
1132 wizEncapPage::wizEncapPage( wxWizard *parent ) : wxWizardPage(parent)
1133 {
1134     int i;
1135     i_mux = 0;
1136     p_parent = (WizardDialog *)parent;
1137     p_streaming_page = NULL;
1138     p_transcode_page = NULL;
1139     p_prev = NULL;
1140     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1141
1142     /* Create the texts */
1143     pageHeader( this, mainSizer, ENCAP_TITLE, ENCAP_TEXT );
1144
1145     mainSizer->Add( 0,0,1 );
1146
1147     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
1148     {
1149         encap_radios[i] = new wxRadioButton( this, EncapRadio0_Event + i,
1150                                wxU( encaps_array[i].psz_encap ) );
1151         encap_radios[i]->SetToolTip( wxU(_( encaps_array[i].psz_descr ) ) );
1152         mainSizer->Add( encap_radios[i], 0, wxLEFT, 5 );
1153         encap_radios[i]->Disable();
1154     }
1155
1156     mainSizer->Add( 0,0,1 );
1157
1158     SetSizer(mainSizer);
1159     mainSizer->Fit(this);
1160 }
1161
1162 wizEncapPage::~wizEncapPage()
1163 {
1164 }
1165
1166 void wizEncapPage::OnWizardPageChanging(wxWizardEvent& event)
1167 {
1168     int i;
1169     if( !event.GetDirection() )
1170     {
1171         for( i = 0 ; i< MUXERS_NUMBER ; i++ )
1172         {
1173             encap_radios[i]->Disable();
1174         }
1175     }
1176     p_parent->SetMux( encaps_array[i_mux].psz_mux );
1177
1178     if( p_parent->GetAction() == ACTION_STREAM )
1179     {
1180         if( strstr( p_parent->method, "rtp" ))
1181         {
1182             ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable();
1183             ((wizStreamingExtraPage *)GetNext())->sap_text->Enable(false);
1184         }
1185         else
1186         {
1187            ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable( false );
1188            ((wizStreamingExtraPage *)GetNext())->sap_text->Enable( false );
1189         }
1190     }
1191
1192     return;
1193 }
1194
1195
1196 void wizEncapPage::OnEncapChange( wxCommandEvent& event )
1197 {
1198     i_mux = event.GetId() - EncapRadio0_Event;
1199 }
1200
1201 void wizEncapPage::EnableEncap( int encap )
1202 {
1203     int i;
1204     for( i = 0 ; i< MUXERS_NUMBER ; i++)
1205     {
1206         if( encaps_array[i].id == encap )
1207         {
1208             encap_radios[i]->Enable();
1209             encap_radios[i]->SetValue(true);
1210             i_mux = i;
1211         }
1212     }
1213 }
1214
1215 void wizEncapPage::SetStreamingPage( wxWizardPage *page)
1216 {
1217     p_streaming_page = page;
1218 }
1219
1220 void wizEncapPage::SetTranscodePage( wxWizardPage *page)
1221 {
1222     p_transcode_page = page;
1223 }
1224
1225 wxWizardPage *wizEncapPage::GetPrev() const { return p_prev; }
1226
1227 wxWizardPage *wizEncapPage::GetNext() const
1228 {
1229     if( i_action== ACTION_STREAM )
1230         return p_streaming_page;
1231     else
1232        return p_transcode_page;
1233 }
1234
1235 void wizEncapPage::SetAction( int i_act  ) { i_action = i_act; }
1236
1237 void wizEncapPage::SetPrev( wxWizardPage *page) { p_prev = page; }
1238
1239 /***************************************************
1240  * Extra transcoding page : Select file            *
1241  ***************************************************/
1242 wizTranscodeExtraPage::wizTranscodeExtraPage( wxWizard *parent,
1243                        wxWizardPage *prev,
1244                        wxWizardPage *next) : wxWizardPage(parent)
1245 {
1246     p_next = next;
1247     p_prev = prev;
1248     p_parent = (WizardDialog *) parent;
1249     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1250
1251     /* Create the texts */
1252     pageHeader( this, mainSizer, EXTRATRANSCODE_TITLE, EXTRATRANSCODE_TEXT );
1253
1254     mainSizer->Add( 0, 0, 1 );
1255
1256     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 2, 1 );
1257     sizer->Add( new wxStaticText( this, -1,
1258                     wxU(_("Select the file to save to") ) ),
1259                     0, wxALL, 5 );
1260     sizer->Add( 0, 0, 1 );
1261
1262     file_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
1263                                 wxSize( 150, -1 ) );
1264
1265     sizer->Add( file_text, 0,  wxALL, 5 );
1266     sizer->Add( new wxButton( this, Open_Event, wxU("Choose") ) );
1267
1268     mainSizer->Add( sizer, 0, 0, 0) ;
1269
1270     mainSizer->Add( 0, 0, 1 );
1271     SetSizer(mainSizer);
1272     mainSizer->Fit(this);
1273 }
1274
1275 void wizTranscodeExtraPage::OnSelectFile( wxCommandEvent &event)
1276 {
1277     wxFileDialog *file_dialog =  new wxFileDialog( this, wxU(_("Save to file")),
1278                    wxT(""), wxT(""), wxT("*"), wxSAVE );
1279
1280     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
1281     {
1282         if( file_dialog->GetFilename().mb_str() )
1283         {
1284             file_text->SetValue( file_dialog->GetPath() );
1285         }
1286     }
1287 }
1288
1289 void wizTranscodeExtraPage::OnWizardPageChanging( wxWizardEvent& event )
1290 {
1291     if( event.GetDirection() && file_text->GetValue().IsEmpty() )
1292     {
1293         wxMessageBox( wxU( CHOOSE_OUTFILE ), wxU( ERROR_MSG ),
1294                       wxICON_WARNING | wxOK, this->p_parent );
1295         event.Veto();
1296     }
1297     if( event.GetDirection() )
1298     {
1299        p_parent->SetTranscodeOut( file_text->GetValue().mb_str());
1300     }
1301 }
1302
1303 wxWizardPage *wizTranscodeExtraPage::GetPrev() const { return p_prev; }
1304 wxWizardPage *wizTranscodeExtraPage::GetNext() const {return p_next; }
1305
1306 /***********************************************************
1307  *  Extra streaming page
1308  ***********************************************************/
1309 wizStreamingExtraPage::wizStreamingExtraPage( wxWizard *parent,
1310                        wxWizardPage *prev,
1311                        wxWizardPage *next) : wxWizardPage(parent)
1312 {
1313     p_next = next;
1314     p_prev = prev;
1315     p_parent = (WizardDialog *) parent;
1316     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1317
1318     /* Create the texts */
1319     pageHeader( this, mainSizer, EXTRASTREAMING_TITLE, EXTRASTREAMING_TEXT );
1320
1321     mainSizer->Add( 0, 0, 1 );
1322
1323     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2,2,1) ;
1324
1325     /* TTL */
1326     sizer->Add( new wxStaticText( this, -1, wxU(_("Time-To-Live (TTL)"))),
1327                     0, wxALL,  5 );
1328     ttl_spin = new wxSpinCtrl( this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
1329                     0, 1, 255, 1 );
1330     ttl_spin->SetToolTip(wxU(_(TTL) ) ) ;
1331     sizer->Add( ttl_spin, 0, wxALL , 5 );
1332
1333     /* SAP announce */
1334     sap_checkbox =  new wxCheckBox( this, SAP_Event, wxU(_("SAP Announce")) );
1335     sap_checkbox->SetToolTip( wxU(_( SAP ) ) );
1336     sizer->Add( sap_checkbox, 0, 0 , 0 );
1337     sap_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
1338                     wxSize(100,25) );
1339     sap_text->SetToolTip( wxU(_( SAP ) ) );
1340     sizer->Add( sap_text, 0, wxALL , 5 );
1341
1342     mainSizer->Add(sizer, 0, wxALL, 5 );
1343
1344     mainSizer->Add( 0, 0, 1 );
1345
1346     SetSizer(mainSizer);
1347     mainSizer->Fit(this);
1348 }
1349
1350 void wizStreamingExtraPage::OnSAP( wxCommandEvent &event )
1351 {
1352     sap_text->Enable( event.IsChecked() );
1353 }
1354
1355 void wizStreamingExtraPage::OnWizardPageChanging(wxWizardEvent& event)
1356 {
1357     if( sap_checkbox->IsChecked() )
1358     {
1359         if( sap_text->GetValue().IsEmpty() )
1360         {
1361             p_parent->SetSAP( true, NULL );
1362         }
1363         else
1364         {
1365             p_parent->SetSAP( true,
1366                              (const char *)sap_text->GetValue().mb_str() );
1367         }
1368     }
1369     else
1370     {
1371         p_parent->SetSAP( false, NULL );
1372     }
1373
1374     p_parent->SetTTL( ttl_spin->GetValue() );
1375 }
1376
1377 wxWizardPage *wizStreamingExtraPage::GetPrev() const { return p_prev; }
1378 wxWizardPage *wizStreamingExtraPage::GetNext() const {return p_next; }
1379
1380
1381 /***************************************************************************
1382  * Implementation of the wizard itself
1383  ***************************************************************************/
1384 wizHelloPage *page1;
1385 wizInputPage *page2 ;
1386 wizTranscodeCodecPage *tr_page1 ;
1387 wizStreamingMethodPage *st_page1;
1388 wizTranscodeExtraPage *tr_page2 ;
1389 wizStreamingExtraPage *st_page2;
1390 wizEncapPage *encap_page;
1391
1392 WizardDialog::WizardDialog(intf_thread_t *_p_intf, wxWindow *_p_parent,
1393                            char *psz_uri, int _i_from, int _i_to  ) :
1394 wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, wxDefaultPosition)
1395 {
1396     /* Initializations */
1397     p_intf = _p_intf;
1398     SetPageSize(wxSize(400,420));
1399
1400     /* Initialize structure */
1401     i_action = 0;
1402     i_from = _i_from;
1403     i_to = _i_to;
1404     i_ttl = 1;
1405     vb = 0;
1406     ab = 0;
1407     acodec=NULL;
1408     vcodec=NULL;
1409
1410     page1 = new wizHelloPage(this);
1411     page2 = new wizInputPage(this, page1, p_intf);
1412
1413     if( psz_uri )
1414     {
1415         page2->SetUri( psz_uri );
1416     }
1417     if( i_from != 0 || i_to != 0 )
1418     {
1419         page2->SetPartial( i_from, i_to );
1420     }
1421
1422     encap_page = new wizEncapPage(this );
1423     tr_page1 = new wizTranscodeCodecPage(this, encap_page );
1424     st_page1 = new wizStreamingMethodPage( p_intf, this, encap_page);
1425
1426     tr_page2 = new wizTranscodeExtraPage(this, encap_page, NULL );
1427     st_page2 = new wizStreamingExtraPage(this, encap_page, NULL );
1428
1429     /* Page 1 -> 2 */
1430     page1->SetNext( page2 );
1431     /* 2->1 in constructor of 2 */
1432
1433     /* Page 2 -> 3 */
1434     page2->SetTranscodePage(tr_page1);
1435     page2->SetStreamingPage(st_page1);
1436     page2->SetPintf( p_intf );
1437     tr_page1->SetPrev(page2);
1438     st_page1->SetPrev(page2);
1439
1440     /* Page 3 -> 4 */
1441     encap_page->SetTranscodePage( tr_page2 );
1442     encap_page->SetStreamingPage( st_page2 );
1443     /* 3->4 in constructor of 3 */
1444 //    encap_page->SetPrev(tr_page1);
1445 }
1446
1447 WizardDialog::~WizardDialog()
1448 {
1449     Destroy();
1450     delete page1;
1451     delete page2;
1452     delete tr_page1;
1453     delete st_page1 ;
1454     delete st_page2;
1455     delete tr_page2;
1456     delete encap_page;
1457 }
1458
1459 void WizardDialog::SetMrl( const char *mrl )
1460 {
1461     this->mrl = strdup( mrl );
1462 }
1463
1464 void WizardDialog::SetTTL( int i_ttl )
1465 {
1466     this->i_ttl = i_ttl;
1467 }
1468
1469 void WizardDialog::SetSAP( bool b_enabled, const char *psz_text )
1470 {
1471     this->b_sap = b_enabled;
1472     if( b_enabled )
1473     {
1474         if( psz_text != NULL )
1475         {
1476             this->psz_sap_name = strdup( psz_text );
1477         }
1478         else
1479         {
1480             this->psz_sap_name = NULL;
1481         }
1482     }
1483 }
1484
1485 void WizardDialog::SetPartial( int i_from, int i_to )
1486 {
1487     this->i_from = i_from;
1488     this->i_to = i_to;
1489 }
1490
1491 void WizardDialog::SetTranscode( char const *vcodec, int vb,
1492                                  char const *acodec, int ab)
1493 {
1494     if( strcmp( vcodec, "dummy") )
1495     {
1496         this->vcodec= strdup(vcodec);
1497     }
1498     if( strcmp( acodec, "dummy" ) )
1499     {
1500         this->acodec = strdup(acodec);
1501     }
1502     this->vb = vb;
1503     this->ab = ab;
1504 }
1505
1506 void WizardDialog::SetStream( char const *method, char const *address )
1507 {
1508     this->method = strdup( method );
1509     this->address = strdup( address );
1510 }
1511
1512 void WizardDialog::SetTranscodeOut( char const *address )
1513 {
1514     char *psz_utf8 = FromLocale( address );
1515     this->address = strdup( psz_utf8 );
1516     LocaleFree( psz_utf8 );
1517 }
1518
1519 void WizardDialog::SetMux( char const *mux )
1520 {
1521     this->mux = strdup( mux );
1522 }
1523
1524 void WizardDialog::SetAction( int i_action )
1525 {
1526     this->i_action = i_action;
1527 }
1528
1529 int WizardDialog::GetAction()
1530 {
1531     return i_action;
1532 }
1533
1534 void WizardDialog::Run()
1535 {
1536     if( RunWizard(page1) )
1537     {
1538         int i_size;
1539         char *psz_opt;
1540
1541         if( i_action == ACTION_TRANSCODE )
1542         {
1543             msg_Dbg( p_intf,"Starting transcode of %s to file %s",
1544                                   mrl, address);
1545             msg_Dbg( p_intf,"Using %s (%i kbps) / %s (%i kbps),encap %s",
1546                                 vcodec,vb,acodec,ab,mux);
1547             char *psz_transcode;
1548
1549             if( vcodec != NULL || acodec != NULL )
1550             {
1551                 int i_tr_size = 14;
1552                 if( vcodec != NULL )
1553                     i_tr_size += strlen( vcodec ) + 17;
1554                 if( acodec != NULL )
1555                     i_tr_size += strlen( acodec ) + 17;
1556
1557                 if( vb > 999999 )
1558                     vb = 999999;
1559                 else if( vb < 0 )
1560                     vb = 0;
1561
1562                 if( ab > 999999 )
1563                     ab = 999999;
1564                 else if( ab < 0 )
1565                     ab = 0;
1566
1567                 psz_transcode = (char *)malloc( i_tr_size * sizeof(char) );
1568
1569                 strcpy( psz_transcode, "transcode{" );
1570                 if( vcodec != NULL )
1571                 {
1572                     sprintf( psz_transcode + strlen( psz_transcode ),
1573                              "vcodec=%s,vb=%i%s", vcodec, vb,
1574                              ( acodec != NULL ) ? "," : "}:" );
1575                 }
1576                 if( acodec != NULL )
1577                 {
1578                     sprintf( psz_transcode + strlen( psz_transcode ),
1579                              "acodec=%s,ab=%i}:", acodec, ab );
1580                 }
1581             }
1582             else
1583                 psz_transcode = "";
1584
1585             i_size = 73 + strlen(mux) + strlen(address) + strlen(psz_transcode);
1586             psz_opt = (char *)malloc( i_size * sizeof(char) );
1587             snprintf( psz_opt, i_size, ":sout=#%sstandard{mux=%s,url=%s,"
1588                       "access=file}", psz_transcode, mux, address );
1589
1590             if( *psz_transcode )
1591                 free( psz_transcode );
1592         }
1593         else
1594         {
1595             msg_Dbg( p_intf, "Starting stream of %s to %s using %s, encap %s",
1596                                mrl, address, method, mux);
1597             if( b_sap )
1598             {
1599                 char *psz_sap_option = NULL;
1600                 if( psz_sap_name )
1601                 {
1602                     psz_sap_option = (char *) malloc( strlen( psz_sap_name )
1603                                                + 15 );
1604                     snprintf( psz_sap_option,strlen( psz_sap_name ) + 15,
1605                              "sap,name=\"%s\"",psz_sap_name );
1606                 }
1607                 else
1608                     psz_sap_option = strdup( "sap" );
1609
1610                 i_size = 40 + strlen(mux) + strlen(address) +
1611                               strlen( psz_sap_option);
1612                 psz_opt = (char *)malloc( i_size * sizeof(char) );
1613                 snprintf( psz_opt, i_size,
1614                           ":sout=#standard{mux=%s,url=%s,access=%s,%s}",
1615                           mux, address,method, psz_sap_option);
1616                 if( psz_sap_option ) free( psz_sap_option );
1617             }
1618             else
1619             {
1620                 i_size = 40 + strlen(mux) + strlen(address);
1621                 psz_opt = (char *)malloc( i_size * sizeof(char) );
1622                 snprintf( psz_opt, i_size,
1623                           ":sout=#standard{mux=%s,url=%s,access=%s}",
1624                           mux, address,method);
1625             }
1626         }
1627
1628         playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
1629                             VLC_OBJECT_PLAYLIST, FIND_ANYWHERE);
1630         if( p_playlist )
1631         {
1632             playlist_item_t *p_item = playlist_ItemNew( p_playlist, mrl,
1633                                                         ITEM_NAME );
1634             playlist_ItemAddOption( p_item, psz_opt);
1635             if( i_from != 0)
1636             {
1637                 char psz_from[20];
1638                 snprintf( psz_from, 20, "start-time=%i", i_from);
1639                 playlist_ItemAddOption( p_item, psz_from);
1640             }
1641             if( i_to != 0)
1642             {
1643                 char psz_to[20];
1644                 snprintf( psz_to, 20, "stop-time=%i", i_to);
1645                 playlist_ItemAddOption( p_item, psz_to);
1646             }
1647
1648             char psz_ttl[20];
1649             snprintf( psz_ttl, 20, "ttl=%i",i_ttl );
1650             playlist_ItemAddOption( p_item, psz_ttl );
1651
1652             playlist_AddItem( p_playlist, p_item, PLAYLIST_GO, PLAYLIST_END );
1653             vlc_object_release(p_playlist);
1654         }
1655         else
1656         {
1657             wxMessageBox( wxU( NO_PLAYLIST ), wxU( ERROR_MSG ),
1658                           wxICON_WARNING | wxOK, this );
1659         }
1660     }
1661 }