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