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