* modules/gui/wxwindows/*: misc small improvements and fixes.
[vlc.git] / modules / gui / wxwindows / streamout.cpp
index 28beb3e..2fb7fca 100644 (file)
@@ -2,7 +2,7 @@
  * streamout.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: streamout.cpp,v 1.1 2003/03/22 03:14:34 gbazin Exp $
+ * $Id: streamout.cpp,v 1.5 2003/04/01 16:11:43 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -89,7 +89,6 @@ enum
     AccessRadio3_Event, AccessRadio4_Event,
     NetPort_Event,
     NetAddr_Event,
-    MulticastCheckbox_Event,
 
     EncapsulationRadio1_Event, EncapsulationRadio2_Event,
     EncapsulationRadio3_Event, EncapsulationRadio4_Event,
@@ -110,7 +109,6 @@ BEGIN_EVENT_TABLE(SoutDialog, wxDialog)
     EVT_TEXT(NetPort_Event, SoutDialog::OnNetChange)
     EVT_SPINCTRL(NetPort_Event, SoutDialog::OnNetChange)
     EVT_TEXT(NetAddr_Event, SoutDialog::OnNetChange)
-    EVT_CHECKBOX(MulticastCheckbox_Event, SoutDialog::OnMulticastChange)
  
     /* Events generated by the encapsulation panel */
     EVT_RADIOBUTTON(EncapsulationRadio1_Event,
@@ -128,29 +126,22 @@ END_EVENT_TABLE()
  * Constructor.
  *****************************************************************************/
 SoutDialog::SoutDialog( intf_thread_t *_p_intf, Interface *_p_main_interface ):
-    wxDialog( _p_main_interface, -1, _("Stream Output"), wxDefaultPosition,
+    wxDialog( _p_main_interface, -1, _("Stream output"), wxDefaultPosition,
              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
 {
     /* Initializations */
     p_intf = _p_intf;
     p_main_interface = _p_main_interface;
+    SetIcon( *p_intf->p_sys->p_icon );
 
     /* Create a panel to put everything in */
     wxPanel *panel = new wxPanel( this, -1 );
     panel->SetAutoLayout( TRUE );
 
-    /* Initialise MRL value */
-    char *psz_sout = config_GetPsz( p_intf, "sout" );
-    if( psz_sout )
-    {
-        mrl = psz_sout;
-        free( psz_sout );
-    }
-
     /* Create MRL combobox */
     wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
     wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
-                               _("Stream Output MRL") );
+                               _("Stream output MRL") );
     wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
                                                         wxHORIZONTAL );
     wxStaticText *mrl_label = new wxStaticText( panel, -1,
@@ -194,6 +185,9 @@ SoutDialog::SoutDialog( intf_thread_t *_p_intf, Interface *_p_main_interface ):
     main_sizer->Add( panel, 1, wxGROW, 0 );
     main_sizer->Layout();
     SetSizerAndFit( main_sizer );
+
+    /* Update all the values */
+    ParseMRL();
 }
 
 SoutDialog::~SoutDialog()
@@ -227,24 +221,22 @@ void SoutDialog::UpdateMRL()
     switch( i_access_type )
     {
     case FILE_ACCESS_OUT:
-        mrl = "file" + encapsulation + "://" + file_combo->GetValue();
+        mrl = "file" + encapsulation + ":" + file_combo->GetValue();
         break;
 
     case HTTP_ACCESS_OUT:
-        mrl = "http" + encapsulation + "://" + net_addr->GetLineText(0)
+        mrl = "http" + encapsulation + ":" + net_addr->GetLineText(0)
               + wxString::Format( ":%d", net_port->GetValue() );
         break;
 
     case UDP_ACCESS_OUT:
-        mrl = "udp" + encapsulation + (b_multicast ? "://@" : "://")
-              + net_addr->GetLineText(0)
-              + wxString::Format( ":%d", net_port->GetValue() );
-        break;
-
     case RTP_ACCESS_OUT:
-        mrl = "rtp" + encapsulation + (b_multicast ? "://@" : "://")
-              + net_addr->GetLineText(0)
-              + wxString::Format( ":%d", net_port->GetValue() );
+        mrl = ( i_access_type == UDP_ACCESS_OUT ) ? "udp" : "rtp";
+       mrl += encapsulation + ":" + net_addr->GetLineText(0);
+       if( net_port->GetValue() != config_GetInt( p_intf, "server-port" ) )
+       {
+           mrl += wxString::Format( ":%d", net_port->GetValue() );
+       }
         break;
     }
 
@@ -308,12 +300,13 @@ wxPanel *SoutDialog::AccessPanel( wxWindow* parent )
     subpanel_sizer->Add( net_addr, 1,
                          wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
 
+    int val = config_GetInt( p_intf, "server-port" );
     label = new wxStaticText( access_subpanels[2], -1, _("Port") );
     net_port = new wxSpinCtrl( access_subpanels[2], NetPort_Event,
-                               wxString::Format(_("%d"), 0/*val*/),
+                               wxString::Format("%d", val),
                                wxDefaultPosition, wxDefaultSize,
                                wxSP_ARROW_KEYS,
-                               0, 16000, 0/*val*/);
+                               0, 16000, val );
 
     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
     subpanel_sizer->Add( net_port, 0,
@@ -321,16 +314,6 @@ wxPanel *SoutDialog::AccessPanel( wxWindow* parent )
 
     access_subpanels[2]->SetSizerAndFit( subpanel_sizer );
 
-    /* Multicast row */
-    subpanel_sizer = new wxFlexGridSizer( 1, 1, 20 );
-    b_multicast = VLC_FALSE;
-    multicast_checkbox = new wxCheckBox( access_subpanels[3],
-                                         MulticastCheckbox_Event,
-                                         _("Multicast") );
-    subpanel_sizer->Add( multicast_checkbox, 0, wxEXPAND |
-                         wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
-    access_subpanels[3]->SetSizerAndFit( subpanel_sizer );
-
 
     /* Stuff everything into the main panel */
     for( i=0; i<4; i++ )
@@ -345,13 +328,6 @@ wxPanel *SoutDialog::AccessPanel( wxWindow* parent )
 
     panel->SetSizerAndFit( panel_sizer );
 
-    /* Update access output panel */
-    net_addr->SetValue( "127.0.0.1" );
-    net_port->SetValue( config_GetInt( p_intf, "server-port" ) );
-    wxCommandEvent dummy_event;
-    dummy_event.SetId( AccessRadio1_Event );
-    OnAccessTypeChange( dummy_event );
-
     return panel;
 }
 
@@ -381,7 +357,7 @@ wxPanel *SoutDialog::EncapsulationPanel( wxWindow* parent )
             new wxRadioButton( panel, EncapsulationRadio1_Event + i,
                                encapsulation_array[i] );
         panel_sizer->Add( encapsulation_radios[i], 0,
-                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
+                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
     }
 
     panel->SetSizerAndFit( panel_sizer );
@@ -393,6 +369,89 @@ wxPanel *SoutDialog::EncapsulationPanel( wxWindow* parent )
     return panel;
 }
 
+void SoutDialog::ParseMRL()
+{
+    /* Initialise MRL value */
+    char *psz_sout = config_GetPsz( p_intf, "sout" );
+    if( psz_sout )
+    {
+        mrl = psz_sout;
+        free( psz_sout );
+    }
+
+    /* Parse the MRL */
+    wxString access = mrl.BeforeFirst( '/' );
+    wxString encapsulation = mrl.BeforeFirst( ':' ).AfterFirst('/');
+
+    if( !access.Cmp( "http" ) )
+    {
+        i_access_type = HTTP_ACCESS_OUT;
+    }
+    else if( !access.Cmp( "udp" ) )
+    {
+        i_access_type = UDP_ACCESS_OUT;
+    }
+    else if( !access.Cmp( "rtp" ) )
+    {
+        i_access_type = RTP_ACCESS_OUT;
+    }
+    else
+    {
+        i_access_type = FILE_ACCESS_OUT;
+    }
+
+    if( !encapsulation.Cmp( "ps" ) )
+    {
+        i_encapsulation_type = PS_ENCAPSULATION;
+    }
+    else if( !encapsulation.Cmp( "avi" ) )
+    {
+        i_encapsulation_type = AVI_ENCAPSULATION;
+    }
+    else if( !encapsulation.Cmp( "ogg" ) )
+    {
+        i_encapsulation_type = OGG_ENCAPSULATION;
+    }
+    else
+    {
+        i_encapsulation_type = TS_ENCAPSULATION;
+    }
+
+    wxString second_part = mrl.AfterFirst( ':' );
+
+    if( i_access_type == FILE_ACCESS_OUT )
+    {
+        /* The whole second part of the MRL is the filename */
+        file_combo->SetValue( second_part );
+    }
+    else
+    {
+        /* we've got address:port */
+        wxString address = second_part.BeforeLast( ':' );
+        net_addr->SetValue( address );
+
+        long int i_port;
+        wxString port = second_part.AfterLast( ':' );
+        if( port.ToLong( &i_port ) )
+        {
+            net_port->SetValue( i_port );
+        }
+        else
+        {
+            net_port->SetValue( config_GetInt( p_intf, "server-port" ) );
+        }
+    }
+
+    /* Update access output panel */
+    wxCommandEvent dummy_event;
+    dummy_event.SetId( AccessRadio1_Event + i_access_type );
+    OnAccessTypeChange( dummy_event );
+
+    /* Update encapsulation output panel */
+    dummy_event.SetId( EncapsulationRadio1_Event + i_encapsulation_type );
+    OnEncapsulationChange( dummy_event );
+}
+
 /*****************************************************************************
  * Events methods.
  *****************************************************************************/
@@ -477,7 +536,7 @@ void SoutDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
 
     if( dialog.ShowModal() == wxID_OK )
     {
-        file_combo->SetValue( dialog.GetPath() );      
+        file_combo->SetValue( dialog.GetPath() );
         UpdateMRL();
     }
 }
@@ -490,12 +549,6 @@ void SoutDialog::OnNetChange( wxCommandEvent& WXUNUSED(event) )
     UpdateMRL();
 }
 
-void SoutDialog::OnMulticastChange( wxCommandEvent& event )
-{
-    b_multicast = event.GetInt();
-    UpdateMRL();
-}
-
 /*****************************************************************************
  * Encapsulation panel event methods.
  *****************************************************************************/